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