#!/bin/sh set -eu : "${CPU_AS:?}" : "${CPU_LD:?}" : "${CPU_RUN:?}" : "${TEST_SRCDIR:?}" D="${TMPDIR:-/tmp}/libcpu-reloc-$$" trap 'rm -rf "$D"' EXIT HUP INT TERM mkdir -p "$D" cat > "$D/main.s" <<'EOS' .global _start .global _life .extern add_two .extern shared .text _start_life: LDI r64@0x00000, 40 CALL add_two STORE shared, r64@0x00000 LOAD r64@0x00018, shared LDI r32@0x00030, 0 EXIT r32@0x00030 EOS cat > "$D/lib.s" <<'EOS' .global add_two .global shared .data .align 32 shared: .integer 64, 0 raw_bytes: .byte 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x40, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0xd4, 0x37 .text add_two: LDI r64@0x00008, 2 IADD r64@0x00000, r64@0x00000, r64@0x00008 RET EOS "$CPU_AS" -o "$D/main.o" "$D/main.s" >/dev/null "$CPU_AS" "$D/lib.s" -o "$D/lib.o" >/dev/null "$CPU_LD" --stack-size=512 --heap-size=1M --heap-limit=8G -o "$D/a" "$D/main.o" "$D/lib.o" >/dev/null "$CPU_LD" --stack-size=1KiB --heap-size=1MiB --heap-limit=1GiB -o "$D/a-units" "$D/main.o" "$D/lib.o" >/dev/null if "$CPU_LD" --stack-size=1KiB --heap-size=-1M --heap-limit=1GiB -o "$D/a-bad" "$D/main.o" "$D/lib.o" >/dev/null 2>&1; then echo "mcpu-ld accepted negative heap size" >&2 exit 1 fi if "$CPU_LD" --stack-size=1KiB --heap-size=1B --heap-limit=1GiB -o "$D/a-bad" "$D/main.o" "$D/lib.o" >/dev/null 2>&1; then echo "mcpu-ld accepted unsupported B suffix" >&2 exit 1 fi v=`"$CPU_RUN" --int-reg=r64@0x00018 "$D/a"` test "x$v" = x42 # DATA integer output is target-representation aware. v=`"$CPU_RUN" --int-data=64@32 "$D/a"` test "x$v" = x42 # raw_bytes starts at DATA offset 40. Request beyond the end of .data: # cpu-run must clip the dump to the 20 bytes that remain in .data. out=`"$CPU_RUN" --raw-data=64@40 "$D/a"` printf '%s\n' "$out" | grep -F 'DATA memory dump: (20 bytes):' >/dev/null printf '%s\n' "$out" | grep -F ' 0000 : 02 00 01 00 01 00 40 00 00 00 00 00 00 00 00 00 | ......@.........' >/dev/null printf '%s\n' "$out" | grep -F ' 0010 : 00 00 d4 37 ' >/dev/null # The linker-owned DATA NULL guard is not part of .data and must not be dumpable. if "$CPU_RUN" --raw-data=1@16 "$D/a" >/dev/null 2>&1; then echo 'raw DATA dump escaped the linked .data section' >&2 exit 1 fi