Files
sp00nz 8c74940293 Model the OHCI registers, and stop writing the MMIO decoder a third time
A title's XAPI is linked into its own image and reads the USB host controller
registers directly, so a gamepad only exists if those registers do. This
runtime backs the whole MCPX aperture with zeroed RAM, which describes a
controller reporting revision 0 and no root hub ports -- correctly enumerating
nothing.

src/usb/ohci.c is the register half: two controllers at 0xFED00000 and
0xFED08000, four downstream ports between them, one device on HC0 port 1. The
registers modelled are the ones with behaviour rather than storage, which are
exactly the ones a driver gets stuck on. HcCommandStatus.HCR is self-clearing
and is the first thing a driver writes, so a reset bit left set is a hang
before anything else runs. HcInterruptStatus is write-1-to-clear. HcRhPortStatus
writes are set/clear requests by bit position rather than a value to store, and
treating them as a value looks precisely like a port that will not enable.
HcFmNumber and HcFmRemaining advance on their own, because a stopped frame
counter is how a driver recognises a controller that is not running.

It is behind RECOMP_USB and off by default. A port with no descriptor walker
behind it is not yet a controller, and a title that worked without one has to
keep behaving exactly as it did.

Reaching the registers means faulting on them rather than reading RAM, and the
decoder for that already existed twice -- once in nv2a_mmio_hook.c, once in
apu_mmio_hook.c -- as one opcode table written out against two different pairs
of accessors. src/platform/mmio_decode.h is that logic with the accessors
passed in, so this device did not add a third. The originals still carry their
own and can move onto it whenever they are next touched; rewriting two working
decoders to prove a point is how you spend an evening finding out which of them
had the bug you just inherited.

tests/mmio_decode covers it, and the cases are the ones where being wrong is
silent: an instruction length that leaves the instruction pointer mid-opcode, a
32-bit read that does not clear the high half of its destination, flags that
send a poll loop the wrong way, and an unrecognised opcode reported as handled
-- which steps over an instruction nobody decoded and corrupts the guest with
no message at all. It refuses that case rather than guessing.

Written from the OHCI 1.0a specification and the title's own code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PvNxGv5fth3NiNe3ZLCKZo
2026-09-07 10:48:00 -07:00
..