Skip to content

Architecture Overview

SAGE OS is designed with a modern, modular architecture that prioritizes security, performance, and multi-platform support. This document provides a comprehensive overview of the system architecture.

🏛ïļ System Architecture

graph TB
    subgraph "User Space"
        A[Applications]
        B[System Services]
        C[Standard Libraries]
        D[SAGE Libraries]
    end

    subgraph "Kernel Space"
        E[System Call Interface]
        F[Process Manager]
        G[Memory Manager]
        H[File System]
        I[Device Drivers]
        J[Network Stack]
        K[Security Manager]
    end

    subgraph "Hardware Abstraction Layer"
        L[Architecture Interface]
        M[Platform Drivers]
        N[Boot Interface]
    end

    subgraph "Hardware"
        O[CPU]
        P[Memory]
        Q[Storage]
        R[Network]
        S[Peripherals]
    end

    A --> E
    B --> E
    C --> E
    D --> E
    E --> F
    E --> G
    E --> H
    E --> K
    F --> I
    G --> I
    H --> I
    I --> L
    J --> L
    L --> M
    M --> N
    N --> O
    N --> P
    N --> Q
    N --> R
    N --> S

ðŸŽŊ Design Principles

1. Security First

  • Memory Safety: Built with Rust to prevent buffer overflows and memory corruption
  • Principle of Least Privilege: Minimal permissions for all components
  • Isolation: Strong process and memory isolation
  • Secure Boot: Hardware-backed boot chain verification

2. Multi-Architecture Support

  • Unified Codebase: Single codebase supporting multiple architectures
  • Architecture Abstraction: Clean separation between generic and platform-specific code
  • Cross-Compilation: Seamless building for different target platforms

3. Modularity

  • Microkernel Influence: Modular design with clear interfaces
  • Plugin Architecture: Loadable drivers and modules
  • Service Orientation: System services as separate processes

4. Performance

  • Zero-Copy I/O: Efficient data handling without unnecessary copying
  • NUMA Awareness: Optimized for modern multi-core systems
  • Real-Time Support: Low-latency scheduling capabilities

🧠 Kernel Architecture

Core Components

classDiagram
    class Kernel {
        +init()
        +main_loop()
        +shutdown()
    }

    class ProcessManager {
        +create_process()
        +schedule()
        +terminate_process()
        +handle_signals()
    }

    class MemoryManager {
        +allocate_pages()
        +map_memory()
        +handle_page_fault()
        +garbage_collect()
    }

    class FileSystem {
        +mount()
        +open()
        +read()
        +write()
        +close()
    }

    class DeviceManager {
        +register_driver()
        +handle_interrupt()
        +device_io()
    }

    class NetworkStack {
        +send_packet()
        +receive_packet()
        +socket_operations()
    }

    Kernel --> ProcessManager
    Kernel --> MemoryManager
    Kernel --> FileSystem
    Kernel --> DeviceManager
    Kernel --> NetworkStack

Memory Layout

graph TD
    subgraph "Virtual Memory Space"
        A[User Space<br/>0x0000_0000_0000_0000 - 0x0000_7FFF_FFFF_FFFF]
        B[Kernel Space<br/>0xFFFF_8000_0000_0000 - 0xFFFF_FFFF_FFFF_FFFF]
    end

    subgraph "Kernel Space Details"
        C[Kernel Code<br/>0xFFFF_8000_0000_0000]
        D[Kernel Data<br/>0xFFFF_8000_1000_0000]
        E[Kernel Heap<br/>0xFFFF_8000_2000_0000]
        F[Device Memory<br/>0xFFFF_8000_F000_0000]
        G[Temporary Mappings<br/>0xFFFF_FFFF_F000_0000]
    end

    B --> C
    B --> D
    B --> E
    B --> F
    B --> G

ðŸĨū Boot Process

The SAGE OS boot process is designed to be secure and efficient across all supported architectures.

sequenceDiagram
    participant BIOS as BIOS/UEFI
    participant Stage1 as Stage 1 Bootloader
    participant Stage2 as Stage 2 Bootloader
    participant Kernel as Kernel
    participant Init as Init Process

    BIOS->>Stage1: Load and execute
    Stage1->>Stage1: Initialize basic hardware
    Stage1->>Stage2: Load stage 2
    Stage2->>Stage2: Setup memory map
    Stage2->>Stage2: Load kernel
    Stage2->>Kernel: Jump to kernel entry
    Kernel->>Kernel: Initialize subsystems
    Kernel->>Init: Start init process
    Init->>Init: Start system services

Boot Stages

  1. Stage 1 Bootloader
  2. Minimal assembly code
  3. Hardware initialization
  4. Load Stage 2 from disk

  5. Stage 2 Bootloader

  6. Memory detection and mapping
  7. File system access
  8. Kernel loading and verification
  9. Graphics mode setup

  10. Kernel Initialization

  11. Architecture-specific setup
  12. Memory manager initialization
  13. Device driver loading
  14. Process manager startup

  15. User Space Initialization

  16. Init process creation
  17. System service startup
  18. User environment setup

🔧 System Call Interface

SAGE OS provides a clean, efficient system call interface for user space applications.

graph LR
    A[User Application] --> B[System Call Wrapper]
    B --> C[System Call Handler]
    C --> D[Kernel Function]
    D --> E[Hardware Operation]
    E --> D
    D --> C
    C --> B
    B --> A

System Call Categories

Category Examples Purpose
Process Management fork, exec, exit, wait Process lifecycle
Memory Management mmap, munmap, brk Memory allocation
File Operations open, read, write, close File I/O
Network Operations socket, bind, listen, accept Network communication
Device Control ioctl, select, poll Device interaction
Time Management clock_gettime, nanosleep Time operations

System Call Implementation

=== "x86_64"

// System call entry point
#[naked]
unsafe extern "C" fn syscall_entry() {
    asm!(
        "swapgs",
        "mov gs:0x10, rsp",  // Save user stack
        "mov rsp, gs:0x08",  // Load kernel stack
        "push rax",          // Save syscall number
        "call syscall_handler",
        "pop rax",
        "mov rsp, gs:0x10",  // Restore user stack
        "swapgs",
        "sysretq",
        options(noreturn)
    );
}

=== "ARM64"

// System call entry point
#[naked]
unsafe extern "C" fn syscall_entry() {
    asm!(
        "stp x29, x30, [sp, #-16]!",
        "mov x29, sp",
        "bl syscall_handler",
        "ldp x29, x30, [sp], #16",
        "eret",
        options(noreturn)
    );
}

=== "RISC-V"

// System call entry point
#[naked]
unsafe extern "C" fn syscall_entry() {
    asm!(
        "addi sp, sp, -16",
        "sd ra, 8(sp)",
        "sd fp, 0(sp)",
        "call syscall_handler",
        "ld ra, 8(sp)",
        "ld fp, 0(sp)",
        "addi sp, sp, 16",
        "sret",
        options(noreturn)
    );
}

ðŸ’ū Memory Management

SAGE OS implements a sophisticated memory management system with support for virtual memory, paging, and memory protection.

Virtual Memory Manager

graph TD
    A[Virtual Memory Manager] --> B[Page Allocator]
    A --> C[Address Space Manager]
    A --> D[Page Fault Handler]

    B --> E[Physical Page Frames]
    C --> F[Page Tables]
    D --> G[Swap Manager]

    F --> H[Hardware MMU]
    G --> I[Storage Device]

Memory Allocation Hierarchy

  1. Physical Memory Manager
  2. Manages physical page frames
  3. Buddy allocator for large allocations
  4. Slab allocator for small objects

  5. Virtual Memory Manager

  6. Manages virtual address spaces
  7. Page table management
  8. Memory mapping and protection

  9. Kernel Heap

  10. Dynamic memory allocation for kernel
  11. Multiple allocation strategies
  12. Memory leak detection

  13. User Space Allocator

  14. User space memory allocation
  15. Memory-mapped files
  16. Shared memory regions

📁 File System Architecture

SAGE OS supports multiple file systems through a Virtual File System (VFS) layer.

graph TD
    A[Application] --> B[VFS Layer]
    B --> C[EXT4]
    B --> D[FAT32]
    B --> E[TmpFS]
    B --> F[ProcFS]

    C --> G[Block Device]
    D --> G
    E --> H[Memory]
    F --> I[Kernel Data]

Supported File Systems

File System Type Features Use Case
EXT4 Disk-based Journaling, large files Primary storage
FAT32 Disk-based Cross-platform compatibility Boot partition
TmpFS Memory-based High performance Temporary files
ProcFS Virtual Kernel information System monitoring
DevFS Virtual Device files Device access

🔌 Device Driver Architecture

SAGE OS uses a modular driver architecture that supports both static and dynamic loading.

graph TD
    A[Device Manager] --> B[Driver Registry]
    B --> C[PCI Driver]
    B --> D[USB Driver]
    B --> E[Network Driver]
    B --> F[Storage Driver]

    C --> G[PCI Bus]
    D --> H[USB Controller]
    E --> I[Network Interface]
    F --> J[Storage Controller]

Driver Types

  1. Bus Drivers
  2. PCI, USB, I2C, SPI
  3. Device enumeration
  4. Power management

  5. Class Drivers

  6. Storage, network, input
  7. Common functionality
  8. Standard interfaces

  9. Function Drivers

  10. Specific device support
  11. Hardware abstraction
  12. Performance optimization

🌐 Network Stack

SAGE OS implements a full TCP/IP network stack with support for modern networking features.

graph TD
    A[Socket API] --> B[Transport Layer]
    B --> C[TCP]
    B --> D[UDP]
    C --> E[Network Layer]
    D --> E
    E --> F[IP]
    F --> G[Link Layer]
    G --> H[Ethernet]
    G --> I[WiFi]
    H --> J[Network Driver]
    I --> J

Network Features

  • IPv4/IPv6 Support: Dual-stack networking
  • TCP/UDP Protocols: Reliable and unreliable transport
  • Socket Interface: POSIX-compatible API
  • Packet Filtering: Firewall and traffic shaping
  • Quality of Service: Traffic prioritization

🔒 Security Architecture

Security is integrated throughout the SAGE OS architecture.

graph TD
    A[Security Manager] --> B[Access Control]
    A --> C[Cryptography]
    A --> D[Secure Boot]
    A --> E[Audit System]

    B --> F[Capabilities]
    B --> G[Mandatory Access Control]
    C --> H[Hardware Crypto]
    D --> I[TPM]
    E --> J[Log System]

Security Features

  1. Memory Protection
  2. Address Space Layout Randomization (ASLR)
  3. Data Execution Prevention (DEP)
  4. Stack canaries and guards

  5. Access Control

  6. Capability-based security
  7. Mandatory Access Control (MAC)
  8. Role-based permissions

  9. Cryptography

  10. Hardware-accelerated crypto
  11. Secure key storage
  12. Certificate management

  13. Audit and Monitoring

  14. System call auditing
  15. Security event logging
  16. Intrusion detection

🏗ïļ Multi-Architecture Support

SAGE OS is designed to run on multiple processor architectures with a unified codebase.

Architecture Abstraction

graph TD
    A[Generic Kernel Code] --> B[Architecture Interface]
    B --> C[x86_64 Implementation]
    B --> D[ARM64 Implementation]
    B --> E[RISC-V Implementation]

    C --> F[Intel/AMD Processors]
    D --> G[ARM Processors]
    E --> H[RISC-V Processors]

Platform-Specific Features

=== "x86_64" - CPUID: Feature detection - MSRs: Model-specific registers - APIC: Advanced interrupt controller - VMX: Virtualization extensions

=== "ARM64" - Device Tree: Hardware description - GIC: Generic interrupt controller - SMMU: System MMU - TrustZone: Security extensions

=== "RISC-V" - Hart: Hardware thread support - PLIC: Platform interrupt controller - SBI: Supervisor binary interface - Extensions: Modular ISA extensions

📊 Performance Characteristics

Benchmarks

Metric x86_64 ARM64 RISC-V
Boot Time 2.5s 3.1s 3.8s
Context Switch 0.8Ξs 1.2Ξs 1.5Ξs
System Call 0.3Ξs 0.4Ξs 0.5Ξs
Memory Bandwidth 95% 92% 88%

Optimization Strategies

  1. Compiler Optimizations
  2. Link-time optimization (LTO)
  3. Profile-guided optimization (PGO)
  4. Architecture-specific tuning

  5. Runtime Optimizations

  6. CPU cache optimization
  7. NUMA-aware scheduling
  8. Lock-free data structures

  9. Memory Optimizations

  10. Page size optimization
  11. Memory prefetching
  12. Compression algorithms