aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / tests / fixtures / osh / make-osh-units.sh
| 1 | #!/bin/bash |
| 2 | # make-osh-units.sh: pack the three compiled OSH shell-core units (lex_run, parse_run, expand_run; OSH-AIENOS-0) |
| 3 | # into TEST-signed OSC unit containers with the spec's own generator helpers. Usage: |
| 4 | # make-osh-units.sh SPEC_DIR OSCC_OUT_DIR OUT_DIR |
| 5 | # SPEC_DIR a checkout of aien-protocols specs/osc-unit-artifact (tools/make-vectors.sh, keys/test1.pub) |
| 6 | # OSCC_OUT_DIR holds osh_{lex,parse,expand}.{ir,code,entries} written by `oscc src/osh/osh_X.osc OUT` (omega) |
| 7 | # OUT_DIR receives osh_lex.unit osh_parse.unit osh_expand.unit |
| 8 | # Unlike make-l01.sh the IR and the code are REAL compiler output (oscc), not hand-assembled, and every function |
| 9 | # gets its entry record from OUT.entries (lines: fn_index nregs ret_kind k0..k5 code_offset name). |
| 10 | # One container per unit, TEST signer (the spec's throwaway key test1), no caps, max_stack_bytes 16384, |
| 11 | # cpu_ticks 1000 (1 tick = 10 ms, so 10 s per call, QEMU TCG). |
| 12 | # QEMU (aarch64 virt), TEST signer, not physical. Needs xxd, sha256sum, openssl (Ed25519), bash. No Python. |
| 13 | set -eu |
| 14 | export LC_ALL=C |
| 15 | SPEC=${1:?SPEC_DIR} |
| 16 | OSCC=${2:?OSCC_OUT_DIR} |
| 17 | OUT=${3:?OUT_DIR} |
| 18 | STACK=16384 |
| 19 | TICKS=1000 |
| 20 | mkdir -p "$OUT" |
| 21 | work=$(mktemp -d) |
| 22 | trap 'rm -rf "$work"' EXIT |
| 23 | n=$(grep -n '^cp "\$SRC/min.ir"' "$SPEC/tools/make-vectors.sh" | head -1 | cut -d: -f1) |
| 24 | { echo 'here='"$SPEC/tools"; sed -n "1,$((n - 1))p" "$SPEC/tools/make-vectors.sh" | sed '/^here=/d'; } >"$work/helpers.sh" |
| 25 | OUT_UNIT=$OUT |
| 26 | set -- "$work/keys-out" "$work/keys-out" # helpers read OUT_DIR=$1, KEYS_DIR=$2 |
| 27 | mkdir -p "$work/keys-out" |
| 28 | SRC=$SPEC/src |
| 29 | # shellcheck disable=SC1090 |
| 30 | . "$work/helpers.sh" |
| 31 | OUT=$OUT_UNIT |
| 32 | cmp -s "$KEYS/test1.pub" "$SPEC/keys/test1.pub" || { echo "TEST key mismatch: generator is not the frozen one" >&2; exit 1; } |
| 33 | |
| 34 | for u in lex parse expand; do |
| 35 | b=$OSCC/osh_$u |
| 36 | nfn=$(wc -l <"$b.entries") |
| 37 | { |
| 38 | while read -r idx nregs ret k0 k1 k2 k3 k4 k5 off name; do |
| 39 | entry "$idx" "$nregs" "$ret" "$k0" "$k1" "$k2" "$k3" "$k4" "$k5" "$off" "$name" |
| 40 | done <"$b.entries" |
| 41 | } >"$work/ent_$u" |
| 42 | caps_none >"$work/caps0" |
| 43 | build "$OUT/osh_$u.unit" test1 1 5 1 "$nfn" "$b.ir" "$b.code" "$work/ent_$u" "$work/caps0" |
| 44 | # header offset 36: max_stack_bytes (u32 LE), offset 40: cpu_ticks (u64 LE); both are signed, so re-sign |
| 45 | s=$(printf '%08x' "$STACK"); t=$(printf '%016x' "$TICKS") |
| 46 | le() { echo "$1" | sed -E 's/(..)/\1 /g' | awk '{for(i=NF;i>0;i--) printf "%s ", $i}'; } |
| 47 | # shellcheck disable=SC2046 |
| 48 | patch "$OUT/osh_$u.unit" 36 $(le "$s") $(le "$t") >"$OUT/osh_$u.unit.new" |
| 49 | mv "$OUT/osh_$u.unit.new" "$OUT/osh_$u.unit" |
| 50 | resign "$OUT/osh_$u.unit" test1 |
| 51 | echo "built $OUT/osh_$u.unit ($nfn functions)" |
| 52 | done |