Rainbow-OS: Building a 32-Bit Operating System from Scratch


What if you built a complete operating system from scratch — no libraries, no existing kernel, no abstraction layers? That’s exactly what Rainbow-OS is: a self-built 32-bit operating system for the Intel 486 architecture, emulated with QEMU.

What is Rainbow-OS?

Rainbow-OS is a hobby project that demonstrates how a modern operating system works at the lowest level. It consists of a hand-written bootloader in NASM assembly and a kernel in C — completely without stdlib, without Linux, without any OS abstractions. Everything runs on bare metal (or QEMU’s emulation of it).

Why Build Your Own OS?

Most developers work with operating systems every day without ever understanding what’s really going on underneath. Rainbow-OS changes that. Every line of code — from the first boot sector to the filesystem — was written and understood by hand. The project is an intense journey through:

  • x86 assembly and Protected Mode
  • Hardware interrupts and the 8259A PIC
  • Memory management at the frame level
  • Filesystem structures (FAT12)
  • SVGA graphics with bank switching

Technology Stack

ComponentTechnology
BootloaderNASM Assembly (Stage 1 + Stage 2)
KernelC (freestanding, no stdlib)
Target ArchitectureIntel 486, 32-bit Protected Mode
EmulatorQEMU (-cpu 486, -m 32, -vga cirrus)
Build SystemCMake with i686-elf cross-compiler
Development SetupMacBook M1 + CLion + GDB Remote

Architecture: The Boot Process

When the system starts, a multi-stage process runs — every part implemented by hand:

x86 Memory Map – Rainbow-OS showing BIOS, bootloader and kernel addresses
x86 memory layout: from the BIOS interrupt vectors at 0x00000 to the kernel at 0x100000+
  1. Stage 1 (boot.asm, 512 bytes) — The MBR. Enables A20, saves the boot drive, loads Stage 2.
  2. Stage 2 (stage2.asm) — Sets up the GDT, switches to 32-bit Protected Mode, copies the kernel to address 0x100000.
  3. Kernel Entry (entry.asm) — Sets up the stack and calls kernel_main().
  4. Kernel (kernel.c) — Initializes all subsystems: Serial, VGA, PIC, IDT, PMM, Paging, Ramdisk, SVGA, Keyboard, Shell.

The 9 Milestones

The project was built incrementally across 9 milestones — each one building on the previous:

MilestoneDescription
M12-stage bootloader with Protected Mode switch
M2VGA text mode (80×25 characters)
M3Serial console (COM1 logging for debugging)
M4PS/2 keyboard input via IDT and PIC
M5Interactive shell with commands
M6Physical memory manager + paging (32 MB)
M7FAT12 filesystem on a 64 KB ramdisk
M8SVGA graphics with Cirrus GD5446 (640×480, 8bpp)
M9HDD boot support (16 MB image)

The Shell: Direct Hardware Control

The system boots into a minimalist shell. Available commands: help, version, meminfo, ls, cat, gfx (switch to SVGA graphics mode), clear, and reboot.

Technical Highlights

SVGA Bank Switching: The Cirrus GD5446 uses a 64 KB window at 0xA0000. To address all 307,200 pixels in 640×480 mode, the GR9 register is used for bank selection — a technique straight out of the DOS era.

Freestanding C: The entire kernel runs without any C standard library. Even basic functions like memset, memcpy, and strcmp are implemented in a custom lib/string.c.

Cross-Compilation on M1: Developed on an Apple Silicon MacBook using an i686-elf-gcc cross-compiler. QEMU emulates the entire x86 hardware via TCG (no KVM).

Source Code

The full source code is available on GitHub:

Conclusion

Rainbow-OS is a complete, bootable operating system — built out of pure curiosity and the desire to truly understand every layer of computing. From the first 512 bytes of the boot sector to the SVGA graphics: every line of code was written deliberately and understood completely.

If you want to understand how a computer really works, there is no better school than building one yourself.