# The CPU: CW33300 integer core, pipeline, delay slots, exceptions Sources (pins in `scripts/pinned_*.json`, tiers in validation.md): - **psx-spx** `docs/cpuspecifications.md` at `6d7d1bc` (tier 3: community document with hardware-tested statements; its README says parts were copied or rephrased from Sony's confidential SDK documents, so it is facts only and "not clean room"). - **LSI Logic LR33300/LR33310 Self-Embedding Processor User's Manual, chapters 1-4** (scans in ogamespec/psxdev `docs/`, CC0 repository; the manual itself is LSI's: facts only). The LR33300 is the packaged sibling of the CW33300 CoreWare core. OCR'd here with tesseract (2026-11-25); page citations are "LR33300 ch.N". - **ogamespec/psxdev** `wiki_eng/cpu.md` (tier 1-3: chip photographs and board tracing; CC0). ## The chip around the core (DIE, DOC) psxdev `wiki_eng/cpu.md` (photographs and service manuals): the CPU is one 208-pin chip, IC103, **CXD8530BQ / CXD8530CQ** (PU-7 to PU-16) and **CXD8606AQ/BQ/CQ** (PU-18 on, PSone), holding "a slightly modified LSI Logic CW33300 core", the GTE (COP2), the MDEC, a 7-channel DMA controller, the interrupt controller, the DRAM controller, the bus unit, SIO0/SIO1, the PIO port, three root counters, the instruction cache, the scratchpad "used instead of the data cache", and R- and W-buffers. Revisions: 90025 (PU-7, early PU-8), 90048 ("some bug in MDEC" fixed), 90082 (SCPH-5500 / PU-18 onwards), 90182 (late PSone PM-41(2)). The crystal is 67.7376 MHz; the CPU runs at half, **33.8688 MHz = 44,100 x 768** (psx-spx GPU timings; MAME lists the chip at 67,737,600 Hz, OBSERVED `-listxml`). **This repository owns the core, the COP0, the caches, the BCC register and the GTE.** Everything else on that die (MDEC, DMA, IRQ controller, timers, SIO, memory control) is a memory-mapped peripheral on the bus and belongs to psx-python (handoff-brief.md, import boundary). That split follows the bus, not the package. ## Programmer's model (DOC: psx-spx "CPU Registers"; LR33300 ch.1) 32 general registers (R0 reads zero), PC, HI, LO. No flags. MIPS I encoding: primary opcode bits 31-26, SPECIAL function bits 5-0, REGIMM (`BcondZ`) on rt; the tables are in psx-spx "CPU Opcode Encoding" and LR33300 ch.3. Every "N/A" primary or SPECIAL slot raises **Reserved Instruction (excode 0Ah)**; unused operand fields are ignored (psx-spx "Illegal Opcodes"). BcondZ decodes only rt bit 0 (BGEZ/BLTZ) and bits 4-1 = 1000b for the link forms; what the other rt values do is U3. Things the spec must state explicitly, each with its tag: | Behaviour | Evidence | | --- | --- | | ADD/ADDI/SUB trap on signed overflow (excode 0Ch) and leave rd unchanged | DOC psx-spx; TEST ROM amidog psxtest_cpu | | No exception on divide by zero: DIVU x/0 -> HI=x, LO=FFFFFFFFh; DIV x/0 -> HI=x, LO=-1 (x>=0) or +1 (x<0); DIV 80000000h/-1 -> HI=0, LO=80000000h | DOC psx-spx table; TEST ROM (amidog, PeterLemon CPUTest) | | Unaligned LW/LH/SH/SW: Address Error (AdEL 04h / AdES 05h), BadVaddr set, rt untouched | DOC psx-spx; LR33300 ch.4 | | LWL/LWR/SWL/SWR merge per the byte tables; LWL/LWR to the register a pending load targets merge with the **pending** value (no stall between them) | DOC psx-spx "Unaligned Load/Store"; the pending-value merge is the classic R3000 forwarding, HYPOTHESIS until amidog "advanced load" or the SST LWL/LWR cases confirm it | | 8/16-bit stores put all 32 GPR bits on the bus (a 32-bit I/O register sees the whole word) | DOC psx-spx "8/16-bit writes to certain IO registers" (the shell's sound scope relies on it). This is a **bus** fact: the core reports the full register and the size; the board decides | | BLTZAL/BGEZAL always write RA, taken or not; with rs=RA the comparison uses RA before linking | DOC psx-spx "jumps and branches" | | JR/JALR to an unaligned address: no exception at the jump; AdEL on the next fetch, EPC/BadVaddr = the bad target | DOC psx-spx; LR33300 ch.4 | | SYSCALL (08h) and BREAK (09h) act immediately (no delay slot) | DOC psx-spx | | RFE: SR bits 5-0 shift right by two, bits 5-4 kept | DOC psx-spx "RFE"; LR33300 ch.4 | ## The pipeline and the two delays (DOC LR33300 ch.1 and ch.3; DOC psx-spx) Five stages, IF RD ALU MEM WB, about one instruction per cycle from cache (LR33300 ch.1, fig. 1.6-1.7). Two architectural delays follow from it (LR33300 ch.3 sec 3.10, "The Delayed Instruction Slot"): - **Branch delay slot.** The instruction after a jump or branch always executes. Target = address of the delay-slot instruction + offset x 4 (ch.3 note 7). - **Load delay slot.** Loaded data reaches the register file at the end of MEM: too late for the next instruction's ALU stage, in time for the one after. The next instruction reads the **old** value. psx-spx adds an observation the spec must model: if an interrupt is taken between the load and the next instruction, the load completes during exception entry and the restarted instruction sees the new value. MFC0/MFC2/CFC2 have the same one-instruction delay (psx-spx; "reportedly two, but that seems to be nonsense" - one). Rules the spec has to decide and write down (the SingleStepTests r3000 state carries exactly these fields: `delay.load.{target,val}`, `delay.branch.{slot,take,target}`): 1. A second load to the same register in the delay slot of the first: the first load's write is cancelled (HYPOTHESIS, from the R3000 pipeline; judge: SST LW cases, amidog). 2. An ALU write in the load delay slot to the load's target: the ALU result is overwritten by the load at the end of the slot? or the load is cancelled? The common reading is that the ALU write wins (the load is dropped) - **U1**, judge SST + amidog "delayed load". 3. A branch in a branch delay slot (psx-spx calls these "unofficial branches"; amidog 1.1 tests them): behaviour is the plain pipeline consequence (the second branch's target follows one instruction of the first target) - HYPOTHESIS, judge amidog psxtest_cpu. ## Exceptions (DOC LR33300 ch.4; DOC psx-spx "COP0 - Exception Handling") Vectors: reset BFC00000h; general 80000080h (BEV=0) / BFC00180h (BEV=1); debug break 80000040h / BFC00140h; UTLB 80000000h (never used, no TLB). On entry: EPC = the faulting instruction, or the branch before it with CAUSE.BD=1 when the fault is in a delay slot; CAUSE.BT=1 and **TAR** (cop0r6) = the branch target when that branch was taken (psx-spx; TAR is a CW33300/LR33300 extension, not in the R3000A); SR's KU/IE stack pushes by two; ExcCode as psx-spx's table. Priority (psx-spx "Exception Priority", from the LR33300): reset > AdEL/AdES/DBE (data) > Ovf > Int > Sys/Bp/RI/CpU > AdEL/IBE (fetch). PlayStation-specific points the board depends on: - **Interrupts and GTE commands** (psx-spx "Interrupts vs GTE Commands"): when an interrupt is taken "on" a COP2 command, the command has executed but EPC points at it; the kernel's handler skips it. Crash Bandicoot, Spyro and Jinx draw broken geometry if this is wrong. The spec must say exactly at which pipeline point an interrupt is sampled relative to a COP2 command (**U2**; judges: amidog psxtest_cpx, a MAME trace of a kernel IRQ on a COP2 command, then the games). - The hardware interrupt input is CAUSE bit 10 (IP2), a level, driven by the board's `(I_STAT & I_MASK) != 0` (psx-spx "PSX specific COP0 Notes"); CAUSE.IP bits 11-15 are always 0; bits 8-9 are software interrupts (R/W latches). ## Timing (instruction level with bus transactions) The charter's level for this CPU: **instruction level with transaction timing** (every bus transaction with its cost; no per-pipeline-stage model unless evidence asks for one). Costs that must be modelled, all on the CPU's 33.8688 MHz clock: | Cost | Value | Evidence | | --- | --- | --- | | an instruction from the i-cache | 1 cycle | DOC LR33300 ch.1 | | an i-cache miss | a line refill from the fetched word to the end of the line (IBLKSZ), each word at the bus's cost | DOC psx-spx "i-Cache Fill behavior" (2026 edits marked "hardware testing") | | a load from main RAM | about 5 cycles per access, all sizes | TEST ROM ps1-tests `cpu/access-time/psx.log` (RAM 5.21 / 5.3 / 5.14 cycles for 8/16/32 bit) | | a load from the BIOS ROM (8-bit bus, default delays) | 7.6 / 12.94 / 24.94 cycles (8/16/32 bit) | TEST ROM same log | | a load from the scratchpad | ~1 cycle (1.5 / 1.1 / 0.94: measurement overhead) | TEST ROM same log | | loads from I/O | 3-4 cycles (most), CD-ROM 8/14/26, SPU 18/18/39 | TEST ROM same log | | a store | 1 cycle into the 4-word write queue; a full queue stalls; any KSEG1 access drains it | DOC psx-spx "Write queue", "Store instructions" | | MULT/MULTU | 6 / 9 / 13 cycles by the size of **rs** (thresholds 800h and 100000h; signed by magnitude) | DOC psx-spx table. **Contradicts** LR33300 ch.3 table 3.7: 4 / 7 / 12 cycles by "any operand" < 512 / < 256K (**C1**) | | DIV/DIVU | 36 cycles | DOC psx-spx | | MFHI/MFLO while busy | stall until done; "do not touch HI/LO in the next 2 cycles" rule not understood | DOC psx-spx (**U4**) | | load scheduling (LDSCH): a load does not stall unless the data is needed | one outstanding load | DOC LR33300 ch.3 "Load Scheduling", fig. 3.7 (the scan's `LR33300_Chap4.pdf` begins with that page); enabled by BCC bit 16 LDSCH, "usually 1" (psx-spx) | The bus cost of each access is the **board's** answer (memory control registers, DMA holding the bus): the core asks `read(address, size, kind) -> (value, cycles)` and charges what it is told. Load scheduling means the stall is charged when the loaded register is next read, not at the load: that is the main reason this core cannot be "one instruction = fixed cycles" (MAME's psx CPU appears to be: 16,951,337 instructions in each of two 1.001-second windows of the BIOS intro, exactly 1.998 cycles each - OBSERVED, docs/ mame-oracle.md; a property of MAME's model, not of the hardware). ## What is not here No TLB (TLBR/TLBWI/TLBWR/TLBP raise RI, psx-spx "COP0 - Misc"); no FPU (COP1, COP3 unusable); no reverse-endian (SR.RE "doesn't exist in PSX?", U5).