Skip to content

Make reset robust with IRQ-safe IOP handoff and SDK-owned stdio - #71

Closed
fjtrujy wants to merge 3 commits into
ps2dev:masterfrom
fjtrujy:fix/reset-robust-sdk-libcglue
Closed

fjtrujy wants to merge 3 commits into
ps2dev:masterfrom
fjtrujy:fix/reset-robust-sdk-libcglue

Conversation

@fjtrujy

@fjtrujy fjtrujy commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Purpose

Alternative to #70 (based on @kaisa847's reset work), with the same EE/IOP reset reliability fixes without copying newlib-nano's private struct _reent layout into ps2link. ps2sdk #969 is already merged and owns the stdio reinitialization required after ExecPS2().

This PR replaces rather than supplements #70; please do not merge both.

Changes

  • Retain the original fixes for command-thread priority, thread cleanup, GIF/VIF1 DMA quiescing, waiting for IOP BOOTEND, and SIF DMA queue retries.
  • Record pre-application EE threads by entry point, stack and GP as well as ID. This prevents a recycled ID from automatically being treated as a preserved ps2link thread.
  • Retry EE SifIopReset() submissions only when accepted by the SDK, with a bounded BOOTEND wait; if no completion occurs, restart the EE and let ps2link's startup retry the IOP reset.
  • Route both UDP RESET and the physical reset button through a dedicated IOP worker. The poweroff-module callback runs in interrupt context and now only calls iWakeupThread(), never blocking or performing DMA retries directly.
  • Keep host: and tty mounted until the IOP reboot actually occurs. A failed SIF submission no longer destructively removes these services.
  • Use separate SIF DMA staging buffers for RESET and IOP exceptions, so the reset worker cannot overwrite a normal command's payload.
  • Correct SIF DMA payload capacity/transfer length accounting for the command word and avoid delaying from the IOP exception handler.
  • Initialize the EE SIF0-handler ID as invalid until a handler has actually been installed.

Verification

  • Local compilation/link/pack: default and highloading builds, all with -Werror.
  • Local compilation/link/pack: both PWOFFONRESET=0 and PWOFFONRESET=1.
  • Plain-C exception packet and file-I/O reply regression tests pass.
  • Physical PS2 testing is still required. The local ps2sdk libcglue.a predates ps2sdk #969, so these builds cannot establish that the rebuilt SDK fixes the runtime newlib-nano restart path.

Required real-hardware regression matrix

  1. Start without IPCONFIG.DAT, verify first printf() after the self-restart and successful subsequent network commands.
  2. Launch/repeatedly reset a multithreaded SDL2 program using audio, pad input and gsKit; verify ps2client can reach ps2link and launch another ELF each cycle.
  3. Exercise physical-button reset with and without PWOFFONRESET.
  4. Inject SIF DMA queue congestion/failure, confirming no premature host: teardown or permanent stale half-reset state.
  5. Check a second execee after recovery, and run at least 10 consecutive reset cycles.

Dependency and attribution

  • Depends on the installed/rebuilt ps2sdk containing ps2sdk #969 (merge commit cf9557d or newer); updating headers alone is not enough.
  • Built from @kaisa847's ps2link #70; attribution is retained in commit history.

Apply the reset fixes from ps2dev#70 while relying on ps2dev/ps2sdk#969 to reset newlib-nano stdio state during startup after ExecPS2.

Co-authored-by: kaisa847 <226997300+kaisa847@users.noreply.github.com>
@fjtrujy
fjtrujy marked this pull request as ready for review November 18, 2026 15:44
Keep IOP host services mounted until reboot; route network and physical reset requests through one worker; isolate DMA staging for reset and exception packets; bound EE IOP reboot waits and recover via ExecPS2 on timeout. Identify preserved EE threads by their entry/stack/GP rather than recycled IDs.
@fjtrujy fjtrujy changed the title Make reset reliable with SDK-owned stdio reinitialization Make reset robust with IRQ-safe IOP handoff and SDK-owned stdio Nov 24, 2026
@fjtrujy
fjtrujy marked this pull request as draft November 24, 2026 19:08
fjtrujy added a commit to kaisa847/ps2link that referenced this pull request Nov 24, 2026
Consolidate the additional reset reliability fixes from ps2dev#71 into the original contributor PR. Remove the duplicate newlib-nano private struct, defer physical-button reset to an IOP worker, guard SIF DMA submission failures and the EE IOP reboot wait, and harden thread identity handling.
@fjtrujy

fjtrujy commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Consolidated into #70. The original contributor's eight commits are preserved there, with the IRQ-safe reset worker, guarded IOP reboot, DMA staging, and ps2sdk #969 dependency added in commit 870d62c. Please review and test #70 only; this alternative PR is no longer needed.

@fjtrujy fjtrujy closed this Nov 24, 2026
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