#!/usr/bin/env python3 """Name an SMN address from the NV22_A0 memory map. No hardware access whatsoever -- this is a lookup table, and is the safe way to get value out of a memory map. FINDING-NO-PSP-MEMORY-APERTURE.md left several decoding SMN bases recorded as "small, unidentified"; a naming dictionary turns those into leads without touching the card. python3 smn_name.py 0x1300000 0x10100000 ... python3 smn_name.py --block MP_MP0MMU The map is NV22_A0 and the card is NV31, so a name is a HYPOTHESIS about what lives at an address, never a confirmation. Anything acted on must be checked against the card in small batches with a health check, per the rule in FINDING-NO-PSP-MEMORY-APERTURE.md. """ import os import sys MAP = os.path.expanduser("~/nv22_a0_memmap.txt") def load(): rows = [] with open(MAP) as fh: for line in fh: if line.startswith("#"): continue p = line.split() if len(p) < 4 or not p[0].startswith("0x"): continue try: addr = int(p[0], 16) except ValueError: continue rows.append((addr, p[2], p[3])) return rows def name_at(rows, addr, window=0x10000): exact = [r for r in rows if r[0] == addr] if exact: return exact, 0 near = [r for r in rows if 0 <= addr - r[0] < window] if not near: return [], None best = max(r[0] for r in near) return [r for r in near if r[0] == best], addr - best def main(): rows = load() args = sys.argv[1:] if not args: print(__doc__) return 2 if args[0] == "--block": pref = args[1].upper() seen = set() for a, kind, nm in sorted(rows): base = nm.split(".")[0].upper() if base.startswith(pref) and nm not in seen: seen.add(nm) print(" %#010x %-6s %s" % (a, kind, nm)) return 0 for s in args: addr = int(s, 0) hits, delta = name_at(rows, addr) if not hits: print("%#012x : no NV22 row within 64K below it" % addr) continue tag = "exact" if delta == 0 else "base+%#x" % delta names = sorted({h[2].split("[")[0] for h in hits}) print("%#012x : %-10s %s" % (addr, tag, ", ".join(names[:4]))) return 0 if __name__ == "__main__": sys.exit(main())