interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / rung0 / gate0.sh

31 lines · 2963 bytes Raw Blame History
1#!/bin/sh
2# gate0.sh <out dir> -- rung 0 gates (seed/README.md). Shell glue; the Omega decoder and GNU objdump/readelf
3# run as reference checks and never make a byte of seed/.
4# (a) load0.sh (the one outside tool) builds seed0.bin from seed0.hex; seed0.bin run on seed0.hex
5# gives seed0.bin byte for byte, and equals the committed seed/rung0/seed0.bin
6# (b)+(c) audit.sh: every word against our decoder and objdump, 0 mismatches -> seed0.audit
7# controls: a changed name must be caught by the audit; seed0 refuses a bad character (exit 4) and a
8# cut-short word (exit 1); upper-case digits read the same as lower-case; readelf reads the header
9set -u
10D=$(cd "$(dirname "$0")/.." && pwd); R=$(cd "$D/.." && pwd); O=$1; mkdir -p "$O"
11CHK=$R/build/seed/a64check
12fail=0; ok() { echo "PASS $*"; }; bad() { echo "FAIL $*"; fail=1; }
13mkdir -p "$R/build/seed"
14(cd "$R" && sha256sum -c --status seed/out/omc.sha256) || { echo "FAIL a64check: seed/out/omc does not match seed/out/omc.sha256"; exit 1; }
15printf 'a64check compiler '
16sha256sum "$D/out/omc" || { echo "FAIL a64check compiler hash log"; exit 1; }
17"$D/out/omc" < "$D/check/a64check.om" > "$CHK" && chmod +x "$CHK" || { echo "FAIL a64check build"; exit 1; }
18sh "$D/rung0/load0.sh" "$D/rung0/seed0.hex" "$O/seed0.bin" && chmod +x "$O/seed0.bin" || bad "load0"
19"$O/seed0.bin" < "$D/rung0/seed0.hex" > "$O/seed0.self"; rc=$?
20[ $rc = 0 ] && cmp -s "$O/seed0.bin" "$O/seed0.self" && ok "(a) seed0 rebuilds itself byte for byte ($(wc -c < "$O/seed0.bin") bytes)" || bad "(a) self-rebuild rc=$rc"
21cmp -s "$O/seed0.bin" "$D/rung0/seed0.bin" && ok "(a) equals the committed seed/rung0/seed0.bin" || bad "(a) committed seed0.bin differs"
22sh "$D/check/audit.sh" "$D/rung0/seed0.hex" "$O/seed0.bin" "$CHK" > "$O/seed0.audit"; rc=$?
23[ $rc = 0 ] && ok "(b)(c) $(tail -1 "$O/seed0.audit")" || bad "(b)(c) $(tail -1 "$O/seed0.audit")"
24sed 's/# \[0\] movz x9, #10 /# [0] movz x9, #11 /' "$D/rung0/seed0.hex" > "$O/ctl-name.hex"
25sh "$D/check/audit.sh" "$O/ctl-name.hex" "$O/seed0.bin" "$CHK" > "$O/ctl-name.audit" && bad "control: wrong name not caught" || ok "control: a wrong name is caught ($(tail -1 "$O/ctl-name.audit"))"
26printf 'd2800149\nd28g0039\n' | "$O/seed0.bin" > /dev/null; rc=$?; [ $rc = 4 ] && ok "control: bad character refused (exit 4)" || bad "bad char exit $rc"
27printf 'd2800149\nd28000\n' | "$O/seed0.bin" > /dev/null; rc=$?; [ $rc = 1 ] && ok "control: cut-short word refused (exit 1)" || bad "short word exit $rc"
28a=$(printf 'D2A00837 # x\n' | "$O/seed0.bin" | od -An -tx1 | tr -d ' '); [ "$a" = 3708a0d2 ] && ok "upper-case word D2A00837 -> bytes 37 08 a0 d2" || bad "upper-case gave $a"
29readelf -h -l "$O/seed0.bin" > "$O/seed0.readelf" 2>&1 && grep -q "AArch64" "$O/seed0.readelf" && grep -q "0x400078" "$O/seed0.readelf" && ok "readelf (reference) reads the hand-written header: AArch64, entry 0x400078" || bad "readelf"
30[ $fail = 0 ] && echo "GATE0 PASS" || echo "GATE0 FAIL"
31exit $fail