#!/usr/bin/env python3 """FP cmd 2: does the declared cmd_buf_len decide whether it hangs? With cmd_buf_len = 0x4000 (pass 75 fuzz) FP cmd 2 is clean and only cmd 7 stalls. With cmd_buf_len = 0x1000 FP cmd 2 stalls. So the host-declared window appears to decide whether a command completes or hangs -- i.e. a command whose output does not fit produces a hang instead of an error. Sweep the declared length, largest first (a stall costs an ATX cycle). """ 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) FP=glob.glob('/root/psp/contall/ta_19-0-0-8_7e8be282*')[0] blob=open(FP,'rb').read() def run(decl): 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=decl try: r=submit(c); st=r.resp.status&0xFFFFFFFF; sid=r.resp.session_id except Exception: return None buf=bytearray(0x8000); struct.pack_into(' %#-12x %5.1fs%s'%(decl,st,s,dt,' <<< STALL' if dt>5 else ''), flush=True) return dt>5 for d in (0x4000, 0x2000, 0x1800, 0x1000): if run(d): break