Project Structure
This document provides a comprehensive overview of the SAGE OS project structure, explaining the role and purpose of each directory and key files.
๐ Root Directory Structure
SAGE-OS/
โโโ ๐ README.md # Project overview and quick start
โโโ ๐ LICENSE # BSD 3-Clause license
โโโ ๐ COMMERCIAL_TERMS.md # Commercial licensing terms
โโโ ๐ CONTRIBUTING.md # Contribution guidelines
โโโ ๐ SECURITY.md # Security policy and reporting
โโโ ๐ Cargo.toml # Rust workspace configuration
โโโ ๐ Makefile # Main build system
โโโ ๐ mkdocs.yml # Documentation configuration
โโโ ๐ .gitignore # Git ignore patterns
โโโ ๐ .gitattributes # Git attributes
โโโ ๐ฅพ bootloader/ # Bootloader implementation
โโโ ๐ง kernel/ # Kernel source code
โโโ ๐ฅ userspace/ # User space applications
โโโ ๐ง tools/ # Development and build tools
โโโ ๐ docs/ # Documentation source
โโโ ๐งช tests/ # Test suites
โโโ ๐ฆ scripts/ # Build and utility scripts
โโโ ๐๏ธ build/ # Build artifacts (generated)
โโโ ๐ dist/ # Distribution files (generated)
โโโ ๐ง .github/ # GitHub workflows and templates
๐ฅพ Bootloader (bootloader/
)
The bootloader directory contains the multi-stage boot process implementation.
bootloader/
โโโ ๐ Cargo.toml # Bootloader workspace
โโโ ๐ Makefile # Bootloader build system
โโโ ๐ง stage1/ # First stage bootloader
โ โโโ ๐ Cargo.toml # Stage 1 configuration
โ โโโ ๐ src/
โ โ โโโ ๐ main.rs # Stage 1 entry point
โ โ โโโ ๐ boot.s # Assembly boot code
โ โ โโโ ๐ lib.rs # Stage 1 library
โ โโโ ๐ linker.ld # Linker script
โโโ ๐ง stage2/ # Second stage bootloader
โ โโโ ๐ Cargo.toml # Stage 2 configuration
โ โโโ ๐ src/
โ โ โโโ ๐ main.rs # Stage 2 entry point
โ โ โโโ ๐ memory.rs # Memory detection
โ โ โโโ ๐ disk.rs # Disk I/O
โ โ โโโ ๐ elf.rs # ELF loader
โ โ โโโ ๐ graphics.rs # Graphics initialization
โ โโโ ๐ linker.ld # Linker script
โโโ ๐ง uefi/ # UEFI boot support
โ โโโ ๐ Cargo.toml # UEFI configuration
โ โโโ ๐ src/
โ โ โโโ ๐ main.rs # UEFI entry point
โ โ โโโ ๐ protocols.rs # UEFI protocols
โ โ โโโ ๐ services.rs # UEFI services
โ โโโ ๐ build.rs # Build script
โโโ ๐ง common/ # Shared bootloader code
โโโ ๐ Cargo.toml # Common library
โโโ ๐ src/
โโโ ๐ lib.rs # Common library
โโโ ๐ console.rs # Console output
โโโ ๐ memory_map.rs # Memory mapping
โโโ ๐ boot_info.rs # Boot information
Key Files
File | Purpose | Architecture Support |
---|---|---|
stage1/src/boot.s |
Initial assembly boot code | x86_64, ARM64 |
stage2/src/main.rs |
Extended bootloader logic | All |
uefi/src/main.rs |
UEFI boot implementation | x86_64, ARM64 |
common/src/boot_info.rs |
Boot information structure | All |
๐ง Kernel (kernel/
)
The kernel directory contains the core operating system implementation.
kernel/
โโโ ๐ Cargo.toml # Kernel workspace
โโโ ๐ Makefile # Kernel build system
โโโ ๐ src/
โ โโโ ๐ main.rs # Kernel entry point
โ โโโ ๐ lib.rs # Kernel library
โ โโโ ๐ panic.rs # Panic handler
โ โโโ ๐ allocator.rs # Memory allocator
โโโ ๐๏ธ arch/ # Architecture-specific code
โ โโโ ๐ง x86_64/ # x86_64 implementation
โ โ โโโ ๐ mod.rs # Architecture module
โ โ โโโ ๐ boot.rs # Boot initialization
โ โ โโโ ๐ interrupts.rs # Interrupt handling
โ โ โโโ ๐ memory.rs # Memory management
โ โ โโโ ๐ gdt.rs # Global Descriptor Table
โ โ โโโ ๐ idt.rs # Interrupt Descriptor Table
โ โ โโโ ๐ paging.rs # Page table management
โ โ โโโ ๐ syscalls.rs # System call interface
โ โโโ ๐ง aarch64/ # ARM64 implementation
โ โ โโโ ๐ mod.rs # Architecture module
โ โ โโโ ๐ boot.rs # Boot initialization
โ โ โโโ ๐ exceptions.rs # Exception handling
โ โ โโโ ๐ memory.rs # Memory management
โ โ โโโ ๐ mmu.rs # Memory Management Unit
โ โ โโโ ๐ syscalls.rs # System call interface
โ โโโ ๐ง riscv64/ # RISC-V implementation
โ โโโ ๐ mod.rs # Architecture module
โ โโโ ๐ boot.rs # Boot initialization
โ โโโ ๐ traps.rs # Trap handling
โ โโโ ๐ memory.rs # Memory management
โ โโโ ๐ paging.rs # Page table management
โ โโโ ๐ syscalls.rs # System call interface
โโโ ๐ง drivers/ # Device drivers
โ โโโ ๐ mod.rs # Driver module
โ โโโ ๐ console.rs # Console driver
โ โโโ ๐ keyboard.rs # Keyboard driver
โ โโโ ๐ mouse.rs # Mouse driver
โ โโโ ๐ storage.rs # Storage drivers
โ โโโ ๐ network.rs # Network drivers
โ โโโ ๐ graphics.rs # Graphics drivers
โ โโโ ๐ usb.rs # USB drivers
โโโ ๐ง fs/ # File system implementation
โ โโโ ๐ mod.rs # File system module
โ โโโ ๐ vfs.rs # Virtual File System
โ โโโ ๐ ext4.rs # EXT4 file system
โ โโโ ๐ fat32.rs # FAT32 file system
โ โโโ ๐ tmpfs.rs # Temporary file system
โ โโโ ๐ procfs.rs # Process file system
โโโ ๐ง mm/ # Memory management
โ โโโ ๐ mod.rs # Memory module
โ โโโ ๐ allocator.rs # Kernel allocator
โ โโโ ๐ vmm.rs # Virtual memory manager
โ โโโ ๐ pmm.rs # Physical memory manager
โ โโโ ๐ heap.rs # Heap management
โ โโโ ๐ slab.rs # Slab allocator
โโโ ๐ง proc/ # Process management
โ โโโ ๐ mod.rs # Process module
โ โโโ ๐ scheduler.rs # Process scheduler
โ โโโ ๐ task.rs # Task management
โ โโโ ๐ thread.rs # Thread management
โ โโโ ๐ ipc.rs # Inter-process communication
โ โโโ ๐ signal.rs # Signal handling
โโโ ๐ง net/ # Network stack
โ โโโ ๐ mod.rs # Network module
โ โโโ ๐ ethernet.rs # Ethernet protocol
โ โโโ ๐ ip.rs # IP protocol
โ โโโ ๐ tcp.rs # TCP protocol
โ โโโ ๐ udp.rs # UDP protocol
โ โโโ ๐ socket.rs # Socket interface
โโโ ๐ง sync/ # Synchronization primitives
โโโ ๐ mod.rs # Sync module
โโโ ๐ mutex.rs # Mutex implementation
โโโ ๐ rwlock.rs # Read-write lock
โโโ ๐ semaphore.rs # Semaphore
โโโ ๐ atomic.rs # Atomic operations
Architecture-Specific Code
Each architecture has its own subdirectory with platform-specific implementations:
=== "x86_64" - Boot: GRUB multiboot and UEFI support - Interrupts: IDT and interrupt handlers - Memory: Paging with 4-level page tables - System Calls: SYSCALL/SYSRET instructions
=== "ARM64" - Boot: Device tree and UEFI support - Exceptions: Exception level handling - Memory: ARMv8 MMU with translation tables - System Calls: SVC instruction
=== "RISC-V" - Boot: OpenSBI and device tree support - Traps: Supervisor trap handling - Memory: Sv48 virtual memory - System Calls: ECALL instruction
๐ฅ User Space (userspace/
)
User space applications and system services.
userspace/
โโโ ๐ Cargo.toml # Userspace workspace
โโโ ๐ง init/ # Init system
โ โโโ ๐ Cargo.toml # Init configuration
โ โโโ ๐ src/
โ โโโ ๐ main.rs # Init process
โ โโโ ๐ service.rs # Service management
โ โโโ ๐ config.rs # Configuration parser
โโโ ๐ง shell/ # Command shell
โ โโโ ๐ Cargo.toml # Shell configuration
โ โโโ ๐ src/
โ โโโ ๐ main.rs # Shell main
โ โโโ ๐ parser.rs # Command parser
โ โโโ ๐ builtins.rs # Built-in commands
โ โโโ ๐ history.rs # Command history
โโโ ๐ง utils/ # System utilities
โ โโโ ๐ ls/ # List directory
โ โโโ ๐ cat/ # Display file contents
โ โโโ ๐ cp/ # Copy files
โ โโโ ๐ mv/ # Move files
โ โโโ ๐ rm/ # Remove files
โ โโโ ๐ mkdir/ # Create directory
โ โโโ ๐ rmdir/ # Remove directory
โ โโโ ๐ ps/ # Process status
โ โโโ ๐ top/ # System monitor
โ โโโ ๐ mount/ # Mount file systems
โโโ ๐ง libs/ # User space libraries
โ โโโ ๐ libc/ # C standard library
โ โโโ ๐ libstd/ # Standard library
โ โโโ ๐ libsage/ # SAGE OS specific library
โโโ ๐ง apps/ # Applications
โโโ ๐ editor/ # Text editor
โโโ ๐ calculator/ # Calculator
โโโ ๐ file_manager/ # File manager
๐ง Tools (tools/
)
Development and build tools.
tools/
โโโ ๐ Cargo.toml # Tools workspace
โโโ ๐ง build-tools/ # Build utilities
โ โโโ ๐ iso-creator/ # ISO image creator
โ โโโ ๐ cross-compiler/ # Cross-compilation setup
โ โโโ ๐ qemu-runner/ # QEMU test runner
โโโ ๐ง debug-tools/ # Debugging utilities
โ โโโ ๐ gdb-scripts/ # GDB debugging scripts
โ โโโ ๐ memory-analyzer/ # Memory analysis tool
โ โโโ ๐ trace-viewer/ # Execution trace viewer
โโโ ๐ง dev-tools/ # Development utilities
โโโ ๐ code-formatter/ # Code formatting tool
โโโ ๐ license-checker/ # License compliance checker
โโโ ๐ doc-generator/ # Documentation generator
๐ Documentation (docs/
)
Documentation source files and assets.
docs/
โโโ ๐ index.md # Main documentation page
โโโ ๐ง getting-started/ # Getting started guides
โโโ ๐ง architecture/ # Architecture documentation
โโโ ๐ง components/ # Component documentation
โโโ ๐ง development/ # Development guides
โโโ ๐ง security/ # Security documentation
โโโ ๐ง files/ # File reference
โโโ ๐ง api/ # API documentation
โโโ ๐ง tutorials/ # Tutorials
โโโ ๐ง troubleshooting/ # Troubleshooting guides
โโโ ๐ง assets/ # Images and assets
โโโ ๐ง stylesheets/ # Custom CSS
โโโ ๐ง javascripts/ # Custom JavaScript
๐งช Tests (tests/
)
Test suites and testing infrastructure.
tests/
โโโ ๐ Cargo.toml # Test workspace
โโโ ๐ง unit/ # Unit tests
โโโ ๐ง integration/ # Integration tests
โโโ ๐ง system/ # System tests
โโโ ๐ง performance/ # Performance tests
โโโ ๐ง security/ # Security tests
โโโ ๐ง fixtures/ # Test fixtures and data
๐ฆ Scripts (scripts/
)
Build and utility scripts.
scripts/
โโโ ๐ build.sh # Main build script
โโโ ๐ create-iso.sh # ISO creation script
โโโ ๐ run-qemu.sh # QEMU execution script
โโโ ๐ setup-dev.sh # Development environment setup
โโโ ๐ cross-compile.sh # Cross-compilation script
โโโ ๐ test-runner.sh # Test execution script
โโโ ๐ deploy.sh # Deployment script
โโโ ๐ง ci/ # CI/CD scripts
โโโ ๐ build-matrix.sh # Multi-architecture build
โโโ ๐ security-scan.sh # Security scanning
โโโ ๐ deploy-docs.sh # Documentation deployment
๐ง GitHub Workflows (.github/
)
GitHub Actions workflows and templates.
.github/
โโโ ๐ง workflows/ # GitHub Actions workflows
โ โโโ ๐ ci.yml # Main CI/CD pipeline
โ โโโ ๐ license-headers.yml # License header checking
โ โโโ ๐ documentation.yml # Documentation generation
โ โโโ ๐ security-scan.yml # Security scanning
โ โโโ ๐ release.yml # Release automation
โโโ ๐ง ISSUE_TEMPLATE/ # Issue templates
โ โโโ ๐ bug_report.md # Bug report template
โ โโโ ๐ feature_request.md # Feature request template
โ โโโ ๐ security_report.md # Security report template
โโโ ๐ PULL_REQUEST_TEMPLATE.md # Pull request template
โโโ ๐ CODEOWNERS # Code ownership
โโโ ๐ apply-license-headers.py # License header application
๐๏ธ Build Artifacts (build/
and dist/
)
Generated directories containing build outputs.
build/ # Build artifacts (gitignored)
โโโ ๐ง x86_64/ # x86_64 build outputs
โโโ ๐ง aarch64/ # ARM64 build outputs
โโโ ๐ง riscv64/ # RISC-V build outputs
dist/ # Distribution files (gitignored)
โโโ ๐ sage-os-x86_64.iso # x86_64 ISO image
โโโ ๐ sage-os-aarch64.img # ARM64 disk image
โโโ ๐ sage-os-riscv64.img # RISC-V disk image
๐ Configuration Files
Root Configuration Files
File | Purpose | Format |
---|---|---|
Cargo.toml |
Rust workspace configuration | TOML |
Makefile |
Main build system | Makefile |
mkdocs.yml |
Documentation configuration | YAML |
.gitignore |
Git ignore patterns | Text |
.gitattributes |
Git attributes | Text |
Build Configuration
File | Purpose | Architecture |
---|---|---|
bootloader/*/linker.ld |
Linker scripts | Specific |
kernel/arch/*/memory.x |
Memory layout | Specific |
scripts/qemu-*.sh |
QEMU configurations | Specific |
๐ File Relationships
graph TD
A[Bootloader] --> B[Kernel]
B --> C[User Space]
D[Tools] --> A
D --> B
D --> C
E[Scripts] --> A
E --> B
E --> C
F[Tests] --> B
F --> C
G[Docs] --> H[All Components]
I[GitHub Workflows] --> J[CI/CD Pipeline]
J --> A
J --> B
J --> C
J --> F
๐ File Statistics
Component | Files | Lines of Code | Languages |
---|---|---|---|
Bootloader | ~50 | ~5,000 | Rust, Assembly |
Kernel | ~200 | ~25,000 | Rust, Assembly |
User Space | ~100 | ~10,000 | Rust, C |
Tools | ~30 | ~3,000 | Rust, Shell |
Documentation | ~50 | ~15,000 | Markdown |
Tests | ~80 | ~8,000 | Rust |
Scripts | ~20 | ~2,000 | Shell, Python |
๐ฏ Key Design Principles
- Modularity: Clear separation of concerns
- Architecture Independence: Common interfaces across platforms
- Security: Secure coding practices throughout
- Testing: Comprehensive test coverage
- Documentation: Extensive documentation for all components
- Maintainability: Clean, readable code structure
๐ File Naming Conventions
- Rust files:
snake_case.rs
- Assembly files:
snake_case.s
orsnake_case.asm
- Documentation:
kebab-case.md
- Scripts:
kebab-case.sh
orsnake_case.py
- Configuration:
kebab-case.yml
orsnake_case.toml