Skip to content
Achille BOSC
All projects

KFS — Kernel From Scratch

32-bit x86 kernel written solo from scratch, from GRUB boot to preemptive multitasking.

The problem

Write an operating system with nothing underneath: no standard library, no printf, no memory management. Everything a user program takes for granted has to be built, in the right order, directly against the processor.

Kernel architecture, layer by layer

  1. User spaceprocesses
  2. System callsuser ↔ kernel boundary
  3. Schedulerpreemptive multitasking, timer tick
  4. InterruptsIDT · exceptions · IRQ · keyboard
  5. Memorypaging · allocation
  6. GDTsegmentation · privilege levels
  7. BootGRUB Multiboot · ASM entry · linker script
  8. x86 hardwarei386, protected mode
Each layer rests on the one below it: they were built bottom-up.

What I built

The first four stages of the KFS track, entirely on my own:

  • Boot: kernel loaded by GRUB (Multiboot), assembly entry point, linker script placing every section in memory.
  • GDT: the Global Descriptor Table, defining segmentation and privilege levels.
  • Memory: paging and kernel memory allocation.
  • Interrupts: IDT, CPU exception and hardware interrupt handling, keyboard driver.
  • System calls: the interface between user space and the kernel.
  • Preemptive multitasking: process scheduling driven by the timer interrupt.

Technical challenges

  • Debugging without a safety net: a mistake in the GDT or IDT causes a triple fault and an instant reboot, with no message. You reason from register state.
  • Build order: paging needs an allocator, the scheduler needs interrupts. Each building block rests on the previous one.
  • The ASM / C boundary: context switches, register saving and interrupt return are written in assembly, right at the calling convention.

Skills demonstrated

x86 protected-mode architecture, C and assembly with no library, virtual memory management, interrupts and drivers, scheduling, autonomy on a long and demanding project.

Next projectft_shield