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 / seed / build / birth.om

1073 lines · 19709 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/build/birth.om: Pure seeded-Omega Compiler Birth & Self-Rebuild Coordinator.
3note Replaces seed/omega-from-seed.sh, seed/rung4/mk4.sh, and python3 seed/omc/tests/size-record.py.
4note Zero shell, zero Python, zero sed/awk/cmp/sha256sum in the delivery path.
5note Build: cat seed/build/common.om seed/build/birth.om | seed/out/omc > build/om-birth
6note Usage: om-birth [--verify] [SCRATCH_DIR]
7note default: full seed0 -> hex1 -> asm2 -> om4 -> omc fixpoint -> diaggen -> 8-case size-record ->
8note install seed/out/omc & seed/out/omc.sha256 -> update size-history.tsv -> 4 names-pass probes
9note --verify: same full birth & checks, verifies stage3 == seed/out/omc & omc.sha256 without modifying tracked files.
10
11text b_u "usage: om-birth [--verify] [SCRATCH_DIR]\n"
12text b_fverify "--verify"
13text b_defscr "build/seed/birth-"
14text b_tmpsuf ".tmp."
15text b_fail "FAIL: "
16text b_pass "PASS "
17text b_rc0 "RC=0\n"
18text b_s0hex "seed/rung0/seed0.hex"
19text b_s0bin "seed/rung0/seed0.bin"
20text b_h1hex "seed/rung1/hex1.hex"
21text b_h1bin "seed/rung1/hex1.bin"
22text b_a2src "seed/rung2/asm2.hex1"
23text b_a2bin "seed/rung2/asm2.bin"
24text b_t2 "seed/rung2/table.s2"
25text b_t3 "seed/rung3/table3.s2"
26text b_t4 "seed/rung4/table4.s2"
27text b_om4s "seed/rung4/om4.s"
28text b_om4b "seed/rung4/om4.bin"
29text b_omcsrc "seed/omc/omc.om"
30text b_errreg "seed/omc/error-codes.reg"
31text b_tsha "seed/trace/sha256.om"
32text b_drt "seed/omc/diag-runtime.om"
33text b_dgen "seed/omc/diaggen.om"
34text b_outomc "seed/out/omc"
35text b_outsha "seed/out/omc.sha256"
36text b_hist "seed/omc/size-history.tsv"
37text b_outdir "seed/out"
38text b_pfmark " .w 0x"
39text b_pfsuf " ; p_filesz = the size of om4.bin"
40text b_pfmid ", "
41text b_pfend " bytes (asm2 has no size arithmetic; gate4.sh checks it)"
42text b_om2l "om2\n"
43text b_fnsha "fn sha256 "
44text b_pfwd "seed/rung4/tests/r5b_fwd.om"
45text b_pmut "seed/rung4/tests/r5b_mut.om"
46text b_pcyc "seed/rung4/tests/r5b_cycle.om"
47text b_passg "seed/rung4/tests/r5b_assign.om"
48text b_err9 "error 9"
49text b_err7 "error 7"
50text b_s0_self "/seed0.self"
51text b_s0_out "/seed0.bin"
52text b_h1_out "/hex1.bin"
53text b_h1_self "/hex1.self"
54text b_a2_out "/asm2.bin"
55text b_om4_src "/om4.all.s"
56text b_om4_out "/om4.bin"
57text b_om4_s2 "/om4.s.patched"
58text b_st1 "/stage1"
59text b_st2 "/stage2"
60text b_st3 "/stage3"
61text b_dgom "/diaggen.om"
62text b_dgbin "/diaggen"
63text b_dgout "/diagnostics-source.om"
64text b_szrec "/size-record.tsv"
65text b_sr_src "/sr-source.om"
66text b_sr_bin "/sr-compiler"
67text b_sr_out "/sr-out.tsv"
68text b_sr_alt "fn a\n note fn ignored\nfn b\nfn c"
69text b_sr_pfx "seeded-"
70text b_sr_mid "\tGenerated from seeded source and executable\t"
71text b_sr_tab "\t"
72text b_sr_bad "BAD!"
73text b_fnsp "fn "
74text b_p_fwd "/fwd.bin"
75text b_p_fwde "/fwd.err"
76text b_p_mut "/mut.bin"
77text b_p_mute "/mut.err"
78text b_p_cyc "/cycle.bin"
79text b_p_cyce "/cycle.err"
80text b_p_asg "/assign.bin"
81text b_p_asge "/assign.err"
82text b_m_s0 "seed0 "
83text b_m_s0b " bytes, rebuilds itself\n"
84text b_m_h1 "hex1 "
85text b_m_h1b " bytes, born from seed0\n"
86text b_m_a2 "asm2 "
87text b_m_a2b " bytes, born from hex1\n"
88text b_m_o4 "om4 om4.bin "
89text b_m_o4b " bytes\n"
90text b_m_dg "diagnostic source identity and generated strings\n"
91text b_m_fp "omc fixpoint "
92text b_m_sr "generated compiler size record\n"
93text b_m_srp "SIZE_RECORD PASS cases=8\n"
94text b_m_f1 "fwd exit 0\n"
95text b_m_f2 "fwd runs, exit 7\n"
96text b_m_m1 "mut exit 0\n"
97text b_m_m2 "mut runs, exit 0\n"
98text b_m_c1 "cycle exit 9\n"
99text b_m_a1 "assign exit 7\n"
100text b_e_s0parse "seed0.hex parse failed\n"
101text b_e_s0self "seed0 did not rebuild itself\n"
102text b_e_s0cmp "seed0.bin is not what seed0.hex makes\n"
103text b_e_h1cmp "hex1.bin is not what seed0 makes from hex1.hex\n"
104text b_e_h1self "hex1 did not rebuild itself\n"
105text b_e_a2cmp "asm2.bin is not what hex1 makes\n"
106text b_e_om4 "om4 build failed\n"
107text b_e_st1 "om4 failed to compile omc.om\n"
108text b_e_dg "diagnostic source is stale or diaggen failed\n"
109text b_e_st2 "stage1 failed to compile omc.om\n"
110text b_e_st3 "stage2 failed to compile omc.om\n"
111text b_e_fp "fixpoint mismatch: stage1/stage2/stage3 differ\n"
112text b_e_ver "verify: stage3 differs from seed/out/omc or seed/out/omc.sha256\n"
113text b_e_sr "SIZE_RECORD FAIL\n"
114text b_e_pr "names-pass probe failed\n"
115text b_shasuf " seed/out/omc\n"
116
117global b_scr uchar 4096
118global b_scrl ulong 1
119global b_verify ulong 1
120global b_h1 uchar 64
121global b_h2 uchar 64
122global b_h3 uchar 64
123global b_szwant uchar 256
124global b_szwl ulong 1
125global b_defused ulong 1
126
127fn b_cleanup_def to void
128if eq get b_defused 0 0
129ret
130end
131cb_pa_clr
132for j ulong get b_scrl 0 bound 4096
133cb_pa_ch get b_scr j
134end
135cb_rm_flat_pa
136put b_defused 0 0
137end
138
139fn b_pa_append_pid to void
140x = ulong getpid
141k = ulong 32
142for j ulong 21
143k = sub k 1
144put cb_numbuf k uchar add 48 rem x 10
145x = div x 10
146if eq x 0
147break
148end
149end
150for j ulong sub 32 k bound 32
151cb_pa_ch get cb_numbuf add k j
152end
153end
154
155fn b_pb_append_pid to void
156x = ulong getpid
157k = ulong 32
158for j ulong 21
159k = sub k 1
160put cb_numbuf k uchar add 48 rem x 10
161x = div x 10
162if eq x 0
163break
164end
165end
166for j ulong sub 32 k bound 32
167cb_pb_ch get cb_numbuf add k j
168end
169end
170
171fn b_die msg view uchar * to void
172b_cleanup_def
173cb_err b_fail
174cb_err msg
175exit 1
176end
177
178fn b_pscr suf view uchar * to void
179cb_pa_clr
180n = get b_scrl 0
181for i ulong n bound 4096
182cb_pa_ch get b_scr i
183end
184cb_pa_tx suf
185end
186
187fn b_pbscr suf view uchar * to void
188cb_pb_clr
189n = get b_scrl 0
190for i ulong n bound 4096
191cb_pb_ch get b_scr i
192end
193cb_pb_tx suf
194end
195
196note Run binary at cb_pc[0..binlen) with stdin cb_pa and stdout cb_pb (mode 0755)
197fn b_pipe_bin binlen ulong mode int to ulong
198fi = fopen cb_pa 0 get cb_n 3 524288 0
199if lt fi 0
200ret 512
201end
202z0 = unlink cb_pb 0 get cb_n 4
203fo = fopen cb_pb 0 get cb_n 4 524865 mode
204if lt fo 0
205z1 = fclose int fi
206ret 512
207end
208cb_av_clr
209p = get cb_n 5
210put cb_av p uchar and binlen 255
211put cb_av add p 1 uchar shr binlen 8
212for i ulong binlen bound 4096
213put cb_av add add p 2 i get cb_pc i
214end
215put cb_n 5 add add p 2 binlen
216put cb_n 6 1
217put cb_av 0 1
218put cb_av 1 0
219ret cb_spawn_fds int fi int fo -1 false
220end
221
222fn b_set_pc_scr suf view uchar * to ulong
223n = get b_scrl 0
224for i ulong n bound 4096
225put cb_pc i get b_scr i
226end
227m = len suf
228for i ulong m bound 4096
229put cb_pc add n i get suf i
230end
231ret add n m
232end
233
234note Step 1: strict seed0.hex loader in pure Omega (exact parity with seed/rung0/load0.sh)
235fn b_load_seed0 to ulong
236cb_pa_set b_s0hex
237if not cb_read_pa
238b_die b_e_s0parse
239end
240n = get cb_n 0
241cb_wb_clr
242i = ulong 0
243while lt i n bound 9223372036854775807
244e = i
245while lt e n bound 9223372036854775807
246if eq get cb_rb e 10
247break
248end
249e = add e 1
250end
251note strip comment from '#' and trim spaces/tabs/CR
252c_end = e
253for k ulong sub e i bound 4096
254if eq get cb_rb add i k 35
255c_end = add i k
256break
257end
258end
259val = ulong 0
260digs = ulong 0
261for k ulong sub c_end i bound 4096
262ch = get cb_rb add i k
263if or eq ch 32 or eq ch 9 eq ch 13
264continue
265end
266hv = cb_hex_val ch
267if gt hv 15
268b_die b_e_s0parse
269end
270val = or shl val 4 hv
271digs = add digs 1
272end
273if ne digs 0
274if ne digs 8
275b_die b_e_s0parse
276end
277cb_wb_ch uchar and val 255
278cb_wb_ch uchar and shr val 8 255
279cb_wb_ch uchar and shr val 16 255
280cb_wb_ch uchar and shr val 24 255
281end
282i = add e 1
283end
284b_pscr b_s0_out
285if not cb_write_wb_pa 493
286b_die b_e_s0parse
287end
288ret get cb_n 1
289end
290
291fn b_step1 to void
292sz = b_load_seed0
293bl = b_set_pc_scr b_s0_out
294cb_pa_set b_s0hex
295b_pbscr b_s0_self
296if ne b_pipe_bin bl 420 0
297b_die b_e_s0self
298end
299b_pscr b_s0_out
300b_pbscr b_s0_self
301if not cb_cmp_pa_pb
302b_die b_e_s0self
303end
304cb_pb_set b_s0bin
305if not cb_cmp_pa_pb
306b_die b_e_s0cmp
307end
308cb_out b_pass
309cb_out b_m_s0
310cb_wnum 1 sz
311cb_out b_m_s0b
312end
313
314fn b_step2 to void
315bl = b_set_pc_scr b_s0_out
316cb_pa_set b_h1hex
317b_pbscr b_h1_out
318if ne b_pipe_bin bl 493 0
319b_die b_e_h1cmp
320end
321b_pscr b_h1_out
322cb_pb_set b_h1bin
323if not cb_cmp_pa_pb
324b_die b_e_h1cmp
325end
326sz = cb_file_size_pa
327h1l = b_set_pc_scr b_h1_out
328cb_pa_set b_h1hex
329b_pbscr b_h1_self
330if ne b_pipe_bin h1l 420 0
331b_die b_e_h1self
332end
333b_pscr b_h1_out
334b_pbscr b_h1_self
335if not cb_cmp_pa_pb
336b_die b_e_h1self
337end
338cb_out b_pass
339cb_out b_m_h1
340cb_wnum 1 ulong sz
341cb_out b_m_h1b
342end
343
344fn b_step3 to void
345bl = b_set_pc_scr b_h1_out
346cb_pa_set b_a2src
347b_pbscr b_a2_out
348if ne b_pipe_bin bl 493 0
349b_die b_e_a2cmp
350end
351b_pscr b_a2_out
352cb_pb_set b_a2bin
353if not cb_cmp_pa_pb
354b_die b_e_a2cmp
355end
356sz = cb_file_size_pa
357cb_out b_pass
358cb_out b_m_a2
359cb_wnum 1 ulong sz
360cb_out b_m_a2b
361end
362
363fn b_match_rb pos ulong t view uchar * to bool
364n = get cb_n 0
365m = len t
366if gt add pos m n
367ret false
368end
369for j ulong m bound 4096
370if ne get cb_rb add pos j get t j
371ret false
372end
373end
374ret true
375end
376
377note Patch p_filesz line of om4.s in cb_rb into cb_wb with new size sz
378fn b_patch_om4s sz ulong to void
379cb_wb_clr
380n = get cb_n 0
381i = ulong 0
382patched = ulong 0
383while lt i n bound 9223372036854775807
384e = i
385while lt e n bound 9223372036854775807
386if eq get cb_rb e 10
387break
388end
389e = add e 1
390end
391has_nl = lt e n
392if and eq patched 0 and b_match_rb i b_pfmark b_match_rb add i 15 b_pfsuf
393cb_wb_tx b_pfmark
394for d ulong 8
395sh = mul sub 7 d 4
396cb_wb_ch get cb_hexd and shr sz sh 15
397end
398cb_wb_tx b_pfsuf
399cb_wb_tx b_pfmid
400cb_wb_num sz
401cb_wb_tx b_pfend
402if has_nl
403cb_wb_ch 10
404end
405patched = 1
406else
407lenl = sub e i
408if has_nl
409lenl = add lenl 1
410end
411cb_wb_rb i lenl
412end
413i = add e 1
414end
415if eq patched 0
416b_die b_e_om4
417end
418end
419
420fn b_join_om4 use_patched bool to void
421cb_wb_clr
422cb_pa_set b_t2
423if not cb_append_pa_to_wb
424b_die b_e_om4
425end
426cb_pa_set b_t3
427if not cb_append_pa_to_wb
428b_die b_e_om4
429end
430cb_pa_set b_t4
431if not cb_append_pa_to_wb
432b_die b_e_om4
433end
434if use_patched
435b_pscr b_om4_s2
436else
437cb_pa_set b_om4s
438end
439if not cb_append_pa_to_wb
440b_die b_e_om4
441end
442b_pscr b_om4_src
443if not cb_write_wb_pa 420
444b_die b_e_om4
445end
446end
447
448fn b_step4 to void
449b_join_om4 false
450a2l = b_set_pc_scr b_a2_out
451b_pscr b_om4_src
452b_pbscr b_om4_out
453if ne b_pipe_bin a2l 493 0
454b_die b_e_om4
455end
456b_pscr b_om4_out
457sz1 = cb_file_size_pa
458if le sz1 0
459b_die b_e_om4
460end
461cb_pa_set b_om4s
462if not cb_read_pa
463b_die b_e_om4
464end
465b_patch_om4s ulong sz1
466b_pscr b_om4_s2
467if not cb_write_wb_pa 420
468b_die b_e_om4
469end
470if eq get b_verify 0 0
471cb_pa_set b_om4s
472if not cb_write_wb_pa 420
473b_die b_e_om4
474end
475end
476b_join_om4 true
477b_pscr b_om4_src
478b_pbscr b_om4_out
479if ne b_pipe_bin a2l 493 0
480b_die b_e_om4
481end
482b_pscr b_om4_out
483sz2 = cb_file_size_pa
484if ne sz1 sz2
485b_die b_e_om4
486end
487if eq get b_verify 0 0
488b_pscr b_om4_out
489cb_pb_set b_om4b
490if not cb_copy_pa_to_pb 493
491b_die b_e_om4
492end
493else
494b_pscr b_om4_out
495cb_pb_set b_om4b
496if not cb_cmp_pa_pb
497b_die b_e_om4
498end
499end
500cb_out b_pass
501cb_out b_m_o4
502cb_wnum 1 ulong sz2
503cb_out b_m_o4b
504end
505
506note Compose diaggen.om: om2\n + seed/trace/sha256.om up to "^fn sha256 " + seed/omc/diaggen.om
507fn b_build_diaggen to void
508cb_pa_set b_tsha
509if not cb_read_pa
510b_die b_e_dg
511end
512n = get cb_n 0
513cut = n
514i = ulong 0
515while lt i n bound 9223372036854775807
516if b_match_rb i b_fnsha
517cut = i
518break
519end
520while lt i n bound 9223372036854775807
521if eq get cb_rb i 10
522i = add i 1
523break
524end
525i = add i 1
526end
527end
528cb_wb_clr
529cb_wb_tx b_om2l
530cb_wb_rb 0 cut
531cb_pa_set b_dgen
532if not cb_append_pa_to_wb
533b_die b_e_dg
534end
535b_pscr b_dgom
536if not cb_write_wb_pa 420
537b_die b_e_dg
538end
539st1l = b_set_pc_scr b_st1
540b_pscr b_dgom
541b_pbscr b_dgbin
542if ne cb_run_omc st1l 493 -1 0
543b_die b_e_dg
544end
545note Run diaggen to check diagnostic source identity
546cb_av_clr
547b_pscr b_dgbin
548cb_av_push_pa
549cb_av_push_tx b_omcsrc
550cb_av_push_tx b_errreg
551cb_av_push_tx b_tsha
552cb_av_push_tx b_drt
553b_pscr b_dgout
554z0 = unlink cb_pa 0 get cb_n 3
555fo = fopen cb_pa 0 get cb_n 3 524865 420
556if lt fo 0
557b_die b_e_dg
558end
559if ne cb_spawn_fds -1 int fo -1 false 0
560b_die b_e_dg
561end
562b_pscr b_dgout
563cb_pb_set b_omcsrc
564if not cb_cmp_pa_pb
565b_die b_e_dg
566end
567cb_out b_pass
568cb_out b_m_dg
569end
570
571note Pure-Omega replacement for python3 seed/omc/tests/size-record.py (all 8 cases!)
572fn b_sr_expect_line src_len ulong bin_len ulong to void
573lines = ulong 0
574fns = ulong 0
575i = ulong 0
576at_bol = true
577while lt i src_len bound 9223372036854775807
578if at_bol
579if b_match_rb i b_fnsp
580fns = add fns 1
581end
582at_bol = false
583end
584if eq get cb_rb i 10
585lines = add lines 1
586at_bol = true
587end
588i = add i 1
589end
590words = div sub bin_len 176 4
591cb_wb_clr
592cb_wb_tx b_sr_pfx
593for j ulong 12
594cb_wb_ch get cb_shex j
595end
596cb_wb_tx b_sr_mid
597cb_wb_num lines
598cb_wb_tx b_sr_tab
599cb_wb_num fns
600cb_wb_tx b_sr_tab
601cb_wb_num words
602cb_wb_tx b_sr_tab
603for j ulong 64
604cb_wb_ch get cb_shex j
605end
606cb_wb_ch 10
607n = get cb_n 1
608if gt n 256
609b_die b_e_sr
610end
611for j ulong n bound 256
612put b_szwant j get cb_wb j
613end
614put b_szwl 0 n
615end
616
617fn b_sr_run_dg expect_rc ulong check_out bool to void
618cb_av_clr
619b_pscr b_dgbin
620cb_av_push_pa
621if ne expect_rc 60
622b_pscr b_sr_src
623cb_av_push_pa
624b_pscr b_sr_bin
625cb_av_push_pa
626end
627b_pscr b_sr_out
628z0 = unlink cb_pa 0 get cb_n 3
629fo = fopen cb_pa 0 get cb_n 3 524865 420
630fe = fopen cb_devnull 0 len cb_devnull 524289 0
631if or lt fo 0 lt fe 0
632b_die b_e_sr
633end
634rc = cb_spawn_fds -1 int fo int fe false
635if ne rc expect_rc
636b_die b_e_sr
637end
638b_pscr b_sr_out
639if not cb_read_pa
640b_die b_e_sr
641end
642if check_out
643wl = get b_szwl 0
644if ne get cb_n 0 wl
645b_die b_e_sr
646end
647for j ulong wl bound 256
648if ne get cb_rb j get b_szwant j
649b_die b_e_sr
650end
651end
652else
653if ne get cb_n 0 0
654b_die b_e_sr
655end
656end
657end
658
659fn b_check_size_records to void
660note Case 1: current omc.om + stage3
661cb_pa_set b_omcsrc
662b_pbscr b_sr_src
663if not cb_copy_pa_to_pb 420
664b_die b_e_sr
665end
666b_pscr b_st3
667b_pbscr b_sr_bin
668if not cb_copy_pa_to_pb 420
669b_die b_e_sr
670end
671b_pscr b_sr_bin
672blen = cb_file_size_pa
673if not cb_sha_file_pa
674b_die b_e_sr
675end
676b_pscr b_sr_src
677if not cb_read_pa
678b_die b_e_sr
679end
680b_sr_expect_line get cb_n 0 ulong blen
681b_sr_run_dg 0 true
682
683note Case 2: source-lines
684cb_wb_clr
685cb_wb_tx b_sr_alt
686b_pscr b_sr_src
687if not cb_write_wb_pa 420
688b_die b_e_sr
689end
690b_pscr b_sr_bin
691if not cb_sha_file_pa
692b_die b_e_sr
693end
694b_pscr b_sr_src
695if not cb_read_pa
696b_die b_e_sr
697end
698b_sr_expect_line get cb_n 0 ulong blen
699b_sr_run_dg 0 true
700
701note Case 3: binary-content (flip last byte of stage3)
702cb_pa_set b_omcsrc
703b_pbscr b_sr_src
704if not cb_copy_pa_to_pb 420
705b_die b_e_sr
706end
707b_pscr b_st3
708if not cb_read_pa
709b_die b_e_sr
710end
711bn = get cb_n 0
712last = get cb_rb sub bn 1
713put cb_rb sub bn 1 xor last 1
714b_pscr b_sr_bin
715if not cb_write_rb_pa 420
716b_die b_e_sr
717end
718if not cb_sha_file_pa
719b_die b_e_sr
720end
721b_pscr b_sr_src
722if not cb_read_pa
723b_die b_e_sr
724end
725b_sr_expect_line get cb_n 0 bn
726b_sr_run_dg 0 true
727
728note Case 4: empty binary -> exit 67
729cb_wb_clr
730b_pscr b_sr_bin
731if not cb_write_wb_pa 420
732b_die b_e_sr
733end
734b_sr_run_dg 67 false
735
736note Case 5: short binary (175 bytes) -> exit 67
737b_pscr b_st3
738if not cb_read_pa
739b_die b_e_sr
740end
741cb_wb_clr
742cb_wb_rb 0 175
743b_pscr b_sr_bin
744if not cb_write_wb_pa 420
745b_die b_e_sr
746end
747b_sr_run_dg 67 false
748
749note Case 6: unaligned binary (bn - 1 bytes) -> exit 67
750cb_wb_clr
751cb_wb_rb 0 sub bn 1
752b_pscr b_sr_bin
753if not cb_write_wb_pa 420
754b_die b_e_sr
755end
756b_sr_run_dg 67 false
757
758note Case 7: bad magic -> exit 67
759cb_wb_clr
760cb_wb_tx b_sr_bad
761cb_wb_rb 4 sub bn 4
762b_pscr b_sr_bin
763if not cb_write_wb_pa 420
764b_die b_e_sr
765end
766b_sr_run_dg 67 false
767
768note Case 8: usage (no args) -> exit 60
769b_sr_run_dg 60 false
770cb_out b_m_srp
771end
772
773fn b_copy_hex_to dst ulong to void
774for j ulong 64
775if eq dst 1
776put b_h1 j get cb_shex j
777else
778if eq dst 2
779put b_h2 j get cb_shex j
780else
781put b_h3 j get cb_shex j
782end
783end
784end
785end
786
787fn b_hex_eq_12 to bool
788for j ulong 64
789if ne get b_h1 j get b_h2 j
790ret false
791end
792end
793ret true
794end
795
796fn b_hex_eq_23 to bool
797for j ulong 64
798if ne get b_h2 j get b_h3 j
799ret false
800end
801end
802ret true
803end
804
805fn b_update_history to void
806note Generate size record for stage3
807cb_av_clr
808b_pscr b_dgbin
809cb_av_push_pa
810cb_av_push_tx b_omcsrc
811b_pscr b_st3
812cb_av_push_pa
813b_pscr b_szrec
814z0 = unlink cb_pa 0 get cb_n 3
815fo = fopen cb_pa 0 get cb_n 3 524865 420
816if lt fo 0
817b_die b_e_sr
818end
819if ne cb_spawn_fds -1 int fo -1 false 0
820b_die b_e_sr
821end
822if eq get b_verify 0 0
823cb_pa_set b_hist
824if cb_read_pa
825hn = get cb_n 0
826note check if last line ends with TAB + b_h3
827has = false
828if ge hn 66
829pos = sub hn 65
830if eq get cb_rb sub hn 1 10
831pos = sub hn 66
832end
833if eq get cb_rb pos 9
834ok = true
835for j ulong 64
836if ne get cb_rb add add pos 1 j get b_h3 j
837ok = false
838break
839end
840end
841has = ok
842end
843end
844if not has
845b_pscr b_szrec
846if not cb_read_pa
847b_die b_e_sr
848end
849fd = fopen b_hist 0 len b_hist 525377 420
850if lt fd 0
851b_die b_e_sr
852end
853w = write int fd cb_rb 0 get cb_n 0
854z1 = fclose int fd
855end
856end
857end
858cb_out b_pass
859cb_out b_m_sr
860end
861
862fn b_step5 to void
863o4l = b_set_pc_scr b_om4_out
864cb_pa_set b_omcsrc
865b_pbscr b_st1
866if ne cb_run_omc o4l 493 -1 0
867b_die b_e_st1
868end
869b_build_diaggen
870s1l = b_set_pc_scr b_st1
871cb_pa_set b_omcsrc
872b_pbscr b_st2
873if ne cb_run_omc s1l 493 -1 0
874b_die b_e_st2
875end
876s2l = b_set_pc_scr b_st2
877cb_pa_set b_omcsrc
878b_pbscr b_st3
879if ne cb_run_omc s2l 493 -1 0
880b_die b_e_st3
881end
882b_pscr b_st1
883if not cb_sha_file_pa
884b_die b_e_fp
885end
886b_copy_hex_to 1
887b_pscr b_st2
888if not cb_sha_file_pa
889b_die b_e_fp
890end
891b_copy_hex_to 2
892b_pscr b_st3
893if not cb_sha_file_pa
894b_die b_e_fp
895end
896b_copy_hex_to 3
897if or not b_hex_eq_23 not b_hex_eq_12
898b_die b_e_fp
899end
900if eq get b_verify 0 0
901cb_pa_set b_outdir
902z0 = cb_mkdir_p_pa
903b_pscr b_st3
904cb_pb_set b_outomc
905cb_pb_tx b_tmpsuf
906b_pb_append_pid
907if not cb_copy_pa_to_pb 493
908b_die b_e_fp
909end
910cb_pa_pb
911cb_pb_set b_outomc
912if not cb_rename_pa_pb
913z1 = unlink cb_pa 0 get cb_n 3
914b_die b_e_fp
915end
916cb_wb_clr
917for j ulong 64
918cb_wb_ch get b_h3 j
919end
920cb_wb_tx b_shasuf
921cb_pa_set b_outsha
922cb_pa_tx b_tmpsuf
923b_pa_append_pid
924if not cb_write_wb_pa 420
925b_die b_e_fp
926end
927cb_pb_set b_outsha
928if not cb_rename_pa_pb
929z2 = unlink cb_pa 0 get cb_n 3
930b_die b_e_fp
931end
932else
933b_pscr b_st3
934cb_pb_set b_outomc
935if not cb_cmp_pa_pb
936b_die b_e_ver
937end
938cb_pa_set b_outsha
939if not cb_read_pa
940b_die b_e_ver
941end
942if lt get cb_n 0 64
943b_die b_e_ver
944end
945for j ulong 64
946if ne get cb_rb j get b_h3 j
947b_die b_e_ver
948end
949end
950end
951cb_out b_pass
952cb_out b_m_fp
953r = write 1 b_h3 0 64
954cb_out cb_nl
955b_update_history
956b_check_size_records
957end
958
959fn b_probe b_suf view uchar * e_suf view uchar * want_rc ulong to void
960s3l = b_set_pc_scr b_st3
961note save src path in cb_pb temporarily? No: caller sets cb_sb or we pass src via cb_pa -> save to cb_pb first!
962cb_pb_from_pa
963b_pscr e_suf
964z0 = unlink cb_pa 0 get cb_n 3
965fe = fopen cb_pa 0 get cb_n 3 524865 420
966if lt fe 0
967b_die b_e_pr
968end
969cb_pa_pb
970b_pbscr b_suf
971rc = cb_run_omc s3l 493 int fe
972if ne rc want_rc
973b_die b_e_pr
974end
975end
976
977fn b_run_bin b_suf view uchar * want_rc ulong to void
978cb_av_clr
979b_pscr b_suf
980cb_av_push_pa
981fo = fopen cb_devnull 0 len cb_devnull 524289 0
982if lt fo 0
983b_die b_e_pr
984end
985rc = cb_spawn_fds -1 int fo -1 false
986if ne rc want_rc
987b_die b_e_pr
988end
989end
990
991fn b_step6 to void
992cb_pa_set b_pfwd
993b_probe b_p_fwd b_p_fwde 0
994cb_out b_pass
995cb_out b_m_f1
996b_run_bin b_p_fwd 7
997cb_out b_pass
998cb_out b_m_f2
999cb_pa_set b_pmut
1000b_probe b_p_mut b_p_mute 0
1001cb_out b_pass
1002cb_out b_m_m1
1003b_run_bin b_p_mut 0
1004cb_out b_pass
1005cb_out b_m_m2
1006cb_pa_set b_pcyc
1007b_probe b_p_cyc b_p_cyce 9
1008b_pscr b_p_cyce
1009if not cb_file_contains_pa b_err9
1010b_die b_e_pr
1011end
1012cb_out b_pass
1013cb_out b_m_c1
1014cb_pa_set b_passg
1015b_probe b_p_asg b_p_asge 7
1016b_pscr b_p_asge
1017if not cb_file_contains_pa b_err7
1018b_die b_e_pr
1019end
1020cb_out b_pass
1021cb_out b_m_a1
1022end
1023
1024fn main to int
1025put b_verify 0 0
1026cb_pa_set b_defscr
1027ac = argcnt
1028if gt ac 3
1029cb_err b_u
1030ret 2
1031end
1032idx = ulong 1
1033while lt idx ulong ac bound 4
1034if not cb_pa_arg idx
1035cb_err b_u
1036ret 2
1037end
1038if cb_pa_eq b_fverify
1039put b_verify 0 1
1040else
1041for j ulong get cb_n 3 bound 4096
1042put b_scr j get cb_pa j
1043end
1044put b_scrl 0 get cb_n 3
1045end
1046idx = add idx 1
1047end
1048if eq get b_scrl 0 0
1049cb_pa_set b_defscr
1050b_pa_append_pid
1051for j ulong get cb_n 3 bound 4096
1052put b_scr j get cb_pa j
1053end
1054put b_scrl 0 get cb_n 3
1055put b_defused 0 1
1056end
1057cb_pa_clr
1058for j ulong get b_scrl 0 bound 4096
1059cb_pa_ch get b_scr j
1060end
1061if not cb_mkdir_p_pa
1062b_die b_e_s0parse
1063end
1064b_step1
1065b_step2
1066b_step3
1067b_step4
1068b_step5
1069b_step6
1070b_cleanup_def
1071cb_out b_rc0
1072ret 0
1073end