tinygrad/extra/disassemblers/adreno/__init__.py

23 lines
607 B
Python
Raw Normal View History

2023-03-06 00:32:03 +08:00
import ctypes
import os
import pathlib
2024-09-24 15:23:43 +08:00
import struct
2023-03-06 00:32:03 +08:00
from hexdump import hexdump
fxn = None
def disasm_raw(buf):
2023-03-06 00:32:03 +08:00
global fxn
if fxn is None:
shared = pathlib.Path(__file__).parent / "disasm.so"
if not shared.is_file():
2023-03-06 00:32:03 +08:00
os.system(f'cd {pathlib.Path(__file__).parent} && gcc -shared disasm-a3xx.c -o disasm.so')
2023-04-19 10:17:41 +08:00
fxn = ctypes.CDLL(shared.as_posix())['disasm']
fxn(buf, len(buf))
def disasm(buf):
2024-09-24 15:23:43 +08:00
def _read_lib(off): return struct.unpack("I", buf[off:off+4])[0]
image_offset = _read_lib(0xc0)
image_size = _read_lib(0x100)
disasm_raw(buf[image_offset:image_offset+image_size])