mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 10:19:47 -04:00
71c2df0f54
The generated dispatcher ran kernel-window table hits (RAM [0x500,0x8500), the BIOS's boot-time copy of ROM 0x1FC10000+) natively with NO check that the live RAM bytes still match the ROM image the functions were compiled from — unsound for runtime-patched kernel code (the BIOS installs pad/SIO handlers INSIDE compiled bodies; live diff: 15 clusters, 348 bytes). It never misfired only because entry points happened to avoid patched keys. A static kernel hit now requires psx_kernel_bless_dispatchable(): the emitter emits psx_bios_kernel_bodies[] (key -> full RAM extent of the code reachable from it; continuations carry their parent's extent, 499 entries), and the runtime lazily byte-compares each entry's body against the ROM source, caches the verdict, and invalidates precisely on writes into the body (store chokepoint, DMA/EXE range marks, savestate restore). Clean -> guarded native; patched/unverifiable -> the faithful dirty-RAM interpreter, exactly as Rule 18 prescribes. This implements the runtime half of the relocation-manifest contract (docs/RELOCATION_MANIFEST_FORMAT.md). Measured on Tomba (SCUS-94236): 208-214 of 219 verified functions clean (the 5 mismatches are the genuinely patched pad-driver family, faithfully interpreted); millions of guarded native hits per boot; title 1.00x, village 0.92x (parity — kernel keys were already native, now they are PROVEN native); LLE and HLE boots + gameplay input verified. Kernel-window interp measures 1.3% of interp burden (dirty_ram_stats), so this is a soundness fix, not a speedup; the dominant interp cost is overlay-region coverage (cg-tag hygiene), tracked separately. Observability: TCP kernel_bless (entries/clean/mismatch/native_hits/ verifies/invalidations), always-on. PSX_KERNEL_BLESS=0 reverts to unguarded-table behavior for A/B. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>