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 / bridge / omega-bridge / tests / native / x86 / check_physical_receipt.om

2233 lines · 36297 bytes Raw Blame History
1om2
2note check_physical_receipt.om: check a physical x86-64 receipt against docs/NATIVE-X86-PHYSICAL.md (DRA-104).
3note usage: check_physical_receipt RECEIPT.json [LOGDIR], run from the repository root (it reads tools/native).
4note LOGDIR defaults to the receipt path without its suffix (evidence/native-x86-physical-PIN8/).
5note It reads only the receipt, its four logs and tools/native; it runs no compiler, caller or emulator.
6note It refuses any receipt that is not a PHYSICAL NATIVE_PASS at the current x86 pin, including every
7note EMULATED or VIRTUAL receipt, and any receipt whose logs do not show the suite's own NATIVE PASS line
8note with virtualization=none and the hypervisor flag clear. Passing is a format and consistency check;
9note it is not itself a run. Output: one PASS or FAIL line per check, then PHYSICAL-RECEIPT ACCEPTED (exit 0)
10note or PHYSICAL-RECEIPT REJECTED (exit 1); a wrong argument count prints the usage line and exits 2.
11note This program replaces check_physical_receipt.py (removed); the differences are listed in
12note evidence/native-x86-physical-checker/README.md.
13const PO ulong 0
14const RL ulong 1
15const NN ulong 2
16const PU ulong 3
17const SO ulong 4
18const SL ulong 5
19const NF ulong 6
20const LN ulong 7
21const FL ulong 8
22const PL ulong 9
23const DL ulong 10
24const ABN ulong 11
25const NBN ulong 12
26const E1 ulong 13
27const E2 ulong 14
28const HX ulong 15
29const HB ulong 16
30const LS ulong 17
31const LE ulong 18
32const TL ulong 19
33const FLAST ulong 20
34const FEMU ulong 21
35const FVIRT ulong 22
36const FHYP ulong 23
37const FFAIL ulong 24
38const FCPU ulong 25
39const FKERN ulong 26
40const FCTRL ulong 27
41const FWRONG ulong 28
42const FMUT ulong 29
43const OPN ulong 30
44const BIGN ulong 31
45const NODES ulong 524288
46const RCAP ulong 900000
47const FCAP ulong 16777215
48const KNONE ulong 4294967295
49global gv ulong 64
50global rcp uchar 1048576
51global pool uchar 1048576
52global nty uchar 524288
53global npa long 524288
54global nko ulong 524288
55global nkl ulong 524288
56global nvo ulong 524288
57global nvl ulong 524288
58global nix ulong 524288
59global fch long 524288
60global nxs long 524288
61global lch long 524288
62global hfst ulong 524288
63global hlst ulong 524288
64global liv uchar 524288
65global htab ulong 1048576
66global fbuf uchar 16777216
67global hexo uchar 64
68global ln uchar 8388608
69global fl uchar 8388608
70global pth uchar 4096
71global ldr uchar 4096
72global ab uchar 4096
73global nb uchar 4096
74global opn uchar 8192
75global xp uchar 2097152
76global pinb uchar 128
77note SHA-256 (FIPS 180-4) of fbuf[0..n), digest as 64 lowercase hex bytes in hexo[0..64).
78note The schedule, round and padding code is copied from omega-mv e5b32567 om/sha256/sha256-om2.om
79note (Apache-2.0), changed only to read the message from the global fbuf instead of an unsized view.
80fn kinit k edit uint 64 to void
81put k 0 0x428a2f98
82put k 1 0x71374491
83put k 2 0xb5c0fbcf
84put k 3 0xe9b5dba5
85put k 4 0x3956c25b
86put k 5 0x59f111f1
87put k 6 0x923f82a4
88put k 7 0xab1c5ed5
89put k 8 0xd807aa98
90put k 9 0x12835b01
91put k 10 0x243185be
92put k 11 0x550c7dc3
93put k 12 0x72be5d74
94put k 13 0x80deb1fe
95put k 14 0x9bdc06a7
96put k 15 0xc19bf174
97put k 16 0xe49b69c1
98put k 17 0xefbe4786
99put k 18 0x0fc19dc6
100put k 19 0x240ca1cc
101put k 20 0x2de92c6f
102put k 21 0x4a7484aa
103put k 22 0x5cb0a9dc
104put k 23 0x76f988da
105put k 24 0x983e5152
106put k 25 0xa831c66d
107put k 26 0xb00327c8
108put k 27 0xbf597fc7
109put k 28 0xc6e00bf3
110put k 29 0xd5a79147
111put k 30 0x06ca6351
112put k 31 0x14292967
113put k 32 0x27b70a85
114put k 33 0x2e1b2138
115put k 34 0x4d2c6dfc
116put k 35 0x53380d13
117put k 36 0x650a7354
118put k 37 0x766a0abb
119put k 38 0x81c2c92e
120put k 39 0x92722c85
121put k 40 0xa2bfe8a1
122put k 41 0xa81a664b
123put k 42 0xc24b8b70
124put k 43 0xc76c51a3
125put k 44 0xd192e819
126put k 45 0xd6990624
127put k 46 0xf40e3585
128put k 47 0x106aa070
129put k 48 0x19a4c116
130put k 49 0x1e376c08
131put k 50 0x2748774c
132put k 51 0x34b0bcb5
133put k 52 0x391c0cb3
134put k 53 0x4ed8aa4a
135put k 54 0x5b9cca4f
136put k 55 0x682e6ff3
137put k 56 0x748f82ee
138put k 57 0x78a5636f
139put k 58 0x84c87814
140put k 59 0x8cc70208
141put k 60 0x90befffa
142put k 61 0xa4506ceb
143put k 62 0xbef9a3f7
144put k 63 0xc67178f2
145end
146fn iv s edit uint 8 to void
147put s 0 0x6a09e667
148put s 1 0xbb67ae85
149put s 2 0x3c6ef372
150put s 3 0xa54ff53a
151put s 4 0x510e527f
152put s 5 0x9b05688c
153put s 6 0x1f83d9ab
154put s 7 0x5be0cd19
155end
156fn sched w edit uint 64 o ulong to void
157q = ulong 0
158x = uint 0
159y = uint 0
160for i ulong 16 unroll
161q = add o mul i 4
162x = uint get fbuf q
163x = or shl x 8 uint get fbuf add q 1
164x = or shl x 8 uint get fbuf add q 2
165put w i or shl x 8 uint get fbuf add q 3
166end
167for i ulong 48 unroll
168x = get w add i 1
169y = get w add i 14
170x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3
171put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10
172end
173end
174fn schedp w edit uint 64 p view uchar 128 o ulong to void
175q = ulong 0
176x = uint 0
177y = uint 0
178for i ulong 16 unroll
179q = add o mul i 4
180x = uint get p q
181x = or shl x 8 uint get p add q 1
182x = or shl x 8 uint get p add q 2
183put w i or shl x 8 uint get p add q 3
184end
185for i ulong 48 unroll
186x = get w add i 1
187y = get w add i 14
188x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3
189put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10
190end
191end
192fn rounds s edit uint 8 w view uint 64 kt view uint 64 to void
193a = get s 0
194b = get s 1
195c = get s 2
196d = get s 3
197e = get s 4
198f = get s 5
199g = get s 6
200h = get s 7
201t = uint 0
202for i ulong 64 unroll
203h = add h get kt i
204h = add h get w i
205t = xor rotr e 6 rotr e 11
206t = xor t rotr e 25
207h = add h t
208h = add h xor g and e xor f g
209d = add d h
210t = xor rotr a 2 rotr a 13
211t = xor t rotr a 22
212h = add h t
213t = and c or a b
214h = add h or and a b t
215t = h
216h = g
217g = f
218f = e
219e = d
220d = c
221c = b
222b = a
223a = t
224end
225put s 0 add get s 0 a
226put s 1 add get s 1 b
227put s 2 add get s 2 c
228put s 3 add get s 3 d
229put s 4 add get s 4 e
230put s 5 add get s 5 f
231put s 6 add get s 6 g
232put s 7 add get s 7 h
233end
234text hexd "0123456789abcdef"
235fn hexout s view uint 8 to void
236for i ulong 8
237v = get s i
238for j2 ulong 8
239sh = sub uint 28 mul uint j2 4
240d = ulong and shr v sh 15
241q = add mul i 8 j2
242put hexo q get hexd d
243end
244end
245end
246fn tailblk s edit uint 8 w edit uint 64 kt view uint 64 n ulong to void
247p = new uchar 128 0
248off = shl shr n 6 6
249k = sub n off
250for i ulong k
251put p i get fbuf add off i
252end
253put p k 0x80
254e = ulong 64
255if ge k 56
256e = 128
257end
258bits = shl n 3
259for i ulong 8 unroll
260put p sub e add i 1 uchar and shr bits mul i 8 0xff
261end
262schedp w view p 0
263rounds s view w kt
264if eq e 128
265schedp w view p 64
266rounds s view w kt
267end
268end
269fn shafbuf n ulong to void
270s = new uint 8 0
271w = new uint 64 0
272kt = new uint 64 0
273kinit kt
274iv s
275nbl = shr n 6
276j = ulong 0
277while lt j nbl bound 999999
278sched w shl j 6
279rounds s view w view kt
280j = add j 1
281end
282tailblk s w view kt n
283hexout view s
284end
285
286note ---- output: one check line is built in ln, then written as PASS/FAIL ----
287text tpass "PASS "
288text tfail "FAIL "
289note a line longer than ln (only from a pathological receipt value) is cut there
290fn lnb b uchar to void
291n = get gv LN
292if ge n 8388608
293ret
294end
295put ln n b
296put gv LN add n 1
297end
298fn lnt t view uchar * to void
299for i ulong len t
300lnb get t i
301end
302end
303fn lnpool o ulong n ulong to void
304for i ulong n
305lnb get pool add o i
306end
307end
308fn lndec v ulong to void
309d = new uchar 24 0
310k = ulong 0
311x = v
312go = true
313while go bound 30
314put d k uchar add 48 rem x 10
315k = add k 1
316x = div x 10
317go = gt x 0
318end
319while gt k 0 bound 30
320k = sub k 1
321lnb get d k
322end
323end
324fn lnhex v ulong nd ulong to void
325k = nd
326while gt k 0 bound 16
327k = sub k 1
328d = ulong and shr v mul k 4 15
329lnb get hexd d
330end
331end
332fn wln to void
333n = get gv LN
334o = ulong 0
335while lt o n bound 999999
336w = write 1 ln o sub n o
337if le w 0
338exit 3
339end
340o = add o ulong w
341end
342put gv LN 0
343end
344fn flkeep to void
345f = get gv FL
346if ge f 8388606
347ret
348end
349if gt f 0
350put fl f 59
351put fl add f 1 32
352f = add f 2
353end
354n = get gv LN
355if gt n sub 8388608 f
356n = sub 8388608 f
357end
358for i ulong n
359put fl add f i get ln i
360end
361put gv FL add f n
362end
363fn emit ok bool to void
364if ok
365w = write 1 tpass 0 5
366else
367w2 = write 1 tfail 0 5
368nf = get gv NF
369if lt nf 4
370flkeep
371end
372put gv NF add nf 1
373end
374lnb 10
375wln
376end
377fn chk t view uchar * ok bool to void
378lnt t
379emit ok
380end
381text trej "PHYSICAL-RECEIPT REJECTED ("
382text tfailed " failed: "
383text tacc "PHYSICAL-RECEIPT ACCEPTED (format and log consistency only; not a run)\n"
384fn finish to int
385nf = get gv NF
386if eq nf 0
387w = write 1 tacc 0 len tacc
388ret 0
389end
390put gv LN 0
391lnt trej
392lndec nf
393lnt tfailed
394f = get gv FL
395for i ulong f
396lnb get fl i
397end
398lnb 41
399lnb 10
400wln
401ret 1
402end
403
404note ---- JSON (RFC 8259 as Python json.loads accepts it, without NaN/Infinity) into a node table ----
405note node j: nty 1 object, 2 array, 3 string, 4 integer, 8 number with a fraction, 9 number with an
406note exponent, 5 true, 6 false, 7 null; npa parent (-1 for the top value); nko/nkl the member key in pool
407note (nkl KNONE for array elements, which carry their index in nix); nvo/nvl the decoded string or the
408note number's text in pool. Every pass of each loop consumes at least one receipt byte (at most RCAP).
409fn pk to long
410p = get gv PO
411if lt p get gv RL
412ret long get rcp p
413end
414ret -1
415end
416fn adv to void
417put gv PO add get gv PO 1
418end
419fn skipws to void
420go = true
421while go bound 999999
422c = pk
423go = or or eq c 32 eq c 9 or eq c 10 eq c 13
424if go
425adv
426end
427end
428end
429fn isdig c long to bool
430ret and ge c 48 le c 57
431end
432fn hexv c long to long
433if isdig c
434ret sub c 48
435end
436if and ge c 97 le c 102
437ret sub c 87
438end
439if and ge c 65 le c 70
440ret sub c 55
441end
442ret -1
443end
444fn hex4 to long
445v = long 0
446for i ulong 4
447h = hexv pk
448if lt h 0
449ret -1
450end
451v = add mul v 16 h
452adv
453end
454ret v
455end
456fn pput b ulong to void
457u = get gv PU
458put pool u uchar b
459put gv PU add u 1
460end
461fn putcp cp ulong to void
462if lt cp 128
463pput cp
464ret
465end
466if lt cp 2048
467pput or 192 shr cp 6
468pput or 128 and cp 63
469ret
470end
471if lt cp 65536
472pput or 224 shr cp 12
473pput or 128 and shr cp 6 63
474pput or 128 and cp 63
475ret
476end
477pput or 240 shr cp 18
478pput or 128 and shr cp 12 63
479pput or 128 and shr cp 6 63
480pput or 128 and cp 63
481end
482fn lowsur v long to long
483if or lt v 0xd800 ge v 0xdc00
484ret v
485end
486p = get gv PO
487if ne pk 92
488ret v
489end
490adv
491if ne pk 117
492put gv PO p
493ret v
494end
495adv
496w = hex4
497if and ge w 0xdc00 lt w 0xe000
498ret add 0x10000 add shl sub v 0xd800 10 sub w 0xdc00
499end
500put gv PO p
501ret v
502end
503fn pesc to bool
504c = pk
505if lt c 0
506ret false
507end
508adv
509if eq c 117
510v = hex4
511if lt v 0
512ret false
513end
514v2 = lowsur v
515putcp ulong v2
516ret true
517end
518m = long -1
519if or eq c 34 or eq c 92 eq c 47
520m = c
521end
522if eq c 98
523m = 8
524end
525if eq c 102
526m = 12
527end
528if eq c 110
529m = 10
530end
531if eq c 114
532m = 13
533end
534if eq c 116
535m = 9
536end
537if lt m 0
538ret false
539end
540pput ulong m
541ret true
542end
543fn pstr to bool
544if ne pk 34
545ret false
546end
547adv
548put gv SO get gv PU
549go = true
550while go bound 999999
551c = pk
552if lt c 32
553ret false
554end
555adv
556if eq c 34
557go = false
558else
559if eq c 92
560ok = pesc
561if not ok
562ret false
563end
564else
565pput ulong c
566end
567end
568end
569put gv SL sub get gv PU get gv SO
570ret true
571end
572fn digs to ulong
573k = ulong 0
574while isdig pk bound 999999
575adv
576k = add k 1
577end
578ret k
579end
580fn pnum to long
581s = get gv PO
582if eq pk 45
583adv
584end
585c = pk
586if eq c 48
587adv
588else
589if not isdig c
590ret -1
591end
592d = digs
593end
594ty = long 4
595if eq pk 46
596adv
597if eq digs 0
598ret -1
599end
600ty = 8
601end
602c = pk
603if or eq c 101 eq c 69
604adv
605c = pk
606if or eq c 43 eq c 45
607adv
608end
609if eq digs 0
610ret -1
611end
612ty = 9
613end
614put gv SO get gv PU
615e = get gv PO
616while lt s e bound 999999
617pput ulong get rcp s
618s = add s 1
619end
620put gv SL sub get gv PU get gv SO
621ret ty
622end
623fn plit t view uchar * to bool
624for i ulong len t
625if ne pk long get t i
626ret false
627end
628adv
629end
630ret true
631end
632note ---- object members: a hash of (parent, key) finds the first member with that key (hfst) and the
633note last one (hlst of the first), so lookups and Python dict order cost one probe, not a scan ----
634fn hpool p long o ulong k ulong to ulong
635h = ulong 0xcbf29ce484222325
636h = xor h ulong add p 1
637h = mul h 0x100000001b3
638for i ulong k
639h = xor h ulong get pool add o i
640h = mul h 0x100000001b3
641end
642r = and h 1048575
643ret r
644end
645fn htext p long t view uchar * to ulong
646h = ulong 0xcbf29ce484222325
647h = xor h ulong add p 1
648h = mul h 0x100000001b3
649for i ulong len t
650h = xor h ulong get t i
651h = mul h 0x100000001b3
652end
653r = and h 1048575
654ret r
655end
656fn sibeq a ulong b ulong to bool
657if ne get nkl a get nkl b
658ret false
659end
660oa = get nko a
661ob = get nko b
662k = get nkl a
663for i ulong k
664x = get pool add oa i
665if ne x get pool add ob i
666ret false
667end
668end
669ret true
670end
671note at most NODES entries in 1048576 slots, so a probe always reaches an empty slot
672fn hput n ulong to void
673p = get npa n
674s = hpool p get nko n get nkl n
675go = true
676while go bound 999999
677v = get htab s
678if eq v 0
679put htab s add n 1
680put hfst n n
681put hlst n n
682ret
683end
684m = sub v 1
685if eq get npa m p
686if sibeq m n
687put hfst n m
688put hlst m n
689ret
690end
691end
692s = and add s 1 1048575
693end
694end
695fn keyeq j ulong t view uchar * to bool
696if ne get nkl j len t
697ret false
698end
699o = get nko j
700for i ulong len t
701if ne get pool add o i get t i
702ret false
703end
704end
705ret true
706end
707fn dget par long t view uchar * to long
708if lt par 0
709ret -1
710end
711if ne get nty par 1
712ret -1
713end
714s = htext par t
715go = true
716while go bound 999999
717v = get htab s
718if eq v 0
719ret -1
720end
721m = sub v 1
722if eq get npa m par
723if keyeq m t
724ret long get hlst m
725end
726end
727s = and add s 1 1048575
728end
729ret -1
730end
731fn newnd ty uchar par long ko ulong kl ulong ix ulong to long
732n = get gv NN
733if ge n NODES
734ret -1
735end
736put nty n ty
737put npa n par
738put nko n ko
739put nkl n kl
740put nix n ix
741put nvo n get gv SO
742put nvl n get gv SL
743put fch n -1
744put nxs n -1
745put lch n -1
746if ge par 0
747l = get lch par
748if lt l 0
749put fch par long n
750else
751put nxs l long n
752end
753put lch par long n
754end
755if ne kl KNONE
756hput n
757end
758put gv NN add n 1
759ret long n
760end
761text ttrue "true"
762text tfalse "false"
763text tnull "null"
764fn pobj par long ko ulong kl ulong ix ulong dep ulong to bool
765n = newnd 1 par ko kl ix
766if lt n 0
767ret false
768end
769adv
770skipws
771if eq pk 125
772adv
773ret true
774end
775go = true
776while go bound 999999
777skipws
778ok = pstr
779if not ok
780ret false
781end
782k0 = get gv SO
783k1 = get gv SL
784skipws
785if ne pk 58
786ret false
787end
788adv
789ok2 = pval n k0 k1 0 add dep 1
790if not ok2
791ret false
792end
793skipws
794c = pk
795adv
796if eq c 125
797go = false
798else
799if ne c 44
800ret false
801end
802end
803end
804ret true
805end
806fn parr par long ko ulong kl ulong ix ulong dep ulong to bool
807n = newnd 2 par ko kl ix
808if lt n 0
809ret false
810end
811adv
812skipws
813if eq pk 93
814adv
815ret true
816end
817i = ulong 0
818go = true
819while go bound 999999
820ok = pval n 0 KNONE i add dep 1
821if not ok
822ret false
823end
824i = add i 1
825skipws
826c = pk
827adv
828if eq c 93
829go = false
830else
831if ne c 44
832ret false
833end
834end
835end
836ret true
837end
838fn pscal par long ko ulong kl ulong ix ulong to bool
839c = pk
840ty = long 0
841if eq c 34
842ok = pstr
843if not ok
844ret false
845end
846ty = 3
847end
848if eq c 116
849if not plit ttrue
850ret false
851end
852ty = 5
853end
854if eq c 102
855if not plit tfalse
856ret false
857end
858ty = 6
859end
860if eq c 110
861if not plit tnull
862ret false
863end
864ty = 7
865end
866if or eq c 45 isdig c
867ty = pnum
868end
869if le ty 0
870ret false
871end
872n = newnd uchar ty par ko kl ix
873ret ge n 0
874end
875fn pval par long ko ulong kl ulong ix ulong dep ulong to bool
876if gt dep 900
877ret false
878end
879skipws
880c = pk
881if eq c 123
882ret pobj par ko kl ix dep
883end
884if eq c 91
885ret parr par ko kl ix dep
886end
887ret pscal par ko kl ix
888end
889
890note ---- receipt bytes must be UTF-8 (Python read_text then json.loads) ----
891fn cont p ulong lo ulong hi ulong to bool
892if ge p get gv RL
893ret false
894end
895b = ulong get rcp p
896ret and ge b lo le b hi
897end
898fn u8len p ulong to ulong
899b = ulong get rcp p
900if lt b 0x80
901ret 1
902end
903if and ge b 0xc2 le b 0xdf
904if cont add p 1 0x80 0xbf
905ret 2
906end
907ret 0
908end
909lo = ulong 0x80
910hi = ulong 0xbf
911if eq b 0xe0
912lo = 0xa0
913end
914if eq b 0xed
915hi = 0x9f
916end
917if and ge b 0xe0 le b 0xef
918if and cont add p 1 lo hi cont add p 2 0x80 0xbf
919ret 3
920end
921ret 0
922end
923if eq b 0xf0
924lo = 0x90
925end
926if eq b 0xf4
927hi = 0x8f
928end
929if and ge b 0xf0 le b 0xf4
930if and cont add p 1 lo hi and cont add p 2 0x80 0xbf cont add p 3 0x80 0xbf
931ret 4
932end
933end
934ret 0
935end
936fn utf8ok to long
937p = ulong 0
938n = get gv RL
939while lt p n bound 999999
940k = u8len p
941if eq k 0
942ret long p
943end
944p = add p k
945end
946ret -1
947end
948note ---- node lookups (a repeated key: the last one wins, as in a Python dict) ----
949fn isobj n long to bool
950if lt n 0
951ret false
952end
953ret eq get nty n 1
954end
955fn nch par long to ulong
956if lt par 0
957ret 0
958end
959if ne get nty par 2
960ret 0
961end
962c = ulong 0
963j = get fch par
964while ge j 0 bound 999999
965c = add c 1
966j = get nxs j
967end
968ret c
969end
970fn aget par long i ulong to long
971if lt par 0
972ret -1
973end
974if ne get nty par 2
975ret -1
976end
977j = get fch par
978while ge j 0 bound 999999
979if eq get nix j i
980ret j
981end
982j = get nxs j
983end
984ret -1
985end
986note ---- value tests ----
987fn peq o ulong n ulong t view uchar * to bool
988if ne n len t
989ret false
990end
991for i ulong n
992if ne get pool add o i get t i
993ret false
994end
995end
996ret true
997end
998fn vstr n long t view uchar * to bool
999if lt n 0
1000ret false
1001end
1002if ne get nty n 3
1003ret false
1004end
1005ret peq get nvo n get nvl n t
1006end
1007fn psub o ulong n ulong t view uchar * to bool
1008m = len t
1009if lt n m
1010ret false
1011end
1012s = ulong 0
1013while le s sub n m bound 999999
1014if peq add o s m t
1015ret true
1016end
1017s = add s 1
1018end
1019ret false
1020end
1021fn vsub n long t view uchar * to bool
1022if lt n 0
1023ret false
1024end
1025if ne get nty n 3
1026ret false
1027end
1028ret psub get nvo n get nvl n t
1029end
1030note value == d for d 0 or 1 with exact decimal arithmetic: true is 1, false is 0, and a number is
1031note compared by its digits and exponent (-0, 1.0, 10e-1, 0e5 all count). Python compares the binary64
1032note rounding instead, so a number like 1.00000000000000001 that only rounds to 1 is refused here.
1033fn numcls n long to ulong
1034o = get nvo n
1035e = add o get nvl n
1036if eq get pool o 45
1037o = add o 1
1038end
1039ipe = e
1040st = ulong 0
1041nz = ulong 0
1042dig = ulong 0
1043pz = ulong 0
1044ex = long 0
1045while lt o e bound 999999
1046c = ulong get pool o
1047if or eq c 46 or eq c 101 eq c 69
1048if eq st 0
1049ipe = o
1050end
1051st = 1
1052if ne c 46
1053st = 2
1054end
1055else
1056if eq c 45
1057st = 3
1058else
1059if lt st 2
1060if and ne c 43 ne c 48
1061nz = add nz 1
1062dig = c
1063pz = o
1064end
1065else
1066if and ne c 43 lt ex 100000000
1067ex = add mul ex 10 long sub c 48
1068end
1069end
1070end
1071end
1072o = add o 1
1073end
1074if eq nz 0
1075ret 0
1076end
1077s0 = get nvo n
1078if eq get pool s0 45
1079ret 2
1080end
1081if or ne nz 1 ne dig 49
1082ret 2
1083end
1084if eq st 3
1085ex = neg ex
1086end
1087r = add long ipe ex
1088if lt pz ipe
1089r = sub r 1
1090end
1091if eq long pz r
1092ret 1
1093end
1094ret 2
1095end
1096fn numis n long d ulong to bool
1097if lt n 0
1098ret false
1099end
1100t = get nty n
1101if eq t 5
1102ret eq d 1
1103end
1104if eq t 6
1105ret eq d 0
1106end
1107if and and ne t 4 ne t 8 ne t 9
1108ret false
1109end
1110ret eq numcls n d
1111end
1112fn cplen o ulong to ulong
1113b = get pool o
1114if lt b 0x80
1115ret 1
1116end
1117if lt b 0xe0
1118ret 2
1119end
1120if lt b 0xf0
1121ret 3
1122end
1123ret 4
1124end
1125fn cpat o ulong to ulong
1126b = ulong get pool o
1127k = cplen o
1128if eq k 1
1129ret b
1130end
1131v = ulong and b 0x1f
1132if eq k 3
1133v = and b 0x0f
1134end
1135if eq k 4
1136v = and b 0x07
1137end
1138for i ulong sub k 1
1139v = or shl v 6 and ulong get pool add o add i 1 0x3f
1140end
1141ret v
1142end
1143fn isspc cp ulong to bool
1144if or and ge cp 9 le cp 13 and ge cp 28 le cp 32
1145ret true
1146end
1147if or or eq cp 0x85 eq cp 0xa0 or eq cp 0x1680 and ge cp 0x2000 le cp 0x200a
1148ret true
1149end
1150ret or or eq cp 0x2028 eq cp 0x2029 or or eq cp 0x202f eq cp 0x205f eq cp 0x3000
1151end
1152note text(v): a string that is not empty after Python str.strip()
1153fn vtext n long to bool
1154if lt n 0
1155ret false
1156end
1157if ne get nty n 3
1158ret false
1159end
1160o = get nvo n
1161e = add o get nvl n
1162while lt o e bound 999999
1163if not isspc cpat o
1164ret true
1165end
1166o = add o cplen o
1167end
1168ret false
1169end
1170fn ishexs n long k ulong to bool
1171if lt n 0
1172ret false
1173end
1174if ne get nty n 3
1175ret false
1176end
1177if ne get nvl n k
1178ret false
1179end
1180o = get nvo n
1181for i ulong k
1182c = long get pool add o i
1183if not or isdig c and ge c 97 le c 102
1184ret false
1185end
1186end
1187ret true
1188end
1189
1190note ---- Python repr() and str() of a JSON value, appended to the check line ----
1191text tnone "None"
1192text ttru "True"
1193text tfls "False"
1194fn npr cp ulong to bool
1195if or le cp 0xa0 eq cp 0xad
1196ret true
1197end
1198if or and ge cp 0xd800 le cp 0xf8ff or eq cp 0x1680 and ge cp 0x2000 le cp 0x200f
1199ret true
1200end
1201if or and ge cp 0x2028 le cp 0x202f or eq cp 0x205f and ge cp 0x2060 le cp 0x206f
1202ret true
1203end
1204ret or or eq cp 0x3000 eq cp 0xfeff and ge cp 0xfff9 le cp 0xfffb
1205end
1206fn rpcp cp ulong q ulong o ulong k ulong to void
1207if or eq cp q eq cp 92
1208lnb 92
1209lnb uchar cp
1210ret
1211end
1212if eq cp 9
1213lnb 92
1214lnb 116
1215ret
1216end
1217if eq cp 10
1218lnb 92
1219lnb 110
1220ret
1221end
1222if eq cp 13
1223lnb 92
1224lnb 114
1225ret
1226end
1227if and ge cp 32 lt cp 127
1228lnb uchar cp
1229ret
1230end
1231if and lt cp 128 or lt cp 32 eq cp 127
1232lnb 92
1233lnb 120
1234lnhex cp 2
1235ret
1236end
1237if npr cp
1238lnb 92
1239if le cp 0xff
1240lnb 120
1241lnhex cp 2
1242else
1243lnb 117
1244lnhex cp 4
1245end
1246ret
1247end
1248lnpool o k
1249end
1250fn rpstr o ulong n ulong to void
1251sq = false
1252dq = false
1253for i ulong n
1254b = get pool add o i
1255if eq b 39
1256sq = true
1257end
1258if eq b 34
1259dq = true
1260end
1261end
1262q = ulong 39
1263if and sq not dq
1264q = 34
1265end
1266lnb uchar q
1267i = ulong 0
1268while lt i n bound 999999
1269p = add o i
1270k = cplen p
1271rpcp cpat p q p k
1272i = add i k
1273end
1274lnb uchar q
1275end
1276fn rpnum n long to void
1277o = get nvo n
1278k = get nvl n
1279if eq get nty n 4
1280if eq k 2
1281if and eq get pool o 45 eq get pool add o 1 48
1282lnb 48
1283ret
1284end
1285end
1286end
1287lnpool o k
1288end
1289fn rpobj n long to void
1290lnb 123
1291c = ulong 0
1292j = get fch n
1293while ge j 0 bound 999999
1294u = ulong j
1295if eq get hfst u u
1296if gt c 0
1297lnb 44
1298lnb 32
1299end
1300rpstr get nko u get nkl u
1301lnb 58
1302lnb 32
1303prep long get hlst u
1304c = add c 1
1305end
1306j = get nxs u
1307end
1308lnb 125
1309end
1310fn rparr n long to void
1311lnb 91
1312j = get fch n
1313while ge j 0 bound 999999
1314if ne j get fch n
1315lnb 44
1316lnb 32
1317end
1318prep j
1319j = get nxs j
1320end
1321lnb 93
1322end
1323fn prep n long to void
1324if lt n 0
1325lnt tnone
1326ret
1327end
1328t = get nty n
1329if eq t 3
1330rpstr get nvo n get nvl n
1331ret
1332end
1333if eq t 5
1334lnt ttru
1335ret
1336end
1337if eq t 6
1338lnt tfls
1339ret
1340end
1341if eq t 7
1342lnt tnone
1343ret
1344end
1345if eq t 1
1346rpobj n
1347ret
1348end
1349if eq t 2
1350rparr n
1351ret
1352end
1353rpnum n
1354end
1355fn pstrv n long to void
1356if ge n 0
1357if eq get nty n 3
1358lnpool get nvo n get nvl n
1359ret
1360end
1361end
1362prep n
1363end
1364note the receipt (its live members only, as json.dumps sees the dict) names EMULATED anywhere
1365text temu "EMULATED"
1366note live: the member json.dumps would see, i.e. no later sibling has its key and its parent is live;
1367note parents come before children in the node table, so one forward pass fills liv
1368fn sayemu to bool
1369k = get gv NN
1370for j ulong k
1371p = get npa j
1372ok = true
1373if ge p 0
1374ok = eq get liv p 1
1375end
1376if ne get nkl j KNONE
1377if ne get hlst get hfst j j
1378ok = false
1379end
1380end
1381put liv j 0
1382if ok
1383put liv j 1
1384if ne get nkl j KNONE
1385if psub get nko j get nkl j temu
1386ret true
1387end
1388end
1389if eq get nty j 3
1390if psub get nvo j get nvl j temu
1391ret true
1392end
1393end
1394end
1395end
1396ret false
1397end
1398
1399note ---- paths: Python pathlib display (str(Path(arg))) and Path.with_suffix("") ----
1400fn nbb b uchar to void
1401k = get gv NBN
1402put nb k b
1403put gv NBN add k 1
1404end
1405note normalise ab[0..ABN) into nb: repeated slashes and "." parts dropped, "//" kept at the start
1406fn normp to void
1407n = get gv ABN
1408put gv NBN 0
1409pre = ulong 0
1410if gt n 0
1411if eq get ab 0 47
1412nbb 47
1413pre = 1
1414if gt n 1
1415if eq get ab 1 47
1416if or eq n 2 ne get ab 2 47
1417nbb 47
1418pre = 2
1419end
1420end
1421end
1422end
1423end
1424i = ulong 0
1425while lt i n bound 4097
1426if eq get ab i 47
1427i = add i 1
1428continue
1429end
1430j = i
1431while lt j n bound 4097
1432if eq get ab j 47
1433break
1434end
1435j = add j 1
1436end
1437dot = and eq sub j i 1 eq get ab i 46
1438if not dot
1439if gt get gv NBN pre
1440nbb 47
1441end
1442for k ulong sub j i
1443nbb get ab add i k
1444end
1445end
1446i = j
1447end
1448if eq get gv NBN 0
1449nbb 46
1450end
1451end
1452fn rdarg i ulong to void
1453r = argread i ab 0 4096
1454if lt r 0
1455exit 2
1456end
1457put gv ABN ulong r
1458normp
1459end
1460note start of the last path part of nb (the name); equal to NBN when the name is empty
1461fn namest to ulong
1462k = get gv NBN
1463if and eq k 1 eq get nb 0 46
1464ret 1
1465end
1466i = k
1467while gt i 0 bound 4097
1468if eq get nb sub i 1 47
1469ret i
1470end
1471i = sub i 1
1472end
1473ret 0
1474end
1475fn topth to void
1476k = get gv NBN
1477for i ulong k
1478put pth i get nb i
1479end
1480put gv PL k
1481end
1482fn toldr k ulong to void
1483for i ulong k
1484put ldr i get nb i
1485end
1486put gv DL k
1487end
1488note logdir default: the receipt path without its suffix (Python Path.suffix: 0 < rfind(".") < len-1)
1489fn dfltdir to void
1490k = get gv NBN
1491s = namest
1492c = k
1493i = k
1494while gt i s bound 4097
1495i = sub i 1
1496if eq get nb i 46
1497c = i
1498break
1499end
1500end
1501if or eq c k or eq c s eq c sub k 1
1502c = k
1503end
1504toldr c
1505end
1506note ---- tools/native pins: the first line exactly KEY= plus 64 lowercase hex ----
1507text tpin "PIN="
1508text tx86 "X86_PIN="
1509fn fhex p ulong to bool
1510c = long get fbuf p
1511ret or isdig c and ge c 97 le c 102
1512end
1513fn pinln s ulong e ulong t view uchar * to bool
1514k = len t
1515if ne sub e s add k 64
1516ret false
1517end
1518for i ulong k
1519if ne get fbuf add s i get t i
1520ret false
1521end
1522end
1523for i ulong 64
1524if not fhex add s add k i
1525ret false
1526end
1527end
1528ret true
1529end
1530text tnat "tools/native"
1531fn rdfile fd int to long
1532n = ulong 0
1533go = true
1534while go bound 999999
1535r = read fd fbuf n sub FCAP n
1536if lt r 0
1537ret r
1538end
1539if eq r 0
1540go = false
1541else
1542n = add n ulong r
1543if eq n FCAP
1544r2 = read fd fbuf n 1
1545if ne r2 0
1546ret -27
1547end
1548go = false
1549end
1550end
1551end
1552ret long n
1553end
1554fn natpins to void
1555put gv HX 0
1556put gv HB 0
1557fd = fopen tnat 0 len tnat 0 0
1558if lt fd 0
1559ret
1560end
1561n = rdfile int fd
1562c = fclose int fd
1563if lt n 0
1564ret
1565end
1566s = ulong 0
1567while lt s ulong n bound 999999
1568e = s
1569while lt e ulong n bound 999999
1570if eq get fbuf e 10
1571break
1572end
1573e = add e 1
1574end
1575if and eq get gv HX 0 pinln s e tx86
1576put gv HX 1
1577for i ulong 64
1578put pinb i get fbuf add s add 8 i
1579end
1580end
1581if and eq get gv HB 0 pinln s e tpin
1582put gv HB 1
1583for i ulong 64
1584put pinb add 64 i get fbuf add s add 4 i
1585end
1586end
1587s = add e 1
1588end
1589end
1590fn pineq n long base ulong to bool
1591if lt n 0
1592ret false
1593end
1594if ne get nty n 3
1595ret false
1596end
1597if ne get nvl n 64
1598ret false
1599end
1600o = get nvo n
1601for i ulong 64
1602if ne get pool add o i get pinb add base i
1603ret false
1604end
1605end
1606ret true
1607end
1608text tfpre "native-x86-physical-"
1609text tjson ".json"
1610fn fnameok to bool
1611k = get gv PL
1612s = k
1613while gt s 0 bound 4097
1614if eq get pth sub s 1 47
1615break
1616end
1617s = sub s 1
1618end
1619if eq k 1
1620if eq get pth 0 46
1621s = 1
1622end
1623end
1624if ne sub k s 33
1625ret false
1626end
1627for i ulong 20
1628if ne get pth add s i get tfpre i
1629ret false
1630end
1631end
1632for i ulong 8
1633if ne get pth add s add 20 i get pinb i
1634ret false
1635end
1636end
1637for i ulong 5
1638if ne get pth add s add 28 i get tjson i
1639ret false
1640end
1641end
1642ret true
1643end
1644
1645note ---- logs: open LOGDIR/NAME, require a regular file (Path.is_file), read it into fbuf ----
1646text tlog0 "x86-native.log"
1647text tlog1 "x86-native-controls.log"
1648text tlog2 "x86-native-wrongpin.log"
1649text tlog3 "x86-native-mut.log"
1650fn opb b uchar to void
1651k = get gv OPN
1652put opn k b
1653put gv OPN add k 1
1654end
1655fn opnam t view uchar * to void
1656put gv OPN 0
1657k = get gv DL
1658for i ulong k
1659opb get ldr i
1660end
1661opb 47
1662for i ulong len t
1663opb get t i
1664end
1665end
1666note returns the byte count, -1 when the path is not a regular file, -2 when larger than FCAP
1667fn rdlog t view uchar * to long
1668opnam t
1669fd = fopen opn 0 get gv OPN 2048 0
1670if lt fd 0
1671ret -1
1672end
1673st = new uchar 128 0
1674r = fstat int fd st 0 128
1675m = or uint get st 16 shl uint get st 17 8
1676if or lt r 0 ne and m 0xf000 0x8000
1677c = fclose int fd
1678ret -1
1679end
1680n = rdfile int fd
1681c2 = fclose int fd
1682if lt n 0
1683ret -2
1684end
1685ret n
1686end
1687note ---- line scan with Python str.splitlines() terminators ----
1688fn lend s ulong n ulong to ulong
1689e = s
1690while lt e n bound 999999
1691b = get fbuf e
1692put gv TL 1
1693if or eq b 10 eq b 13
1694if eq b 13
1695if lt add e 1 n
1696if eq get fbuf add e 1 10
1697put gv TL 2
1698end
1699end
1700end
1701ret e
1702end
1703if or or eq b 11 eq b 12 and ge b 28 le b 30
1704ret e
1705end
1706if and eq b 0xc2 lt add e 1 n
1707if eq get fbuf add e 1 0x85
1708put gv TL 2
1709ret e
1710end
1711end
1712if and eq b 0xe2 lt add e 2 n
1713if eq get fbuf add e 1 0x80
1714c = get fbuf add e 2
1715if or eq c 0xa8 eq c 0xa9
1716put gv TL 3
1717ret e
1718end
1719end
1720end
1721e = add e 1
1722end
1723put gv TL 0
1724ret n
1725end
1726fn fpre s ulong e ulong t view uchar * to bool
1727k = len t
1728if lt sub e s k
1729ret false
1730end
1731for i ulong k
1732if ne get fbuf add s i get t i
1733ret false
1734end
1735end
1736ret true
1737end
1738fn feq s ulong e ulong t view uchar * to bool
1739if ne sub e s len t
1740ret false
1741end
1742ret fpre s e t
1743end
1744fn xeq s ulong e ulong o ulong k ulong to bool
1745if ne sub e s k
1746ret false
1747end
1748for i ulong k
1749if ne get fbuf add s i get xp add o i
1750ret false
1751end
1752end
1753ret true
1754end
1755note substring search of t in fbuf[s..e)
1756fn fsubc a ulong b ulong e ulong t view uchar * to bool
1757p = a
1758while lt p b bound 999999
1759if fpre p e t
1760ret true
1761end
1762p = add p 1
1763end
1764ret false
1765end
1766fn fsub s ulong e ulong t view uchar * to bool
1767m = len t
1768if lt sub e s m
1769ret false
1770end
1771lst = add sub e m 1
1772a = s
1773while lt a lst bound 999999
1774b = add a 900000
1775if gt b lst
1776b = lst
1777end
1778if fsubc a b e t
1779ret true
1780end
1781a = b
1782end
1783ret false
1784end
1785text tvirt "INFO virtualization=none"
1786text thyp "INFO cpu hypervisor flag=no"
1787text tfln "FAIL "
1788text tctl "NATIVE-X86 CONTROLS PASS (NATIVE"
1789text tnpass "NATIVE-X86 NATIVE PASS "
1790text tvnone "virtualization=none"
1791fn sline s ulong e ulong to void
1792put gv LS s
1793put gv LE e
1794if feq s e tvirt
1795put gv FVIRT 1
1796end
1797if feq s e thyp
1798put gv FHYP 1
1799end
1800if fpre s e tfln
1801put gv FFAIL 1
1802end
1803if xeq s e 0 get gv E1
1804put gv FCPU 1
1805end
1806if xeq s e 1048576 get gv E2
1807put gv FKERN 1
1808end
1809end
1810fn kline s ulong e ulong kind ulong to void
1811if eq kind 0
1812sline s e
1813else
1814if fpre s e tctl
1815put gv FCTRL 1
1816end
1817end
1818end
1819note one pass over at most 900000 lines from s; returns where it stopped
1820fn lchunk s ulong n ulong kind ulong to ulong
1821p = s
1822c = ulong 0
1823while and lt p n lt c 900000 bound 999999
1824e = lend p n
1825kline p e kind
1826p = add e get gv TL
1827if eq get gv TL 0
1828p = n
1829end
1830c = add c 1
1831end
1832ret p
1833end
1834fn lscan n ulong kind ulong to void
1835p = ulong 0
1836while lt p n bound 999999
1837p = lchunk p n kind
1838end
1839end
1840
1841note ---- the checks, in the order and wording of the replaced Python checker ----
1842text tusage "usage: check_physical_receipt RECEIPT.json [LOGDIR] (run from the repository root)\n"
1843text trdj "receipt is readable JSON ("
1844text terrno "open or read failed: errno "
1845text tbig "larger than 900000 bytes"
1846text tutf "not UTF-8 at byte "
1847text tbad "invalid JSON near byte "
1848text tobj "receipt is a JSON object"
1849fn rdfail t view uchar * v ulong hasv bool to int
1850put gv LN 0
1851lnt trdj
1852lnt t
1853if hasv
1854lndec v
1855end
1856lnb 41
1857emit false
1858ret finish
1859end
1860note returns -1 when the receipt parsed (node 0 is the top value), else the finish status
1861fn rdrcp to int
1862fd = fopen pth 0 get gv PL 0 0
1863if lt fd 0
1864ret rdfail terrno ulong neg fd true
1865end
1866n = ulong 0
1867go = true
1868while go bound 999999
1869r = read int fd rcp n sub 1048576 n
1870if lt r 0
1871c = fclose int fd
1872ret rdfail terrno ulong neg r true
1873end
1874if eq r 0
1875go = false
1876end
1877n = add n ulong r
1878if gt n RCAP
1879c2 = fclose int fd
1880ret rdfail tbig 0 false
1881end
1882end
1883c3 = fclose int fd
1884put gv RL n
1885u = utf8ok
1886if ge u 0
1887ret rdfail tutf ulong u true
1888end
1889put gv PO 0
1890ok = pval -1 0 KNONE 0 0
1891skipws
1892if or not ok ne get gv PO n
1893ret rdfail tbad get gv PO true
1894end
1895ret -1
1896end
1897text tsch "schema is 1"
1898text tsch2 "schema"
1899text tlab "label is PHYSICAL (got "
1900text tlabk "label"
1901text tphys "PHYSICAL"
1902text tsta "status is NATIVE_PASS (got "
1903text tstak "status"
1904text tnp "NATIVE_PASS"
1905text tnx "native_x86 is PASS (got "
1906text tnxk "native_x86"
1907text tpassv "PASS"
1908text tnoemu "receipt nowhere says EMULATED"
1909text tbc "bridge_commit is a full sha"
1910text tbck "bridge_commit"
1911text txo "x86_omc_sha256 is the tools/native X86_PIN"
1912text txok "x86_omc_sha256"
1913text tbo "baseline_omc_sha256 is the tools/native PIN"
1914text tbok "baseline_omc_sha256"
1915text tfn "file name carries the x86 pin prefix"
1916text tgotc ")"
1917fn gotchk t view uchar * v long want view uchar * to void
1918put gv LN 0
1919lnt t
1920prep v
1921lnb 41
1922emit vstr v want
1923end
1924fn chktop to void
1925r = long 0
1926put gv LN 0
1927chk tsch numis dget r tsch2 1
1928gotchk tlab dget r tlabk tphys
1929gotchk tsta dget r tstak tnp
1930gotchk tnx dget r tnxk tpassv
1931chk tnoemu not sayemu
1932chk tbc ishexs dget r tbck 40
1933hx = eq get gv HX 1
1934chk txo and hx pineq dget r txok 0
1935chk tbo and eq get gv HB 1 pineq dget r tbok 64
1936chk tfn and hx fnameok
1937end
1938text thost "host"
1939text tvirtk "virtualization"
1940text thv "host.virtualization is none (got "
1941text tnone2 "none"
1942text thf "host.hypervisor_flag is no (got "
1943text thfk "hypervisor_flag"
1944text tno "no"
1945text tcpu "host.cpu_model is recorded"
1946text tcpuk "cpu_model"
1947text tker "host.kernel is recorded"
1948text tkerk "kernel"
1949text tos "host.os is recorded"
1950text tosk "os"
1951text tbin "binfmt_qemu_aarch64"
1952text tbiv "host.binfmt_qemu_aarch64 interpreter and version recorded"
1953text tbis "host.binfmt_qemu_aarch64 sha256 recorded"
1954text tinter "interpreter"
1955text tver "version"
1956text tsha "sha256"
1957fn objor n long to long
1958if isobj n
1959ret n
1960end
1961ret -1
1962end
1963fn chkhost to long
1964h = objor dget long 0 thost
1965gotchk thv dget h tvirtk tnone2
1966gotchk thf dget h thfk tno
1967chk tcpu vtext dget h tcpuk
1968chk tker vtext dget h tkerk
1969chk tos vtext dget h tosk
1970b = objor dget h tbin
1971chk tbiv and vtext dget b tinter vtext dget b tver
1972chk tbis ishexs dget b tsha 64
1973ret h
1974end
1975text ttools "toolchains"
1976text ttc "toolchains."
1977text tvrec " version recorded"
1978text tgcc "gcc"
1979text tgpp "g++"
1980text trustc "rustc"
1981text tzig "zig"
1982text tgo "go"
1983text tpy "python"
1984fn chktc t long name view uchar * to void
1985put gv LN 0
1986lnt ttc
1987lnt name
1988lnt tvrec
1989emit vtext dget t name
1990end
1991fn chktools to void
1992t = objor dget long 0 ttools
1993chktc t tgcc
1994chktc t tgpp
1995chktc t trustc
1996chktc t tzig
1997chktc t tgo
1998chktc t tpy
1999end
2000text tcmds "commands"
2001text tfour "four runbook commands recorded (got "
2002text tcmd "command "
2003text tisrb " is the runbook command ("
2004text texit " exit is "
2005text tgot " (got "
2006text tresn " result names "
2007text tcmdk "command"
2008text texitk "exit"
2009text tresk "result"
2010text tn1 "OMEGA_NATIVE_X86_EXEC=native sh tests/native/x86/run.sh"
2011text tn2 "OMEGA_NATIVE_X86_EXEC=native python3 tests/native/x86/test_build_failures.py"
2012text tn3 "OMEGA_NATIVE_X86_OMC="
2013text tn4 "tools/native --target x86linux"
2014text tr1 "NATIVE-X86 NATIVE PASS"
2015text tr2 "NATIVE-X86 CONTROLS PASS"
2016text tr3 "FAIL x86 compiler pin"
2017text tr4 "refused"
2018fn chkcmd c long i ulong nd view uchar * res view uchar * to void
2019code = ulong 0
2020if ge i 2
2021code = 1
2022end
2023e = objor aget c i
2024put gv LN 0
2025lnt tcmd
2026lndec add i 1
2027lnt tisrb
2028lnt nd
2029lnb 41
2030emit vsub dget e tcmdk nd
2031put gv LN 0
2032lnt tcmd
2033lndec add i 1
2034lnt texit
2035lndec code
2036lnt tgot
2037x = dget e texitk
2038prep x
2039lnb 41
2040emit numis x code
2041put gv LN 0
2042lnt tcmd
2043lndec add i 1
2044lnt tresn
2045lnt res
2046emit vsub dget e tresk res
2047end
2048fn chkcmds to void
2049c = dget long 0 tcmds
2050if lt c 0
2051c = -1
2052else
2053if ne get nty c 2
2054c = -1
2055end
2056end
2057k = nch c
2058put gv LN 0
2059lnt tfour
2060lndec k
2061lnb 41
2062emit eq k 4
2063chkcmd c 0 tn1 tr1
2064chkcmd c 1 tn2 tr2
2065chkcmd c 2 tn3 tr3
2066chkcmd c 3 tn4 tr4
2067end
2068text tlg "log "
2069text tpres " present in "
2070text tsham " sha256 matches receipt"
2071text tlogs "logs_sha256"
2072fn chklog h long t view uchar * to long
2073put gv LN 0
2074lnt tlg
2075lnt t
2076lnt tpres
2077k = get gv DL
2078for i ulong k
2079lnb get ldr i
2080end
2081n = rdlog t
2082emit ne n -1
2083if eq n -1
2084ret -1
2085end
2086ok = false
2087if ge n 0
2088shafbuf ulong n
2089x = dget h t
2090if ge x 0
2091if eq get nty x 3
2092if eq get nvl x 64
2093ok = true
2094o = get nvo x
2095for i ulong 64
2096if ne get pool add o i get hexo i
2097ok = false
2098end
2099end
2100end
2101end
2102end
2103end
2104put gv LN 0
2105lnt tlg
2106lnt t
2107lnt tsham
2108emit ok
2109if lt n 0
2110ret 0
2111end
2112ret n
2113end
2114note expected suite lines "INFO cpu model=" + str(host.cpu_model) and "INFO kernel=" + str(host.kernel)
2115text tem1 "INFO cpu model="
2116text tem2 "INFO kernel="
2117fn mkexp h long to void
2118put gv LN 0
2119lnt tem1
2120pstrv dget h tcpuk
2121k = get gv LN
2122for i ulong k
2123put xp i get ln i
2124end
2125put gv E1 k
2126put gv LN 0
2127lnt tem2
2128pstrv dget h tkerk
2129k2 = get gv LN
2130for i ulong k2
2131put xp add 1048576 i get ln i
2132end
2133put gv E2 k2
2134put gv LN 0
2135end
2136text tsl1 "suite log ends with the NATIVE PASS line"
2137text tsl2 "suite log never ran EMULATED"
2138text tsl3 "suite log shows virtualization=none"
2139text tsl4 "suite log shows hypervisor flag clear"
2140text tsl5 "suite log has no FAIL line"
2141text tsl6 "suite log cpu model matches receipt"
2142text tsl7 "suite log kernel matches receipt"
2143text tcl "controls log reports NATIVE CONTROLS PASS"
2144text twp "wrong-pin log refuses the x86 compiler pin"
2145text tmu "mutated-compiler log is refused by tools/native"
2146text twpn "NATIVE-X86 FAIL x86 compiler pin"
2147text tmun "tools/native: x86 omc sha256"
2148fn fg i ulong to bool
2149ret eq get gv i 1
2150end
2151fn suitefx n long to void
2152if le n 0
2153ret
2154end
2155k = ulong n
2156if fsub 0 k temu
2157put gv FEMU 1
2158end
2159put gv LS 0
2160put gv LE 0
2161put gv FLAST 2
2162lscan k 0
2163s = get gv LS
2164e = get gv LE
2165if and fpre s e tnpass fsub s e tvnone
2166put gv FLAST 1
2167end
2168end
2169fn chklogs h long to void
2170l = objor dget long 0 tlogs
2171n0 = chklog l tlog0
2172suitefx n0
2173n1 = chklog l tlog1
2174if gt n1 0
2175lscan ulong n1 1
2176end
2177n2 = chklog l tlog2
2178if gt n2 0
2179if fsub 0 ulong n2 twpn
2180put gv FWRONG 1
2181end
2182end
2183n3 = chklog l tlog3
2184if gt n3 0
2185if fsub 0 ulong n3 tmun
2186put gv FMUT 1
2187end
2188end
2189chk tsl1 fg FLAST
2190chk tsl2 not fg FEMU
2191chk tsl3 fg FVIRT
2192chk tsl4 fg FHYP
2193chk tsl5 not fg FFAIL
2194chk tsl6 fg FCPU
2195chk tsl7 fg FKERN
2196chk tcl fg FCTRL
2197chk twp fg FWRONG
2198chk tmu fg FMUT
2199end
2200fn main to int
2201c = argcnt
2202if or lt c 2 gt c 3
2203w = write 2 tusage 0 len tusage
2204ret 2
2205end
2206rdarg 1
2207topth
2208if eq c 3
2209rdarg 2
2210toldr get gv NBN
2211else
2212rdarg 1
2213dfltdir
2214end
2215r = rdrcp
2216if ge r 0
2217ret r
2218end
2219put gv LN 0
2220ob = isobj 0
2221chk tobj ob
2222if not ob
2223ret finish
2224end
2225natpins
2226chktop
2227h = chkhost
2228chktools
2229chkcmds
2230mkexp h
2231chklogs h
2232ret finish
2233end