Master the fundamental concepts of bios & uefi programming through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksUEFI tracks physical RAM with a memory map of variable-sized descriptors. Each entry lists type, physical start, page count, and attributes. Boot loaders must call GetMemoryMap, copy the map, then ExitBootServices only after the map is stable. For example, regions tagged EfiLoaderData are free for your stack once firmware hands off.
cLoading…
The map key changes if you allocate between GetMemoryMap calls; you need the key matching the final map before exit.
Allocate scratch buffers with AllocateAnyPages only before the final GetMemoryMap snapshot. Each allocation can change map size and invalidate the previous key. Print descriptor types in hex so you can spot accidental use of MMIO as RAM. The kernel you hand off to should receive a copy in conventional memory or a known physical address recorded in a boot info struct.
You will process a list of EFI_MEMORY_DESCRIPTOR entries exactly as a bootloader does before ExitBootServices: classify each by type (7 = Conventional, 3/4 = Boot Services, 9/10 = ACPI, 11/12 = MMIO), total the usable and reclaimable bytes, and find the largest conventional region your kernel can live in. This exercise requires the page math (each page is 4 KB) that every EFI stub performs.
Before calling ExitBootServices, a UEFI loader reads the memory map and decides what the kernel may use. Classify a map and total it by EFI memory type:
| Type | Meaning | Reported as |
|---|---|---|
| 7 | Conventional, free RAM | conventional bytes, and the largest such region |
| 3, 4 | Boot services code/data, reusable after ExitBootServices | reclaimable bytes |
| 9, 10 | ACPI reclaim and NVS | acpi_pages, a page count |
| 11, 12 | Memory-mapped I/O, never RAM | mmio bytes |
Every other type is ignored. A page is 4096 bytes. Use 64-bit arithmetic: a 4 GiB map is 2^32 bytes.
N, then N descriptors TYPE START PAGES: the type in decimal, the physical start in hex, the page count in decimal.
Five lines, for example:
cLoading…
The last line is the start (lowercase hex) and page count of the largest type-7 region. On a tie the first one wins; with no type-7 region it is 0x0 0.