milo

01 — Architecture Overview

Milo is a freestanding C++20 microkernel built for AArch64 (cortex-a53 compilation target, QEMU virt cortex-a57 runtime platform) with an architecture-agnostic Hardware Abstraction Layer (kernel/hal/) and a Linux AArch64 (LP64) system-call ABI layer (kernel/uapi/, kernel/syscalls/).

Microkernel Philosophy & Trusted Computing Base (TCB)

Milo enforces a strict separation between architecture/target code (arch/aarch64-linux-gnu/, kernel/hal/targets/qemu_virt/), portable freestanding kernel subsystems (kernel/), and unprivileged user-space processes (EL0). All kernel C++ code compiles with -std=c++20 -ffreestanding -fno-exceptions -fno-rtti -fno-threadsafe-statics, using RAII ownership (Kernel::Sync::IrqGuard, Kernel::FS::RefPtr, Kernel::Process::FdTable) and deterministic static/page-backed allocators.

Privilege Boundaries (EL1 vs. EL0)

Privilege Level Scope & Responsibilities Key Components
Kernel Space (EL1, TTBR1_EL1 + kernel TTBR0_EL1 mappings) Trusted Computing Base (TCB): exception vectors, MMU/page-table isolation, physical frame & slab/compound heap allocation, preemptive scheduling, signals, svc #0 syscall dispatch, VFS, IPC (Pipe, AF_UNIX), ELF64 loader, interactive milo> diagnostics shell, and in-tree board/VirtIO drivers. arch/aarch64-linux-gnu/*, kernel/main.cpp, kernel/mm/*, kernel/process/*, kernel/syscalls/*, kernel/ipc/*, kernel/net/*, kernel/fs/*, kernel/loader/*, kernel/drivers/*, kernel/hal/*, kernel/shell/*
User Space (EL0, isolated per-process TTBR0_EL1) Unprivileged applications, shells (/bin/sh via BusyBox or /bin/bash), dynamic linker (/lib/ld-musl-aarch64.so.1 + /lib/libc.so), and smoke/test binaries (user/*.s, user/*.c). Cannot access EL1 system registers, kernel higher-half memory, or raw MMIO; interacts with the kernel strictly via svc #0, file descriptors, devfs nodes (/dev/console, /dev/tty, /dev/null, /dev/fb0, /dev/input/event<N>), pipes, and AF_UNIX sockets. user/*, initrds/busybox.cpio, initrds/bash.cpio
Host Verification Harness (HOST_TEST, native x86_64/host) Hardware-independent kernel subsystems compiled natively with host g++, ASan/UBSan, snitch, and gcovr against deterministic HAL mocks (tests/host/mocks/host_hal.{hpp,cpp}), bypassing arch/aarch64-linux-gnu/ assembly. tests/host/*

Architecture Status ([WIP] / Roadmap Note): Core hardware drivers (GicV2, Pl011Uart, FwCfgDevice, RamfbDevice, and VirtIO-MMIO block/net/gpu/input) and filesystems (rootfs, tmpfs, devfs, ext2) currently execute inside EL1 behind the portable HAL boundary rather than as isolated EL0 driver servers. A decoupled Driver Development Kit (include/ddk/) and out-of-tree driver isolation are planned on the roadmap (see docs/reference.md).

System Block Diagram

flowchart TB
    subgraph EL0["User Space (EL0 — Isolated per-process TTBR0_EL1)"]
        SHELLS["Interactive Shells (/bin/sh, /bin/bash)"]
        BINS["EL0 Binaries & Musl Payloads (user/*, ld-musl)"]
    end

    subgraph TRAP["Privilege & ABI Boundary"]
        SVC["svc #0 Syscall Trap & Signal Delivery (boot.s, trap_aarch64.cpp)"]
        DISP["SyscallDispatcher (84 Linux AArch64 Syscalls, kernel/uapi/*)"]
    end

    subgraph KERN["Portable Freestanding C++20 Kernel Core (EL1)"]
        PROC["Process, Scheduler, WaitQueue, SignalTable, FdTable (kernel/process/)"]
        MM["PageFrameAllocator, KernelHeap, AddressSpace & VMA (kernel/mm/)"]
        LOAD["Elf64View & load_elf / PT_INTERP Loader (kernel/loader/)"]
        IPC["Pipe Ring Buffers & AF_UNIX Sockets (kernel/ipc/, kernel/net/)"]
        VFS["VFS, PageCache, rootfs, tmpfs, devfs, ext2 (kernel/fs/)"]
        KSHELL["Interactive milo> Kernel Shell & EL0 Test Suites (kernel/shell/)"]
    end

    subgraph HAL_LAYER["Hardware Abstraction Layer (kernel/hal/)"]
        HAL_IF["HAL::CpuControl, HAL::MemoryControl, HAL::AddressSpaceBackend, HAL::Console, HAL::Platform"]
    end

    subgraph BACKENDS["Target & Host Backends"]
        ARCH["AArch64 Arch Backend (arch/aarch64-linux-gnu/*)"]
        QEMU["QEMU virt Target & In-Tree Drivers (kernel/hal/targets/qemu_virt/, kernel/drivers/)"]
        MOCK["Host Test HAL Mocks (tests/host/mocks/host_hal.{hpp,cpp})"]
    end

    SHELLS --> SVC
    BINS --> SVC
    SVC --> DISP
    DISP --> PROC
    DISP --> MM
    DISP --> IPC
    DISP --> VFS
    PROC --> LOAD
    LOAD --> MM
    VFS --> MM
    KSHELL --> PROC
    KSHELL --> VFS

    PROC --> HAL_IF
    MM --> HAL_IF
    IPC --> HAL_IF
    VFS --> HAL_IF
    KSHELL --> HAL_IF

    HAL_IF --> ARCH
    HAL_IF --> QEMU
    HAL_IF -. "HOST_TEST builds" .-> MOCK

Directory-to-Subsystem Mapping

Path Subsystem Key Files & Responsibilities
arch/aarch64-linux-gnu/ AArch64 Architecture Backend boot.s (_start, vector_table, cpu_switch_context, user_trap_exit), linker.ld, memory_config.hpp, cpu_context.hpp, cpu.cpp (AArch64CpuControl, PlatformInfo), mmu_aarch64.cpp (4-level TTBR0/TTBR1, CoW, demand-zero), trap_aarch64.cpp (sync/IRQ/abort dispatch), uart_console.cpp, arch_test.cpp, user_test.s, arch.mk.
kernel/main.cpp Kernel Entry & Bring-Up kmain(uintptr_t dtb_paddr) orchestrating console, .init_array, FDT, PFA, MMU, heap, VFS mounts, GICv2/timer/scheduler, VirtIO/fw_cfg/ramfb, ext2, and shell handoff.
kernel/boot/ Flattened Device Tree (FDT) fdt.{hpp,cpp}: DTB validation, usable RAM bank discovery, /memreserve/ carveouts, linux,initrd-* bounds, virtio,mmio and qemu,fw-cfg-mmio node parsing.
kernel/core/ Core Primitives & Logging traits.hpp (freestanding type traits), log.{hpp,cpp} (Kernel::Log leveled console logger).
kernel/hal/ Portable HAL & Board Targets cpu.hpp, mmu.hpp, console.hpp, trap.hpp, platform.hpp, test_hooks.hpp, plus QEMU virt target glue under kernel/hal/targets/qemu_virt/ (platform_{board,block,gpu,input,net}.cpp, timer.{hpp,cpp}, gicv2.hpp, fw_cfg.hpp; pl001.cpp is an empty [WIP] stub).
kernel/mm/ Memory Management pfa.{hpp,cpp} (Page, PageFrameAllocator with atomic refcounts), heap.{hpp,cpp} (KernelHeap 8-class slab + compound allocator), AddressSpace.{hpp,cpp} (VMAs, file-backed fault resolution, copy_from_user/copy_to_user).
kernel/process/ Tasks, Scheduling & Signals Process.{hpp,cpp}, scheduler.{hpp,cpp} (Runqueue, round-robin tick scheduler), wait_queue.{hpp,cpp}, FdTable.{hpp,cpp}, FileDescriptor.hpp, Signal.{hpp,cpp}, stack_builder.{hpp,cpp}, resource.{hpp,cpp}.
kernel/syscalls/ Linux AArch64 Syscall Layer SyscallDispatcher.cpp (84 syscalls), SyscallInternal.hpp, SyscallHelpers.cpp, and domain handlers: FileSyscalls.cpp, MemorySyscalls.cpp, ProcessSyscalls.cpp, SignalSyscalls.cpp, SocketSyscalls.cpp, TimeSyscalls.cpp.
kernel/uapi/ Linux ABI Definitions Compile-time verified C-compatible headers (errno.hpp, fb.hpp, fs.hpp, input.hpp, signal.hpp, socket.hpp, sys.hpp, termios.hpp, time.hpp).
kernel/fs/ Virtual File System & FS Drivers Vfs.{hpp,cpp}, VfsTypes.hpp, Inode.hpp, Dentry.hpp, File.hpp, Mount.hpp, Superblock.hpp, PageCache.{hpp,cpp}, cpio.{hpp,cpp}, plus rootfs/, tmpfs/, devfs/ (TTY, console, null, /dev/fb0, /dev/input/event<N>), and ext2/.
kernel/ipc/ Inter-Process Communication Pipe.{hpp,cpp}: 4 KiB ring buffer pipes with WaitQueue blocking, SIGPIPE, and poll() support.
kernel/net/ Networking & Local Sockets NetworkDevice.hpp abstract NIC interface and af_unix.{hpp,cpp} (UnixSocket SOCK_STREAM/SOCK_DGRAM engine bound to VFS S_IFSOCK inodes).
kernel/loader/ Executable Loader elf64.{hpp,cpp} (Elf64View) and elf_loader.{hpp,cpp} (load_elf, load_elf_interpreter for static, PIE, and PT_INTERP binaries).
kernel/drivers/ Hardware & VirtIO Drivers irq/gicv2.{hpp,cpp}, uart/pl011.{hpp,cpp}, firmware/fw_cfg.{hpp,cpp}, video/{framebuffer,ramfb}.{hpp,cpp}, block/block_device.hpp, and virtio/ (SplitVirtqueue, VirtioMmioTransport, VirtioMmioBus, virtio_{blk,gpu,input,net}).
kernel/input/ Input Subsystem InputEvent.hpp and InputQueue.{hpp,cpp} (256-event ring buffer with WaitQueue backing /dev/input/event<N>).
kernel/sync/ & kernel/time/ & kernel/runtime/ Synchronization, Time & C++ ABI sync/IrqGuard.hpp (RAII IRQ mask guard), time/Duration.hpp, and runtime/cxx_abi.cpp (freestanding operator new/delete and C++ ABI hooks).
kernel/shell/ Kernel Shell & On-Target Tests shell.{hpp,cpp} (milo> interactive console) and tests/test_*.cpp (40+ on-target hardware, MMU, VFS, IPC, and EL0 test suites).
user/ EL0 Sample & Smoke Payloads hello.s, hello_musl.c, hello_dyn.c, fb_test.c, evdev_smoke.c, unix_echo_server.c, unix_echo_client.c, unix_sock_smoke.c packaged into initrds by Makefile.
tests/host/ Host-Native Unit Tests mocks/host_hal.{hpp,cpp} and 24 snitch test suites (*_test.cpp) executed natively under ASan/UBSan and gcovr.
scripts/ & Makefile Build & Quality Automation Top-level Makefile, kernel/kernel.mk, arch/aarch64-linux-gnu/arch.mk, and helper scripts (check_license_headers.py, generate_compile_commands.py, generate_quality_report.py, count_loc.py, ai_dump.py).