diff options
| author | user <user@clank> | 2026-10-09 16:11:31 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-10-09 16:11:31 +0200 |
| commit | bc43149d914325e15dc0490dee9d982e21287623 (patch) | |
| tree | a632cf70de742d5a60d01c9c0d806bf5b9257538 /psp_emu/harness/probe_sysdrv_1076_dispatch.py | |
| parent | GCP->ASD 0x403: ASD-internal chain PROVEN end-to-end in emulator (real handlers) (diff) | |
| download | amd-psp-re-main.tar.gz amd-psp-re-main.tar.xz amd-psp-re-main.zip | |
Diffstat (limited to 'psp_emu/harness/probe_sysdrv_1076_dispatch.py')
| -rw-r--r-- | psp_emu/harness/probe_sysdrv_1076_dispatch.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/psp_emu/harness/probe_sysdrv_1076_dispatch.py b/psp_emu/harness/probe_sysdrv_1076_dispatch.py new file mode 100644 index 0000000..61f1189 --- /dev/null +++ b/psp_emu/harness/probe_sysdrv_1076_dispatch.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""Signed SYS_DRV .54 opcode 0x1076 short-output test, synthetic caller region. + +No sOS/GCP transport or hardware effects are modeled. The successful selector-1 +path also clears SYS_DRV internal state and invokes SVC 0x7B: never use this +harness as a justification for an unplanned hardware request. +""" +from __future__ import annotations + +import sys +from pathlib import Path + +from unicorn import UC_HOOK_CODE +from unicorn.arm_const import UC_ARM_REG_R1 + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from pspemu import sysdrv_env # noqa: E402 +from pspemu.component import Fault # noqa: E402 + +SIGNED = Path(__file__).resolve().parents[2] / 'psp_out/elf/sys_drv_0.49.0.54_18bd9d26.elf' +ENTRY = 0xE087E4 +LEAF = 0xE2005C +TABLE = 0xE6873C +END_OF_GCP = 0x41C000 + + +def main() -> None: + sd = sysdrv_env.make() + assert Path(sd.image_path).read_bytes() == SIGNED.read_bytes(), 'image differs from signed .54' + init_ret, init_fault, _ = sysdrv_env.run_init(sd) + assert init_ret == 0 and not init_fault and sysdrv_env.init_flag(sd) == 1 + req, cfg = sd.alloc(0x100), sd.alloc(0x400) + sd.write(cfg, b'\x00' * 0x400) + seen = [] + sd.uc.hook_add(UC_HOOK_CODE, lambda uc, ea, size, data: seen.append(ea), + begin=LEAF, end=LEAF) + + sd.write(req, b'\x00' * 0x100) + for i, v in ((0, 0x1076), (1, 2), (sysdrv_env.REQ_CONFIG_DWORD, cfg)): + sd.wr32(req + 4 * i, v) + for declared in (4, 52): + out = sd.alloc(0x80, fill=b'\xA5') + sd.wr32(out, 1) # selector 1 selects the fixed 24-byte zeroing branch + sd.wr32(req + 8, out) + sd.wr32(req + 12, declared) + sd.wr32(TABLE + 4, 0x55667788) + before = len(seen) + rv = sd.run_function(ENTRY, (req, 2, 0, 0), count=3_000_000, + timeout=4_000_000) + after = sd.read(out, 0x80) + assert rv == 0 and len(seen) == before + 1 and not sd.faults, (rv, sd.faults) + assert after[:4] == b'\x01\x00\x00\x00' + assert after[4:28] == b'\xA5' * 24 and after[28:52] == b'\x00' * 24 + assert after[52:] == b'\xA5' * (0x80 - 52) + assert sd.rd32(TABLE + 4) == 0 + print('declared', declared, 'status', hex(rv), 'leaf', len(seen) - before, + 'changed offsets 28..51; synthetic table cleared') + + # Caller-window model, not the live sOS/GCP mapping. The declaration of 52 + # must be rejected, while 4 may pass and then fault at the first store. + base, end = 0x400000, END_OF_GCP + sd.uc.mem_map(base, end - base) + edge = end - 4 + sd.wr32(edge, 1) + sd.wr32(req + 8, edge) + sd.wr32(TABLE + 4, 0x55667788) + + def caller_window(comp, num): + descriptor = comp.uc.reg_read(UC_ARM_REG_R1) + for i, val in enumerate((base, end, 0, 0)): + comp.wr32(descriptor + 4 * i, val) + return 0 + + sd.svc.register(0xB5, caller_window) + before = len(seen) + sd.wr32(req + 12, 52) + rejected = sd.run_function(ENTRY, (req, 2, 0, 0), count=3_000_000, + timeout=4_000_000) + assert rejected != 0 and len(seen) == before + assert sd.rd32(edge) == 1 and sd.rd32(TABLE + 4) == 0x55667788 + sd.wr32(req + 12, 4) + try: + sd.run_function(ENTRY, (req, 2, 0, 0), count=3_000_000, + timeout=4_000_000) + except Fault as exc: + assert end <= exc.addr < end + 0x40, (exc, sd.faults) + assert len(seen) == before + 1 and sd.rd32(TABLE + 4) == 0x55667788 + assert sd.rd32(edge) == 1 + print('synthetic window: length52 rejected', hex(rejected), + 'length4 first out-of-range store faults at', hex(exc.addr)) + else: + raise AssertionError('short length did not fault at synthetic window edge') + + +if __name__ == '__main__': + main() |
