mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
89 lines
3.8 KiB
Python
89 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate or verify original LSF 84-byte boot descriptor vectors in isolated private RAM."""
|
|
import argparse
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "tools"))
|
|
from _lsf_oracle_elf import ( # noqa: E402
|
|
ENGINE_SPECS,
|
|
FALCON,
|
|
GPU,
|
|
OBJECT,
|
|
RESULT,
|
|
RO,
|
|
LsfUnicornHarness,
|
|
discover_rm_object,
|
|
load_relocated_rm_object,
|
|
retain_json,
|
|
)
|
|
|
|
|
|
def main(argv=None) -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description="Run or verify LSF boot descriptor oracle."
|
|
)
|
|
parser.add_argument("--rm-object", type=Path, default=None)
|
|
parser.add_argument("--check", action="store_true")
|
|
opt = parser.parse_args(argv)
|
|
|
|
loaded = load_relocated_rm_object(discover_rm_object(opt.rm_object))
|
|
harness = LsfUnicornHarness(loaded)
|
|
netlist = (ROOT / "analysis/gr-580/gv100-netlist.bin").read_bytes()
|
|
out_dir = ROOT / "analysis/lsf-580"
|
|
descriptor_records = []
|
|
|
|
for engine, setter, initializer, body, code_region, data_region in ENGINE_SPECS:
|
|
harness.run_engine_image(
|
|
engine, setter, initializer, body, code_region, data_region, netlist, out_dir, opt.check
|
|
)
|
|
# Actual selected original vtable calls. Physical base branch3a4 is a fixture
|
|
# input, not evidence of runtime assignment or WPR admission.
|
|
vtable = RO + (0x05ED3D38 if engine == "FECS" else 0x05ED4058) - 0x0111D660
|
|
fn70 = harness.funcs.get(int.from_bytes(harness.uc.mem_read(vtable + 0x70, 8), "little"))
|
|
fn28 = harness.funcs.get(int.from_bytes(harness.uc.mem_read(vtable + 0x28, 8), "little"))
|
|
if fn70 != "_nv028829rm" or fn28 != "_nv028812rm":
|
|
raise SystemExit(f"Unexpected LSF vtable slots for {engine}: +0x70={fn70!r}, +0x28={fn28!r}")
|
|
interface = OBJECT + 8
|
|
harness.uc.mem_write(interface, struct.pack("<Q", vtable))
|
|
harness.uc.mem_write(interface + 0x18, struct.pack("<Q", FALCON))
|
|
harness.uc.mem_write(FALCON + 0x5D8, struct.pack("<Q", interface))
|
|
harness.uc.mem_write(FALCON + 0x3A4, b"\1")
|
|
for base in (0x100000, 0x1234560000, 0xFEDCBA987000):
|
|
for dma_context in (0, 2, 4, 6):
|
|
harness.uc.mem_write(FALCON + 0x5F0, struct.pack("<Q", base))
|
|
harness.uc.mem_write(FALCON + 0x560, struct.pack("<I", dma_context))
|
|
harness.uc.mem_write(RESULT + 0x1000, bytes([0xA5]) * 256)
|
|
harness.uc.mem_write(RESULT + 0x1800, bytes(4))
|
|
harness.call("_nv028829rm", [GPU, interface, RESULT, RESULT + 0x1000, RESULT + 0x1800])
|
|
written = int.from_bytes(harness.uc.mem_read(RESULT + 0x1800, 4), "little")
|
|
if written != 84:
|
|
raise SystemExit(f"Expected 84-byte descriptor for {engine}, got {written}")
|
|
descriptor_records.append(
|
|
{
|
|
"engine": engine,
|
|
"base": base,
|
|
"dma_context": dma_context,
|
|
"descriptor": bytes(harness.uc.mem_read(RESULT + 0x1000, 84)).hex(),
|
|
"padding_preserved": bytes(harness.uc.mem_read(RESULT + 0x1000 + 84, 172))
|
|
== bytes([0xA5]) * 172,
|
|
}
|
|
)
|
|
|
|
report = {
|
|
"artifact_sha256": loaded["digest"],
|
|
"actual_bodies": ["028829", "028607", "028812"],
|
|
"modeled_input": "Falcon3a4true physicalGPUbase5f0 plus actualDMAcontext560",
|
|
"descriptor_records": descriptor_records,
|
|
"physical_gpu_access": False,
|
|
}
|
|
retain_json(ROOT / "reports/gpu-lsf-boot-descriptor-oracle.json", report, opt.check)
|
|
print(len(descriptor_records), "original84-byte descriptors")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|