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