Skip to content

2 Boot and Early Kernel Initialization

Glen edited this page Nov 14, 2026 · 2 revisions

Boot and Early Kernel Initialization

Relevant source files

This page provides a high-level overview of the boot path in CadenzaOS, tracing execution from raw BIOS boot sectors through multi-stage bootloaders, memory map collection, long-mode transition, and finally into the higher-half kernel entry point and kmain orchestration src/kernel/kernel.zig1-14src/boot/boot.asm1-15 CadenzaOS operates as a 64-bit x86-64 bare-metal operating system, leveraging a higher-half layout src/kernel/kernel.zig88

For detailed technical breakdowns of specific sub-components, refer to the child pages:

  • Bootloader Stages and Linking — boot.asm stage 1, stage2.asm long-mode transition and E820 collection, linker.ld higher-half layout, kernel_info.inc generation.
  • kmain Boot Sequence — Phase-by-phase walkthrough of kernel_entry/kmain: serial, framebuffer, stack switch, FS recovery, memory reservation, APIC/IDT setup, scheduler handoff.
  • Splash Screen and Branding — splash.zig, logo.zig, Splash.rgb asset and boot-time visual presentation.

Boot Path and System Architecture

The boot sequence transforms the CPU state from 16-bit real mode into a fully paged 64-bit long-mode environment with active interrupt management, hardware timers, and memory allocation.

Title: Boot Path Code Entity Mapping

diagram

Sources: src/boot/boot.asm1-110src/kernel/kernel.zig1-14


2.1. Bootloader Stages and Linking

The bootloader is split into distinct stages that progressively configure the hardware platform before handing control to the Zig kernel image. Stage 1 resides in the master boot record (src/boot/boot.asm) and uses BIOS interrupts (INT 13h extended read) to load Stage 2 from disk src/boot/boot.asm1-110 Stage 2 executes in real mode, transitions through unreal mode to access memory above 1 MiB, collects physical memory maps via BIOS INT 0x15 (E820), configures early page tables, and enables 64-bit long mode.

The kernel binary layout is governed by linker scripts which enforce a higher-half virtual base mapped against a physical load address of 1 MiB. During the build process, sector counts and entry symbols are automatically generated into build/kernel_info.inc to inform Stage 2 of the exact payload size required for disk reads.

For complete implementation details, see Bootloader Stages and Linking.

Sources: src/boot/boot.asm1-110


2.2. kmain Boot Sequence

Once long mode is established, the CPU jumps to kernel_entry, which sets up essential segment registers and stacks before invoking kmain in src/kernel/kernel.zigsrc/kernel/kernel.zig1-14 The kmain routine executes an early-boot orchestration sequence:

  1. Initialises serial output drivers and framebuffers for logging src/kernel/kernel.zig46-47
  2. Configures bootstrap memory allocators (FixedBufferAllocator) utilizing heap_buffersrc/kernel/kernel.zig71-81
  3. Restores and mounts the CodaFS filesystem instance (fs_global) over the RAM disk region mapped at RAMDISK_VIRT_ADDR (0xFFFFFF8002000000) src/kernel/kernel.zig87-101
  4. Sets up interrupt descriptor tables, local APIC structures, and task state segments src/kernel/kernel.zig27-50
  5. Hands control over to the task scheduler to spawn the initial user-facing shell environment src/kernel/kernel.zig33

Title: Kernel Memory and Stack Topology

diagram

Sources: src/kernel/kernel.zig52-116

For a phase-by-phase walkthrough of this sequence, see kmain Boot Sequence.

Sources: src/kernel/kernel.zig1-116src/boot/boot.asm1-110


2.3. Splash Screen and Branding

CadenzaOS incorporates early-boot visual presentation routines handled by splash.zig and rendered via the VESA VBE framebuffer or text-mode console. Utilizing compiled-in raw RGB assets (Splash.rgb) and modular font glyph generators (logo.zig), the kernel displays branding elements during the hardware initialization phase before transitioning to the interactive shell console.

For details on asset packaging and rendering mechanics, see Splash Screen and Branding.

Sources: src/kernel/kernel.zig49

Clone this wiki locally