tosin_rtos — Real-Time Operating System
A complete from-scratch RTOS for x86 with custom bootloader, preemptive multitasking, 16-priority scheduler, best-fit heap allocator, IPC primitives, and interactive shell — all in ~20KB and ~4,050 lines of C and x86 Assembly.
Visit websiteWhy build an OS from scratch?
To truly understand systems engineering, you have to go all the way down. tosin_rtos started as a deep dive into how hardware and software meet — from the very first instruction the CPU executes after power-on to a fully interactive shell running user processes. No libraries, no OS calls, no safety nets — just raw metal, registers, and memory.
Bootloader & kernel
The system starts with a custom 512-byte MBR bootloader written in x86 Assembly (NASM) that transitions the CPU from 16-bit real mode to 32-bit protected mode, sets up the GDT, and loads the kernel from disk.
The kernel implements preemptive round-robin scheduling across 16 priority levels with context switching completing in approximately 100 CPU cycles (~0.1μs at 1GHz). Scheduler overhead stays below 1% at 100Hz tick rate. The entire kernel fits in roughly 20KB.
Memory & IPC
Memory management uses a best-fit heap allocator with block splitting and coalescing to minimize fragmentation. The allocator tracks free blocks efficiently and reclaims memory deterministically.
Inter-process communication is built on counting semaphores with timeout support and circular buffer message queues — all O(1) operations. Processes can synchronize and exchange data without spinning or polling.
Interactive shell & drivers
The built-in shell provides commands including ps (process listing), meminfo (heap diagnostics), uname (system info), test (benchmark suite), echo, clear, and help. All output goes through a custom VGA text mode driver (80×25) with a full printf implementation and PS/2 keyboard input handler.
The entire system comprises ~4,050 lines of code across 27 files — C for the kernel logic and x86 Assembly (NASM) for the bootloader and low-level CPU operations. It boots and runs in QEMU, demonstrating real preemptive multitasking on bare x86 hardware.