Skip to content

Comments

3-operand MULT/MULTU & delay slot exception handling#71

Closed
aslanhudajev wants to merge 0 commit intoran-j:mainfrom
aslanhudajev:main
Closed

3-operand MULT/MULTU & delay slot exception handling#71
aslanhudajev wants to merge 0 commit intoran-j:mainfrom
aslanhudajev:main

Conversation

@aslanhudajev
Copy link
Contributor

This commit: 6821c69eb5674807569416cbac236510491f41a4 fixes a lot of runtime errors.
The MULT/MULTU fix is the most impactful I would say. Not super sure about the delay slot fix, it did however fix many issues in the game I am trying to get to run.

Fix R5900 3-operand MULT/MULTU:
Standard MIPS MULT rs, rt only writes HI/LO. The R5900 extends this with a 3-operand form MULT rd, rs, rt that also writes the low 32 bits of the result into rd. The code generator was omitting the rd write, leaving the destination register stale. Any game code that reads rd after a multiply (instead of using MFLO) would get garbage, causing infinite loops and incorrect computations. This was found in Gauntlet: Dark Legacy's InitAtreeSeqs where the loop counter was computed via 3-operand MULT and never advanced.

Fix delay slot exception handling:
When a MIPS exception occurs on a delay slot instruction, the CPU sets the BD (Branch Delay) bit in the Cause register and EPC points to the branch instruction, not the delay slot. The runtime's exception handler needs to know it was in a delay slot to correctly re-execute the branch after returning from the exception. The code generator now emits ctx->in_delay_slot = 1 / = 0 around delay slot instruction code, allowing raiseCop0Exception to set EPC and BD correctly and preserve the branch target.

Copy link
Owner

@ran-j ran-j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey nice work, the Vu0 implementations seens good to me but please create a new PR with only thouse changes, we have a lot of "noise" from your recompilation like gitignore changed and some cursor thing.

@@ -0,0 +1,6525 @@

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok you have some files like this one that is specific for you project and can't be merge like this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will fix that.
I'll make a new PR.

@@ -1,6 +0,0 @@
#include "register_functions.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not delete this

)
FetchContent_MakeAvailable(raylib)

set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "" FORCE)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't have this deep on the runtime this scene specific for your project.

.gitignore Outdated
ps2xRuntime/src/runner/register_functions.cpp
ps2xRuntime/output No newline at end of file
ps2xRuntime/output
ps2xRuntime/src/runner
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not update this file

@ran-j
Copy link
Owner

ran-j commented Feb 21, 2026

Also the build are fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants