"""LOAD_IP_FW (ring cmd 6) with fw_type in {49,50,85} -- the branch that SKIPS the size gate. Explicitly flagged untouched in earlier notes. sysdrv_tee_load_firmware (0xE12D80) gate: fw_type >= 0x62 -> 0x8000030A fw_type in {0x31,0x32,0x55}-> skip the size check entirely otherwise -> size must be > 0xFF (a MINIMUM, not a maximum) ring == 0xFFFF -> fw_type_is_known() is SKIPPED (host ring is 0xFFFF) So for these three types the host can drive the loader with a SMALL or ZERO size, which the >0xFF requirement normally forbids. ATTACK-SURFACE only ever recorded size>0xFF (which hangs) and size<=0xFF for other types (0xFFFF0010). Non-destructive intent: small sizes only, valid VRAM source buffer, never the large-size case that is known to hang. Compares the three special types against ordinary types as controls. """ import ctypes, time from tinygrad import Device from tinygrad.runtime.autogen.am import am from tinygrad.helpers import lo32, hi32 d = Device["AMD"]; adev = d.iface.dev_impl; psp = adev.psp SZ = ctypes.sizeof(am.struct_psp_gfx_cmd_resp) def alive(): return adev.reg(f"{psp.reg_pref}_81").read() != 0 def stat(): return int.from_bytes(bytes(adev.vram.view(psp.cmd_paddr, SZ)[:])[864:868], "little") # a real, mapped VRAM buffer with a position-dependent fill pa = adev.mm.palloc(0x10000, align=0x1000, zero=True) mc = adev.paddr2mc(pa) adev.vram.view(pa, 0x1000)[:] = bytes(((i * 7 + 0x5A) & 0xFF) for i in range(0x1000)) adev.gmc.flush_hdp() def load_ip_fw(fw_type, size): adev.vram.view(psp.cmd_paddr, SZ)[:] = b"\x00" * SZ c = am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_LOAD_IP_FW) t = c.cmd.cmd_load_ip_fw t.fw_phy_addr_hi, t.fw_phy_addr_lo = hi32(mc), lo32(mc) t.fw_size = size t.fw_type = fw_type t0 = time.time() try: psp._ring_submit(c); s = 0 except RuntimeError: s = stat() except TimeoutError: return "TIMEOUT", time.time() - t0 return s, time.time() - t0 print("fw_type size status dt alive") SPECIAL = [49, 50, 85] CONTROL = [1, 2, 0x3C, 0x40, 0x61] for ft in SPECIAL + CONTROL: tag = "SPECIAL" if ft in SPECIAL else "control" for size in (0, 0x10, 0x80, 0xFF): if not alive(): print("!! sOS dead -- stopping"); break s, dt = load_ip_fw(ft, size) ss = s if isinstance(s, str) else hex(s) print(" %3d %-8s 0x%04x %-12s %6.3fs %s" % (ft, tag, size, ss, dt, alive())) else: continue break print("\nsOS alive at end:", alive())