| LeveretOS An operating system built from scratch, one lesson at a time. |
LeveretOS is a small operating system built from scratch in C++. It is built as a series of lessons, where each one adds one new feature on top of the last. New code is commented for beginners, so the project can double as a step-by-step guide to how an OS works.
| Note: this is the classic-web version of the site. It is plain HTML with no JavaScript. The modern version, with an in-browser emulator for every lesson, is linked at the bottom. |
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 grows a little better with every lesson.
Each lesson has its own numbered folder and adds one new feature on top of the last. New or changed code has comments to guide you through each step. Reused code is left uncommented, so the new work stands out.
The first big goal is a version of LeveretOS that can go online and open a web page. These are the checkpoints along the way, ticked off as we reach them:
| [x] | Play a game (Rock Paper Scissors) — done |
| [x] | Type commands into it, like a real terminal — done |
| [x] | Show a running clock — done |
| [ ] | Greet you with a login screen at startup |
| [ ] | Draw real graphics on screen, so the browser has a display |
| [ ] | Open a page from the web |
Once it can browse the web, the goals get bigger. This is where LeveretOS grows from a single program into something closer to a real operating system:
| [ ] | Log in securely, with a real password |
| [ ] | Create, open, and manage files |
| [ ] | Write and save notes in a text editor |
| [ ] | Run separate apps, instead of everything being one program |
| [ ] | Open the web browser as one of those apps |
| 01. Hello World | Booting via GRUB and writing text straight to VGA memory. |
| 02. Text Output | A moving cursor, putchar and print, newlines and wrapping. |
| 03. Text Input | Reading the keyboard: scancodes, getchar, read_line. |
| 04. Print Numbers | Turning integers into on-screen digits. |
| 05. String helpers | Our own helpers for strings and memory. |
| 06. Scrolling | Shifting lines up when text reaches the bottom. |
| 07. Rock Paper Scissors | A playable terminal game, built from everything so far. |
| 08. Restructure | Splitting the kernel into multiple files and headers. |
| 09. GDT | Our own segment table, so the kernel controls its own code and data. |
| 10. Interrupts (IDT) | Catching CPU exceptions with our own interrupt table. |
| 11. Keyboard via interrupts | The keyboard now sends key presses, instead of constant polling. |
| 12. Shell | A command prompt the user can type into, with the commands help, clear, about, and echo. |
| 13. Timer & Clock | A timer, and a clock command which shows the real time from the RTC. |
| 14. Physical Memory | Create a physical memory manager, and check RAM usage with a command. |
| 15. Paging | Turn on paging, or virtual memory, using page tables instead of physical addresses. |
| 16. Heap | Build a memory allocation system, allowing us to give out memory blocks of any size. |
| 17. Reorganize | Sort source files into folders to clean up the project. |
| 18. PCI Scan | Scan the PCI bus to find external devices, such as the network card. |
| 19. Find Network Card | Communicate with the network card and read its MAC address. |
| 20. Send and Receive | Send ethernet frames out of the network card. |
| 21. Ethernet and ARP | An Ethernet layer to create headers, and ARP to find a machine's MAC from its IP. |
Each lesson folder is self-contained and includes a build script 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). There is also a Docker image with the build environment. A good guide for the toolchain is OSDev Bare Bones.
Links: Source code on GitHub | Modern version of this site
Built by Om Bhalodia.