488 lines
19 KiB
Bash
Executable File
488 lines
19 KiB
Bash
Executable File
#!/bin/sh
|
|
# M4 end-to-end runner: compile translation units, assemble/link with the 1987
|
|
# GSPA/GSPLNK toolchain under DOSBox, load the COFF in MAME, and evaluate the
|
|
# marker Lua script.
|
|
#
|
|
# scripts/m4/run.sh
|
|
#
|
|
# The default is unsigned.c at -O0, linked with entry.asm and checked by
|
|
# m4-check.lua. Other M4 tasks can reuse this runner:
|
|
#
|
|
# M4_SOURCES="foo bar" C basenames under scripts/m4 (default: unsigned)
|
|
# M4_ENTRY=/path/entry.asm assembly entry file (default: scripts/m4/entry.asm)
|
|
# M4_CHECK_LUA=/path.lua MAME marker script (default: scripts/m4/m4-check.lua)
|
|
# M4_CLANG_OPT=-O2 tms-clang optimization level (default: -O0)
|
|
# M4_LLC_OPT=-O0 llc optimization level (default: -O0)
|
|
# M4_ROM_SYMBOLS=1 append the per-ROM import stubs from symbols
|
|
# M4_EXTRA_ASM="/a.asm /b.asm" extra assembly to concatenate
|
|
# M4_EXTRA_INCLUDES="-I dir" extra tms-clang include flags
|
|
# M4_EXTRA_CFLAGS="-std=..." extra tms-clang language flags (default empty;
|
|
# the conformance sweep uses this for c-torture's
|
|
# gnu89 dialect; shipped gates pass nothing)
|
|
# M4_NATIVE=1 compile with llc -filetype=obj and link the
|
|
# objects with GSPLNK (the default is GSPA text)
|
|
# M4_NATIVE_SKIP_ASM=1 in native mode, do not also emit .s for a TU
|
|
# whose raw GSPA form is intentionally rejected
|
|
# (for example an odd-offset pointer record)
|
|
# M4_NATIVE_RTS=1 add `-l rts.lib` to the native link
|
|
# M4_NATIVE_LIBS="a b" add `-l a -l b` to the native link (library
|
|
# files must already be in the SDK directory; the
|
|
# conformance shim uses flib.lib/rts.lib for %f)
|
|
# M4_NATIVE_PROG_LEN=8000h native program region length (bits)
|
|
# M4_NATIVE_RAM_LEN=80000h native RAM region length (bits)
|
|
# M4_LINK_CMD=/path/link.cmd asm-path GSPLNK command file (default link.cmd)
|
|
# M4_LINKER=tms-link native-mode opt-in: link the GSPA entry/extras
|
|
# objects and any M4_NATIVE_LIBS/M4_NATIVE_RTS
|
|
# archives with tools/tms-link instead of GSPLNK
|
|
# (default: gsplnk, which remains the oracle).
|
|
# Requires M4_NATIVE=1.
|
|
# M4_OS2=1 assemble/link with the 1990 r5.01 OS/2 tools
|
|
# under 2ine+qemu-i386 instead of DOSBox (run
|
|
# scripts/m8/setup-os2.sh first; the 1987
|
|
# GSPA/GSPLNK oracle is still the default)
|
|
# M4_OS2_LX=/path ../../2ine-tms34010/build-qemu/lx_loader
|
|
# M4_OS2_SDK=/path extracted r5.01 tree (bin/ and lib/)
|
|
# M4_SKIP_MAME=1 stop after a clean GSPA/GSPLNK link
|
|
# M4_COFF_REPAIR=1 validate the linked COFF magic/section sizes and
|
|
# repair GSPLNK's observed zero-header and
|
|
# odd-.bss shapes (default 1; set 0 to validate
|
|
# only and fail on the defect)
|
|
#
|
|
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TMS_LINK MAME DOSBOX
|
|
# DOSBOX_CONF SDK_IMG M4_WORK M4_COFF M4_SDK M4_SYMS LOADER_AT
|
|
# LOADER_END M4_COFF_REPAIR
|
|
set -eu
|
|
|
|
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
|
DIR=$ROOT/scripts/m4
|
|
|
|
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
|
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
|
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
|
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
|
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
|
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
|
|
|
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
|
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=${M4_WORK:-$ROOT/build/m4}
|
|
COFF=${M4_COFF:-$WORK/m4.coff}
|
|
SDK=${M4_SDK:-$ROOT/build/m4-sdk}
|
|
ASM=$WORK/asm
|
|
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
|
LOADER_BIN=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
|
LOADER_AT=${LOADER_AT:-2500}
|
|
LOADER_END=${LOADER_END:-2700}
|
|
SYMS=${M4_SYMS:-$ROOT/symbols/vt1200-v22.syms}
|
|
|
|
SOURCES=${M4_SOURCES:-unsigned}
|
|
ENTRY=${M4_ENTRY:-$DIR/entry.asm}
|
|
CHECK_LUA=${M4_CHECK_LUA:-$DIR/m4-check.lua}
|
|
CLANG_OPT=${M4_CLANG_OPT:--O0}
|
|
LLC_OPT=${M4_LLC_OPT:--O0}
|
|
EXTRA_INCLUDES=${M4_EXTRA_INCLUDES:-}
|
|
EXTRA_CFLAGS=${M4_EXTRA_CFLAGS:-}
|
|
NATIVE=${M4_NATIVE:-0}
|
|
OS2=${M4_OS2:-0}
|
|
NATIVE_SKIP_ASM=${M4_NATIVE_SKIP_ASM:-0}
|
|
NATIVE_RTS=${M4_NATIVE_RTS:-0}
|
|
NATIVE_LIBS=${M4_NATIVE_LIBS:-}
|
|
NATIVE_PROG_LEN=${M4_NATIVE_PROG_LEN:-8000h}
|
|
NATIVE_RAM_LEN=${M4_NATIVE_RAM_LEN:-80000h}
|
|
LINK_CMD=${M4_LINK_CMD:-$DIR/link.cmd}
|
|
LINKER=${M4_LINKER:-gsplnk}
|
|
COFF_REPAIR=${M4_COFF_REPAIR:-1}
|
|
|
|
fail() {
|
|
echo "m4: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
|
[ -x "$tool" ] || fail "missing tool: $tool"
|
|
done
|
|
case $LINKER in
|
|
gsplnk|tms-link) ;;
|
|
*) fail "M4_LINKER must be 'gsplnk' or 'tms-link', got '$LINKER'" ;;
|
|
esac
|
|
if [ "$LINKER" = tms-link ]; then
|
|
[ "$NATIVE" = 1 ] || fail "M4_LINKER=tms-link requires M4_NATIVE=1"
|
|
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
|
fi
|
|
[ -f "$ENTRY" ] || fail "missing entry: $ENTRY"
|
|
|
|
mkdir -p "$ASM" "$WORK/evidence" "$WORK/run/nvram" "$WORK/run/cfg"
|
|
mkdir -p "$(dirname "$COFF")"
|
|
|
|
echo "== compile and select ($CLANG_OPT / llc $LLC_OPT)"
|
|
export TMS_CLANG TMS_OPT TMS_BITADDR
|
|
export TMS_CLANG_EXTRA_FLAGS="$EXTRA_CFLAGS"
|
|
for name in $SOURCES; do
|
|
case $name in
|
|
*/*) src=$name ;;
|
|
*) src=$DIR/$name.c ;;
|
|
esac
|
|
base=$(basename "$src" .c)
|
|
[ -f "$src" ] || fail "missing source: $src"
|
|
# shellcheck disable=SC2086
|
|
"$ROOT/scripts/tms-clang" "$CLANG_OPT" $EXTRA_INCLUDES \
|
|
-o "$ASM/$base.ll" "$src"
|
|
if [ "$NATIVE" = 1 ]; then
|
|
if [ "$NATIVE_SKIP_ASM" != 1 ]; then
|
|
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=asm \
|
|
"$ASM/$base.ll" -o "$ASM/$base.s" \
|
|
|| fail "llc -filetype=asm failed for $name"
|
|
fi
|
|
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=obj \
|
|
"$ASM/$base.ll" -o "$ASM/$base.o" \
|
|
|| fail "llc -filetype=obj failed for $name"
|
|
echo " $base.o: $(wc -c < "$ASM/$base.o") bytes"
|
|
else
|
|
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=asm \
|
|
"$ASM/$base.ll" -o "$ASM/$base.s" \
|
|
|| fail "llc -filetype=asm failed for $name"
|
|
echo " $base.s: $(grep -c . "$ASM/$base.s") lines"
|
|
fi
|
|
done
|
|
|
|
echo "== extract the 1987 SDK"
|
|
if [ ! -f "$SDK/GSPA.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/GSPA.EXE" ] || fail "GSPA.EXE not extracted into $SDK"
|
|
|
|
# .bss is placed at 0x01A00000 (link.cmd). The 640x480 1-bit image is
|
|
# 38400 bytes; with the 4 KiB C stack and 1 KiB XG block it cannot fit the old
|
|
# 32 KiB region at 0x018A9000. 0x01A00000 is the region the termtris loader
|
|
# uses for its 125984-bit .bss (termtris.map 0x01A00000..0x01A1EC20), while the
|
|
# X server's request buffer lives in low RAM (0x00988FD0..0x0098CFD0).
|
|
echo "== assemble and link with GSPA/GSPLNK under DOSBox"
|
|
# GSPA 2.00 has one flat symbol table per assembly, and llc names basic blocks
|
|
# LBB0_1, LBB1_2, ... restarting in every translation unit. Give each TU its
|
|
# own LBB prefix, as the M3 runner does, so a multi-TU client (xshow + xgfix)
|
|
# cannot collide. The per-TU .s files keep their original labels.
|
|
if [ -n "${M4_ROM_SYMBOLS:-}" ]; then
|
|
"$ROOT/scripts/m2/gen-rom-imports.sh" "$SYMS" "$WORK/rom-imports.asm"
|
|
fi
|
|
|
|
# A separately assembled entry must declare the symbols another object
|
|
# defines; GSPA otherwise treats an undefined reference as an assembly error.
|
|
# (In the asm path the definitions are in the same concatenated assembly.)
|
|
entry_externs() {
|
|
awk '
|
|
{
|
|
line = $0
|
|
sub(/;.*/, "", line)
|
|
if (line ~ /^[[:space:]]*\.(globl|ref|bss)[[:space:]]/) {
|
|
n = split(line, a, /[[:space:],]+/)
|
|
for (i = 1; i <= n; i++)
|
|
if (a[i] ~ /^_[A-Za-z0-9_]+$/) known[a[i]] = 1
|
|
}
|
|
if (line ~ /^[[:space:]]*_[A-Za-z0-9_]+:/) {
|
|
s = line
|
|
sub(/^[[:space:]]*/, "", s)
|
|
sub(/:.*/, "", s)
|
|
known[s] = 1
|
|
}
|
|
n = split(line, a, /[^A-Za-z0-9_]+/)
|
|
for (i = 1; i <= n; i++)
|
|
if (a[i] ~ /^_[A-Za-z0-9_]+$/) ref[a[i]] = 1
|
|
}
|
|
END { for (s in ref) if (!known[s]) print s }
|
|
' "$@" | sort
|
|
}
|
|
|
|
strip_end() {
|
|
sed '/^[[:space:]]*\.end[[:space:]]*$/d' "$1"
|
|
}
|
|
|
|
# Optional host-side 1990 OS/2 r5.01 assembler/linker path (2ine + qemu-i386).
|
|
if [ "$OS2" = 1 ]; then
|
|
. "$ROOT/scripts/m8/os2-toolchain.sh"
|
|
os2_init
|
|
fi
|
|
|
|
EXTRAS=
|
|
if [ -n "${M4_EXTRA_ASM:-}" ]; then
|
|
for extra in $M4_EXTRA_ASM; do
|
|
[ -f "$extra" ] || fail "missing extra assembly: $extra"
|
|
EXTRAS="$EXTRAS $extra"
|
|
done
|
|
fi
|
|
if [ -n "${M4_ROM_SYMBOLS:-}" ]; then
|
|
EXTRAS="$EXTRAS $WORK/rom-imports.asm"
|
|
fi
|
|
|
|
if [ "$NATIVE" = 1 ]; then
|
|
# Assemble the entry and the extras (cinit, ROM import stubs) as their own
|
|
# objects, with the extras last. That keeps the linked layout equal to the
|
|
# default asm path (entry, C code, extras), so the dis34 stream comparison
|
|
# sees the same function addresses.
|
|
{
|
|
entry_externs "$ENTRY" | sed 's/^/\t.globl\t/'
|
|
strip_end "$ENTRY"
|
|
printf '\t.end\n'
|
|
} > "$SDK/M4.ASM"
|
|
if [ -n "$EXTRAS" ]; then
|
|
{
|
|
# shellcheck disable=SC2086
|
|
entry_externs $EXTRAS | sed 's/^/\t.globl\t/'
|
|
for extra in $EXTRAS; do
|
|
strip_end "$extra"
|
|
done
|
|
printf '\t.end\n'
|
|
} > "$SDK/M4EXT.ASM"
|
|
fi
|
|
|
|
NATIVE_OBJS="M4.OBJ"
|
|
for name in $SOURCES; do
|
|
case $name in
|
|
*/*) src=$name ;;
|
|
*) src=$DIR/$name.c ;;
|
|
esac
|
|
base=$(basename "$src" .c)
|
|
dos=$(printf '%s' "$base" | tr '[:lower:]' '[:upper:]')
|
|
[ "${#dos}" -le 8 ] \
|
|
|| fail "native object name '$dos.OBJ' does not fit 8.3"
|
|
cp "$ASM/$base.o" "$SDK/$dos.OBJ"
|
|
NATIVE_OBJS="$NATIVE_OBJS $dos.OBJ"
|
|
done
|
|
if [ -n "$EXTRAS" ]; then
|
|
NATIVE_OBJS="$NATIVE_OBJS M4EXT.OBJ"
|
|
fi
|
|
if [ "$NATIVE_RTS" = 1 ]; then
|
|
[ -f "$SDK/RTS.LIB" ] || fail "RTS.LIB not extracted into $SDK"
|
|
NATIVE_LIBS="$NATIVE_LIBS rts.lib"
|
|
fi
|
|
# Resolve the library names to SDK paths for tms-link. GSPLNK keeps
|
|
# consuming the -l lines in M4.CMD; the order is identical.
|
|
NATIVE_LIB_PATHS=
|
|
for lib in $NATIVE_LIBS; do
|
|
dos=$(printf '%s' "$lib" | tr '[:lower:]' '[:upper:]')
|
|
if [ -f "$SDK/$dos" ]; then
|
|
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $SDK/$dos"
|
|
elif [ -f "$SDK/$lib" ]; then
|
|
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $SDK/$lib"
|
|
else
|
|
fail "$lib not extracted into $SDK"
|
|
fi
|
|
done
|
|
{
|
|
printf '%s\n' '-a' '-o M4.OUT' '-m M4.MAP' '-e _start'
|
|
printf '%s\n' "$NATIVE_OBJS"
|
|
for lib in $NATIVE_LIBS; do
|
|
printf '%s\n' "-l $lib"
|
|
done
|
|
printf '%s\n' 'MEMORY' '{'
|
|
printf ' prog: origin = 018A0000h, length = %s\n' "$NATIVE_PROG_LEN"
|
|
printf ' ram: origin = 01A00000h, length = %s\n' "$NATIVE_RAM_LEN"
|
|
printf '%s\n' '}'
|
|
printf '%s\n' 'SECTIONS' '{'
|
|
printf '%s\n' ' .text: {} > prog'
|
|
printf '%s\n' ' .data: {} > prog'
|
|
printf '%s\n' ' .cinit: {} > prog'
|
|
printf '%s\n' ' .bss: {} > ram'
|
|
printf '%s\n' '}'
|
|
} > "$WORK/m4.cmd"
|
|
sed 's/$/\r/' "$WORK/m4.cmd" > "$SDK/M4.CMD"
|
|
else
|
|
tag=0
|
|
for name in $SOURCES; do
|
|
case $name in
|
|
*/*) src=$name ;;
|
|
*) src=$DIR/$name.c ;;
|
|
esac
|
|
base=$(basename "$src" .c)
|
|
tag=$((tag + 1))
|
|
sed "s/LBB\([0-9][0-9]*_[0-9][0-9]*\)/LBB$tag\1/g" \
|
|
"$ASM/$base.s" > "$ASM/$base.unique.s"
|
|
done
|
|
cat "$ENTRY" > "$SDK/M4.ASM"
|
|
for name in $SOURCES; do
|
|
case $name in
|
|
*/*) src=$name ;;
|
|
*) src=$DIR/$name.c ;;
|
|
esac
|
|
base=$(basename "$src" .c)
|
|
cat "$ASM/$base.unique.s" >> "$SDK/M4.ASM"
|
|
done
|
|
if [ -n "${M4_EXTRA_ASM:-}" ]; then
|
|
for extra in $M4_EXTRA_ASM; do
|
|
cat "$extra" >> "$SDK/M4.ASM"
|
|
done
|
|
fi
|
|
if [ -n "${M4_ROM_SYMBOLS:-}" ]; then
|
|
cat "$WORK/rom-imports.asm" >> "$SDK/M4.ASM"
|
|
fi
|
|
# The linker command file must keep CRLF line endings.
|
|
sed 's/\r$//' "$LINK_CMD" | sed 's/$/\r/' > "$SDK/M4.CMD"
|
|
fi
|
|
rm -f "$SDK/M4.OBJ" "$SDK/M4.OUT" "$SDK/M4.MAP" "$SDK/M4.LST"
|
|
rm -f "$SDK/M4EXT.OBJ" "$SDK/M4EXT.LST"
|
|
|
|
run_dosbox() {
|
|
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
|
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
|
-noprimaryconf -nolocalconf "$@" > "$WORK/dosbox.log" 2>&1
|
|
}
|
|
|
|
if [ "$OS2" = 1 ]; then
|
|
os2_gspa M4
|
|
if [ -f "$SDK/M4EXT.ASM" ]; then
|
|
os2_gspa M4EXT
|
|
fi
|
|
# tms-link is a host tool and runs below; the asm/GSPLNK path links here.
|
|
if [ "$NATIVE" != 1 ] || [ "$LINKER" != tms-link ]; then
|
|
os2_gsplnk
|
|
fi
|
|
elif [ "$NATIVE" = 1 ] && [ "$LINKER" = tms-link ]; then
|
|
# tms-link is a host tool: GSPA still assembles the entry/extras objects,
|
|
# but GSPLNK is not run.
|
|
if [ -n "$EXTRAS" ]; then
|
|
run_dosbox \
|
|
-c "mount c $SDK" -c "c:" \
|
|
-c "gspa M4 M4.obj M4.lst -l" \
|
|
-c "gspa M4EXT M4EXT.obj M4EXT.lst -l" \
|
|
-c "exit" -exit \
|
|
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
|
else
|
|
run_dosbox \
|
|
-c "mount c $SDK" -c "c:" \
|
|
-c "gspa M4 M4.obj M4.lst -l" \
|
|
-c "exit" -exit \
|
|
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
|
fi
|
|
elif [ "$NATIVE" = 1 ] && [ -n "$EXTRAS" ]; then
|
|
run_dosbox \
|
|
-c "mount c $SDK" -c "c:" \
|
|
-c "gspa M4 M4.obj M4.lst -l" \
|
|
-c "gspa M4EXT M4EXT.obj M4EXT.lst -l" \
|
|
-c "gsplnk M4.cmd" \
|
|
-c "exit" -exit \
|
|
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
|
else
|
|
run_dosbox \
|
|
-c "mount c $SDK" -c "c:" \
|
|
-c "gspa M4 M4.obj M4.lst -l" \
|
|
-c "gsplnk M4.cmd" \
|
|
-c "exit" -exit \
|
|
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
|
fi
|
|
|
|
if [ "$NATIVE" = 1 ] && [ "$LINKER" = tms-link ]; then
|
|
TMSLINK_INPUTS=
|
|
for obj in $NATIVE_OBJS; do
|
|
TMSLINK_INPUTS="$TMSLINK_INPUTS $SDK/$obj"
|
|
done
|
|
echo "== link with tools/tms-link"
|
|
# shellcheck disable=SC2086
|
|
"$TMS_LINK" -o "$SDK/M4.OUT" --map "$SDK/M4.MAP" --entry _start \
|
|
--text 018A0000 --bss 01A00000 \
|
|
--prog-len "$NATIVE_PROG_LEN" --ram-len "$NATIVE_RAM_LEN" \
|
|
$TMSLINK_INPUTS $NATIVE_LIB_PATHS \
|
|
|| fail "tms-link failed"
|
|
# Keep the pre-coff-check image so parity gates can compare tms-link's
|
|
# raw output; the repaired $COFF below remains the loader image.
|
|
cp "$SDK/M4.OUT" "$WORK/M4.RAW.OUT"
|
|
fi
|
|
|
|
check_lst() {
|
|
lst=$1
|
|
[ -f "$SDK/$lst.LST" ] \
|
|
|| fail "GSPA produced no $lst.LST (see $WORK/dosbox.log)"
|
|
sed 's/\r$//' "$SDK/$lst.LST" > "$WORK/$lst.lst"
|
|
grep -q 'No Errors' "$WORK/$lst.lst" \
|
|
|| { grep -i -B2 -A2 'error' "$WORK/$lst.lst" >&2 || true; \
|
|
fail "GSPA reported errors in $lst"; }
|
|
grep -q 'No Warnings' "$WORK/$lst.lst" \
|
|
|| { grep -i -B2 -A2 'warning' "$WORK/$lst.lst" >&2 || true; \
|
|
fail "GSPA reported warnings in $lst"; }
|
|
}
|
|
|
|
check_lst M4
|
|
[ -z "$EXTRAS" ] || [ "$NATIVE" != 1 ] || check_lst M4EXT
|
|
[ -f "$SDK/M4.OUT" ] || fail "$LINKER produced no M4.OUT"
|
|
sed 's/\r$//' "$SDK/M4.MAP" > "$WORK/m4.map"
|
|
cp "$SDK/M4.OUT" "$COFF"
|
|
cp "$SDK/M4.ASM" "$WORK/m4.asm"
|
|
[ ! -f "$SDK/M4EXT.ASM" ] || cp "$SDK/M4EXT.ASM" "$WORK/m4ext.asm"
|
|
|
|
ENTRY_ADDR=$(awk '$2 == "_start" { print $1; exit }' "$WORK/m4.map" | tr 'a-f' 'A-F')
|
|
[ "$ENTRY_ADDR" = "018A0000" ] || fail "linker entry _start is '$ENTRY_ADDR', want 018A0000"
|
|
grep -q 'ENTRY POINT SYMBOL: "_start"' "$WORK/m4.map" \
|
|
|| fail "linker map has no _start entry point"
|
|
|
|
# GSPLNK 2.00 can zero the 48-byte file+optional header (observed on links
|
|
# whose test object contributed no initialized .data), and can emit an odd
|
|
# .bss size.
|
|
# Validate every linked COFF and repair only those two known shapes; any other
|
|
# malformed image is a hard link failure.
|
|
command -v python3 >/dev/null 2>&1 || fail "python3 is required for COFF validation"
|
|
if [ "$COFF_REPAIR" = 1 ]; then
|
|
coff_out=$(python3 "$ROOT/scripts/m4/coff-check.py" --repair \
|
|
--entry "$ENTRY_ADDR" "$COFF" 2>&1) \
|
|
|| { printf '%s\n' "$coff_out" | sed 's/^/ /' >&2; \
|
|
fail "COFF validation/repair failed for $COFF"; }
|
|
else
|
|
coff_out=$(python3 "$ROOT/scripts/m4/coff-check.py" --entry "$ENTRY_ADDR" \
|
|
"$COFF" 2>&1) \
|
|
|| { printf '%s\n' "$coff_out" | sed 's/^/ /' >&2; \
|
|
fail "COFF validation failed for $COFF"; }
|
|
fi
|
|
printf '%s\n' "$coff_out" | sed 's/^/ /'
|
|
echo " linked .text at 018A0000, M4.OUT -> $COFF"
|
|
|
|
if [ -n "${M4_SKIP_MAME:-}" ]; then
|
|
echo "M4 LINK: PASS"
|
|
exit 0
|
|
fi
|
|
|
|
echo "== run the COFF in MAME"
|
|
[ -x "$MAME" ] || fail "MAME binary not built: $MAME"
|
|
[ -f "$LOADER_LUA" ] || fail "COFF loader missing: $LOADER_LUA"
|
|
[ -f "$LOADER_BIN" ] || fail "COFF loader payload missing: $LOADER_BIN"
|
|
[ -f "$CHECK_LUA" ] || fail "marker Lua missing: $CHECK_LUA"
|
|
|
|
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:-900}" "$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 "$CHECK_LUA" -autoboot_delay 0 \
|
|
> "$WORK/mame.log" 2>&1 \
|
|
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
|
|
|
MARKERS=$(grep -E '^(M4|M7|M8 LIB): ' "$WORK/mame.log" | tail -1 || true)
|
|
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; fail "MAME produced no M4/M7/M8 LIB markers"; }
|
|
echo " $MARKERS"
|
|
|
|
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 -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
|
|| fail "COFF loader could not verify the placed .text bytes"
|
|
grep -qE '^M[47] MAME: PASS|^M8 LIB MAME: PASS' "$WORK/mame.log" \
|
|
|| { tail -30 "$WORK/mame.log" >&2; fail "marker check failed"; }
|
|
|
|
case "$MARKERS" in
|
|
M7:*) echo "M7 MAME: PASS" ;;
|
|
M8\ LIB:*) echo "M8 LIB MAME: PASS" ;;
|
|
*) echo "M4 MAME: PASS" ;;
|
|
esac
|