#!/usr/bin/env python3 """End-to-end display chain in the emulator: ASD registration -> display RPCs. WHY THIS EXISTS `psp_out/ANGLE-DISPLAY-SINK-INPUT-SURFACE.md` traced a five-link chain from "can a monitor open attack surface" down to one blocker: display RPC surface reachable <- dest 2 (SERVICE_ASD) registered in sOS's table @0xE4A8 <- LOAD_TA asd returns 0, not 7 <- ASD's 0xFFFF0002 registration succeeds <- sub_D14AA4 returns 0 instead of 7 `sub_D14AA4` does: 00d14abc svc #0x8d ; -> sOS returns the byte at global 0x80D0 00d14abe subs r2, r0, #1 00d14ac2 movs r0, #7 ; default status 00d14ac4 cmp r2, #0x34 00d14ac6 bhi -> return 7 ; id must satisfy 1 <= id <= 0x35 00d14ac8 tbb [pc, r2] ; per-platform handler and sOS's SVC 0x8D handler is just 0000627c ldr r0, =0x000080d0 0000627e ldrb r4, [r0] ; return that byte Nothing in sOS, SYS_DRV or ASD ever WRITES 0x80D0 (one literal reference in the whole sOS image, and it is this reader). The byte is supplied by a boot stage this emulator does not run, so it is 0 here and ASD always declines registration. WHAT IS MODELLED, AND WHY THAT IS LEGITIMATE This harness writes that one byte. It is an INPUT handed to sOS by an earlier boot stage, not a result the firmware computes -- so supplying it models a missing environment, in the same class as the measured SVC values in `pspemu/services.py`. It is NOT a patch around firmware behaviour: every check, including ASD's own 1..0x35 range test and its per-platform dispatch, runs unmodified. The value is not invented either. ASD's own `tbb` table at 0xD14ACC defines which ids it accepts: 22 of the 53 entries have distinct handlers (0x1-0x5, 0x14-0x1b, 0x1d, 0x23-0x25, 0x2b, 0x2d, 0x31, 0x33, 0x35) and the other 31 route to the error path. The harness sweeps that firmware-defined set rather than guessing one. WHICH id is Navi31's is still UNKNOWN -- see the caveat printed at the end. CONTROLS positive : with a valid id, LOAD_TA asd must return 0 AND dest 2 must appear in sOS's service table negative : with the byte left at 0 (this emulator's normal state), LOAD_TA asd must still return 7 and dest 2 must stay unregistered Without the negative control a harness that always registers would look identical to one that proved something. """ import os import sys import struct sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import importlib.util # noqa: E402 _s = importlib.util.spec_from_file_location( "fs", os.path.join(os.path.dirname(os.path.abspath(__file__)), "full_system.py")) FS = importlib.util.module_from_spec(_s); _s.loader.exec_module(FS) BM, M = FS.BM, FS.M from pspemu.oracle import Probe # noqa: E402 PLATFORM_ID_BYTE = 0x80D0 # sOS global returned by SVC 0x8D SERVICE_TABLE = 0xE4A8 # sOS RPC service table; index 2 == SERVICE_ASD ASD_VALID_IDS = (0x1, 0x2, 0x3, 0x4, 0x5, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1d, 0x23, 0x24, 0x25, 0x2b, 0x2d, 0x31, 0x33, 0x35) def boot(platform_id=None): """Fresh boot; optionally supply the platform-id byte an earlier stage sets.""" c, ccp, irqs, exc = BM.build() run, _ = M.make_det_runner(c, irqs) BM.drain_until(run, lambda: int.from_bytes(c.uc.mem_read(M.RING_STATUS, 4), "little") == 0x80000000, slices=12, blocks=500_000) M.install_debug_gpio(c) box = M.Mailbox(c, irqs) if platform_id is not None: c.uc.mem_write(PLATFORM_ID_BYTE, bytes([platform_id])) c.uc.mem_write(BM.RING_PA, b"\x00" * BM.RING_SZ) rp = bytearray(0x1C) rp[0x10:0x14] = struct.pack(" %#x dest2 = %#x table = %s" % (off_status, off_dest2, off_table[:6].hex(" "))) on_status, on_dest2, on_table = load_asd(ASD_VALID_IDS[0]) print(" platform id = %#x (from ASD's own accepted set):" % ASD_VALID_IDS[0]) print(" LOAD_TA asd -> %#x dest2 = %#x table = %s" % (on_status, on_dest2, on_table[:6].hex(" "))) print() p = Probe("supplying the platform-id byte lets ASD register as service 2", measure=lambda: (on_status, on_dest2, off_status, off_dest2), positive=lambda: on_status == 0 and on_dest2 != 0, negative=lambda: off_status == 0 or off_dest2 != 0, positive_desc="with a valid id: LOAD_TA asd == 0 and dest 2 registered", negative_desc="with no id: LOAD_TA asd still 7 and dest 2 unregistered") rc = p.report(fmt=lambda v: "id set -> status %#x dest2 %#x | id unset -> status %#x dest2 %#x" % v) if rc: return rc print("\nStage 1b -- which of ASD's accepted ids actually register") ok = [] for pid in ASD_VALID_IDS: st, d2, _ = load_asd(pid) if st == 0 and d2: ok.append(pid) print(" %d/%d ids register: %s" % (len(ok), len(ASD_VALID_IDS), [hex(i) for i in ok])) rejected = [hex(i) for i in ASD_VALID_IDS if i not in ok] print(" ids ASD's table accepts but registration still refuses: %s" % (rejected or "none")) print("\nStage 2 -- HDCP cmd 0x0E through the registered service to the display RPC") chain = full_chain(ASD_VALID_IDS[0]) print(" asd=%#x dest2=%#x hdcp=%#x sess=%#x invoke=%#x" % (chain["asd"], chain["dest2"], chain["hdcp"], chain["sess"], chain["invoke"])) print(" links reached: %s" % chain["hits"]) print(" ASD blocks executed during the invoke: %d" % chain["asd_blocks"]) print(" RPC 0x1a0 returned: %s" % (hex(chain["rpc1a0_rv"]) if chain["rpc1a0_rv"] is not None else "not observed")) p2 = Probe("a host ring command drives HDCP into a display RPC serviced by REAL ASD", measure=lambda: (chain["hits"], chain["asd_blocks"]), positive=lambda: (chain["invoke"] != 0xDEADBEEF and chain["hits"].get("hdcp_cmd0E") and chain["hits"].get("rpc_0x1a0") and chain["hits"].get("asd_dispatcher") and chain["asd_blocks"] > 0), negative=lambda: chain["dest2"] == 0, positive_desc="cmd 0x0E -> sub_404626 -> RPC 0x1a0 -> ASD dispatcher, ASD code runs", negative_desc="ASD is genuinely registered (dest 2 non-zero)") rc2 = p2.report(fmt=lambda v: "links %s, %d ASD blocks" % (v[0], v[1])) if rc2: return rc2 print() print("Stage 3 -- sink model at ASD's svc 0x7b: NOT YET EXERCISABLE") print(" RPC 0x1a0 returns %s from ASD, and ASD performs no svc 0x7b register" % (hex(chain["rpc1a0_rv"]) if chain["rpc1a0_rv"] is not None else "?")) print(" reads while servicing it, so there is no display-register access to") print(" answer yet. cmd 0x0E therefore stops at sub_404626 and never reaches") print(" RPC 0x103 (gate B). Next: why ASD answers 0x1a0 with that status.") print() print("CAVEAT, stated so this is not over-read: the platform id for THIS part") print("(Navi31/gfx1100) is not known. Registration succeeding under a swept id") print("shows the mechanism and unblocks the chain; it does not establish which") print("id real silicon reports -- so stage 2 proves the PATH is live, not that") print("this is the configuration real hardware boots into.") return 0 if __name__ == "__main__": sys.exit(main())