86 lines
2.2 KiB
D
86 lines
2.2 KiB
D
import uefi;
|
|
import output;
|
|
import heap;
|
|
import hos.bootinfo;
|
|
|
|
__gshared EFI_SYSTEM_TABLE * st;
|
|
__gshared BootInfo * bootinfo;
|
|
|
|
private void wait_key()
|
|
{
|
|
writeln("Press any key...");
|
|
st.ConIn.Reset(st.ConIn, FALSE);
|
|
EFI_INPUT_KEY key;
|
|
while (st.ConIn.ReadKeyStroke(st.ConIn, &key) == EFI_NOT_READY)
|
|
{
|
|
}
|
|
}
|
|
|
|
private bool set_graphics_mode()
|
|
{
|
|
UINTN buffer_size = heap_free();
|
|
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
|
EFI_HANDLE * handles = cast(EFI_HANDLE *)heap_base();
|
|
EFI_STATUS status = st.BootServices.LocateHandle(ByProtocol,
|
|
&gop_guid, null, &buffer_size, handles);
|
|
if (status != EFI_SUCCESS)
|
|
{
|
|
writeln("LocateHandle: error %u", status);
|
|
return false;
|
|
}
|
|
EFI_HANDLE gop_handle = handles[0];
|
|
EFI_HANDLE gop_interface;
|
|
status = st.BootServices.HandleProtocol(gop_handle,
|
|
&gop_guid, &gop_interface);
|
|
if (status != EFI_SUCCESS)
|
|
{
|
|
writeln("HandleProtocol: error %u", status);
|
|
return false;
|
|
}
|
|
if (gop_interface == null)
|
|
{
|
|
writeln("null interface from HandleProtocol");
|
|
return false;
|
|
}
|
|
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = cast(EFI_GRAPHICS_OUTPUT_PROTOCOL *)gop_interface;
|
|
UINTN info_size;
|
|
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * info;
|
|
uint best_width;
|
|
uint best_mode_number;
|
|
for (uint mode_number = 0u;
|
|
(status = gop.QueryMode(gop, mode_number, &info_size, &info)) == EFI_SUCCESS;
|
|
mode_number++)
|
|
{
|
|
if (info.HorizontalResolution > best_width)
|
|
{
|
|
best_width = info.HorizontalResolution;
|
|
best_mode_number = mode_number;
|
|
}
|
|
st.BootServices.FreePool(info);
|
|
}
|
|
gop.SetMode(gop, best_mode_number);
|
|
return true;
|
|
}
|
|
|
|
extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st)
|
|
{
|
|
.st = st;
|
|
|
|
st.ConOut.ClearScreen(st.ConOut);
|
|
|
|
writeln("HOS EFI loader");
|
|
writeln("Firmware vendor: '%S', version: 0x%x", st.FirmwareVendor, st.FirmwareVendor);
|
|
|
|
bootinfo = cast(BootInfo *)heap_consume(BootInfo.sizeof);
|
|
|
|
if (!set_graphics_mode())
|
|
{
|
|
wait_key();
|
|
return EFI_SUCCESS;
|
|
}
|
|
|
|
wait_key();
|
|
|
|
return EFI_SUCCESS;
|
|
}
|