# The two CPUs, what they share, and the IPC ## The CPUs (cores, pinned by commit when they have code) | | ARM9 | ARM7 | | --- | --- | --- | | Chip | ARM946E-S r1 (ARMv5TE) | ARM7TDMI (ARMv4T) | | Core repository | `../arm946es-python` (Phase 0 tonight) | `../arm7tdmi-python` (built; rungs 0-4 pass; gba-python's CPU) | | Clock | 67.027964 MHz (bus x 2) | 33.513982 MHz (the bus clock); 16.76 MHz in GBA mode | | Memory inside the CPU | 32 KB ITCM, 16 KB DTCM, 8 KB I-cache, 4 KB D-cache, CP15 PU, write buffer | none (no CP15, no cache: GBATEK "The NDS7 doesn't have any TCM, Cache, or CP15") | | Bus contract | AHB transactions with a cost in bus cycles (arm946es-python handoff-brief.md) | one callback per CPU cycle with N/S/I/C and width (arm7tdmi-python's contract, as gba-python uses it) | | Interrupt controller | IME/IE/IF at 4000208h-4000214h, ARM9 sources | IME/IE/IF, ARM7 sources | | Halt | CP15 wait-for-interrupt; it "locks up if interrupts are disabled via IME=0" (GBATEK "DS Power Control"), so the board drives the core's IRQ line from IME AND (IE AND IF), while the core wakes on the line whatever CPSR.I says (DDI 0201D 2.3.10) | HALTCNT, 4000301h ("different bits than on GBA"): halt (paused while IE AND IF = 0, IME not checked), sleep, and the GBA-mode switch (BIOS CustomHalt) | **Reuse:** arm7tdmi-python is used unchanged for the ARM7. What the DS needs from it that the GBA did not: nothing new in the instruction set; the bus contract is the same; the board must feed it the DS's wait states (memory-map.md) instead of the GBA's. A DS-only corner found on the ARM7 (none known) would be raised on the core. ## What the CPUs share - **Main RAM** (4 MB): both, through one memory interface with a priority bit (EXMEMCNT bit 15). Most data passes this way: the ARM9 runs game code from it, the ARM7 runs its sound and Wi-Fi driver from WRAM and reads sound data from main RAM. - **Shared WRAM** (32 KB): split by WRAMCNT (memory-map.md); usually all given to the ARM7 by Nintendo's SDK. - **VRAM C and D** as ARM7 WRAM, when mapped so. - **The GBA slot and the DS slot**: one owner each (EXMEMCNT bits 7 and 11). - **The IPC registers** (below), readable by both "without generating waitstates at either side" (GBATEK). ## IPC (GBATEK "DS Inter Process Communication") - **IPCSYNC** (4000180h on each side): a 4-bit value each CPU shows the other (bits 8-11 out, bits 0-3 in), a "send IRQ to remote" bit (13) and an "accept IRQ from remote" enable (14). The IRQ is IF bit 16. - **IPCFIFOCNT** (4000184h), **IPCFIFOSEND** (4000188h), **IPCFIFORECV** (4100000h): two 16-word FIFOs, one each way. Status bits for empty/full on both ends, a sticky error bit (read empty or send full, acknowledged by writing 1), an enable (bit 15). Disabled: sends are ignored (no error), receives return the oldest word without removing it. Empty: the last received word (or 0 after a clear), and the error bit sets. IRQs are **edge triggered**: IF.17 when "send-empty IRQ enabled and send FIFO empty" goes 0->1, IF.18 when "receive-not-empty enabled and not empty" goes 0->1. - rockwrestler tests IPCSYNC (both directions, IRQs), the FIFOs (including the empty-read and error cases) and the FIFO IRQs (validation.md). ## What this means for the order of record The CPUs meet at memory as well as at the IPC registers: Nintendo's SDK passes messages through the FIFO, but software also polls shared main RAM and WRAM. In the order of record (x-python, serial; domains.md), the two cores are interleaved on the common bus clock in short slices, with every access to a shared location (main RAM, shared WRAM, IPC, the slots, VRAM C/D when the ARM7's) made at its exact bus time. The slice length is a correctness question, not a speed one: a slice longer than the time between two accesses that can observe each other changes results. U-items: - U1 How main-RAM contention between the CPUs and DMA is resolved per cycle (memory-map.md U2): decides the exact interleaving rule. - U2 IPCFIFO latency: does a word sent at bus cycle t appear to the receiver at t, t+1, or later? (GBATEK says only that there are no wait states.) Default t+1, HYPOTHESIS. - U3 Whether IPCSYNC's IRQ reaches the other CPU in the same cycle.