# Handoff: build `ee-python`, the PlayStation 2's EE Core ## Context you are inheriting Chips are cores, boards compose cores, CPUs always get their own core (charter). This core's only user is `ps2-python` (`../ps2-python`, Phase 0 written beside this one); a board that finds a corner of this core raises it **on the core**. Era 4 (charter): thin evidence, instruction and functional levels dominate, turbo with recompilation, named concessions likely on weak targets. Read `../emulator-lineage/docs/proposals/ 2026-11-late-era-method.md` (slices, x-rust as the first runnable tier, shared state format) and `../n64-python/docs/execution-architecture.md` (the time-keeping lesson) before writing code; this machine is the hardest case of both. Nearest models in the family: - `vr4300-python` (`../vr4300-python`): MIPS III, 64-bit, CP0/TLB, caches with direct-mapped no-LRU tags, an instruction-level timing model with stall rules. The EE Core is its cousin: copy its shape, never its code. - `r3000a-python` (`../r3000a-python`): the bus contract with `kind` bits, the scratchpad answered by the core, the coprocessor protocol (`Coprocessor`), the GTE as a COP2 that the core interlocks with. - `rsp-python` (`../rsp-python`): a vector unit with its own repository (the precedent for decision E6). - `sh2-python`: the readability contract and the handler subset (JIT proposal, J2). Rules: Python >= 3.11, CPython and PyPy; modern forms; MIT; nothing read from GPL emulators (PCSX2, DobieStation); MAME closed; Play! readable with its notice; Sony's manuals facts only; no BIOS or game bytes committed; run Python that reads `reference/` with `-I`; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; docs/isa.md; docs/cop0-tlb-caches.md; docs/fpu.md; docs/pipeline-timing.md; docs/vu.md; docs/validation.md; docs/mame-oracle.md; docs/sources-ee.md; then ECUM ch. 1-2, 5-6, 8 in full and ECISM for each instruction as you write its handler; ps2-python's docs/memory-map.md for what the board answers. ## Scope In: the EE Core: 128-bit GPRs, HI/LO with HI1/LO1, SA, PC; the integer, MIPS IV subset, EE-specific multiply and MMI instruction sets; COP0 (all registers, both exception levels, the breakpoint and performance-counter registers); the TLB with ITLB/DTLB; the I-cache, D-cache (line lock), BTAC/BHT state reachable by CACHE; the scratchpad (owned here, reached by the board's DMAC through two methods); the WBB and UCAB as transaction shapers; COP1 (the FPU) as `ee_python.fpu`; the COP2 socket. Out: VU0 and VU1 (vu-python, decision E6; until then a stub behind the socket), VIF, GIF, DMAC, INTC, timers, IPU, SIF, main memory and its controller, the GS (all ps2-python); hosts, windows, sites. ## Proposed names - Repository `ee-python`, package **`ee_python`**. - `ee_python.EECore`: the core as Sony configured it (C790, 16 KB I-cache, 8 KB D-cache, 16 KB SPRAM, 48-entry TLB). No generic `C790` base class until a second configuration appears. - `ee_python.fpu.FPU` (COP1, inside the core: it shares the C1 pipe and I0); integer-only float arithmetic. - `ee_python.coprocessor.Coprocessor2`: the COP2 protocol (`move_from(reg, interlock)`, `move_to(reg, value, interlock)`, `control_from/to`, `operate(word)`, `call_micro(addr)`, `busy_until()`); `ee_python.coprocessor.AbsentCop2` raises CpU. - `bus.py`: `read(physical, size, kind) -> (value, cycles)`, `write(physical, size, value, kind) -> cycles`, sizes 1/2/4/8/16 bytes, `kind` bits `FETCH`, `FILL`, `WRITEBACK`, `UNCACHED`, `ACCEL` (uncached accelerated: UCAB fill or WBB gather), `WRITE`, observe-only `HIT`. - `run(cycles)` runs to a cycle budget and returns at an instruction-pair boundary; `set_int0(level)`, `set_int1(level)` drive the two interrupt lines; `spram_read(index)`, `spram_write(index, qword)` for the DMAC. ## Import boundary The core imports nothing of the family's except, when decision E6 lands, nothing either: the COP2 object is passed in by the board. The board imports `ee_python` and `vu_python`. The core never imports the board. ## Unknowns (U) and contradictions (C) - U1 What DMULT/DMULTU/DDIV/DDIVU/LL/LLD/SC/SCD do when executed (ECUM §2.2.2 says only "not supported"). isa.md. - U2 The short-loop erratum's effect. isa.md. - U3 HI/LO after divide by zero and 80000000h / -1 (ps2autotests `muldiv` decides). isa.md. - U4 The EE's PRId value. cop0-tlb-caches.md. - U5 ITLB/DTLB coherency after TLB writes. - U6 CACHE operations on a scratchpad-mapped page. - U7 WBB behaviour on a same-address store of another size. - U8 UCAB invalidation. - U9 The FPU's truncating datapath. fpu.md. - U10 MADD.S rounding (once or twice). - U11 RSQRT precision and flags. - U12 MAX/MIN on exponent-255 values. - U13 BHT update rule, misprediction penalty. pipeline-timing.md. - U14 Main-memory latency per access kind (the board's). - U15 The "Y" pairing stall's exact cycle. - U16 A non-blocking load's destination overwritten before the load returns. - U17 VU vs COP1 truncation. vu.md. - U18 Macro-mode COP2 moves without `.I` while a micro subroutine runs. - U19 VU0 reads of VU1's registers at 4000h-43FFh mid-update. - U20 EFU precision. - U21 Which console revision produced ps2autotests' `.expected` files. - C1 Float-to-integer overflow: ECUM Table 8-4 "no flag" vs Table 8-6 "I (SI) set". fpu.md. - C2 The bus clock: Sony's EE User's Manual says 147.456 MHz; the GS manual states its rates at "150 MHz" (ps2-python docs/gs.md). Nominal vs actual, most likely; the core only needs the 2:1 ratio, which ECUM §6.3.3 states. - C3 TX79 copies: the pinned bitsavers r2.0 and the DarrenRainey copy have different SHA-256s with the same page count (727); to compare page by page before citing a page number from the second. ## Milestones Rungs 0-7 in validation.md, in order. The Python core's job is correctness only. ## Domains and speed **Domains and channels.** The EE Core is the heart of ps2-python's domain A (EE core, VU0, DMAC, INTC, timers, SIF's EE side, scratchpad, IPU front end; ps2-python docs/domains.md). Its channels: the CPU bus (every uncached, accelerated and refill transaction, timed by the board), INT0/INT1, the SPRAM ports used by DMA channels 8/9, and the COP2 socket to VU0. VU1, the GS back end, the IOP side and the SPU2 are other domains (ps2-python). **The need, with the arithmetic shown** (desktop-equivalent host cycles per guest instruction on one core: desktop 5.0e9 / R, phone app 4.0e9 / R, phone browser 2.4e9 / R, the ratios n64-python and psx-python use; HYPOTHESIS until measured): | EE rate `R` | Basis | Desktop | Phone app | Browser | | --- | --- | ---: | ---: | ---: | | 589.8 M instr/s | peak: 2 per cycle x 294.912 MHz (DOC) | 8.5 | 6.8 | 4.1 | | 295 M instr/s | 1.0 IPC (HYPOTHESIS: dual issue offset by misses and stalls) | 17 | 14 | 8.1 | | 150 M instr/s | 0.5 IPC (HYPOTHESIS: a cache-miss-heavy game) | 33 | 27 | 16 | | 258 M instr/s | MAME's charge in a BIOS delay loop (OBSERVED, not hardware) | 19 | 16 | 9.3 | **What an exact interpreter costs.** The family's measured yardstick is sh2-rust-fast, about 89-145 host cycles per SH-2 instruction with a stage scheduler (MEASURED, sh2-rust-fast docs/status.md); n64-python estimates 25-60 for a MIPS core with timing as data, a scoreboard and one deadline compare (HYPOTHESIS). The EE adds dual-issue pairing (Table 1-3 per pair), a 128-bit register file, two MACs, the WBB/UCAB and a 2-way LRF cache. Estimate for ee-rust-fast: **30-70 cycles per instruction** (HYPOTHESIS). **Does the no-JIT path reach real time?** - **ee-rust-fast** (exact interpreter, timing as data): 30-70 against a need of 17-33 at typical rates: **no, on every target**, by 1.5-4x on a desktop core. - **A cached interpreter** keyed by I-cache line (exact for cached code, because hits do not change LRF: cop0-tlb-caches.md) and **memoized block timing** with the pairing of a block precomputed for its entry scoreboard state: the SH-2 study puts the decode at 3.6 %, so the gain is the fetch path plus pairing and timing work, perhaps to **12-25 cycles** (HYPOTHESIS). That would reach real time on a fast desktop core for games near 0.5-1.0 IPC, and **not on a phone app (14-27 needed against 12-25 available only at the low end) and not in a browser (8-16)**. - **Threads** do not help the EE itself: it is one instruction stream. They help by moving everything else off its core (VU1, the GS back end, the IOP, the SPU2), which the board's plan does. - **So:** on a phone and in a browser, the EE needs either `recompile: native | wasm` where allowed (Android apps, desktop, the browser's wasm path), or **named concessions** where not (native iOS): first a timing concession (a fixed cost per instruction and no pairing/cache-timing model: "EE coarse timing", which changes observables such as when stores reach the VIF), then inexact idle-loop skipping (the BIOS and many games spin on Count or on status registers). Play!'s README says a game launched without JIT on iOS crashes (OBSERVED, README at `1f27232`): the one permissive PS2 emulator we can read does not offer an interpreter path for play. The family's path is no different in kind, only honest about it in the capability record. **What the Python specification can be.** A PyPy instruction rate of 0.05-0.3 M/s (HYPOTHESIS, from vr4300-python's 0.02-0.2 and sh2-python's 0.1-0.2; 128-bit MMI values are plain Python ints) is 1/500 to 1/12,000 of the EE's typical rate: a 60 Hz frame of EE code (2.5-10 M instructions) takes 10 s to 3 min. The specification therefore runs **the test programs (seconds each) and short slices** from states transplanted out of ee-rust/ps2-rust (late-era method L1-L3), never a boot. ## Open decisions for Aubrey - **E1. Modelling level: instruction level with issue pairing, interlocks, scoreboard and bus transactions; no per-stage model.** *Recommend* yes (pipeline-timing.md): the structure is in the manuals, the constants are not, and no judge could check stages. - **E2. ECUM Tables 1-1 to 1-3 and §2.12 as typed fact tables** (pipe class, pairing, latency) from which the scheduler is driven: timing as data (JIT proposal, J2). *Recommend* yes. - **E3. WBB and UCAB in the core as transaction shapers** (when and how large each bus access is), with their gathering rules from ECUM §5.2.6/§6.5. *Recommend* yes: the board sees the sizes (GS and VIF registers). - **E4. Interrupts sampled at instruction-pair boundaries**, with the exact sampling point in a pair as U-item to be judged by `kernel/ee/interrupt/*` (ps2autotests) on the board. *Recommend* yes, marked HYPOTHESIS. - **E5. The COP2 socket** as named in "Proposed names", with the `.I` interlock as a call. *Recommend* yes. - **E6. VU0/VU1 in their own core repository `vu-python`**, one core in two configurations; VIF and GIF stay in ps2-python. *Recommend* yes (vu.md: the CPU rule; the RSP precedent). If accepted, vu-python gets its own Phase 0 next, and docs/vu.md moves there with its history. - **E7. Forbidden instruction sequences** (ECUM §1.3.6) and the short-loop shape logged as events, not given invented behaviour. *Recommend* yes, until a console shows what happens. - **E8. A test-harness syscall shim** (tests/ only, never a BIOS model) so the core's rungs run ps2autotests ELFs without booting a BIOS. *Recommend* yes; ps2-python never uses it. - **E9. MAME's BSD-3 PS2 device files stay closed**, as the psx ones. *Recommend* yes. - **E10. No PS2 hardware probes are possible** (the family owns no PS2): the timing constants stay FITTED/HYPOTHESIS. If Aubrey ever acquires a PS2 with homebrew access, the probe list (Count around pairing cases, the short loop, divide by zero, U-items marked "probe") is ready to batch. *Recommend* noting it in the probe queue, nothing more.