Repository navigation
1.2 Kernel Configuration and Global State
Relevant source files
This page details the compile-time configuration constants, system policies, hardware tuning parameters, and runtime global pointers that govern CadenzaOS kernel operations. Centralising these parameters in src/kernel/config.zig, src/kernel/globals.zig, and src/kernel/boot_info.zig allows for clean separation between static structural definitions and dynamic runtime state.
The kernel defines several compile-time Logical Block Address (LBA) constants and sizing limits in src/kernel/config.zig to partition the virtual disk, stage embedded applications, and structure CodaFS operations src/kernel/config.zig30-61
-
PARTITION_START_LBA: Set to sector4096, leaving the initial sectors free for bootloader data, staging areas, and partition metadata src/kernel/config.zig30-34 -
APP_LBA_START: Staging sector (3700) withAPP_MAX_SECTORS(256) for the embedded user application (prog1), verified via acomptimecheck to ensure it does not overlap withPARTITION_START_LBAsrc/kernel/config.zig36-44 -
SB_LBA: Relative to the start of the CodaFS partition, the superblock sits at sector0src/kernel/config.zig52-56 -
BLOCK_SIZE: Fixed at512bytes, matching the underlying ATA disk sector size src/kernel/config.zig58-61 -
DISK_SECTOR_COUNT: Total virtual capacity defined as20,480sectors (10 MiB) src/kernel/config.zig63-66
Buffer sizes such as BASE_IO_BUF_SIZE, KEYBOARD_BUF_SIZE, and TERMINAL_LINE_SIZE scale directly from BLOCK_SIZE to standardize memory chunking across the I/O subsystems src/kernel/config.zig73-86
Title: Disk Space and Layout Constants in config.zig

Sources: src/kernel/config.zig30-66
To keep command parsing lightweight and behavioural tracking tables compact, shell commands are mapped to compact u8 identifiers via the CommandID enum src/kernel/config.zig97-123
System behavior is governed by the SystemPolicy enum, which defines three operating profiles src/kernel/config.zig135-145:
-
DEV: Development-oriented profile with minimal friction src/kernel/config.zig138 -
GAMING: Performance-oriented profile with reduced safety checks src/kernel/config.zig141 -
ADMIN: Conservative profile prioritizing validation and stability src/kernel/config.zig144
The active runtime policy is held in current_policy (defaulting to .ADMIN) src/kernel/config.zig147-151
Title: Command Parsing and SystemPolicy Routing (Code Entity Space)

Sources: src/kernel/config.zig97-151
Task execution and preemption are parameterized under the scheduler and timer structures in src/kernel/config.zigsrc/kernel/config.zig155-201
-
scheduler.timeslice_ticks: Number of timer ticks allocated to a task before context switching (default:10) src/kernel/config.zig159-171 -
scheduler.max_tasks: Maximum concurrently scheduled tasks (8) src/kernel/config.zig173-174 -
scheduler.default_stack_size: Default stack allocation per task (4096bytes) src/kernel/config.zig176-180 -
timer.frequency_hz: System timer frequency (100Hz / 10 ms interval) src/kernel/config.zig188-193 -
timer.use_apic: Boolean flag selecting between legacy PIC/PIT (false) and Local APIC timer (true) src/kernel/config.zig195-200 -
USE_SCHEDULER_SHELL: Enables or disables shell execution inside the scheduler task framework src/kernel/config.zig204-208
Title: Timer and Scheduler Configuration Flow

Sources: src/kernel/config.zig155-208
Kernel-wide runtime pointers are maintained in globals.zig (and re-exported or mirrored in config.zig) src/kernel/globals.zig1-27:
-
fs_global: Global pointer to the mountedCodaFsfilesystem instance src/kernel/globals.zig20 also referenced inconfig.zigsrc/kernel/config.zig219 -
kernel_allocator: Globalstd.mem.Allocatorinitialized during early boot for heap allocations src/kernel/globals.zig27
Early-boot parameters passed from the bootloader are mapped at physical address 0x7000 (BOOT_INFO_ADDR) via the BootInfo extern struct src/kernel/boot_info.zig1-72 This structure forms an ABI contract between the bootloader and the kernel (verified at compile-time to be exactly 160 bytes) src/kernel/boot_info.zig19-59
Key fields within BootInfo include:
- Kernel physical ranges (
kernel_start,kernel_end,kernel_size) src/kernel/boot_info.zig24-26 - Initial stack top (
stack_top) src/kernel/boot_info.zig27 - E820 memory map pointer and entry count (
e820_addr,e820_count) src/kernel/boot_info.zig29-32 - Early page table base (
page_table_base) src/kernel/boot_info.zig33 - Framebuffer configuration data (
framebuffer_addr, dimensions, strides, pixel formats) src/kernel/boot_info.zig35-51
Access to this read-only structure is provided by boot_info.get()src/kernel/boot_info.zig66-72
Title: BootInfo and Global State Architecture (Code Entity Space)

Sources: src/kernel/boot_info.zig1-72src/kernel/globals.zig1-27src/kernel/config.zig215-220
- 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