Skip to content

1.2 Kernel Configuration and Global State

Glen edited this page Nov 14, 2026 · 2 revisions

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.


1. Compile-Time Disk and Filesystem Layout

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 sector 4096, leaving the initial sectors free for bootloader data, staging areas, and partition metadata src/kernel/config.zig30-34
  • APP_LBA_START: Staging sector (3700) with APP_MAX_SECTORS (256) for the embedded user application (prog1), verified via a comptime check to ensure it does not overlap with PARTITION_START_LBAsrc/kernel/config.zig36-44
  • SB_LBA: Relative to the start of the CodaFS partition, the superblock sits at sector 0src/kernel/config.zig52-56
  • BLOCK_SIZE: Fixed at 512 bytes, matching the underlying ATA disk sector size src/kernel/config.zig58-61
  • DISK_SECTOR_COUNT: Total virtual capacity defined as 20,480 sectors (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

diagram

Sources: src/kernel/config.zig30-66


2. Command Identifiers and System Policies

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:

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)

diagram

Sources: src/kernel/config.zig97-151


3. Scheduler and Timer Configuration

Task execution and preemption are parameterized under the scheduler and timer structures in src/kernel/config.zigsrc/kernel/config.zig155-201

Title: Timer and Scheduler Configuration Flow

diagram

Sources: src/kernel/config.zig155-208


4. Runtime Globals and Boot Handoff

Globals (globals.zig)

Kernel-wide runtime pointers are maintained in globals.zig (and re-exported or mirrored in config.zig) src/kernel/globals.zig1-27:

Boot Information (boot_info.zig)

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:

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)

diagram

Sources: src/kernel/boot_info.zig1-72src/kernel/globals.zig1-27src/kernel/config.zig215-220

Clone this wiki locally