"""Is asd_encoder_state_check's unbounded index reachable from the host? asd_encoder_state_check does, with NO bound on a1 (its sibling asd_connector_state_check bounds a1<=8 for the SAME table): LDRB R1, [0xD42660 + 3*a1 + 2] a1 comes from topology entry+20, which asd_topology_update writes from host data. Test: drive each dword of the DTM topology struct to a huge value, then poke the HDCP/topology paths, and watch for a PSP fault. A data abort at 0xD42660+3*a1+2 would show as a TA hang / sOS death. Health checked after every step; recovery is a proven link reset + cold cycle. """ import ctypes,struct,sys,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); P='/Users/user/dev/amd-psp-re/psp_out/'; S=0x8000 def stat(): return int.from_bytes(bytes(adev.vram.view(psp.cmd_paddr,SZ)[:])[864:868],"little") def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True); return pa,adev.paddr2mc(pa) def load(cmd,blob): ap,amc=alloc(0x40000); cp,cmc=alloc(S) adev.vram.view(ap,len(blob))[:]=blob; adev.gmc.flush_hdp() adev.vram.view(psp.cmd_paddr,SZ)[:]=b"\x00"*SZ c=am.struct_psp_gfx_cmd_resp(cmd_id=cmd); t=c.cmd.cmd_load_ta t.app_phy_addr_hi,t.app_phy_addr_lo=hi32(amc),lo32(amc); t.app_len=len(blob) t.cmd_buf_phy_addr_hi,t.cmd_buf_phy_addr_lo=hi32(cmc),lo32(cmc); t.cmd_buf_len=S return psp._ring_submit(c).resp.session_id, cp def inv(sid,shm,buf,tc): adev.vram.view(shm,S)[:]=bytes(buf); adev.gmc.flush_hdp() adev.vram.view(psp.cmd_paddr,SZ)[:]=b"\x00"*SZ ic=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_INVOKE_CMD); iv=ic.cmd.cmd_invoke_cmd iv.session_id,iv.ta_cmd_id=sid,tc try: psp._ring_submit(ic); ps=0 except RuntimeError: ps=stat() except TimeoutError: return "TIMEOUT",None return ps, bytes(adev.vram.view(shm,S)[:]) asd,_=load(am.GFX_CMD_ID_LOAD_ASD,open(P+'asd_full.bin','rb').read()) dtm,dsh=load(am.GFX_CMD_ID_LOAD_TA,open(P+'dtm_full.bin','rb').read()) hdcp,hsh=load(am.GFX_CMD_ID_LOAD_TA,open(P+'hdcp_full.bin','rb').read()) print("sids asd=%#x dtm=%#x hdcp=%#x MEMSIZE=%s"%(asd,dtm,hdcp,hex(adev.rreg(0xde3)))) def topo(h, fields): b=bytearray(S); struct.pack_into(' %s ; health=%s"%(BASE,topo(0,BASE),health())) print("baseline hdcp 0x0E -> %s ; 0x10 -> %s"%(hdcpcmd(0x0E),hdcpcmd(0x10))) HUGE=[0x10000000,0x40000000,0x7fffffff,0xfffffff0] for slotidx in range(len(BASE)): for hv in HUGE[:2]: f=list(BASE); f[slotidx]=hv r=topo(0,f) a1,m1=health() # poke the paths that touch the topology entry r2=hdcpcmd(0x0E); r3=hdcpcmd(0x10); r4=hdcpcmd(0x12) a2,m2=health() flag="" if not a2 or m2!='0x5ff0' or r2[0]=="TIMEOUT" or r3[0]=="TIMEOUT" or r4[0]=="TIMEOUT": flag=" <<<< FAULT" print(" field[%d]=%#010x topo=%-5s 0x0E=%-14s 0x10=%-14s 0x12=%-14s alive=%s MEM=%s%s"%( slotidx,hv,r,r2,r3,r4,a2,m2,flag)) if flag: print(" !! stopping on fault"); sys.exit(2) # restore topo(0,BASE) print("\nfinal health:",health())