# Handoff: build `x86-p3-python`, the Xbox's Pentium III ## Context you are inheriting The family's shape: chips are cores, boards compose cores, CPUs always get their own core (charter). This core's first and only planned user is `xbox-python` (`../xbox-python`, Phase 0 done the same night; do not edit it from here). A board that finds a corner of this core raises it **on the core**. This is **era 4** in the charter's table in all but date: an out-of-order 32-bit CPU at 733 MHz, thin evidence for timing, instruction and transaction levels dominating, turbo with recompilation the only way to play. Read the late-era method proposal (`../emulator-lineage/docs/proposals/2026-11-late-era-method.md`) and the N64's execution architecture (`../n64-python/docs/execution-architecture.md`) before writing code: this core's gate cases are test programs and slices, and its time-keeping must be data from the first commit. Models to read before writing code: `z80-python` (the readability contract, docs layout), `sh2-python` (a decode table generated from a document, one small handler per instruction, a bus contract with `kind` bits), `r3000a-python` and `vr4300-python`'s briefs (era-3 CPUs: instruction level with bus transactions, caches in the specification), and `i8086-python`'s documents (the 8086 subset this core contains). Copy shapes, never code. Rules: Python >= 3.11, CPython and PyPy (classes under ~80 attributes: the register file and the descriptor caches want small objects); modern forms; local git only; MIT with SPDX headers; nothing read from GPL/LGPL emulators (Bochs, QEMU, 86Box, PCem, DOSBox, xemu, Cxbx-Reloaded); MAME closed (decision 4); no firmware, game bytes or MAME traces committed; Python that reads `reference/` runs with `-I`. ### Read in this order README.md; docs/scope-and-size.md; docs/timing.md; docs/system.md; docs/fpu-mmx-sse.md; docs/reuse.md; docs/validation.md; docs/mame-oracle.md; then `reference/text/` (run `python -I scripts/fetch_references.py --text`): SDM vol. 2 chapter 3 and appendix A (the opcode map), SDM vol. 3 chapters 2-5, 9 and 10, 245127-001 chapter 1 and appendices C and D; XED's `datafiles/xed-isa.txt` and `xed-chips.txt`; abaire's tests' sources. ## Scope In: the integer unit in real mode (the reset path and 16-bit forms) and 32-bit protected mode with segmentation, privilege levels 0 and 3, interrupt and trap gates and the TSS stack switch; paging with 4 KB and 4 MB pages and global pages; TLBs; L1 and L2 caches with MESI line states; store and write-combining buffers; MTRRs and PAT; x87, MMX, SSE; CPUID, RDTSC, RDMSR/WRMSR for the MSRs the Xbox touches; exceptions with error codes, double fault, shutdown; INTR/NMI/INIT/RESET inputs; the local APIC as state (disabled); the timing model of timing.md. Out (each a "not modelled" stop, so a board run finds out): virtual-8086 mode, task switches, call gates, SMM, PAE, PSE-36, SSE2 and later (#UD as on the part). Out (the board, xbox-python): RAM and the NV2A's memory controller, the flash, the MCPX ROM overlay and its hiding, PCI configuration space, every device and I/O port, the 8259s, the PIT and RTC. ## Proposed names - Repository `x86-p3-python`, package **`x86_p3_python`** (the 2026-11-12 naming rule). - `x86_p3_python.PentiumIII(bus, model=XBOX)`: the core; `model` is a small dataclass (CPUID signature and descriptors, L2 size and associativity, clock) so that the Xbox's Coppermine-128 is a configuration, not a subclass. `XBOX` is the only model until a second board wants another. - Modules: `decode/` (generated from XED: `_table.py`, committed with XED's Apache-2.0 notice; `gen_decode.py` in scripts/), `alu.py`, `x87.py`, `mmx.py`, `sse.py`, `segments.py`, `paging.py` (with `tlb.py`), `caches.py`, `wc.py`, `msr.py`, `exceptions.py`, `timing.py` (the cost tables as data), `bus.py` (the contract), `state.py` (a `CPUState` listing every processor-owned field), `disasm.py`. - Bus `kind` values as system.md lists them. ## Unknowns (U) and contradictions (C) - U1 The Xbox part's CPUID stepping and leaf-2 descriptors (abaire/nxdk_check_cpuid prints them; no hardware output published). - U2 The front-side bus clock: xboxdevwiki `Motherboard` r7356 (pinned in xbox-python) lists "733MHz CPU 133MHz FSB" (tier 3, community, no measurement cited); no Intel or Microsoft document gives it; the multiplier's source (strapping) is undocumented. - U3 x87 transcendental last bits on the P6 (no document; no capture). - U4 The RCPSS/RSQRTSS lookup behaviour behind abaire's "baseline bit patterns". - U5 When the hardware drains write-combining buffers apart from the architectural triggers. - U6 Whether Xbox titles run at ring 0 or ring 3 (sets how much privilege checking the board exercises). - U7 The TLB replacement rule (FITTED). - U8 DMA coherence: whether NV2A and MCPX bus masters snoop the CPU caches. - U9 Whether the kernel enables the local APIC. - U10 Which MSRs the kernel and titles touch. - C1 **L2 associativity**: SDM vol. 3 Table 10-1 lists P6-family L2s as 4-way; the Xbox's part is described as 8-way like the Coppermine Pentium III (Wikipedia and AnandTech by search, tier 3 at best) and the Coppermine-128 Celeron as 4-way. CPUID leaf 2 on an Xbox would settle it (U1). - C2 MAME's reset EFLAGS shows bit 21 set and bit 1 clear (00200000h); SDM vol. 3 Table 9-1 gives 00000002h. MAME detail; the specification follows Table 9-1. - C3 MAME boots BIOS 4134 and loops on 4817 (mame-oracle.md): an MCPX-version pairing in MAME, not a CPU fact. ## Milestones (rungs; exit tests in validation.md) 0. Tooling and decode: the XED-generated table, a disassembler checked against MAME's text on the BIOS 4134 trace, the state/trace/debug tools in z80-python's shape. 1. SingleStepTests 80386 real mode: every published case. 2. Host vectors (to write first: validation.md): defined results of user-mode integer, x87, MMX, SSE instructions. 3. abaire's Xbox CPU tests: all cases. 4. System architecture unit tests from SDM vol. 3. 5. MAME lockstep over the BIOS 4134 boot's first frame (player's firmware). 6. The timing model as data, FITTED, stated as such. 7. Seeded faults, each caught. ## Domains and speed **Domains and channels.** The CPU and its front-side bus are one domain (the board's "CPU domain"). Its channels are the bus transactions of system.md (uncached and write-combined accesses, line fills and write-backs, locked cycles, I/O, the interrupt acknowledge), the INTR/NMI inputs and the snoop hook. Sync points: every uncached or I/O transaction, every WC drain, every interrupt sample at an instruction boundary. Cache hits and TLB hits are not sync points. The other domains (NV2A front end, APU, DSPs, USB, IDE) are the board's (xbox-python domains-and-speed.md). **Instructions per second (the need).** - Clock 733.33 MHz (MAME lists 733,333,333 Hz, OBSERVED; xboxdevwiki `CPU`: 733 MHz, DOC). - A P6 retires up to three micro-ops per clock (245127-001); typical IPC on game code is not measured anywhere we found. HYPOTHESIS 0.55-1.0, so **R = 400-730 M x86 instructions per emulated second**, and bursts above that in tight loops. - MAME's boot window: 20,461,122 instructions in 1/30 s = 614 M/s (its own cost model, OBSERVED), inside that range. **Budgets** in desktop-equivalent host cycles per guest instruction (the N64 document's host assumptions: desktop 5.0e9, phone app 4.0e9, phone browser 2.4e9 per second): | R | Desktop | Phone app | Phone browser | | --- | ---: | ---: | ---: | | 400 M/s | 12.5 | 10.0 | 6.0 | | 730 M/s | 6.8 | 5.5 | 3.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 its stage scheduler (MEASURED, sh2-rust-fast docs/status.md, as ../n64-python/docs/execution-architecture.md reports it). An x86 interpreter has more decode work (variable length, prefixes, ModR/M and SIB, segment and paging checks on every access, lazy flags), offset by cheaper time-keeping if timing is data (timing.md option 3). HYPOTHESIS: **25-60 host cycles per instruction** for a well-made Rust -fast interpreter with a decoded- instruction cache keyed by physical page. The Python specification: HYPOTHESIS 0.1-0.5 M instructions/s on PyPy, i.e. **1/800 to 1/7,000 of real time**; a boot to the kernel's first frame is about 20 M instructions (MAME), so minutes; a boot to a game's first frame is billions (HYPOTHESIS), so hours to days. Slices are the only gate cases that fit (late-era method, section 1). **The no-JIT path, per target:** | Target | x-rust-fast interpreter | + cached interpreter | + threads at channels | Verdict | | --- | --- | --- | --- | --- | | Desktop | 25-60 cycles against 6.8-12.5: **2-9x short** | a block cache removes decode, not the segment/paging/flags work: perhaps x1.5-2 (HYPOTHESIS) | the CPU is one domain; threads help the board's other domains, not this one | **not real time** | | Phone app | 2.5-11x short | as above | as above | **not real time** | | Phone browser | 4-18x short | as above | as above | **not real time** | So **`recompile: none` does not reach real time on any target**, by a margin that no interpreter technique closes. Real time needs either **native recompilation** (x86 to the host ISA; on an x86 host the translation is close to the identity, with segment and paging checks hoisted per block and interrupts and channel accesses at block boundaries: turbo, `recompile: native`) or **hardware virtualisation** (the guest's code runs on an x86 host's own core under KVM, HVF or WHPX; xboxdevwiki `Emulators` r7319 lists XQEMU's KVM support; OBSERVED). Virtualisation is not in the charter's capability list, it breaks the per-instruction determinism the charter requires unless interrupts are delivered only at controlled exits, and it exists only on x86 hosts. It is a board decision (xbox-python decision X1). In the browser, `recompile: wasm` would have to translate x86 to WebAssembly at several hundred million instructions per second with the GPU work beside it: HYPOTHESIS out of reach. The honest answer for this core: **a readable specification and its transcription are in reach; the exact interpreter is a test oracle and a fallback; playing needs turbo with native recompilation on desktops, and phones and browsers are out of reach for commercial games.** ## Open decisions for Aubrey 1. **Scope: the Xbox's subset of IA-32**, with V86, task switches, call gates, SMM and PAE as "not modelled" stops. *Recommended*: the board finds out cheaply if any of them is reached; the specification stays a third shorter. 2. **The decode table generated from Intel's XED datafiles** (Apache-2.0), committed with the notice; the generator shared with i8086-python later, once both cores exist. *Recommended*: XED is Intel's own definition, readable as data, and permissive. 3. **x87 transcendentals**: correctly rounded results with the documented flags, marked HYPOTHESIS, until a capture on an Xbox exists (U3). *Recommended*: it is the only choice that is defined and honest; the host's x87 is a later microcode and not a P6 judge. 4. **MAME's BSD-3-Clause i386 and Xbox files stay closed.** *Recommended*: closed, as in tonight's other Phase 0s; Intel's documents and the tests suffice, and MAME's Xbox driver is preliminary. 5. **A host vector generator** (validation.md) as rung 2, tier 1 "for an IA-32 processor's defined results", with the CPU model in each corpus header and the README stating the limit. *Recommended*: it is the only per-instruction hardware corpus beyond the 386EX that the family can make without an Xbox. 6. **Hardware probes need an Xbox** (CPUID leaf 2 for C1, RDTSC timing chains for the model, transcendental and RCP tables). The family has none (memory: hardware on hand is a Super Famicom and an early Genesis). *Recommended*: queue them in the probe batch as "needs an Xbox"; asking abaire, whose suites already run on a 1.0 Xbox, is an outside contact and so Aubrey's call. 7. **Agner Fog's instruction tables** (measured P6 latencies, tier 3): his site's robots.txt does not block AI agents; the document's terms were not checked tonight. *Recommended*: check the terms, then pin as facts only for the timing model. 8. **The timing claim**: "time is the specification's model, FITTED in aggregate, not the hardware's cycles" in the README, the charter's tier rule held between tiers. *Recommended*: yes; it is the only true sentence available. 9. **Default provisional choices** (Aubrey's 2026-11-12 rule): L2 8-way (C1), titles at ring 0 (U6), APIC disabled (U9), WC drains only on architectural triggers (U5), TLB replacement round-robin per set (U7). Each marked HYPOTHESIS in code.