S12v5: r7 restore in-stub

This commit is contained in:
SashegDev
2026-09-13 12:20:35 +00:00
parent 68fab44137
commit 757e74fb4f
3 changed files with 38 additions and 9 deletions
+32 -5
View File
@@ -104,6 +104,13 @@ def main():
calls = [] if "--calltrace" in sys.argv else None
rets = [] if "--retrace" in sys.argv else None
qlog = [] if "--querylog" in sys.argv else None
# frozen-maze breaker: maze entries with identical lr and no bl
# between them mean a zero-state-change spin (maze->mid-fn->maze).
# After K, redirect once to poll resumption (fresh bls unfreeze lr).
_fmlr = [None]
_fmct = [0]
_FMK = 50
_FMPC = 0x8007779
_traps = []
_trap_n = [0]
if "--trap" in sys.argv:
@@ -127,6 +134,25 @@ def main():
def hook_code(mu, addr, size, data):
count[0] += 1
last[0] = addr
if 0x08006B8C <= addr < 0x08006B9E:
try:
_lr = mu.reg_read(_LR)
except Exception:
_lr = None
if _lr == _fmlr[0]:
_fmct[0] += 1
if _fmct[0] >= _FMK:
_fmct[0] = 0
_fmlr[0] = None
mu.reg_write(_PC, _FMPC)
return
else:
_fmlr[0] = _lr
_fmct[0] = 0
elif _fmlr[0] is not None:
# any non-maze fetch: reset only on bl (lr change means
# fresh calls; other insns keep the freeze assessment)
pass
if _splog is not None:
try:
sp = mu.reg_read(UC_ARM_REG_SP)
@@ -385,16 +411,17 @@ def main():
# to the dispatcher via stale lr (TZ bringup deferred).
# NOTE: overwrites 4B of real ARM trampoline (recoverable from ELF).
mu.mem_write(0x00221EF8, bytes([0x00, 0x20, 0x70, 0x47]))
# S12-stub (b27, 84B @0x08006964, ARM): blx-to-padding becomes
# S12-stub (b27, 92B @0x08006964, ARM): blx-to-padding becomes
# smart dispatcher: ldr ip,[sp,#4] (=pushed lr); ip==STUBV/even/
# non-code => ip=poll resumption 0x8007779; else keep pushed-lr;
# then ACK peripheral bit1 ([literal 0x073A100]); bx lr.
# PBL would place the real ARM helper here.
# restore r7 (peripheral base, S16 dormant); ACK peripheral bit1
# ([literal 0x073A100]); bx lr. PBL would place the real helper.
mu.mem_write(0x08006964, bytes.fromhex(
"04c09de58d3b06e3003840e303005ce10700000a0100"
"1ce30500000a2c3ca0e1080053e30400000a2c3ea0e1"
"080053e30100000a79c707e300c840e30c309fe50020"
"93e5022082e3002083e51eff2fe100a17300"))
"080053e30100000a79c707e300c840e300700ae37370"
"40e30c309fe5002093e5022082e3002083e51eff2fe1"
"00a17300"))
# S16-stublet (b27, 64B @0x08006CC0): smart return for B66 bx ip.
# ip==STUBV (fill/maze, never a legit return) => default;
# ip odd + top 8 (code) => add sp,#8 (pop the helper frame B66