An x86-64 kernel written in Rust, largely following the Writing an OS in Rust blog by Philipp Oppermann.
Requires Nightly Rust 2025-03-17 with the rust-src
and llvm-tools-preview
,
as specified in rust-toolchain.toml
.
Install it with
rustup install nightly-2025-03-17
rustup component add --toolchain nightly-2025-03-17-x86_64-unknown-linux-gnu rust-src llvm-tools-preview
Building the kernel requires the bootimage
tool.
Install it with cargo install bootimage
.
Build the kernel with
cargo bootimage --release
This leaves you with a raw disk image at target/x86-64-bare/release/bootimage-kernel.bin
.
You can boot this image with QEMU using
qemu-system-x86_64 -drive format=raw,file=target/x86-64-bare/release/bootimage-kernel.bin
Alternatively, you can use bootimage
to automatically run the kernel in QEMU with
cargo run --release
- Cooperative multitasking implemented on top of Rust async.
- Global millisecond-granular clock implemented via the PIT1.
- Convenient VGA Text Mode handling utilities
with
println!
macro color integration. - Custom interrupt-aware spinlock-backed Mutex and lock-free LazyStatic implementation.
- Global freelist-backed heap allocator2.
- Event-driven keyboard input1.
- Support for unit and integration testing.
- BIOS support via the
bootloader
crate3.
The eventual goal of this project is to build an OS that can run Doom, but the current state of the kernel is very far from that.
The kernel in its current state provides a sufficient interface for building Terminal UI applications and simple games, however VGA Text Mode is very limiting and everything must run in kernel space.
As an example, I implemented a quick-and-dirty "shell"(glorified string literal matcher with rudimentary input handling) and two "apps". They are snake and flappy bird.
- VGA Graphics Mode
- Transitioning to
bootloader
version 0.113. - Multithreading.
- Userspace and syscall support.
- Preemptive multitasking for userspace.
- Frame-aware global allocator.
- Read/Write/Seek syscalls.
- Memory mapping syscalls
- File system.
- Process management syscalls.
- Windowing.
- Exposing a graphics API to userspace.
- Porting a subset of libc.
- Doom.
Footnotes
-
Timer and keyboard interrupts are handled via the legacy PIC. A transition to the APIC is in-progress. ↩ ↩2
-
The freelist allocator is fairly simple and can be improved by using a block-allocator to allow for allocations <16 bytes in size, that falls back to the freelist allocator for larger allocations. ↩
-
The
bootimage
tool used is incompatible with versions ofbootloader
>= 0.10. Transitioning off of it will enable UEFI support and simplify the build process. This will also require switching from VGA Text Mode to VGA Graphics Mode. ↩ ↩2