Documentation
ARBOS is a 32-bit x86 operating system built from scratch, designed to run on real hardware or emulators like QEMU. It includes essential OS components such as:
- Bootloader (Multiboot-compliant)
- Memory Management (PMM & Paging)
- Interrupt Handling (IDT, PIC, Exceptions, IRQs)
- Process Scheduling (Basic Round-Robin Scheduler)
- System Calls (Syscall Interface)
- Device Drivers (Keyboard, VGA, Timer)
This document explains the key components and their functionality step-by-step.
- The OS boots using a Multiboot-compliant bootloader.
- The bootloader:
- Sets up a stack for the kernel.
- Calls
idt_setup()to initialize interrupts. - Jumps to the kernel’s
kmain()function.
- Initializes core OS components:
- Physical Memory Manager (PMM)
- Paging (Virtual Memory)
- Timer (PIT)
- Task Scheduler
- Creates two test tasks (
task_a()andtask_b()) and starts the scheduler.
- Tracks free and used memory pages (4KB each).
- Uses a bitmap to manage allocations.
- Key Functions:
pmm_init(): Marks low memory (0-1MB) and kernel space as used.pmm_alloc_page(): Allocates a free page.pmm_free_page(): Releases a page back to the free pool.
- Implements identity paging (maps physical addresses 1:1 to virtual).
- Sets up a Page Directory (PD) and Page Tables (PT).
- Enables paging by setting the CR0 and CR3 registers.
- The IDT defines how the CPU handles interrupts.
idt_setup():- Configures exception handlers (ISRs 0-31).
- Remaps the PIC (Programmable Interrupt Controller) to avoid conflicts.
- Sets up IRQ handlers (Timer, Keyboard).
- Configures Syscall handler (int 0x80).
- Handles CPU exceptions (e.g., Divide Error, Page Fault).
- Prints debug info (exception number, error code).
-
Timer (
kernel/timer.c)- Uses the PIT (Programmable Interval Timer).
init_timer(): Sets the timer frequency (e.g., 100Hz).timer_handler(): Increments a tick counter.
-
Keyboard (
drivers/keyboard.c)- Reads scancodes from PS/2 keyboard.
- Converts scancodes to ASCII and prints them via VGA.
- Each task has:
- PID (Process ID)
- State (Running, Ready, Blocked, etc.)
- Stack Pointer (Saved ESP)
- Stack Page (4KB allocated memory)
- Round-Robin Scheduling: Tasks yield CPU voluntarily.
- Key Functions:
task_create(): Allocates a stack and initializes a task.task_yield(): Switches to the next ready task.scheduler_start(): Begins task execution.
- Saves CPU registers of the current task.
- Loads registers of the next task.
- Uses
pushad/popadfor register preservation.
int 0x80triggers a syscall.- Syscall Numbers:
SYS_WRITE(1): Writes data to the screen.SYS_GET_TICKS(2): Returns timer ticks.
- The syscall stub forwards arguments to
syscall_handler_regparm(). - Return values are stored in
syscall_ret.
- Writes text to 0xB8000 (VGA buffer).
- Functions:
vga_putc(): Prints a character.vga_puts(): Prints a string.vga_clear(): Clears the screen.
- IRQ1 handler reads scancodes from port 0x60.
- Converts scancodes to ASCII (simplified mapping).
- Uses NASM for assembly files.
- Uses Clang for C files (cross-compiled for
i686-elf). - Links objects into
kernel.bin.
qemu-system-i386 -kernel dist/kernel.bin- Boots the OS in QEMU with keyboard support.
- User-mode separation (Ring 3).
- File system support.
- Dynamic memory allocation (Heap management).
- Multi-core CPU support.
- Better shell/command interface.
ARBOS is a simple but functional 32-bit OS with:
✔ Bootloader
✔ Memory Management
✔ Interrupts & Syscalls
✔ Task Scheduling
✔ Basic Drivers