7 Commits
Author SHA1 Message Date
ArzarothandClaude Opus 5.5 543ed5f390 [sc3/cop0-perf] feat(recomp): register 25's select reaches bozo_cop0_read and bozo_cop0_write
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 23:14:49 +01:00
Thomas MartinandCodex f715d57887 Replace selected hardware instructions with native port operations
Allow ports to replace output instructions and completion tests before MMIO, including delay slots. Keep original instructions and store PCs for reference checkers, and guard retired graphics I/O in native mode. Native draws no longer need GS environment register mirroring.

Validation: five CTest checks pass, including all 146 instruction cases and six new native replacement/completion cases; TMB windowed movies and four-player gameplay pass with the graphics guard enabled.

Co-Authored-By: Codex <[email protected]>
2026-11-06 11:18:08 +01:00
Thomas MartinandClaude Opus 5.5 60a8d50e1f Phase 4 M0: a port's overrides run natively (bozo/port.h), the free host, the renderer's game side and the packs moved
TMB_Recomp's runtime builds on BozoEngine (its branch bozo/m0, cmake -DTMB_BOZO=ON): its overrides run natively, each
call checked against the reference's log (tmb-check), and with no log at all (tmb-headless).

- Port API (runtime/include/bozo/port.h, bozo_port): Registry::registerFunction, BOZO_PORT, the startup check that
  every registered override is an external of the generated code (port::undeclared), and what overrides use: the
  kernel (changePriority, rotateReadyQueue, transfer), the EE clock (now, accountCycles), vblankCount, the hardware
  registers (ioRead32 / ioWrite32: a port's own access), frameEnd, callLibrary, scratchpad, libraries, deterministic,
  realTime, setStorePatch. A port::Host is behind them.
- Overrides that run guest code (kernel.md section 3b): checkpoints charge, no event is taken in place; an event due,
  a call that blocks, a jump through a register, an inner call's return and a recursive call's return make guest code
  leave the override there, the stop deferred to its end (Dispatcher::beginOutcall / leave / takeDeferredStop); the
  override's own code runs on, as the reference's did; no exception goes through it. Every rule settled on a record.
- Generated code: bozo::checkpoint and bozo::innerReturn return true when guest code leaves, the check after each
  call tests ctx->leaving, a recursive call's return inside an override calls bozo_leave; ctx->outcall,
  ctx->leaving; the externals table (<prefix>_external_table); "store 0xADDR" externals (the store sets ctx->pc first).
- bozo-externals (tools/externals): the --externals list from the ELF's symbols BozoEngine answers, a port's stub names
  and its override list; --check compares the stubs with a call log's.
- bozo-run as a library (bozo_run, run_main.h): a port's checker links it with its generated code and overrides,
  which run natively (--overrides native|log); LogHost checks each call (context words, memory runs, traced calls, the
  operations and frame end inside, where it left) and pins where the reference's override left and whether a timed
  call inside it waited. The renderer's draw lists fill the record's draws (reported).
- The free host (runtime/host/free_host.cpp, bozo_host): every out-call native, libraries bound by the ELF's symbols,
  free timing, a watchdog when no frame ends.
- Moved from the team's fork code (phase4-inventory.md 2.1, MIT headers): the renderer's game side
  (bozo/render/renderer.h, renderer.cpp: headless, recording the published lists and their hash), Texture,
  the texture and mesh packs, mesh_draw, the movie picture hook, the FramePacer (unpaced off real time) and
  determinism.h (settable by the host).
- Libraries, from what only ran inside overrides before: sceGsExecLoadImage (0, no upload), T8H/T4HL/T4HH image tags as
  32-bit texels, the GS CSR's FIELD, sceSifSetDma raising SIF0's DMAC interrupt, CPCOND0 counting completions from
  the last FlushCache, a port's own register accesses, RotateThreadReadyQueue returning 0, libmpeg calling the movie
  picture hook, PadState::multitap.
- BOZO_BUILD_TOOLS (zlib-free configure for a port), the tests only when top level.

Results: TMB boot --pinned with every override native, 3000 of 3000 frames and 4,650,558 of 4,650,558 records (ram,
scratchpad, calls, threads); match1p: see docs/phase4-m0-notes.md. bozo-run without a port still matches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 11:02:09 +01:00
Thomas MartinandClaude Opus 5.5 c53d7f231c Phase 2: the EE kernel, the dispatcher and bozo-run (TMB boot: frames 0-1614 equal to boot.ref)
runtime/ee: BozoEngine's own EE kernel (threads, ready queues, semaphores, INTC and DMAC handlers and their
queue, the vblank, the kernel calls TMB makes) and dispatcher (runs guest code on the kernel's threads and stacked
handlers, the reference's cycle model, stops by unwinding and resumes through the resume entries, time slices).
runtime/harness: the PS2XREF1 record (writer, reader, the calls and threads hashes). bozo/hash.h: XXH64, FNV-1a.

tools/run: bozo-run, TMB's generated code on that kernel with every other out-call answered from a call log and
every decision checked record by record against it; bozo-calllog-tool lists a log's external addresses for the
generator. Recompiler: jumps through a register go through bozo_jump (the reference's dispatcher), except the jump
tables it resolves itself (built in place); direct tail jumps are not charged; tail calls to externals go through
bozo_tail_call (the reference's record of calls only has jal and jalr).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 13:03:35 +01:00
Thomas MartinandClaude Opus 5.5 852947ae04 Recompiler: the reference's EE time model and resume entries
Checkpoints now charge what calllog.md section 2 says the reference charges: 32 cycles at a taken backward branch or
jump to a label of the same function, 8 at a call or jump leaving the function (made before the transfer, with the
transfer's target in ctx->pc, so a thread stopped there resumes at the target), nothing at function entry or at a
return. A return leaves its target in ctx->pc.

Every function is now entered through a body taking an entry pc: its start, its extra entries, every label and the
return address after each call. The resume table (<prefix>_resume_table: each function's range and resume_0x<start>,
which enters it at ctx->pc) is how the phase 2 dispatcher runs a thread on from where it stopped, as the reference
does after a thread switch or a handler. bozo_resume_failed reports a pc that is not a label.

Phase 1's replay still matches 9,232 of 9,232 samples; the 139 instruction tests pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 12:20:47 +01:00
Thomas MartinandClaude Opus 5.5 0e543da976 FPU and VU0 semantics settled against the captures: 6,449 -> 9,225 of 9,232 samples (the other 7: CPCOND0, next commit)
Every change was found by replaying the TMB captures (bozo-replay) and is pinned by an instruction test:
- FPU add/sub: one guard bit below the larger operand's last mantissa bit, then truncation (Q1). No guard bit
  matched 6,449 samples, exact truncation 7,921, IEEE nearest 7,246, one guard bit 9,169.
- mul.s, div.s, sqrt.s, cvt.s.w: the exact result rounded to nearest even, exponent 255 kept as an ordinary
  exponent (Q3, Q9, Q10); a product past 0x7FFFFFFF saturates.
- VU0 add/sub round to nearest even (the FPU's guard-bit adder lost 731 samples there); VU0 mul is the FPU's.
- VU0 macro FMAC instructions set the MAC and status flags (Q11): Z, S, U, O per field (O also for a result of
  exponent 255), the status OR and sticky bits, the divider's I/D; an FMAC writing vf00 still sets them (the
  emitter now runs it into a temporary); max/mini leave them.
- FCR31: the arithmetic never changes its flags (Q7); a division by zero sets bit 20, as the reference does.
- Tests for the externals routing (stub: every transfer; override: calls only) and the stub runtime's record of
  bozo_call_indirect targets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 02:37:11 +01:00
Thomas MartinandClaude Opus 5.5 b453ef2b8f Recompiler: ELF loader, R5900 decoder (0 unknown words in TMB's .text), function discovery, C++ emitter, runtime helper headers
bozo-recomp <elf> <out dir>: one C++ function per guest function with abi.md's signature and naming, a header and a
function table. Discovery from ELF function symbols, gaps carved at call/branch targets and code pointers, jump
tables, extra entry points for branches into another function's body. Memory, FPU (PS2 non-IEEE arithmetic in
integers), MMI and VU0 macro mode go through inline helpers in runtime/include/bozo/. tests/compile_check builds the
whole generated program with a stub runtime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 00:04:22 +01:00