234 lines
10 KiB
Bash
Executable File
234 lines
10 KiB
Bash
Executable File
#!/bin/sh
|
|
# M6 float/double gate: flib.lib soft-float.
|
|
#
|
|
# scripts/tests/m6/float.sh
|
|
#
|
|
# Compiles llvm/test/CodeGen/TMS34010/m6-float.ll and the C driver
|
|
# scripts/m6/float-main.c, assembles/links them with GSPA/GSPLNK 2.00 and the
|
|
# 1990 flib.lib/rts.lib under DOSBox, loads the COFF with the existing dwt
|
|
# loader and runs it in MAME. Both -O0 and -O2 are run by default, so the
|
|
# -O2 evidence is enforced by the committed gate; FLOAT_OPT=-O0 (or -O2)
|
|
# selects a single level.
|
|
#
|
|
# What it proves at runtime:
|
|
# - the flib stack ABI: source-order operand pushes, the result on A14,
|
|
# compares/conversions in A8, and the caller's A14 save/restore;
|
|
# - float one-word and GSP double two-word (LSW first) arguments/returns;
|
|
# - the caller-allocated hidden return slot (ADDI 32/ADDI 64, RETS 2) from
|
|
# both sides: the .ll functions are callees, the C driver is the caller;
|
|
# - fadd/fsub/fmul/fdiv/fneg, integer <-> float/double conversions,
|
|
# f32 <-> f64, and true/false compares in both precisions;
|
|
# - control flow on a float/double compare: the true and false path of an
|
|
# `if`, a float-compared `while`, and `?:` on a double (integer and float
|
|
# conditions);
|
|
# - signed zero canonicalising to the GSP +0 words;
|
|
# - the GSP constant-pool words and a negative constant;
|
|
# - no IEEE soft-float helper (__addsf3/__adddf3/...) is referenced.
|
|
#
|
|
# Overridable: LLVM_BIN TMS_LLC TMS_CLANG TMS_OPT TMS_BITADDR MAME DOSBOX
|
|
# DOSBOX_CONF SDK_IMG FLOAT_WORK FLOAT_COFF FLOAT_SDK LOADER_AT
|
|
# LOADER_END MAME_TIMEOUT DOSBOX_TIMEOUT FLOAT_OPT
|
|
set -eu
|
|
|
|
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
|
DIR=$ROOT/scripts/m6
|
|
TEST=$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m6-float.ll
|
|
|
|
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
|
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
|
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
|
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
|
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
|
|
|
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}
|
|
|
|
BASE_WORK=${FLOAT_WORK:-$ROOT/build/m6-float}
|
|
SDK=${FLOAT_SDK:-$BASE_WORK/sdk}
|
|
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:-3400}
|
|
# Both opt levels by default. FLOAT_OPT=-O2 runs only that level.
|
|
FLOAT_OPTS=${FLOAT_OPT:--O0 -O2}
|
|
|
|
fail() {
|
|
echo "m6 float: FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
|
[ -x "$tool" ] || fail "missing tool: $tool"
|
|
done
|
|
[ -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"
|
|
|
|
mkdir -p "$BASE_WORK" "$SDK"
|
|
|
|
echo "== extract the 1987 GSPA/GSPLNK tools"
|
|
if [ ! -f "$SDK/GSPA.EXE" ] || [ ! -f "$SDK/GSPLNK.EXE" ]; then
|
|
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
|
[ -f "$SDK_IMG" ] || fail "1987 SDK image not found: $SDK_IMG"
|
|
mcopy -n -i "$SDK_IMG" "::/A2/GSPA.EXE" "::/A2/GSPLNK.EXE" "$SDK/"
|
|
fi
|
|
[ -f "$SDK/GSPA.EXE" ] || fail "GSPA.EXE not extracted into $SDK"
|
|
[ -f "$SDK/GSPLNK.EXE" ] || fail "GSPLNK.EXE not extracted into $SDK"
|
|
|
|
echo "== extract the 1990 flib.lib/rts.lib"
|
|
LIB_SDK=${M6_LIB_SDK:-$ROOT/build/m6-sdk}
|
|
M6_SDK_OUT="$LIB_SDK" "$DIR/flib-extract.sh" > "$BASE_WORK/flib-extract.log" 2>&1 \
|
|
|| { cat "$BASE_WORK/flib-extract.log" >&2; fail "flib-extract.sh failed"; }
|
|
cp "$LIB_SDK/flib.lib" "$LIB_SDK/rts.lib" "$SDK/"
|
|
|
|
run_one() {
|
|
opt=$1
|
|
tag=$(echo "$opt" | tr -d '-')
|
|
WORK=$BASE_WORK/$tag
|
|
COFF=${FLOAT_COFF:-$WORK/float.coff}
|
|
|
|
mkdir -p "$WORK/evidence" "$WORK/run/nvram" "$WORK/run/cfg"
|
|
|
|
echo "== [$opt] compile m6-float.ll (the callee side)"
|
|
"$TMS_LLC" -march=tms34010 "$opt" -filetype=asm "$TEST" \
|
|
-o "$WORK/float-funcs.s" \
|
|
|| fail "$opt: llc -filetype=asm failed for m6-float.ll"
|
|
echo " float-funcs.s: $(grep -c . "$WORK/float-funcs.s") lines"
|
|
|
|
echo "== [$opt] compile the C driver (the caller side)"
|
|
export TMS_CLANG TMS_OPT TMS_BITADDR
|
|
"$ROOT/scripts/tms-clang" "$opt" -o "$WORK/float-main.ll" "$DIR/float-main.c" \
|
|
|| fail "$opt: tms-clang failed for float-main.c"
|
|
"$TMS_LLC" -march=tms34010 "$opt" -filetype=asm "$WORK/float-main.ll" \
|
|
-o "$WORK/float-main.s" || fail "$opt: llc failed for float-main.ll"
|
|
echo " float-main.s: $(grep -c . "$WORK/float-main.s") lines"
|
|
|
|
# No IEEE soft-float helper may appear: flib is GSP and rts.lib has none of
|
|
# these names. A generic soft-float legalization (or a wrong f32/f64
|
|
# legalization) would show up here.
|
|
for helper in __addsf3 __subsf3 __mulsf3 __divsf3 __negsf2 \
|
|
__adddf3 __subdf3 __muldf3 __divdf3 __negdf2 \
|
|
__extendsfdf2 __truncdfsf2 __fixsfsi __fixunssfsi \
|
|
__fixdfsi __fixunsdfsi __floatsisf __floatunsisf \
|
|
__floatsidf __floatunsidf; do
|
|
if grep -q "$helper" "$WORK/float-funcs.s" "$WORK/float-main.s"; then
|
|
fail "$opt: the compiler emitted an IEEE soft-float helper: $helper"
|
|
fi
|
|
done
|
|
|
|
# The exact flib entry symbols must be in the calls.
|
|
for sym in 'FS$ADD' 'FS$SUB' 'FS$MUL' 'FS$DIV' 'FS$NEG' \
|
|
'FS$EQ' 'FS$NE' 'FS$LT' 'FS$LE' 'FS$GT' 'FS$GE' \
|
|
'FD$ADD' 'FD$SUB' 'FD$MUL' 'FD$DIV' 'FD$NEG' \
|
|
'FD$EQ' 'FD$LT' 'FD$GE' \
|
|
'FD$FTOI' 'FD$FTOU' 'FD$DTOI' 'FD$DTOU' \
|
|
'FD$ITOF' 'FD$UTOF' 'FD$ITOD' 'FD$UTOD' \
|
|
'FD$FTOD' 'FD$DTOF'; do
|
|
if [ "$sym" = 'FS$NEG' ] && ! grep -q "CALLA $sym\$" "$WORK/float-funcs.s"; then
|
|
# -O2 folds the f32 sign flip to XOR with bit 31, which is the GSP
|
|
# sign bit; both are correct lowerings of fneg.
|
|
grep -q 'XOR A' "$WORK/float-funcs.s" \
|
|
|| fail "$opt: compiler output has neither CALLA FS\$NEG nor the XOR sign flip"
|
|
continue
|
|
fi
|
|
grep -q "CALLA $sym\$" "$WORK/float-funcs.s" \
|
|
|| fail "$opt: compiler output has no CALLA $sym"
|
|
done
|
|
|
|
echo "== [$opt] assemble/link with GSPA/GSPLNK under DOSBox"
|
|
cat "$DIR/float-entry.asm" "$WORK/float-funcs.s" "$WORK/float-main.s" > "$SDK/M6.ASM"
|
|
sed 's/\r$//' "$DIR/float-link.cmd" | sed 's/$/\r/' > "$SDK/M6.CMD"
|
|
rm -f "$SDK/M6.OBJ" "$SDK/M6.OUT" "$SDK/M6.MAP" "$SDK/M6.LST" "$SDK/M6.LNK"
|
|
|
|
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
|
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
|
-noprimaryconf -nolocalconf \
|
|
-c "mount c $SDK" -c "c:" \
|
|
-c "gspa M6 M6.obj M6.lst -l" \
|
|
-c "gsplnk M6.cmd > M6.LNK" \
|
|
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
|
|| { tail -20 "$WORK/dosbox.log" >&2; fail "$opt: DOSBox failed"; }
|
|
|
|
[ -f "$SDK/M6.LST" ] || fail "$opt: GSPA produced no listing (see $WORK/dosbox.log)"
|
|
sed 's/\r$//' "$SDK/M6.LST" > "$WORK/m6.lst"
|
|
grep -q 'No Errors' "$WORK/m6.lst" \
|
|
|| { grep -i -B2 -A2 'error' "$WORK/m6.lst" >&2 || true; \
|
|
fail "$opt: GSPA reported errors"; }
|
|
grep -q 'No Warnings' "$WORK/m6.lst" \
|
|
|| { grep -i -B2 -A2 'warning' "$WORK/m6.lst" >&2 || true; \
|
|
fail "$opt: GSPA reported warnings"; }
|
|
[ -f "$SDK/M6.OUT" ] \
|
|
|| { if [ -f "$SDK/M6.LNK" ]; then cat "$SDK/M6.LNK" >&2; fi; \
|
|
fail "$opt: GSPLNK produced no M6.OUT"; }
|
|
[ -f "$SDK/M6.MAP" ] || fail "$opt: GSPLNK produced no M6.MAP"
|
|
sed 's/\r$//' "$SDK/M6.MAP" > "$WORK/m6.map"
|
|
cp "$SDK/M6.OUT" "$COFF"
|
|
cp "$SDK/M6.ASM" "$WORK/m6.asm"
|
|
|
|
entry=$(awk '$2 == "_start" { print $1; exit }' "$WORK/m6.map")
|
|
[ "$entry" = "018A0000" ] || fail "$opt: linked _start is '$entry', want 018A0000"
|
|
markers=$(awk '$2 == "_float_markers" { print $1; exit }' "$WORK/m6.map")
|
|
[ -n "$markers" ] || fail "$opt: linker map has no _float_markers symbol"
|
|
echo " _start=$entry _float_markers=$markers"
|
|
|
|
# The linked image must reference the flib entries, not a C soft-float helper.
|
|
for sym in FS\$ADD FS\$SUB FS\$MUL FS\$DIV FS\$NEG FD\$ADD FD\$SUB FD\$MUL \
|
|
FD\$DIV FD\$NEG FD\$EQ FD\$LT FD\$FTOI FD\$DTOI FD\$ITOF FD\$ITOD \
|
|
FD\$FTOD FD\$DTOF; do
|
|
if [ "$sym" = 'FS$NEG' ] && ! grep -q 'CALLA FS\$NEG' "$WORK/float-funcs.s"; then
|
|
continue # -O2 uses the XOR sign flip instead of the flib entry
|
|
fi
|
|
grep -q " $sym\$" "$WORK/m6.map" || fail "$opt: linker map has no $sym"
|
|
done
|
|
for helper in __addsf3 __adddf3 __muldf3 __divdf3; do
|
|
if grep -q " $helper\$" "$WORK/m6.map"; then
|
|
fail "$opt: the linked image references an IEEE helper: $helper"
|
|
fi
|
|
done
|
|
|
|
echo "== [$opt] run the 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" \
|
|
M2_LOADER_LUA="$LOADER_LUA" \
|
|
FLOAT_MARKERS="$markers" \
|
|
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 "$DIR/float-check.lua" -autoboot_delay 0 \
|
|
> "$WORK/mame.log" 2>&1 \
|
|
|| { tail -30 "$WORK/mame.log" >&2; fail "$opt: MAME run failed"; }
|
|
|
|
MARKERS=$(grep -E '^M6 float:' "$WORK/mame.log" | tail -1 || true)
|
|
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; \
|
|
fail "$opt: MAME produced no float markers"; }
|
|
echo " $MARKERS"
|
|
|
|
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
|
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; \
|
|
fail "$opt: COFF loader did not report status 0"; }
|
|
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
|
|| fail "$opt: COFF loader could not verify the placed .text bytes"
|
|
grep -q '^M6 FLOAT MAME: PASS' "$WORK/mame.log" \
|
|
|| { grep 'M6 float: marker\|M6 FLOAT MAME' "$WORK/mame.log" >&2 || true; \
|
|
tail -30 "$WORK/mame.log" >&2; \
|
|
fail "$opt: float marker check failed"; }
|
|
|
|
echo "M6 FLOAT ($opt): PASS"
|
|
}
|
|
|
|
for opt in $FLOAT_OPTS; do
|
|
run_one "$opt"
|
|
done
|
|
|
|
echo "M6 FLOAT: PASS"
|