interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / allen_route_card.sh

47 lines · 2826 bytes Raw Blame History
1#!/usr/bin/env bash
2# allen_route_card.sh -- build a pi5-allen route card (\EFI\AIENOS\ALLEN.EXM with header "AIENALR1 QUALIF-ALLEN-ROUTE",
3# crates/allen-reflex-kernel/src/card.rs parse_route) from route family files (aienos#399). Only the request id, the
4# speaker, the consent/pending flags and the turns go into the card; the expected route stays on the host.
5# Capabilities never go into the card: the image passes its own (core/allen.c CK_ALLEN_ROUTE_CAPS).
6#
7# allen_route_card.sh <out file> <file>...
8#
9# A .psv file is a route family (id|family|speaker|flags|expected_route|expected_then|turns, docs/native/pi5-8/route/);
10# a .req file holds requests with no expected answer (id|owner|guest|flags|turns), for example requests written after
11# the image was built. Each request gets its own session id (its line number on the card).
12# Refuses held-out and sealed files: the Pi card is a rehearsal; held-out families are scored once on the host only.
13set -euo pipefail
14out="${1:?out file}"; shift
15[[ $# -ge 1 ]] || { echo "usage: $0 <out file> <file>..." >&2; exit 2; }
16for f in "$@"; do
17 case "$(readlink -f "$f")" in
18 */sealed/*|*heldout*) echo "REFUSE: ${f} is a held-out or sealed file" >&2; exit 2 ;;
19 esac
20 [[ -r "$f" ]] || { echo "no file ${f}" >&2; exit 2; }
21done
22tmp="$(mktemp)"
23trap 'rm -f "${tmp}"' EXIT
24printf 'AIENALR1 QUALIF-ALLEN-ROUTE\n' > "${tmp}"
25for f in "$@"; do
26 if [[ "$f" == *.psv ]]; then nf=6; else nf=3; fi
27 # keep id, speaker, flags; drop the family and expected columns; turns may hold '|' (all after the last field)
28 awk -v nf="${nf}" '!/^#/ && NF {
29 r = $0
30 for (n = 0; n < nf; n++) { j = index(r, "|"); if (!j) { print "bad line: " $0 > "/dev/stderr"; exit 1 }
31 f[n] = substr(r, 1, j - 1); r = substr(r, j + 1) }
32 sp = (nf == 6) ? f[2] : f[1]; fl = (nf == 6) ? f[3] : f[2]
33 print f[0] "|" sp "|" fl "|" r }' "$f" >> "${tmp}"
34done
35# speaker -> speaker:<session>, session = the request's line number on the card
36awk 'NR == 1 { print; next } { i = index($0, "|"); id = substr($0, 1, i - 1); r = substr($0, i + 1);
37 j = index(r, "|"); sp = substr(r, 1, j - 1); print id "|" sp ":" NR - 1 "|" substr(r, j + 1) }' "${tmp}" > "${tmp}.s"
38mv "${tmp}.s" "${tmp}"
39n=$(( $(wc -l < "${tmp}") - 1 ))
40bytes=$(stat -c %s "${tmp}")
41[[ ${bytes} -le 131072 ]] || { echo "card file ${bytes} bytes > 131072" >&2; exit 1; }
42[[ ${n} -ge 1 && ${n} -le 512 ]] || { echo "card file has ${n} requests (1..512)" >&2; exit 1; }
43dups=$(tail -n +2 "${tmp}" | cut -d'|' -f1 | sort | uniq -d | head -3 | tr '\n' ' ')
44[[ -z "${dups}" ]] || { echo "duplicate request ids: ${dups}" >&2; exit 1; }
45mv "${tmp}" "${out}"
46trap - EXIT
47echo "route card ${out}: ${n} requests, ${bytes} bytes, sha256 $(sha256sum "${out}" | cut -d' ' -f1)"