From 6189a86d73bcc36e9c5fbad7949ebecf2198c9aa Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:45:11 +0000 Subject: [PATCH] decomp: match pdm_part_is_master_boot_sector and __nupParseServerInfo, link pdm_partition and nup (worker d1576e7c) --- configure.py | 4 +- libs/MSL/include/string.h | 12 +++++ libs/RVL_SDK/src/fa/pdm_partition.c | 2 +- libs/RVL_SDK/src/nup/nup.cpp | 3 +- tools/decomp-assist/o3-small.attempts.md | 59 ++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 tools/decomp-assist/o3-small.attempts.md diff --git a/configure.py b/configure.py index c16668b1..08701a70 100644 --- a/configure.py +++ b/configure.py @@ -1691,7 +1691,7 @@ config.libs = [ Object(Matching, "fa/pdm_api.c"), Object(Matching, "fa/pdm_bpb.c"), Object(Matching, "fa/pdm_disk.c"), - Object(NonMatching, "fa/pdm_partition.c"), + Object(Matching, "fa/pdm_partition.c"), Object(Matching, "fa/pf_cache.c"), Object(Matching, "fa/pf_cluster.c"), Object(Matching, "fa/pf_dir.c"), @@ -1869,7 +1869,7 @@ config.libs = [ ] ), RVLSDKLib("nup", [ - Object(NonMatching, "nup/nup.cpp"), + Object(Matching, "nup/nup.cpp"), Object(Matching, "nup/nup_nhttp.cpp"), Object(Matching, "nup/nup_mem.cpp"), ] diff --git a/libs/MSL/include/string.h b/libs/MSL/include/string.h index b951a16e..ac094a57 100644 --- a/libs/MSL/include/string.h +++ b/libs/MSL/include/string.h @@ -22,7 +22,11 @@ int strcmp(const char* s1, const char* s2); char* strpbrk(const char* s1, const char* s2); size_t strspn(const char* s1, const char* s2); char* strtok(char* str, const char* delimiters); +#ifdef __cplusplus +const char* strstr(const char* str, const char* pat); +#else char* strstr(const char* str, const char* pat); +#endif char* strncpy(char* dst, const char* src, size_t length); char* strncat(char* dst, const char* src, size_t length); @@ -39,4 +43,12 @@ int strcmpi(const char* s1, const char* s2); } #endif +#ifdef __cplusplus +extern "C++" { +inline char* strstr(char* str, const char* pat) { + return const_cast(strstr(static_cast(str), pat)); +} +} +#endif + #endif // MSL_STRING_H diff --git a/libs/RVL_SDK/src/fa/pdm_partition.c b/libs/RVL_SDK/src/fa/pdm_partition.c index 98bf04cc..decb07c3 100644 --- a/libs/RVL_SDK/src/fa/pdm_partition.c +++ b/libs/RVL_SDK/src/fa/pdm_partition.c @@ -8,7 +8,7 @@ static inline pf_u16 read_boot_u16(pf_u8* buf, pf_u32 offset) { return PF_SWAP_16(*(pf_u16*)&buf[(offset + 1) & ~1]); } -pf_s32 pdm_part_is_master_boot_sector(pf_u8* buf, pf_u32 total, pf_bool* p_is_mbr) { +pf_s32 pdm_part_is_master_boot_sector(volatile pf_u8* buf, pf_u32 total, pf_bool* p_is_mbr) { pf_u32* p_start; pf_u32* p_count; pf_s16 index; diff --git a/libs/RVL_SDK/src/nup/nup.cpp b/libs/RVL_SDK/src/nup/nup.cpp index 4846250f..4807bf90 100644 --- a/libs/RVL_SDK/src/nup/nup.cpp +++ b/libs/RVL_SDK/src/nup/nup.cpp @@ -175,7 +175,8 @@ static inline char* __nupFindTag(char* response, const char* startTag, const cha } *value = start + strlen(startTag); *length = end - *value; - return end + strlen(endTag); + end += strlen(endTag); + return end; } static s32 __nupParseServerInfo(NUPContextInfo* context, char* response, char* messageId, diff --git a/tools/decomp-assist/o3-small.attempts.md b/tools/decomp-assist/o3-small.attempts.md new file mode 100644 index 00000000..f04918c2 --- /dev/null +++ b/tools/decomp-assist/o3-small.attempts.md @@ -0,0 +1,59 @@ +# o3-small attempts (2026-10-09) + +Worktree `sol-low`, branch `agent/w1009/o3-small`, base `ad5b9dea` (origin/main). Full build OK and +DOL SHA1 `26116613f624061ba99c8d1a299aaa6efa85670d` before, after nup, and after pdm (both units linked). + +## libs/RVL_SDK/src/nup/nup: __nupParseServerInfo 66 -> 0 (unit flipped to Matching) + +Root cause: the target colors every `__nupFindTag` strstr result as if it were an IRO temp created after +inlining, in source order (start_1, end_1, start_2, end_2, ...). Our source had `start` as an inline +local (inline object band) and `end` collapsed into the backend call-result temp (numbered last). + +How it was found: +- `/tmp/o3-small/nup/vmap2.py` maps every virtual register of an mwdbg capture to the target's + physical register (final code aligned by PCode instruction address), giving a want map (92 vregs). +- regsim relabel experiments (`/tmp/o3-small/nup/t5`-`t11.py`): no per-expansion order of the 4 values works + (matches o2-small), but one band of all start/end values below the inline tag objects, ordered + s1 > e1 > s2 > e2 ... (temps created in source order after inlining) gives 0/92 mismatches. +- MWCC decomp (rayanht/mwcc): only `CInline.c:InlineWrapResult` creates `EFORCELOAD` (result of an + expression-inlined call that contains a load or call), and IRO lowering turns it into a fresh temp. + So both strstr calls must go through an expression-inlined function. +- Prior art: Petari's MSL `cstring` (SMGCommunity/Petari libs/MSL_C/include/cstring) declares, for C++, + `const char* strstr(const char*, const char*)` plus the const-correct overload + `extern "C++" inline char* strstr(char*, const char*)`. NUP is C++ and passes `char*`. +- Backend copy propagation (`CopyPropagation.c`) still folds `end` into the call-result temp unless a use + block kills the copy; `end += strlen(endTag); return end;` does that (wrapper alone: 83, both: 0). + +Change: `libs/MSL/include/string.h` gets the MSL C++ overload (C declaration unchanged for C), and +`__nupFindTag` ends with `end += strlen(endTag); return end;`. Other C++ users of strstr +(nup_nhttp, iplSetting, iplNandSDWorker, ut_ArchiveFontBase) only change `.strtab`/debug metadata; +their code/data sections are byte-identical. nup: 23/23 exact, pool 28/28, symbol order differs only in +label names (lbl_ vs @n, `pad$` vs `fillByte$` static name). + +Tried first (all worse, reduced file `/tmp/o3-small/nup/red_base.cpp` scored registers only): +value-first helpers (204/477), ternary helpers (478+), shared caller tagStart/tagEnd via pointers (89), +call inside the if condition (66), non-inline helper (66), strstr wrapper on one call only (66/83). + +## libs/RVL_SDK/src/fa/pdm_partition: pdm_part_is_master_boot_sector 21 -> 0 (unit flipped to Matching) + +Root cause: the eight MBR byte loads are volatile in the target. Change: the parameter is +`volatile pf_u8* buf` (C function, symbol unchanged; no prototype elsewhere; all reads go through it). + +Proof that the target needs ordered (volatile) loads: +- Pass-2 scheduler model (`/tmp/o2-small/sim/sched750.py` + `model2.py`) checked against the GC/3.0a5.2 + binary: pick 0x599920, DAG builder 0x599ac0, add_dependency 0x599e90, 750 can_issue 0x63c880, + timing table built at 0x63c1b0 (record forms +2 latency via flags2 0x100000). It reproduces + 5875/6036 blocks of every mwdbg capture in `_mwdbg/runs` (failures are alias-object cases). +- With the final 24 instructions and registers, no pass-2 input order reaches the target (random + topological search: best 10 base alias, 8 all alias; every load/store alias subset: best 6; + block-split partitions only at unnatural points). The blocker is cycle 2: `slwi r30,r9,24` frees + `lbz r9,0x1c7` (WAR) while `lbz r11,0x1c6` frees nothing, so the slwi must issue first. +- Adding 0-latency load->load ordering edges (what GC3 adds for PCode flag 0x80 at 0x599b5b) + makes the target a fixed point. mwdbg on the volatile build shows LBZ flags 0xa2 (0x22|0x80). +- Compiled: `volatile pf_u8* buf` gives 20/20 exact; use-site cast form also exact (not used). + The buffer is filled by the disk driver (pdm_disk_physical_read) outside this function. + +Tried first (all 19-85): 120 add-tree shapes (`/tmp/o3-small/v2.py`, reassociation pairs +((A+B)+C)+D -> (C+A)+(D+B)), LE32 inline helpers (21), byte loops (43-97), `#pragma scheduling` +once/twice/off and every processor model (21-83), Wii/1.x compilers (17-20, siblings break). +`#pragma scheduling once` (pass 2 only) exists in GC3 and was never in the combosweep list. -- 2.49.1