Chapter 12 of 16 · Deutschnullos.de

Build it yourself

How the source turns into bootloader, kernel, compiler and tools.

Bootloader nb

A single C file, no libc. clang compiles it for the Windows target (UEFI programs are Windows PE files), lld-link turns it into an EFI application:

clang --target=x86_64-unknown-windows -ffreestanding … -c boot/nb.c
lld-link -subsystem:efi_application -entry:efi_main -out:build/nb.efi

For demos: make clean os NBFLAGS=-DNB_PAUSE=2000 keeps the bootloader screen up for 2 seconds.

Kernel nk

The portable core and the x86_64 part plus startup code in assembly. clang for x86_64-unknown-elf, freestanding (no standard library, no SSE, no red zone), then ld.lld with its own linker script. The kernel runs high up in the address space (0xffffffff80200000); nb already builds the page tables for that.

Plus init.img: a ustar archive with everything that sits in / at startup – the kernel's test programs and all tools from make nullos-tools in /bin.

make os      # build/nb.efi + build/nk.elf → build/esp/

Or without clang at all, only with our own toolchain:

make -C cc kernel   # cc + own assembler + own linker, then boot test in QEMU

libc

make -C libc                    # for the Mac: build/libc/host/
make -C libc TARGET=nullos      # for NULLos: build/libc/nullos/{libc.a,crt0.o}
make nullos-tools               # all cmd/* against the NULLos libc → /bin
sh libc/test/vergleich.sh       # byte for byte against the macOS libc

Contract with the kernel: the list of system calls and the header for it – both include the same file; if a constant differed, the build would break.

Compiler cc

make -C cc           # builds build/cc/cc (with Apple clang)
make -C cc test      # all tests (x86_64 programs run via Rosetta 2)
make -C cc stage3    # self-compilation: cc → cc2 → cc3, output must match
make -C cc check     # everything: tests, cross-check with clang, all tools, assembler comparison,
                     # self-compilation, kernel boot, ARM64
make -C cc test-qemu-arm64     # tests as ARM64 programs in QEMU
make -C cc test-qemu-riscv64   # tests as RISC-V 64 programs in QEMU
make -C cc kernel    # build all of NULLos with cc (kernel, libc, tools) and boot it
make -C cc nullos    # cc on NULLos: compiles itself there

Use it as usual: cc -o hallo hallo.c, -S, -c, -E, for NULLos --target=x86_64-elf.

Tools

make host     # all cmd/* for the Mac → build/host/
make test     # run every test.sh, result per tool

One tool = its own C file plus a small shared helper library, compiled strictly (-std=c11 -Wall -Wextra -Werror -pedantic). The Abgleich (a Python script) checks the whole status and writes it into a status list.

Download images

sh tools/release/mkrelease.sh      # .img, .iso, SHA256SUMS → build/release/<version>/
sh tools/release/check-release.sh  # check all six boot methods in QEMU

What gets checked: .img as SATA disk, NVMe SSD and USB stick, .iso as CD, USB stick and SATA disk. More in Installing.

These docs

sh tools/doku/build.sh

Compiles the docs generator (C) and rewrites these pages. A make doku is wanted. coming soon