ps2pack stub: set up its own stack before unpacking #2

Merged
techwritescode merged 4 commits from ps2pack-own-stack into main 2026-09-29 22:16:54 +00:00

The ps2pack stub jumped straight into unpacking on whatever stack the launcher gave it. If that stack is in low memory (below 1 MB), a payload linked there is unpacked over the stub's own stack. ps2link links at 0x94000 by default, so a packed ps2link went black on hardware, while a packed program at 0x100000 or above (all four hwhello ELFs) worked.

The previous ps2-packer stub, disassembled from a known-good PS2LINK.ELF, starts with SetupThread (stack at the top of RAM, 128 KB) and ei before it decompresses. This does the same: crt0.s now calls SetupThread with a top-of-RAM stack, after clearing its bss and saving argc/argv, then calls main. The entry point is unchanged (0x1D0001C).

Verified in PCSX2: packed hello and packed ps2link (low address, all modules load, no exceptions) still start.

Not verified on hardware: whether this is the cause of the black screen. A test kit (old stub vs new stub, low address) is in scratch/blackscreen-kit4; results decide whether this is the fix. Please hold the merge until then.

The ps2pack stub jumped straight into unpacking on whatever stack the launcher gave it. If that stack is in low memory (below 1 MB), a payload linked there is unpacked over the stub's own stack. ps2link links at 0x94000 by default, so a packed ps2link went black on hardware, while a packed program at 0x100000 or above (all four hwhello ELFs) worked. The previous ps2-packer stub, disassembled from a known-good `PS2LINK.ELF`, starts with `SetupThread` (stack at the top of RAM, 128 KB) and `ei` before it decompresses. This does the same: `crt0.s` now calls `SetupThread` with a top-of-RAM stack, after clearing its bss and saving argc/argv, then calls `main`. The entry point is unchanged (0x1D0001C). Verified in PCSX2: packed hello and packed ps2link (low address, all modules load, no exceptions) still start. Not verified on hardware: whether this is the cause of the black screen. A test kit (old stub vs new stub, low address) is in scratch/blackscreen-kit4; results decide whether this is the fix. Please hold the merge until then.
ps2pack stub: move to a stack at the top of RAM before unpacking
All checks were successful
Build / build (push) Successful in 1m0s
eff1472447
The stub trusted the launcher's stack. When that stack is in low memory, a payload
linked below 1 MB (ps2link's default, 0x94000) is unpacked over it. The stub now
calls SetupThread with a top-of-RAM stack before decompressing, as the previous
ps2-packer stub did.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
ps2pack stub: start the unpacked program with ExecPS2
All checks were successful
Build / build (push) Successful in 1m0s
bf13be9802
The stock ps2-packer stub hands off through ExecPS2 rather than a plain jump.
Jumping straight in left large images (real ps2link) black on hardware.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Revert "ps2pack stub: start the unpacked program with ExecPS2"
All checks were successful
Build / build (push) Successful in 59s
990869c8bc
Hardware: packed real ps2link stayed black with the ExecPS2 hand-off and works
with the plain jump.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Stop tracking stub/build
All checks were successful
Build / build (push) Successful in 57s
35480d8ca1
The build output is ignored; only the embedded internal/ps2pack/pack/stub.elf is
the checked-in artifact.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
techwritescode force-pushed ps2pack-own-stack from 35480d8ca1
All checks were successful
Build / build (push) Successful in 57s
to 3868d489ec
All checks were successful
Build / build (push) Successful in 53s
Build / build-macos (push) Successful in 34s
2026-09-29 22:14:42 +00:00
Compare
techwritescode deleted branch ps2pack-own-stack 2026-09-29 22:16:55 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ps2/tools!2
No description provided.