forked from arti/vt1200
checkpoint: VT1200 reverse-engineering workspace before board-model work
This commit is contained in:
commit
acb92d3e44
325 files changed
+951894
No files matched your search
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Map ROM string refs to enclosing functions in the unidasm output."""
|
||||
import bisect
|
||||
import re
|
||||
import struct
|
||||
|
||||
ASM = "/tmp/opencode/v22.asm"
|
||||
ROM = "vt1200_v22.bin"
|
||||
ROM_BASE = 0x07E40000
|
||||
|
||||
lines = []
|
||||
with open(ASM) as f:
|
||||
for line in f:
|
||||
head = line.split(":", 1)[0].strip()
|
||||
try:
|
||||
a = int(head, 16)
|
||||
except ValueError:
|
||||
continue
|
||||
lines.append((a, line.rstrip("\n")))
|
||||
addrs = [a for a, _ in lines]
|
||||
|
||||
# function prologues: MMTM SP, ... ; MOVE A14,A13
|
||||
entries = []
|
||||
for i, (a, t) in enumerate(lines):
|
||||
if "MMTM SP," in t:
|
||||
# look ahead a few instructions for MOVE A14,A13
|
||||
for j in range(i + 1, min(i + 4, len(lines))):
|
||||
if "MOVE A14,A13" in lines[j][1]:
|
||||
entries.append(a)
|
||||
break
|
||||
|
||||
print(f"{len(entries)} function entries (MMTM prologue)")
|
||||
|
||||
|
||||
def enclosing(bitaddr):
|
||||
i = bisect.bisect_right(entries, bitaddr) - 1
|
||||
return entries[i] if i >= 0 else None
|
||||
|
||||
|
||||
def main():
|
||||
image = open(ROM, "rb").read()
|
||||
pat = re.compile(r"DMUL|DMUX|demultiplex|Illegal slot|service class|"
|
||||
r"STOP_SLOT|ATTN|DATA_B|Data_A|host_credits|Multiplex|"
|
||||
r"insert_latjob|LAT_CREATE|LAT_CLOSE|LAT_SEND|lat session|"
|
||||
r"slot|extinct|circuit|Circuit|Calloc")
|
||||
for m in re.finditer(rb"[\x20-\x7e]{4,}", image):
|
||||
s = m.group().decode("latin1")
|
||||
if not pat.search(s):
|
||||
continue
|
||||
off = m.start()
|
||||
val = (ROM_BASE + off) << 3
|
||||
p = struct.pack("<I", val)
|
||||
start = 0
|
||||
refs = []
|
||||
while True:
|
||||
i = image.find(p, start)
|
||||
if i < 0:
|
||||
break
|
||||
refs.append(i * 8)
|
||||
start = i + 1
|
||||
if not refs:
|
||||
continue
|
||||
for r in refs:
|
||||
e = enclosing(r)
|
||||
print(f"func 0x{(e or 0)//8:06X} ref 0x{r//8:06X} str 0x{off:06X} {s!r}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user