"Who calls this?" is the question that stalls a reverse-engineering thread most often, and the usual answer — "nothing does" — is usually wrong. This sweep looks for every way the game can reach an address, across every code image on the disc at once, so that answer becomes a measurement instead of a shrug.
scripts/ghidra-analysis/find-address-word-refs.py - host-side, runs against extracted/, no Ghidra project neededSCUS_942.54 + all 31 recovered overlay images + (with --prot) the raw bytes of all 1233 archive entrieslui pair (completed by an addiu/ori or by a load / store's offset), jal, j, PC-relative branch - all in one passscripts/ghidra-analysis/find-gp-relative-refs.py covers the two forms it cannot see; a negative counts once both agreedispatch-table / template-field / incidental-code)unreferenced ignore-list categoryA call-graph tool looks for jal, the MIPS call instruction. Legaia reaches much of its code some other way, and each is invisible to that search:
lui + addiu/ori pair - and Ghidra's cross-reference index does not join the pairs back together (see Ghidra in Docker).FUN_ entry at each of those.Reach for this scan whenever a port-catalog row says "no caller", before you either port the routine or declare it dead. It is the instrument behind the rule that zero static callers in SCUS_942.54 does not mean dead in retail.
--rangelui pair / jal / j / branch, over SCUS + 31 overlays (+ raw PROT) find-address-word-refs.pystatic-overlays.tomlscripts/ghidra-analysis/find-address-word-refs.py 8005126c| Command | Does |
|---|---|
find-address-word-refs.py 8005126c --prot | Widen to every extracted PROT entry |
find-address-word-refs.py 801e58a8 --home field | Mark branch hits from slot siblings as aliases |
find-address-word-refs.py --range 800705fc:80070760 | Who references this table? |
find-address-word-refs.py --file addrs.txt --context | Batch a worklist, print neighbours |
find-address-word-refs.py 8004da00 --expect-scus 800767fc | Self-check with exit status |
| Form | What it is | Carries its target? |
|---|---|---|
| Literal word | The address stored as a 32-bit data word - a pointer-table entry or template field. | Yes |
lui pair | A lui plus a partner carrying the low half: an addiu/ori that materialises the address, or a load / store off the lui register - the commonest way retail reads a named global. | Yes (in two halves) |
jal | Ordinary call. | Yes |
j | Absolute jump (tail calls, dispatcher exits). | Yes |
| PC-relative branch | beq/bne/... - a distance, not a destination. | No - only meaningful inside its own image |
Reporting a hit as a memory address requires knowing where its containing file loads, and the three cases are kept apart because conflating them has put an impossible address into this project's own notes:
| Image | Load address comes from | A hit is reported as |
|---|---|---|
SCUS_942.54 | the PS-X EXE header t_addr | file offset and the one address it can be |
| Overlay images | crates/asset/data/static-overlays.toml (see static overlay pipeline) | offset and address, named by image |
Other archive entries (--prot) | none - streamed data | file offset only |
The middle row is the one that bites: many overlays load at the same address, so the same address is a different word in each of them - the image is as much of the answer as the offset. The bottom row is why streamed entries carry no address: inventing one would be exactly the phantom-VA defect the first row exists to avoid.
Only a word-aligned hit can be a table entry, so unaligned ones are reported as incidental. For the aligned ones, three counts over the surrounding bytes are printed alongside the verdict so it can be second-guessed:
| Count | Measures |
|---|---|
code | jr ra and addiu sp, sp, ±N words within ±0x200 - real code carries several, a pointer table none |
entry | Neighbouring words (±4) that are addresses landing on a function prologue in this same image |
ptr / const | Neighbouring words that are RAM-band addresses, or small constants |
dispatch-table needs two or more entry neighbours; template-field is a lone pointer among constants; incidental-code is a word inside an instruction stream. The verdict is triage, not a substitute for reading the disassembly at the hit.
A template inside a code region reads as incidental-code: code outranks the other counts, and a static actor template is a small constant record linked among the routines it seats, not in a data region - so its +0x8 tick word scores code > 0 with entry = 0 even though a lone pointer among constants is exactly the template shape. The tell is one word back: FUN_80020DE0 reads a template's +0x4 model selector, which is 0xFFFF for the transform-node helpers, so a routine's VA immediately after an ffff0000 word is a template's tick slot. 801D2298 (0897 field, template 0x801F2294) and 801D4098 (0980 dance, template 0x801D42FC) are both real, ported entries with exactly that shape. A template-seated routine collects one aligned word hit; an interior label collects no word hit at all.
Four of the five forms carry a copy of the address they reach, so a hit is evidence wherever it turns up. A branch encodes a distance, not a destination, so it can only reach code in its own image - a branch hit is evidence about that image's copy of the address and nothing else. Since overlays share load addresses, every one of them has a byte at every address: two routines on this project's inert-code list read as referenced for exactly this reason and are not (0x801CFE20 collects a branch from the field overlay, whose bytes there are an unrelated epilogue; 0x801E58A8 collects one from battle_action).
--home <image> makes the check mechanical: name the image that holds the routine (locate-entry-image.py answers that from the prologue) and branch hits from any other overlay print as br~ and tally under branch_alias. When a target's only hits are aliased branches, the tool says so outright; a typo'd name exits non-zero rather than quietly marking every hit an alias.
unreferenced ignore-list category as a documented negative.Sweeping every anchor the port catalog's audit lists as disclosed inert answers whether a row is waiting on wiring or on nothing. Almost all are waiting on wiring; these are the ones that are not:
| Address | Image | Routine |
|---|---|---|
8005126C | SCUS | battle actor on-screen test |
80035274 | SCUS | item / equipment passive-name draw |
80050D40 | SCUS | 12-bit angle tween |
80025054 | SCUS | actor-template tick; unreachable through its record 0x80070614 |
801CFE20 / 801CFE5C | 0970 cutscene_str | MDEC in / out sync wrappers |
801D0230 | 0970 cutscene_str | MDEC status-word leaf; both call sites are inside the two wrappers above |
801D5780 | 0897 field | generic arc-hop spawn |
801D5C2C | 0972 fishing | 3-D segment clip + projection |
801DAD6C | 0899 menu | five-step menu open sequence |
801DBA90 | 0898 battle_action | reward-banner composer |
801E5834 / 801E58A8 | 0897 field | pooled actor spawn + actor anim-clip pick |
Every row was checked with locate-entry-image.py first, so each begins where it is said to begin. The scan settles reachability, not identity: a row here still says nothing about whether the decoded behaviour is right. Per-routine write-ups live in the function directory.
A tool is only worth its negatives if its positives are checked, so it is run against known answers before a "nothing found" is believed: a known template word (8004da00 → exactly one hit at SCUS 0x800767FC, classified template-field; --expect-scus turns that into a pass/fail exit status), a known call target (800195a8 → jal sites across SCUS and five overlays, no word hits), a known branch target (80051308 → one BR site and nothing else), and a known dispatch table (--range over the menu overlay's sub-screen pointer array at 0x801E4F40 recovers its single materialisation site).
--prot scans raw bytes, so a reference inside an LZS-compressed entry is invisible. Overlay code is stored raw, so this gap does not cover the images callers actually live in.lui and one addiu/ori or load / store carrying the exact low half within a few instructions; the sibling gp-relative sweep's register walk covers an address assembled in more steps. table_base + index is covered to the extent the bytes allow: both scans carry the lui register through the indexing addu and report the array's base - never the element a runtime index picks - so a per-record negative over a table still needs the table base scanned before it means anything.scripts/ghidra-analysis/mips_walk.py, mirrored by the byte account's lui_forms): any other write drops the register, a copy or one runtime index carries it, a branch forks it, a call keeps only callee-saved registers past its delay slot, and jr ra ends the path. The earlier walk stopped only at another lui, and about a quarter of the pairs it formed were a high half paired with a register already rewritten; no recorded "unreferenced" verdict depended on one.PROT.DAT entry is reached by its index, not its address, and an index the code builds with arithmetic occurs nowhere as a constant. Two entries read as "loaded by nothing" for exactly that reason - their index is formed as addiu a0,s0,0x4c7 with a runtime register. Sweep the base of the arithmetic, not the value it produces.$gp and a split low half. Two forms this tool does not decode: a disp(gp) access, and an access whose low half is split between the base register and the operand's displacement. Both are in the sibling sweep; run it before reading a negative as "nothing references this".dispatch-table classification says the neighbours look like function entries, not that the runtime indexes them.BR hit in an image that does not hold the routine is not a reference to it; pass --home and read branch_alias.Three Ghidra-side scripts cover pieces of this from inside a loaded program (find_lui_writers.py, find_addr_data.py / find_data_word.py, find_terrain_emitter_caller.py - catalogued on Ghidra in Docker). They stay the right tool when you want the containing function of a hit, which they can name and this cannot; the host-side scan adds corpus and closure - every image at once, the raw PROT entries no Ghidra project holds, all five forms in one pass.
find-gp-relative-refs.py covers what the five-form sweep is structurally blind to:
disp(gp). A small-data access such as sw a0,0x678(gp) carries a 16-bit displacement and nothing else, so no scan for the absolute address can see it, writer or reader.lui a0,0x1f80; ori a0,a0,0x314; sb v0,0xd4(a0) writes 0x1F8003E8 without any instruction holding the address or its low half. This is how retail reaches every scratchpad byte and every field of a struct held in a register; the sweep walks the register forward from each lui to recover it.lui/load pair is found by both tools; this one reports it alongside the gp-relative accesses to the same slot, so one run answers "every access" for a small-data global.The gp form is a silent half-answer. The battle sound bank's record table at gp+0x678 has one gp-relative writer and seven lui+lw readers: a five-form sweep of 0x8007B990 finds the readers and not the writer, because the one instruction that fills the table carries only 0x678. $gp is written once by the runtime, and --find-gp decodes that pair rather than trusting a remembered value. A displacement scan needs no $gp at all, which makes it meaningful over raw archive entries - at the cost of coincidental hits in scene data, so read the disassembly before calling a hit a reference.
scripts/ghidra-analysis/find-gp-relative-refs.py --va 0x8007b990