#!/usr/bin/env python3 """Which host field drives FP cmd3's output count, and can it be made large? The six-TA differential showed FP cmd3 returns dword[+4] = 8 with a zeroed buffer and 4 with the 'big' profile, so some host input reaches a count-like value. This isolates which input field does it by varying one dword at a time, and then tries to push that value up. Relevance: the static reading says the length FP passes to the SYS_DRV 0x33 descriptor is the constant 0x10. If a host field can drive a length-like quantity, that reading needs revisiting. Safety: ordinary INVOKEs to FP only. FP does not emit SYS_DRV opcode 0xd. """ import argparse, glob, os, struct, sys def main(): ap = argparse.ArgumentParser() ap.add_argument('--dir', default='/root/psp/contall') a = ap.parse_args() from tinygrad import Device import tinygrad.runtime.autogen.am.am as am adev = Device["AMD"].iface.dev_impl; psp = adev.psp def alloc(n): pa = adev.mm.palloc(n, align=0x1000, zero=True, boot=False) return pa, adev.paddr2mc(pa) def load(blob): 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=0x8000 try: r=psp._ring_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 invoke(sid, shm, cid, mutate): buf = bytearray(0x2000); struct.pack_into(' st=%#x out=%s' % (off, s2, out[:16].hex())) if not changed: print(' (none)') # push the responsible field up if changed: off = changed[0][0] print('\nscaling field +%#x:' % off) for v in (0x10, 0x80, 0x100, 0x800, 0x10000, 0xFFFFFFFF): def mut(b, o=off, val=v): struct.pack_into(' st=%#-12x out=%s' % (v, s2, out[:16].hex())) c = am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_UNLOAD_TA) c.cmd.cmd_unload_ta.session_id = sid try: psp._ring_submit(c) except Exception: pass return 0 if __name__ == '__main__': sys.exit(main())