ralph balazs
← Back to all projects
Systems Low-level C/ASM

KFS-1 — a tiny x86 kernel

A bootable 32-bit x86 kernel in freestanding C and NASM assembly — GRUB/Multiboot boot, VGA text driver, PS/2 keyboard driver, libc-free kprintf.

Context
42 school project
Team
Pair project
Status
My part: the PS/2 keyboard driver
Stack
C (freestanding) · NASM · Makefile · QEMU/GDB · GRUB
Links

Why write a kernel

KFS is 42's kernel series: a progressive project that starts from nothing — no OS, no libc, no safety net — and builds up an x86 kernel piece by piece. KFS-1, the level covered here, is a pair project focused on getting a minimal kernel to boot and talk to the keyboard and screen.

Boot path

The kernel boots through GRUB via a Multiboot header, hands off from assembly to C, and links with a custom ld linker script. It's compiled -ffreestanding -nostdlib — no host OS, no standard library — and tested under QEMU with remote GDB attached for debugging.

My part: the keyboard driver

My main contribution is the PS/2 keyboard driver: reading the x86 I/O ports directly with inb (ports 0x60/0x64), decoding make/break scancodes, and handling modifier state — Shift, Caps Lock — as well as extended keys like arrows and Delete. The kernel also ships a VGA text-mode driver (scrolling, hardware cursor, line editing) and a minimal kprintf, which I built together with my teammate, who was the main author of the base kernel and its bonus features.

Debugging bare metal

With no OS underneath to catch you, debugging happens through QEMU running the kernel image with GDB attached remotely — stepping through boot code and driver logic at the instruction level when something goes wrong.

Honest scope

KFS-1 is deliberately limited: display and keyboard I/O, nothing more. There's no virtual memory and no scheduler yet — those come in later levels of the KFS series. This write-up covers exactly what was built at this stage, not the full series.