"""RETEST: previous run never satisfied the gate. asd_encoder_query reaches asd_encoder_state_check only when: entry+40 == 0x30 (host: a2[32]) entry+32 != 0 (host: a2[24]) then passes entry+20 (host: a2[12]) as the UNBOUNDED index into 0xD42660+3*a1+2. asd_topology_update mapping (a2 = the 0x40-byte struct): a2[0]->entry+8 a2[4]->+12 a2[8]->+16 a2[12]->+20 a2[16]->+24 a2[20]->+28 a2[24]->+32 a2[28]->+36 a2[32]->+40 In our DTM frame the struct starts at buf+0x14, so field[i] = a2[4*i]: field3 -> entry+20 (INDEX) field6 -> entry+32 (!=0) field8 -> entry+40 (==0x30) """ 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 topo(h, f): b=bytearray(S); struct.pack_into('