HELLO: Add scratch module

This commit is contained in:
Josh Holtrop 2022-03-18 16:03:50 -04:00
parent 372b7265f1
commit ef01239468
2 changed files with 26 additions and 6 deletions

View File

@ -1,10 +1,10 @@
import uefi;
import output;
import scratch;
import hulk.bootinfo;
__gshared EFI_SYSTEM_TABLE * st;
__gshared BootInfo bootinfo;
__gshared ubyte[512 * 1024] scratch;
__gshared UINTN memory_map_key;
private void wait_key()
@ -31,9 +31,9 @@ private bool in_qemu()
private bool set_graphics_mode()
{
uint max_horizontal_resolution = in_qemu() ? 1920u : 0xFFFFFFFFu;
UINTN buffer_size = scratch.sizeof;
UINTN buffer_size = scratch_free();
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_HANDLE * handles = cast(EFI_HANDLE *)&scratch;
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)
@ -87,12 +87,13 @@ private bool set_graphics_mode()
private bool get_memory_map()
{
UINTN memory_map_size = scratch.sizeof;
UINTN memory_map_size = scratch_free();
UINTN descriptor_size;
UINT32 descriptor_version;
ubyte * scratch_base = scratch_current();
UINTN status = st.BootServices.GetMemoryMap(
&memory_map_size,
cast(EFI_MEMORY_DESCRIPTOR *)&scratch,
cast(EFI_MEMORY_DESCRIPTOR *)scratch_base,
&memory_map_key,
&descriptor_size,
&descriptor_version);
@ -105,7 +106,7 @@ private bool get_memory_map()
size_t di;
for (size_t i = 0u; i < n_entries; i++)
{
EFI_MEMORY_DESCRIPTOR * descriptor = cast(EFI_MEMORY_DESCRIPTOR *)&scratch[i * descriptor_size];
EFI_MEMORY_DESCRIPTOR * descriptor = cast(EFI_MEMORY_DESCRIPTOR *)&scratch_base[i * descriptor_size];
if ((descriptor.Type == EfiConventionalMemory) ||
(descriptor.Type == EfiBootServicesCode) ||
(descriptor.Type == EfiBootServicesData))

19
src/hello/scratch.d Normal file
View File

@ -0,0 +1,19 @@
__gshared ubyte[512 * 1024] scratch;
__gshared size_t scratch_used;
size_t scratch_free()
{
return scratch.sizeof - scratch_used;
}
ubyte * scratch_current()
{
return &scratch[scratch_used];
}
ubyte * scratch_alloc(size_t n = 1)
{
ubyte * address = &scratch[scratch_used];
scratch_used += 4096u * n;
return address;
}