LeveretOS, a small educational Operating System built from scratch. New additions are split into separate lessons, with each step documented. Every change includes educational comments, built for beginners. This repository aims to double as a step-by-step guide on how an OS actually works.
Boot the latest version of LeveretOS in browser! No install required. This runs the same ISO as the latest lesson.
arp.Emulated in browser with v86.
Each lesson will have its own folder, and will add one new feature on top of the last. New or changed code will contain comments to guide you through each step. Note that reused code will be left without educative comments to improve simplicity.
Each lesson folder is a copy of the one before, with the addition of one new feature. It is unnecessary to reread every file each lesson. A few files change per lesson, and you can see them in the following ways:
.LessonOverview.txt, which explains what the
lesson adds and lists which files were added or changed.git diff --no-index 12-Shell/src 13-Timer/src (swap in the
two folders). New lines are shown in green and removed lines in red. You can also browse
the code on GitHub.
When studying lessons, the recommended way is: read the overview, open the changed files,
look for the new-code comments, and compare the differences with git diff.
A leveret is a baby hare, small, quick, and one of the fastest-growing young animals around. It felt like the right mascot for an OS that started as almost nothing and will grow a little better with every lesson.
Photo by Tony Stoddard on Unsplash.
| 01 | Hello World | Booting via GRUB and writing text to VGA memory | Boot → |
| 02 | Text Output | A moving cursor for typing, putchar/print, newlines and wrapping | Boot → |
| 03 | Text Input | Reading the keyboard: scancodes, getchar, read_line | Boot → |
| 04 | Print Numbers | Turning integers into on-screen digits | Boot → |
| 05 | String helpers | Create helpers for strings and memory | Boot → |
| 06 | Scrolling | Shift lines up when text reaches the bottom | Boot → |
| 07 | Rock Paper Scissors | A playable terminal game, built from everything so far | Boot → |
| 08 | Restructure | Split the kernel into multiple files and headers (same behaviour) | Boot → |
| 09 | GDT | Build our own segment table so the kernel controls its own code and data (same behaviour) | Boot → |
| 10 | Interrupts (IDT) | Catch CPU exceptions with our own interrupt table | Boot → |
| 11 | Keyboard via interrupts | The keyboard now sends key presses, instead of constant polling | Boot → |
| 12 | Shell | A command prompt the user can type into, with the commands help, clear, about, and echo | Boot → |
| 13 | Timer & Clock | A timer, and a clock command which shows the real time | Boot → |
| 14 | Physical Memory | Create a physical memory manager, and check RAM usage with a command | Boot → |
| 15 | Paging | Turn on paging, or virtual memory, using page tables instead of physical addresses | Boot → |
| 16 | Heap | Build a memory allocation system, allowing us to give out memory blocks of any size | Boot → |
| 17 | Reorganize | Sort source files into folders to clean up the project | Boot → |
| 18 | PCI Scan | Scan the PCI bus to find external devices, such as the network card | Boot → |
| 19 | Find Network Card | Communicate with the network card and read its MAC address | Boot → |
| 20 | Send and Receive | Send ethernet frames out of the network card | Boot → |
| 21 | Ethernet and ARP | An Ethernet layer to create headers, and ARP to find a machine's MAC from its IP | Boot → |
Don't want to download anything? Every lesson can be booted in browser, just press the "Boot" button on any lesson above. If you'd rather build it yourself, you can use the following methods.
Each lesson folder is self-contained and includes a build.sh that assembles
the bootloader, compiles the kernel, makes a bootable ISO, and launches it in QEMU. You
will need nasm, a 32-bit-capable g++, grub-mkrescue,
xorriso, and qemu-system-i386 (on Windows, a Linux environment
such as WSL works well).
A good guide for setting up the necessary software to be able to boot: OSDev Bare Bones.
If you don't want to install everything by hand, the repo includes a
Dockerfile with the build environment. You only need
Docker to build, and
QEMU to run.
# From the repo root, build the toolchain container once:
docker build -t leveretos .
# Build a lesson's ISO inside the container (change the folder for other lessons):
docker run --platform linux/amd64 --rm -v "$PWD":/src -w /src/06-Scrolling leveretos ../build-iso.sh
# Run the resulting ISO with QEMU on your own machine:
qemu-system-i386 -cdrom 06-Scrolling/build/LeveretOS-Scrolling.iso
The container is pinned to x86-64, so on Apple Silicon Macs Docker can emulate it (a little
slower, but it works). The ISO is written to the lesson's build/ folder, so
you run it with QEMU on the host.
The first big goal is a LeveretOS that can go online and open a web page. These are the checkpoints we have set to reach our goal.
Once we can browse the web, our goals can get bigger. This is where LeveretOS will grow from a single program into something closer to a real operating system.