Skip to content

Recompiler: incorrect codegen for branch-always thunks + fragment misdecode with mixed VU0/MMI #86

@Boodax78

Description

@Boodax78

Two independent codegen issues encountered while bringing up an ELF with entry discovery enabled. Both are reproducible.

Bug 1: b target thunks do not execute target function
When a function consists only of a branch-always (b target, no link), the recompiler emits:
ctx->pc = 0xXXXXXXXXu;
return;

Example:
0x11A548: 10000012 b 0x11A594

Generated C++:
ctx->pc = 0x11A594u;
return;

Problem:
The original jal at the call site already set $ra.
The branch-only thunk should transfer control to the target while preserving $ra.
The target function must execute normally and return via its own jr $ra.

Instead, the target function never runs. The caller resumes with an unexpected ctx->pc, breaking dispatcher-style return contracts.
Expected behavior: the thunk should effectively behave as:
FUN_0011a594_0x11a594(rdram, ctx, runtime);

Manual workaround: registerFunction(thunk_addr, target_function).
This appears to be a base codegen issue for branch-always instructions, independent of entry discovery.

Bug 2: Mixed VU0 + MMI fragments misdecoded and over-sliced
Fragments discovered through the entry discovery pass that originate inside a parent function and contain both VU0 (vmove, vsub, vrinit, vrxor) and MMI instructions (pextlw, pextuw, pcpyld) are decoded incorrectly.

Observed behavior:
Instructions are misidentified (e.g. decoded as MFC1 or unrelated opcodes).
Generated fragment is not functional as generated.
Fragment boundary detection overflows into the next function in the binary.

This only occurs for fragments created by the entry discovery pass. Top-level functions decoded normally do not exhibit this issue.

These appear to be two separate root causes, bug 1 is in base codegen for branch-always instructions, bug 2 is in decode and boundary logic for mixed VU0/MMI fragment slicing.

Tested on commit 8d1f1c5

Thanks

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions