Repository navigation
Make reset reliable (IRQ-safe handoff, robust IOP reboot, SDK-owned stdio) - #70
Merged
Merged
Conversation
The command thread ran at priority 20. The EE kernel schedules strictly by priority, so a thread of the loaded program that never blocks and runs at a numerically lower priority starves it, and reset (and every other command) is never executed. The thread sleeps unless a command arrives, so a high priority costs the program nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SifIopSync() returns 1 once the IOP has finished booting (BOOTEND). pkoReset() looped while it returned 1, so it fell through at once and called SifInitRpc() on an IOP that was still rebooting. Use the same loop as restartIOP() in ps2link.c: while (!SifIopSync()); Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the program's main thread (userThreadID) was terminated. Other threads it created (e.g. an SDL audio thread, pad or network threads) kept running while the IOP was reset underneath them, for example blocked in or issuing RPCs. Remember which threads exist right before the first program is started (ps2link's own and any kernel/patch threads) and terminate and delete every other thread in pkoReset(). The list lives in .bss, so it is rebuilt after the ExecPS2() restart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A program may leave a GIF (channel 2) or VIF1 (channel 1) transfer running or PATH3 masked. Stop both channels (with CPND held while STR is cleared), then reset VIF1 and GIF before the IOP reset and the restart. Only kuseg registers (0x1000xxxx) are touched, so this also works when the EE runs in user mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pkoReset() restarts ps2link with ExecPS2(&__start, ...). crt0 clears .bss but .data is kept. newlib marks stdio as initialized in _impure_data (.data, __cleanup), while the FILE structs and their locks (__sf) live in .bss. After the restart __sinit() therefore skips the re-initialization and the first printf() takes a NULL lock: TLB load exception, BadVAddr 8, EPC in __retarget_lock_acquire_recursive, called from the command thread's first dbgprintf(). It shows up on every start when IPCONFIG.DAT is missing (the initial boot prints "Error reading ipconfig.dat" and then restarts), and after a reset once ps2link has printed anything. libcglue clears the mark in __locks_init(), but through the full struct _reent of the installed headers. ps2link links newlib-nano (NEWLIB_NANO = 1), which is built with _REENT_SMALL, where __cleanup is at offset 32 instead of 52, so that reset hits another field. Clear the mark through the _REENT_SMALL layout before ExecPS2(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On reset, the IOP command thread first unmounted host: and deleted the tty driver, and only then sent PKO_RPC_RESET to the EE. With a program that keeps talking to the IOP (an SDL2 program printing once a second while streaming audio), the reset never ran: host: was gone (TCP 18193 refused), the program froze and only ICMP still answered. Send the command to the EE first, then remove host: and tty as before. Also import DelayThread, which the next commit uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sceSifSetDma() returns 0 when the SIF DMA queue is full, e.g. while a program streams audio or pad data. pkoSendSifCmd() then dropped the command; for a reset that leaves ps2link dead. Retry for up to about one second. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ps2sdk's InitThread() moves a program's main thread to priority 1 and SDL2 runs its audio thread one above that, at 0. When such a thread keeps the CPU busy, the command thread (priority 1) is woken by the SIF0 interrupt but never runs, so pkoReset() is never called. When the interrupt handler sees PKO_RPC_RESET, demote all threads of the program to the lowest priority and raise the command thread to 0 before waking it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
marked this pull request as draft
November 24, 2026 19:56
fjtrujy
marked this pull request as ready for review
November 24, 2026 20:07
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
resetcould leave ps2link unreachable after running an EE program, particularly when an SDL2 program used audio, pad input and gsKit. A boot withoutIPCONFIG.DATcould also crash on the firstprintf()after ps2link restarted itself, because newlib-nano's stdio state survived in.datawhile its FILE locks in.bsswere cleared.This is the single consolidated reset-reliability PR. The additional fixes were integrated here from the former alternative #71; there is no need to merge #71 separately. The original eight commits by @kaisa847 are preserved, followed by the consolidation commit.
Changes
SifIopReset()submission, bound retries and BOOTEND waits, and continue into the ps2link startup recovery path if the IOP did not reboot successfully.host:andttymounted until the reboot itself instead of deleting them on a failed submission.struct _reentlayout in ps2link. The stdio reset is now owned by merged ps2sdk #969, whose__locks_init()runs on ps2link's startup afterExecPS2().Validation
Original implementation, tested by @kaisa847 on PSX DESR-5100 hardware:
IPCONFIG.DATprintf()crashed after self-restartIPCONFIG.DATConsolidated code, verified so far:
-Werror.PWOFFONRESET=0andPWOFFONRESET=1builds passed.Still required before marking ready: repeat runtime tests for the new consolidated branch on real hardware. In particular, use an updated/rebuilt ps2sdk
libcglue.athat contains ps2sdk #969 (mergecf9557dor newer). The installed SDK used by the earlier local tests predates this fix, so those builds alone do not prove the newlib-nano restart.Real-hardware regression cases: no-
IPCONFIG.DATcold boot and subsequentprintf(), at least ten sequential application reset/relaunch cycles with an SDL2 audio workload, the physical reset button in both configurations, and congested/failed SIF DMA submission. Confirm that ps2client can reconnect to ps2link and execute another ELF after each recovery, not merely that ICMP ping succeeds.Related