interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / doctrine / gate.om

361 lines · 5701 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gate: the ARCH-DOCTRINE gate runner (#316), seeded native Omega.
3note usage: gate OMC ROOT (run from tools/doctrine; writes under build/)
4note Builds ../zero-legacy/sha256.om and doctrine.om with OMC, hashes OMC with the native sha256
5note and compares it to ../zero-legacy/omega.pin, prints AIEN-OBS lines, then runs
6note build/doctrine ROOT with this process's stdout. Exit: the checker's exit (0 PASS, 1 FAIL,
7note 2 ROOT unusable); 3 when OMC is missing or does not match the pin (NOT_RUN); 1 when a
8note build fails. gate.sh independently authenticates OMC before executing it to compile this gate.
9
10text tbl "../zero-legacy/sha256.om\nbuild/sha256\ndoctrine.om\nbuild/doctrine\nbuild/omc.sha\nbuild/doctrine.sha\n../zero-legacy/omega.pin\nbuild\n"
11text tobs "AIEN-OBS "
12text tsha "doctrine_sha256 \""
13text tq "\"\n"
14text texit "doctrine_exit "
15text tnl "\n"
16text tuse "usage: gate OMC ROOT\n"
17text tnot "gate: OMC missing or not the pinned compiler (NOT_RUN)\n"
18text tcf "gate: compile failed\n"
19text tkey "omc_sha256: "
20
21global omcp uchar 4096
22global omcl ulong 1
23global rootp uchar 4096
24global rootl ulong 1
25global pk uchar 4096
26global pkn ulong 1
27global pkc ulong 1
28global arg uchar 4096
29global argl ulong 1
30global fin uchar 256
31global finl ulong 1
32global fout uchar 256
33global foutl ulong 1
34global status uchar 4
35global pin uchar 4096
36global pinl ulong 1
37global sha uchar 128
38global nb uchar 24
39
40note ---- text table ----
41
42fn pick i ulong to void
43s = ulong 0
44k = ulong 0
45while lt k i bound 4096
46if eq get tbl s 10
47k = add k 1
48end
49s = add s 1
50end
51n = ulong 0
52while ne get tbl add s n 10 bound 256
53put arg n get tbl add s n
54n = add n 1
55end
56put argl 0 n
57end
58
59note ---- packets for execprog ----
60
61fn pk0 to void
62put pkn 0 2
63put pkc 0 0
64end
65
66fn pka to void
67n = get pkn 0
68m = get argl 0
69put pk n uchar rem m 256
70put pk add n 1 uchar div m 256
71for i ulong m
72put pk add n add 2 i get arg i
73end
74put pkn 0 add n add 2 m
75c = add get pkc 0 1
76put pkc 0 c
77put pk 0 uchar rem c 256
78put pk 1 uchar div c 256
79end
80
81fn pkt i ulong to void
82pick i
83pka
84end
85
86fn pkomc to void
87for i ulong get omcl 0
88put arg i get omcp i
89end
90put argl 0 get omcl 0
91pka
92end
93
94fn pkroot to void
95for i ulong get rootl 0
96put arg i get rootp i
97end
98put argl 0 get rootl 0
99pka
100end
101
102fn setin i ulong to void
103pick i
104for j ulong get argl 0
105put fin j get arg j
106end
107put finl 0 get argl 0
108end
109
110fn setout i ulong to void
111pick i
112for j ulong get argl 0
113put fout j get arg j
114end
115put foutl 0 get argl 0
116end
117
118fn noio to void
119put finl 0 0
120put foutl 0 0
121end
122
123note ---- run the packet; stdin/stdout redirected when set; returns exit code or -1 ----
124
125fn child to void
126if gt get finl 0 0
127fd = fopen fin 0 get finl 0 0 0
128if lt fd 0
129exit 126
130end
131r = dupfd int fd 0 0
132end
133if gt get foutl 0 0
134fd = fopen fout 0 get foutl 0 577 420
135if lt fd 0
136exit 126
137end
138r = dupfd int fd 1 0
139end
140r = execprog pk 0 get pkn 0
141exit 127
142end
143
144fn run to long
145pid = fork
146if lt pid 0
147ret -1
148end
149if eq pid 0
150child
151end
152r = waitpid int pid status 0 4 0
153if ne r pid
154ret -1
155end
156if ne get status 0 0
157ret -1
158end
159ret long get status 1
160end
161
162note ---- steps ----
163
164fn compile src ulong dst ulong to bool
165pk0
166pkomc
167setin src
168setout dst
169r = run
170if ne r 0
171ret false
172end
173pick dst
174r = chmod arg 0 get argl 0 493
175ret eq r 0
176end
177
178note hash the file named by table entry f into table entry out; read 64 hex into sha
179fn hashto f ulong out ulong to bool
180pk0
181pkt 1
182pkt f
183put finl 0 0
184setout out
185r = run
186if ne r 0
187ret false
188end
189ret readsha out
190end
191
192fn hashomc to bool
193pk0
194pkt 1
195pkomc
196put finl 0 0
197setout 4
198r = run
199if ne r 0
200ret false
201end
202ret readsha 4
203end
204
205fn readsha out ulong to bool
206pick out
207fd = fopen arg 0 get argl 0 0 0
208if lt fd 0
209ret false
210end
211r = read int fd sha 0 128
212c = fclose int fd
213ret ge r 64
214end
215
216fn loadpin to bool
217pick 6
218fd = fopen arg 0 get argl 0 0 0
219if lt fd 0
220ret false
221end
222r = read int fd pin 0 4096
223c = fclose int fd
224if le r 0
225ret false
226end
227put pinl 0 ulong r
228ret true
229end
230
231note does sha[0..64) equal the 64 bytes after "omc_sha256: " in the pin
232fn pinok to bool
233n = get pinl 0
234m = len tkey
235if lt n add m 64
236ret false
237end
238e = sub n add m 64
239i = ulong 0
240while le i e bound 4096
241j = ulong 0
242while lt j m bound 16
243if ne get pin add i j get tkey j
244break
245end
246j = add j 1
247end
248if eq j m
249ret same add i m
250end
251i = add i 1
252end
253ret false
254end
255
256fn same p ulong to bool
257for j ulong 64
258if ne get pin add p j get sha j
259ret false
260end
261end
262ret true
263end
264
265note build/doctrine ROOT, stdout inherited
266fn rundoc to long
267pk0
268pkt 3
269pkroot
270noio
271ret run
272end
273
274note ---- output ----
275
276fn wnum v long to void
277if lt v 0
278put nb 22 45
279put nb 23 49
280r = write 1 nb 22 2
281ret
282end
283x = ulong v
284n = ulong 0
285if eq x 0
286put nb 23 48
287n = 1
288end
289while gt x 0 bound 20
290put nb sub 23 n uchar add 48 rem x 10
291x = div x 10
292n = add n 1
293end
294r = write 1 nb sub 24 n n
295end
296
297fn obs1 to void
298r = write 1 tobs 0 len tobs
299r = write 1 tsha 0 len tsha
300r = write 1 sha 0 64
301r = write 1 tq 0 len tq
302end
303
304fn obs2 v long to void
305r = write 1 tobs 0 len tobs
306r = write 1 texit 0 len texit
307wnum v
308r = write 1 tnl 0 1
309end
310
311fn main to int
312if lt argcnt 3
313r = write 2 tuse 0 len tuse
314ret 64
315end
316n = argread 1 omcp 0 4095
317if lt n 1
318r = write 2 tuse 0 len tuse
319ret 64
320end
321put omcl 0 ulong n
322n = argread 2 rootp 0 4095
323if lt n 1
324r = write 2 tuse 0 len tuse
325ret 64
326end
327put rootl 0 ulong n
328pick 7
329r = makedir arg 0 get argl 0 493
330if not compile 0 1
331r = write 2 tnot 0 len tnot
332ret 3
333end
334if not loadpin
335r = write 2 tnot 0 len tnot
336ret 3
337end
338if not hashomc
339r = write 2 tnot 0 len tnot
340ret 3
341end
342if not pinok
343r = write 2 tnot 0 len tnot
344ret 3
345end
346if not compile 2 3
347r = write 2 tcf 0 len tcf
348ret 1
349end
350if not hashto 3 5
351r = write 2 tcf 0 len tcf
352ret 1
353end
354obs1
355e = rundoc
356obs2 e
357if lt e 0
358ret 1
359end
360ret int e
361end