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 / gpu / hw / core.om

922 lines · 16234 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note core.om: hardware capability manifest reader, checker and admission (seeded Omega, AArch64).
3note Unit 1 of hwman: cat backend/hw/core.om backend/hw/cpu.om backend/hw/tpm.om backend/hw/main.om | omc
4note Units share globals; each unit's private names carry its prefix (cpu*, tpm*); core owns the rest.
5note
6note Manifest format (backend/hw/manifest.tsv): line 1 is exactly "hwman<TAB>1" (schema 1); line 2 is
7note exactly the column header THDR below; every later line that is neither empty nor starts with '#'
8note is one target row of exactly NCOL tab-separated nonempty fields ("-" when a field has no value).
9note The checker refuses (exit 3) a wrong schema line, a wrong header, a wrong field count, an empty
10note field, an id outside [a-z0-9-] or repeated, a family/route/status/admit value outside its
11note enumeration, a non-decimal timeout_ms, any of the 21 required families missing, and these rules:
12note admit YES needs status CHIP_TESTED, evidence other than NOT_RUN, a hwman-* runner, ops, blocker -
13note BLOCKED_* needs a blocker and admit NO; route UNRESOLVED exactly when status BLOCKED_NAME
14note PROPOSED needs admit NO; every other status except BLOCKED_* needs evidence other than NOT_RUN
15note Refusals print one line "REFUSE <class> <reason> ..." on stdout.
16om2
17
18text THDR "id\tfamily\tvendor\tpart\trevision\troute\tplatform\tidentity\tnode\tisa_cmds\tdiscovery\tops\taddr_spaces\tdma_coherence\tqueue_irq\treset_power\tfirmware\tcompiler_artifact\trefs\trunner\ttimeout_ms\tstatus\tadmit\tevidence\tblocker"
19text TSCH "hwman\t1"
20text TFAM "CPU GPU APU PPU SPU NPU TPU LPU MCU ISP TPM SECURE_ENCLAVE ASIC FPGA DPU WSE NEUROMORPHIC PHOTONIC QPU TSU BPU"
21text TROUTE "NATIVE_ISA DIRECT_DEVICE VENDOR_RUNTIME REMOTE_SERVICE FIRMWARE_OWNED UNRESOLVED"
22text TSTAT "CHIP_TESTED PRIOR_RECEIPT EMULATED HOST_TESTED PROPOSED BLOCKED_ACCESS BLOCKED_NAME"
23text TYESNO "YES NO"
24text TDASH "-"
25text TNOTRUN "NOT_RUN"
26text THWPFX "hwman-"
27note The closed runner table: the runners this program implements, the one family and route each
28note drives, and the operations each dispatches (cpuop in cpu.om; runtpm in main.om). check refuses
29note a row naming any other hwman- runner, another family or route, or another operation.
30text TRUN "hwman-cpu hwman-tpm"
31text TOPCPU "sumsq64 fnv1a64"
32text TOPTPM "props getrandom"
33const FCPU long 0
34const FTPM long 10
35const RNATIVE long 0
36const RDIRECT long 1
37text TREF "REFUSE "
38text TNL "\n"
39text TSP " "
40text TEQ "="
41text TLINE " line="
42text TIO "hwman: I/O error reading "
43text TBIG "hwman: manifest larger than 262144 bytes\n"
44
45note column indices (0-based)
46const CID ulong 0
47const CFAM ulong 1
48const CVEND ulong 2
49const CPART ulong 3
50const CREV ulong 4
51const CROUTE ulong 5
52const CIDENT ulong 7
53const CNODE ulong 8
54const COPS ulong 11
55const CRUNNER ulong 19
56const CTMO ulong 20
57const CSTAT ulong 21
58const CADMIT ulong 22
59const CEVID ulong 23
60const CBLOCK ulong 24
61const NCOL ulong 25
62const NFAM ulong 21
63const MAXROW ulong 128
64const MANCAP ulong 262144
65
66note exit classes shared by every command
67const XOK int 0
68const XUSAGE int 2
69const XMAN int 3
70const XUNKNOWN int 4
71const XUNSUP int 5
72const XAUTH int 6
73const XSTALE int 7
74const XWRDEV int 8
75const XBUSY int 9
76const XOFFLINE int 10
77const XTIMEOUT int 11
78const XMISM int 12
79const XDEVERR int 13
80const XINVAL int 14
81const XIO int 74
82
83global gman uchar 262144
84global gav uchar 8192
85global gao ulong 16
86global gal ulong 16
87global gpath uchar 4096
88global gfile uchar 65536
89global gob uchar 8192
90global gfo ulong 32
91global gfl ulong 32
92global grow ulong 128
93global grln ulong 128
94note gst: 0 manifest length, 1 output fill, 2 fields in current row, 3 rows, 4 argc, 5 path length,
95note 6 current row line number, 7 gfile length, 8 admitted rows
96global gst ulong 16
97
98fn oflush to void
99n = write 1 gob 0 get gst 1
100put gst 1 0
101end
102
103fn oc b uchar to void
104f = get gst 1
105if ge f 8000
106oflush
107f = get gst 1
108end
109put gob f b
110put gst 1 add f 1
111end
112
113fn ot t view uchar * to void
114for i ulong len t
115oc get t i
116end
117end
118
119fn odec v ulong to void
120d = new uchar 20 0
121k = ulong 0
122x = v
123while true bound 21
124put d k uchar add rem x 10 48
125k = add k 1
126x = div x 10
127if eq x 0
128break
129end
130end
131for i ulong k
132oc get d sub sub k i 1
133end
134end
135
136fn osdec v long to void
137if lt v 0
138oc 45
139odec ulong sub 0 v
140else
141odec ulong v
142end
143end
144
145fn ohx v ulong w ulong to void
146oc 48
147oc 120
148for i ulong w
149s = mul sub sub w i 1 4
150q = and shr v s 15
151if lt q 10
152oc uchar add q 48
153else
154oc uchar add q 87
155end
156end
157end
158
159fn ofield k ulong to void
160o = get gfo k
161for i ulong get gfl k
162oc get gman add o i
163end
164end
165
166fn oarg a ulong to void
167o = get gao a
168for i ulong get gal a
169oc get gav add o i
170end
171end
172
173fn fail code int msg view uchar * to void
174oflush
175n = write 2 msg 0 len msg
176exit code
177end
178
179note copy every argument into gav; argument a is gav[gao a .. + gal a]
180fn loadargs to void
181c = argcnt
182if gt c 16
183fail XUSAGE TNL
184end
185put gst 4 ulong c
186o = ulong 0
187for a ulong ulong c
188n = argread a gav o sub len gav o
189if lt n 0
190fail XUSAGE TNL
191end
192put gao a o
193put gal a ulong n
194o = add o ulong n
195end
196end
197
198fn argc to ulong
199ret get gst 4
200end
201
202fn argeq a ulong t view uchar * to bool
203if ne get gal a len t
204ret false
205end
206o = get gao a
207for i ulong len t
208if ne get gav add o i get t i
209ret false
210end
211end
212ret true
213end
214
215note decimal argument; -1 when empty, non-decimal or above 2^40
216fn argdec a ulong to long
217n = get gal a
218if eq n 0
219ret -1
220end
221if gt n 13
222ret -1
223end
224o = get gao a
225v = ulong 0
226for i ulong n
227c = get gav add o i
228if or lt c 48 gt c 57
229ret -1
230end
231v = add mul v 10 ulong sub c 48
232end
233ret long v
234end
235
236note path buffer
237fn pclear to void
238put gst 5 0
239end
240
241fn pc b uchar to void
242p = get gst 5
243if ge p sub len gpath 1
244fail XUSAGE TNL
245end
246put gpath p b
247put gst 5 add p 1
248end
249
250fn pt t view uchar * to void
251for i ulong len t
252pc get t i
253end
254end
255
256fn pfield k ulong to void
257o = get gfo k
258for i ulong get gfl k
259pc get gman add o i
260end
261end
262
263fn parg a ulong to void
264o = get gao a
265for i ulong get gal a
266pc get gav add o i
267end
268end
269
270fn pdec v ulong to void
271d = new uchar 20 0
272k = ulong 0
273x = v
274while true bound 21
275put d k uchar add rem x 10 48
276k = add k 1
277x = div x 10
278if eq x 0
279break
280end
281end
282for i ulong k
283pc get d sub sub k i 1
284end
285end
286
287note read the file named in gpath into gfile; return its length or -errno
288fn readpath to long
289fd = fopen gpath 0 get gst 5 0 0
290if lt fd 0
291ret fd
292end
293t = ulong 0
294while true bound 4096
295n = read int fd gfile t sub len gfile t
296if lt n 0
297c = fclose int fd
298ret n
299end
300if eq n 0
301break
302end
303t = add t ulong n
304if eq t len gfile
305break
306end
307end
308c = fclose int fd
309put gst 7 t
310ret long t
311end
312
313fn readman a ulong to void
314pclear
315parg a
316fd = fopen gpath 0 get gst 5 0 0
317if lt fd 0
318ot TIO
319oarg a
320oc 10
321fail XIO TNL
322end
323t = ulong 0
324while true bound 4096
325n = read int fd gman t sub MANCAP t
326if lt n 0
327fail XIO TIO
328end
329if eq n 0
330break
331end
332t = add t ulong n
333if eq t MANCAP
334fail XMAN TBIG
335end
336end
337c = fclose int fd
338put gst 0 t
339end
340
341note split the line starting at off into gfo/gfl; return the offset after its newline
342fn rowat off ulong to ulong
343m = get gst 0
344k = ulong 0
345s = off
346i = off
347put gfo 0 off
348while true bound 262145
349if ge i m
350break
351end
352c = get gman i
353if eq c 10
354break
355end
356if eq c 9
357if lt k sub len gfo 1
358put gfl k sub i s
359k = add k 1
360put gfo k add i 1
361end
362s = add i 1
363end
364i = add i 1
365end
366put gfl k sub i s
367put gst 2 add k 1
368if lt i m
369ret add i 1
370end
371ret i
372end
373
374fn feq k ulong t view uchar * to bool
375if ne get gfl k len t
376ret false
377end
378o = get gfo k
379for i ulong len t
380if ne get gman add o i get t i
381ret false
382end
383end
384ret true
385end
386
387fn fpfx k ulong t view uchar * to bool
388if lt get gfl k len t
389ret false
390end
391o = get gfo k
392for i ulong len t
393if ne get gman add o i get t i
394ret false
395end
396end
397ret true
398end
399
400fn fargeq k ulong a ulong to bool
401if ne get gfl k get gal a
402ret false
403end
404o = get gfo k
405p = get gao a
406for i ulong get gfl k
407if ne get gman add o i get gav add p i
408ret false
409end
410end
411ret true
412end
413
414note gman[o..o+n) equals t[s..s+n)
415fn mteq o ulong n ulong t view uchar * s ulong to bool
416if gt add s n len t
417ret false
418end
419for j ulong n
420if ne get gman add o j get t add s j
421ret false
422end
423end
424ret true
425end
426
427note gman[o..o+n) equals gav[p..p+n)
428fn maeq o ulong n ulong p ulong to bool
429for j ulong n
430if ne get gman add o j get gav add p j
431ret false
432end
433end
434ret true
435end
436
437note index of field k in the space-separated enumeration t, or -1
438fn fenum k ulong t view uchar * to long
439o = get gfo k
440n = get gfl k
441idx = long 0
442s = ulong 0
443for i ulong add len t 1
444b = true
445if lt i len t
446b = eq get t i 32
447end
448if b
449if eq sub i s n
450if mteq o n t s
451ret idx
452end
453end
454idx = add idx 1
455s = add i 1
456end
457end
458ret -1
459end
460
461note decimal field value, or -1
462fn fdec k ulong to long
463n = get gfl k
464if or eq n 0 gt n 13
465ret -1
466end
467o = get gfo k
468v = ulong 0
469for i ulong n
470c = get gman add o i
471if or lt c 48 gt c 57
472ret -1
473end
474v = add mul v 10 ulong sub c 48
475end
476ret long v
477end
478
479note does the comma list in field k contain argument a
480fn flisthas k ulong a ulong to bool
481o = get gfo k
482n = get gfl k
483w = get gal a
484if eq w 0
485ret false
486end
487s = ulong 0
488for i ulong add n 1
489b = true
490if lt i n
491b = eq get gman add o i 44
492end
493if b
494if eq sub i s w
495if maeq add o s w get gao a
496ret true
497end
498end
499s = add i 1
500end
501end
502ret false
503end
504
505note is gman[o..o+w) one word of the space-separated list t
506fn wordin o ulong w ulong t view uchar * to bool
507if eq w 0
508ret false
509end
510s = ulong 0
511for i ulong add len t 1
512b = true
513if lt i len t
514b = eq get t i 32
515end
516if b
517if eq sub i s w
518if mteq o w t s
519ret true
520end
521end
522s = add i 1
523end
524end
525ret false
526end
527
528note is every comma-separated item of field k a word of the space-separated list t
529fn listin k ulong t view uchar * to bool
530o = get gfo k
531n = get gfl k
532s = ulong 0
533for i ulong add n 1
534b = true
535if lt i n
536b = eq get gman add o i 44
537end
538if b
539if not wordin add o s sub i s t
540ret false
541end
542s = add i 1
543end
544end
545ret true
546end
547
548note gav[p..p+w) equals t[s..s+w)
549fn ateq p ulong w ulong t view uchar * s ulong to bool
550for j ulong w
551if ne get gav add p j get t add s j
552ret false
553end
554end
555ret true
556end
557
558note is argument a one word of the space-separated list t
559fn argin a ulong t view uchar * to bool
560w = get gal a
561s = ulong 0
562for i ulong add len t 1
563b = true
564if lt i len t
565b = eq get t i 32
566end
567if b
568if and eq sub i s w gt w 0
569if ateq get gao a w t s
570ret true
571end
572end
573s = add i 1
574end
575end
576ret false
577end
578
579fn mrefuse why view uchar * line ulong to int
580ot TREF
581ot why
582ot TLINE
583odec line
584oc 10
585oflush
586ret XMAN
587end
588
589text RSCHEMA "manifest schema_version"
590text RHDR "manifest header"
591text RCOLS "manifest field_count"
592text REMPTY "manifest empty_field"
593text RIDCH "manifest id_charset"
594text RDUP "manifest duplicate_id"
595text RFAM "manifest family"
596text RROUTE "manifest route"
597text RSTAT "manifest status"
598text RADMIT "manifest admit"
599text RTMO "manifest timeout_ms"
600text RADMEV "manifest admit_without_chip_evidence"
601text RBLK "manifest blocked_without_blocker"
602text RUNRES "manifest unresolved_route_status"
603text RPROP "manifest proposed_admitted"
604text REVID "manifest status_without_evidence"
605text RROWS "manifest too_many_rows"
606text RMISS "manifest missing_family "
607text RRUN "manifest unknown_runner"
608text RRFAM "manifest runner_family_route"
609text RROP "manifest runner_op"
610
611note is the line starting at st exactly t (followed by a newline or the end of the manifest)
612fn lineis st ulong t view uchar * to bool
613m = get gst 0
614if gt add st len t m
615ret false
616end
617for i ulong len t
618if ne get gman add st i get t i
619ret false
620end
621end
622e = add st len t
623if eq e m
624ret true
625end
626ret eq get gman e 10
627end
628
629note print token idx of the space-separated enumeration t
630fn otok t view uchar * idx ulong to void
631k = ulong 0
632for i ulong len t
633c = get t i
634if eq c 32
635k = add k 1
636else
637if eq k idx
638oc c
639end
640end
641end
642end
643
644global gchk ulong 4
645
646note the id of the split row is [a-z0-9-]
647fn idok to bool
648o = get gfo CID
649for i ulong get gfl CID
650c = get gman add o i
651ok = or and ge c 97 le c 122 or and ge c 48 le c 57 eq c 45
652if not ok
653ret false
654end
655end
656ret true
657end
658
659note runner rn of TRUN drives exactly one family and route
660fn runok rn long fam long route long to bool
661if eq rn 0
662ret and eq fam FCPU eq route RNATIVE
663end
664ret and eq fam FTPM eq route RDIRECT
665end
666
667note every operation of the row is one runner rn dispatches
668fn runops rn long to bool
669if eq rn 0
670ret listin COPS TOPCPU
671end
672ret listin COPS TOPTPM
673end
674
675note rules for the split row at manifest line `line`; sets gchk 0 family index, gchk 1 admitted
676fn chkrow line ulong to int
677if ne get gst 2 NCOL
678ret mrefuse RCOLS line
679end
680for k ulong NCOL
681if eq get gfl k 0
682ret mrefuse REMPTY line
683end
684end
685if not idok
686ret mrefuse RIDCH line
687end
688fam = fenum CFAM TFAM
689if lt fam 0
690ret mrefuse RFAM line
691end
692route = fenum CROUTE TROUTE
693if lt route 0
694ret mrefuse RROUTE line
695end
696sts = fenum CSTAT TSTAT
697if lt sts 0
698ret mrefuse RSTAT line
699end
700yes = fenum CADMIT TYESNO
701if lt yes 0
702ret mrefuse RADMIT line
703end
704if lt fdec CTMO 0
705ret mrefuse RTMO line
706end
707noev = or feq CEVID TNOTRUN feq CEVID TDASH
708nobl = feq CBLOCK TDASH
709put gchk 1 0
710if eq yes 0
711ok = and and eq sts 0 not noev and and fpfx CRUNNER THWPFX nobl not feq COPS TDASH
712if not ok
713ret mrefuse RADMEV line
714end
715put gchk 1 1
716end
717if ge sts 5
718if or nobl eq yes 0
719ret mrefuse RBLK line
720end
721end
722if ne eq route 5 eq sts 6
723ret mrefuse RUNRES line
724end
725if and eq sts 4 eq yes 0
726ret mrefuse RPROP line
727end
728if and lt sts 4 noev
729ret mrefuse REVID line
730end
731if fpfx CRUNNER THWPFX
732rn = fenum CRUNNER TRUN
733if lt rn 0
734ret mrefuse RRUN line
735end
736if not runok rn fam route
737ret mrefuse RRFAM line
738end
739if not runops rn
740ret mrefuse RROP line
741end
742end
743put gchk 0 ulong fam
744ret XOK
745end
746
747note gman[a..a+n) equals gman[b..b+n)
748fn mmeq a ulong b ulong n ulong to bool
749for j ulong n
750if ne get gman add a j get gman add b j
751ret false
752end
753end
754ret true
755end
756
757note does any of the first rows rows carry the id at gman[io..io+il)
758fn iddup rows ulong io ulong il ulong to bool
759for r ulong rows
760q = rowat get grow r
761if eq get gfl CID il
762if mmeq get gfo CID io il
763ret true
764end
765end
766end
767ret false
768end
769
770note check the loaded manifest; record row offsets in grow/grln; return an exit class
771fn check to int
772m = get gst 0
773if not lineis 0 TSCH
774ret mrefuse RSCHEMA 1
775end
776h = rowat 0
777if not lineis h THDR
778ret mrefuse RHDR 2
779end
780off = rowat h
781line = ulong 2
782rows = ulong 0
783fams = ulong 0
784adm = ulong 0
785while true bound 65536
786if ge off m
787break
788end
789line = add line 1
790st = off
791off = rowat st
792if and eq get gfl 0 0 eq get gst 2 1
793continue
794end
795if eq get gman st 35
796continue
797end
798c = chkrow line
799if ne c XOK
800ret c
801end
802if ge rows MAXROW
803ret mrefuse RROWS line
804end
805if iddup rows get gfo CID get gfl CID
806ret mrefuse RDUP line
807end
808put grow rows st
809put grln rows line
810rows = add rows 1
811fams = or fams shl ulong 1 get gchk 0
812adm = add adm get gchk 1
813end
814put gst 3 rows
815put gst 8 adm
816note report the first missing family by name
817for f ulong NFAM
818if eq and shr fams f 1 0
819ot TREF
820ot RMISS
821otok TFAM f
822oc 10
823oflush
824ret XMAN
825end
826end
827ret XOK
828end
829
830note row index of the target named by argument a, or -1; leaves that row split
831fn findrow a ulong to long
832for r ulong get gst 3
833q = rowat get grow r
834if fargeq CID a
835ret long r
836end
837end
838ret -1
839end
840
841fn hexdig c uchar to long
842if and ge c 48 le c 57
843ret long sub c 48
844end
845if and ge c 97 le c 102
846ret long sub c 87
847end
848if and ge c 65 le c 70
849ret long sub c 55
850end
851ret -1
852end
853
854note "0x" hex number at gfile[off..off+n), optional trailing newline; -1 when malformed or above 2^60
855fn hexat off ulong n ulong to long
856if lt n 3
857ret -1
858end
859if or ne get gfile off 48 ne get gfile add off 1 120
860ret -1
861end
862v = ulong 0
863d = ulong 0
864for i ulong sub n 2
865c = get gfile add add off 2 i
866if eq c 10
867if eq add i 3 n
868break
869end
870ret -1
871end
872x = hexdig c
873if lt x 0
874ret -1
875end
876if ge v 0x0800000000000000
877ret -1
878end
879v = or shl v 4 ulong x
880d = add d 1
881end
882if eq d 0
883ret -1
884end
885ret long v
886end
887
888note identity field "key=0xHEX": the value, or -1
889fn fidhex to long
890o = get gfo CIDENT
891n = get gfl CIDENT
892e = n
893for i ulong n
894if eq get gman add o i 61
895if eq e n
896e = i
897end
898end
899end
900if ge add e 3 n
901ret -1
902end
903if or ne get gman add add o e 1 48 ne get gman add add o e 2 120
904ret -1
905end
906v = ulong 0
907for i ulong sub sub n e 3
908x = hexdig get gman add add add o e 3 i
909if or lt x 0 ge v 0x0800000000000000
910ret -1
911end
912v = or shl v 4 ulong x
913end
914ret long v
915end
916
917fn hexc q ulong to uchar
918if lt q 10
919ret uchar add q 48
920end
921ret uchar add q 87
922end