diff --git a/Makefile b/Makefile index f91576c..4e7cea8 100644 --- a/Makefile +++ b/Makefile @@ -3,5 +3,5 @@ all: @./rscons .PHONY: run -run: +run: all qemu-system-x86_64 -bios OVMF.fd -hdb build/e.1/efi-loader.img diff --git a/main.c b/main.c index b14ee5f..5dd5842 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,26 @@ #include #include +#include + +EFI_SYSTEM_TABLE * g_system_table; + +static void write_string(uint16_t * string) +{ + g_system_table->ConOut->OutputString(g_system_table->ConOut, string); +} + +static void write_uint(uint32_t n) +{ + uint16_t s[12] = {0}; + size_t i = 0u; + while ((n != 0u) || (i == 0u)) + { + s[10u - i] = '0' + (n % 10u); + n /= 10u; + i++; + } + write_string(&s[11u - i]); +} EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table) @@ -7,7 +28,9 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table) EFI_STATUS status; EFI_INPUT_KEY key; - status = system_table->ConOut->OutputString(system_table->ConOut, L"My first EFI loader\n\r"); + g_system_table = system_table; + + write_string(L"My first EFI loader\r\n"); if (EFI_ERROR(status)) return status; @@ -15,6 +38,20 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table) if (EFI_ERROR(status)) return status; + EFI_HANDLE buffer[10]; + UINTN buffer_size = sizeof(buffer); + status = system_table->BootServices->LocateHandle(ByProtocol, + &(EFI_GUID)EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, + NULL, + &buffer_size, + buffer); + write_string(L"status = "); + write_uint(status); + write_string(L", num entries = "); + write_uint(buffer_size / sizeof(EFI_HANDLE)); + write_string(L"\r\n"); + + write_string(L"Press any key...\r\n"); while ((status = system_table->ConIn->ReadKeyStroke(system_table->ConIn, &key)) == EFI_NOT_READY) { }