Repository navigation
4.4 Demonstration Tasks
Relevant source files
The purpose of this section is to document the implementation and operation of the demonstration tasks defined in src/kernel/task.zig. These tasks serve as concrete, visible workloads used by the CadenzaOS kernel to verify task creation, context switching, preemptive scheduling timing, and output routing across both legacy VGA text mode and VESA framebuffer graphics modes src/kernel/task.zig1-8
The task subsystem defines two independent entry points, taskA_main() and taskB_main(), which run concurrently under the scheduler src/kernel/task.zig20-81 Both tasks initialize their execution context by enabling interrupts via the sti assembly instruction src/kernel/task.zigNaN-NaN
taskA_main maintains a 32-bit execution counter (run_count) that increments on each iteration src/kernel/task.zig24-27 It outputs this counter to row 23, column 60 of the display src/kernel/task.zig29-35 It then flashes an 'A' indicator character at row 23, column 79, alternating with a space every 500 milliseconds using a busy-wait delay src/kernel/task.zig37-47
taskB_main operates similarly to Task A but runs at a distinct cadence to allow visual verification of scheduling and preemption src/kernel/task.zig52-53 It maintains its own run_count, rendering the counter value at row 24, column 60 src/kernel/task.zig58-69 It flashes a 'B' indicator character at row 24, column 79 at a higher frequency (250 millisecond intervals) than Task A src/kernel/task.zig71-80
Title: Task Execution Flow and Code Mapping

Sources: src/kernel/task.zig20-81
To support varying boot configurations, demonstration tasks do not target a single display device. Instead, helper functions inspect vga_mod.graphics_mode to transparently route output to either the direct VGA text buffer or the graphical VESA framebuffer src/kernel/task.zig85-155
-
draw_counter: Converts a 32-bit integer into a 4-digit hexadecimal string representation using a hex lookup table (0123456789ABCDEF) src/kernel/task.zig87-104 Ifvga_mod.graphics_modeis enabled, it computes pixel coordinates usingfont.GLYPH_WIDTHandfont.GLYPH_HEIGHTand invokesfb.drawStringAtPixelsrc/kernel/task.zig105-118 Otherwise, it writes directly to the legacy VGA text buffer mapped at0xB8000src/kernel/task.zig119-126 -
draw_char: Renders a single character with specified color attributes, selecting between framebuffer pixel operations and direct memory-mapped text buffer writes src/kernel/task.zig131-155
Title: Display Routing and Rendering Functions

Sources: src/kernel/task.zig85-155
Both demonstration tasks rely on a crude busy-wait delay function, sleep(), to pace their output cycles src/kernel/task.zig41-45src/kernel/task.zig75-79src/kernel/task.zig162-170
| Function | Parameter | Implementation Detail | Source Citation |
|---|---|---|---|
sleep |
ms: u64 |
Multiplies input milliseconds by 10,000 and executes a tight loop containing the nop assembly instruction |
src/kernel/task.zig162-170 |
taskA_main |
None | Alternates between 500ms delay cycles | src/kernel/task.zig41-45 |
taskB_main |
None | Alternates between 250ms delay cycles | src/kernel/task.zig75-79 |
Sources: src/kernel/task.zig41-45src/kernel/task.zig75-79src/kernel/task.zig162-170
- 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