Skip to content

Kernel

The iPod classic runs a small real-time kernel of the RTXC family, and everything else on the device leans on it. Chikuma reproduces the firmware's own design in Zig, in chikuma/kernel/, with the behaviour programs on top of it depend on. The host tests that make check runs cover its logic.

What the kernel provides

Service What it does
Tasks fixed priorities, with preemption: a higher-priority task that becomes runnable takes the processor
Mutexes priority inheritance, so a low-priority holder is lifted while a high-priority task waits on it
Timers, slots, events the message passing the UI and the drivers are built on
Heap boundary tags for allocation
Memory lending 512 KiB blocks of main memory lent to domains with a budget, such as the stream cache or a film's frames, and given back when the domain closes
Thread exit a thread ends through the kernel, and a dedicated reaper task frees its stack
Service dispatch the single entry through which tasks ask the kernel for work, with every slot read and classified

The reaper is how a game's thread gets cleaned up when the game quits.

The task table is the device's own

The kernel comes up with the firmware's real task table. Its tasks carry the names, ids and priorities the original uses. The great majority were recovered from the image's own strings.

Where two independent recovery routes both name a task, they agree, and that agreement turns a plausible name into a recovered one. When Chikuma spawns a thread, it takes the thread's number from this table instead of choosing one.

The disk sits behind a queue

The filesystem never calls the disk. It posts a request to a work queue and blocks. A dedicated pair of tasks does the bulk transfer and wakes the caller: one owns the work loop, the other handles the completion interrupt.

The disk tasks block instead of spinning, so the rest of the system keeps running while a transfer is in flight.

This arrangement explains why a stack trace taken when a disk command goes out can never name the code that asked for the data. The requester sits in another task, already blocked. A probe that expects a direct call chain from filesystem to disk looks in the wrong place. Storage shows the layers above the queue.

Priority classes

A thread is spawned with a priority class, and two small tables turn the class into a run-time priority. The first maps nine classes to an index, with a fallback for anything else. The second maps the index to the RTXC priority. Lower numbers run first:

Class Priority Example
0x100 0x08 the compositor's driver update
0xC0 0x09 the disk's interrupt task
0x20 0x31 the time manager, the USB tasks
0x18 0x33 the disk's work loop
0x10 0x34 the event and window managers

The table was checked against tasks whose priorities came from a separate route. Every one agreed. The clearest case is the disk pair: one spawn site starts both tasks with two different classes, and the two priorities it produces are the two the task table already had.

Messages between tasks

RetailOS's tasks talk through ports. A port is a queue of fixed slots with its own mutexes and condition variables, one side for free slots and one for pending messages. A send takes a slot from the sender's free list, stamps it with the time and the payload, and appends it to the receiver's pending list. A synchronous send then parks the sender until the receiver releases the slot. A coalescing send drops the message when the receiver already has one pending.

Events ride on top of this. A 28-byte event gets copied into a block from one global pool of a hundred, posted, and copied back out on the other side. The event manager's and the timer manager's own ports are a hundred deep.

Chikuma has the parts its tasks need for the moment: the window manager's queue with an event wake, and condition variables built from RTXC event slots for the audio and disk paths. A general port of the firmware's shape is not built yet.

Timekeeping

The kernel ticks at 500 Hz on a 16-bit hardware timer, as the firmware does, and every duration in Chikuma is written in milliseconds on top of it. Memory, interrupts and time has the timers, the interrupt controllers and the memory map underneath the kernel.