forked from RetroPortingToolKit/psxrecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
Review: preserve registers in ExitCriticalSection #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Alexbeav
wants to merge
2
commits into
codex/review-base-exit-critical-section-17f49ad3
from
codex/fix-exit-critical-section
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # ExitCriticalSection register contract | ||
|
|
||
| `psx_syscall` handles BIOS SYS(02h) directly, including when optional BIOS HLE | ||
| services are disabled. It enables the current interrupt bit and the hardware | ||
| interrupt mask in COP0 SR. It preserves the caller's general registers. | ||
| In particular, it must not assign a return value to `v0`. | ||
|
|
||
| An SDK wrapper can call another BIOS service, then ExitCriticalSection, and | ||
| return the earlier result. Clearing `v0` turns a successful operation into a | ||
| false failure. This can prevent a caller from entering its video decode loop | ||
| even though disc streaming and audio have already started. | ||
|
|
||
| The hardware contract is documented in | ||
| [PSX-SPX, SYS(02h)](https://psx-spx.consoledev.net/kernelbios/#sys02h-exitcriticalsection-syscall-with-r402h). | ||
| The specification allows K0 to change; this direct handler preserves it too. | ||
| The host-only `cpu->pc = 0` continuation and C return value remain unchanged. | ||
|
|
||
| `exit_critical_section_test` compiles the real `traps.c` implementation with | ||
| LTO and tests 16 combinations of incoming `v0` and SR. It checks the full CPU | ||
| state, allowing only the documented SR update and host continuation change. | ||
| The test uses no BIOS, generated retail code, or game data. | ||
|
|
||
| The fixture links only the real trap unit and its test driver. It relies on | ||
| interprocedural optimization removing syscall paths that the driver never | ||
| calls, rather than providing fake scheduler or exception implementations. | ||
| This link contract is verified with Windows x64 MinGW GCC 16.1.0 and is enabled | ||
| only for that toolchain. Other configurations still register the test, but | ||
| CTest reports it as **Skipped** with the unsupported compiler and reason. | ||
| They do not provide register-preservation coverage until the fixture's link | ||
| contract is validated there or a portable real-dependency harness replaces it. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* Exercise the real psx_syscall case, with no BIOS or retail fixture. | ||
| * LTO removes the unused scheduler/exception cases so this focused executable | ||
| * does not need to stub them. The syscall selector remains a constant 2. */ | ||
| #include "cpu_state.h" | ||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| int psx_syscall(CPUState *cpu, uint32_t code); | ||
|
|
||
| int main(void) { | ||
| const uint32_t results[] = {0u, 1u, 0x80010000u, UINT32_MAX}; | ||
| const uint32_t statuses[] = {0u, 1u, 0x40000400u, 0x40000401u}; | ||
| for (unsigned r = 0; r < sizeof(results) / sizeof(results[0]); ++r) { | ||
| for (unsigned s = 0; s < sizeof(statuses) / sizeof(statuses[0]); ++s) { | ||
| CPUState cpu = {0}; | ||
| for (unsigned i = 1; i < 32; ++i) | ||
| cpu.gpr[i] = 0x98760000u + i; | ||
| cpu.gpr[2] = results[r]; | ||
| cpu.gpr[4] = 2u; | ||
| cpu.pc = 0x80012340u; | ||
| cpu.hi = 0x12345678u; | ||
| cpu.lo = 0xFEDCBA98u; | ||
| cpu.cop0[12] = statuses[s]; | ||
| CPUState expected = cpu; | ||
| expected.cop0[12] |= 0x401u; | ||
| expected.pc = 0u; /* host continuation: resume after SYSCALL */ | ||
| if (psx_syscall(&cpu, 0u) != 0 || | ||
| memcmp(&cpu, &expected, sizeof(cpu)) != 0) { | ||
| fprintf(stderr, "SYS(02h) changed preserved state: v0=%08X SR=%08X\n", | ||
| results[r], statuses[s]); | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
| puts("exit_critical_section_test: PASS (16 state combinations)"); | ||
| return 0; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.