Minimal x86 Kernel Zig
github.com82 points by lopespm 7 hours ago
82 points by lopespm 7 hours ago
Here's one for Risc-V that's a little more fleshed out, also in Zig: https://github.com/Fingel/aeros-v/blob/main/src/kernel.zig
I'm very surprised it's *that* short - handling one in rust i'm surprised by the very low amount of code to get that up. Thanks or sharing that was a first time reading some Zig for me !
what you’re experiencing is more or less why I am building some stuff in Zig instead of Rust
Very neat. To clarify, Qemu can boot it, but I'm pretty sure you need some bootloader (e.g. Grub) to boot it on a physical system.
Looks like it's multiboot compliant, so you can pick your favorite multiboot loader. ipxe, grub, pretty sure there's some other ones out there.
As it's multiboot, it should likely run on v86 too. It's always fun to have an in browser demo of a little OS like this.
If you want to use Grub, this tutorial works (see "Booting the kernel"):
https://wiki.osdev.org/Zig_Bare_Bones
Yes, just tried it.
From the GitHub page:
> It boots on an x86 (i386) machine via the Multiboot 1 protocol
Yes, it does need a compliant bootloader on virtual or physical hardware.
thats not a kernel
Indeed, it's freestanding, the repo name doesn't have the correct term, but the source file does near the end: https://github.com/lopespm/zig-minimal-kernel-x86/blob/main/...
Also baremetal where the metal is virtual. LLVM uses this term for when an OS isn't available https://github.com/llvm/llvm-project/tree/main/libc/src/stdl...
What's the point of doing this in "Zig" instead of C, the traditional choice for this kind of thing?
Because you can is a pretty traditional reason.
Zig is supposed to be an improvement upon C, so doing C things with it seems reasonable.
Kind of neat that there's no need for a separate assembly file although there is inline assembly. Might get better (or worse) syntax support for separate assembly files? But it doesn't make a big difference until there's more features that need it (interrupts, threads/processes and maintaining their stacks, syscalls, starting other processors, etc)
Zig is essentially a substantially improved and enhanced C, both in character and intent. There is a lot to recommend it for applications where you might otherwise use C.
because Zig is simply a better C, often faster (normally at least as fast), but with way more safety guarantees or at least things preventing the vast majority of traditional C footguns from happening
Why choose intel? Let's build bootable software in 2026
I'm not that cluey, but from the README it sounds like it can be compiled for a bunch of arches
Minimal slop.
Gold! I see Zig, I upvote!