Repository navigation
Recompiler: VCALLMSR reads CMSAR0 instead of out-of-bounds vi[27] - #444
Open
Miquelzorno wants to merge 1 commit into
Open
Miquelzorno wants to merge 1 commit into
Miquelzorno wants to merge 1 commit into
Conversation
vcallmsr is always written "vcallmsr $vi27", so the emitter formatted ctx->vi[27] on the 16-entry vi array: an out-of-bounds read. On hardware VCALLMSR always starts at CMSAR0, which CTC2/CFC2 already keep in ctx->vu0_cmsar0, so read it from there. Fixes ran-j#262.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #262.
vcallmsris always written asvcallmsr $vi27, so the emitter formattedctx->vi[27]. Butviisuint16_t vi[16], which makes that an out-of-bounds read (undefined behaviour). It returns whatever sits after the array, so the microprogram starts at a garbage address.On hardware, VCALLMSR always starts at CMSAR0, whatever the operand says. The
$vi27is just CMSAR0's number in the control-register space.CTC2/CFC2already keep CMSAR0 inctx->vu0_cmsar0, so VCALLMSR now reads it from there:About the
vi[32]approach suggested in the issue: makingvi32 entries wide would also fix this, and it matches how PCSX2 lays out the register file. But every other control register in this codebase lives in a named field (vu0_status,vu0_fbrst,vu0_cmsar0…), and CFC2/CTC2 apply per-register semantics on top of them (masks,TPC >> 3, read-only registers). Moving tovi[32]means changing theR5900Contextlayout and keeping two copies of each register in sync. That is a bigger change, better done as its own PR if you want it. This PR is the minimal fix that matches the current design:vu0_cmsar0is already the single source of truth thatctc2 $rt, $vi27writes.Changes
ps2xRecomp/src/lib/vu_translation_helpers.cpp:translateVU_VCALLMSRreadsctx->vu0_cmsar0instead ofctx->vi[inst.rd].ps2xTest/src/code_generator_tests.cpp: new test checking that VCALLMSR emits avu0_cmsar0read and novi[index.Testing
ps2x_tests: 447/447 pass (MSVC 14.44, Ninja, Release, Windows 11).