From 0be1b113aad13640f9fb0295a975252540cf4f34 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 14 Mar 2022 13:53:02 -0400 Subject: [PATCH] Add output module for console output routines --- Rsconscript | 2 +- src/hel/hel.d | 9 +++++++-- src/hel/output.d | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/hel/output.d diff --git a/Rsconscript b/Rsconscript index 6b05d7b..0dfea37 100644 --- a/Rsconscript +++ b/Rsconscript @@ -76,7 +76,7 @@ hel_env = env "hel", use: %w[ldc2 x86_64-w64-mingw32-gcc] do |env| env["sources"] = glob("src/hel/**/*.d") env["sources"] += glob("uefi-d/source/**/*.d") env["DFLAGS"] += %w[-mtriple=x86_64-unknown-windows-coff --betterC -release -O3] - env["D_IMPORT_PATH"] += %w[src uefi-d/source] + env["D_IMPORT_PATH"] += %w[src/hel uefi-d/source] env["LD"] = "x86_64-w64-mingw32-gcc" env["LDFLAGS"] += %w[-nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -Wl,-Map,${_TARGET}.map] env["LDCMD"] = %w[${LD} -o ${_TARGET} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}] diff --git a/src/hel/hel.d b/src/hel/hel.d index c238ba1..9a6b48d 100644 --- a/src/hel/hel.d +++ b/src/hel/hel.d @@ -1,11 +1,16 @@ import uefi; +import output; + +__gshared EFI_SYSTEM_TABLE * g_st; extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st) { + g_st = st; + st.ConOut.ClearScreen(st.ConOut); - st.ConOut.OutputString(st.ConOut, cast(CHAR16 *)"HOS EFI loader\r\n"w); - st.ConOut.OutputString(st.ConOut, cast(CHAR16 *)"Press any key...\r\n"w); + writeln("HOS EFI loader"); + writeln("Press any key..."); st.ConIn.Reset(st.ConIn, FALSE); EFI_INPUT_KEY key; diff --git a/src/hel/output.d b/src/hel/output.d new file mode 100644 index 0000000..fa4e304 --- /dev/null +++ b/src/hel/output.d @@ -0,0 +1,21 @@ +import uefi; +import hel; + +void write(string s) +{ + __gshared static CHAR16[256] s16; + size_t i = 0u; + while (i < s.length) + { + s16[i] = s[i]; + i++; + } + s16[i++] = 0u; + g_st.ConOut.OutputString(g_st.ConOut, &s16[0]); +} + +void writeln(string s) +{ + write(s); + write("\r\n"); +}