b22: rollback NOP + S9v3 baked (sp reset)

This commit is contained in:
SashegDev
2026-09-13 10:31:40 +00:00
parent c29860618f
commit f2510065ea
3 changed files with 112 additions and 7 deletions
+17 -3
View File
@@ -236,6 +236,7 @@ def main():
# immune to [0]-writes that clobber a static maze copy
from unicorn.arm_const import UC_ARM_REG_PC as _PC
_nulllog = []
_halt_on_null = "--haltonnull" in sys.argv
def hook_null(mu, addr, size, data):
if len(_nulllog) < 10:
@@ -247,6 +248,8 @@ def main():
r, lr, sp = [], -1, -1
# walk back: find the branch source from hist
_nulllog.append((count[0], r, lr, sp))
if _halt_on_null and len(_nulllog) == 1:
return False
mu.reg_write(_PC, STUB + 1)
mu.hook_add(UC_HOOK_CODE, hook_null, begin=0x0, end=0xFFF)
@@ -313,6 +316,15 @@ def main():
"ff2c13d940f20004c0f2220440f20005c0f2220540f2000a"
"c0f6060a41f2000bc0f6060bdff800f081f60208dff800f0"
"a53b0108"))
# S9 stublet (62B @0x08006C48, b22): labyrinth-epilogue exit router.
# ldr r3,[sp,#0x14]: nonzero -> original pop.w (legit return);
# zero (empty scaffold frames) -> restore r0/r4/r5/sl/fp, reset sp
# to 0x085FFF00 (fresh STUBV-fill stack), jump to sbl_main 0x802f69d
# via ip (no literal loads).
mu.mem_write(0x08006C48, bytes.fromhex(
"059b0bb1bde8f081002040f20004c0f2220440f20005c0f2"
"220540f2000ac0f6060a41f2000bc0f6060b4ff60073c0f6"
"5f039d464ff29d6cc0f6020c6047"))
# stack zone fill (STUBV odd)
mu.mem_write(0x085F0000, struct.pack("<I", STUBV) * (0x10000 // 4))
# pop-site slots (sp values from traces)
@@ -349,7 +361,7 @@ def main():
# --- end parity ---
# stub range is readonly on HW/QEMU: ignore SBL heap-clobber writes,
# keep maze/stublets intact (restore-on-write with reentrancy guard)
STUB_LO, STUB_HI = 0x080068C0, 0x08006C50 # +S7 + banner tail
STUB_LO, STUB_HI = 0x080068C0, 0x08006C90 # +S7/S9 + banner tail
stub_snap = bytes(mu.mem_read(STUB_LO, STUB_HI - STUB_LO))
_inww = [False]
_swn = [0]
@@ -461,8 +473,10 @@ def main():
print("hist:", [hex(pc) for pc, _ in list(hist)[-12:]])
if elog is not None:
print(f"entries: {len(elog)}")
for n, prev, cur in elog[-30:]:
print(f" insn#{n} {prev:#x} -> {cur:#x}")
for n, prev, cur in elog[:10]:
print(f" FIRST insn#{n} {prev:#x} -> {cur:#x}")
for n, prev, cur in elog[-10:]:
print(f" LAST insn#{n} {prev:#x} -> {cur:#x}")
if _splog is not None:
print(f"sp-highs: {len(_splog)}")
for n, pc, sp in _splog: