Rework scratch module and use qualified names for function calls

This commit is contained in:
Josh Holtrop 2022-03-20 22:21:10 -04:00
parent 1e00d7a9e9
commit b40151055c
2 changed files with 26 additions and 12 deletions

View File

@ -2,7 +2,7 @@ module hello.hello;
import uefi;
import console = hello.console;
import hello.scratch;
import scratch = hello.scratch;
import hulk.bootinfo;
import hos.page_table;
import hos.cpu;
@ -28,9 +28,9 @@ private bool in_qemu()
private bool set_graphics_mode()
{
uint max_horizontal_resolution = in_qemu() ? 1920u : 0xFFFFFFFFu;
UINTN buffer_size = scratch_free();
UINTN buffer_size = scratch.free();
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_HANDLE * handles = cast(EFI_HANDLE *)scratch_current();
EFI_HANDLE * handles = cast(EFI_HANDLE *)scratch.current();
EFI_STATUS status = st.BootServices.LocateHandle(ByProtocol,
&gop_guid, null, &buffer_size, handles);
if (status != EFI_SUCCESS)
@ -84,10 +84,10 @@ private bool set_graphics_mode()
private ulong get_memory_map()
{
UINTN memory_map_size = scratch_free();
UINTN memory_map_size = scratch.free();
UINTN descriptor_size;
UINT32 descriptor_version;
ubyte * scratch_base = scratch_current();
ubyte * scratch_base = scratch.current();
UINTN status = st.BootServices.GetMemoryMap(
&memory_map_size,
cast(EFI_MEMORY_DESCRIPTOR *)scratch_base,
@ -134,7 +134,7 @@ private ulong get_memory_map()
private PageTableEntry * new_page_table()
{
PageTableEntry * pt = cast(PageTableEntry *)scratch_alloc(1u);
PageTableEntry * pt = cast(PageTableEntry *)scratch.alloc(1u);
memset64(pt, 0u, 512);
return pt;
}
@ -257,7 +257,6 @@ extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st)
console.writeln("HELLO, HOS EFI Lightweight LOader, v0.1.0");
console.writeln("Firmware vendor: '%S', version: 0x%x", st.FirmwareVendor, st.FirmwareVendor);
wait_key();
if (!set_graphics_mode())
{

View File

@ -1,19 +1,34 @@
/**
* HELLO scratch buffer.
*/
module hello.scratch;
align(4096) __gshared ubyte[1024 * 1024] scratch;
__gshared size_t scratch_used;
/* Scratch buffer. */
private align(4096) __gshared ubyte[1024 * 1024] scratch;
size_t scratch_free()
/* Number of scratch buffer bytes used. */
private __gshared size_t scratch_used;
/**
* Get the number of free bytes in the scratch buffer.
*/
size_t free()
{
return scratch.sizeof - scratch_used;
}
ubyte * scratch_current()
/**
* Get the current free scratch buffer address.
*/
ubyte * current()
{
return &scratch[scratch_used];
}
ubyte * scratch_alloc(size_t n = 1)
/**
* Allocate pages from the scratch buffer.
*/
ubyte * alloc(size_t n = 1)
{
ubyte * address = &scratch[scratch_used];
scratch_used += 4096u * n;