#!/usr/bin/env python3 """Run the original GV100 OBJACR InitLocked and Load (ACR bootstrap on SEC2) and write an oracle. The environment is the one tools/check_gpu_wpr_blob_binary.py builds (the whole object relocated; GPU chip identification; OBJBSP, OBJSEC2, the PMU class, FECS and GPCCS objects from their creators; OBJLSFM and OBJACR bound and their properties initialised; five Falcons bound, attached and configured). That file's setup part, up to its first case, is executed here unchanged, so both harnesses share one description of the objects. Executed original code (chip HAL 0x23, RM HAL 2): OBJLSFM InitLocked _nv043236rm and Load _nv043238rm (as in the image harness), then the writer _nv043215rm from inside the bootstrap. OBJACR InitLocked _nv016955rm with _nv016940rm, +120 _nv016953rm, _nv016937rm and _nv016725rm; Load _nv016956rm; +180 _nv016923rm; the bootstrap +128 _nv016931rm with _nv016747rm, the HS runner _nv016741rm, the image preparation _nv016905rm (bundle getter +1f0 _nv016889rm, descriptors unpacked by the original unpacker), the signature placement _nv016965rm, the region descriptor and shadow copy +110 _nv016753rm (CPU branch) with +368 _nv016963rm and _nv016932rm, the status check +158 _nv016730rm, the cleanup _nv016748rm, the region check _nv016974rm with +150 _nv016745rm, and _nv016973rm with +190 _nv016911rm and +198. Falcon +248 _nv028470rm with +250 _nv028502rm (boot loader records), the reset _nv028467rm (three times) and what it reaches in the OBJSEC2 interface and OBJMC, _nv028746rm, +260 _nv028420rm, +98 _nv028536rm, +270 _nv028379rm, +a8 _nv028759rm with _nv013358rm, the DMEM writer _nv028452rm, the IMEM writer _nv028523rm, +1c8 _nv028764rm, +268 _nv028781rm with _nv028782rm, +278 _nv028770rm and +a0 _nv028537rm. OBJMC +198 _nv043581rm, +158, +150, +188, +190 as bound by _nv006001rm. PMU class +2f8 _nv052412rm, +3d8 _nv052308rm. Fixture-supplied (recorded as events where they are observable): register read _nv053907rm and write _nv053912rm; the delay _nv049598rm and the time functions _nv059509rm, _nv059505rm, _nv059492rm; diagnostics; the allocator, fill and copy; the registry lookup _nv049786rm; the memory services: descriptor creation _nv043694rm, allocation _nv043691rm (the address is a case input), _nv043704rm, _nv043699rm, _nv043721rm, _nv043696rm, _nv043717rm, the placement override _nv043742rm, the CPU mappings _nv043739rm/_nv043773rm and _nv044028rm/_nv044029rm (backed by a framebuffer model; every byte the original stores is captured), the fill _nv044030rm; the address-space services: _nv060601rm and _nv060602rm (create and destroy), the address space's functions at +e0 and +e8, the instance block writer _nv040832rm, MemoryManager+358, the mapping _nv026096rm and its release _nv026107rm; KernelBus+4c8; the FIFO lookup at +1b8; the multi-GPU section _nv031478rm; the clock-gating feature services; the functions of the GPU+1e70 object (+100), of the GPU+22c8 object's child (+178), of the GPU+20c8 object (+238, +270) and the GPU check _nv031156rm. MemorySystem+1058, +ec8 and +ed0 run as bound by _nv005936rm. No hardware is involved. `--traced` stops after the traced V100 case (the transcript comparison and target/gpu-stage/original-acr-hs-image-gv100.bin) without writing the oracle. """ import hashlib import itertools import json from pathlib import Path import struct import sys HERE = Path(__file__).resolve() SOURCE = HERE.with_name("check_gpu_wpr_blob_binary.py") MARKER = "# ------------------------------------------------- the traced V100 case" source = SOURCE.read_text() assert MARKER in source exec(compile(source[:source.index(MARKER)], str(SOURCE), "exec"), globals()) # noqa: S102 from unicorn import UC_HOOK_MEM_WRITE as MEM_WRITE # noqa: E402 from unicorn.x86_const import UC_X86_REG_RSP as RSP # noqa: E402 TRANSCRIPT_LINES = TRANSCRIPT.read_text().split("\n") FBMEM, FBMEM_BYTES = 0x70000000, 0x400000 DESCRIPTORS, DESCRIPTOR_BYTES = 0x68000000, 0x10000 cpu.mem_map(FBMEM, FBMEM_BYTES) cpu.mem_map(DESCRIPTORS, DESCRIPTOR_BYTES) # Objects this harness adds, in the spare part of the image harness's MEMORY block. (MC, MEMSYS, LPWR, LPWR_CHILD, OBJ_1E70, OBJ_22C0, OBJ_23C8, FIFO, KBUS, KGMMU, DMA, VASPACE, VASPACE_VTABLE, MEMMGR2) = (MEMORY + 0x8000 + 0x1800 * index for index in range(14)) assert MEMMGR2 + 0x1800 <= MEMORY + 0x20000 trace = [] descriptors = {} state = {"reads": {}, "checks": [], "addresses": [], "fail": {}, "counts": {}, "fb": 0} def emit(token): trace.append(token) def failing(kind): """Status injected at the n-th call of a service (1-based), else 0.""" state["counts"][kind] = state["counts"].get(kind, 0) + 1 wanted = state["fail"].get(kind) return wanted[1] if wanted and wanted[0] == state["counts"][kind] else 0 def unhook(*names): for name in names: address = text(name) hooks.pop(address, None) if address in installed: cpu.hook_del(installed.pop(address)) def stack_argument(index): return pointer(cpu.reg_read(RSP) + 8 + 8 * index) @hook("_nv053907rm") def register_read(a, low): assert (a[0], low[1], low[2]) == (GPU + 0x4120, 0, 0), a values = state["reads"].get(low[3]) assert values, f"unexpected read {low[3]:#x}" value = values.pop(0) if len(values) > 1 else values[0] emit(f"r:{low[3]:x}:{value:x}") return value @hook("_nv053912rm") def register_write(a, low): assert (a[0], low[1], low[2]) == (GPU + 0x4120, 0, 0), a emit(f"w:{low[3]:x}:{low[4]:x}") return 0 @hook("_nv049598rm") def delay(a, low): emit(f"t:{low[0]:x}") return 0 @hook("_nv059509rm") def timeout_start(a, low): assert a[0] == GPU + 0x1e08 emit(f"ts:{low[2]:x}:{low[3]:x}") return 0 @hook("_nv059505rm") def timeout_check(a, low): assert a[0] == GPU + 0x1e08 status = state["checks"].pop(0) if state["checks"] else 0 # A wait whose register never changes and whose time checks are used up # would run forever: the case is wrong, not the original. state["idle_checks"] = 0 if state["checks"] else state.get("idle_checks", 0) + 1 if state["idle_checks"] > 50000: raise RuntimeError("the case does not terminate") emit(f"tc:{low[2]:x}:{status:x}") return status @hook("_nv059492rm") def timeout_reset(a, low): emit("tr") return 0 @hook("_nv031478rm") def gpu_section(a, low): assert (a[0], low[1], low[2]) == (GPU, 0, 0), a emit(f"gs:{low[3]:x}") return 0 @hook("_nv031034rm") def feature_state(a, low): emit(f"fs:{low[1]:x}:{low[2]:x}:0") return 0 @hook("_nv031133rm") def record_feature(a, low): emit(f"rf:{low[1]:x}:{low[2]:x}:{low[3] & 0xff:x}") return 0 @hook("_nv030608rm") def fifo_object(a, low): return FIFO @hook("_nv049786rm") def registry(a, low): return 0x56 def new_descriptor(size, alignment, contiguous, space, cache, flags, parent=None, offset=0): handle = DESCRIPTORS + 0x200 * (len(descriptors) + 1) assert handle + 0x200 <= DESCRIPTORS + DESCRIPTOR_BYTES cpu.mem_write(handle, bytes(0x200)) q(handle + 0x30, size) descriptors[handle] = dict(size=size, alignment=alignment, contiguous=contiguous, space=space, cache=cache, flags=flags, address=None, backing=None, parent=parent, offset=offset, number=len(descriptors)) return handle def address_of_descriptor(handle): entry = descriptors[handle] if entry["parent"] is not None: return address_of_descriptor(entry["parent"]) + entry["offset"] assert entry["address"] is not None, "descriptor used before allocation" return entry["address"] def backing_of(handle): entry = descriptors[handle] if entry["parent"] is not None: return backing_of(entry["parent"]) + entry["offset"] return entry["backing"] @hook("_nv043694rm") def descriptor_create(a, low): assert a[1] == GPU cache, flags = stack_argument(0) & 0xffffffff, stack_argument(1) status = failing("create") emit(f"dc:{low[2]:x}:{low[3]:x}:{low[4]:x}:{low[5]:x}:{cache:x}:{flags:x}:{status:x}") if status: q(a[0], 0) return status q(a[0], new_descriptor(a[2], low[3], low[4], low[5], cache, flags)) return 0 @hook("_nv043691rm") def descriptor_allocate(a, low): entry = descriptors[a[0]] status = failing("allocate") tag = word(a[0] + 0xa0) if status: emit(f"da:{tag:x}:{entry['size']:x}:{status:x}") return status entry["address"] = state["addresses"].pop(0) entry["tag"] = tag size = (entry["size"] + 0xfff) & ~0xfff if state["fb"] + size + 0x1000 <= FBMEM_BYTES: entry["backing"] = FBMEM + state["fb"] state["fb"] += size + 0x1000 state["ranges"].append((entry["backing"], size, entry["address"])) emit(f"da:{tag:x}:{entry['size']:x}:0:{entry['address']:x}") return 0 @hook("_nv043704rm") def descriptor_free(a, low): if not a[0]: return 0 # a null descriptor: the release functions are entered and do nothing entry = descriptors[a[0]] emit("df:-" if entry["parent"] is None and entry["address"] is None else f"df:{address_of_descriptor(a[0]):x}") return 0 @hook("_nv043699rm") def descriptor_destroy(a, low): if not a[0]: return 0 entry = descriptors[a[0]] if entry["parent"] is None: emit("dd:-" if entry["address"] is None else f"dd:{entry['address']:x}") return 0 @hook("_nv043721rm") def descriptor_address(a, low): assert low[1] == 1, a return address_of_descriptor(a[0]) + a[2] @hook("_nv043696rm") def sub_descriptor(a, low): assert a[2] == GPU, a q(a[0], new_descriptor(a[4], 0, 1, 2, 0, 0, parent=a[1], offset=a[3])) return 0 @hook("_nv043742rm") def placement_override(a, low): """_nv043742rm(location, name, &address space, &cache): the case chooses the space.""" d(a[2], state["instance_space"]) return 0 def mapping(kind, handle, flags): if failing(kind): emit(f"{kind}:{address_of_descriptor(handle):x}:{descriptors[handle]['size']:x}:{flags:x}:" "fail") return 0 emit(f"{kind}:{address_of_descriptor(handle):x}:{descriptors[handle]['size']:x}:{flags:x}") return backing_of(handle) @hook("_nv043739rm") def map_descriptor(a, low): assert a[0] == GPU return mapping("m", a[1], low[2]) @hook("_nv043773rm") def unmap_descriptor(a, low): assert a[0] == GPU emit(f"u:{address_of_descriptor(a[1]):x}:{low[2]:x}") return 0 @hook("_nv044028rm") def map_region(a, low): return mapping("M", a[1], low[2]) @hook("_nv044029rm") def unmap_region(a, low): emit(f"U:{address_of_descriptor(a[1]):x}:{low[2]:x}") return 0 @hook("_nv044030rm") def fill_descriptor(a, low): """_nv044030rm(memory manager, descriptor, value, bytes; zero means all).""" entry = descriptors[a[1]] size = a[3] or entry["size"] cpu.mem_write(backing_of(a[1]), bytes([low[2] & 0xff]) * size) emit(f"z:{address_of_descriptor(a[1]):x}:{size:x}:{low[2]:x}") return 0 def framebuffer(address): """Framebuffer address of an emulator address inside a mapped allocation.""" for backing, size, base in state["ranges"]: if backing <= address < backing + size: return base + address - backing return None def copy(a, low): data = bytes(cpu.mem_read(a[1], low[2])) source, destination = framebuffer(a[1]), framebuffer(a[0]) if source is not None: emit(f"l:{source:x}+{low[2]:x}") if destination is not None: emit(f"c:{destination:x}+{low[2]:x}:{hashlib.sha256(data).hexdigest()[:16]}") cpu.mem_write(a[0], data) return a[0] hooks[address_of(by_name["os_mem_copy"])] = ("os_mem_copy", copy) def framebuffer_store(emu, access, address, size, value, unused): target = framebuffer(address) assert target is not None, hex(address) if trace and trace[-1].startswith("s:"): start, length = (int(part, 16) for part in trace[-1][2:].split("+")) if start + length == target: trace[-1] = f"s:{start:x}+{length + size:x}" return emit(f"s:{target:x}+{size:x}") cpu.hook_add(MEM_WRITE, framebuffer_store, begin=FBMEM, end=FBMEM + FBMEM_BYTES - 1) @hook("_nv060601rm") def address_space_create(a, low): status = failing("vas") emit(f"vc:{low[1]:x}:{low[3]:x}:{a[4]:x}:{a[5]:x}:{stack_argument(3):x}:{status:x}") target = stack_argument(4) q(target, 0 if status else VASPACE) return status @hook("_nv060602rm") def address_space_destroy(a, low): assert a[1] == VASPACE emit("vd") return 0 @hook("_nv040832rm") def instance_block_init(a, low): assert (a[0], a[2]) == (KGMMU, VASPACE), a status = failing("instance") emit(f"vi:{address_of_descriptor(a[1]):x}:{low[3]:x}:{status:x}") return status @hook("_nv026096rm") def address_space_map(a, low): assert (a[0], a[1], a[2]) == (GPU, DMA, VASPACE), a status = failing("vmap") emit(f"vm:{address_of_descriptor(a[3]):x}:{descriptors[a[3]]['size']:x}:{a[5]:x}:" f"{stack_argument(0):x}:{stack_argument(1):x}:{stack_argument(2):x}:{status:x}") if not status: q(a[4], state["virtual"].pop(0)) return status @hook("_nv026107rm") def address_space_unmap(a, low): assert (a[0], a[1], a[2]) == (GPU, DMA, VASPACE), a emit(f"vu:{a[3]:x}:{address_of_descriptor(a[4]):x}:{a[5]:x}") return 0 @hook("_nv028817rm") def falcon_on_gpu(a, low): assert a[0] == GPU and a[1] == SEC2 + 0xe8, a return F_SEC2 @hook("_nv031156rm") def gpu_check(a, low): assert (a[0], low[1], low[2]) == (GPU, 0, 0), a emit(f"g6:{state['g6']:x}") return state["g6"] @service("address space +e0") def address_space_pin(a, low): assert (a[0], a[1]) == (VASPACE, GPU) status = failing("pin") emit(f"vp:{status:x}") return status @service("address space +e8") def address_space_unpin(a, low): assert (a[0], a[1]) == (VASPACE, GPU) emit("vq") return 0 @service("MemoryManager+358") def memory_page_size(a, low): assert (a[0], a[1]) == (GPU, MEMMGR), a status = failing("pagesize") emit(f"ps:{address_of_descriptor(a[2]):x}:{a[3]:x}:{low[4]:x}:{status:x}") return status @service("KernelBus+4c8") def bus_flush(a, low): assert a[0] == GPU emit("bf") return 0 @service("FIFO+1b8") def fifo_lookup(a, low): assert (a[0], a[1]) == (GPU, FIFO) status, value = (state["fifo"][0] if (low[2], low[4]) == (0, 8) else state["fifo"][1]) assert (low[2], low[4]) in ((0, 8), (8, 6)), low if status == 0: d(a[5], value) emit(f"fi:{low[2]:x}:{low[3]:x}:{low[4]:x}:{status:x}:{value if not status else 0:x}") return status @service("GPU+1e70 object +100") def object_1e70_100(a, low): assert (a[0], a[1], low[2], low[3]) == (GPU, OBJ_1E70, 0, 0), a emit(f"k1:{state['k1']:x}") return state["k1"] @service("GPU+22c8 child +178") def lpwr_child_178(a, low): assert a[0] == GPU emit("lp") return 0 @service("GPU+20c8 object +238") def vbios_238(a, low): assert (a[0], a[1], low[2]) == (GPU, VBIOS, 6), a emit(f"v8:{state['v238']:x}") return state["v238"] image_allocate = hooks[text("_nv052687rm")][1] @hook("_nv052687rm") def allocate_or_fail(a, low): if state.get("no_buffer") == low[0]: emit(f"al:{low[0]:x}:fail") return 0 return image_allocate(a, low) @hook("_nv049632rm") def os_flush(a, low): emit(f"of:{framebuffer(a[1]):x}:{a[2]:x}") return 0 def slot(base, offset): return entries.get(pointer(base + offset) - TEXT, hex(pointer(base + offset))) # ----------------------------------------------------------- additional setup # The image harness resolves the rax thunk only; the failure path of # InitLocked calls through rdx. from unicorn.x86_const import UC_X86_REG_RDX as RDX # noqa: E402 THUNK_RDX = address_of(by_name["__x86_indirect_thunk_rdx"]) hooks[THUNK_RDX] = ("__x86_indirect_thunk_rdx", None) installed[THUNK_RDX] = cpu.hook_add(UC_HOOK_CODE, lambda emu, address, size, unused: emu.reg_write( UC_X86_REG_RIP, emu.reg_read(RDX)), begin=THUNK_RDX, end=THUNK_RDX) unhook("_nv017883rm", "_nv017897rm") call("_nv006001rm", MC, CHIP, RM) for binder in ("_nv005936rm",): call(binder, MEMSYS, CHIP, RM) q(VASPACE, VASPACE_VTABLE) q(VASPACE_VTABLE + 0xe0, address_space_pin) q(VASPACE_VTABLE + 0xe8, address_space_unpin) for offset, target in ((0x1ea0, MC), (0x1ec0, MEMSYS), (0x22c8, LPWR), (0x1e70, OBJ_1E70), (0x22c0, OBJ_22C0), (0x23c8, 0), (0x1f80, KBUS), (0x1f90, KGMMU), (0x1fb0, DMA), (0x1f78, 0)): q(GPU + offset, target) q(LPWR + 0x11b8, LPWR_CHILD) q(LPWR_CHILD + 0x178, lpwr_child_178) q(OBJ_1E70 + 0x100, object_1e70_100) q(KBUS + 0x4c8, bus_flush) q(FIFO + 0x1b8, fifo_lookup) q(MEMMGR + 0x358, memory_page_size) q(VBIOS + 0x238, vbios_238) q(BSS + by_name["_nv029075rm"]["st_value"], SYSTEM) BOUND = { "OBJACR": (ACR, {0x110: "_nv016753rm", 0x120: "_nv016953rm", 0x128: "_nv016931rm", 0x148: "_nv016916rm", 0x150: "_nv016745rm", 0x158: "_nv016730rm", 0x180: "_nv016923rm", 0x190: "_nv016911rm", 0x198: "_nv016948rm", 0x1c0: "_nv016919rm", 0x1c8: "_nv016950rm", 0x1d0: "_nv016927rm", 0x1f0: "_nv016889rm", 0x368: "_nv016963rm"}), "Falcon": (F_SEC2, {0x98: "_nv028536rm", 0xa0: "_nv028537rm", 0xa8: "_nv028759rm", 0x128: "_nv028679rm", 0x1a0: "_nv028785rm", 0x1c8: "_nv028764rm", 0x248: "_nv028470rm", 0x250: "_nv028502rm", 0x258: "_nv028390rm", 0x260: "_nv028420rm", 0x268: "_nv028781rm", 0x270: "_nv028379rm", 0x278: "_nv028770rm", 0x2e8: "_nv028579rm"}), "OBJMC": (MC, {0x150: "_nv043634rm", 0x158: "_nv043619rm", 0x188: "_nv043603rm", 0x190: "_nv043639rm", 0x198: "_nv043581rm", 0x1a8: "_nv043589rm"}), "MemorySystem": (MEMSYS, {0x1058: "_nv046002rm", 0xf00: "_nv044278rm", 0xf08: "_nv044306rm", 0xec8: "_nv044823rm", 0xed0: "_nv044821rm"}), "OBJSEC2": (SEC2, {0x3a0: "_nv055663rm"}), "PMU class": (PMU, {0x2f0: "_nv052403rm", 0x2f8: "_nv052412rm", 0x3d8: "_nv052308rm"}), } bound = {} for label, (base, slots) in BOUND.items(): for offset, function in slots.items(): assert slot(base, offset) == function, (label, hex(offset), slot(base, offset)) bound[f"{label}+{offset:#x}"] = function SEC2_INTERFACE = pointer(F_SEC2 + 0x5d8) assert SEC2_INTERFACE == SEC2 + 0xe8 and pointer(SEC2 + 0x1b8) == SEC2_INTERFACE INTERFACE = {f"+{offset:#x}": slot(pointer(SEC2_INTERFACE), offset) for offset in (0x58, 0x68, 0xc8, 0xd0)} # What the OBJACR constructor _nv016731rm leaves for a GV100 without registry # values: the region count of +148 at +394 and a zeroed array of count + 1 # records of 0x38 bytes at +3a0; +3a8 (requests) and +3b0 empty. REGION_COUNT = call("_nv016916rm", GPU, ACR) assert REGION_COUNT == 2 d(ACR + 0x394, REGION_COUNT) REGION_RECORDS = MEMMGR2 cpu.mem_write(REGION_RECORDS, bytes(0x38 * (REGION_COUNT + 1))) q(ACR + 0x3a0, REGION_RECORDS) # InitLocked undoes a failure through the object's vtable slot e0, the # StateDestroy body _nv016954rm of the class. q(ACR, MEMMGR2 + 0x400) q(MEMMGR2 + 0x400 + 0xe0, text("_nv016954rm")) PREPARED = snapshot() SERVICE_REGISTERS = (0x100c80, 0x100cb8, 0x100cec, 0x100cbc, 0x70000, 0x1373a0) V100 = dict(primary=0x7fde80000, shadow=0x7fdda0000, image=0x7fdf79000, instance=0x7fdf78000) TRACED_READS = {0x10ac08: [0], 0x21644: [1], 0x10a108: [0x400e0100], 0x87108: [0x20420100], 0x10a100: [0x10]} rows, counts = [], {} FALCON_STATE = (("3a5", 0x3a5), ("3a7", 0x3a7), ("3aa", 0x3aa), ("3b1", 0x3b1), ("582", 0x582), ("628", 0x628), ("638", 0x638)) SETTINGS = dict(a385=0, a386=1, a392=0, a529=0, a37f=1, a382=1, a510=1, k108=0, k1=0, lp234=0, g91c=0, g917=0, g918=0, g926=0, g4de4=0, g4de5=0, g90e=0, f582=0, f3b4=0, f3b5=0, f3a6=0, mc=1, space=2, va=0x1000, ix=0x2f, bx=14, ia=0, ba=0, g6=0, v238=0, m8cef=0, m8ccf=0, store=0, buffer=1, fail="") def transcript_reads(first, last): reads = {} for line in TRANSCRIPT_LINES[first - 1:last]: kind, offset, value, unused = line.split() if kind == "R": reads.setdefault(int(offset, 16), []).append(int(value, 16)) return reads def transcript_tokens(first, last): tokens = [] for line in TRANSCRIPT_LINES[first - 1:last]: kind, offset, value, unused = line.split() if int(offset, 16) not in SERVICE_REGISTERS: tokens.append(f"{kind.lower()}:{int(offset, 16):x}:{int(value, 16):x}") return tokens def begin(reads, addresses, checks, settings): del trace[:] diagnostics[0] = 0 fail = {} for item in filter(None, settings["fail"].split(",")): kind, number, status = item.split(":") fail[kind] = (int(number), int(status, 16)) state.update(idle_checks=0, reads={offset: list(values) for offset, values in reads.items()}, checks=list(checks), addresses=list(addresses), fail=fail, counts={}, instance_space=settings["space"], virtual=[settings["va"]], fifo=((settings["ia"], settings["ix"]), (settings["ba"], settings["bx"])), k1=settings["k1"], v238=settings["v238"], g6=settings["g6"], no_buffer=None if settings["buffer"] else 0xe0000) for offset, name in ((0x385, "a385"), (0x386, "a386"), (0x392, "a392"), (0x529, "a529"), (0x37f, "a37f"), (0x382, "a382")): b(ACR + offset, settings[name]) b(OBJ_1E70 + 0x108, settings["k108"]) b(LPWR + 0x234, settings["lp234"]) for offset, name in ((0x91c, "g91c"), (0x917, "g917"), (0x918, "g918"), (0x926, "g926"), (0x4de4, "g4de4"), (0x4de5, "g4de5"), (0x90e, "g90e")): b(GPU + offset, settings[name]) for offset, name in ((0x582, "f582"), (0x3b4, "f3b4"), (0x3b5, "f3b5"), (0x3a6, "f3a6")): b(F_SEC2 + offset, settings[name]) q(GPU + 0x1ea0, MC if settings["mc"] else 0) b(MEMSYS + 0x8cef, settings["m8cef"]) b(MEMSYS + 0x8ccf, settings["m8ccf"]) if settings["store"]: handle = new_descriptor(0x2000000, 0x20000, 1, 2, 0, 0) descriptors[handle]["address"] = settings["store"] q(MEMSYS + 0x13c8, handle) def fresh(): prepare(dict(DEFAULT, pre=1)) state.update(fb=0, ranges=[]) descriptors.clear() cpu.mem_write(FBMEM, bytes(FBMEM_BYTES)) cpu.mem_write(DESCRIPTORS, bytes(DESCRIPTOR_BYTES)) def text_of(settings): return " ".join(f"{key}={value}" if isinstance(value, str) else f"{key}={value:x}" for key, value in settings.items()) def reads_of(reads): return " ".join(f"{offset:x}=" + ",".join(f"{value:x}" for value in values) for offset, values in reads.items()) def used(reads): """The read values a case consumed; lists whose last value repeats are kept whole.""" return {offset: values[:max(1, len(values) - len(state["reads"][offset]) + 1)] for offset, values in reads.items() if len(values) != len(state["reads"][offset]) or any( token.startswith(f"r:{offset:x}:") for token in trace)} def region_records(): out = [] for index in range(1, REGION_COUNT + 1): base = REGION_RECORDS + 0x38 * index fields = struct.unpack("<5I4x4Q", cpu.mem_read(base, 0x38)) out.append(":".join(f"{value:x}" for value in fields[:5]) + ":" + ":".join( f"{descriptors[handle]['address']:x}" if handle in descriptors and descriptors[handle]["address"] is not None else ("-" if not handle else "?") for handle in fields[5:8])) return ",".join(out) def requests(): out, node = [], pointer(ACR + 0x3a8) while node: identity, size, alignment, attribute, mask, flag = struct.unpack( "