Skip to content
lxePublic

About

A from-scratch, no_std x86_64 Linux-ABI-compatible OS kernel in Rust

Resources

Stars

77 stars

Watchers

1 watching

Forks

Repository files navigation

Ferrite

A from-scratch, no_std x86_64 Linux-ABI-compatible operating system kernel written in Rust (~25k lines of Rust including the UEFI bootloader).

Ferrite runs unmodified Linux x86_64 userspace binaries — zsh, curl, rustc/cargo (self-hosting its own release kernel), Sway + kitty + btop + fastfetch + Mesa llvmpipe, aplay, lsusb, and evtest — while stripping out decades of legacy x86 hardware and kernel baggage.

Ferrite booting from framebuffer console into stock Sway 1.12, Kitty (fastfetch + live HTTPS curl), btop, and Mesa llvmpipe 3D gears


Priorities & Design Philosophy

  1. Modern Linux x86_64 ABI, no legacy cruft. Binary compatibility with x86_64-unknown-linux-gnu and -musl means standard Linux compilers, shells, Wayland compositors, audio tools, and closed userspace libraries run unmodified without a custom toolchain. Legacy surfaces (i386 compat, vm86, a.out, 8259 PIC, PIT ticks) are omitted.
  2. Modern x86-64-v3 hardware assumptions. Targets x2APIC + TSC-deadline tickless timers, invariant TSC, SYSCALL/SYSRET, FSGSBASE, PCID/INVPCID, SMEP/SMAP, XSAVES, 1 GiB direct-map pages, and hybrid P-core / E-core awareness (CPUID 0x1A).
  3. Fast hot paths by construction. Single per-thread work flags word on syscall exit, zero-bounce per-CPU run queues, vDSO timekeeping (clock_gettime, gettimeofday, getcpu, getrandom), VFS path-lookup cache, PAT write-combining framebuffer mappings, zero-copy TCP receive loans, and scatter-gather chained DMA.
  4. Differential correctness against mainline Linux. Every test binary and shell suite runs identically on both Ferrite and mainline Linux under the same QEMU/KVM configuration via scripts/compare.sh, diffing outputs line by line.

Features

  • Core Kernel & SMP
    • Symmetric multiprocessing (tested up to 24 CPUs), hybrid P-core/E-core topology awareness, per-CPU run queues, tickless TSC-deadline scheduling, adaptive halt-polling.
    • Demand-paged B-tree VMAs, copy-on-write fork, shared zero page, buddy frame allocator, mmap/munmap/mprotect/mremap, futex, POSIX signals, epoll, eventfd, timerfd, signalfd, memfd, UNIX domain sockets, dynamic ELF loading (glibc & musl).
    • Self-hosting: boots rustc + cargo + rust-lld inside Ferrite to compile a verified Stage-2 release ferrite kernel (scripts/selfhost.sh).
  • Graphics, Console & Wayland
    • Linear framebuffer (/dev/fb0) backed by Bochs VBE (QEMU) or UEFI GOP (efifb=), with PAT write-combining mmap.
    • Built-in VT102/TERM=linux framebuffer console (fbcon) with auto 2× HiDPI scaling and UNIX98 PTYs (/dev/ptmx, /dev/pts/N).
    • Runs stock Wayland compositors (Sway 1.12), kitty, btop, fastfetch, and Mesa llvmpipe OpenGL ES 3D rendering.
  • Networking
    • virtio-net (MSI-X, zero-copy RX loans) and Intel I225-V 2.5GbE (igc, PCIe VFIO tested).
    • smoltcp-based IPv4/TCP/UDP stack + loopback fast path; runs unmodified curl over HTTPS/TLS.
  • Audio
    • Native ALSA character device ABI (/dev/snd/controlC0, /dev/snd/pcmC0D0p, /proc/asound/*) with Linux's hw_params refinement engine, MMAP_INTERLEAVED & RW_INTERLEAVED, poll/epoll, xrun recovery, and virtio-sound-pci backend.
    • Byte-for-byte identical aplay -l, --dump-hw-params, and aplay -v output compared to Linux; verified pure 440 Hz tone playback (scripts/sound-smoke.sh).
  • USB, Input & Block Storage
    • Native xHCI 1.1 host controller driver (MSI/MSI-X, Control, auto-rearming Interrupt IN, 64 KiB scatter-gather chained Bulk TRBs, Isochronous, and USB Hub class 0x09).
    • USB Core + /sys/bus/usb/devices/* (lsusb), Linux evdev (/dev/input/eventN, evtest), USB HID keyboard/mouse/tablet (wired to both evdev and interactive console TTY with Ctrl-C/SIGINT), and USB Mass Storage BOT+SCSI (/dev/sda).
  • UEFI Bootloader & Bare-Metal Readiness
    • Standalone uefi-rs loader (loader/) with zstd initramfs decompression, GOP framebuffer handoff, E820 conversion, and PVH trampoline (scripts/ovmf-boot.sh).
    • 128 GiB MMIO-hole-safe memory map, xAPIC→x2APIC transition, warm-reset RAM panic log ring, port 0x80 POST codes, and a hard PCI safety blocklist.
  • Experimental NVIDIA / CUDA RM Bring-Up (--features nvidia)

Architecture Overview

Ferrite is a single monolithic kernel mapped into the upper half of every address space, with all physical RAM direct-mapped at 0xffff_8000_0000_0000.

  • Boot & Entry (kernel/src/arch/, loader/): Under QEMU, Ferrite boots directly via Xen PVH (-kernel). On UEFI/OVMF, loader/ loads the kernel ELF and (optionally .zst-compressed) initramfs from \EFI\ferrite\, records the UEFI memory map, ACPI RSDP, and GOP framebuffer (efifb=...), exits boot services, and jumps to the exact same PVH entry point via a low-memory trampoline.
  • Traps & Syscalls (arch/syscall.rs, arch/trap.rs, syscall/): Syscalls, exceptions, and IRQs save a unified TrapFrame. Fast syscalls return via SYSRET and check a single per-thread pending-work word; execve and signal delivery fall back to IRET.
  • Memory (mm/): Global buddy allocator with per-page refcounts, 4-level paging with PCID/INVPCID, ioremap (UC/WC), vmalloc, and per-process B-tree VMA tables with rep movsb fault-handled user copies.
  • Scheduling (task/): Per-CPU run queues with work stealing, tickless TSC-deadline preemption, futex waitqueues, and P/E-core-aware scheduling.
  • VFS & Devices (fs/, sysfs.rs, tty.rs, input.rs, blk.rs, sound/, usb/): tmpfs root unpacked from cpio initramfs, path-lookup dcache, devtmpfs, procfs, sysfs, pipes, PTYs, ALSA PCM/CTL, evdev, block devices, and PCIe ECAM enumeration.

Repository Layout

Path Description
kernel/ no_std x86_64 Rust kernel (arch, mm, task, fs, syscall, sound, usb, nvidia, net/inet/igc/virtio*)
loader/ Standalone x86_64-unknown-uefi bootloader (uefi-rs + ruzstd) handing off to PVH
vdso/ Userspace vDSO (clock_gettime, gettimeofday, time, getcpu, getrandom)
third_party/smoltcp/ Thin smoltcp fork with per-address neighbor-discovery rate limiting
user/ Deterministic syscall tests, shell suites, microbenchmarks, and ALSA C regression tests
scripts/ Build, differential test (compare.sh), fuzzing, benchmark, OVMF, self-host, USB, and sound runners
docs/ ARCHITECTURE.md, benchmark raw logs, and subsystem design docs in docs/research/

Performance Highlights

Measured in identical QEMU/KVM configurations (-cpu host,+invtsc, pinned P-cores) against mainline Linux with mitigations=off nokaslr audit=0 tsc=reliable nowatchdog (docs/bench-ferrite.txt vs docs/bench-linux-tuned.txt, docs/netbench-raw-2026-12-03b.txt):

Benchmark Ferrite Tuned Linux Delta
Null syscall 39.2 ns 54.4 ns 1.39× faster
clock_gettime (vDSO) 15.4 ns 15.7 ns 1.02× faster
pread 4 KiB (tmpfs) 94.5 ns 144.6 ns 1.53× faster
stat (path cache) 140.9 ns 209.9 ns 1.49× faster
open + close 254.4 ns 341.3 ns 1.34× faster
Page fault (anonymous) 99.7 ns 185.6 ns 1.86× faster
mmap + munmap 64 KiB 339.4 ns 610.2 ns 1.80× faster
Pipe roundtrip 767.2 ns 1,423.1 ns 1.85× faster
fork + exit + wait 8.84 µs 13.54 µs 1.53× faster
fork + exec + wait 17.63 µs 27.13 µs 1.54× faster
Loopback TCP_RR (netperf) ~497k tx/s ~313k tx/s 1.59× faster
virtio-net TCP_CRR (netperf) ~52.6k tx/s ~43.3k tx/s 1.21× faster
USB 3.0 Mass Storage (dd 64 MiB SG-Bulk) 1.1–1.2 GB/s — 64 KiB chained xHCI TRBs

Quick Start

Prerequisites

  • Linux x86_64 host with KVM (/dev/kvm) and qemu-system-x86_64
  • Rust nightly toolchain (pinned in rust-toolchain.toml, with rust-src, llvm-tools, and x86_64-unknown-none target; add x86_64-unknown-uefi to build loader/)
  • busybox, gcc, cpio (plus edk2-ovmf / mtools for UEFI testing, alsa-utils / usbutils / evtest for subsystem smoke tests)

Build & Test

# Build the kernel (debug and release)
cargo build
cargo build --release

# Differential test suite: runs 30 tests on both Ferrite and host Linux and diffs output
./scripts/compare.sh

# Syscall and SMP fuzzers
./scripts/fuzz.sh
SMP=8 ./scripts/fuzz-smp.sh

# Subsystem smoke tests
./scripts/usb-io-smoke.sh                  # xHCI, lsusb, HID->evdev, USB storage
./scripts/sound-smoke.sh ferrite virtio    # ALSA + virtio-sound 440 Hz FFT check
./scripts/sound-smoke.sh ferrite virtio tests

# Boot through the Rust UEFI loader under OVMF
./scripts/ovmf-boot.sh -m 4G --smp 4 build/cmp/tests.cpio

# Bare-metal-style smoke test (24 CPUs, 16 GiB, USB hub + keyboard -> zsh on fbcon)
./scripts/bare-metal-smoke.sh

# Self-host: compile the Ferrite release kernel inside Ferrite
STAGE2=1 ./scripts/selfhost.sh

Status & Disclaimer

Ferrite is an experimental research OS under active development. It has no security mitigations (KPTI, Spectre/Meltdown), no user/permission isolation guarantees, and is not intended for production workloads.

If you experiment with booting Ferrite on real hardware via loader/, review the PCI device safety blocklist in kernel/src/pci.rs first so host storage and firmware controllers are never touched.

About

A from-scratch, no_std x86_64 Linux-ABI-compatible OS kernel in Rust

Resources

Stars

77 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages