Master the fundamental concepts of build a mini kernel through this focused micro-challenge.
Paging uses CR3 as root physical address of page tables. Set CR0.PG after building valid PDE/PTE chains mapping kernel text and an identity map for bring-up.
Bring-up pattern:
4 MB identity for transitionFor example, PTE for virtual 0xC0000000 might point to physical 0x00100000 with present+writable bits.
The two-level page directory and page table you set up here are the literal structures the x86 MMU walks via CR3 on every memory access, and identity-mapping the first 4MB is the standard trick every OSDev tutorial uses so the kernel doesn't crash the instant paging is enabled. Forget the present bit on a single entry and the very next instruction fetch after enabling paging triggers a page fault with no handler yet installed.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will allocate page tables from the E820-backed allocator and enable paging. The task asks you to handle a deliberate page fault by fixing a missing PTE.
Simulate x86 page table setup in C.
Requirements:
Test:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github