diff --git a/docs/asm-inventory.md b/docs/asm-inventory.md new file mode 100644 index 00000000..192d83c8 --- /dev/null +++ b/docs/asm-inventory.md @@ -0,0 +1,213 @@ +# Assembly inventory + +Audit of `ad5100a5`, 4.3U, 2026-10-05. 175 functions contain 178 assembly +bodies/blocks: 162 ORIGINAL functions and 13 PLACEHOLDER functions. + +Run `python3 tools/check_asm_inventory.py`. Completion requires exit 0, complete +coverage and zero placeholders. The checker also rejects stale/duplicate rows, +invalid classifications and syntax it cannot inspect. This audit supersedes the +historical inventory in `tools/decomp-assist/asm-inventory.md`. + +Scope: C/C++ sources and headers in `src/` and `libs/`, including inactive +platform branches, plus standalone assembly there or referenced by +`configure.py`. There are currently no standalone assembly files in that scope. +One row covers all blocks in a function; runtime save/restore entry labels belong +to their enclosing assembly body. Names use their source spelling. Declarations, +comments and string contents do not count. + +ORIGINAL requires hardware, startup, runtime or original SDK assembly evidence. +An SDK path, `nofralloc` alone or an exact assembled object proves no C conversion. +The rvl_dec family follows the original decoder convention specified for this +audit; ASH/ASR also show unsigned `lis @h`/`ori @l` address construction and +hand-built `stmw` frames. C scores below are recorded rejected trials, not fresh +measurements or scores of the retained assembly. Unrecorded means no C score was +found. Historical logs absent from this branch have commit IDs and excerpts in +[the audit log](../tools/decomp-assist/rx36.attempts.md). + +| File | Function | Classification | Evidence | +| --- | --- | --- | --- | +| `libs/MetroTRK/src/Export/targsupp.c` | `TRKAccessFile` | ORIGINAL | twi 31,r0,0 is the debugger file-service trap, with debugger-controlled return registers. | +| `libs/MetroTRK/src/Export/targsupp.c` | `TRKOpenFile` | ORIGINAL | twi 31,r0,0 is the debugger file-service trap, with debugger-controlled return registers. | +| `libs/MetroTRK/src/Export/targsupp.c` | `TRKCloseFile` | ORIGINAL | twi 31,r0,0 is the debugger file-service trap, with debugger-controlled return registers. | +| `libs/MetroTRK/src/Export/targsupp.c` | `TRKPositionFile` | ORIGINAL | twi 31,r0,0 is the debugger file-service trap, with debugger-controlled return registers. | +| `libs/NW4R/include/nw4r/math/arithmetic.h` | `FSelect` | ORIGINAL | fsel inline assembly matches the public [NW4R arithmetic header][arithmetic-h]. | +| `libs/NW4R/include/nw4r/math/arithmetic.h` | `FAbs` | ORIGINAL | fabs inline assembly matches the public [NW4R arithmetic header][arithmetic-h]. | +| `libs/NW4R/include/nw4r/math/types.h` | `VEC3Add` | ORIGINAL | psq_l/ps_add/psq_st implements paired-single vector/matrix operations. | +| `libs/NW4R/include/nw4r/math/types.h` | `VEC3Sub` | ORIGINAL | psq_l/ps_sub/psq_st implements paired-single vector/matrix operations. | +| `libs/NW4R/include/nw4r/math/types.h` | `VEC3Scale` | ORIGINAL | psq_l/ps_muls0/psq_st implements paired-single vector/matrix operations. | +| `libs/NW4R/src/math/math_arithmetic.cpp` | `FrSqrt` | ORIGINAL | frsqrte plus fixed refinement matches the public [NW4R arithmetic assembly][arithmetic-cpp]. | +| `libs/NW4R/src/math/math_types.cpp` | `MTX44Identity` | ORIGINAL | psq_st/ps_merge01/ps_merge10 implements paired-single vector/matrix operations. | +| `libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c` | `TMCJPEGDEC_parse_sof` | PLACEHOLDER | JPEG frame parsing; diagnostic C 98.05381%, 223/223 instructions, 34 differences, temporary incomplete extern, [rx19](../tools/decomp-assist/rx19.attempts.md). | +| `libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c` | `TMCJPEGDEC_err_restart` | PLACEHOLDER | JPEG marker scan; best C 95.73913%, 114/115 instructions, folded exit branch, [rx19](../tools/decomp-assist/rx19.attempts.md), [rx24][rx24]. | +| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `OSInitFastCast` | ORIGINAL | mtspr programs the GQR quantization registers. | +| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `__OSu16tof32` | ORIGINAL | psq_l uses a GQR integer conversion format for the fast cast. | +| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `__OSf32tou8` | ORIGINAL | psq_st uses a GQR integer conversion format for the fast cast. | +| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `__OSf32tou16` | ORIGINAL | psq_st uses a GQR integer conversion format for the fast cast. | +| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `__OSs16tof32` | ORIGINAL | psq_l uses a GQR integer conversion format for the fast cast. | +| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `__OSf32tos16` | ORIGINAL | psq_st uses a GQR integer conversion format for the fast cast. | +| `libs/RVL_SDK/src/ai/ai.c` | `__AICallbackStackSwitch` | ORIGINAL | Saves r1 to __OldStack, installs __CallbackStack, calls through LR, then restores r1. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfmsr` | ORIGINAL | Special-register or synchronization operation: `mfmsr r3`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtmsr` | ORIGINAL | Special-register or synchronization operation: `mtmsr newMSR`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCOrMsr` | ORIGINAL | Special-register or synchronization operation: `mfmsr r4`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCAndMsr` | ORIGINAL | Special-register or synchronization operation: `mfmsr r4`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCAndCMsr` | ORIGINAL | Special-register or synchronization operation: `mfmsr r4`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfhid0` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, HID0`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMthid0` | ORIGINAL | Special-register or synchronization operation: `mtspr HID0, newHID0`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfhid1` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, HID1`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfl2cr` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, L2CR`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtl2cr` | ORIGINAL | Special-register or synchronization operation: `mtspr L2CR, newL2cr`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtdec` | ORIGINAL | Special-register or synchronization operation: `mtdec newDec`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfdec` | ORIGINAL | Special-register or synchronization operation: `mfdec r3`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCSync` | ORIGINAL | Special-register or synchronization operation: `sc`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCEieio` | ORIGINAL | Special-register or synchronization operation: `mfmsr r5`, `mtmsr r6`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCHalt` | ORIGINAL | Special-register or synchronization operation: `sync`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfmmcr0` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, MMCR0`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtmmcr0` | ORIGINAL | Special-register or synchronization operation: `mtspr MMCR0, newMmcr0`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfmmcr1` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, MMCR1`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtmmcr1` | ORIGINAL | Special-register or synchronization operation: `mtspr MMCR1, newMmcr1`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfpmc1` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, PMC1`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtpmc1` | ORIGINAL | Special-register or synchronization operation: `mtspr PMC1, newPmc1`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfpmc2` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, PMC2`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtpmc2` | ORIGINAL | Special-register or synchronization operation: `mtspr PMC2, newPmc2`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfpmc3` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, PMC3`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtpmc3` | ORIGINAL | Special-register or synchronization operation: `mtspr PMC3, newPmc3`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfpmc4` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, PMC4`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtpmc4` | ORIGINAL | Special-register or synchronization operation: `mtspr PMC4, newPmc4`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMffpscr` | ORIGINAL | Special-register or synchronization operation: `mffs fp31`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfsia` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, SIA`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtsia` | ORIGINAL | Special-register or synchronization operation: `mtspr SIA, newSia`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtfpscr` | ORIGINAL | Special-register or synchronization operation: `mtfsf 0xff, fp31`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfhid2` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, HID2`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMthid2` | ORIGINAL | Special-register or synchronization operation: `mtspr HID2, newhid2`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfwpar` | ORIGINAL | Special-register or synchronization operation: `sync`, `mfspr r3, WPAR`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtwpar` | ORIGINAL | Special-register or synchronization operation: `mtspr WPAR, newwpar`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfdmaU` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, DMA_U`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfdmaL` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, DMA_L`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtdmaU` | ORIGINAL | Special-register or synchronization operation: `mtspr DMA_U, newdmau`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMtdmaL` | ORIGINAL | Special-register or synchronization operation: `mtspr DMA_L, newdmal`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMfpvr` | ORIGINAL | Special-register or synchronization operation: `mfspr r3, PVR`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCSetFpIEEEMode` | ORIGINAL | Special-register or synchronization operation: `mtfsb0 FPSCR_NI_BIT`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCSetFpNonIEEEMode` | ORIGINAL | Special-register or synchronization operation: `mtfsb1 FPSCR_NI_BIT`. | +| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMthid4` | ORIGINAL | Both branches write HID4 with mtspr; the fallback preserves the Broadway H4A bit. | +| `libs/RVL_SDK/src/cntcache/cntcache.c` | `CNTCACHEClear` | PLACEHOLDER | NAND/token logic; best C 93.364235%, 147/151 instructions, four missing pool literals, [rx30][rx30]. | +| `libs/RVL_SDK/src/cntcache/cntcache.c` | `_CNTCACHEIsTitleRemovable` | PLACEHOLDER | NAND/TMD checks; best diagnostic C 93.70731%, 82/82 instructions, status-register interference, [rx18][rx18]. | +| `libs/RVL_SDK/src/cntcache/cntcache.c` | `_CNTCACHEDeleteContent` | PLACEHOLDER | Token parsing and ES deletion; best C 95.793106%, 143/145 instructions, missing reload/copy, [rx18][rx18]. | +| `libs/RVL_SDK/src/db/db.c` | `__DBExceptionDestination` | ORIGINAL | mfmsr/mtmsr enable address translation before the exception-handler tail branch. | +| `libs/RVL_SDK/src/gx/GXLight.c` | `PushLight` | ORIGINAL | psq_l/psq_st transfers paired-single values for the GX command stream. | +| `libs/RVL_SDK/src/gx/GXTransform.c` | `WriteProjPS` | ORIGINAL | psq_l/psq_st transfers paired-single values for the GX command stream. | +| `libs/RVL_SDK/src/gx/GXTransform.c` | `Copy6Floats` | ORIGINAL | psq_l/psq_st copies three pairs of floats. | +| `libs/RVL_SDK/src/gx/GXTransform.c` | `WriteMTXPS4x3` | ORIGINAL | psq_l/psq_st transfers paired-single values for the GX command stream. | +| `libs/RVL_SDK/src/gx/GXTransform.c` | `WriteMTXPS3x3from3x4` | ORIGINAL | psq_l/psq_st transfers paired-single values for the GX command stream. | +| `libs/RVL_SDK/src/gx/GXTransform.c` | `WriteMTXPS4x2` | ORIGINAL | psq_l/psq_st transfers paired-single values for the GX command stream. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXIdentity` | ORIGINAL | psq_st/ps_merge01/ps_merge10 implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXCopy` | ORIGINAL | psq_l/psq_st implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXConcat` | ORIGINAL | psq_l/ps_muls0/ps_madds1/ps_madds0 implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXInverse` | ORIGINAL | psq_l/ps_merge10/ps_mul/ps_msub implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXInvXpose` | ORIGINAL | psq_l/ps_merge10/ps_mul/ps_msub implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXRotTrig` | ORIGINAL | Two blocks use frsp, ps_neg, ps_merge00 and psq_st to construct a paired-single rotation. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXTrans` | ORIGINAL | psq_st implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXTransApply` | ORIGINAL | psq_l/psq_st/ps_sum1 implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXScale` | ORIGINAL | psq_st implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtx.c` | `PSMTXScaleApply` | ORIGINAL | psq_l/ps_muls0/psq_st implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/mtxvec.c` | `PSMTXMultVec` | ORIGINAL | psq_l/ps_mul/ps_madd/ps_sum0 implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/vec.c` | `PSVECNormalize` | ORIGINAL | psq_l/ps_mul/ps_madd/ps_sum0 implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/mtx/vec.c` | `PSVECCrossProduct` | ORIGINAL | psq_l/ps_merge10/ps_mul/ps_muls0 implements paired-single vector/matrix operations. | +| `libs/RVL_SDK/src/os/OS.c` | `__OSFPRInit` | ORIGINAL | mfmsr/mtmsr enable the FPU; psq_l initializes paired registers and mtfsf initializes FPSCR. | +| `libs/RVL_SDK/src/os/OS.c` | `OSInit` | PLACEHOLDER | Two lis/addi blocks pin __ArenaLo to 0x816a9800; C score unrecorded, [rx36 audit][rx36-osinit]. | +| `libs/RVL_SDK/src/os/OS.c` | `__OSDBIntegrator` | ORIGINAL | nofralloc debug-vector fragment changes MSR and transfers through the saved hook LR. | +| `libs/RVL_SDK/src/os/OS.c` | `__OSDBJump` | ORIGINAL | Single absolute bla __OSDBJumpTarget between entry labels copied into exception vectors. | +| `libs/RVL_SDK/src/os/OS.c` | `OSExceptionVector` | ORIGINAL | Saves interrupted state, sets SRR0/SRR1 and executes rfi into the exception handler. | +| `libs/RVL_SDK/src/os/OS.c` | `OSDefaultExceptionHandler` | ORIGINAL | Captures GQR1..7 with mfspr and interrupted r13..31 with stmw before dispatch. | +| `libs/RVL_SDK/src/os/OS.c` | `__OSPSInit` | ORIGINAL | mtspr initializes GQR0..7 for paired-single quantization. | +| `libs/RVL_SDK/src/os/OSAlarm.c` | `DecrementerExceptionHandler` | ORIGINAL | Saves interrupted GPRs and GQR1..7 via stmw/mfspr before the C callback. | +| `libs/RVL_SDK/src/os/OSCache.c` | `DCEnable` | ORIGINAL | sync and HID0 mfspr/mtspr enable the data cache. | +| `libs/RVL_SDK/src/os/OSCache.c` | `DCInvalidateRange` | ORIGINAL | dcbi invalidates each cache line. | +| `libs/RVL_SDK/src/os/OSCache.c` | `DCFlushRange` | ORIGINAL | dcbf flushes cache lines; sc invokes the synchronization vector. | +| `libs/RVL_SDK/src/os/OSCache.c` | `DCStoreRange` | ORIGINAL | dcbst writes cache lines; sc invokes the synchronization vector. | +| `libs/RVL_SDK/src/os/OSCache.c` | `DCFlushRangeNoSync` | ORIGINAL | dcbf flushes cache lines without the synchronization call. | +| `libs/RVL_SDK/src/os/OSCache.c` | `DCZeroRange` | ORIGINAL | dcbz zeroes each cache line. | +| `libs/RVL_SDK/src/os/OSCache.c` | `ICInvalidateRange` | ORIGINAL | icbi invalidates instructions, followed by sync/isync. | +| `libs/RVL_SDK/src/os/OSCache.c` | `ICFlashInvalidate` | ORIGINAL | HID0 mfspr/mtspr triggers instruction-cache flash invalidation. | +| `libs/RVL_SDK/src/os/OSCache.c` | `ICEnable` | ORIGINAL | isync and HID0 mfspr/mtspr enable the instruction cache. | +| `libs/RVL_SDK/src/os/OSCache.c` | `LCDisable` | ORIGINAL | dcbi clears locked-cache lines; HID2 mfspr/mtspr disables the locked cache. | +| `libs/RVL_SDK/src/os/OSContext.c` | `__OSLoadFPUContext` | ORIGINAL | Restores caller FPRs, FPSCR and paired-single halves using mtfsf/psq_l. | +| `libs/RVL_SDK/src/os/OSContext.c` | `__OSSaveFPUContext` | ORIGINAL | Captures caller FPSCR/FPRs and paired-single halves using mffs/psq_st. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSLoadFPUContext` | ORIGINAL | Moves context to r4 and tail-branches to __OSLoadFPUContext, which replaces caller FPRs. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSSaveFPUContext` | ORIGINAL | Moves context to r5 and tail-branches to __OSSaveFPUContext before caller FPRs change. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSSetCurrentContext` | ORIGINAL | mfmsr/mtmsr/isync change the FPU-enable bit while installing context pointers. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSSaveContext` | ORIGINAL | Captures caller r1/r2, GPRs, GQR1..7, CR, LR, XER and MSR for a later nonlocal return. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSLoadContext` | ORIGINAL | Restores GPRs and GQR1..7, sets SRR0/SRR1 and resumes interrupted execution with rfi. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSGetStackPointer` | ORIGINAL | nofralloc leaf returns the caller stack pointer directly with mr r3,r1. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSSwitchStack` | ORIGINAL | Returns the old r1 and installs the supplied stack pointer directly. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSSwitchFiber` | ORIGINAL | Installs another r1 and calls the supplied PC through LR; restores the old stack afterward. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSSwitchFiberEx` | ORIGINAL | Preserves r3..r6 arguments while switching r1 and calling the supplied PC through LR. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSInitContext` | ORIGINAL | Copies live ABI registers r2/r13 directly and seeds SRR state for a new execution context. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSSwitchFPUContext` | ORIGINAL | mfmsr/mtmsr/isync enable the FPU; the exception path restores SRR state and uses rfi. | +| `libs/RVL_SDK/src/os/OSContext.c` | `OSFillFPUContext` | ORIGINAL | mfmsr/mtmsr/isync enable the FPU before mffs and paired-single register saves. | +| `libs/RVL_SDK/src/os/OSInterrupt.c` | `OSDisableInterrupts` | ORIGINAL | mfmsr/mtmsr read and clear MSR_EE atomically within the restartable sequence. | +| `libs/RVL_SDK/src/os/OSInterrupt.c` | `OSEnableInterrupts` | ORIGINAL | mfmsr/mtmsr read and set MSR_EE. | +| `libs/RVL_SDK/src/os/OSInterrupt.c` | `OSRestoreInterrupts` | ORIGINAL | mfmsr/mtmsr replace MSR_EE with the saved interrupt state. | +| `libs/RVL_SDK/src/os/OSInterrupt.c` | `ExternalInterruptHandler` | ORIGINAL | Captures interrupted GPRs and GQR1..7 with stmw/mfspr before C interrupt dispatch. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM1_24MB` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM1_48MB` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM2_52MB` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM2_56MB` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM2_64MB` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM2_112MB` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM2_128MB` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `ConfigMEM_ES1_0` | ORIGINAL | isync and mtspr program IBAT/DBAT mappings; SRR0/SRR1 and rfi return with translation enabled. | +| `libs/RVL_SDK/src/os/OSMemory.c` | `RealMode` | ORIGINAL | Writes SRR0/SRR1 and executes rfi with address translation disabled. | +| `libs/RVL_SDK/src/os/OSSync.c` | `SystemCallVector` | ORIGINAL | Changes HID0 with mfspr/mtspr around sync/isync, then returns with rfi. | +| `libs/RVL_SDK/src/os/OSTime.c` | `OSGetTime` | ORIGINAL | mftbu/mftb/mftbu retries until the upper time-base word is stable. | +| `libs/RVL_SDK/src/os/OSTime.c` | `OSGetTick` | ORIGINAL | mftb reads the hardware time-base register. | +| `libs/RVL_SDK/src/os/OSTime.c` | `__SetTime` | ORIGINAL | mttbl/mttbu/mttbl updates the hardware time base in a fixed sequence. | +| `libs/RVL_SDK/src/os/__ppc_eabi_init.cpp` | `__init_hardware` | ORIGINAL | Before normal C startup, mfmsr/mtmsr enables the FPU and r31 holds LR across init calls. | +| `libs/RVL_SDK/src/os/__ppc_eabi_init.cpp` | `__flush_cache` | ORIGINAL | dcbst/sync/icbi/isync make freshly initialized code visible to instruction fetch. | +| `libs/RVL_SDK/src/os/__ppc_eabi_init.cpp` | `__init_user` | ORIGINAL | fralloc/bl __init_cpp/frfree/blr matches the public [SDK startup assembly][sdk-init]. | +| `libs/RevoEX/src/nwc24/NWC24UserId.c` | `getUnScrambleId` | PLACEHOLDER | Integer byte permutation; best C 76.27329%, 161/161 instructions, 97 register/scheduling differences, [rx30][rx30]. | +| `libs/Runtime/src/Gecko_setjmp.c` | `__setjmp` | ORIGINAL | Saves or restores caller GPRs/FPRs, LR, CR, and stack state across nonlocal returns. | +| `libs/Runtime/src/Gecko_setjmp.c` | `longjmp` | ORIGINAL | Saves or restores caller GPRs/FPRs, LR, CR, and stack state across nonlocal returns. | +| `libs/Runtime/src/__init_cpp_exceptions.cpp` | `__exception_info_constants` | ORIGINAL | Reads the caller ABI TOC register r2 directly for exception registration. | +| `libs/Runtime/src/ptmf.c` | `__ptmf_scall` | ORIGINAL | Special compiler ABI takes the member-function descriptor in r12 and tail-dispatches through CTR. | +| `libs/Runtime/src/runtime.c` | `__cvt_fp2unsigned` | ORIGINAL | Unsigned conversion runtime helper with explicit CR0/CR6/CR7 tests; [public runtime assembly][runtime]. | +| `libs/Runtime/src/runtime.c` | `__save_fpr` | ORIGINAL | Entry labels _savefpr_14..31 store caller FPRs relative to r11 without an ABI call frame. | +| `libs/Runtime/src/runtime.c` | `__restore_fpr` | ORIGINAL | Entry labels _restfpr_14..31 reload caller FPRs relative to r11 without an ABI call frame. | +| `libs/Runtime/src/runtime.c` | `__save_gpr` | ORIGINAL | Entry labels _savegpr_14..31 store caller GPRs relative to r11 without an ABI call frame. | +| `libs/Runtime/src/runtime.c` | `__restore_gpr` | ORIGINAL | Entry labels _restgpr_14..31 reload caller GPRs relative to r11 without an ABI call frame. | +| `libs/Runtime/src/runtime.c` | `__div2u` | ORIGINAL | 64-bit compiler division helper uses r3:r4/r5:r6 and carry chains; [public assembly][runtime]. | +| `libs/Runtime/src/runtime.c` | `__div2i` | ORIGINAL | Signed 64-bit compiler division helper manages register-pair signs/carry; [public assembly][runtime]. | +| `libs/Runtime/src/runtime.c` | `__mod2u` | ORIGINAL | 64-bit compiler remainder helper uses register-pair restoring division; [public assembly][runtime]. | +| `libs/Runtime/src/runtime.c` | `__mod2i` | ORIGINAL | Signed 64-bit compiler remainder helper manages register-pair signs/carry; [public assembly][runtime]. | +| `libs/Runtime/src/runtime.c` | `__shl2i` | ORIGINAL | Compiler helper shifts r3:r4 by r5 without recursively calling the 64-bit shift helper. | +| `libs/Runtime/src/runtime.c` | `__shr2u` | ORIGINAL | Compiler helper shifts unsigned r3:r4 by r5 across the word boundary. | +| `libs/Runtime/src/runtime.c` | `__shr2i` | ORIGINAL | Compiler helper shifts signed r3:r4 by r5, explicitly propagating the sign. | +| `libs/Runtime/src/runtime.c` | `__cvt_sll_dbl` | ORIGINAL | Compiler conversion ABI uses r3:r4 input and f1 result with explicit carry/rounding. | +| `libs/Runtime/src/runtime.c` | `__cvt_ull_dbl` | ORIGINAL | Compiler conversion ABI uses r3:r4 input and f1 result with explicit carry/rounding. | +| `libs/Runtime/src/runtime.c` | `__cvt_ull_flt` | ORIGINAL | Compiler conversion ABI uses r3:r4 input and f1 result with explicit single-precision rounding. | +| `libs/Runtime/src/runtime.c` | `__cvt_dbl_usll` | ORIGINAL | Compiler conversion ABI uses f1 input and r3:r4 result without a recursive conversion call. | +| `libs/Runtime/src/runtime.c` | `__cvt_dbl_ull` | ORIGINAL | Compiler conversion helper decodes f1 into r3:r4; [public runtime assembly][runtime]. | +| `src/BS2/BS2Init.c` | `ClearOtherBATs` | ORIGINAL | isync and direct IBAT/DBAT register writes. | +| `src/BS2/BS2Mach.c` | `Run` | ORIGINAL | Clears ABI registers, replaces r1, uses dcbz/dcbf, and jumps via LR. | +| `src/BS2/BS2Start.c` | `__start` | ORIGINAL | Runs before the C stack and ABI registers exist; constructs the initial stack. | +| `src/BS2/BS2Start.c` | `__init_registers` | ORIGINAL | Initializes GPRs, r1, r2, and r13 for the C runtime. | +| `src/scene/nakamuraTest/gamespy/common/gsPlatformUtil.c` | `GetTicks` | ORIGINAL | Inactive PS2 branch reads the CP0 Count register with mfc0 $9. | +| `src/system/TVRC.cpp` | `TVRCSendStartAsync` | PLACEHOLDER | IR command setup; best recorded C 99.77273%, 198/198 instructions, seven differences, [rx2](../tools/decomp-assist/rx2.attempts.md); newer [rx17][rx17] 99.747475%. | +| `src/system/iplChannelManager.cpp` | `getTitleName__Q33ipl7channel7ManagerCFiii` | PLACEHOLDER | Channel-name copying; best C 99.57746%, 71/71 instructions, four address-order differences, [rx17][rx17]. | +| `src/system/iplSaveDataManager.cpp` | `Manager::hasChannel` | PLACEHOLDER | Title-slot search; best C 98.87324%, 71/71 instructions, 14 mask/base register differences, [rx30][rx30]. | +| `src/system/iplSaveDataManager.cpp` | `Manager::makePriorTitleIDList` | PLACEHOLDER | Title filtering; best recorded C 80.22556%, 124/133 instructions, address CSE, [da1](../tools/decomp-assist/da1.attempts.md); newer [rx17][rx17] 79.827065%. | +| `src/system/iplSaveDataManager.cpp` | `Manager::doUpdateChanInfos` | PLACEHOLDER | Channel metadata updates; best C 93.35821%, 68/67 instructions, extra memset base, [rx17][rx17]. | +| `src/system/iplSystem.cpp` | `System::warning_run` | PLACEHOLDER | Scene/render calls; best C 98.66477%, 176/176 instructions, 47 saved-register differences, [rx17][rx17]. | +| `src/system/rvl_dec.c` | `Rvl_decode` | ORIGINAL | Direct beq decoder entries preserve r3/r4 and LR; lis/ori builds the format signatures. | +| `src/system/rvl_dec.c` | `Rvl_decode_szs` | ORIGINAL | Original SZS decoder convention: nofralloc, r0 retains output length, fixed r3..r10/CTR byte-copy pipeline. | +| `src/system/rvl_dec.c` | `Rvl_decode_ash` | ORIGINAL | nofralloc hand-built 0x40 frame saves r21..31 with stmw; work address uses lis @h/ori @l. | +| `src/system/rvl_dec.c` | `Rvl_decode_asr` | ORIGINAL | nofralloc hand-built 0x40 frame saves r21..31 with stmw; work address uses lis @h/ori @l. | + +[rx17]: ../tools/decomp-assist/rx36.attempts.md#rx17 +[rx18]: ../tools/decomp-assist/rx36.attempts.md#rx18 +[rx24]: ../tools/decomp-assist/rx36.attempts.md#rx24 +[rx30]: ../tools/decomp-assist/rx36.attempts.md#rx30 +[rx36-osinit]: ../tools/decomp-assist/rx36.attempts.md#osinit +[sdk-init]: https://github.com/doldecomp/ogws/blob/master/src/revolution/OS/__ppc_eabi_init.c +[runtime]: https://github.com/doldecomp/ogws/blob/master/src/runtime/runtime.c +[arithmetic-h]: https://github.com/doldecomp/ogws/blob/master/include/nw4r/math/math_arithmetic.h +[arithmetic-cpp]: https://github.com/doldecomp/ogws/blob/master/src/nw4r/math/math_arithmetic.cpp diff --git a/tools/check_asm_inventory.py b/tools/check_asm_inventory.py new file mode 100644 index 00000000..872e34fa --- /dev/null +++ b/tools/check_asm_inventory.py @@ -0,0 +1,267 @@ +#!/usr/bin/env python3 +"""Require an inventory entry for every assembly function and zero placeholders.""" + +import argparse +import ast +import re +import sys +from dataclasses import dataclass +from pathlib import Path + + +SOURCE_SUFFIXES = {".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx", ".inc", ".inl"} +ASM_SUFFIXES = {".s", ".asm"} +IDENTIFIER = r"[A-Za-z_$~][\w$~]*(?:::[A-Za-z_$~][\w$~]*)*" +ASM_IDENTIFIER = r"[A-Za-z_.$][\w.$]*" +ASM_TOKEN = re.compile(r"\b(?:asm|__asm|__asm__|nofralloc)\b") +LITERALS = re.compile( + r'R"(?P[^ ()\\\t\r\n]{0,16})\(.*?\)(?P=delimiter)"' + r'|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'' + r"|//(?:\\\r?\n|[^\n])*|/\*.*?\*/", + re.DOTALL, +) + + +@dataclass(frozen=True) +class Body: + file: str + function: str + line: int + + @property + def key(self): + return self.file, self.function + + +def mask_literals(text): + return LITERALS.sub(lambda match: re.sub(r"[^\n]", " ", match.group()), text) + + +def read_source(path): + data = path.read_bytes() + encoding = "utf-16" if data.startswith((b"\xff\xfe", b"\xfe\xff")) else "utf-8-sig" + return data.decode(encoding) + + +def closing(text, start, left, right): + depth = 0 + for pos in range(start, len(text)): + if text[pos] == left: + depth += 1 + elif text[pos] == right: + depth -= 1 + if depth == 0: + return pos + raise ValueError(f"unclosed {left!r} at line {text.count(chr(10), 0, start) + 1}") + + +def function_spans(text): + spans = [] + for match in re.finditer(rf"(?P{IDENTIFIER})\s*\(", text): + name = match["name"] + if name in {"if", "for", "while", "switch", "catch", "sizeof", "__declspec"}: + continue + end = closing(text, match.end() - 1, "(", ")") + tail = re.match(r"\s*(?:(?:const|volatile|override|final|noexcept)\s*)*\{", text[end + 1:]) + if tail: + start = end + tail.end() + spans.append((match.start(), start, closing(text, start, "{", "}"), name)) + return spans + + +def scan_source(path, relative): + text = read_source(path) + if not ASM_TOKEN.search(text): + return [] + text = mask_literals(text) + markers = list(ASM_TOKEN.finditer(text)) + if not markers: + return [] + spans = function_spans(text) + bodies = [] + covered = [] + owners = {} + + def record(span, line): + name = span[3] + if name in owners and owners[name] != span[0]: + raise ValueError(f"line {line}: ambiguous assembly function name: {name}") + owners[name] = span[0] + bodies.append(Body(relative, name, line)) + + for marker in markers: + pos = marker.start() + if any(start <= pos <= end for start, end in covered): + continue + line = text.count("\n", 0, pos) + 1 + owner = next((span for span in reversed(spans) if span[1] < pos < span[2]), None) + if marker.group() == "nofralloc": + if owner is None: + raise ValueError(f"line {line}: nofralloc outside a recognized function") + record(owner, line) + continue + tail = re.match(r"\s*(?:(?:volatile|__volatile__|__volatile|inline|goto)\s*)*([({])", text[marker.end():]) + if tail: + start = marker.end() + tail.end() - 1 + end = closing(text, start, tail[1], "}" if tail[1] == "{" else ")") + if owner is None: + raise ValueError(f"line {line}: assembly outside a recognized function") + record(owner, line) + covered.append((pos, end)) + continue + boundary = re.search(r"[;{}]", text[marker.end():]) + if boundary is None: + raise ValueError(f"line {line}: unrecognized assembly declaration") + end = marker.end() + boundary.start() + definition = next((span for span in spans if pos < span[0] < end and span[1] == end), None) + if definition: + record(definition, line) + covered.append((pos, definition[2])) + elif boundary.group() != ";" or not re.search(rf"{IDENTIFIER}\s*\([^;{{}}]*\)\s*(?:const\s*)?$", text[marker.end():end]): + raise ValueError(f"line {line}: unrecognized assembly syntax") + return bodies + + +def scan_assembly(path, relative): + text = re.sub(r"/\*.*?\*/", lambda match: "\n" * match.group().count("\n"), read_source(path), flags=re.DOTALL) + text = re.sub(r"(?m)(?:#|//).*", "", text) + declared = set() + for match in re.finditer(r"(?m)^\s*\.(?:global|globl|weak)\s+([^\n]+)", text): + declared.update(name.strip() for name in match[1].split(",")) + declared.update(re.findall(rf"\.type\s+({ASM_IDENTIFIER})\s*,\s*[@%]function", text)) + bodies = [] + in_code = True + owner = None + for line, source in enumerate(text.splitlines(), 1): + source = source.strip() + if re.match(r"\.(?:include|incbin|macro|rept|irp|irpc|pushsection|popsection|previous)\b", source): + raise ValueError(f"line {line}: assembly expansion requires inspection: {source}") + if re.match(r"(?:\.endfn|endfunc|endfunction)\b", source): + owner = None + continue + section = re.match(r'\.(?:section\s+"?(\.?[\w.$]+)|((?:text|init|fini|data|rodata|bss|sdata2?|sbss2?)\b))', source) + if section: + name = (section[1] or section[2]).lstrip(".") + in_code = name.split(".")[0] in {"text", "init", "fini"} or bool(re.search(r'"[^"\n]*x[^"\n]*"', source)) + owner = None + continue + entry = re.match(rf"(?:\.fn|glabel|func|function)\s+({ASM_IDENTIFIER})(?:\s|,|$)", source) + label = re.match(rf"({ASM_IDENTIFIER})\s*:", source) + if in_code and (entry or label): + name = (entry or label)[1] + if entry or name in declared or owner is None: + bodies.append(Body(relative, name, line)) + owner = name + elif name != owner and not name.startswith(".L"): + raise ValueError(f"line {line}: untyped assembly label requires inspection: {name}") + elif in_code and source and owner is None: + if not source.startswith(".") or re.match(r"\.(?:byte|short|word|long|4byte|8byte)\b", source): + raise ValueError(f"line {line}: executable assembly without a function label") + return list({body.key: body for body in bodies}.values()) + + +def scan_tree(root): + paths = set() + failures = [] + for directory in ("src", "libs"): + parent = root / directory + if not parent.is_dir(): + failures.append(f"missing source directory: {directory}") + else: + paths.update(path for path in parent.rglob("*") if path.is_file()) + config = root / "configure.py" + if not config.is_file(): + failures.append("missing configure.py") + else: + try: + tree = ast.parse(config.read_text(encoding="utf-8")) + for node in ast.walk(tree): + if not isinstance(node, ast.Constant) or not isinstance(node.value, str): + continue + name = node.value + if name.lower() in ASM_SUFFIXES: + failures.append(f"configure.py: dynamic assembly path requires inspection: {name}") + continue + if Path(name).suffix.lower() not in ASM_SUFFIXES: + continue + candidate = root / name + matches = [candidate] if candidate.is_file() else [path for path in paths if path.as_posix().endswith("/" + name)] + if len(matches) != 1: + failures.append(f"configure.py: unresolved or ambiguous assembly path: {name}") + else: + paths.add(matches[0]) + except (SyntaxError, OSError, UnicodeError) as exc: + failures.append(f"configure.py: {exc}") + bodies = [] + for path in sorted(paths): + suffix = path.suffix.lower() + if suffix not in SOURCE_SUFFIXES | ASM_SUFFIXES: + continue + try: + relative = path.relative_to(root).as_posix() + scanner = scan_assembly if suffix in ASM_SUFFIXES else scan_source + bodies.extend(scanner(path, relative)) + except (ValueError, OSError, UnicodeError) as exc: + failures.append(f"{path}: {exc}") + return bodies, failures + + +def read_inventory(path): + rows = {} + failures = [] + for line, text in enumerate(path.read_text(encoding="utf-8").splitlines(), 1): + if not text.startswith("|"): + continue + cells = [cell.strip() for cell in re.split(r"(? 93.96723 +global fuzzy_match_percent: 99.81488 -> 99.81488 +global complete_code_percent: 80.08451 -> 80.08451 +global matched_data_percent: 99.99410 -> 99.99410 +forbidden patterns added (net, per file): 0 +readability warnings (net, per file; must be 0 in the final result): 0 +GATE PASS +``` + +`python3 tools/test_workflow_guards.py`: 20 tests passed, including 12 new +inventory tests. Fixtures cover declarations/comments/strings, inactive headers, +multiple inline blocks, nofralloc, UTF-16, standalone/configured assembly, +unlisted bodies, placeholders, duplicate/stale rows and inspection failures. + +`python3 tools/check_asm_inventory.py`: exit 1 as required. Exactly 13 placeholder +failures; zero missing, stale, duplicate or parse failures. Counts remain +175 functions / 178 bodies and blocks / 162 ORIGINAL / 13 PLACEHOLDER. + +Independent delimiter audit agrees at 178 bodies/blocks and 65 declarations, +with no missing or extra source locations. The broad search for other asm +spellings and standalone sources found only an ASM word in a comment. + +`git diff --check` passed. A final SHA1 check returned the required retail hash. +`git diff -- src libs include configure.py config` is empty. No production code, +data, function or link measure changed; the full gate reports zero regressions. +The inventory still blocks a fully-decompiled claim because 13 placeholders +remain. The sole placeholder with no recorded C score is OSInit. diff --git a/tools/test_workflow_guards.py b/tools/test_workflow_guards.py index 2aac76ef..fd16793b 100644 --- a/tools/test_workflow_guards.py +++ b/tools/test_workflow_guards.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import copy import json +import subprocess import sys import tempfile import unittest @@ -9,6 +10,132 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from check_decomp_complete import check_dol, check_report, exact +from check_asm_inventory import check_inventory + + +class AssemblyInventoryTests(unittest.TestCase): + def setUp(self): + directory = tempfile.TemporaryDirectory() + self.addCleanup(directory.cleanup) + self.root = Path(directory.name) + for name in ("src", "libs", "docs"): + (self.root / name).mkdir() + (self.root / "configure.py").write_text("objects = []\n", encoding="utf-8") + + def inventory(self, *rows): + text = "| File | Function | Classification | Evidence |\n| --- | --- | --- | --- |\n" + for file, function, verdict in rows: + text += f"| `{file}` | `{function}` | {verdict} | test fixture |\n" + (self.root / "docs/asm-inventory.md").write_text(text, encoding="utf-8") + + def check(self): + return check_inventory(self.root) + + def test_asm_declarations_comments_and_literals_are_not_bodies(self): + source = r''' +extern "C" asm void declared(); +asm int Widget::declared() const; +// asm void comment() { nofralloc } +/* void comment() { asm { sync } } */ +const char* message = "asm { nofralloc }"; +const char* raw = R"tag(quote " asm { sync })tag"; +// continued comment \ +asm void hidden() { nofralloc } +''' + (self.root / "src/declared.cpp").write_text(source, encoding="utf-8") + self.inventory() + bodies, _, failures = self.check() + self.assertEqual(bodies, []) + self.assertEqual(failures, []) + + def test_all_inline_forms_and_inactive_headers_are_inventoried(self): + source = ''' +asm void whole() { nofralloc; blr; } +void mixed() { if (ready) { asm volatile { sync } } __asm__("isync"); } +int Widget::read() const { __asm { mfspr r3, 1 } return 0; } +void bare() { nofralloc; blr; } +#if 0 +void inactive() { asm("sync"); } +#endif +''' + (self.root / "libs/arch.h").write_text(source, encoding="utf-8") + names = {"whole", "mixed", "Widget::read", "bare", "inactive"} + self.inventory(*[("libs/arch.h", name, "ORIGINAL") for name in sorted(names)]) + bodies, _, failures = self.check() + self.assertEqual({body.function for body in bodies}, names) + self.assertEqual(len(bodies), 6) + self.assertEqual(failures, []) + + def test_unlisted_asm_fails(self): + (self.root / "src/missing.c").write_text("void missing() { asm { sync } }", encoding="utf-8") + self.inventory() + self.assertIn("unlisted assembly: src/missing.c: missing", self.check()[2]) + + def test_placeholder_and_original_cli_exit_codes(self): + (self.root / "src/entry.c").write_text("asm void entry() { nofralloc; blr; }", encoding="utf-8") + script = Path(__file__).resolve().with_name("check_asm_inventory.py") + for verdict, status in (("PLACEHOLDER", 1), ("ORIGINAL", 0)): + with self.subTest(verdict=verdict): + self.inventory(("src/entry.c", "entry", verdict)) + result = subprocess.run([sys.executable, str(script), "--root", str(self.root)], capture_output=True, text=True) + self.assertEqual(result.returncode, status, result.stderr) + if status: + self.assertIn("placeholder: src/entry.c: entry", result.stderr) + else: + self.assertIn("ASM INVENTORY PASS", result.stdout) + + def test_utf16_source_is_scanned(self): + (self.root / "src/wide.cpp").write_text("asm void wide() { nofralloc; blr; }", encoding="utf-16") + self.inventory() + self.assertIn("unlisted assembly: src/wide.cpp: wide", self.check()[2]) + + def test_configured_assembly_and_tree_assembly_are_scanned(self): + (self.root / "boot").mkdir() + (self.root / "configure.py").write_text('objects = [Object(Matching, "boot/start.s")]\n', encoding="utf-8") + (self.root / "boot/start.s").write_text(".text\n.global start\nstart:\n sync\n.Lloop:\n blr\n", encoding="utf-8") + (self.root / "libs/helper.S").write_text(".section .text\n.fn helper, global\n blr\n.endfn helper\n", encoding="utf-8") + (self.root / "src/labels.s").write_text(".text\n.globl first, lbl_exported\nfirst:\n b first\nlbl_exported:\n blr\n.data\nvalue:\n.long 1\n", encoding="utf-8") + self.inventory(("boot/start.s", "start", "ORIGINAL"), ("libs/helper.S", "helper", "ORIGINAL"), ("src/labels.s", "first", "ORIGINAL")) + self.assertIn("unlisted assembly: src/labels.s: lbl_exported", self.check()[2]) + self.inventory(("boot/start.s", "start", "ORIGINAL"), ("libs/helper.S", "helper", "ORIGINAL"), ("src/labels.s", "first", "ORIGINAL"), ("src/labels.s", "lbl_exported", "ORIGINAL")) + self.assertEqual(self.check()[2], []) + + def test_unresolved_configured_assembly_fails(self): + (self.root / "configure.py").write_text('objects = ["missing.s"]\n', encoding="utf-8") + self.inventory() + self.assertTrue(any("unresolved" in failure for failure in self.check()[2])) + + def test_dynamic_assembly_path_requires_inspection(self): + (self.root / "configure.py").write_text('objects = [path + ".s"]\n', encoding="utf-8") + self.inventory() + self.assertTrue(any("dynamic assembly path" in failure for failure in self.check()[2])) + + def test_unknown_syntax_and_unowned_assembly_fail_closed(self): + self.inventory() + for source in ("nofralloc", 'asm("sync");', "#define HARDWARE asm { sync }"): + with self.subTest(source=source): + (self.root / "src/unknown.c").write_text(source, encoding="utf-8") + self.assertTrue(self.check()[2]) + (self.root / "src/unknown.c").unlink() + (self.root / "src/unowned.s").write_text(".text\nblr\n", encoding="utf-8") + self.assertTrue(any("without a function label" in failure for failure in self.check()[2])) + (self.root / "src/unowned.s").write_text(".text\nfirst: blr\nsecond: blr\n", encoding="utf-8") + self.inventory(("src/unowned.s", "first", "ORIGINAL")) + self.assertTrue(any("untyped assembly label" in failure for failure in self.check()[2])) + + def test_same_name_in_distinct_functions_is_not_silently_merged(self): + (self.root / "src/scopes.cpp").write_text("namespace one { void f() { asm { sync } } }\nnamespace two { void f() { asm { isync } } }", encoding="utf-8") + self.inventory(("src/scopes.cpp", "f", "ORIGINAL")) + self.assertTrue(any("ambiguous assembly function name" in failure for failure in self.check()[2])) + + def test_stale_duplicate_and_invalid_rows_fail(self): + self.inventory(("src/gone.c", "gone", "ORIGINAL"), ("src/gone.c", "gone", "UNKNOWN")) + failures = self.check()[2] + for message in ("stale inventory entry", "duplicate entry", "invalid entry"): + self.assertTrue(any(message in failure for failure in failures), failures) + + def test_missing_inventory_fails(self): + self.assertTrue(any("inventory:" in failure for failure in self.check()[2])) class WorkflowGuardTests(unittest.TestCase):