149 lines
6.1 KiB
Bash
Executable File
149 lines
6.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# M4 layout gate: the X11R4-compatible XImage/XEvent/XErrorEvent and the ROM's
|
|
# Display/Screen layouts must match the 32-bit VT1200 ABI.
|
|
#
|
|
# layout.c asserts the byte offsets with _Static_assert and returns the ROM's
|
|
# bit displacements (byte offset * 8). layout-ti.c is the same layout compiled
|
|
# by the 1987 TI compiler once; its &-of-member is already a bit address.
|
|
# Both asm files must carry the same constants.
|
|
#
|
|
# No host X11 headers are used: layout.c includes only scripts/m4/x11m4.h and
|
|
# tms-clang runs with -nostdinc.
|
|
set -eu
|
|
|
|
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
|
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_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
|
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
|
WORK=${M4_LAYOUT_WORK:-$ROOT/build/m4-layout}
|
|
GOLDEN=$ROOT/scripts/m4/layout-ti.s
|
|
|
|
fail() {
|
|
echo "layout.sh: FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_LLC" "$TMS_BITADDR"; do
|
|
[ -x "$tool" ] || fail "missing tool: $tool"
|
|
done
|
|
[ -f "$GOLDEN" ] || fail "missing TI golden: $GOLDEN"
|
|
|
|
mkdir -p "$WORK"
|
|
|
|
# Exit 0 here means every _Static_assert in layout.c held on the target.
|
|
TMS_CLANG="$TMS_CLANG" TMS_OPT="$TMS_OPT" TMS_BITADDR="$TMS_BITADDR" \
|
|
"$ROOT/scripts/tms-clang" -O0 -o "$WORK/layout.ll" \
|
|
"$ROOT/scripts/m4/layout.c" \
|
|
|| fail "target compile failed (XImage/XEvent/XErrorEvent/Display static asserts?)"
|
|
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
|
"$WORK/layout.ll" -o "$WORK/layout.s" \
|
|
|| fail "llc failed for layout.ll"
|
|
|
|
# Print one function body, stopping at the next function label. TI's
|
|
# EPI0_n labels are inside the function and come after the constant we check.
|
|
body() { # body FILE FUNC
|
|
awk -v want="_$2:" '
|
|
$1 == want { infn = 1; next }
|
|
infn {
|
|
if ($0 ~ /^[A-Za-z_][A-Za-z0-9_]*:/ && $0 !~ /^LBB/) exit
|
|
print
|
|
}
|
|
' "$1"
|
|
}
|
|
|
|
# Allowed spellings for a constant: C hex, assembler hex with `h`, decimal.
|
|
has_const() { # has_const FILE FUNC ERE
|
|
body "$1" "$2" | tr 'A-Z' 'a-z' | grep -Eq "$3"
|
|
}
|
|
|
|
check() { # check FILE FUNC ERE WHAT
|
|
if ! has_const "$1" "$2" "$3"; then
|
|
echo "layout.sh: $1: _$2 body:" >&2
|
|
body "$1" "$2" >&2
|
|
fail "_$2 in $1 does not contain $4"
|
|
fi
|
|
}
|
|
|
|
# First MOVI immediate in a function body, in decimal.
|
|
const_value() { # const_value FILE FUNC
|
|
body "$1" "$2" | awk '
|
|
/MOVI/ {
|
|
for (i = 1; i <= NF; i++)
|
|
if ($i == "MOVI") {
|
|
v = $(i + 1)
|
|
sub(/,.*/, "", v)
|
|
print v
|
|
exit
|
|
}
|
|
}
|
|
'
|
|
}
|
|
|
|
to_dec() { # to_dec TOKEN
|
|
case "$1" in
|
|
0x* | 0X*) printf '%d' "$1" ;;
|
|
*h | *H) printf '%d' "0x${1%?}" ;;
|
|
*) printf '%d' "$1" ;;
|
|
esac
|
|
}
|
|
|
|
HEX480='(0x480|480h|[^0-9a-f]1152[^0-9a-f])'
|
|
HEX40='(0x40|40h|[^0-9a-f]64[^0-9a-f])'
|
|
HEX80='(0x80|80h|[^0-9a-f]128[^0-9a-f])'
|
|
HEXA0='(0xa0|0a0h|[^0-9a-f]160[^0-9a-f])'
|
|
HEX140='(0x140|140h|[^0-9a-f]320[^0-9a-f])'
|
|
HEX160='(0x160|160h|[^0-9a-f]352[^0-9a-f])'
|
|
HEX200='(0x200|200h|[^0-9a-f]512[^0-9a-f])'
|
|
HEX1A0='(0x1a0|1a0h|[^0-9a-f]416[^0-9a-f])'
|
|
|
|
for asm in "$WORK/layout.s" "$GOLDEN"; do
|
|
check "$asm" layout_display_screens "$HEX480" "0x480 (Display.screens)"
|
|
check "$asm" layout_screen_root "$HEX40" "0x40 (Screen.root)"
|
|
check "$asm" layout_image_data "$HEX80" "0x80 (XImage.data at byte 16)"
|
|
check "$asm" layout_image_byte_order "$HEXA0" "0xA0 (XImage.byte_order at byte 20)"
|
|
check "$asm" layout_image_bytes_per_line "$HEX140" "0x140 (XImage.bytes_per_line at byte 40)"
|
|
check "$asm" layout_image_bits_per_pixel "$HEX160" "0x160 (XImage.bits_per_pixel at byte 44)"
|
|
check "$asm" layout_image_f "$HEX200" "0x200 (XImage.f at byte 64)"
|
|
check "$asm" layout_error_error_code "$HEX80" "0x80 (XErrorEvent.error_code at byte 16)"
|
|
check "$asm" layout_event_xkey_keycode "$HEX1A0" "0x1A0 (XEvent.xkey.keycode at byte 52)"
|
|
done
|
|
|
|
# sizeof(XEvent) is in bytes. It must cover the termtris vt_u32 evbuf[24].
|
|
TARGET_TOKEN=$(const_value "$WORK/layout.s" layout_event_size) \
|
|
|| fail "could not read layout_event_size from layout.s"
|
|
GOLDEN_TOKEN=$(const_value "$GOLDEN" layout_event_size) \
|
|
|| fail "could not read layout_event_size from the TI golden"
|
|
[ -n "$TARGET_TOKEN" ] || fail "layout.s layout_event_size has no MOVI constant"
|
|
[ -n "$GOLDEN_TOKEN" ] || fail "TI golden layout_event_size has no MOVI constant"
|
|
TARGET_SIZE=$(to_dec "$TARGET_TOKEN") \
|
|
|| fail "could not parse layout_event_size '$TARGET_TOKEN' from layout.s"
|
|
GOLDEN_SIZE=$(to_dec "$GOLDEN_TOKEN") \
|
|
|| fail "could not parse layout_event_size '$GOLDEN_TOKEN' from the TI golden"
|
|
[ "$TARGET_SIZE" -ge 96 ] \
|
|
|| fail "target sizeof(XEvent) = $TARGET_SIZE bytes, want >= 96"
|
|
[ "$GOLDEN_SIZE" -ge 96 ] \
|
|
|| fail "TI sizeof(XEvent) = $GOLDEN_SIZE bytes, want >= 96"
|
|
[ "$TARGET_SIZE" -eq "$GOLDEN_SIZE" ] \
|
|
|| fail "target sizeof(XEvent)=$TARGET_SIZE but TI golden=$GOLDEN_SIZE"
|
|
|
|
# root_probe exercises the real access path: vt_root() follows Display.screens
|
|
# (bit 0x480) and reads Screen.root (bit 0x40). The helper is always_inline.
|
|
check "$WORK/layout.s" root_probe "$HEX480" "0x480 (Display.screens)"
|
|
check "$WORK/layout.s" root_probe "$HEX40" "0x40 (Screen.root)"
|
|
if body "$WORK/layout.s" root_probe | grep -q 'MOVB'; then
|
|
fail "root_probe contains MOVB: align-1 field loads did not select MOVE"
|
|
fi
|
|
|
|
# Guard against the old byte/bit-confusion mistake: Display.screens must not
|
|
# be 0x480*8 (9216) and Screen.root must not be 0x40*8 (512).
|
|
if body "$WORK/layout.s" layout_display_screens | tr 'A-Z' 'a-z' |
|
|
grep -Eq '(^|[^0-9])(9216|2400h)([^0-9a-f]|$)' ||
|
|
body "$WORK/layout.s" layout_screen_root | tr 'A-Z' 'a-z' |
|
|
grep -Eq '(^|[^0-9])(512|200h)([^0-9a-f]|$)'; then
|
|
fail "target carries byte-pad offsets (9216/512); ROM displacements are bits 0x480/0x40"
|
|
fi
|
|
|
|
echo "layout.sh: PASS (XImage data/byte_order/bpl/bpp/f = 0x80/0xA0/0x140/0x160/0x200; XErrorEvent.error_code=0x80; XEvent.xkey.keycode=0x1A0; sizeof(XEvent)=$TARGET_SIZE; Display.screens=0x480, Screen.root=0x40; target + TI golden)"
|