mirror of
https://git.k-space.ee/arti/vt1200.git
synced 2026-10-31 12:05:05 +02:00
80 lines
2.7 KiB
Bash
Executable File
80 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# reldemo.sh -- prove what GSPLNK does with relocations, and that the linked
|
|
# image is position-dependent.
|
|
#
|
|
# 1. assemble two objects that reference each other's symbols (ext_func,
|
|
# ext_data); the .obj files carry relocation records.
|
|
# 2. link them with `-a` (the normal app flow): the output COFF must have
|
|
# nreloc = 0 -- the image is fully resolved.
|
|
# 3. link the *same* objects at two different origin sets and diff the .text
|
|
# bytes: they differ, so the image is position-dependent.
|
|
# 4. link without `-a`: report whether GSPLNK emits a relocatable COFF.
|
|
#
|
|
# All scratch/output stays under dwt/loader/reldemo/.
|
|
set -eu
|
|
|
|
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
|
DIR=$(cd "$(dirname "$0")" && pwd)
|
|
WORK="$DIR/work"
|
|
OUT="$DIR/build"
|
|
IMG="$ROOT/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img"
|
|
DOSBOX_CONF="$ROOT/harness/sdk-scratch/dosbox-bench.conf"
|
|
|
|
mkdir -p "$WORK" "$OUT"
|
|
if [ ! -x "$WORK/GSPA.EXE" ]; then
|
|
mcopy -s -n -i "$IMG" "::/A2/*" "$WORK/"
|
|
mcopy -s -n -i "$IMG" "::/C2/*" "$WORK/"
|
|
fi
|
|
|
|
cp "$DIR/rel_a.asm" "$WORK/RELA.ASM"
|
|
cp "$DIR/rel_b.asm" "$WORK/RELB.ASM"
|
|
|
|
run_dos() {
|
|
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
|
timeout 180 dosbox -conf "$DOSBOX_CONF" -noprimaryconf -nolocalconf \
|
|
-c "mount c $WORK" -c "c:" "$@" -c "exit" -exit >/dev/null 2>&1
|
|
}
|
|
|
|
printf '%s\n' \
|
|
'-a' '-o RELABS.out' '-m RELABS.map' '-e _start' \
|
|
'RELA.obj RELB.obj' \
|
|
'SECTIONS' '{' \
|
|
' .text 018C0000h: {}' \
|
|
' .data 018D0000h: {}' \
|
|
' .bss 018D8000h: {}' \
|
|
'}' > "$WORK/RELABS.CMD"
|
|
printf '%s\n' \
|
|
'-a' '-o RELABS2.out' '-m RELABS2.map' '-e _start' \
|
|
'RELA.obj RELB.obj' \
|
|
'SECTIONS' '{' \
|
|
' .text 018E0000h: {}' \
|
|
' .data 018F0000h: {}' \
|
|
' .bss 018F8000h: {}' \
|
|
'}' > "$WORK/RELABS2.CMD"
|
|
printf '%s\n' \
|
|
'-o RELOC.out' '-m RELOC.map' '-e _start' \
|
|
'RELA.obj RELB.obj' > "$WORK/RELOC.CMD"
|
|
sed -i 's/$/\r/' "$WORK"/*.CMD
|
|
|
|
rm -f "$WORK"/REL*.OBJ "$WORK"/REL*.OUT "$WORK"/REL*.LST \
|
|
"$WORK"/REL*.MAP "$WORK"/REL*.HI "$WORK"/REL*.LO
|
|
run_dos \
|
|
-c "gspa rela rela.obj -q" \
|
|
-c "gspa relb relb.obj -q" \
|
|
-c "gsplnk relabs.cmd" \
|
|
-c "gsplnk relabs2.cmd"
|
|
# A missing relocatable output is itself a result; do not fail the script.
|
|
run_dos -c "gsplnk reloc.cmd" || true
|
|
|
|
for f in "$WORK"/REL*.OUT; do
|
|
[ -f "$f" ] && cp "$f" "$OUT/$(basename "$f" | tr 'A-Z' 'a-z')"
|
|
done
|
|
for f in "$WORK"/REL*.OBJ; do
|
|
[ -f "$f" ] && cp "$f" "$OUT/$(basename "$f" | tr 'A-Z' 'a-z')"
|
|
done
|
|
|
|
python3 "$DIR/coff.py" summary "$OUT/rela.obj" "$OUT/relb.obj" \
|
|
"$OUT/relabs.out" "$OUT/relabs2.out" "$OUT/reloc.out"
|
|
echo
|
|
python3 "$DIR/coff.py" raw "$OUT/relabs.out" "$OUT/relabs2.out"
|