Print memory map
This commit is contained in:
parent
dd406cf5b5
commit
fdc5584110
59
main.c
59
main.c
@ -22,14 +22,14 @@ static void write_uint(uint32_t n)
|
||||
write_string(&s[11u - i]);
|
||||
}
|
||||
|
||||
static void write_ptr(size_t n)
|
||||
static void write_hex64(size_t n)
|
||||
{
|
||||
CHAR16 hexchars[] = L"0123456789ABCDEF";
|
||||
CHAR16 s[20] = {0};
|
||||
size_t s_i = 0u;
|
||||
for (size_t i = 0u; i < 16u; i++)
|
||||
{
|
||||
if ((i != 0u) && ((i % 4u) == 0u))
|
||||
if (i == 8u)
|
||||
{
|
||||
s[s_i++] = L'_';
|
||||
}
|
||||
@ -38,7 +38,7 @@ static void write_ptr(size_t n)
|
||||
write_string(s);
|
||||
}
|
||||
|
||||
static void check_handle(EFI_HANDLE handle)
|
||||
static void check_gop_handle(EFI_HANDLE handle)
|
||||
{
|
||||
EFI_HANDLE interface = NULL;
|
||||
EFI_STATUS status = g_system_table->BootServices->HandleProtocol(handle,
|
||||
@ -59,12 +59,57 @@ static void check_handle(EFI_HANDLE handle)
|
||||
}
|
||||
|
||||
write_string(L"interface is at ");
|
||||
write_ptr((size_t)interface);
|
||||
write_hex64((size_t)interface);
|
||||
write_string(L"\r\n");
|
||||
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = (EFI_GRAPHICS_OUTPUT_PROTOCOL *)interface;
|
||||
}
|
||||
|
||||
static void dump_memory_map(void)
|
||||
{
|
||||
static uint8_t memory_map_buffer[16384];
|
||||
UINTN memory_map_size = sizeof(memory_map_buffer);
|
||||
UINTN map_key;
|
||||
UINTN descriptor_size;
|
||||
UINT32 descriptor_version;
|
||||
EFI_STATUS status = g_system_table->BootServices->GetMemoryMap(&memory_map_size,
|
||||
memory_map_buffer,
|
||||
&map_key,
|
||||
&descriptor_size,
|
||||
&descriptor_version);
|
||||
write_string(L"GetMemoryMap status = ");
|
||||
write_uint(status);
|
||||
write_string(L"\r\n");
|
||||
write_string(L" memory_map_size = ");
|
||||
write_uint(memory_map_size);
|
||||
write_string(L"\r\n");
|
||||
if (!EFI_ERROR(status))
|
||||
{
|
||||
write_string(L" descriptor_size = ");
|
||||
write_uint(descriptor_size);
|
||||
write_string(L"\r\n");
|
||||
size_t n_descriptors = memory_map_size / descriptor_size;
|
||||
for (size_t i = 0u; i < n_descriptors; i++)
|
||||
{
|
||||
EFI_MEMORY_DESCRIPTOR * descriptor = (EFI_MEMORY_DESCRIPTOR *)&memory_map_buffer[i * descriptor_size];
|
||||
if (descriptor->Type == EfiConventionalMemory)
|
||||
{
|
||||
write_string(L" ");
|
||||
write_hex64(descriptor->PhysicalStart);
|
||||
write_string(L" : ");
|
||||
write_hex64(descriptor->VirtualStart);
|
||||
write_string(L", n=");
|
||||
write_uint(descriptor->NumberOfPages);
|
||||
write_string(L", t=");
|
||||
write_uint(descriptor->Type);
|
||||
write_string(L", a=");
|
||||
write_hex64(descriptor->Attribute);
|
||||
write_string(L"\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table)
|
||||
{
|
||||
@ -80,9 +125,11 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table)
|
||||
return status;
|
||||
|
||||
write_string(L"system_table is at ");
|
||||
write_ptr((size_t)system_table);
|
||||
write_hex64((size_t)system_table);
|
||||
write_string(L"\r\n");
|
||||
|
||||
dump_memory_map();
|
||||
|
||||
EFI_HANDLE buffer[10];
|
||||
UINTN buffer_size = sizeof(buffer);
|
||||
status = system_table->BootServices->LocateHandle(ByProtocol,
|
||||
@ -99,7 +146,7 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * system_table)
|
||||
|
||||
for (size_t i = 0u; i < buffer_size; i++)
|
||||
{
|
||||
check_handle(buffer[i]);
|
||||
check_gop_handle(buffer[i]);
|
||||
}
|
||||
|
||||
write_string(L"Press any key...\r\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user