# CP0, exceptions, caches and timing ## CP0 registers (DOC: YAPSPD 4.3, 5.3; register users there are Sony kernel module names) Two register spaces, both used by the kernel: the MFC0/MTC0 "status" registers and a second CFC0/CTC0 "control" space of 32 words that the kernel uses as scratch storage for exception contexts (YAPSPD 4.3.2: EPC, saved v0/v1, the exception vector table, the syscall table, SC_MAX, the kernel and user stack pointers, the current thread control block, the profiler base...). The second space is Sony's, not MIPS's: the core holds it as 32 plain registers whose meaning is the kernel's (U9: whether any bit of it has hardware meaning). | # | Name | Access | Notes | | --- | --- | --- | --- | | 0-6, 10, 20 | - | - | "not available (TLB)": no TLB on the part | | 8 | BadVAddr | r | | | 9 | Count | r/w | | | 11 | Compare | r/w | the timer interrupt, as MIPS (U10: which IP bit) | | 12 | Status | r/w | IE, EXL, ERL, KSU (user/supervisor/kernel: Copetti; YAPSPD 7.1), CU bits | | 13 | Cause | r/w | ExcCode table: YAPSPD 9.1 | | 14 | EPC | r/w | | | 15 | PRId | r | value: U12 | | 16 | Config | r (ME) / r/w | cache sizes are read from here by the kernel (YAPSPD lists `utils` as a user) | | 21 | SCCode | r | the SYSCALL code << 2: the kernel's dispatcher reads it (YAPSPD 4.3.1) | | 22 | CPUId | r | 0 = main CPU, 1 = Media Engine: the one register that tells the two instances apart | | 25 | EBase | r/w | exception vector base (the ME's is set here too: YAPSPD 5.1) | | 28, 29 | TagLo, TagHi | r/w | cache tag access for CACHE index load/store tag | | 30 | ErrorEPC | r/w | | | 7, 17-19, 23, 24, 26, 27, 31 | ? | | YAPSPD: unknown (Watch, Cache ECC/Error guessed); U9 | Debug registers DRCNTL, DEPC, DDATA0/1, IBC, DBC, IBA, IBAM, DBA, DBAM, DBD, DBDM (YAPSPD 4.2) and a debug vector at 0xBFC01000 (YAPSPD 9.6): out of scope for M1 (no game uses them; U14). **The interrupt latch (MFIC/MTIC).** A single register reached by SPECIAL2 functions 0x24 and 0x26; writing 0 disables interrupts, writing the saved value restores them (YAPSPD 4.8.2). The Sleigh notes that "the same register is selected for all RD values" (tier 5). The core models it as one bit or word ANDed with Status.IE (U1: its exact relation to Status.IE). ## Exceptions (DOC: YAPSPD 9; TEST ROM: `cpu/cop0/eret`, `cpu/crash/*`) - Reset, NMI and the "error" vector: 0xBFC00000 (YAPSPD 9.2: "Reset Vector (HW,SW,NMI)"). The main CPU's reset vector is the Pre-IPL ROM (Copetti, Kernel/IPL); the ME's is RAM the main CPU writes (YAPSPD 9.2.1 "ME Reset Handler"; psp-python). - General exceptions and interrupts: EBase (YAPSPD 9.3). - Cause codes include the MIPS set plus "VCED ... called 'Error' on the PSP" for code 31 (YAPSPD 9.1). Address errors on unaligned loads and stores, bus errors from the board's protection registers (psp-python). - ERET clears ERL if set, else EXL, and does not execute the next instruction (`cop0/eret.expected`, recorded on a PSP). ## Caches (DOC: YAPSPD 4.10, Copetti; TEST ROM: `lsu/cacheop`, `icache/icache`) - 16 KB instruction, 16 KB data, 64-byte lines (16 words: `cacheop` "line granularity", "next line untouched"), write-back with write-allocate, no snooping: DMA and the GE do not see dirty lines, and the CPU does not see DMA writes over valid lines. - **The caches are in the specification, not an optimisation.** Software-visible results depend on them: a store through KU0 then a read through KU1 (+0x40000000) sees the old value until a writeback (`cacheop.expected`: "after cached store: cached=2 uncached=1"). The GE reads display lists from memory, so a game that forgets a writeback draws garbage on hardware (YAPSPD 4.10.2), and that is a behaviour to reproduce. - **The instruction cache:** `icache/icache.expected` holds two lines ("1", "2"): the test shows stale instructions after a code write without an invalidate (U15: read the test's intent before rung 4; pspautotests' `not_working_on_real_psp.txt` lists `icache`, so this test may itself not run on hardware: the judge is doubtful). - CACHE operation numbers on the PSP: 0x19 Hit Invalidate (D), 0x1A Hit Writeback (D), 0x1B Hit Writeback Invalidate (D) from `cacheop`; the rest of the table is to be filled from the kernel's use (YAPSPD 4.10.4 lists the kernel functions that wrap them) and tests (U16). MIPS32's numbering puts D-cache Hit Invalidate at 0x11: the PSP's differs (C5). - Associativity and replacement: unknown (U8). The PSP-1000 measurement below shows a 16 KB working set fitting and 32 KB not; it does not tell 2-way from direct-mapped. ## Timing (MEASURED by a third party; HYPOTHESIS where noted) The only cycle measurements found are the VFPU documentation's reference outputs, run by its author (davidgfnet) on real units. We did not see the runs; their files say so in their headers. Values are cycles of the CPU clock, averaged over loops (hence 1.03, not 1). | Measurement | Value (cycles) | Unit | | --- | --- | --- | | J / JR taken, latency | 3.05 / 3.06 | PSP-3000 | | BEQ taken | 4.07 | PSP-3000 | | MULT throughput / latency | 1.03 / 7.08 | PSP-3000 | | DIV throughput / latency | 20.2 / 21.3 | PSP-3000 | | FPU add.s, mul.s latency | 5.05 | PSP-3000 | | FPU div.s / sqrt.s latency | 31.3 / 30.3 | PSP-3000 | | Load latency, sequential, buffer <= 16 KB | 3.04-3.10 | PSP-1000 | | Load latency, sequential, buffer >= 32 KB | 6.40 | PSP-1000 | | Load latency, random, 4 MB buffer | 72.5 | PSP-1000 (a miss to DDR) | | LW throughput, buffer >= 32 KB | 4.52 per word (0.88 bytes/cycle) | PSP-1000 | | LV.Q throughput, buffer <= 8 KB / >= 32 KB | 1.07 / 7.97 per quad | PSP-1000 | What the model takes from this (HYPOTHESIS until rung 5): an interlocked single-issue pipeline whose costs are a static table per instruction plus a load-use interlock, a multiply/divide unit with a busy time, an FPU and a VFPU with their own latencies, and a miss cost that depends on the line refill. The 64-byte line and the 6.4-cycle sequential latency (about 102 cycles per 16-word line, against 72 for a random word) suggest critical-word-first refills: a question for rung 5, not a fact (U17). **The clock is a board parameter.** The PSP-3000 and PSP-1000 runs above do not say which clock the CPU ran at (222 or 333 MHz); cycle counts in the CPU's own clock do not depend on it, but **the DDR miss cost does**, because memory runs on the bus clock (U13). The board will state the ratio. ## The scratchpad 16 KB at physical 0x00010000 (YAPSPD 7.2), reachable by the CPU and the GE (Copetti, "16 KB SRAM"). Whether the core decodes it (as r3000a-python's scratchpad) or the board does is U7; the brief recommends the board, because the GE and DMA also reach it.