LocateHandle for graphics output protocol

This commit is contained in:
Josh Holtrop 2022-03-08 22:19:09 -05:00
parent 353e3d7276
commit 617f4de515
2 changed files with 39 additions and 2 deletions

View File

@ -3,5 +3,5 @@ all:
@./rscons @./rscons
.PHONY: run .PHONY: run
run: run: all
qemu-system-x86_64 -bios OVMF.fd -hdb build/e.1/efi-loader.img qemu-system-x86_64 -bios OVMF.fd -hdb build/e.1/efi-loader.img

39
main.c
View File

@ -1,5 +1,26 @@
#include <efi.h> #include <efi.h>
#include <efilib.h> #include <efilib.h>
#include <stddef.h>
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_STATUS
efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table) 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_STATUS status;
EFI_INPUT_KEY key; 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)) if (EFI_ERROR(status))
return status; return status;
@ -15,6 +38,20 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table)
if (EFI_ERROR(status)) if (EFI_ERROR(status))
return 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) while ((status = system_table->ConIn->ReadKeyStroke(system_table->ConIn, &key)) == EFI_NOT_READY)
{ {
} }