Introduction
Portix OS is a bare-metal x86_64 kernel written in Rust, designed to boot directly on hardware without relying on an external bootloader or operating system. The kernel demonstrates modern OS development practices including custom memory management, interrupt handling, and a complete driver stack.Portix OS v0.7.4 is a monolithic kernel that boots from BIOS, transitions through multiple CPU modes, and runs entirely in 64-bit long mode.
High-Level Architecture
The system follows a layered architecture:Directory Structure
The kernel source code is organized into logical modules:boot/
boot/
Bootloader components written in x86 assembly:
boot.asm- Stage 1 bootloader (512 bytes, MBR)stage2.asm- Stage 2 bootloader (handles mode transitions)
kernel/src/arch/
kernel/src/arch/
Architecture-specific code for x86_64:
idt.rs- Interrupt Descriptor Table setupisr_handlers.rs- Interrupt Service Routinesisr.asm- Low-level ISR stubshardware.rs- CPU detection and features
kernel/src/mem/
kernel/src/mem/
Memory management subsystem:
allocator.rs- Buddy system allocator (O(log N))- Implements Rust’s
GlobalAlloctrait - Manages heap from 0x400000 with configurable size
kernel/src/drivers/
kernel/src/drivers/
Device drivers:
input/keyboard.rs- PS/2 keyboard driverinput/mouse.rs- PS/2 mouse with scrollwheelstorage/ata.rs- ATA/IDE disk driverstorage/fat32.rs- FAT32 filesystemserial.rs- COM1 serial port (debugging)bus/pci.rs- PCI bus enumeration
kernel/src/graphics/
kernel/src/graphics/
Framebuffer graphics:
driver/framebuffer.rs- VESA mode setupfont.rs- Bitmap font rendering (8x14)- Double-buffered rendering at 30 Hz
kernel/src/console/
kernel/src/console/
Terminal and command system:
terminal/mod.rs- Line-based terminalterminal/commands/- Built-in commandsterminal/editor.rs- Text editor
kernel/src/ui/
kernel/src/ui/
User interface components:
tabs/system.rs- System information tabtabs/ide.rs- Integrated development environmenttabs/explorer.rs- File browser- Chrome and navigation UI
Module Organization
The kernel’smain.rs declares the module hierarchy:
kernel/src/main.rs
Component Interaction
Here’s how the major components interact during runtime:All components run in kernel mode (ring 0) with full hardware access. There is no user/kernel mode separation in the current design.
Initialization Sequence
The kernel follows a strict initialization order inrust_main() (main.rs:192):
Boot Protocol
Portix OS uses a two-stage bootloader:- Stage 1 (
boot.asm) - Loaded by BIOS at 0x7C00, loads Stage 2 - Stage 2 (
stage2.asm) - Switches to long mode, loads kernel - Kernel - Rust entry point at
rust_main()
Memory Layout
| Address Range | Usage |
|---|---|
0x0000 - 0x0FFF | Real mode IVT (preserved) |
0x1000 - 0x4FFF | Page tables (PML4, PDPT, PD) |
0x6000 - 0x6FFF | VESA info buffer |
0x7C00 - 0x7DFF | Stage 1 bootloader |
0x8000 - 0xFFFF | Stage 2 bootloader |
0x9000 - 0x9FFF | Boot info structure |
0x10000+ | Kernel binary |
0x400000+ | Heap (managed by buddy allocator) |
0x600000+ | Double-buffer for framebuffer |
Design Philosophy
No Dependencies
Completely
no_std - no standard library, libc, or external runtimeBare Metal
Direct hardware access, no hypervisor or firmware dependencies beyond BIOS
Safety First
Rust’s type system prevents many common OS bugs, with
unsafe only where neededReal Hardware
Designed to boot on real x86_64 hardware (VirtualBox, QEMU, physical machines)
Next Steps
Boot Process
Learn how Portix OS transitions from BIOS to 64-bit mode
Memory Management
Explore the buddy allocator and heap management
Interrupt Handling
Understand how interrupts and exceptions are processed