Hello world UEFI app in D using uefi-d library
This commit is contained in:
commit
216ef2d654
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/build/
|
||||
/.rscons*
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "uefi-d"]
|
||||
path = uefi-d
|
||||
url = git://github.com/kubasz/uefi-d
|
37
Rsconscript
Normal file
37
Rsconscript
Normal file
@ -0,0 +1,37 @@
|
||||
configure do
|
||||
check_d_compiler "ldc2"
|
||||
check_c_compiler "x86_64-w64-mingw32-gcc"
|
||||
check_program "mformat"
|
||||
end
|
||||
|
||||
class Image < Builder
|
||||
def run(options)
|
||||
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||
print_run_message("Image <target>#{@target}<reset>", nil)
|
||||
system(*%W[dd if=/dev/zero of=#{@target} bs=1k count=1440])
|
||||
system(*%W[mformat -i #{@target} -f 1440 ::])
|
||||
system(*%W[mmd -i #{@target} ::/EFI])
|
||||
system(*%W[mmd -i #{@target} ::/EFI/BOOT])
|
||||
system(*%W[mcopy -i #{@target} #{@sources.first} ::/EFI/BOOT])
|
||||
@cache.register_build(@target, nil, @sources, @env)
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
uefi_env = env "uefi" do |env|
|
||||
env.add_builder(Image)
|
||||
env["sources"] = glob("src/**/*.d")
|
||||
env["sources"] += glob("uefi-d/source/**/*.d")
|
||||
env["DFLAGS"] += %w[-mtriple=x86_64-unknown-windows-coff --betterC -release]
|
||||
env["D_IMPORT_PATH"] += %w[uefi-d/source]
|
||||
env["LD"] = "x86_64-w64-mingw32-gcc"
|
||||
env["LDFLAGS"] += %w[-nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main]
|
||||
env["LDCMD"] = %w[${LD} -o ${_TARGET} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}]
|
||||
env.Program("^/BOOTX64.EFI", "${sources}")
|
||||
env.Image("^/efi-loader.img", "^/BOOTX64.EFI")
|
||||
end
|
||||
|
||||
task "run" do
|
||||
sh %W[qemu-system-x86_64 -bios OVMF.fd -hda #{uefi_env.expand("^/efi-loader.img")}]
|
||||
end
|
22
src/main.d
Normal file
22
src/main.d
Normal file
@ -0,0 +1,22 @@
|
||||
import uefi;
|
||||
|
||||
extern (C) void * _tls_index = null;
|
||||
|
||||
void write_string(EFI_SYSTEM_TABLE * st, const(wchar)[] str)
|
||||
{
|
||||
st.ConOut.OutputString(st.ConOut, cast(CHAR16 *)str.ptr);
|
||||
}
|
||||
|
||||
extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st)
|
||||
{
|
||||
write_string(st, "Hello, D UEFI world!\r\n"w);
|
||||
write_string(st, "Press any key...\r\n"w);
|
||||
|
||||
st.ConIn.Reset(st.ConIn, FALSE);
|
||||
EFI_INPUT_KEY key;
|
||||
while (st.ConIn.ReadKeyStroke(st.ConIn, &key) == EFI_NOT_READY)
|
||||
{
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
1
uefi-d
Submodule
1
uefi-d
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 6f471937f2bfec2e5d37ad9182149db1a8df6d32
|
Loading…
x
Reference in New Issue
Block a user