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 / amd / gate.om

1053 lines · 19735 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/amd/gate.om: OMEGA-GPU-AMD, the gate of the AMD gfx942 back end, in seeded Omega (Linux AArch64).
3note Build from the repository root (OM-2 program mode; seed/ng/sha256.om supplies sh_dat, sh_all, sh_dig):
4note { printf 'om2\n'; cat seed/ng/sha256.om gpu/amd/gate.om; } | seed/out/omc > gate
5note Run from the repository root: gate OMC SCRATCH
6note OMC the compiler under test; its sha256 must equal the first word of seed/out/omc.sha256, or nothing
7note runs (exit 69, nothing written)
8note SCRATCH a new directory (created 0700), at most 1024 bytes of path; an existing one is refused (exit 2)
9note 1. Units. Each row of g_units is composed from its sources in order (+om2 is the line "om2", +x86 the line
10note "target x86linux", PATH! is PATH up to its line "fn main to int") into SCRATCH/NAME.om and compiled twice
11note by OMC: each compile exits 0 with empty stderr, and both binaries hold the same bytes.
12note 2. Card bytes. gpu/amd/card.tsv: "obj NAME SHA" is the object the code-object writer (unit hsaco) makes from
13note gpu/amd/gfx942/NAME.isa and "bin NAME SHA" the binary of unit NAME, both run on the MI300X; "host NAME SHA"
14note is a unit's binary recorded on the host and never run on the card (printed as a reference). Each must hash
15note to SHA. Each object must also pass the portable loader check: unit targets, `targets load AMDGPU_HSACO FILE
16note gfx942`, exit 0. A card with no obj or no bin row, or a malformed row, fails.
17note 3. Controls, each must be caught: a compiler one byte longer fails the digest check; embed5120_step.isa with
18note one kernel-descriptor word changed (0xaf0103 to 0xaf0102) does not give the card bytes; a missing table is
19note refused by the writer.
20note Output: one line per check, then OMEGA-GPU-AMD PASS|FAIL units=U objects=O binaries=B references=R controls=C
21note caught=K hardware=NOT_RUN. Exit 0 PASS, 1 FAIL, 2 bad usage or setup, 69 compiler digest refused. Every input
22note is length-checked; a trap exit (101..114) would be a defect of this gate, never a pass.
23note This gate opens no device; every hardware row stays NOT_RUN. Results on hardware carry over to this tree
24note only through the byte identity checked in step 2.
25text g_units "hsaco gpu/amd/gfx942/hsaco.om|targets gpu/targets.om|exec gpu/amd/gfx942/exec/fp.om gpu/amd/gfx942/exec/fma.om gpu/amd/gfx942/exec/main.om|rope gpu/amd/gfx942/rope.om|aql gpu/amd/kfd/aql.om gpu/amd/kfd/cli.om|kernarg gpu/amd/kfd/kernarg.om gpu/amd/kfd/cli.om|records gpu/amd/kfd/records.om gpu/amd/kfd/cli.om|ring gpu/amd/kfd/ring.om gpu/amd/kfd/cli.om|launch-a64 +om2 gpu/amd/kfd/launch/common.om gpu/amd/kfd/launch/elf.om gpu/amd/kfd/launch/device.om gpu/amd/kfd/launch/dispatch.om gpu/amd/kfd/launch/plan.om gpu/amd/kfd/launch/main.om gpu/amd/kfd/cli.om|launch-x86 +x86 +om2 gpu/amd/kfd/launch/common.om gpu/amd/kfd/launch/elf.om gpu/amd/kfd/launch/device.om gpu/amd/kfd/launch/dispatch.om gpu/amd/kfd/launch/plan.om gpu/amd/kfd/launch/main.om gpu/amd/kfd/cli.om|semantics-probe gpu/amd/gfx942/exec/fp.om gpu/amd/gfx942/exec/fma.om gpu/amd/gfx942/exec/main.om! gpu/amd/tests/amd-exec/semantics-probe.om|row-probe gpu/amd/gfx942/exec/fp.om gpu/amd/gfx942/exec/fma.om gpu/amd/gfx942/exec/main.om! gpu/amd/tests/amd-exec/row-probe.om|fma-probe +om2 gpu/amd/gfx942/exec/fma.om gpu/amd/tests/amd-exec/fma-probe.om|trans-probe gpu/amd/gfx942/exec/fp.om gpu/amd/tests/amd-exec/trans-probe.om|ropefreq-probe gpu/amd/gfx942/rope.om! gpu/amd/tests/amd-exec/ropefreq-probe.om"
26text t_pin "seed/out/omc.sha256"
27text t_card "gpu/amd/card.tsv"
28text t_isa "gpu/amd/gfx942/"
29text t_isx ".isa"
30text t_om ".om"
31text t_b1 ".1"
32text t_b2 ".2"
33text t_e1 ".1.err"
34text t_e2 ".2.err"
35text t_hs ".hsaco"
36text t_hse ".hsaco.err"
37text t_ld ".load"
38text t_lde ".load.err"
39text t_null "/dev/null"
40text t_hsaco "hsaco"
41text t_tgts "targets"
42text t_load "load"
43text t_fmt "AMDGPU_HSACO"
44text t_gfx "gfx942"
45text t_acc "LOAD ACCEPT "
46text t_om2 "om2\n"
47text t_x86 "target x86linux\n"
48text t_main "fn main to int"
49text t_plus "omc-plus-one"
50text t_chg "changed"
51text t_mis "missing"
52text t_e5 "embed5120_step"
53text t_kdw "0xaf0103"
54text t_usage "usage: gate OMC SCRATCH (run from the omega-mv repository root)\n"
55text t_refd "OMEGA-GPU-AMD REFUSED: compiler digest differs from seed/out/omc.sha256 (exit 69)\n"
56text t_nopin "OMEGA-GPU-AMD INVALID: cannot read a 64-hex digest from seed/out/omc.sha256\n"
57text t_noscr "OMEGA-GPU-AMD INVALID: SCRATCH exists or cannot be made\n"
58text t_nocard "OMEGA-GPU-AMD INVALID: cannot read gpu/amd/card.tsv\n"
59text t_ok "ok "
60text t_fail "FAIL "
61text t_unit "unit "
62text t_obj "object "
63text t_bin "binary "
64text t_ref "reference "
65text t_kobj "obj"
66text t_kbin "bin"
67text t_khost "host"
68text t_sr " references="
69text t_long "OMEGA-GPU-AMD INVALID: SCRATCH path longer than 1024 bytes\n"
70text t_ctl "control "
71text t_bytes " bytes="
72text t_sha " sha256="
73text t_want " want="
74text t_exit " exit="
75text t_src "source unreadable: "
76text t_big "output unreadable or over 16 MiB"
77text t_cmp "compile"
78text t_stderr " stderr not empty"
79text t_twice " two builds differ"
80text t_write "cannot write "
81text t_kind "card.tsv: malformed row or unknown kind"
82text t_empty "card.tsv names no obj row or no bin row: it proves nothing"
83text t_ldr " loader check failed"
84text t_caught " caught"
85text t_esc " ESCAPED"
86text t_noapp " not applied"
87text t_sum "OMEGA-GPU-AMD "
88text t_pass "PASS"
89text t_fl "FAIL"
90text t_su " units="
91text t_so " objects="
92text t_sb " binaries="
93text t_sc " controls="
94text t_sk " caught="
95text t_hw " hardware=NOT_RUN\n"
96global g_pa uchar 4096
97global g_scr uchar 4096
98global g_omc uchar 4096
99global g_nm uchar 256
100global g_av uchar 8192
101global g_b uchar 16777216
102global g_c uchar 1048576
103global g_o uchar 8192
104global g_hx uchar 64
105global g_pin uchar 64
106global g_d1 uchar 32
107global g_stb uchar 4
108global g_n ulong 32
109note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 output length,
110note 6 buffer length, 7 card length, 8 units, 9 objects, 10 binaries, 11 failures, 12 controls, 13 caught,
111note 14 name length, 15 row cursor, 16 obj rows, 17 bin rows, 18 host references
112note ---- output
113fn oc c ulong to void
114n = get g_n 5
115put g_o n uchar c
116put g_n 5 add n 1
117end
118fn ot t view uchar * to void
119for i ulong len t bound 4096
120oc ulong get t i
121end
122end
123fn onm to void
124for i ulong get g_n 14 bound 256
125oc ulong get g_nm i
126end
127end
128fn onum v ulong to void
129if ge v 10
130onum div v 10
131end
132oc add 48 rem v 10
133end
134fn ohex to void
135for j ulong 32
136b = get sh_dig j
137oc ulong sh_hexd uint shr b 4
138oc ulong sh_hexd uint and b 15
139end
140end
141fn ohx to void
142for j ulong 64
143oc ulong get g_hx j
144end
145end
146fn oflush to void
147r = write 1 g_o 0 get g_n 5
148put g_n 5 0
149end
150fn onl to void
151oc 10
152oflush
153end
154note a failed check: FAIL KIND NAME then the reason; counts a failure
155fn ofail kind view uchar * why view uchar * to void
156ot t_fail
157ot kind
158onm
159oc 32
160ot why
161onl
162put g_n 11 add get g_n 11 1
163end
164note ---- paths: g_pa[0, g_n 0)
165fn pclr to void
166put g_n 0 0
167end
168fn pc c ulong to void
169n = get g_n 0
170put g_pa n uchar c
171put g_n 0 add n 1
172end
173fn pt t view uchar * to void
174for i ulong len t bound 4096
175pc ulong get t i
176end
177end
178fn pscr to void
179for j ulong get g_n 2 bound 4096
180pc ulong get g_scr j
181end
182end
183fn pnm to void
184for j ulong get g_n 14 bound 256
185pc ulong get g_nm j
186end
187end
188note scratch file NAME then suffix
189fn psn suf view uchar * to void
190pclr
191pscr
192pnm
193pt suf
194end
195note scratch file named by a text
196fn pst t view uchar * suf view uchar * to void
197pclr
198pscr
199pt t
200pt suf
201end
202note scratch file named by a text alone
203fn psc t view uchar * to void
204pclr
205pscr
206pt t
207end
208fn nmset t view uchar * to void
209for i ulong len t bound 256
210put g_nm i get t i
211end
212put g_n 14 len t
213end
214note ---- files
215fn fopn fl ulong mode ulong to int
216r = fopen g_pa 0 get g_n 0 int fl int mode
217if lt r 0
218ret -1
219end
220ret int r
221end
222fn frd to int
223ret fopn 524288 0
224end
225fn fwr to int
226ret fopn 524865 420
227end
228fn fexe to int
229r = unlink g_pa 0 get g_n 0
230ret fopn 524865 448
231end
232fn fclo fd int to void
233if ge fd 0
234r = fclose fd
235end
236end
237note append the file at g_pa to g_b; false when unreadable or past the buffer
238fn bload to bool
239fd = frd
240if lt fd 0
241ret false
242end
243n = get g_n 6
244ok = true
245while true bound 16777218
246x = read fd g_b n sub len g_b n
247if lt x 0
248ok = false
249break
250end
251if eq x 0
252break
253end
254n = add n ulong x
255if ge n len g_b
256ok = false
257break
258end
259end
260fclo fd
261put g_n 6 n
262ret ok
263end
264note write g_b[0, g_n 6) to the file at g_pa (0644, or 0700 when exe)
265fn bsave exe bool to bool
266fd = int -1
267if exe
268fd = fexe
269else
270fd = fwr
271end
272if lt fd 0
273ret false
274end
275n = get g_n 6
276o = ulong 0
277ok = true
278while lt o n bound 16777217
279x = write fd g_b o sub n o
280if le x 0
281ok = false
282break
283end
284o = add o ulong x
285end
286fclo fd
287ret ok
288end
289note sha256 of the file at g_pa into sh_dig; false when unreadable or past 16 MiB
290fn fhash to bool
291fd = frd
292if lt fd 0
293ret false
294end
295n = ulong 0
296ok = true
297while true bound 16777218
298x = read fd sh_dat n sub len sh_dat n
299if lt x 0
300ok = false
301break
302end
303if eq x 0
304break
305end
306n = add n ulong x
307if ge n len sh_dat
308ok = false
309break
310end
311end
312fclo fd
313if not ok
314ret false
315end
316sh_all n
317ret true
318end
319note the size of the file at g_pa, or 2^63 when unreadable
320fn fsize to ulong
321put g_n 6 0
322if not bload
323ret shl ulong 1 63
324end
325ret get g_n 6
326end
327note sh_dig equals the hex in g_hx
328fn digeq to bool
329for j ulong 32
330b = get sh_dig j
331if ne get g_hx mul j 2 sh_hexd uint shr b 4
332ret false
333end
334if ne get g_hx add mul j 2 1 sh_hexd uint and b 15
335ret false
336end
337end
338ret true
339end
340fn dsave to void
341for j ulong 32
342put g_d1 j get sh_dig j
343end
344end
345fn dsame to bool
346for j ulong 32
347if ne get g_d1 j get sh_dig j
348ret false
349end
350end
351ret true
352end
353note ---- processes
354fn aclr to void
355put g_n 3 2
356put g_n 4 0
357put g_av 0 0
358put g_av 1 0
359end
360note append g_pa as one argument
361fn apa to void
362p = get g_n 3
363n = get g_n 0
364for j ulong n bound 4096
365put g_av add add p 2 j get g_pa j
366end
367put g_av p uchar and n 255
368put g_av add p 1 uchar shr n 8
369put g_n 3 add p add n 2
370c = add get g_n 4 1
371put g_n 4 c
372put g_av 0 uchar and c 255
373put g_av 1 uchar shr c 8
374end
375fn atx t view uchar * to void
376pclr
377pt t
378apa
379end
380fn redir s int d int to void
381if ne dupfd s d 0 long d
382exit 127
383end
384end
385note run the argument list with stdin, stdout, stderr fds (closed here): the exit code, 256 + the signal, 512
386note when a file could not be opened, 1000 when the child passed the 600 s deadline (killed)
387fn spawn fi int fo int fe int to ulong
388if or lt fi 0 or lt fo 0 lt fe 0
389fclo fi
390fclo fo
391fclo fe
392ret 512
393end
394pid = fork
395if lt pid 0
396exit 2
397end
398if eq pid 0
399redir fi 0
400redir fo 1
401redir fe 2
402r = execprog g_av 0 get g_n 3
403exit 127
404end
405fclo fi
406fclo fo
407fclo fe
408t0 = monons
409while true bound 1000000000
410r = waitpid int pid g_stb 0 len g_stb 1
411if eq r pid
412x = ulong get g_stb 0
413if ne x 0
414ret add 256 x
415end
416ret ulong get g_stb 1
417end
418if lt r 0
419exit 2
420end
421if gt sub monons t0 600000000000
422r = killpid int pid 9
423r = waitpid int pid g_stb 0 len g_stb 0
424ret 1000
425end
426q = sleepns 200000
427end
428exit 2
429end
430note OMC < SCRATCH/NAME.om > SCRATCH/NAME.SUF 2> SCRATCH/NAME.ERR
431fn omc suf view uchar * err view uchar * to ulong
432psn t_om
433fi = frd
434aclr
435pclr
436for j ulong get g_n 1 bound 4096
437pc ulong get g_omc j
438end
439apa
440psn suf
441fo = fexe
442psn err
443fe = fwr
444ret spawn fi fo fe
445end
446note ---- the compiler digest
447note the first 64 characters of seed/out/omc.sha256 into g_pin; false unless lowercase hex
448fn pinread to bool
449pclr
450pt t_pin
451put g_n 6 0
452if not bload
453ret false
454end
455if lt get g_n 6 64
456ret false
457end
458for j ulong 64
459c = get g_b j
460ok = or and ge c 48 le c 57 and ge c 97 le c 102
461if not ok
462ret false
463end
464put g_pin j c
465end
466ret true
467end
468note the file at g_pa hashes to g_pin
469fn pinok to bool
470if not fhash
471ret false
472end
473for j ulong 64
474put g_hx j get g_pin j
475end
476ret digeq
477end
478note ---- units
479note compose unit row [s, e) of g_units into g_b; false (reported) when a source is unreadable
480fn compose s ulong e ulong to bool
481put g_n 6 0
482i = s
483while lt i e bound 4096
484while uis i e 32 bound 4096
485i = add i 1
486end
487if ge i e
488break
489end
490j = i
491while uisnt j e 32 bound 4096
492j = add j 1
493end
494if eq get g_units i 43
495if eq get g_units add i 1 120
496lit t_x86
497else
498lit t_om2
499end
500else
501cut = eq get g_units sub j 1 33
502k = j
503if cut
504k = sub j 1
505end
506pclr
507for q ulong sub k i bound 4096
508pc ulong get g_units add i q
509end
510st = get g_n 6
511if not bload
512pnm2
513ofail t_unit t_src
514ret false
515end
516if cut
517mcut st
518end
519end
520i = j
521end
522ret true
523end
524note print the path in g_pa after a failure line's text (used for unreadable sources)
525fn pnm2 to void
526for q ulong get g_n 0 bound 4096
527put g_nm q get g_pa q
528end
529put g_n 14 get g_n 0
530end
531fn lit t view uchar * to void
532n = get g_n 6
533for q ulong len t bound 64
534put g_b add n q get t q
535end
536put g_n 6 add n len t
537end
538note cut g_b at the first line, at or after st, that starts with "fn main to int"
539fn mcut st ulong to void
540n = get g_n 6
541p = st
542while lt p n bound 16777216
543if mline p n
544put g_n 6 p
545ret
546end
547while and lt p n ne get g_b p 10 bound 16777216
548p = add p 1
549end
550p = add p 1
551end
552end
553fn mline p ulong n ulong to bool
554if gt add p len t_main n
555ret false
556end
557for q ulong len t_main
558if ne get g_b add p q get t_main q
559ret false
560end
561end
562ret true
563end
564note compile the composed unit twice; true when both exit 0 with empty stderr and equal bytes
565fn build to bool
566psn t_om
567if not bsave false
568ofail t_unit t_write
569ret false
570end
571r1 = omc t_b1 t_e1
572r2 = omc t_b2 t_e2
573if or ne r1 0 ne r2 0
574ot t_fail
575ot t_unit
576onm
577oc 32
578ot t_cmp
579ot t_exit
580onum r1
581oc 47
582onum r2
583onl
584put g_n 11 add get g_n 11 1
585ret false
586end
587psn t_e1
588s1 = fsize
589psn t_e2
590s2 = fsize
591if or ne s1 0 ne s2 0
592ofail t_unit t_stderr
593ret false
594end
595psn t_b1
596if not fhash
597ofail t_unit t_big
598ret false
599end
600dsave
601psn t_b2
602if not fhash
603ofail t_unit t_big
604ret false
605end
606if not dsame
607ofail t_unit t_twice
608ret false
609end
610psn t_b1
611sz = fsize
612psn t_b1
613z = fhash
614ot t_ok
615ot t_unit
616onm
617ot t_bytes
618onum sz
619ot t_sha
620ohex
621onl
622put g_n 8 add get g_n 8 1
623ret true
624end
625fn units to void
626n = len g_units
627s = ulong 0
628while lt s n bound 4096
629e = s
630while uisnt e n 124 bound 65536
631e = add e 1
632end
633k = s
634while uisnt k e 32 bound 256
635k = add k 1
636end
637for q ulong sub k s bound 256
638put g_nm q get g_units add s q
639end
640put g_n 14 sub k s
641if compose k e
642z = build
643end
644s = add e 1
645end
646end
647note g_units[i] is c, for i below e (never reads at or past e)
648fn uis i ulong e ulong c ulong to bool
649if ge i e
650ret false
651end
652ret eq ulong get g_units i c
653end
654fn uisnt i ulong e ulong c ulong to bool
655if ge i e
656ret false
657end
658ret ne ulong get g_units i c
659end
660note ---- card bytes
661note SCRATCH/hsaco.1 TABLE > SCRATCH/NAME.hsaco: TABLE is gpu/amd/gfx942/NAME.isa (tbl 0) or SCRATCH/NAME.isa
662fn wrun tbl ulong to ulong
663aclr
664pst t_hsaco t_b1
665apa
666pclr
667if eq tbl 0
668pt t_isa
669pnm
670pt t_isx
671else
672pscr
673pnm
674pt t_isx
675end
676apa
677pclr
678pt t_null
679fi = frd
680psn t_hs
681fo = fwr
682psn t_hse
683fe = fwr
684ret spawn fi fo fe
685end
686fn loadok to bool
687aclr
688pst t_tgts t_b1
689apa
690atx t_load
691atx t_fmt
692psn t_hs
693apa
694atx t_gfx
695pclr
696pt t_null
697fi = frd
698psn t_ld
699fo = fwr
700psn t_lde
701fe = fwr
702r = spawn fi fo fe
703if ne r 0
704ret false
705end
706psn t_ld
707put g_n 6 0
708if not bload
709ret false
710end
711if lt get g_n 6 len t_acc
712ret false
713end
714for q ulong len t_acc
715if ne get g_b q get t_acc q
716ret false
717end
718end
719ret true
720end
721fn cobj to void
722r = wrun 0
723if ne r 0
724ot t_fail
725ot t_obj
726onm
727ot t_exit
728onum r
729onl
730put g_n 11 add get g_n 11 1
731ret
732end
733psn t_hs
734if not fhash
735ofail t_obj t_big
736ret
737end
738if not digeq
739ot t_fail
740ot t_obj
741onm
742ot t_sha
743ohex
744ot t_want
745ohx
746onl
747put g_n 11 add get g_n 11 1
748ret
749end
750if not loadok
751ofail t_obj t_ldr
752ret
753end
754ot t_ok
755ot t_obj
756onm
757ot t_sha
758ohex
759onl
760put g_n 9 add get g_n 9 1
761end
762note a binary row: card-proven (host false, counted in g_n 10) or a host-built reference (host true, g_n 18)
763fn cbin host bool to void
764psn t_b1
765if not fhash
766ofail t_bin t_big
767ret
768end
769if not digeq
770ot t_fail
771ot t_bin
772onm
773ot t_sha
774ohex
775ot t_want
776ohx
777onl
778put g_n 11 add get g_n 11 1
779ret
780end
781ot t_ok
782if host
783ot t_ref
784else
785ot t_bin
786end
787onm
788ot t_sha
789ohex
790onl
791if host
792put g_n 18 add get g_n 18 1
793else
794put g_n 10 add get g_n 10 1
795end
796end
797note g_c[s, k) is the word t
798fn kword s ulong k ulong t view uchar * to bool
799if ne sub k s len t
800ret false
801end
802for q ulong len t bound 8
803if ne get g_c add s q get t q
804ret false
805end
806end
807ret true
808end
809note one card.tsv row [s, e): KIND NAME SHA, single spaces; # starts a comment line. KIND is obj, bin or host;
810note NAME is 1 to 255 bytes; SHA is 64 lowercase hex. Anything else is a FAIL line, never a trap.
811fn crow s ulong e ulong to void
812if or eq s e eq get g_c s 35
813ret
814end
815put g_n 14 0
816k = s
817while and lt k e ne get g_c k 32 bound 1048576
818k = add k 1
819end
820if ge k e
821ofail t_obj t_kind
822ret
823end
824a = add k 1
825b = a
826while and lt b e ne get g_c b 32 bound 1048576
827b = add b 1
828end
829if or ge b e or eq b a gt sub b a 255
830ofail t_obj t_kind
831ret
832end
833for q ulong sub b a bound 256
834put g_nm q get g_c add a q
835end
836put g_n 14 sub b a
837if ne sub e add b 1 64
838ofail t_obj t_kind
839ret
840end
841for q ulong 64
842put g_hx q get g_c add add b 1 q
843end
844if kword s k t_kobj
845put g_n 16 add get g_n 16 1
846cobj
847ret
848end
849if kword s k t_kbin
850put g_n 17 add get g_n 17 1
851cbin false
852ret
853end
854if kword s k t_khost
855cbin true
856ret
857end
858ofail t_obj t_kind
859end
860fn card to bool
861pclr
862pt t_card
863put g_n 6 0
864if not bload
865ret false
866end
867n = get g_n 6
868if ge n len g_c
869ret false
870end
871for q ulong n bound 1048576
872put g_c q get g_b q
873end
874s = ulong 0
875while lt s n bound 1048576
876e = s
877while and lt e n ne get g_c e 10 bound 1048576
878e = add e 1
879end
880crow s e
881s = add e 1
882end
883ret true
884end
885note ---- controls
886fn caught c bool what view uchar * to void
887put g_n 12 add get g_n 12 1
888nmset what
889if c
890ot t_ok
891ot t_ctl
892onm
893ot t_caught
894onl
895put g_n 13 add get g_n 13 1
896else
897ofail t_ctl t_esc
898end
899end
900note a compiler one byte longer must fail the digest check
901fn cwrong to void
902pclr
903for j ulong get g_n 1 bound 4096
904pc ulong get g_omc j
905end
906put g_n 6 0
907ok = bload
908n = get g_n 6
909put g_b n 0
910put g_n 6 add n 1
911psc t_plus
912ok = and ok bsave true
913psc t_plus
914c = and ok not pinok
915caught c t_plus
916end
917note embed5120_step with its first 0xaf0103 changed to 0xaf0102 must not give the card bytes
918fn cchanged to void
919nmset t_e5
920psn t_hs
921ok = fhash
922dsave
923pclr
924pt t_isa
925pt t_e5
926pt t_isx
927put g_n 6 0
928ok = and ok bload
929n = get g_n 6
930hit = n
931for p ulong n bound 16777216
932if and eq hit n kdat p n
933hit = p
934end
935end
936if eq hit n
937nmset t_chg
938ofail t_ctl t_noapp
939ret
940end
941put g_b add hit 7 50
942nmset t_chg
943psn t_isx
944ok = and ok bsave false
945r = wrun 1
946c = ne r 0
947if not c
948psn t_hs
949z = fhash
950c = not dsame
951end
952caught and ok c t_chg
953end
954fn kdat p ulong n ulong to bool
955if gt add p len t_kdw n
956ret false
957end
958for q ulong len t_kdw
959if ne get g_b add p q get t_kdw q
960ret false
961end
962end
963ret true
964end
965note the writer must refuse a table that does not exist
966fn cmissing to void
967nmset t_mis
968r = wrun 1
969caught ne r 0 t_mis
970end
971note ---- main
972fn ausage to int
973r = write 2 t_usage 0 len t_usage
974ret 2
975end
976fn main to int
977if ne argcnt 3
978ret ausage
979end
980r = argread 1 g_omc 0 4095
981if lt r 1
982ret ausage
983end
984put g_n 1 ulong r
985if not pinread
986r = write 2 t_nopin 0 len t_nopin
987ret 2
988end
989pclr
990for j ulong get g_n 1 bound 4096
991pc ulong get g_omc j
992end
993if not pinok
994r = write 2 t_refd 0 len t_refd
995ret 69
996end
997r = argread 2 g_scr 0 4094
998if lt r 1
999ret ausage
1000end
1001if gt r 1024
1002r = write 2 t_long 0 len t_long
1003ret 2
1004end
1005n = ulong r
1006x = makedir g_scr 0 n 448
1007if ne x 0
1008r = write 2 t_noscr 0 len t_noscr
1009ret 2
1010end
1011put g_scr n 47
1012put g_n 2 add n 1
1013units
1014if not card
1015r = write 2 t_nocard 0 len t_nocard
1016ret 2
1017end
1018if or eq get g_n 16 0 eq get g_n 17 0
1019nmset t_card
1020ofail t_obj t_empty
1021end
1022cwrong
1023cchanged
1024cmissing
1025f = get g_n 11
1026ot t_sum
1027if eq f 0
1028ot t_pass
1029else
1030ot t_fl
1031end
1032ot t_su
1033onum get g_n 8
1034ot t_so
1035onum get g_n 9
1036ot t_sb
1037onum get g_n 10
1038ot t_sr
1039onum get g_n 18
1040ot t_sc
1041onum get g_n 12
1042ot t_sk
1043onum get g_n 13
1044ot t_hw
1045oflush
1046if ne f 0
1047ret 1
1048end
1049if ne get g_n 12 get g_n 13
1050ret 1
1051end
1052ret 0
1053end