From 895e059383f9e5c0a55f40b11b4cac8d5d7fbea4 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Fri, 30 Oct 2026 15:58:16 +0200 Subject: [PATCH] build-lance.sh: fail the build if .text overlaps the marker block The text panel grew .text past MARK and the payload overwrote its own code with cell() writes (illegal opcode on the unit). The build now parses build/lance.map and aborts if the end of .text reaches MARK, printing the remaining gap. --- harness/udpstream/build-lance.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/harness/udpstream/build-lance.sh b/harness/udpstream/build-lance.sh index 72d769d..c68e366 100755 --- a/harness/udpstream/build-lance.sh +++ b/harness/udpstream/build-lance.sh @@ -87,6 +87,24 @@ done OUTNAME=${LANCE_OUT:-lance.coff} cp "$WORK/LANCE.OUT" "$OUT/$OUTNAME" sed 's/\r$//' "$WORK/LANCE.MAP" > "$OUT/lance.map" +# Guard: the marker block (MARK in the source) must sit clear of .text, or the +# payload overwrites its own code with cell() writes (an illegal-opcode crash). +python3 - "$SRC" "$OUT/lance.map" <<'PYCHK' +import re, sys +src, mp = sys.argv[1], sys.argv[2] +m = re.search(r'#define\s+MARK\s+(0x[0-9A-Fa-f]+)', open(src).read()) +if m: + mark = int(m.group(1), 16) + for ln in open(mp): + f = ln.split() + if len(f) >= 4 and f[0] == '.text': + start, size = int(f[2], 16), int(f[3], 16) + end = start + size + if end > mark: + sys.stderr.write("build: ERROR .text ends at 0x%X, past MARK 0x%X\n" % (end, mark)) + sys.exit(1) + print("build: .text ends 0x%X, MARK 0x%X (%d bytes clear)" % (end, mark, (mark - end) // 8)) +PYCHK sed 's/\r$//' "$WORK/LANCE.LST" > "$OUT/lance.lst" sed 's/\r$//' "$WORK/ENTRY.LST" > "$OUT/entry.lst" echo "build.sh: $OUT/$OUTNAME ($(wc -c < "$OUT/lance.coff") bytes)"