Skip to content

tafolabi009/tosin-rtos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tosin RTOS

Tosin RTOS is a 32-bit x86 educational real-time operating system built from scratch in C and assembly. It boots via a custom 512-byte MBR bootloader, switches to protected mode, initializes timer interrupts, and runs a preemptive priority scheduler with a shell task.

Current Status

The repository already includes a working end-to-end path:

  • Bootloader loads kernel sectors from disk and enters protected mode.
  • Kernel initializes memory management and scheduler.
  • Idle and shell tasks are created at boot.
  • Timer-driven preemptive scheduling is active.
  • IPC primitives (semaphores and queues) are integrated.
  • Interactive shell commands are available for runtime inspection and testing.

Implemented Features

Boot and CPU setup

  • Custom MBR bootloader in boot/boot.asm
  • Real mode to protected mode transition with GDT setup
  • A20 enable sequence
  • Kernel load to physical address 0x8000
  • Boot signature 0xAA55

Kernel runtime

  • Kernel entry and low-level setup in kernel/core/entry.asm
  • IDT setup and PIC remap
  • PIT programmed for 100 Hz timer ticks
  • Assembly context switching via context_switch

Tasking and scheduling

  • Task model and lifecycle in kernel/core/task.c
  • Scheduler in kernel/core/scheduler.c
  • Preemptive, priority-based round-robin scheduling
  • 16 priority levels (0 through 15)
  • Tick-based sleeping with task_sleep

Memory management

  • Heap allocator in kernel/mm/memory.c
  • Best-fit allocation strategy
  • Block splitting and free-block coalescing
  • 8-byte alignment
  • Runtime usage stats via mem_get_total, mem_get_used, and mem_get_free

IPC

Console and shell

  • VGA text output and keyboard input in lib/io.c
  • Command shell in shell/shell.c
  • Built-in commands:
    • help
    • clear
    • meminfo
    • ps
    • echo
    • uname
    • test

Default Configuration

System defaults are defined in include/config.h:

  • MAX_TASKS: 32
  • TASK_STACK_SIZE: 4096 bytes
  • TIMER_FREQ_HZ: 100
  • TIME_SLICE_MS: 10
  • HEAP_SIZE: 1 MiB
  • MAX_PRIORITY: 15
  • QUEUE_SIZE: 16
  • SHELL_BUFFER_SIZE: 256

Build and Run

This project is built with GNU toolchain-style utilities (Makefile uses dd, rm, ls). Recommended environments:

  • Linux
  • WSL on Windows

Required tools:

  • nasm
  • gcc with 32-bit support
  • ld
  • objcopy
  • make
  • qemu-system-i386 (for emulation)

Build:

make

Run:

make run

Debug (QEMU gdb stub):

make debug

Optional build verification script:

./build.sh

Boot Flow

  1. BIOS loads MBR at 0x7C00.
  2. Bootloader in boot/boot.asm loads kernel sectors and enables protected mode.
  3. Kernel entry in kernel/core/entry.asm sets interrupt/timer hardware.
  4. Kernel main in kernel/core/main.c:
    • initializes heap
    • initializes scheduler
    • creates idle task (priority 0)
    • creates shell task (priority 5)
    • starts scheduler

Project Layout

Documentation

For deeper detail, see:

Known Limits (Current Codebase)

  • 32-bit x86 only
  • No user/kernel isolation
  • No virtual memory or paging subsystem
  • No filesystem or networking stack
  • Shell is minimal and command set is intentionally small

Extending the System

Typical extension points:

License

Provided for educational and development use.

About

32-bit protected-mode monolithic kernel. Preemptive scheduler (16 priority levels), custom paging, VFS, IPC. Sub-20KB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors