# COP0, the instruction cache, the scratchpad and the BCC register Sources: psx-spx `cpuspecifications.md` (COP0 sections), `memorymap.md` (i-Cache, Scratchpad, Write queue), `memorycontrol.md` (FFFE0130h BCC) at `6d7d1bc`; LR33300 ch.1 and ch.4. Several i-cache paragraphs in psx-spx were added in 2025-2026 and say "hardware testing shows": tier 3, cite them as TEST ROM / OBSERVED-on-hardware only once a test program that shows it is pinned (U6). ## COP0 registers (DOC psx-spx "COP0 - Register Summary") | Reg | Name | Notes | | --- | --- | --- | | r3 | BPC | breakpoint PC (R/W) | | r5 | BDA | breakpoint data address | | r6 | TAR | branch target on an exception in a taken branch's delay slot (R) | | r7 | DCIC | debug and cache-invalidate control; bits 12-13 "jump redirection" barely understood (U7) | | r8 | BadVaddr | updated **only** by AdEL/AdES | | r9 | BDAM | data breakpoint mask | | r11 | BPCM | PC breakpoint mask | | r12 | SR | IEc/KUc/IEp/KUp/IEo/KUo, IM 8-15, IsC 16, SwC 17, PZ 18, CM 19, PE 20, TS 21, BEV 22, RE 25, CU0-3 28-31 | | r13 | CAUSE | ExcCode 2-6, Sw 8-9 (R/W), IP 10-15, CE 28-29, BT 30, BD 31 | | r14 | EPC | | | r15 | PRId | 00000002h on a CXD8606CQ (psx-spx); other chips unknown (U8) | | r0-2, r4, r10, r32-63 | none | reading raises RI (excode 0Ah) | | r16-31 | "garbage" | readable without exception even in user mode with CU0=0; the value echoes a recently read register, then 20h/40h/100h later (psx-spx, unexplained: U9) | LWC0/SWC0 and BC0F/BC0T raise **Coprocessor Unusable** (0Bh), not RI (psx-spx). The debug break goes to 80000040h with ExcCode 09h; BREAK goes to 80000080h. Legacy of Kain: Soul Reaver hides LibCrypt values in the debug registers (psx-spx), so they must hold what is written even when no breakpoint is enabled. The CU2 enable bit "acts delayed, about 2 cycles" (psx-spx "Store Delay"; U10). ## Instruction cache (DOC psx-spx memorymap.md "i-Cache"; LR33300 ch.1) - 4 KB, direct mapped, 256 lines x 4 words; index = address bits 11-4. - Tag = **physical** address bits 31-12 plus four per-word valid bits; KUSEG and KSEG0 share tags; KSEG1 bypasses the cache. - Miss fill: from the missed word to the end of the line, no wrap (word 0 -> 0Fh valid, word 3 -> 08h). With BCC.IBLKSZ=0 a word-0 miss fills two words. A tag match with an invalid word is a miss that refills **all four** words. (2026 psx-spx edits, "hardware testing"; U6.) - Stores never touch the i-cache: code overwritten in RAM keeps running from the cache until flushed. Formula One 2001 relies on it (psx-spx). - Flush: BCC = TAG|IS1, SR.IsC=1, store 0 at each line's base; stores in TAG mode write `(data & 0Fh) | (offset & FFFFF000h)` into the tag. TAG-mode loads return valid bits in 3-0 and a match bit in 4 (psx-spx memorycontrol.md BCC). - With IsC=1 and IS1 only, stores write cache code words (the kernel's flush loop). - SwC (SR bit 17): "no observable effect on PSX" (psx-spx, hardware testing). This cache is observable timing (amidog's `where_am_i`, `pipe_line` and `no_code` demos abuse it, and the i-cache decides how many cycles a loop takes), so it is **in the specification**, not an optimisation. ## Scratchpad (DOC psx-spx "Scratchpad") The D-cache in scratchpad mode: 1 KB at 1F800000h-1F8003FFh, mirrored in KUSEG and KSEG0 only (not KSEG1), about one cycle per access (ps1-tests access-time, TEST ROM). **Not executable**: a fetch from it is a bus error on the first instruction (psx-spx). BCC bits 3 (RAM) and 7 (DS) control it; DS=0 "disables scratchpad"; DBLKSZ and a real data cache are "broken" (psx-spx). The LR33300 data sheet gives its part 2 KB of D-cache (LR33300 ch.1 table 1.2); the PlayStation's is 1 KB (**C2**; the PlayStation value is the one software sees, tier 3, and the CW33300 configuration Sony chose is not documented). ## BCC, FFFE0130h (DOC psx-spx memorycontrol.md, "chapter 14 of the LSI L64360 data sheet") Bits: 0 LOCK, 1 INV, 2 TAG, 3 RAM, 4-5 DBLKSZ, 7 DS, 8-9 IBLKSZ (2-3 crash), 11 IS1, 12 INTP, 13 RDPRI, 14 NOPAD, 15 BGNT, 16 LDSCH, 17 NOSTR. The kernel writes it during the flush. Only FFFE0130h is known to do anything in KSEG2 (U11: what other FFFE0xxx addresses return). ## Write queue (DOC psx-spx memorymap.md "Write queue") Four words, pass-through. A read of an address in the queue flushes the queue first. Any KSEG1 access stalls until the queue drains. I/O written through KUSEG/KSEG0 is queued, so writes and reads to devices reach them **reordered** relative to program order (the flash example in psx-spx). The core owns the queue; the board sees its drained writes in queue order at the time they leave. This ordering is what a device sees, so it is part of the per-cycle trace the Rust tiers must reproduce. ## The memory segments the core decodes KUSEG 0-7FFFFFFFh (only the first 512 MB mirror physical memory; the rest raises an address error in the core? or a bus error from the board? - U12), KSEG0 80000000h (cached), KSEG1 A0000000h (uncached, no write queue), KSEG2 C0000000h+ (only the cache control register). The core strips the segment to a 29-bit physical address and tells the board the physical address and whether the access was cached. The scratchpad (1F800000h-1F8003FFh through KUSEG/KSEG0) and FFFE0130h are answered inside the core; every other physical address is the board's.