Skip to content

4.4 Demonstration Tasks

Glen edited this page Nov 14, 2026 · 2 revisions

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


1. Task A and Task B Workloads

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

Task A (taskA_main)

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

Task B (taskB_main)

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

diagram

Sources: src/kernel/task.zig20-81


2. Dual-Mode Rendering Abstraction

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

Counter and Character Rendering

  • 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 If vga_mod.graphics_mode is enabled, it computes pixel coordinates using font.GLYPH_WIDTH and font.GLYPH_HEIGHT and invokes fb.drawStringAtPixelsrc/kernel/task.zig105-118 Otherwise, it writes directly to the legacy VGA text buffer mapped at 0xB8000src/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

diagram

Sources: src/kernel/task.zig85-155


3. Timing and Delay Implementation

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

Clone this wiki locally