Implement M8.1 native .lib linking: System V !<arch> parsing (/ symbol index, // long-name table, /N references, even-byte padding, loud malformed/truncated errors), in-memory member objects labelled lib(member), and extraction in the archive's own symbol-table order driven by currently undefined globals, iterated to a fixpoint without re-extracting a member. Duplicate definitions and unresolved references fail with object/member names. Accept archive paths and -l/-lL in the CLI, preserve layout/map/debug behavior, and let scripts/m4/run.sh pass M4_NATIVE_LIBS/M4_NATIVE_RTS archives to tms-link. Relocation addends are now applied as signed 32-bit values (needed by the termtris rts.lib link). Tests: tms-link archive fixtures and real flib extraction, m7 archive/-l parity, m5 native termtris with tms-link+rts.lib (dis34 match), m6 i64/runtime GSPLNK gates, and scripts/tests/m8/native-lib.sh (FLIB.LIB + RTS.LIB, MAME markers, GSPLNK byte/symbol parity).
92 lines
3.3 KiB
Bash
Executable File
92 lines
3.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# M5 native-object compile/link driver.
|
|
#
|
|
# scripts/m5/native.sh [xshow|termtris]
|
|
#
|
|
# The default mode is `termtris`, so scripts/tests/m4/termtris.sh can use this
|
|
# script as its TERMTRIS_BUILD hook: it produces $TERMTRIS_WORK/termtris.coff
|
|
# and termtris.map from the six pinned C TUs compiled with
|
|
# `llc -filetype=obj` and linked by GSPLNK. The gate then runs the unchanged
|
|
# play_keys/MAME checks.
|
|
#
|
|
# `xshow` builds scripts/m4/xshow.c + xgfix.c through scripts/m4/run.sh with
|
|
# M4_NATIVE=1, links them with GSPLNK and runs the M4 image/event MAME check.
|
|
# The asm/GSPA path remains the default of run.sh.
|
|
#
|
|
# M5_NATIVE_LINKER=tms-link runs the same native builds through tools/tms-link
|
|
# (the termtris run also exercises the rts.lib archive path); the default is
|
|
# GSPLNK, which remains the oracle.
|
|
#
|
|
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC LLVM_BIN M5_NATIVE_LINKER
|
|
# M5_XSHOW_WORK TERMTRIS_WORK TERMTRIS_SDK VT1200_TERMTRIS
|
|
# M4_SDK DOSBOX DOSBOX_CONF SDK_IMG MAME LOADER_AT LOADER_END
|
|
set -eu
|
|
|
|
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
|
MODE=${1:-termtris}
|
|
DIR=$ROOT/scripts/m4
|
|
TERMTRIS_DIR=$DIR/termtris
|
|
VENDOR=${VT1200_TERMTRIS:-$ROOT/vendor/vt1200-termtris}
|
|
LINKER=${M5_NATIVE_LINKER:-gsplnk}
|
|
|
|
fail() {
|
|
echo "M5 native driver: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
case $MODE in
|
|
xshow)
|
|
WORK=${M5_XSHOW_WORK:-$ROOT/build/m5-native-xshow}
|
|
M4_NATIVE=1 \
|
|
M4_LINKER="$LINKER" \
|
|
M4_SOURCES="xshow xgfix" \
|
|
M4_ENTRY="$DIR/xshow-entry.asm" \
|
|
M4_CHECK_LUA="$DIR/xshow-check.lua" \
|
|
M4_CLANG_OPT=-O2 \
|
|
M4_LLC_OPT=-O0 \
|
|
M4_ROM_SYMBOLS=1 \
|
|
LOADER_AT=2500 \
|
|
LOADER_END=3400 \
|
|
M4_WORK="$WORK" \
|
|
VT1200_SKIP_LEVEL1=1 \
|
|
VT1200_MONITOR=VR319 \
|
|
"$DIR/run.sh"
|
|
;;
|
|
termtris)
|
|
WORK=${TERMTRIS_WORK:-$ROOT/build/m5-native-termtris}
|
|
SRC=$VENDOR/apps/termtris/src
|
|
[ -d "$SRC" ] || fail "missing pinned termtris source: $SRC"
|
|
if git -C "$VENDOR" rev-parse --git-dir >/dev/null 2>&1; then
|
|
rev=$(git -C "$VENDOR" rev-parse HEAD)
|
|
[ "$rev" = "be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf" ] \
|
|
|| fail "vendor tree is $rev, want be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf"
|
|
fi
|
|
mkdir -p "$WORK"
|
|
# cinit.asm is a GSPA entry piece (`.sect ".cinit"`); it is assembled into
|
|
# the extras object, not compiled by llc. The rts.lib .cinit data makes the
|
|
# section non-empty, so the empty cinit.asm is sufficient (the asm gate's
|
|
# CINITZ fallback is only needed when no library contributes .cinit).
|
|
M4_NATIVE=1 \
|
|
M4_LINKER="$LINKER" \
|
|
M4_SKIP_MAME=1 \
|
|
M4_SOURCES="$SRC/vt1200/main.c $SRC/game.c $SRC/vt1200/scoredb.c $SRC/vt1200/x11.c $SRC/vt1200/compat.c $SRC/vt1200/xgfix.c" \
|
|
M4_EXTRA_INCLUDES="-I $SRC -I $SRC/vt1200 -I $TERMTRIS_DIR/include" \
|
|
M4_ENTRY="$SRC/vt1200/entry.asm" \
|
|
M4_EXTRA_ASM="$SRC/vt1200/cinit.asm" \
|
|
M4_CLANG_OPT=-O2 \
|
|
M4_LLC_OPT=-O0 \
|
|
M4_NATIVE_RTS=1 \
|
|
M4_NATIVE_PROG_LEN=40000h \
|
|
M4_NATIVE_RAM_LEN=40000h \
|
|
M4_WORK="$WORK" \
|
|
M4_COFF="$WORK/termtris.coff" \
|
|
M4_SDK="${TERMTRIS_SDK:-$WORK/sdk}" \
|
|
"$DIR/run.sh"
|
|
# play_keys.sh reads the linker map by name; run.sh writes m4.map.
|
|
cp "$WORK/m4.map" "$WORK/termtris.map"
|
|
;;
|
|
*)
|
|
fail "unknown mode '$MODE' (want xshow or termtris)"
|
|
;;
|
|
esac
|