LeveretOS hare logo 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.

Why "LeveretOS"?

A leveret, a young hare, resting in grass

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.



The idea

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 goal

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

Lessons so far

Fundamentals

01. Hello WorldBooting via GRUB and writing text straight to VGA memory.
02. Text OutputA moving cursor, putchar and print, newlines and wrapping.
03. Text InputReading the keyboard: scancodes, getchar, read_line.
04. Print NumbersTurning integers into on-screen digits.
05. String helpersOur own helpers for strings and memory.
06. ScrollingShifting lines up when text reaches the bottom.
07. Rock Paper ScissorsA playable terminal game, built from everything so far.

Talking to the Hardware

08. RestructureSplitting the kernel into multiple files and headers.
09. GDTOur 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 interruptsThe keyboard now sends key presses, instead of constant polling.
12. ShellA command prompt the user can type into, with the commands help, clear, about, and echo.
13. Timer & ClockA timer, and a clock command which shows the real time from the RTC.

Managing Memory

14. Physical MemoryCreate a physical memory manager, and check RAM usage with a command.
15. PagingTurn on paging, or virtual memory, using page tables instead of physical addresses.
16. HeapBuild a memory allocation system, allowing us to give out memory blocks of any size.
17. ReorganizeSort source files into folders to clean up the project.

Getting Online

18. PCI ScanScan the PCI bus to find external devices, such as the network card.
19. Find Network CardCommunicate with the network card and read its MAC address.
20. Send and ReceiveSend ethernet frames out of the network card.
21. Ethernet and ARPAn Ethernet layer to create headers, and ARP to find a machine's MAC from its IP.

Building it yourself

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.