Repository navigation
1.1 Getting Started and Build System
Relevant source files
This page details the build system, toolchain prerequisites, execution modes, version generation, and disk image layout for CadenzaOS. It serves as the primary reference for compiling the kernel and bootloader, writing components to the disk image, and launching the OS inside hypervisors such as QEMU or Bochs, as well as preparing images for real hardware deployment.
Sources: build.sh1-12docs/REAL_HARDWARE.md1-15
The CadenzaOS build infrastructure is driven by build.sh [build.sh:1-186] and assumes a POSIX-compliant GNU/Linux host environment. The script relies on system utilities including stat (GNU syntax), readelf, objcopy, as, ld, nasm, and truncate [build.sh:5-6].
Additionally, the build system requires the Zig compiler (version 0.16.0) to compile the freestanding kernel [build.sh:16-20]. If Zig is not found in the host $PATH, the ZIG environment variable must be explicitly exported pointing to the binary.
# Example: Setting custom Zig path if not in PATH
export ZIG=/opt/zig/zig-0.16.0/zig
./build.sh ci
Sources: build.sh1-20
The build.sh script supports four distinct operational modes to control compilation and execution flow [build.sh:8-12]:
-
Default (
./build.sh): Performs a full build of the bootloader, kernel, staging areas, and userland bundles. It checks for an existing disk image (build/disk.img) and prompts the user whether to preserve or re-initialize the CodaFS filesystem partition [build.sh:8-9, 68-83]. Upon completion, it launches QEMU [build.sh:50-54]. -
ciMode (./build.sh ci): Executes a non-interactive build suitable for continuous integration pipelines or real hardware flashing [build.sh:10, 65-66]. It forcefully removes any existing disk image to ensure a completely fresh build, compiles all artifacts, and exits without launching QEMU. -
runMode (./build.sh run): Bypasses the build phase entirely [build.sh:11, 44-54]. It checks for the existence ofbuild/disk.imgand immediately launches QEMU, preserving all pre-existing disk state. -
cleanMode (./build.sh clean): Removes the compiled disk image (build/disk.img) from the local build directory [build.sh:12, 57-61].
Sources: build.sh1-87
During the build phase, build.sh extracts repository metadata using Git to generate a runtime version identifier [build.sh:95-116]. It queries the short commit hash, inspects git status to determine whether the working tree is dirty, and records the UTC build timestamp [build.sh:96-102].
This data is written directly to src/kernel/version.zig [build.sh:112-116], exposing constants accessible throughout the kernel:
pub const git_hash: []const u8 = "3ec0288";
pub const git_dirty: bool = true;
pub const build_ts: []const u8 = "2026-10-15T03:29:11Z";
Sources: build.sh95-116
The OS image build/disk.img is structured as a 10MB raw binary file containing boot sectors, the kernel binary, userland program bundles, and the CodaFS storage partition [build.sh:26-41, 171-184].

Figure 1: Physical disk layout bridging system storage sectors to code and configuration entities (build.sh, config.zig).
Sources: build.sh26-41build.sh171-184
Key sector locations are defined across build.sh [build.sh:26-41] and src/kernel/config.zig:
-
Sector 0: Master boot record / stage 1 bootloader (
src/boot/boot.asm), written viadd[build.sh:181]. -
Sector 1 onwards: Stage 2 long-mode transition loader (
src/stage2/stage2.asm), written with a seek of 1 [build.sh:182]. -
Sector 16 (
KERNEL_LBA): Kernel binary (kernel.bin) [build.sh:27, 183]. -
APP_LBA_START: Userland application staging area parsed directly fromsrc/kernel/config.zig[build.sh:30-41]. -
Sector 4096 (
PARTITION_LBA): Start of the CodaFS filesystem partition [build.sh:28]. When the filesystem is preserved, sectors belowPARTITION_LBAare updated while the filesystem is untouched [build.sh:178-180].
Sources: build.sh26-41build.sh171-184
The kernel build pipeline processes multiple language inputs (Zig, NASM assembly, GAS assembly) into a unified higher-half ELF executable and raw binary image [build.sh:91-132].

Figure 2: Compilation and linking dataflow bridging source files to build outputs (build.sh, linker.ld).
Sources: build.sh91-137
-
Kernel Object Generation:
src/kernel/kernel.zigis compiled using Zig in freestanding x86-64 mode with kernel code model (-mcmodel=kernel -fPIC -O Debug -fno-stack-protector) [build.sh:119-121]. -
Interrupt and Architecture Stubs:
irq_stubs.asmandarch_utils.sare assembled into ELF64 objects [build.sh:123-124]. -
Linking: All objects are linked using
linker.ldwith a 4KB page size enforcement (-z max-page-size=0x1000) [build.sh:126-129]. -
Metadata Extraction:
build.shinspectskernel.elfviareadelfto extract the entry point address and BSS section physical bounds, generatingbuild/kernel_info.incfor the bootloader assembly stages [build.sh:130-157].
Sources: build.sh91-165
CadenzaOS is primarily tested and run using QEMU, Bochs, and verified physical hardware (such as the Dell OptiPlex 3020 in Legacy BIOS / IDE mode) [docs/REAL_HARDWARE.md:5-13].
When running ./build.sh or ./build.sh run, QEMU is invoked with standard system emulation flags [build.sh:50-53]:
qemu-system-x86_64 \
-drive format=raw,file=build/disk.img \
-m 1024 -monitor stdio -no-reboot -no-shutdown -vga std \
-serial file:serial.log
This configuration allocates 1024 MB RAM, routes monitor output to stdio, maps standard VGA, prevents automatic reboots on kernel panics (-no-reboot -no-shutdown), and mirrors COM1 serial output to serial.log [build.sh:50-53].
Alternatively, Bochs can be used via the provided configuration file bochsrc.txt [bochsrc.txt:1-31]:
-
Memory: 1024 MB (
megs: 1024) [bochsrc.txt:5]. -
CPU Model:
core2_penryn_t9600at 50 MIPS [bochsrc.txt:7]. -
Storage: Primary ATA master disk (
ata0-master) mapped tobuild/disk.img[bochsrc.txt:14-15]. -
Serial: COM1 logging directed to
serial.log[bochsrc.txt:21].
For physical USB testing workflows, bochsrcusb.txt maps the primary master disk directly to host device nodes like /dev/sdb [bochsrcusb.txt:10-12].
- Overview
- Getting Started and Build System
- Kernel Configuration and Global State
- Project Governance and Contributing
- Boot and Early Kernel Initialization
- Bootloader Stages and Linking
- kmain Boot Sequence
- Splash Screen and Branding
- Interrupts, Scheduling, and Syscalls
- IDT, PIC, APIC and IRQ Stubs
- Scheduler and Task Lifecycle
- System Call Interface
- Demonstration Tasks
- CodaFS Filesystem and Storage
- On-Disk Format and Operations
- Space Manager and Block Devices
- Binary Format and Program Loading
- Shell, Terminal, and Display
- Shell Command Pipeline
- Terminal, Input Devices and Prompts
- Display: VGA, Framebuffer, Console and Serial