# Userland Programs Relevant source files - [userland/hello/hello.zig](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/hello.zig) - [userland/hello/linker.ld](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/linker.ld) - [userland/prog1/prog1.zig](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/prog1/prog1.zig) ## 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: - [hello, prog1 and kbecho Programs](/GlenMeehan/CadenzaOS/8.1-hello-prog1-and-kbecho-programs) - [Userland Linking and Packaging](/GlenMeehan/CadenzaOS/8.2-userland-linking-and-packaging) --- ## 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-76](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/hello.zig#L36-L76)[userland/prog1/prog1.zig36-76](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/prog1/prog1.zig#L36-L76). 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 `rsi`[userland/hello/hello.zig103-115](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/hello.zig#L103-L115)[userland/prog1/prog1.zig103-130](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/prog1/prog1.zig#L103-L130). ![diagram](mermaids/8-userland-programs-diagram-1.png) Sources: [userland/hello/hello.zig36-115](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/hello.zig#L36-L115)[userland/prog1/prog1.zig36-130](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/prog1/prog1.zig#L36-L130) For details on syscall numbering, argument passing conventions, scratch page memory manipulation, and complete source breakdowns, see [hello, prog1 and kbecho Programs](/GlenMeehan/CadenzaOS/8.1-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-95](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/hello.zig#L84-L95)[userland/hello/linker.ld5-30](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/linker.ld#L5-L30). 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](mermaids/8-userland-programs-diagram-2.png) Sources: [userland/hello/linker.ld1-32](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/linker.ld#L1-L32)[userland/hello/hello.zig84-95](https://github.com/GlenMeehan/CadenzaOS/blob/8f182160/userland/hello/hello.zig#L84-L95) For details on linker scripts, header validation assertions, and packaging utilities, see [Userland Linking and Packaging](/GlenMeehan/CadenzaOS/8.2-userland-linking-and-packaging).