b26: S17 safe-logger baked

This commit is contained in:
SashegDev
2026-09-13 12:08:22 +00:00
parent 13b314e9cf
commit 8b1eaeba18
4 changed files with 120 additions and 5 deletions
+7
View File
@@ -113,3 +113,10 @@
2B) → S16 проверяет ip (odd + top 8 = legit pushed-lr → `bx ip`; 2B) → S16 проверяет ip (odd + top 8 = legit pushed-lr → `bx ip`;
иначе default: restore r7, прыжок `0x8007779`). S12v3 грузит ip из иначе default: restore r7, прыжок `0x8007779`). S12v3 грузит ip из
`[sp+4]` (pushed lr) + ACK bit1. B66-патч в ELF (b25), S12/S16 в scaffold. `[sp+4]` (pushed lr) + ACK bit1. B66-патч в ELF (b25), S12/S16 в scaffold.
## b26: S17 safe-logger (2026-09-13)
- S8 (`bx lr`) гасил весь init-лог (UART пуст by design) вслепую.
S17 (50B @0x08006CF0): печать r1-строки в UARTDM-TF, только если r1
в rodata `[0x804B800,0x8058000)` (wild-указатели скипаются), затем
pop-return (без leak'а, возврат игнорируется). Логгер `0x8034810`
(`pop.w` 4B) → `b.w S17`. Видимость прогресса вместо счёта инстр.
+25 -4
View File
@@ -104,15 +104,15 @@ static void saimaa_tmr_init(Object *obj)
/* Stubs region handle for set_readonly after scaffold implant. */ /* Stubs region handle for set_readonly after scaffold implant. */
static MemoryRegion *saimaa_stubs_mr; static MemoryRegion *saimaa_stubs_mr;
/* DDRLOW stub trap [0x08006B80,0x08006CF0): serves the scaffolded bytes /* DDRLOW stub trap [0x08006B80,0x08006D30): serves the scaffolded bytes
* (S/maze/S6/banner/S7/S9/S10/S16 stubs) on read/fetch, ignores SBL * (S/maze/S6/banner/S7/S9/S10/S16/S17 stubs) on read/fetch, ignores SBL
* heap-clobber writes. Uni parity: deferred-restore guard in sbl_uni.py * heap-clobber writes. Uni parity: deferred-restore guard in sbl_uni.py
* (wider: [0x080068C0,0x08006CF0), also covers PBL stub). * (wider: [0x080068C0,0x08006D30), also covers PBL stub).
* Snapshot is taken AFTER ELF load + all stub writes (readback). * Snapshot is taken AFTER ELF load + all stub writes (readback).
* PBL stub [0x080068C0,0x080068F4) and the ELF-text gap below stay plain * PBL stub [0x080068C0,0x080068F4) and the ELF-text gap below stay plain
* RAM: PBL runs once (if at all), gap holds real hot SBL code. */ * RAM: PBL runs once (if at all), gap holds real hot SBL code. */
#define SAIMAA_DSTUB_BASE 0x08006B80 #define SAIMAA_DSTUB_BASE 0x08006B80
#define SAIMAA_DSTUB_SIZE 0x00000170 #define SAIMAA_DSTUB_SIZE 0x000001B0
static uint8_t saimaa_dstub_mem[SAIMAA_DSTUB_SIZE]; static uint8_t saimaa_dstub_mem[SAIMAA_DSTUB_SIZE];
static uint64_t saimaa_dstub_read(void *opaque, hwaddr off, unsigned size) static uint64_t saimaa_dstub_read(void *opaque, hwaddr off, unsigned size)
@@ -692,6 +692,27 @@ static void saimaa_machine_init(MachineState *machine)
cpu_physical_memory_write(0x08006C88 + k, &word, 4); cpu_physical_memory_write(0x08006C88 + k, &word, 4);
} }
} }
/* S17 safe-logger (50B @0x08006CF0, b26): print r1-string
* via UARTDM-TF iff r1 in rodata [0x804B800,0x8058000);
* pop-return (no leak). Replaces S8 silence with logs. */
{
static const uint8_t s17[] = {
0x4b, 0xf6, 0x00, 0x03, 0xc0, 0xf6, 0x04, 0x03,
0x99, 0x42, 0x11, 0xd3, 0x48, 0xf2, 0x00, 0x03,
0xc0, 0xf6, 0x05, 0x03, 0x99, 0x42, 0x0b, 0xd2,
0x10, 0xb5, 0x4f, 0xf2, 0x00, 0x03, 0xc0, 0xf2,
0x8a, 0x73, 0x0c, 0x46, 0x14, 0xf8, 0x01, 0x0b,
0x08, 0xb1, 0x18, 0x67, 0xfa, 0xe7, 0x10, 0xbd,
0x70, 0x47,
};
size_t k;
for (k = 0; k < sizeof(s17); k += 4) {
uint32_t word = 0;
size_t n = sizeof(s17) - k < 4 ? sizeof(s17) - k : 4;
__builtin_memcpy(&word, &s17[k], n);
cpu_physical_memory_write(0x08006CF0 + k, &word, 4);
}
}
/* PBL version-table fabrication (b23): [0x080528D0] = STUBV /* PBL version-table fabrication (b23): [0x080528D0] = STUBV
* so the rollback query's blx calls maze (0 = versions OK). */ * so the rollback query's blx calls maze (0 = versions OK). */
{ {
+82
View File
@@ -1044,6 +1044,88 @@ def main():
save(d, 'img0_b25.elf') save(d, 'img0_b25.elf')
# b26 = b25 + S17 safe-logger (0x8034810 pop.w -> b.w S17):
# S8 (bx lr) silenced all init logging (UART empty by design).
# S17 (50B @0x08006CF0, scaffold): print r1-string via UARTDM-TF
# only if r1 in rodata [0x804B800,0x8058000) (wild pointers skip),
# then pop-return (no leak, return value ignored by callers).
d = bytearray(base)
for va, (a, b) in BLX2BL.items():
set4(d, va, b)
for va, exp, new in [
(0x802F664, 'e4f77efc', 'c046c046'),
(0x802F672, 'e6f7bbfa', 'c046c046'),
(0x802F678, 'e9f7fef9', 'c046c046'),
(0x801B71E, '9847fee7', 'c046c046'),
(0x8008396, 'fef780f9', 'c046c046'),
(0x8016184, 'fdf790fc', 'c046c046'),
(0x801B76C, '280b0508', '00000708'),
(0x8017AFC, 'bde8fc87', 'eef74fb8'),
(0x802F690, '9847fee7', 'c046c046'),
(0x801671C, '9847fee7', 'c046c046'),
(0x8013BAC, 'f8bd0a4a', 'f3f730b8'),
(0x801B6BE, 'bde8f081', 'ebf7c3ba'),
(0x8016720, '10bd0000', 'f0f7b2ba'),
(0x8034810, 'bde8fc87', 'd2f76eba'),
]:
assert hx(d, va) == exp, (hex(va), hx(d, va))
set4(d, va, new)
# Full bl idiom at 0x8006682 (bl + pop, 6B) -> NOPs (see b18).
o = off(0x8006682)
assert d[o:o + 6].hex() == '00f001f807bd', hx(d, 0x8006682, 6)
d[o:o + 6] = bytes.fromhex('c046c046c046')
o = off(0x8013AA8)
assert d[o:o + 4].hex() == '07f026be', hx(d, 0x8013AA8)
d[o:o + 4] = bytes.fromhex('c046c046')
o = off(0x8013BA6)
assert d[o:o + 2].hex() == 'b888', (hex(0x8013BA6), hx(d, 0x8013BA6, 2))
d[o:o + 2] = bytes.fromhex('ff20')
# Helper-pop S16 chain (see b25).
o = off(0x8007B66)
assert d[o:o + 2].hex() == '10bd', hx(d, 0x8007B66, 2)
d[o:o + 2] = bytes.fromhex('6047')
# Clock S11 (see b24).
o = off(0x800E988)
assert d[o:o + 2].hex() == '10bd', hx(d, 0x800E988, 2)
d[o:o + 2] = bytes.fromhex('7047')
save(d, 'img0_b26.elf')
+6 -1
View File
@@ -367,6 +367,11 @@ def main():
# S10 stublet (10B @0x08006C88, b23): rollback-exit router. # S10 stublet (10B @0x08006C88, b23): rollback-exit router.
# movw/movt ip + bx ip to sbl_main 0x802f6a3. # movw/movt ip + bx ip to sbl_main 0x802f6a3.
mu.mem_write(0x08006C88, bytes.fromhex("4ff2a36cc0f6020c6047")) mu.mem_write(0x08006C88, bytes.fromhex("4ff2a36cc0f6020c6047"))
# S17 safe-logger (50B @0x08006CF0, b26): print r1-string via
# UARTDM-TF only if r1 in rodata [0x804B800,0x8058000); pop-return.
mu.mem_write(0x08006CF0, bytes.fromhex(
"4bf60003c0f60403994211d348f20003c0f605039942"
"0bd210b54ff20003c0f28a730c4614f8010b08b11867fae710bd7047"))
# PBL version-table fabrication (b23): [0x080528D0] = STUBV so the # PBL version-table fabrication (b23): [0x080528D0] = STUBV so the
# rollback query's blx calls maze (returns 0 = versions OK). # rollback query's blx calls maze (returns 0 = versions OK).
W32(0x080528D0, STUBV) W32(0x080528D0, STUBV)
@@ -430,7 +435,7 @@ def main():
# --- end parity --- # --- end parity ---
# stub range is readonly on HW/QEMU: ignore SBL heap-clobber writes, # stub range is readonly on HW/QEMU: ignore SBL heap-clobber writes,
# keep maze/stublets intact (restore-on-write with reentrancy guard) # keep maze/stublets intact (restore-on-write with reentrancy guard)
STUB_LO, STUB_HI = 0x080068C0, 0x08006CF0 # +S7/S9/S10/S16 + banner STUB_LO, STUB_HI = 0x080068C0, 0x08006D30 # +S7/S9/S10/S16/S17
stub_snap = bytes(mu.mem_read(STUB_LO, STUB_HI - STUB_LO)) stub_snap = bytes(mu.mem_read(STUB_LO, STUB_HI - STUB_LO))
_inww = [False] _inww = [False]
_swn = [0] _swn = [0]