Skip to content

Call the BIOS through thunks that keep t1 to the jump - #10

Merged
rixnobis merged 1 commit into
mainfrom
bios-thunks
Oct 28, 2026
Merged

rixnobis merged 1 commit into
mainfrom
bios-thunks

Conversation

@rixnobis

@rixnobis rixnobis commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

The five PS1 wrappers (setjmp, longjmp and abort in ldo.c, write and putchar in luaconf.h) set t1 through a register variable and then called 0xa0, so nothing stopped the compiler reusing t1 before the jump. Each one now goes through a weak COMDAT thunk, j 0xa0 with t1 set in the delay slot, the scheme pcsx-redux/nugget#296 moves nugget to.

make psx builds clean; the thunks disassemble as the two expected instructions.

Summary by CodeRabbit

  • Refactor
    • PlayStation builds now use BIOS-provided routines for runtime control and console output. This updates how these operations are handled on that platform without changing their expected behavior.
    • Builds for other platforms remain unchanged. No new end-user features or visible behavior changes are noted.

The PS1 wrappers set t1 through a register variable and then called 0xa0,
which leaves the compiler free to reuse t1 in between. Each call now goes
through a weak COMDAT thunk, `j 0xa0` with t1 set in the delay slot, the
same scheme nugget uses.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ddfa1774-5af8-4dbc-833b-5d30739bdefc
Commits

Reviewing files that changed from the base of the PR and between 4401a33 and efdedef.

Files selected for processing: 3
  • src/ldo.c
  • src/lpsxbios.h
  • src/luaconf.h

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

For the PSX target, a shared header defines BIOS thunk macros. Error handling and output calls use declared BIOS thunk functions. Non-PSX behavior remains unchanged.

Changes: PSX BIOS Calls

Layer / File(s) Summary
BIOS thunk definition
src/lpsxbios.h
Defines a macro for emitting weak BIOS-call thunks in per-thunk COMDAT sections, plus a macro for external linkage declarations.
Error handling BIOS calls
src/ldo.c
Replaces inline PSX syscall wrappers for setjmp, longjmp, and abort with BIOS thunk declarations and calls.
PSX output BIOS calls
src/luaconf.h
Replaces inline PSX syscall wrappers with BIOS thunk declarations and routes string and line output through the write and putchar functions.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to efded

The BIOS thunk changes preserve the inspected error-handling and output call contracts. No actionable merge-blocking issue was identified; merging remains subject to normal PSX build checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Call the BIOS through thunks that keep t1 to the jump" is specific and matches the changeset. The PR replaces the register-variable approach for setting t1 with weak COMDAT thunks that set …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Call the BIOS through thunks that keep t1 to the jump" is specific and matches the changeset. The PR replaces the register-variable approach for setting t1 with weak COMDAT thunks that set t1 in the delay slot before jumping to the BIOS table at 0xa0. It covers setjmp, longjmp, abort, write, and putchar. The wording is slightly awkward ("keep t1 to the jump"), but a reviewer scanning history would still understand the primary change.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rixnobis
rixnobis merged commit f3e9b01 into main Oct 28, 2026
3 checks passed
@rixnobis
rixnobis deleted the bios-thunks branch October 28, 2026 13:08
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.

1 participant