An implementation of a kernel entirely from scratch.
- Zig 95.1%
- Assembly 3%
- Linker Script 1.7%
- Python 0.2%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| apps/hello-world | ||
| libsys | ||
| scripts | ||
| src | ||
| .gitignore | ||
| .python-version | ||
| build.zig | ||
| build.zig.zon | ||
| pyproject.toml | ||
| pyrightconfig.json | ||
| README.md | ||
| TODO.md | ||
| uv.lock | ||
TinySys
An implementation of a kernel entirely from scratch.
Motivation for this Project
I always prefer to know how the things I use on a daily basis work under the hood. One of those things is Linux, which I use on all of my devices.
Maybe I'll get it to the point where it can be considered an operating system, eventually...
Tech Stack: literally just Zig
Many would want to use C/C++ for such a project. So why choose Zig, you may ask? Because it has:
- an amazing build system (check the
build.zig), - the beautiful
comptimekeyword, instead of C preprocessor macros, deferanderrdefer, handling 95% of what the borrow checker in Rust is for,- no hidden control flow, everything is explicit and therefore easier to reason about,
- no hidden allocations, it is all explicit, using the
std.mem.Allocatorinterface,
and because I just wanted to see how Zig does in such a project, at the lowest level of software there is! (aside from firmware maybe)
First Prototype Goals - for the Hack Club Macondo YSWS
finished
- Booting via the SBI boot protocol
- UART driver for basic printing
- A single U-mode process executing
-> just a kernel-embedded binary at first
-> basic syscalls work:
write,exit
Future Goals
- Small TTY/Shell Initial Process:
- using basic graphics -> bitmap font rendering?
- environment variables and $PATH lookups
- coloring support (ANSI? -> maybe something less complex)
- Symmetric Multi-Processing:
- implement infrastructure for easly declaration of per-CPU state (using the
tpregister) - simple preemptive scheduler, maybe based on fair shares?
- implement infrastructure for easly declaration of per-CPU state (using the
- Persistent Filesystem:
FAT32firstExt4later
- Advanced Graphics Support:
- windowing/window compositor => Wayland protocol?
Project Structure
src/Kernel and Bootloaderlibsys/System Zig Library, equivalent to a POSIXlibcapps/Userspace Applicationsapps/hello-world: A hello world program, that simply prints to stdout.
Building and Running from Source Code
Requirements:
- Zig 0.16.0
- QEMU installation including
qemy-system-riscvto emulate the RISC-V 64-bit ISA
# Run in an optimized build in a headless QEMU with maximum verbose logging
zig build -Dheadless -Dlog-level=debug --release=small run