Memory, interrupts and time¶
Under the kernel sit three things every task depends on without asking: how memory is mapped, how an interrupt finds its handler, and what keeps time. On all three, Chikuma follows the layout RetailOS sets up, recovered from the running original and from the image.
The MMU is on¶
RetailOS runs with address translation enabled, the caches on and the write buffer on. Its first-level table sits in internal SRAM, and every entry is a 1 MiB section with full access in a single domain. The map is short:
| Virtual range | Maps to | Cached | Use |
|---|---|---|---|
| 0x00000000, 1 MiB | internal SRAM | no | the exception vectors |
| 0x08000000, 64 MiB | DRAM, identity | yes | code, data, the CPU's working set |
| 0x18000000, 1 MiB | the top MiB of DRAM | yes | a cached alias |
| 0x22000000, 1 MiB | internal SRAM, identity | no | the kernel's hot code |
| 0x38000000, 128 MiB | peripherals, identity | no | MMIO |
| 0x88000000, 64 MiB | DRAM again | no | the window hardware reads and writes |
The same 64 MiB of DRAM appears twice. The cached view at 0x08000000 is where the CPU works. The uncached view at 0x88000000 is where the display pipe and the other bus masters look, so a store made there is visible to the hardware without a cache clean. Address zero is remapped to SRAM, so the vector table the CPU fetches lives in internal memory.
Chikuma builds this same table before main and turns translation on. A firmware running with the
MMU off has a single view of DRAM and none of the separation the drivers rely on, and that shows up
as data that reads back wrong in strange places.
Where Chikuma's memory goes¶
Chikuma links every large buffer into a named section, and the link writes a map, so each block of DRAM can be accounted for. The layout follows RetailOS's own approach more closely over time:
- One heap. Everything between the end of the static data and the game arena is the heap. The track model and the cover cache come out of it.
- Blocks for media. Out of that heap, the leftover after the databases is cut into 512 KiB blocks. A user such as the stream cache or a film's decoder opens a domain with a budget, takes blocks when its mode starts and gives them back when it ends. A bigger library leaves fewer blocks, as on the device.
- The game arena. One MiB at the top of DRAM stays reserved, because a game image is linked absolutely there. The games pages explain why.
Some of it is still Chikuma's own for the moment. The screen surfaces are pooled, four double pairs shared by every screen, where RetailOS allocates a screen's surfaces when its pane comes up. A few single surfaces and fonts are still static.
Two interrupt controllers, one line space¶
The S5L8702 has two vectored interrupt controllers. The first serves lines 0 to 31. The second serves lines 32 to 63 and reaches the CPU only through the first one's daisy-chain input. An external interrupt controller beside them maps GPIO groups onto VIC lines.
RetailOS treats them as one space of 64 lines:
| Piece | What it does |
|---|---|
| init | masks both controllers, clears 64 handler slots, and writes each line's global number into its vector register |
| dispatch | reads the first controller's status, then the second's. The vector register gives the global line, which indexes the handler table |
| completion | writes the controller's end-of-interrupt word |
| sleep | saves both enable masks and both vector tables, arms only the wake sources, and restores the lot on wake |
The first controller has strict priority over the second, and one interrupt services one line. The device's own handler acknowledges its source in its own block. For the video decoder, on the second controller, that is the only acknowledgement that does anything.
Chikuma carries the same 64-line numbering, so a driver names the line the original names. Each handler is enabled on its own controller, and the dispatch makes one pass over each controller. It reads the status word and drains every asserted line, where the original takes one line per interrupt. A line on the second controller with no handler gets masked and logged, because it would otherwise re-enter forever.
The tick¶
The kernel ticks at 500 Hz, a 2 ms tick, on 16-bit timer block 1. That is the only periodic timer RetailOS arms. The tick handler acknowledges in the timer's own control word.
The timer blocks run from two clocks:
| Blocks | Clock | Used for |
|---|---|---|
| 0 to 3, 16-bit | 3 MHz | the tick, the clicker's gate and tone |
| 4 and up, 32-bit | 12 MHz, divided by 12 | a free-running microsecond counter |
The microsecond counter feeds the wheel's speed ring and every short wait. Chikuma programs its divider the way the firmware does, and derives every duration from milliseconds on top of the tick.
The real-time clock¶
The time of day comes from the platform's real-time clock, read as the firmware reads it. On the emulated machine the host serves the clock, and it can be pinned to a fixed value to reproduce a device whose backup cell has gone flat.
Tests¶
The MMU table was dumped from a booted original and decoded entry by entry. The tick period and the timer clocks come from a logged retail boot that shows each timer write and the code that made it. The interrupt dispatch was proved on video playback: had the second controller's line not been delivered, every frame wait would have run to its timeout, and none did.