- spec 4.2/7.4: the caller-allocated hidden return slot (no sret pointer), with the 1987 _mkbig/_callbig oracle recorded as binding; spec 8 annotates debug info as M7. - README: qualify the complete-surface headline, name the sub-byte stride in the M7 ownership lists, and flag the default -O2 over-scale. - shim: %c honours width and the '-' flag; a bare %c is unchanged. - runtime gate: add %c width output and call rts.lib _isascii, checking it in the GSPLNK map (587 bytes, 13 markers). - aggregate gate: return a packed bitfield struct by value and check its fields, sign extension and raw word (49 markers). - tms-clang: default TMS_CLANG/TMS_OPT to build/llvm-clean-build/bin and fail clearly when a tool is missing; update the README example.
240 lines
11 KiB
Bash
Executable File
240 lines
11 KiB
Bash
Executable File
#!/bin/sh
|
|
# M6 aggregate gate: structs/unions by value, aggregate returns, no sret.
|
|
#
|
|
# scripts/tests/m6/aggregate.sh
|
|
#
|
|
# Compiles llvm/test/CodeGen/TMS34010/m6-aggregate.ll and the C driver
|
|
# scripts/m6/aggregate-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 run by default;
|
|
# AGGREGATE_OPT=-O0 (or -O2) selects one level.
|
|
#
|
|
# What it proves at runtime:
|
|
# - the caller-allocated return slot: reserve alignTo(size, 2) bytes before
|
|
# saving STK, call, copy the object out, release the slot;
|
|
# - the callee writes the object at saved_STK-size (the top of the rounded
|
|
# slot) and ends with LOADSTK + RETS 2, including with no explicit args;
|
|
# - no sret pointer argument and no A8 aggregate return: the driver IR has
|
|
# direct record returns and no `sret`, and the C-side aggregates are
|
|
# returned as `%struct.*`/`%union.*` values;
|
|
# - the 6-byte struct (six), the 5-byte packed struct (five, 6-byte slot),
|
|
# the 20-byte / five-word struct (big, the 1987 `_mkbig` case), the 2-word
|
|
# struct (pair, the 1987 `_mkpair` case), a nested struct, and a union;
|
|
# - a packed bitfield struct (bits, one 16-bit word) returned by value, with
|
|
# its fields, signed sign-extension and raw packed word checked (the
|
|
# Task 5 bitfield / Task 6 aggregate-return seam);
|
|
# - struct/union by-value arguments keep the M5 byval copy-in-the-argument-
|
|
# area behavior (both hand-written .ll callees and C callees);
|
|
# - guards after a 5-byte and a 6-byte object prove the copy is exact and
|
|
# does not write the rounded slot's pad byte into the caller's object;
|
|
# - i64/double/float members of a returned aggregate keep the little-endian
|
|
# i64 order and the GSP double/float word order.
|
|
#
|
|
# Overridable: LLVM_BIN TMS_LLC TMS_CLANG TMS_OPT TMS_BITADDR MAME DOSBOX
|
|
# DOSBOX_CONF SDK_IMG AGGREGATE_WORK AGGREGATE_COFF AGGREGATE_SDK
|
|
# LOADER_AT LOADER_END MAME_TIMEOUT DOSBOX_TIMEOUT AGGREGATE_OPT
|
|
set -eu
|
|
|
|
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
|
DIR=$ROOT/scripts/m6
|
|
TEST=$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m6-aggregate.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=${AGGREGATE_WORK:-$ROOT/build/m6-aggregate}
|
|
SDK=${AGGREGATE_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}
|
|
AGGREGATE_OPTS=${AGGREGATE_OPT:--O0 -O2}
|
|
|
|
fail() {
|
|
echo "m6 aggregate: 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=${AGGREGATE_COFF:-$WORK/aggregate.coff}
|
|
|
|
mkdir -p "$WORK/evidence" "$WORK/run/nvram" "$WORK/run/cfg"
|
|
|
|
echo "== [$opt] compile m6-aggregate.ll (the hand-written callees)"
|
|
"$TMS_LLC" -march=tms34010 "$opt" -filetype=asm "$TEST" \
|
|
-o "$WORK/aggregate-funcs.s" \
|
|
|| fail "$opt: llc -filetype=asm failed for m6-aggregate.ll"
|
|
echo " aggregate-funcs.s: $(grep -c . "$WORK/aggregate-funcs.s") lines"
|
|
|
|
# The hand-written aggregate returns must be direct record returns; the
|
|
# functions are named with the C linkage underscore by llc.
|
|
grep -q '^_mk_six:' "$WORK/aggregate-funcs.s" \
|
|
|| fail "$opt: aggregate-funcs.s has no _mk_six"
|
|
grep -q '^_mk_big:' "$WORK/aggregate-funcs.s" \
|
|
|| fail "$opt: aggregate-funcs.s has no _mk_big"
|
|
# No sret: a hand-written sret form is rejected by the target, and the
|
|
# generated code must not contain an sret-register dance.
|
|
if grep -q 'sret' "$WORK/aggregate-funcs.s"; then
|
|
fail "$opt: aggregate-funcs.s mentions sret"
|
|
fi
|
|
|
|
echo "== [$opt] compile the C driver (caller and C callee side)"
|
|
export TMS_CLANG TMS_OPT TMS_BITADDR
|
|
"$ROOT/scripts/tms-clang" "$opt" -o "$WORK/aggregate-main.ll" \
|
|
"$DIR/aggregate-main.c" \
|
|
|| fail "$opt: tms-clang failed for aggregate-main.c"
|
|
|
|
# Clang must classify record returns as direct/by-value. An sret pointer
|
|
# argument would appear here as `sret(%struct...)`; the target's aggregate
|
|
# lowering is by value and the 1987 ABI has no such argument. At -O2 the
|
|
# named record types may be printed structurally (`{ i32, i16 }`), so
|
|
# check that each C callee returns a non-void value instead of spelling
|
|
# the type.
|
|
if grep -q 'sret' "$WORK/aggregate-main.ll"; then
|
|
fail "$opt: Clang emitted an sret pointer for an aggregate return"
|
|
fi
|
|
for fn in c_mksix c_mkbig c_mkouter c_mkuni c_mkmixed; do
|
|
line=$(grep -E "^define .*@$fn\\(" "$WORK/aggregate-main.ll" || true)
|
|
[ -n "$line" ] || fail "$opt: aggregate-main.ll has no $fn definition"
|
|
case "$line" in
|
|
*" void @$fn(")
|
|
fail "$opt: $fn returns void (an indirect/sret form)" ;;
|
|
esac
|
|
done
|
|
|
|
"$TMS_LLC" -march=tms34010 "$opt" -filetype=asm "$WORK/aggregate-main.ll" \
|
|
-o "$WORK/aggregate-main.s" || fail "$opt: llc failed for aggregate-main.ll"
|
|
echo " aggregate-main.s: $(grep -c . "$WORK/aggregate-main.s") lines"
|
|
|
|
# The six C-side aggregate callees must be linked; the A8-free return
|
|
# shape is covered by the runtime markers and m6-aggregate.ll.
|
|
for fn in _c_mksix _c_mkbig _c_mkouter _c_mkuni _c_mkmixed _c_mkbits; do
|
|
# Internal linkage adds a hash suffix to the symbol (LLVM's internal
|
|
# name mangling), e.g. _c_mksix_CC884A0A.
|
|
grep -Eq "^${fn}(_[0-9A-Fa-f]+)?:" "$WORK/aggregate-main.s" \
|
|
|| fail "$opt: aggregate-main.s has no $fn"
|
|
done
|
|
|
|
echo "== [$opt] assemble/link with GSPA/GSPLNK under DOSBox"
|
|
cat "$DIR/aggregate-entry.asm" "$WORK/aggregate-funcs.s" \
|
|
"$WORK/aggregate-main.s" > "$SDK/M6.ASM"
|
|
sed 's/\r$//' "$DIR/aggregate-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 == "_aggregate_markers" { print $1; exit }' "$WORK/m6.map")
|
|
[ -n "$markers" ] || fail "$opt: linker map has no _aggregate_markers symbol"
|
|
echo " _start=$entry _aggregate_markers=$markers"
|
|
|
|
# Both the hand-written and C-side aggregate entry points are linked.
|
|
for sym in _mk_six _mk_five _mk_big _mk_pair _mk_outer _mk_uni \
|
|
_sum_six _sum_big _sum_uni; do
|
|
grep -q " $sym\$" "$WORK/m6.map" || fail "$opt: linker map has no $sym"
|
|
done
|
|
# The sret-free IR/asm is checked above; a map has no sret symbol text.
|
|
|
|
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" \
|
|
AGGREGATE_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/aggregate-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 aggregate:' "$WORK/mame.log" | tail -1 || true)
|
|
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; \
|
|
fail "$opt: MAME produced no aggregate 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 AGGREGATE MAME: PASS' "$WORK/mame.log" \
|
|
|| { grep 'M6 aggregate: marker\|M6 AGGREGATE MAME' "$WORK/mame.log" >&2 || true; \
|
|
tail -30 "$WORK/mame.log" >&2; \
|
|
fail "$opt: aggregate marker check failed"; }
|
|
|
|
echo "M6 AGGREGATE ($opt): PASS"
|
|
}
|
|
|
|
for opt in $AGGREGATE_OPTS; do
|
|
run_one "$opt"
|
|
done
|
|
|
|
echo "M6 AGGREGATE: PASS"
|