feat(libSceAjm): build control and split-run batch jobs as firmware 13.42 does #12613

Merged
zaryabzip merged 2 commits from upstream-pr/12613 into main 2026-11-14 03:44:29 +00:00
zaryabzip commented 2026-10-28 23:00:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-28T23:00:02Z.


What

Makes sceAjmBatchJobControlBufferRa and sceAjmBatchJobRunSplitBufferRa write the bytes firmware 13.42 writes. It also adds both to libSceAjmi, which exports them too. #12372, which did the same for sceAjmBatchJobRunBufferRa and which this branch was built on, has merged. With it, all three PS4 batch builders match the firmware in both modules.

BunnyFl ran both routines from 13.42's libSceAjm.sprx (0xac0 and 0xc60) and libSceAjmi.sprx (0xb80 and 0xd20) in an x86-64 emulator on a 0xCC-filled buffer. The runs covered:

  • with and without a return address;
  • two input and two output buffers, and null lists with counts of 0;
  • five flags values for each builder.

Both modules wrote identical bytes and called no import. Nothing was measured on a console. Against main:

  • Old header bits are kept, as in #12372. Job headers and flags chunks write bits 0-25 and keep bits 26-31. Buffer chunks write their kind and direction (bits 0-4) and keep the rest.
  • Control flags are masked to 0x000060000000e7ff. That's prosper's control mask, and every row in the table matches it. Run flags are masked to 0x0000e00000001fff, the mask sceAjmBatchJobRunBufferRa uses. main keeps every bit.

All three builders now share the firmware-exact helpers. sceAjmBatchJobRunBufferRa forwards to the split builder again, as it did on main, through an internal function that doesn't throw. sceAjmBatchJobRunSplitBufferRa itself still throws for a null buffer list with a nonzero count, which the runs didn't cover.

In libSceAjmi the two exports are _nid_disambig1 names, like the other two there. They call the same internal builder, never each other's exported names, so the patched names can't bind to libSceAjm's exports.

The test checks both builders in both libraries against BunnyFl's bytes, flags table included. TestConsoleBufferJobs now expects the kept bits from sceAjmBatchJobControlBufferRa, and its batch still decodes through sceAjmBatchStartBuffer.

Merge order with #3205, which also changes core/libs/tests/GuestAjm.cpp: #11238 and #12372 (both merged), this PR, then #3205 rebased on top (proposed on #3205).

Tested

Rebased onto main 578b8311ac for the review; the rebase was clean and only context lines changed. Windows 11 Home 25H2 (i7-11800H, WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2, Release, BUILD_TESTING=ON) at fbfcfcc63e, and Ubuntu 24.04.5 on WSL2 (GCC 13.3.0, CMake 3.28.3) with it merged into main 1db077e876:

  • No warnings in the changed files on either host.
  • ctest -R "guest_ajm|atrac9": 100% tests passed, 0 tests failed out of 7 on Windows, and out of 8 on Linux (Linux adds guest_ajm_teardown).
  • guest_ajm with --repeat until-fail:3: 3 of 3 on both hosts.
  • Baseline: on #12372's rebased head 6a7a2c7ccf with only this GuestAjm.cpp, guest_ajm builds and then aborts on both hosts (Windows exit 0xc0000409). The return address maps to TestConsoleBufferJobs, at the control-word checks this PR changes.
  • The patched libSceAjmi.prx, libSceAjm.prx and libSceAjm.native.prx each export stlghnic3Jc, ElslOCpOIns, 7jdAXK+2fMo and dmDybN--Fn8 once.
  • tools/check_conventions.py passes. tools/pr_overlap.py lists only #3205, whose order is above.
  • Windows, by JJenkx at fbfcfcc63e merged onto main 990481cdbf, a clean merge (comment). Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release: guest_ajm passes 3 of 3, none skipped.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5059045297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12613). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-28T23:00:02Z. --- ### What Makes `sceAjmBatchJobControlBufferRa` and `sceAjmBatchJobRunSplitBufferRa` write the bytes firmware 13.42 writes. It also adds both to libSceAjmi, which exports them too. #12372, which did the same for `sceAjmBatchJobRunBufferRa` and which this branch was built on, has merged. With it, all three PS4 batch builders match the firmware in both modules. BunnyFl [ran both routines](https://github.com/boykopovar/AnyPS5/pull/12372#issuecomment-6482366782) from 13.42's `libSceAjm.sprx` (0xac0 and 0xc60) and `libSceAjmi.sprx` (0xb80 and 0xd20) in an x86-64 emulator on a 0xCC-filled buffer. The runs covered: - with and without a return address; - two input and two output buffers, and null lists with counts of 0; - five flags values for each builder. Both modules wrote identical bytes and called no import. Nothing was measured on a console. Against `main`: - **Old header bits are kept**, as in #12372. Job headers and flags chunks write bits 0-25 and keep bits 26-31. Buffer chunks write their kind and direction (bits 0-4) and keep the rest. - **Control flags are masked to `0x000060000000e7ff`.** That's prosper's control mask, and every row in the table matches it. Run flags are masked to `0x0000e00000001fff`, the mask `sceAjmBatchJobRunBufferRa` uses. `main` keeps every bit. All three builders now share the firmware-exact helpers. `sceAjmBatchJobRunBufferRa` forwards to the split builder again, as it did on `main`, through an internal function that doesn't throw. `sceAjmBatchJobRunSplitBufferRa` itself still throws for a null buffer list with a nonzero count, which the runs didn't cover. In libSceAjmi the two exports are `_nid_disambig1` names, like the other two there. They call the same internal builder, never each other's exported names, so the patched names can't bind to libSceAjm's exports. The test checks both builders in both libraries against BunnyFl's bytes, flags table included. `TestConsoleBufferJobs` now expects the kept bits from `sceAjmBatchJobControlBufferRa`, and its batch still decodes through `sceAjmBatchStartBuffer`. Merge order with #3205, which also changes `core/libs/tests/GuestAjm.cpp`: #11238 and #12372 (both merged), this PR, then #3205 rebased on top ([proposed on #3205](https://github.com/boykopovar/AnyPS5/pull/3205#issuecomment-6481999792)). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Rebased onto `main` 578b8311ac for the review; the rebase was clean and only context lines changed. Windows 11 Home 25H2 (i7-11800H, WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2, Release, `BUILD_TESTING=ON`) at fbfcfcc63e, and Ubuntu 24.04.5 on WSL2 (GCC 13.3.0, CMake 3.28.3) with it merged into `main` 1db077e876: - No warnings in the changed files on either host. - `ctest -R "guest_ajm|atrac9"`: `100% tests passed, 0 tests failed out of 7` on Windows, and `out of 8` on Linux (Linux adds `guest_ajm_teardown`). - `guest_ajm` with `--repeat until-fail:3`: 3 of 3 on both hosts. - Baseline: on #12372's rebased head 6a7a2c7ccf with only this `GuestAjm.cpp`, `guest_ajm` builds and then aborts on both hosts (Windows exit 0xc0000409). The return address maps to `TestConsoleBufferJobs`, at the control-word checks this PR changes. - The patched `libSceAjmi.prx`, `libSceAjm.prx` and `libSceAjm.native.prx` each export `stlghnic3Jc`, `ElslOCpOIns`, `7jdAXK+2fMo` and `dmDybN--Fn8` once. - `tools/check_conventions.py` passes. `tools/pr_overlap.py` lists only #3205, whose order is above. - **Windows, by JJenkx** at `fbfcfcc63e` merged onto `main` `990481cdbf`, a clean merge ([comment](https://github.com/boykopovar/AnyPS5/pull/12613#issuecomment-6720579205)). Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release: `guest_ajm` passes 3 of 3, none skipped. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
BunnyFl commented 2026-11-02 03:44:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T03:44:52Z.

Review: APPROVED


Windows 11, WinLibs GCC 15.2.0 r7, Release. Head fbfcfcc63e merged into upstream/main 93dbd0f82a:

  • guest_ajm, guest_ajm_aac_multichannel, guest_ajm_vibration, guest_ajm_wvorbis and public_headers pass, with libSceAjmi built.
  • Mutation check: with CONSOLE_CONTROL_FLAGS set to all ones, guest_ajm fails, so the flags table pins the control mask.

Cross-checked the masks in firmware 13.42 independently:

  • the control builders (libSceAjm.sprx 0xac0, libSceAjmi.sprx 0xb80) load 0x60000000e7ff;
  • both split/run builders (0xc60, 0xd20) load 0xe00000001fff;
  • the header and chunk masks around them (0x3ffffc0, 0xfc000030, 0xffffffe0, 0xfffffff0) match the kept-bits description;
  • the same mask constants appear in the matching builders of both modules (I compared the constants, not every instruction).

One thing in the description: "ran both routines" has an unfilled link placeholder instead of the comment URL.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5731883098 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12613#pullrequestreview-5731883098). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T03:44:52Z. **Review:** APPROVED --- Windows 11, WinLibs GCC 15.2.0 r7, Release. Head fbfcfcc63e merged into upstream/main 93dbd0f82a: - `guest_ajm`, `guest_ajm_aac_multichannel`, `guest_ajm_vibration`, `guest_ajm_wvorbis` and `public_headers` pass, with `libSceAjmi` built. - Mutation check: with `CONSOLE_CONTROL_FLAGS` set to all ones, `guest_ajm` fails, so the flags table pins the control mask. Cross-checked the masks in firmware 13.42 independently: - the control builders (`libSceAjm.sprx` 0xac0, `libSceAjmi.sprx` 0xb80) load `0x60000000e7ff`; - both split/run builders (0xc60, 0xd20) load `0xe00000001fff`; - the header and chunk masks around them (`0x3ffffc0`, `0xfc000030`, `0xffffffe0`, `0xfffffff0`) match the kept-bits description; - the same mask constants appear in the matching builders of both modules (I compared the constants, not every instruction). One thing in the description: "[ran both routines]({u3})" has an unfilled link placeholder instead of the comment URL.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!12613
No description provided.