"""Fuzz the RAS TA -- ~100 of its 119 functions were never audited and prior campaigns never actually invoked it (they misread their own input as the status). Command in frame[0]: 0 ENABLE, 1 DISABLE, 2 TRIGGER_ERROR, 3 QUERY_BLOCK_INFO, 4 QUERY_SUB_BLOCK_INFO. Response lands at +0x810..0x823. cmd 2 TRIGGER_ERROR is included only in the second phase and gated behind a health check each round -- it drives real error injection. """ import ctypes,struct,random,sys,collections from tinygrad import Device from tinygrad.runtime.autogen.am import am from tinygrad.helpers import lo32,hi32 d=Device["AMD"]; adev=d.iface.dev_impl; psp=adev.psp SZ=ctypes.sizeof(am.struct_psp_gfx_cmd_resp); P='/Users/user/dev/amd-psp-re/psp_out/'; S=0x8000; MARK=0x5A RANGES=[(0x00020000,0x00070000,'sOS'),(0x00400000,0x00412000,'RAS/HDCP'), (0x00D00000,0x00D50000,'ASD'),(0x00E10000,0x00E80000,'SYSDRV'),(0x0020A000,0x0020C000,'TAstage')] def classify(v): for lo,hi,nm in RANGES: if lo<=v1 else 17) ROUNDS=int(sys.argv[2]) if len(sys.argv)>2 else 6000 PHASE2=len(sys.argv)>3 and sys.argv[3]=='trigger' CMDS=[0,1,3,4]+([2] if PHASE2 else []) EX=[0,1,2,3,4,5,6,7,8,9,0xa,0xb,0xc,0xd,0xe,0xf,0x10,0x1f,0x20,0x21,0x31,0x32,0xff,0x100, 0xffff,0x10000,0xffffffff,0x7fffffff,0x80000000,0xfffffffe,49,64,255,256,0x828,0x829] rets=collections.defaultdict(collections.Counter); leaks={}; hangs=0; sizes=collections.Counter() for r in range(ROUNDS): c=rng.choice(CMDS) b=bytearray(S) for i in range(0x800,S): b[i]=MARK struct.pack_into('3: break continue rets[c][struct.unpack_from('