M7.3: add the real-hardware marker gate with MAME acceptance
This commit is contained in:
1 parent
cdf137f64b
commit
fe78805872
3 files changed
+568
No files matched your search
@@ -0,0 +1,111 @@
|
||||
-- hw-check.lua -- M7.3 real-hardware marker gate, MAME-equivalent acceptance.
|
||||
--
|
||||
-- Loads the same COFF that hostload.py sends to the real unit
|
||||
-- (scripts/m7/hwmark.c, linked at .text 018C0000 / .data 018D0000 /
|
||||
-- .bss 018D8000) through vendor/vt1200/dwt/loader/loader.lua, then requires
|
||||
-- exactly what hostload.py's verify_markers() requires:
|
||||
--
|
||||
-- 018E0000 start == the loader result block's entry (018C0000)
|
||||
-- 018E0020 data == 0xDEADBEEF (copied .data)
|
||||
-- 018E0040 data2 == 0x12345678 (copied .data)
|
||||
-- 018E0060 bss == 0 (zeroed .bss; loader pre-fills A5A5)
|
||||
-- 018E0080 count advances (the child is scheduled, not jumped)
|
||||
--
|
||||
-- and that the loader result status is 0. LOADER_AT/LOADER_END come from the
|
||||
-- M4-style environment; the counter is sampled after the child has run, then
|
||||
-- again one frame before the loader exits.
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local RESULT = 0x01882D00
|
||||
|
||||
local CELLS = {
|
||||
{ 0x018E0000, "start" },
|
||||
{ 0x018E0020, "data" },
|
||||
{ 0x018E0040, "data2" },
|
||||
{ 0x018E0060, "bss" },
|
||||
{ 0x018E0080, "count" },
|
||||
}
|
||||
|
||||
-- First sample: a few frames after injection, so the child has started.
|
||||
-- Second sample: the last frame before loader.lua inspects and exits.
|
||||
local SAMPLE0 = math.max(AT + 5, ENDF - 11)
|
||||
local SAMPLE1 = ENDF - 1
|
||||
|
||||
local frames = 0
|
||||
local first_count = nil
|
||||
local checked = false
|
||||
|
||||
local function r32(prog, addr)
|
||||
local ok, v = pcall(function() return prog:read_u32(addr) end)
|
||||
if ok then return v end
|
||||
return nil
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
|
||||
if frames == SAMPLE0 and first_count == nil then
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
first_count = r32(prog, 0x018E0080)
|
||||
end
|
||||
|
||||
if frames == SAMPLE1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local v = {}
|
||||
for _, cell in ipairs(CELLS) do
|
||||
v[cell[2]] = r32(prog, cell[1])
|
||||
end
|
||||
local status = r32(prog, RESULT + 0x000)
|
||||
local entry = r32(prog, RESULT + 0x020)
|
||||
local count0 = first_count or 0
|
||||
local count1 = v.count or 0
|
||||
|
||||
print(string.format(
|
||||
"M7 HW: start=0x%08X data=0x%08X data2=0x%08X bss=0x%08X count=%d->%d status=%d entry=0x%08X",
|
||||
v.start or 0, v.data or 0, v.data2 or 0, v.bss or 0,
|
||||
count0, count1, status or -1, entry or 0))
|
||||
|
||||
local problems = {}
|
||||
if status ~= 0 then
|
||||
problems[#problems + 1] = string.format("loader status=%s, want 0",
|
||||
tostring(status))
|
||||
end
|
||||
if entry ~= 0x018C0000 then
|
||||
problems[#problems + 1] = string.format(
|
||||
"loader entry=0x%08X, want 0x018C0000", entry or 0)
|
||||
end
|
||||
if v.start ~= entry then
|
||||
problems[#problems + 1] = string.format(
|
||||
"start=0x%08X, want the entry 0x%08X", v.start or 0, entry or 0)
|
||||
end
|
||||
if v.data ~= 0xDEADBEEF then
|
||||
problems[#problems + 1] = string.format("data=0x%08X, want 0xDEADBEEF",
|
||||
v.data or 0)
|
||||
end
|
||||
if v.data2 ~= 0x12345678 then
|
||||
problems[#problems + 1] = string.format(
|
||||
"data2=0x%08X, want 0x12345678", v.data2 or 0)
|
||||
end
|
||||
if v.bss ~= 0 then
|
||||
problems[#problems + 1] = string.format("bss=0x%08X, want 0",
|
||||
v.bss or 0)
|
||||
end
|
||||
if count0 <= 0 or count1 <= count0 then
|
||||
problems[#problems + 1] = string.format(
|
||||
"count did not advance (%d -> %d)", count0, count1)
|
||||
end
|
||||
|
||||
if #problems == 0 then
|
||||
print("M7 HW MAME: PASS")
|
||||
else
|
||||
for _, p in ipairs(problems) do
|
||||
print("M7 HW: FAIL: " .. p)
|
||||
end
|
||||
print("M7 HW MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "m7-hw-check")
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* hwmark.c -- M7.3 real-hardware marker client, built at the proven VT1200
|
||||
* hardware origins:
|
||||
*
|
||||
* .text 018C0000h
|
||||
* .data 018D0000h
|
||||
* .bss 018D8000h
|
||||
*
|
||||
* This is the COFF image that dwt/loader/hostload.py pokes and that
|
||||
* dwt/loader/loader.asm places through create_process. The marker cells are
|
||||
* the ones hostload.py's MARKER_CELLS names (all TMS34010 *bit* addresses):
|
||||
*
|
||||
* 018E0000 _start address at run time (must equal the loader entry)
|
||||
* 018E0020 d_magic read from .data (must be DEADBEEF)
|
||||
* 018E0040 d_two read from .data (must be 12345678)
|
||||
* 018E0060 b_zero read from .bss (must be 0)
|
||||
* 018E0080 b_counter, a live counter (must advance)
|
||||
*
|
||||
* The M7.3 brief prefers a C-only entry when the compiler can express it, so
|
||||
* `start` is an ordinary C function and the COFF entry point is `_start`.
|
||||
* create_process() supplies the process stack; the MAME acceptance run proves
|
||||
* the generated prologue's A14/SP use is valid there, and the real-unit run
|
||||
* (VT1200_HOST) is the confirmation on hardware. The `.data` pointer
|
||||
* initializer below is supported as an ordinary pointer relocation, so no
|
||||
* `ptrtoint` constant initializer and no assembly entry are needed.
|
||||
*
|
||||
* The loader zeroes .bss after the harness has pre-filled it with A5A5, so a
|
||||
* zero at 018E0060 is the loader's work, not fresh RAM. The delay loop is
|
||||
* marker.asm's 2000h `dsjs` delay: the child stays scheduled but does not burn
|
||||
* the cooperative scheduler with an unbroken hot loop.
|
||||
*/
|
||||
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018E0000u + (n) * 0x20u))
|
||||
|
||||
/* Initialised .data: the loader must copy these bytes from the COFF. */
|
||||
unsigned int d_magic = 0xDEADBEEFu;
|
||||
unsigned int d_two = 0x12345678u;
|
||||
|
||||
/* Uninitialised .bss: the loader must zero these. */
|
||||
unsigned int b_zero;
|
||||
unsigned int b_counter;
|
||||
|
||||
void start(void);
|
||||
|
||||
/*
|
||||
* The entry address as a relocated pointer, not a ptrtoint constant. The
|
||||
* loader's result block reports the same `_start` bit address as the COFF
|
||||
* entry point, so the runtime start cell proves placement, not a guess.
|
||||
*/
|
||||
void (*const start_address)(void) = start;
|
||||
|
||||
/* A volatile .bss sink keeps the delay loop from being folded away. */
|
||||
static volatile unsigned int delay_sink;
|
||||
|
||||
void start(void) {
|
||||
unsigned int count = 0;
|
||||
|
||||
MARK(0) = (unsigned int)start_address;
|
||||
MARK(1) = d_magic;
|
||||
MARK(2) = d_two;
|
||||
MARK(3) = b_zero;
|
||||
|
||||
for (;;) {
|
||||
unsigned int spin;
|
||||
|
||||
count++;
|
||||
b_counter = count;
|
||||
MARK(4) = count;
|
||||
|
||||
for (spin = 0; spin < 0x2000u; spin++) {
|
||||
delay_sink = spin;
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+383
@@ -0,0 +1,383 @@
|
||||
#!/bin/sh
|
||||
# M7.3 real-hardware marker gate with MAME-equivalent acceptance.
|
||||
#
|
||||
# Builds scripts/m7/hwmark.c (a C-only `_start`) as a TI-COFF object, links it
|
||||
# with tools/tms-link at the proven VT1200 hardware origins, and proves the
|
||||
# image in MAME through the same dwt loader that hostload.py drives:
|
||||
#
|
||||
# .text 018C0000h .data 018D0000h .bss 018D8000h
|
||||
# 018E0000 start = entry (018C0000)
|
||||
# 018E0020 data = DEADBEEF (loader copied .data)
|
||||
# 018E0040 data2 = 12345678 (loader copied .data)
|
||||
# 018E0060 bss = 0 (loader zeroed the A5-prefilled .bss)
|
||||
# 018E0080 count advances (create_process scheduled a live child)
|
||||
#
|
||||
# GSPLNK 2.00 links the same object with explicit section origins as the
|
||||
# layout oracle; the gate requires identical allocated bytes and placement.
|
||||
#
|
||||
# Real unit:
|
||||
#
|
||||
# VT1200_HOST=192.168.99.2 scripts/tests/m7/hardware.sh
|
||||
#
|
||||
# runs dwt/loader/hostload.py --host "$VT1200_HOST" --coff <same COFF>
|
||||
# --marker --out <evidence> --tag hwmark and propagates its failure. Without
|
||||
# VT1200_HOST the gate prints `HARDWARE: DEFERRED` and passes on the MAME
|
||||
# evidence; it never reports a hardware pass without a unit.
|
||||
#
|
||||
# Run this gate alone and serially (it owns MAME/DOSBox and uses fixed
|
||||
# hardware origins).
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_LLC TMS_LINK MAME MAME_TIMEOUT DOSBOX
|
||||
# DOSBOX_CONF SDK_IMG M7_HW_WORK M7_HW_COFF M7_SDK LOADER_AT
|
||||
# LOADER_END VT1200_HOST
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m7
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/scripts/tms-clang}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
MAME_TIMEOUT=${MAME_TIMEOUT:-900}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
|
||||
WORK=${M7_HW_WORK:-$ROOT/build/m7-hardware}
|
||||
COFF=${M7_HW_COFF:-$WORK/hw-marker.coff}
|
||||
SDK=${M7_SDK:-$ROOT/build/m4-sdk}
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
||||
HOSTLOAD=$ROOT/vendor/vt1200/dwt/loader/hostload.py
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
HOST=${VT1200_HOST:-}
|
||||
|
||||
fail() {
|
||||
echo "M7 hardware: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_CLANG" ] || fail "missing tms-clang: $TMS_CLANG"
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
||||
[ -x "$MAME" ] || fail "missing MAME binary: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing COFF loader payload: $LOADER_BIN"
|
||||
[ -f "$HOSTLOAD" ] || fail "missing hostload.py: $HOSTLOAD"
|
||||
[ -f "$DOSBOX_CONF" ] || fail "missing DOSBox config: $DOSBOX_CONF"
|
||||
command -v "$DOSBOX" >/dev/null 2>&1 || fail "missing DOSBox: $DOSBOX"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK/run/nvram" "$WORK/run/cfg" "$WORK/evidence" "$WORK/dos"
|
||||
|
||||
echo "== compile the C-only marker client at the hardware origins"
|
||||
"$TMS_CLANG" -O0 -o "$WORK/hwmark.ll" "$DIR/hwmark.c" \
|
||||
|| fail "tms-clang failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
"$WORK/hwmark.ll" -o "$WORK/hwmark.o" \
|
||||
|| fail "llc -filetype=obj failed"
|
||||
|
||||
echo "== link with tools/tms-link (.text 018C0000 .data 018D0000 .bss 018D8000)"
|
||||
"$TMS_LINK" -o "$COFF" --map "$WORK/hwmark.map" --entry _start \
|
||||
--text 018C0000 --data 018D0000 --bss 018D8000 \
|
||||
--prog-len 18000 --ram-len 8000 \
|
||||
"$WORK/hwmark.o" \
|
||||
|| fail "tms-link failed"
|
||||
|
||||
ENTRY_ADDR=$(awk '$2 == "_start" { print $1; exit }' "$WORK/hwmark.map")
|
||||
[ "$ENTRY_ADDR" = "018C0000" ] \
|
||||
|| fail "tms-link entry _start is '$ENTRY_ADDR', want 018C0000"
|
||||
grep -q 'ENTRY POINT SYMBOL: "_start" address: 018C0000' "$WORK/hwmark.map" \
|
||||
|| fail "tms-link map has no _start entry point at 018C0000"
|
||||
|
||||
echo "== inspect the linked COFF (origins, .data sentinels, no relocations)"
|
||||
python3 - "$COFF" <<'PY' || fail "linked COFF does not match the hardware marker contract"
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
d = open(path, "rb").read()
|
||||
if len(d) < 20:
|
||||
sys.exit(f"{path}: shorter than a COFF file header")
|
||||
machine, nscns, _time, symptr, nsyms, opthdr, flags = struct.unpack_from(
|
||||
"<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want 0x0090")
|
||||
if opthdr != 28:
|
||||
sys.exit(f"{path}: optional header size {opthdr}, want 28")
|
||||
if not (flags & 0x0001):
|
||||
sys.exit(f"{path}: linked image is not executable (flags {flags:#06x})")
|
||||
|
||||
optmagic, = struct.unpack_from("<H", d, 20)
|
||||
entry, textstart = struct.unpack_from("<II", d, 20 + 16)
|
||||
if optmagic != 0x0108:
|
||||
sys.exit(f"{path}: optional header magic {optmagic:#06x}, want 0x0108")
|
||||
if entry != 0x018C0000 or textstart != 0x018C0000:
|
||||
sys.exit(f"{path}: entry/textstart {entry:#x}/{textstart:#x}, "
|
||||
f"want 018C0000")
|
||||
|
||||
SECTIONS = {}
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
off = base + i * 40
|
||||
name = d[off:off + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
paddr, _vaddr, size, scnptr = struct.unpack_from("<IIII", d, off + 8)
|
||||
nreloc, = struct.unpack_from("<H", d, off + 32)
|
||||
sflags, = struct.unpack_from("<I", d, off + 36)
|
||||
if nreloc:
|
||||
sys.exit(f"{path}: linked {name} still has {nreloc} relocations")
|
||||
SECTIONS[name] = dict(index=i + 1, paddr=paddr, size=size,
|
||||
scnptr=scnptr, flags=sflags)
|
||||
|
||||
want = {
|
||||
".text": (0x018C0000, 0x20),
|
||||
".data": (0x018D0000, 0x40),
|
||||
".bss": (0x018D8000, 0x80),
|
||||
}
|
||||
if sorted(SECTIONS) != sorted(want):
|
||||
sys.exit(f"{path}: sections {sorted(SECTIONS)}, want .text/.data/.bss")
|
||||
for name, (paddr, sflags) in want.items():
|
||||
sec = SECTIONS[name]
|
||||
if sec["paddr"] != paddr:
|
||||
sys.exit(f"{path}: {name} origin {sec['paddr']:#x}, want {paddr:#x}")
|
||||
if sec["flags"] != sflags:
|
||||
sys.exit(f"{path}: {name} flags {sec['flags']:#06x}, want {sflags:#06x}")
|
||||
if sec["size"] == 0:
|
||||
sys.exit(f"{path}: {name} is empty")
|
||||
if SECTIONS[".data"]["size"] < 64:
|
||||
sys.exit(f"{path}: .data is smaller than the two sentinels (64 bits)")
|
||||
if SECTIONS[".bss"]["size"] < 64:
|
||||
sys.exit(f"{path}: .bss is smaller than b_zero/b_counter (64 bits)")
|
||||
if SECTIONS[".text"]["paddr"] + SECTIONS[".text"]["size"] > \
|
||||
SECTIONS[".data"]["paddr"]:
|
||||
sys.exit(f"{path}: .text overlaps .data")
|
||||
if SECTIONS[".data"]["paddr"] + SECTIONS[".data"]["size"] > 0x018D8000:
|
||||
sys.exit(f"{path}: .data crosses into the .bss region")
|
||||
if SECTIONS[".bss"]["paddr"] + SECTIONS[".bss"]["size"] > 0x018E0000:
|
||||
sys.exit(f"{path}: .bss crosses into the marker cells at 018E0000")
|
||||
|
||||
# Symbol records: the client's data/bss objects must be in the right section,
|
||||
# and the .data bytes at their symbol offsets must hold the sentinels.
|
||||
string_base = symptr + nsyms * 18
|
||||
syms = {}
|
||||
i = 0
|
||||
while i < nsyms:
|
||||
off = symptr + i * 18
|
||||
if off + 18 > len(d):
|
||||
sys.exit(f"{path}: symbol {i} past EOF")
|
||||
name = d[off:off + 8]
|
||||
if name[:4] == b"\0\0\0\0":
|
||||
soff, = struct.unpack_from("<I", d, off + 4)
|
||||
end = d.find(b"\0", string_base + soff)
|
||||
nm = d[string_base + soff:end].decode("latin1")
|
||||
else:
|
||||
nm = name.rstrip(b"\0").decode("latin1")
|
||||
value, secno, _typ, cls, naux = struct.unpack_from("<IhHBB", d, off + 8)
|
||||
if cls == 2:
|
||||
syms[nm] = (value, secno)
|
||||
i += 1 + naux
|
||||
|
||||
def need(nm, sec):
|
||||
if nm not in syms:
|
||||
sys.exit(f"{path}: missing symbol {nm}")
|
||||
value, secno = syms[nm]
|
||||
if secno != sec:
|
||||
sys.exit(f"{path}: {nm} is in section {secno}, want {sec}")
|
||||
return value
|
||||
|
||||
def abs_need(nm, sec, want):
|
||||
value = need(nm, sec)
|
||||
if value != want:
|
||||
sys.exit(f"{path}: {nm} is at {value:#x}, want {want:#x}")
|
||||
return value
|
||||
|
||||
# A linked image stores absolute bit addresses in its symbol values, like
|
||||
# GSPLNK's map (the unlinked llc object used section-relative values).
|
||||
start = abs_need("_start", SECTIONS[".text"]["index"], 0x018C0000)
|
||||
magic_addr = abs_need("_d_magic", SECTIONS[".data"]["index"], 0x018D0000)
|
||||
two_addr = abs_need("_d_two", SECTIONS[".data"]["index"], 0x018D0020)
|
||||
abs_need("_b_zero", SECTIONS[".bss"]["index"], 0x018D8000)
|
||||
abs_need("_b_counter", SECTIONS[".bss"]["index"], 0x018D8020)
|
||||
|
||||
raw = d[SECTIONS[".data"]["scnptr"]:
|
||||
SECTIONS[".data"]["scnptr"] + SECTIONS[".data"]["size"] // 8]
|
||||
|
||||
def field(addr, want_hex, label):
|
||||
bitoff = addr - SECTIONS[".data"]["paddr"]
|
||||
got = raw[bitoff // 8:bitoff // 8 + 4]
|
||||
if got.hex() != want_hex:
|
||||
sys.exit(f"{path}: {label} bytes {got.hex()}, want {want_hex}")
|
||||
|
||||
field(magic_addr, "efbeadde", "_d_magic")
|
||||
field(two_addr, "78563412", "_d_two")
|
||||
|
||||
print(f" COFF: entry={entry:08X} text={SECTIONS['.text']['paddr']:08X}"
|
||||
f"/{SECTIONS['.text']['size']} bits "
|
||||
f"data={SECTIONS['.data']['paddr']:08X}/{SECTIONS['.data']['size']} bits "
|
||||
f"bss={SECTIONS['.bss']['paddr']:08X}/{SECTIONS['.bss']['size']} bits")
|
||||
print(f" symbols: _start={start:08X} _d_magic={magic_addr:08X} "
|
||||
f"_d_two={two_addr:08X} (absolute bits; sentinels exact)")
|
||||
PY
|
||||
|
||||
echo "== hostload.py MARKER_CELLS contract"
|
||||
python3 - "$HOSTLOAD" <<'PY' || fail "hostload.py marker cells changed"
|
||||
import importlib.util
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
spec = importlib.util.spec_from_file_location("hostload", path)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
want = [
|
||||
(0x018E0000, "start"),
|
||||
(0x018E0020, "data"),
|
||||
(0x018E0040, "data2"),
|
||||
(0x018E0060, "bss"),
|
||||
(0x018E0080, "count"),
|
||||
]
|
||||
if mod.MARKER_CELLS != want:
|
||||
sys.exit(f"{path}: MARKER_CELLS {mod.MARKER_CELLS}, want {want}")
|
||||
print(" MARKER_CELLS: 018E0000 start, 018E0020 data, 018E0040 data2, "
|
||||
"018E0060 bss, 018E0080 count")
|
||||
PY
|
||||
|
||||
echo "== link the same object with GSPLNK 2.00 (layout oracle)"
|
||||
if [ ! -f "$SDK/GSPLNK.EXE" ]; then
|
||||
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
||||
[ -f "$SDK_IMG" ] || fail "SDK image not found: $SDK_IMG"
|
||||
mkdir -p "$SDK"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/A2/*" "$SDK/"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/C2/*" "$SDK/"
|
||||
fi
|
||||
[ -f "$SDK/GSPLNK.EXE" ] || fail "GSPLNK.EXE is not extracted in $SDK"
|
||||
|
||||
cp "$SDK/GSPLNK.EXE" "$WORK/dos/"
|
||||
cp "$WORK/hwmark.o" "$WORK/dos/HWMARK.OBJ"
|
||||
{
|
||||
printf '%s\n' '-a'
|
||||
printf '%s\n' '-o HWMARK.OUT'
|
||||
printf '%s\n' '-m HWMARK.MAP'
|
||||
printf '%s\n' '-e _start'
|
||||
printf '%s\n' 'HWMARK.OBJ'
|
||||
printf '%s\n' 'SECTIONS'
|
||||
printf '%s\n' '{'
|
||||
printf '%s\n' ' .text 018C0000h: {}'
|
||||
printf '%s\n' ' .data 018D0000h: {}'
|
||||
printf '%s\n' ' .bss 018D8000h: {}'
|
||||
printf '%s\n' '}'
|
||||
} > "$WORK/dos/HWMARK.CMD"
|
||||
sed 's/$/\r/' "$WORK/dos/HWMARK.CMD" > "$WORK/dos/HWMARK.NEW"
|
||||
mv "$WORK/dos/HWMARK.NEW" "$WORK/dos/HWMARK.CMD"
|
||||
|
||||
rm -f "$WORK/dos/HWMARK.OUT" "$WORK/dos/HWMARK.MAP"
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $WORK/dos" -c "c:" \
|
||||
-c "gsplnk HWMARK.CMD" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
[ -f "$WORK/dos/HWMARK.OUT" ] \
|
||||
|| { tail -30 "$WORK/dosbox.log" >&2; fail "GSPLNK produced no HWMARK.OUT"; }
|
||||
cp "$WORK/dos/HWMARK.OUT" "$WORK/hwmark-gsplnk.coff"
|
||||
|
||||
python3 - "$COFF" "$WORK/hwmark-gsplnk.coff" <<'PY' \
|
||||
|| fail "tms-link output differs from the GSPLNK oracle"
|
||||
import struct
|
||||
import sys
|
||||
|
||||
|
||||
def parse(path):
|
||||
d = open(path, "rb").read()
|
||||
machine, nscns, _time, _symptr, _nsyms, opthdr, flags = \
|
||||
struct.unpack_from("<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want 0x0090")
|
||||
if not (flags & 0x0001):
|
||||
sys.exit(f"{path}: not executable (flags {flags:#06x})")
|
||||
entry, = struct.unpack_from("<I", d, 20 + 16)
|
||||
base = 20 + opthdr
|
||||
secs = {}
|
||||
for i in range(nscns):
|
||||
off = base + i * 40
|
||||
name = d[off:off + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
paddr, _vaddr, size, scnptr = struct.unpack_from("<IIII", d, off + 8)
|
||||
nreloc, = struct.unpack_from("<H", d, off + 32)
|
||||
if nreloc:
|
||||
sys.exit(f"{path}: linked {name} still has {nreloc} relocations")
|
||||
raw = b"" if name == ".bss" else d[scnptr:scnptr + size // 8]
|
||||
secs[name] = (paddr, size, raw)
|
||||
return entry, secs
|
||||
|
||||
|
||||
ours_entry, ours = parse(sys.argv[1])
|
||||
oracle_entry, oracle = parse(sys.argv[2])
|
||||
if ours_entry != oracle_entry:
|
||||
sys.exit(f"entry: tms-link {ours_entry:#x}, GSPLNK {oracle_entry:#x}")
|
||||
if sorted(ours) != sorted(oracle):
|
||||
sys.exit(f"sections: tms-link {sorted(ours)}, GSPLNK {sorted(oracle)}")
|
||||
for name in (".text", ".data", ".bss"):
|
||||
op, osz, oraw = ours[name]
|
||||
gp, gsz, graw = oracle[name]
|
||||
if (op, osz) != (gp, gsz):
|
||||
sys.exit(f"{name}: tms-link {op:#x}/{osz} bits, "
|
||||
f"GSPLNK {gp:#x}/{gsz} bits")
|
||||
if oraw != graw:
|
||||
sys.exit(f"{name}: allocated bytes differ from GSPLNK")
|
||||
print(" tms-link == GSPLNK: entry, .text/.data/.bss origins, sizes and "
|
||||
"allocated bytes")
|
||||
PY
|
||||
|
||||
echo "== run the marker COFF in MAME"
|
||||
rm -rf "$WORK/run/nvram"
|
||||
mkdir -p "$WORK/run/nvram"
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$COFF" \
|
||||
LOADER_OUT="$WORK/evidence" \
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
timeout "$MAME_TIMEOUT" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/hw-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; \
|
||||
fail "COFF loader did not report status 0"; }
|
||||
grep -qE 'placed \.text at 018C0000: .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .text bytes"
|
||||
grep -qE 'placed \.data at 018D0000: .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .data bytes"
|
||||
grep -q '^M7 HW MAME: PASS$' "$WORK/mame.log" \
|
||||
|| { grep -E '^M7 HW' "$WORK/mame.log" >&2 || true; \
|
||||
tail -30 "$WORK/mame.log" >&2; \
|
||||
fail "MAME marker cells or loader status did not match"; }
|
||||
|
||||
grep '^M7 HW: ' "$WORK/mame.log" | tail -1 | sed 's/^/ /'
|
||||
grep '^LOADER: marker app: ' "$WORK/mame.log" | tail -1 | sed 's/^/ /' || true
|
||||
|
||||
if [ -n "$HOST" ]; then
|
||||
echo "== real hardware: hostload.py --marker at $HOST"
|
||||
if ! python3 "$HOSTLOAD" --host "$HOST" --coff "$COFF" --marker \
|
||||
--out "$WORK/evidence/hostload" --tag hwmark \
|
||||
> "$WORK/evidence/hostload-hwmark.log" 2>&1; then
|
||||
cat "$WORK/evidence/hostload-hwmark.log" >&2
|
||||
fail "real-hardware marker run failed (host $HOST)"
|
||||
fi
|
||||
cat "$WORK/evidence/hostload-hwmark.log"
|
||||
echo "HARDWARE: PASS (host $HOST)"
|
||||
echo "M7 hardware: PASS (MAME-equivalent + real hardware)"
|
||||
else
|
||||
echo "HARDWARE: DEFERRED"
|
||||
echo "HARDWARE: set VT1200_HOST=<unit-ip> to run hostload.py --marker over rdebug"
|
||||
echo "M7 hardware: PASS (MAME-equivalent; hardware deferred)"
|
||||
fi
|
||||
Reference in new issue
Block a user