Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/build/sparkefi.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / build / sparkefi.om` 614 lines ยท 12142 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/build/sparkefi.om: Pure seeded-Omega Bare-Metal SPARK.EFI Builder & PE32+ Verifier. 3 note Replaces aienux/spark/build_spark_efi.sh AND both of its inline Python 3 scripts. 4 note Zero shell, zero Python. 5 note Build: cat seed/build/common.om seed/build/sparkefi.om | seed/out/omc > build/om-sparkefi 6 note Usage: om-sparkefi [OUT_EFI] 7 note Env: OMC (default seed/out/omc), PLAT (default gb10), PLAT_OM_OVERRIDE (test profiles only) 8 9 text se_defout "build/spark/SPARK.EFI" 10 text se_defomc "seed/out/omc" 11 text se_defplat "gb10" 12 text se_env_omc "OMC" 13 text se_env_plat "PLAT" 14 text se_env_ovr "PLAT_OM_OVERRIDE" 15 text se_sparkefi "SPARK.EFI" 16 text se_platpfx "aienux/spark/plat_" 17 text se_omext ".om" 18 text se_hdr "target a64efi\nom2\n" 19 text se_note "note " 20 text se_tmpfile ".spark_unified.om" 21 text se_f_badplat "FAIL: unknown PLAT or missing plat file\n" 22 text se_f_testout "FAIL: test profile refuses to write SPARK.EFI\n" 23 text se_f_ovrgb10 "FAIL: PLAT_OM_OVERRIDE is refused for PLAT=gb10 (production profile)\n" 24 text se_f_ovrmiss "FAIL: PLAT_OM_OVERRIDE file not found\n" 25 text se_f_io "FAIL: sparkefi I/O or missing source file\n" 26 text se_f_omc "FAIL: omc failed compiling spark_unified.om\n" 27 text se_f_pe "FAIL: PE32+ header verification failed\n" 28 text se_pass1 "PASS build_spark_efi: " 29 text se_pass2 " (PLAT=" 30 text se_pass3 ")\n PE32+ Machine=0xaa64 Subsystem=EFI_APP FileSize=" 31 text se_pass4 " B SizeOfImage=" 32 text se_pass5 " B\n sha256=" 33 34 note All 6 Phase 2 slices + spark_main.om 35 text se_s01 "seed/a64efi/efirt.om" 36 text se_s02 "aienux/kernel/arm64/fwops.om" 37 text se_s03 "aienux/kernel/arm64/uart.om" 38 text se_s04 "aienux/kernel/arm64/frames.om" 39 text se_s05 "aienux/kernel/arm64/acpi.om" 40 text se_s06 "aienux/kernel/arm64/mmu.om" 41 text se_s07 "aienux/kernel/arm64/gicv3.om" 42 text se_s08 "aienux/kernel/arm64/smp.om" 43 text se_s09 "aienux/kernel/hal/iort.om" 44 text se_s10 "aienux/kernel/hal/bar0_mmio.om" 45 text se_s11 "aienux/kernel/hal/pcie.om" 46 text se_s12 "aienux/kernel/hal/smmuv3.om" 47 text se_s13 "gpu/driver/gsp/irqbm.om" 48 text se_s14 "gpu/driver/gsp/irq.om" 49 text se_s15 "aienux/disk/nvme_ro_bare.om" 50 text se_s16 "aienux/disk/nvme_bare_a64efi.om" 51 text se_s17 "aienux/disk/sha256_bare.om" 52 text se_s18 "aienux/disk/gpt_ro.om" 53 text se_s19 "aienux/disk/ext4_ro.om" 54 text se_s20 "aienux/net/rtl8127/om/rtl8127/rtl8127.om" 55 text se_s21 "aienux/net/rtl8127/om/rtl8127/bare_a64efi.om" 56 text se_s22 "aienux/net/tcp/tcp.om" 57 text se_s23 "gpu/driver/gsp/bm_hal.om" 58 text se_s24 "gpu/driver/gsp/profile.om" 59 text se_s25 "gpu/driver/gsp/mmio_bm.om" 60 text se_s26 "gpu/driver/gsp/sec2.om" 61 text se_s27 "gpu/driver/gsp/seq.om" 62 text se_s28 "gpu/driver/gsp/seqcore.om" 63 text se_s29 "gpu/driver/gsp/rpc.om" 64 text se_s30 "gpu/driver/gsp/sysinfo.om" 65 text se_s31 "gpu/driver/chan/params.om" 66 text se_s32 "gpu/driver/gsp/boot.om" 67 text se_s33 "gpu/driver/gsp/dispatch.om" 68 text se_s34 "gpu/driver/gsp/fw_bm.om" 69 text se_s35 "gpu/driver/gsp/arena_bm.om" 70 text se_s36 "gpu/driver/gsp/transport_bm.om" 71 text se_s37 "gpu/driver/chan/gmmu_bm.om" 72 text se_s38 "gpu/driver/chan/mem.om" 73 text se_s39 "gpu/driver/chan/chan.om" 74 text se_s40 "gpu/driver/chan/complete.om" 75 text se_s41 "gpu/driver/chan/rmchan.om" 76 text se_s42 "gpu/driver/gsp/compute.om" 77 text se_s43 "gpu/driver/gsp/q38_run.om" 78 text se_s44 "gpu/nvidia/om/codegen/cg_dec_emit.om" 79 text se_s45 "gpu/nvidia/om/codegen/cg_dec.om" 80 text se_s46 "gpu/nvidia/om/components/bw_alloc.om" 81 text se_s47 "gpu/nvidia/om/encoder/bw_enc_sm121.om" 82 text se_s48 "aienux/net/wire/omtk.om" 83 text se_s49 "aienux/net/wire/wire_loop.om" 84 text se_s50 "aienux/spark/spark_main.om" 85 86 note Token rename strings 87 text se_t_rb "rb" 88 text se_t_ctl "ctl" 89 text se_t_imm "imm" 90 text se_t_arg "arg" 91 text se_t_av "av" 92 text se_t_cw "cw" 93 text se_t_nv "nv" 94 text se_t_ob "ob" 95 text se_t_at "at" 96 text se_t_rs "rs" 97 text se_r_cge_rb "cge_rb" 98 text se_r_cge_ctl "cge_ctl" 99 text se_r_cge_imm "cge_imm" 100 text se_r_cge_arg "cge_arg" 101 text se_r_cge_av "cge_av" 102 text se_r_cge_cw "cge_cw" 103 text se_r_cge_nv "cge_nv" 104 text se_r_cge_ob "cge_ob" 105 text se_r_cge_pos "cge_pos" 106 text se_r_cgd_rs "cgd_rs" 107 text se_r_bwe_rb "bwe_rb" 108 text se_r_bwe_ctl "bwe_ctl" 109 110 global se_out uchar 4096 111 global se_outl ulong 1 112 global se_omc uchar 4096 113 global se_omcl ulong 1 114 global se_plat uchar 256 115 global se_platl ulong 1 116 global se_pom uchar 4096 117 global se_poml ulong 1 118 119 fn se_die msg view uchar * to void 120 cb_err msg 121 exit 1 122 end 123 124 fn se_is_word c uchar to bool 125 if and ge c 48 le c 57 126 ret true 127 end 128 if and ge c 65 le c 90 129 ret true 130 end 131 if and ge c 97 le c 122 132 ret true 133 end 134 ret eq c 95 135 end 136 137 fn se_tok_eq off ulong tlen ulong w view uchar * to bool 138 if ne tlen len w 139 ret false 140 end 141 for i ulong tlen bound 64 142 if ne get cb_rb add off i get w i 143 ret false 144 end 145 end 146 ret true 147 end 148 149 note Emit transformed token for mode: 1 = cg_dec_emit, 2 = cg_dec, 3 = bw_enc_sm121 150 fn se_emit_tok mode ulong off ulong tlen ulong to void 151 if eq mode 1 152 if se_tok_eq off tlen se_t_rb 153 cb_wb_tx se_r_cge_rb 154 ret 155 end 156 if se_tok_eq off tlen se_t_ctl 157 cb_wb_tx se_r_cge_ctl 158 ret 159 end 160 if se_tok_eq off tlen se_t_imm 161 cb_wb_tx se_r_cge_imm 162 ret 163 end 164 if se_tok_eq off tlen se_t_arg 165 cb_wb_tx se_r_cge_arg 166 ret 167 end 168 if se_tok_eq off tlen se_t_av 169 cb_wb_tx se_r_cge_av 170 ret 171 end 172 if se_tok_eq off tlen se_t_cw 173 cb_wb_tx se_r_cge_cw 174 ret 175 end 176 if se_tok_eq off tlen se_t_nv 177 cb_wb_tx se_r_cge_nv 178 ret 179 end 180 if se_tok_eq off tlen se_t_ob 181 cb_wb_tx se_r_cge_ob 182 ret 183 end 184 if se_tok_eq off tlen se_t_at 185 cb_wb_tx se_r_cge_pos 186 ret 187 end 188 end 189 if eq mode 2 190 if se_tok_eq off tlen se_t_av 191 cb_wb_tx se_r_cge_av 192 ret 193 end 194 if se_tok_eq off tlen se_t_cw 195 cb_wb_tx se_r_cge_cw 196 ret 197 end 198 if se_tok_eq off tlen se_t_nv 199 cb_wb_tx se_r_cge_nv 200 ret 201 end 202 if se_tok_eq off tlen se_t_ob 203 cb_wb_tx se_r_cge_ob 204 ret 205 end 206 if se_tok_eq off tlen se_t_arg 207 cb_wb_tx se_r_cge_arg 208 ret 209 end 210 if se_tok_eq off tlen se_t_rs 211 cb_wb_tx se_r_cgd_rs 212 ret 213 end 214 end 215 if eq mode 3 216 if se_tok_eq off tlen se_t_rb 217 cb_wb_tx se_r_bwe_rb 218 ret 219 end 220 if se_tok_eq off tlen se_t_ctl 221 cb_wb_tx se_r_bwe_ctl 222 ret 223 end 224 end 225 cb_wb_rb off tlen 226 end 227 228 fn se_line_is_note s ulong e ulong to bool 229 p = s 230 while lt p e bound `9223372036854775807` 231 c = get cb_rb p 232 if or eq c 32 eq c 9 233 p = add p 1 234 else 235 break 236 end 237 end 238 if lt sub e p 5 239 ret false 240 end 241 for j ulong 5 242 if ne get cb_rb add p j get se_note j 243 ret false 244 end 245 end 246 ret true 247 end 248 249 note Append file with word-boundary identifier transformation (skipping note lines) 250 fn se_append_xform path view uchar * mode ulong to void 251 cb_pa_set path 252 if not cb_read_pa 253 se_die se_f_io 254 end 255 n = get cb_n 0 256 i = ulong 0 257 while lt i n bound `9223372036854775807` 258 e = i 259 while lt e n bound `9223372036854775807` 260 if eq get cb_rb e 10 261 break 262 end 263 e = add e 1 264 end 265 has_nl = lt e n 266 if se_line_is_note i e 267 lenl = sub e i 268 if has_nl 269 lenl = add lenl 1 270 end 271 cb_wb_rb i lenl 272 else 273 p = i 274 while lt p e bound `9223372036854775807` 275 c = get cb_rb p 276 if se_is_word c 277 q = p 278 while lt q e bound `9223372036854775807` 279 if not se_is_word get cb_rb q 280 break 281 end 282 q = add q 1 283 end 284 se_emit_tok mode p sub q p 285 p = q 286 else 287 cb_wb_ch c 288 p = add p 1 289 end 290 end 291 if has_nl 292 cb_wb_ch 10 293 end 294 end 295 i = add e 1 296 end 297 end 298 299 fn se_app path view uchar * to void 300 cb_pa_set path 301 if not cb_append_pa_to_wb 302 se_die se_f_io 303 end 304 end 305 306 fn se_compose_all to void 307 cb_wb_clr 308 cb_wb_tx se_hdr 309 se_app se_s01 310 se_app se_s02 311 se_app se_s03 312 se_app se_s04 313 se_app se_s05 314 se_app se_s06 315 se_app se_s07 316 se_app se_s08 317 se_app se_s09 318 se_app se_s10 319 se_app se_s11 320 se_app se_s12 321 se_app se_s13 322 se_app se_s14 323 se_app se_s15 324 se_app se_s16 325 se_app se_s17 326 se_app se_s18 327 se_app se_s19 328 se_app se_s20 329 se_app se_s21 330 se_app se_s22 331 se_app se_s23 332 se_app se_s24 333 se_app se_s25 334 se_app se_s26 335 se_app se_s27 336 se_app se_s28 337 se_app se_s29 338 se_app se_s30 339 se_app se_s31 340 se_app se_s32 341 se_app se_s33 342 se_app se_s34 343 se_app se_s35 344 se_app se_s36 345 se_app se_s37 346 se_app se_s38 347 se_app se_s39 348 se_app se_s40 349 se_app se_s41 350 se_app se_s42 351 se_app se_s43 352 se_append_xform se_s44 1 353 se_append_xform se_s45 2 354 se_app se_s46 355 se_append_xform se_s47 3 356 se_app se_s48 357 se_app se_s49 358 cb_pa_clr 359 for i ulong get se_poml 0 bound 4096 360 cb_pa_ch get se_pom i 361 end 362 if not cb_append_pa_to_wb 363 se_die se_f_io 364 end 365 se_app se_s50 366 end 367 368 fn se_u16_le off ulong to ulong 369 b0 = ulong get cb_rb off 370 b1 = ulong get cb_rb add off 1 371 ret or b0 shl b1 8 372 end 373 374 fn se_u32_le off ulong to ulong 375 b0 = ulong get cb_rb off 376 b1 = ulong get cb_rb add off 1 377 b2 = ulong get cb_rb add off 2 378 b3 = ulong get cb_rb add off 3 379 ret or or b0 shl b1 8 or shl b2 16 shl b3 24 380 end 381 382 fn se_verify_pe to void 383 cb_pa_clr 384 for i ulong get se_outl 0 bound 4096 385 cb_pa_ch get se_out i 386 end 387 if not cb_read_pa 388 se_die se_f_pe 389 end 390 n = get cb_n 0 391 if lt n 512 392 se_die se_f_pe 393 end 394 if or ne get cb_rb 0 77 ne get cb_rb 1 90 395 se_die se_f_pe 396 end 397 pe = se_u32_le 60 398 if gt add pe 96 n 399 se_die se_f_pe 400 end 401 if ne get cb_rb pe 80 402 se_die se_f_pe 403 end 404 if ne get cb_rb add pe 1 69 405 se_die se_f_pe 406 end 407 if ne get cb_rb add pe 2 0 408 se_die se_f_pe 409 end 410 if ne get cb_rb add pe 3 0 411 se_die se_f_pe 412 end 413 mach = se_u16_le add pe 4 414 if ne mach 43620 415 se_die se_f_pe 416 end 417 opt = add pe 24 418 omagic = se_u16_le opt 419 if ne omagic 523 420 se_die se_f_pe 421 end 422 szimg = se_u32_le add opt 56 423 subsys = se_u16_le add opt 68 424 if ne subsys 10 425 se_die se_f_pe 426 end 427 if ge szimg `16777216` 428 se_die se_f_pe 429 end 430 cb_sha_rb 0 n 431 cb_out se_pass1 432 r1 = write 1 se_out 0 get se_outl 0 433 cb_out se_pass2 434 r2 = write 1 se_plat 0 get se_platl 0 435 cb_out se_pass3 436 cb_wnum 1 n 437 cb_out se_pass4 438 cb_wnum 1 szimg 439 cb_out se_pass5 440 cb_wbuf_hex 1 441 cb_out cb_nl 442 end 443 444 fn se_is_gb10 to bool 445 if ne get se_platl 0 4 446 ret false 447 end 448 for i ulong 4 449 if ne get se_plat i get se_defplat i 450 ret false 451 end 452 end 453 ret true 454 end 455 456 fn se_out_basename_is_spark to bool 457 n = get se_outl 0 458 s = ulong 0 459 for i ulong n bound 4096 460 if eq get se_out i 47 461 s = add i 1 462 end 463 end 464 blen = sub n s 465 if ne blen len se_sparkefi 466 ret false 467 end 468 for i ulong blen bound 64 469 if ne get se_out add s i get se_sparkefi i 470 ret false 471 end 472 end 473 ret true 474 end 475 476 fn main to int 477 note OUT_EFI 478 ac = argcnt 479 if ge ac 2 480 if not cb_pa_arg 1 481 se_die se_f_io 482 end 483 for i ulong get cb_n 3 bound 4096 484 put se_out i get cb_pa i 485 end 486 put se_outl 0 get cb_n 3 487 else 488 for i ulong len se_defout bound 4096 489 put se_out i get se_defout i 490 end 491 put se_outl 0 len se_defout 492 end 493 494 note OMC 495 if cb_getenv se_env_omc 496 if gt get cb_n 4 0 497 for i ulong get cb_n 4 bound 4096 498 put se_omc i get cb_pb i 499 end 500 put se_omcl 0 get cb_n 4 501 end 502 end 503 if eq get se_omcl 0 0 504 for i ulong len se_defomc bound 4096 505 put se_omc i get se_defomc i 506 end 507 put se_omcl 0 len se_defomc 508 end 509 510 note PLAT 511 if cb_getenv se_env_plat 512 if and gt get cb_n 4 0 le get cb_n 4 255 513 for i ulong get cb_n 4 bound 256 514 put se_plat i get cb_pb i 515 end 516 put se_platl 0 get cb_n 4 517 end 518 end 519 if eq get se_platl 0 0 520 for i ulong len se_defplat bound 256 521 put se_plat i get se_defplat i 522 end 523 put se_platl 0 len se_defplat 524 end 525 526 note Build default PLAT_OM path 527 cb_pa_set se_platpfx 528 for i ulong get se_platl 0 bound 256 529 cb_pa_ch get se_plat i 530 end 531 cb_pa_tx se_omext 532 for i ulong get cb_n 3 bound 4096 533 put se_pom i get cb_pa i 534 end 535 put se_poml 0 get cb_n 3 536 537 note Safety guard 1: PLAT != gb10 cannot write SPARK.EFI 538 is_prod = se_is_gb10 539 if and not is_prod se_out_basename_is_spark 540 se_die se_f_testout 541 end 542 543 note Safety guard 2: PLAT_OM_OVERRIDE 544 if cb_getenv se_env_ovr 545 if gt get cb_n 4 0 546 if is_prod 547 se_die se_f_ovrgb10 548 end 549 for i ulong get cb_n 4 bound 4096 550 put se_pom i get cb_pb i 551 end 552 put se_poml 0 get cb_n 4 553 end 554 end 555 556 note Check PLAT_OM exists 557 cb_pa_clr 558 for i ulong get se_poml 0 bound 4096 559 cb_pa_ch get se_pom i 560 end 561 fdp = fopen cb_pa 0 get cb_n 3 524288 0 562 if lt fdp 0 563 se_die se_f_badplat 564 end 565 z0 = fclose int fdp 566 567 note Ensure parent directory of OUT exists 568 last_sl = ulong 0 569 has_sl = false 570 for i ulong get se_outl 0 bound 4096 571 if eq get se_out i 47 572 last_sl = i 573 has_sl = true 574 end 575 end 576 if and has_sl gt last_sl 0 577 cb_pa_clr 578 for i ulong last_sl bound 4096 579 cb_pa_ch get se_out i 580 end 581 if not cb_mkdir_p_pa 582 se_die se_f_io 583 end 584 end 585 586 se_compose_all 587 588 note Write temporary composed source beside OUT 589 cb_pa_clr 590 for i ulong get se_outl 0 bound 4096 591 cb_pa_ch get se_out i 592 end 593 cb_pa_tx se_tmpfile 594 if not cb_write_wb_pa 420 595 se_die se_f_io 596 end 597 598 note Compile with OMC 599 for i ulong get se_omcl 0 bound 4096 600 put cb_pc i get se_omc i 601 end 602 cb_pb_clr 603 for i ulong get se_outl 0 bound 4096 604 cb_pb_ch get se_out i 605 end 606 rc = cb_run_omc get se_omcl 0 420 -1 607 z1 = unlink cb_pa 0 get cb_n 3 608 if ne rc 0 609 se_die se_f_omc 610 end 611 612 se_verify_pe 613 ret 0 614 end