How theseus-os/theseus works
Purpose and entry points
Theseus is an experimental Rust OS focused on compiler-enforced resource management, fault recovery, and live runtime evolution. The primary developer entry point is make run, which builds a bootable image and launches QEMU; make ARCH=aarch64 run targets ARMv8. Build orchestration and target definitions reside in Makefile, cfg/Config.mk, and rust-toolchain.toml.
Boot and kernel composition
Boot begins in the architecture-specific nano-core, with BIOS and UEFI paths, assembly startup, linker scripts, and early runtime support in kernel/nano_core/src/lib.rs, kernel/nano_core/src/bios.rs, and kernel/nano_core/src/uefi.rs. Boot metadata is normalized through kernel/boot_info/src/lib.rs. Theseus is composed from many independently compiled Rust crates rather than a monolithic kernel binary; crate metadata and loading support are central to this model.
Initialization and dynamic module management
The root initialization path and first user-visible application are represented by kernel/root/src/lib.rs, kernel/captain/src/lib.rs, and kernel/first_application/src/lib.rs. Runtime crate discovery, metadata, loading, replacement, and serialization are handled across kernel/mod_mgmt/src/lib.rs, kernel/crate_metadata/src/lib.rs, and kernel/crate_swap/src/lib.rs. This is a key boundary: live evolution and fault recovery operate on crate/module units rather than conventional processes or shared libraries.
CPU, interrupts, tasks, and scheduling
Architecture abstraction separates x86_64 and AArch64 CPU, exception, interrupt-controller, and context-switch implementations: kernel/cpu/src/lib.rs, kernel/interrupt_controller/src/lib.rs, and kernel/context_switch_regular/src/lib.rs. Hardware interrupts feed task-oriented execution and deferred work. Core task lifecycle and scheduler integration live in kernel/task/src/lib.rs, with selectable scheduler implementations such as kernel/scheduler_round_robin/src/lib.rs and kernel/scheduler_priority/src/lib.rs. Synchronization, preemption, channels, and wait queues form the concurrency boundary.
Memory and allocation
Early initialization establishes architecture-specific virtual memory; general paging abstractions are in kernel/memory/src/lib.rs and kernel/memory/src/paging/mapper.rs, while platform implementations are split into kernel/memory_x86_64/src/lib.rs and kernel/memory_aarch64/src/lib.rs. Physical frames, pages, heaps, and slab allocation are distinct layers, represented by kernel/frame_allocator/src/lib.rs, kernel/page_allocator/src/lib.rs, and kernel/heap/src/lib.rs. These layers isolate unsafe hardware mapping and allocation policy from higher-level crates.
Devices, storage, networking, and UI
ACPI and PCI expose discovered platform devices to device management: kernel/acpi/src/lib.rs, kernel/pci/src/lib.rs, and kernel/device_manager/src/lib.rs. NIC drivers and queues feed the network stack, whose device/interface/socket boundary is in kernel/net/src/lib.rs, kernel/net/src/interface.rs, and kernel/net/src/socket.rs. Storage is surfaced through device/manager abstractions and filesystem nodes in kernel/storage_manager/src/lib.rs, kernel/vfs_node/src/lib.rs, and kernel/memfs/src/lib.rs. Console/TTY and framebuffer/window subsystems provide interactive output.
Applications, compatibility, and execution environments
Applications are Rust crates loaded into Theseus, including shell and system utilities in applications/shell/src/lib.rs, applications/hull/src/lib.rs, and applications/ls/src/lib.rs. Compatibility layers include a Theseus-oriented standard-library port at ports/theseus_std/src/lib.rs and C-library support at tlibc/src/lib.rs. WebAssembly execution is supported through applications/wasm/src/lib.rs and kernel/wasi_interpreter/src/lib.rs. Runtime validation primarily uses QEMU; supported deployment also includes real hardware, USB/PXE boot, and optional KVM acceleration.
Main entry points: src/lib.rs Root initialization · src/lib.rs Module management · src/lib.rs Tasks & scheduler · src/lib.rs Device manager
Components 22
Build & targets
- Make build orchestration · Builds bootable images and launches QEMU.
Makefile
Boot & composition
- Architecture nano-core · BIOS/UEFI entry, assembly startup, and early runtime.
kernel/nano_core/src/lib.rs - Boot metadata
kernel/boot_info/src/lib.rs - Root initialization
kernel/root/src/lib.rs - Captain
kernel/captain/src/lib.rs
Runtime evolution
- Module management · Discovers, loads, and manages independently compiled crates.
kernel/mod_mgmt/src/lib.rs - Crate metadata
kernel/crate_metadata/src/lib.rs - Crate swapping · Replaces and serializes crate/module units for recovery and upgrades.
kernel/crate_swap/src/lib.rs
CPU, tasks & memory
- CPU abstraction · Separates x86_64 and AArch64 CPU and exception support.
kernel/cpu/src/lib.rs - Interrupt controller
kernel/interrupt_controller/src/lib.rs - Context switching
kernel/context_switch_regular/src/lib.rs - Tasks & scheduler · Owns task lifecycle, preemption, deferred work, channels, and wait queues.
kernel/task/src/lib.rs - Paging abstractions · General mapping interface over architecture-specific paging.
kernel/memory/src/lib.rs - Frame allocator
kernel/frame_allocator/src/lib.rs - Heap allocator · Provides heap and slab allocation above page/frame layers.
kernel/heap/src/lib.rs
Devices & execution
- Device manager · Exposes ACPI/PCI-discovered platform devices.
kernel/device_manager/src/lib.rs - Network stack · Provides NIC, interface, and socket boundaries.
kernel/net/src/lib.rs - Storage manager
kernel/storage_manager/src/lib.rs - VFS nodes
kernel/vfs_node/src/lib.rs - WASI interpreter
kernel/wasi_interpreter/src/lib.rs
Applications & compatibility
- Shell
applications/shell/src/lib.rs - Theseus std port
ports/theseus_std/src/lib.rs
Connections 23
- Make build orchestration → Architecture nano-core: builds image with
- Architecture nano-core → Boot metadata: normalizes boot data
- Boot metadata → Root initialization: initializes
- Root initialization → Captain: starts
- Captain → Module management: loads crates through
- Module management → Crate metadata: uses
- Module management → Crate swapping: enables
- CPU abstraction → Interrupt controller: implements platform support for
- Interrupt controller → Tasks & scheduler: delivers deferred work to
- Context switching → Tasks & scheduler: switches
- Tasks & scheduler → Paging abstractions: uses address spaces
- Paging abstractions → Frame allocator: maps physical frames from
- Heap allocator → Paging abstractions: allocates pages through
- Root initialization → CPU abstraction: initializes
- Root initialization → Paging abstractions: establishes
- Module management → Shell: loads
- Shell → Theseus std port: uses
- Root initialization → Device manager: initializes
- Device manager → Network stack: provides NIC devices to
- Device manager → Storage manager: provides storage devices to
- Storage manager → VFS nodes: surfaces filesystem nodes through
- Module management → WASI interpreter: loads
- Tasks & scheduler → Device manager: coordinates driver work