Master the fundamental concepts of build a mini kernel through this focused micro-challenge.
The GDT holds segment descriptors consumed by the CPU in protected mode. Even with paging, segment registers must reference valid entries. Null descriptor, code, and data entries are the minimum for a flat kernel.
Each 8-byte entry packs:
For example, selector 0x08 (index 1, RPL 0) might be a 4 GB readable code segment for kernel text starting at linear 0.
The flat-model GDT you're encoding here , ring 0 kernel segments, ring 3 user segments, all spanning 4GB , is exactly what every production x86 kernel sets up before touching paging, even though modern OSes rely on page tables rather than segmentation for real protection. Get an access byte wrong (0x9A vs 0x92, code vs data) and user code silently runs with kernel privileges instead of faulting.
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 build GDT entries, load with lgdt, and reload segments. The task asks you to dump selector values in a small C routine compiled for protected mode.
Implement a GDT setup simulation 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