#!/usr/bin/env python3 """Ring-command dword +0x24 is the only field in the invoke structure that is validated. A full-resolution sweep of all 196 dwords showed only +0x24 changes the status (0x2a when all-ones). A validated field is a used field, so: which values are accepted, and does an accepted value change what gets written? """ import glob, struct, sys, time sys.path.insert(0,'/root/psp/hw') from tinygrad import Device import tinygrad.runtime.autogen.am.am as am from ring_wrap import install adev=Device["AMD"].iface.dev_impl; psp=adev.psp submit=install(psp,adev) PAT=0x77777777 base=open(glob.glob('/root/psp/contall/ta_16-0-0-9_9e9044cf*')[0],'rb').read() # AUC: writes output def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa) ap_,amc=alloc(0x80000); cp,cmc=alloc(0x20000) n=(len(base)+3)&~3 adev.vram.view(ap_,n)[:]=base+b'\x00'*(n-len(base)); adev.gmc.flush_hdp() c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_LOAD_TA); t=c.cmd.cmd_load_ta t.app_phy_addr_lo,t.app_phy_addr_hi=amc&0xFFFFFFFF,amc>>32; t.app_len=len(base) t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi=cmc&0xFFFFFFFF,cmc>>32; t.cmd_buf_len=0x4000 r=submit(c); sid=r.resp.session_id print('AUC load %#x sid=%s'%(r.resp.status&0xFFFFFFFF,sid), flush=True) def go(val): adev.vram.view(cp,0x20000)[:]=bytes(struct.pack(' %#-10x %.1fs in-window=%-4d beyond=%d%s'%(val,st,dt,ins,bey, ' <<< STALL' if dt>5 else ''), flush=True) return dt>5 for v in (0,1,2,4,0x10,0x100,0x1000,0x4000,0x8000,0x10000,0x100000,0x7FFFFFFF,0x80000000,0xFFFFFFFF): if go(v): break