"""CORRECT field mapping, derived from dtm_cmd_topology_update_v2 disassembly: STM SP,{R0-R3,R6,R7} from R7=req+8 -> SP+0x00=req[2] .. SP+0x14=req[7] STR R5,[SP+0x18] where R5=req[8] STR R6,[SP+0x1C] where R6=req[9] STRD R0,R1,[SP+0x20] from req[10],req[11] STR R2,[SP+0x28] = req[12] STR R3,[SP+0x30] = normalised req[13] STR R5,[SP+0x34] = req[14] descriptor a2[k] -> entry+(8+k): entry+20 (INDEX) = a2[12] = SP+0x0C = req[5] entry+32 (!=0) = a2[24] = SP+0x18 = req[8] entry+40 (==0x30) = a2[32] = SP+0x20 = req[10] Earlier tests drove req[6] as the index -> wrong field, hence the false negatives. """ 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(idx=None, e32=None, e40=None, link=0): req=[4]*1 + [0]*24 req[0]=4; req[1]=1 # req[1]!=0 -> update path req[9]=0 # bounded <=0x17 if idx is not None: req[5]=idx # entry+20 (the unbounded index) if e32 is not None: req[8]=e32 # entry+32 (must be non-zero) if e40 is not None: req[10]=e40 # entry+40 (must be 0x30) b=bytearray(S) for i,v in enumerate(req): struct.pack_into('