KFS_1 — Kernel From Scratch
This is it. Kernel From Scratch. We are actually building a kernel.
Without any existing software, API, or anything.
There are many parts to this project and they are all linked together. As we build these features, keep in mind that the kernel must be flexible and that functions must easily fit in. Half of the time you’ll spend on these projects will be adding links between different aspects of your kernel.
That means, you have to write memory code before processes & execution code. But processes must use memory, right? So those two have to be linked. Keep it clean, and the internal API simple.
Objectives
By the end of KFS_1, you will have:
- A kernel you can boot via GRUB
- An ASM bootable base
- A basic kernel library, with basic functions and types
- Code to print text on the screen
- A basic “Hello World” kernel
- Full keyboard input via hardware interrupts
- Exception handling to catch CPU faults
- A robust interrupt system
Mandatory Requirements
The kernel must be able to boot with GRUB and write characters on screen. That means:
- Install GRUB on a virtual image
- Write an ASM boot code that handles the Multiboot header, and use GRUB to initialise and call the main function of the kernel
- Compile with correct flags, and link to make it bootable
- Write helpers like kernel types or basic functions
- Must be smaller than 10MB
- Code the interface between the kernel and the screen
- Display text on the screen
For the linker, you must create a linker file with the GNU linker (ld).
Bonus Features (Implemented)
- ✅ Scroll and cursor support
- ✅ Color support
- ✅
printf/printkhelpers - ✅ Keyboard input via interrupts
- ✅ Exception handlers
Project Structure
kfs_1/kfs/
├── Cargo.toml
├── Cargo.lock
├── i386-unknown-none.json # Custom bare-metal target
├── boot.asm # Multiboot header + stack setup
├── kb.asm # Keyboard interrupt wrapper
├── exceptions.asm # Exception handler wrappers
├── linker.ld # Linker script
├── Makefile
└── src/
├── lib.rs # Kernel entry point + panic handler
├── vga.rs # VGA text mode driver
├── idt.rs # Interrupt Descriptor Table
├── pic.rs # Programmable Interrupt Controller
├── kb.rs # Keyboard handler
└── exceptions.rs # CPU exception handlers
Build & Run
make # Build kernel
make run # Run in QEMU
make clean # Clean artifacts
make re # Full rebuild
Prerequisites
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
sudo pacman -S nasm qemu-system-i386 # Arch Linux