# Caches, the locked cache, its DMA engine and the write-gather pipe Source: Gekko UM (IBM, v1.2, 2000; facts only) chapters 3 and 9, sections 2.1.2.4, 2.1.2.8, 2.1.2.10. All DOC unless tagged. ## L1 caches - Instruction and data caches of 32 KB each, 8-way set-associative, 32-byte blocks, pseudo-LRU replacement; the data cache keeps MEI coherency states (UM 1.2.4, chapter 3). - Cache control instructions: `dcbt dcbtst dcbz dcbst dcbf dcbi icbi` and the Gekko's `dcbz_l`; HID0 holds the enable, lock and flash-invalidate bits for each cache (UM 2.1.2.1, HID0 table). - **Why the caches belong in the specification.** Every observable difference a cache makes reaches another domain: a line not yet written back is invisible to Flipper's DMA, the GX FIFO and the DSP; a stale instruction line runs old code after a DMA has replaced it (DVD loads, ARAM transfers). GameCube programs therefore flush and invalidate explicitly, and a model without caches runs programs that would fail on hardware (HYPOTHESIS: the common emulator shortcut; it is a concession, never the specification). The specification models the tags, the states and the pseudo-LRU bits. - Data per line is held as well (a write-back model), because the difference between memory and cache contents is exactly what other masters observe. ## L2 cache 256 KB, unified, on-chip, 2-way set-associative with 2K tags per way, 64-byte lines in two 32-byte sectors, each sector with its own valid and modified bits; write-back; L2CR (SPR 1017) controls it (UM 1.2.5, 9.1). Access takes about 3 processor cycles plus 4 to transfer, not pipelined (UM 9.1.6). The IPL enables it (HYPOTHESIS: firmware is not read here; the board's boot path will see L2CR written). The L2 matters to timing only, not to what another master sees, as long as the board's masters never read memory the CPU holds modified in L2 without a flush (the same rule as for L1). ## The locked cache (HID2[LCE]; UM 9.2) - LCE = 0 at reset: a 32 KB 8-way data cache. LCE = 1 splits it: **ways 0-3 are a 16 KB normal 4-way cache, ways 4-7 a 16 KB locked cache** that only `dcbz_l` and the DMA engine fill. - `dcbz_l` on a miss in both partitions allocates a locked line by pseudo-LRU among ways 4-7 and marks it M, with **no L2 or bus effect**. On a hit in either partition it zeroes the line, marks it M, sets HID2[DCHERR], and raises machine check if HID2[DCHEE] = MSR[EE] = MSR[ME] = 1 and DCHERR was clear (UM 9.2.2.2, 9.2.2.2.1). Alignment exception on write-through or cache-inhibited pages, or with the data cache disabled; illegal instruction with LCE = 0. - `dcbi`, `dcbf`, `dcbst`, `dcbt`, loads and stores act on whichever partition hits; a miss in both always fills the normal partition (UM 9.2.2.3-9.2.2.7). A `dcbf` or `dcbst` of a locked line casts it out to memory as any modified line would. - **The address of the locked cache is whatever address software allocates with `dcbz_l`.** It is a cache: there is no fixed "scratchpad address" in the hardware. GameCube software maps it through a BAT at 0xE0000000 (YAGCD 4.1 lists "0xE0000000 16k L2 Cache", which both misnames it and states a software convention as a map entry: contradiction C6, the UM wins; the BAT setup is HYPOTHESIS until the board sees it). What makes it safe is that such an address need not exist on the bus: a locked line is never filled from memory and only reaches the bus through DMA or an explicit cast-out. - "In Gekko, locked cache and bus snoop are incompatible" (UM 2.1.2.4). ## The DMA engine (DMAU SPR 922, DMAL SPR 923; UM 2.1.2.8, 9.3) - A command moves 1 to 128 cache lines (length field DMAU[27-31] || DMAL[28-29], **0 means 128**) between the locked cache (DMAL[LC_ADDR] || 0b00000) and memory (DMAU[MEM_ADDR] || 0b00000); DMAL[LD] = 1 loads from memory, 0 stores to memory. - `mtspr DMAL` with T = 1, F = 0 enqueues the command (latching DMAU and DMAL) and clears T; F = 1 flushes the queue including the command in progress. With LCE = 0 the registers read and write but T and F read as zero and nothing is queued. - **A 15-entry queue**, processed in order; HID2[DMAQL] counts queued commands including the one in progress. Enqueuing at 15 sets DQOERR and drops the command (machine check if enabled). - Per line: a tag lookup in the data cache; a **hit in the locked partition** moves 32 bytes (store: a write-with-flush burst; load: a burst read, transaction type 0b01011 for all but the last line, 0b01010 for the last, so a memory controller can prefetch); a **hit in the normal partition** moves nothing and sets DNCERR; a **miss** moves nothing and sets DCMERR; each optionally raises machine check. The lookup updates pseudo-LRU but not the MEI state. - `sync` waits for the queue to drain when HID0[ABE] = 0; `eieio` and `sync` otherwise do not affect it. - Timing (UM 9.3.3): one cycle to arbitrate for the tag, one to look it up, then a request to the bus interface unit, which serves DMA, instruction fetch and data misses first-come, first-served; two-entry store and load queues pipeline the transfers. - **For the board this is a bus master inside the CPU**: its bursts are 60x transactions like any other, interleaved with the CPU's own misses. Its progress is visible to software (DMAQL) and to other masters (memory contents), so its timing is part of the specification's order of record, not an implementation detail. ## The write-gather pipe (HID2[WPE], WPAR SPR 921; UM 2.1.2.10, 9.4) - A **128-byte circular FIFO**. With WPE = 1, every **non-cacheable store whose physical address equals WPAR[GB_ADDR] || 0b00000** is appended to the buffer (any width: byte, half, word, double, quantized). Whenever 32 or more bytes are buffered, 32 bytes go out as one write-with-flush burst to that same address. - `mtspr WPAR` sets the address and **discards** whatever the buffer holds. `mfspr WPAR` reads BNE (bit 31): buffer not empty. - A store to an address whose bits 0-26 match but whose bits 27-31 are not zero "will result in incorrect data in the buffer" (UM 9.4.2): U12, what exactly happens. The specification raises nothing and appends the data (HYPOTHESIS), and the case is listed for a hardware test. - The pipe ignores `eieio`, `stwcx.` and `sync`, and does not snoop. The only way to push out a partial block is to fill it (UM 9.4.2): software pads the GX FIFO with NOPs. - A store stalls when more than 120 bytes are pending (UM 9.4.3). The burst request is made the cycle after the 32nd byte arrives; a second may follow as soon as the first is being served. - **For the board**: the GameCube's GX command FIFO is fed this way (WPAR = 0x0C008000: YAGCD 4.1 and 5.11, "GX FIFO"; HYPOTHESIS that every title uses the pipe rather than plain uncached stores, which reach the same address one at a time). The core emits 32-byte bursts to the board's bus; Flipper's command processor sees only those. ## What the core reports to the board Every 60x transaction: kind (single-beat read or write, burst read, burst write with flush, and their transaction types), physical address, size, data, and which source made it (instruction fetch, data miss, cast-out, DMA, write-gather pipe), with the CPU time it was issued. The board answers with the time it completed. This is the core's only coupling to the machine.