Chapter 9 of 16 · Deutschnullos.de

What it looks like inside

From power-on to the prompt – and who talks to whom.

Startup

UEFI nbBootloader nkKernel Prompt >

nb – the bootloader

A small UEFI application (one C file, no libc). It queries the screen (GOP), reads \nullos\nk.elf from the boot partition, puts the parts of the kernel at their addresses, fetches the memory map, says goodbye to UEFI and jumps into the kernel. The kernel gets everything important in one structure: memory, screen, ACPI.

nk – the kernel

Portable C, everything machine-specific in a layer of its own – for x86_64, ARM64 and RISC-V 64. It runs in the upper half of the address space, programs get the whole lower half. What it can do:

Writing to disks, finer locks in the kernel: coming soon Which hardware works: Drivers.

The layers

Tools · shell s · compiler cc libc – its own C library System calls – 85 of them, the contract Kernel nk – portable C Machine layer – x86_64, ARM64, RISC-V 64

System calls

Small on purpose: 85 calls – 16 for sockets, plus mounting, devices, network settings, users and ID card, setting the clock, process and disk statistics, file locks and pseudo-terminals. All are implemented and tested, fixed in a contract with a header to go with it. On x86_64 via syscall, number in rax, arguments like on Linux. Errors come back as a negative number. Numbers are never redefined, only added.

Programs are static ELF64 files, with no libraries at runtime. Later a fast ring for many requests at once will be added.

Tools are written against a small ABI

So that hundreds of tools could be built at the same time while the kernel isn't finished yet, they're all written only against a short list of C functions: strings, memory, files, folders, time, processes. The same source runs on the Mac and unchanged on NULLos.

libc – its own C library

Written from scratch (musl and PDCLib only as reading material). A portable part – strings, malloc, stdio, printf, time, math – and below it a thin layer of about 70 functions to the kernel. There are two of those: one for NULLos and one for macOS that gets by entirely without Apple's libc (system calls directly).

cc – its own C compiler

hallo.c Preprocessor+ parser x86_64ARM64RISC-V Assembler Linker ELF

A C11 compiler in C11, complete with its own assembler and its own ELF linker. The big moments:

Code generation exists for x86_64, ARM64 and RISC-V 64 (the last two tested in QEMU). RISC-V 32 for the small ESP32s and Xtensa are to follow. coming soon