Tech News
← Back to articles

Minimal x86 Kernel Zig

read original related products more articles

Minimal x86 Kernel - built in Zig

A minimal bare-metal kernel written entirely in Zig (zero assembly files). It boots on an x86 (i386) machine via the Multiboot 1 protocol and prints a coloured greeting to the VGA text-mode display, then halts the CPU.

The project is designed to be cross-compiled from any host (including Apple Silicon Macs) and tested instantly with QEMU — no ISO image, no GRUB installation, no bootloader binaries required.

What it does

QEMU loads the ELF binary using its built-in Multiboot 1 support. The CPU starts in 32-bit protected mode at the _start entry point. _start sets up a 16 KiB stack and jumps to kmain . kmain clears the VGA text buffer and writes a message to the screen. The CPU enters an infinite hlt loop.

Preconditions

Tool Version Install Zig 0.14.0+ ziglang.org/download or brew install zig QEMU any recent brew install qemu / nix-env -iA nixpkgs.qemu

No other dependencies. Zig bundles its own LLVM back-end and linker, so cross-compilation to x86-freestanding-none works out of the box on any host OS and architecture (macOS ARM, Linux x86_64, etc.).

How to run

# Build the kernel (produces zig-out/bin/kernel) zig build # Boot it in QEMU (opens a graphical VGA window) zig build run # Or use the helper script (curses mode, auto-kills after a few seconds) chmod +x run.sh ./run.sh

... continue reading