Fix SD switch dispatch hidden by instruction-only matching #623

Merged
coah80 merged 1 commits from agent/bittle/sd-state-switch-tables into main 2026-10-01 23:14:28 +00:00
coah80 commented 2026-10-01 23:00:07 +00:00 (Migrated from github.com)

Actual data/behavior error

Both processWorkerState and calcNormal already have byte-identical instruction streams, but their reconstructed switch case values generated incorrect jump-table destinations. Correct those case labels from the original .rela.data entries, retaining the existing block order.

  • jumptable_81654514: 16 command entries, formerly 1/16 correct, now 16/16. For example command 1 runs processWorkerCommands and command 0 runs handleNandTitleUsageComplete; the old source reversed these.
  • jumptable_81654694: 30 scene-state entries, formerly 0/30 correct, now 30/30. For example state 1 runs processNormalInput, states 8/9 share setPageActionFrame, 10/11 share finishPageScroll, and 22/23 share finishDragPageChange. The old source incorrectly numbered handler blocks consecutively.

All mappings were derived by matching each original function-relative jump destination to the identical compiled instruction block. This is not a compiler/register-allocation workaround, metadata edit, table ownership move or hand-authored data table.

Fresh verification

Rebased on 7dea4122. Fresh source/reference builds, full 43U target and report, compared with separately rebuilt main.

  • Both jump tables' 46/46 relocation targets/addends/types exact (64 + 120 bytes); exactly 45 .data relocation entries corrected and no other source-data relocation changed.
  • The entire compiled source .text section is byte-for-byte unchanged.
  • ctxdiff: processWorkerState 99/99, calcNormal 119/119 instructions, both zero differences.
  • Pool 101/101 identical; workflow guards 7/7, pool tests 8/8, diff/worktree checks pass.
  • Unit exact-function count remains 117/129. Global report measures are unchanged: the current instruction/section scoring does not expose these individual jump-table errors. No percentage-gain claim.
  • Remaining vtable placement/weak-table differences are untouched. No dummy padding, forced data, new assembly or symbol changes.
  • Full all_source, report and build/43U/ok pass; SHA-1 26116613f624061ba99c8d1a299aaa6efa85670d. The unit remains NonMatching, so the DOL continues using the original object.

This fixes the reconstructed source's dispatch semantics rather than chasing a score. It was found by checking jump-table relocations for functions already instruction-exact. Left for Cole's review and merge.

Note

Fix SD switch dispatch in SDChannelSelect hidden by instruction-only matching

Remaps the integer command values in the worker-command dispatcher and the calcNormal state switch in iplSDChannelSelect.cpp. Handler calls and state actions are unchanged; only the integer-to-case mapping is corrected so previously hidden branches now dispatch correctly.

  • Worker-command switch: value 1 now routes to worker-command processing, 2 still handles the SD title list, and completion events use new values through 15
  • Normal-state switch: normal input now uses state 1, with page, drag, channel-move, and dialog actions remapped through state 29; states 0, 2, 3, 4, 6, and 13 fall through to default
  • Risk: any code setting mState or worker-command values to the old integers now hits different handlers or the default branch

Macroscope summarized ca817f6.

## Actual data/behavior error Both `processWorkerState` and `calcNormal` already have byte-identical instruction streams, but their reconstructed switch **case values** generated incorrect jump-table destinations. Correct those case labels from the original `.rela.data` entries, retaining the existing block order. - **jumptable_81654514**: 16 command entries, formerly **1/16 correct**, now **16/16**. For example command 1 runs processWorkerCommands and command 0 runs handleNandTitleUsageComplete; the old source reversed these. - **jumptable_81654694**: 30 scene-state entries, formerly **0/30 correct**, now **30/30**. For example state 1 runs processNormalInput, states 8/9 share setPageActionFrame, 10/11 share finishPageScroll, and 22/23 share finishDragPageChange. The old source incorrectly numbered handler blocks consecutively. All mappings were derived by matching each original function-relative jump destination to the identical compiled instruction block. This is not a compiler/register-allocation workaround, metadata edit, table ownership move or hand-authored data table. ## Fresh verification Rebased on **7dea4122**. Fresh source/reference builds, full 43U target and report, compared with separately rebuilt main. - Both jump tables' **46/46 relocation targets/addends/types exact** (64 + 120 bytes); exactly **45 `.data` relocation entries corrected** and no other source-data relocation changed. - The entire compiled source `.text` section is **byte-for-byte unchanged**. - ctxdiff: processWorkerState **99/99**, calcNormal **119/119 instructions**, both **zero differences**. - Pool **101/101 identical**; workflow guards **7/7**, pool tests **8/8**, diff/worktree checks pass. - Unit exact-function count remains **117/129**. **Global report measures are unchanged**: the current instruction/section scoring does not expose these individual jump-table errors. No percentage-gain claim. - Remaining vtable placement/weak-table differences are untouched. No dummy padding, forced data, new assembly or symbol changes. - Full `all_source`, report and `build/43U/ok` pass; SHA-1 **26116613f624061ba99c8d1a299aaa6efa85670d**. The unit remains NonMatching, so the DOL continues using the original object. This fixes the reconstructed source's dispatch semantics rather than chasing a score. It was found by checking jump-table relocations for functions already instruction-exact. Left for Cole's review and merge. <!-- Macroscope's pull request summary starts here --> <!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. --> <!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. --> > [!NOTE] > ### Fix SD switch dispatch in `SDChannelSelect` hidden by instruction-only matching > Remaps the integer command values in the worker-command dispatcher and the `calcNormal` state switch in [iplSDChannelSelect.cpp](https://github.com/coah80/wii-ipl/pull/623/files#diff-e53501e65bee666a9170934feea187bf6eca90a50d75b60f63ea84bc4af67569). Handler calls and state actions are unchanged; only the integer-to-case mapping is corrected so previously hidden branches now dispatch correctly. > - Worker-command switch: value 1 now routes to worker-command processing, 2 still handles the SD title list, and completion events use new values through 15 > - Normal-state switch: normal input now uses state 1, with page, drag, channel-move, and dialog actions remapped through state 29; states 0, 2, 3, 4, 6, and 13 fall through to default > - Risk: any code setting `mState` or worker-command values to the old integers now hits different handlers or the default branch > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized ca817f6.</sup> > <!-- Macroscope's review summary ends here --> > <!-- Macroscope's pull request summary ends here -->
coah80 commented 2026-10-01 23:14:26 +00:00 (Migrated from github.com)

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.
Sign in to join this conversation.