Skip to content

8 Userland Programs

Glen edited this page Nov 14, 2026 · 2 revisions

Userland Programs

Relevant source files

Purpose and Scope

This page provides a high-level overview of ring-0 userland programs in CadenzaOS, their execution environment, and the build/link conventions required to package them for the OS. CadenzaOS supports running lightweight executable applications loaded from disk, receiving command-line arguments via registers, and interacting with the kernel through the software interrupt system call gateway (int $0x80).

For detailed technical explanations, source code breakdowns, and packaging mechanics, please refer to the child pages:


8.1 hello, prog1 and kbecho Programs

CadenzaOS includes sample userland applications—specifically hello, prog1, and kbecho—located under the userland/ directory. These programs demonstrate how user-level tasks interface with kernel services using inline assembly wrappers around the int $0x80 system call vector, handling operations such as string printing, scratch page manipulation, non-blocking keyboard input, and CPU yielding userland/hello/hello.zig36-76userland/prog1/prog1.zig36-76.

Programs define an entry point _start matching a C-style calling convention that receives argument counts (argc) in register rdi and argument vectors (argv) in register rsiuserland/hello/hello.zig103-115userland/prog1/prog1.zig103-130.

diagram

Sources: userland/hello/hello.zig36-115userland/prog1/prog1.zig36-130

For details on syscall numbering, argument passing conventions, scratch page memory manipulation, and complete source breakdowns, see hello, prog1 and kbecho Programs.


8.2 Userland Linking and Packaging

Userland programs require strict adherence to layout and header conventions so the kernel binary loader can parse and execute them correctly. Each binary embeds a custom 16-byte CDZP header identified by the magic number 0x505A4443 placed at image offset zero (_header_start = 0x0) userland/hello/hello.zig84-95userland/hello/linker.ld5-30.

The custom linker script (linker.ld) enforces this layout by placing the .header section first, followed by .text, .rodata, and .data sections up to _image_end, while discarding unnecessary debugging frames [userland/hello/linker.ld:7-27]. Once compiled, these binaries are bundled for storage staging and integrated into the filesystem image.

diagram

Sources: userland/hello/linker.ld1-32userland/hello/hello.zig84-95

For details on linker scripts, header validation assertions, and packaging utilities, see Userland Linking and Packaging.

Clone this wiki locally