#!/usr/bin/env python3 """Does loading other TAs first make FP cmd 2 stall? In isolation FP runs cmds 0-11 cleanly with cmd_buf_len=0x1000 (pass 80). In a corpus sweep that loaded ta_16 and ta_18 first (each unloaded before the next), FP stalled at cmd 2. If the preceding loads are what change FP's behaviour, that is cross-TA state contamination in the platform, not a property of FP. A FP alone, cmd 2 -> pass 80 says clean B ta_16 loaded+unloaded, then FP -> ? C ta_16 and ta_18 both, then FP -> the sweep's exact prefix """ 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) def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa) def load(path): blob=open(path,'rb').read() ap_,amc=alloc(0x80000); cp,cmc=alloc(0x8000) n=(len(blob)+3)&~3 adev.vram.view(ap_,n)[:]=blob+b'\x00'*(n-len(blob)); 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(blob) t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi=cmc&0xFFFFFFFF,cmc>>32; t.cmd_buf_len=0x1000 try: r=submit(c); return r.resp.status&0xFFFFFFFF, r.resp.session_id, cp except Exception as e: try: return int(str(e).strip().split()[-1])&0xFFFFFFFF,None,cp except Exception: return -1,None,cp def unload(sid): c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_UNLOAD_TA); c.cmd.cmd_unload_ta.session_id=sid try: return submit(c).resp.status&0xFFFFFFFF except Exception: return -1 def inv(sid,shm,cid): buf=bytearray(0x1000); struct.pack_into('5: print(' prefix stalled at cmd %d'%cid, flush=True); sys.exit(3) unload(sid) st,sid,shm=load(FP) print('FP load %#x sid=%s'%(st,sid), flush=True) for cid in (0,1,2,3): s,dt=inv(sid,shm,cid) print(' FP cmd %d -> %#-12x %.1fs%s'%(cid,s,dt,' <<< STALL' if dt>5 else ''), flush=True) if dt>5: break