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/aienos.com/blob/main/public/alpha/wizard.om # aienos.com Source of www.aienos.com, served from my own hardware Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienos.com / public / alpha / wizard.om` 4894 lines · 84223 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note sha256.om: vendored from aien-dev/omega-mv `3364a1dfd0ca50c1b82bf19ba34932d8bc10a7a9` om/sha256/sha256-om2.om 3 note (source sha256 `dbf002dd6aa36585632b9d01d98ac3f0bd2fa0f0475082940de53638847994bb`). Derived mechanically: every "export fn" became "fn", because a 4 note program-mode unit (one with fn main) refuses export (OMEGESE 9.13, error 9). build.sh re-derives 5 note this file from the pinned source and refuses any other difference. 6 note SPDX-License-Identifier: Apache-2.0 7 note sha256-om2.om: FIPS 180-4 SHA-256 in OM-2 (spec/omegese-om2.md, #747/#748, ledger L838). 8 note The four entries are the API of src/sha256.h, exported through omega-bridge ABI v2 as 9 note omega2_sha256_init/update/final/hash; the bridge's generated omega_api.h maps the C names. 10 note 11 note Invariants: 12 note - All hashing state is the caller's 104-byte context (layout shactx below, equal to sha256_ctx 13 note on LP64 AArch64). Nothing else persists between calls, so a byte copy of a live context is an 14 note equivalent context (erratum E3). 15 note - count is the number of bytes absorbed since init, modulo 2^64. buf[0 .. count mod 64) holds the 16 note pending bytes of the current block; the rest of buf is unspecified. state is the chaining value 17 note after the count div 64 whole blocks. 18 note - final reads the context and writes only the digest, so the context is unchanged by it. The 19 note contract promises less (after final the context is unspecified, memory safety only). 20 note - Every branch and every loop count depends only on lengths, never on message bytes (section 8). 21 note - Indices into the unsized input view are checked at run time (trap 3); indices into sized 22 note arrays inside unrolled bodies are constants and checked when compiled. 23 note bridge c-type shactx sha256_ctx 24 note bridge c-define SHA256_DIGEST_SIZE 32 25 note bridge c-define SHA256_BLOCK_SIZE 64 26 om2 27 28 layout shactx 104 29 field state uint 8 at 0 little 30 field count ulong at 32 little 31 field buf uchar 64 at 40 little 32 end 33 34 note K[0..63]: the first 32 bits of the fractional parts of the cube roots of the first 64 primes. 35 note Copied mechanically from seed/qualification/om2/fixtures/sha256-k.dec (tool-computed, never typed). 36 fn kinit k edit uint 64 to void 37 put k 0 0x428a2f98 38 put k 1 0x71374491 39 put k 2 0xb5c0fbcf 40 put k 3 0xe9b5dba5 41 put k 4 0x3956c25b 42 put k 5 0x59f111f1 43 put k 6 0x923f82a4 44 put k 7 0xab1c5ed5 45 put k 8 0xd807aa98 46 put k 9 0x12835b01 47 put k 10 0x243185be 48 put k 11 0x550c7dc3 49 put k 12 0x72be5d74 50 put k 13 0x80deb1fe 51 put k 14 0x9bdc06a7 52 put k 15 0xc19bf174 53 put k 16 0xe49b69c1 54 put k 17 0xefbe4786 55 put k 18 0x0fc19dc6 56 put k 19 0x240ca1cc 57 put k 20 0x2de92c6f 58 put k 21 0x4a7484aa 59 put k 22 0x5cb0a9dc 60 put k 23 0x76f988da 61 put k 24 0x983e5152 62 put k 25 0xa831c66d 63 put k 26 0xb00327c8 64 put k 27 0xbf597fc7 65 put k 28 0xc6e00bf3 66 put k 29 0xd5a79147 67 put k 30 0x06ca6351 68 put k 31 0x14292967 69 put k 32 0x27b70a85 70 put k 33 0x2e1b2138 71 put k 34 0x4d2c6dfc 72 put k 35 0x53380d13 73 put k 36 0x650a7354 74 put k 37 0x766a0abb 75 put k 38 0x81c2c92e 76 put k 39 0x92722c85 77 put k 40 0xa2bfe8a1 78 put k 41 0xa81a664b 79 put k 42 0xc24b8b70 80 put k 43 0xc76c51a3 81 put k 44 0xd192e819 82 put k 45 0xd6990624 83 put k 46 0xf40e3585 84 put k 47 0x106aa070 85 put k 48 0x19a4c116 86 put k 49 0x1e376c08 87 put k 50 0x2748774c 88 put k 51 0x34b0bcb5 89 put k 52 0x391c0cb3 90 put k 53 0x4ed8aa4a 91 put k 54 0x5b9cca4f 92 put k 55 0x682e6ff3 93 put k 56 0x748f82ee 94 put k 57 0x78a5636f 95 put k 58 0x84c87814 96 put k 59 0x8cc70208 97 put k 60 0x90befffa 98 put k 61 0xa4506ceb 99 put k 62 0xbef9a3f7 100 put k 63 0xc67178f2 101 end 102 103 note H(0): the first 32 bits of the fractional parts of the square roots of the first 8 primes 104 note (fixtures/sha256-iv.dec). 105 fn iv s edit uint 8 to void 106 put s 0 0x6a09e667 107 put s 1 0xbb67ae85 108 put s 2 0x3c6ef372 109 put s 3 0xa54ff53a 110 put s 4 0x510e527f 111 put s 5 0x9b05688c 112 put s 6 0x1f83d9ab 113 put s 7 0x5be0cd19 114 end 115 116 note Message schedule of the block m[o .. o+64). w is fresh: its incoming contents are never read. 117 note The compiler proves that every get of w reads an element written earlier in this function 118 note (error 27 otherwise): w[0..16) are the block's big-endian words, w[16..64) the FIPS recurrence. 119 fn sched w edit uint 64 fresh m view uchar * o ulong to void 120 q = ulong 0 121 x = uint 0 122 y = uint 0 123 for i ulong 16 unroll 124 q = add o mul i 4 125 x = uint get m q 126 x = or shl x 8 uint get m add q 1 127 x = or shl x 8 uint get m add q 2 128 put w i or shl x 8 uint get m add q 3 129 end 130 for i ulong 48 unroll 131 x = get w add i 1 132 y = get w add i 14 133 x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3 134 put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10 135 end 136 end 137 138 note The 64 rounds on the chaining value s. One round body, emitted 64 times by unroll; i is a constant 139 note in each copy, so get kt i and get w i need no run-time check. uint arithmetic wraps mod 2^32. 140 note Ch(e,f,g) = (e and f) xor (not e and g) is written g xor (e and (f xor g)); Maj(a,b,c) = 141 note (a and b) xor (a and c) xor (b and c) is written (a and b) or (c and (a or b)). Both are bitwise 142 note identities. h first becomes T1, then T1 + T2, which is the next a; the names then shift by one. 143 note The sums are built a term per line and each Sigma in two lines through t: 12 names are live, and 144 note omc hands out 16 registers with no spilling (error 12 under compiler-s1/s2 for longer lines). 145 fn rounds s edit uint 8 w view uint 64 kt view uint 64 to void 146 a = get s 0 147 b = get s 1 148 c = get s 2 149 d = get s 3 150 e = get s 4 151 f = get s 5 152 g = get s 6 153 h = get s 7 154 t = uint 0 155 for i ulong 64 unroll 156 h = add h get kt i 157 h = add h get w i 158 t = xor rotr e 6 rotr e 11 159 t = xor t rotr e 25 160 h = add h t 161 h = add h xor g and e xor f g 162 d = add d h 163 t = xor rotr a 2 rotr a 13 164 t = xor t rotr a 22 165 h = add h t 166 t = and c or a b 167 h = add h or and a b t 168 t = h 169 h = g 170 g = f 171 f = e 172 e = d 173 d = c 174 c = b 175 b = a 176 a = t 177 end 178 put s 0 add get s 0 a 179 put s 1 add get s 1 b 180 put s 2 add get s 2 c 181 put s 3 add get s 3 d 182 put s 4 add get s 4 e 183 put s 5 add get s 5 f 184 put s 6 add get s 6 g 185 put s 7 add get s 7 h 186 end 187 188 note One block m[o .. o+64) into s. sched and rounds stay calls: inlined, their names would share 189 note one 16-register frame with this function's parameters (no spilling, error 12). 190 fn compress s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * o ulong to void 191 sched w m o 192 rounds s w kt 193 end 194 195 note The whole blocks of m (len m is a multiple of 64 and at most 2^25, so under 2^19 passes). 196 fn run s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * to void 197 for j ulong shr len m 6 198 compress s w kt m shl j 6 199 end 200 end 201 202 note The whole blocks of m (len m a multiple of 64). A rolled loop traps 4 after `1000000` passes 203 note (OMEGESE.md section 2; omc s_for), so m is cut into runs of 2^25 bytes (2^19 blocks): 204 note len m = top * 2^44 + mid * 2^25 + rest, and no loop passes 2^20 times. top reaches `1000000` 205 note only above 1.7e19 bytes, which no AArch64 address space holds. 206 fn blocks s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * to void 207 q = ulong 0 208 for a ulong shr len m 44 209 for b ulong 0x80000 210 run s w kt part m q 0x2000000 211 q = add q 0x2000000 212 end 213 end 214 for b ulong and shr len m 25 0x7ffff 215 run s w kt part m q 0x2000000 216 q = add q 0x2000000 217 end 218 run s w kt part m q sub len m q 219 end 220 221 note Pad the k pending bytes already in p (k < 64; p was all zero past them): 0x80, zeros, and the 222 note 64-bit big-endian bit length of the n-byte message in the last 8 bytes of one or two blocks. 223 fn finish s edit uint 8 w edit uint 64 kt view uint 64 p edit uchar 128 k ulong n ulong to void 224 put p k 0x80 225 e = ulong 64 226 if ge k 56 227 e = 128 228 end 229 bits = shl n 3 230 for i ulong 8 unroll 231 put p sub e add i 1 uchar and shr bits mul i 8 0xff 232 end 233 compress s w kt view p 0 234 if eq e 128 235 compress s w kt view p 64 236 end 237 end 238 239 fn sha256_init c edit shactx to void 240 s = new uint 8 0 241 iv s 242 for i ulong 8 unroll 243 put c state i get s i 244 end 245 put c count 0 246 end 247 248 note k bytes of d from o into the context's buffer at bi (bi + k <= 64). A function of its own: inside 249 note absorb the copy loop needs more than the 16 registers (error 12 under compiler-s4). 250 fn tobuf c edit shactx bi ulong d view uchar * o ulong k ulong to void 251 for i ulong k 252 put c buf add bi i get d add o i 253 end 254 end 255 256 note Whole blocks are hashed straight from d; the bytes that complete a pending block go through blk. 257 fn absorb c edit shactx d view uchar * bi ulong to void 258 n = len d 259 s = new uint 8 0 260 w = new uint 64 0 261 kt = new uint 64 0 262 blk = new uchar 64 0 263 kinit kt 264 for i ulong 8 unroll 265 put s i get c state i 266 end 267 off = ulong 0 268 if gt bi 0 269 off = sub 64 bi 270 for i ulong bi 271 put blk i get c buf i 272 end 273 for i ulong off 274 put blk add bi i get d i 275 end 276 compress s w kt view blk 0 277 end 278 nb = shr sub n off 6 279 blocks s w kt part d off shl nb 6 280 off = add off shl nb 6 281 tobuf c 0 d off sub n off 282 for i ulong 8 unroll 283 put c state i get s i 284 end 285 end 286 287 note Any length, including 0 and >= 2^32. lt n sub 64 bi cannot wrap (bi < 64); add bi n could. 288 fn sha256_update c edit shactx d view uchar * to void 289 n = len d 290 cnt = get c count 291 bi = and cnt 63 292 put c count add cnt n 293 if lt n sub 64 bi 294 tobuf c bi d 0 n 295 ret 296 end 297 absorb c d bi 298 end 299 300 fn sha256_final c edit shactx o out uchar 32 to void 301 s = new uint 8 0 302 w = new uint 64 0 303 kt = new uint 64 0 304 p = new uchar 128 0 305 v = ulong 0 306 kinit kt 307 for i ulong 8 unroll 308 put s i get c state i 309 end 310 cnt = get c count 311 k = and cnt 63 312 for i ulong k 313 put p i get c buf i 314 end 315 finish s w kt p k cnt 316 for i ulong 8 unroll 317 v = ulong get s i 318 for j ulong 4 unroll 319 put o add mul i 4 j uchar and shr v sub 24 mul j 8 0xff 320 end 321 end 322 end 323 324 note Equal to init, update(d), final on a fresh context (section 7), with the state in locals. o may 325 note overlap d: the binding copies o out only after the call returns status 0. 326 fn sha256_hash d view uchar * o out uchar 32 to void 327 s = new uint 8 0 328 w = new uint 64 0 329 kt = new uint 64 0 330 p = new uchar 128 0 331 v = ulong 0 332 kinit kt 333 iv s 334 n = len d 335 nb = shr n 6 336 blocks s w kt part d 0 shl nb 6 337 off = shl nb 6 338 k = sub n off 339 for i ulong k 340 put p i get d add off i 341 end 342 finish s w kt p k n 343 for i ulong 8 unroll 344 v = ulong get s i 345 for j ulong 4 unroll 346 put o add mul i 4 j uchar and shr v sub 24 mul j 8 0xff 347 end 348 end 349 end 350 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 351 note lib.om: the output buffer, numbers, ANSI escapes, paths, files, environment and child 352 note processes shared by every screen of the AienOS wizard. Linux arm64 only; every kernel result is 353 note a count or minus the Linux errno and is checked where it is used. 354 355 global ob uchar 262144 356 global obn ulong 1 357 global pb uchar 4096 358 global pbn ulong 1 359 global rb uchar 524288 360 global rbn ulong 1 361 global hb uchar 1024 362 global hbn ulong 1 363 global rt uchar 1024 364 global rtn ulong 1 365 global pr uchar 512 366 global prn ulong 1 367 global ib uchar 4096 368 global ibn ulong 1 369 global eb uchar 4096 370 global pk uchar 4096 371 global pkn ulong 1 372 global sb uchar 128 373 global ws uchar 8 374 global sn int 64 375 text tslash "/" 376 text t_yes "yes" 377 text tusrbin "/usr/bin/" 378 text tbin "/bin/" 379 380 note Append t to the output buffer. A frame never comes near the 256 KiB cap; past it the 381 note bytes are dropped rather than trapping, and the next flush starts clean. 382 fn emit t view uchar * to void 383 n = get obn 0 384 if gt add n len t len ob 385 ret 386 end 387 for i ulong len t 388 put ob add n i get t i 389 end 390 put obn 0 add n len t 391 end 392 393 fn putb b uchar to void 394 n = get obn 0 395 if lt n len ob 396 put ob n b 397 put obn 0 add n 1 398 end 399 end 400 401 note Decimal digits of v, most significant first. 402 fn num v ulong to void 403 d = new uchar 20 0 404 k = ulong 0 405 x = v 406 while true bound 21 407 put d k uchar add rem x 10 48 408 k = add k 1 409 x = div x 10 410 if eq x 0 411 break 412 end 413 end 414 for i ulong k 415 putb get d sub sub k 1 i 416 end 417 end 418 419 fn snum v long to void 420 if lt v 0 421 putb 45 422 num ulong neg v 423 ret 424 end 425 num ulong v 426 end 427 428 fn numw v ulong w ulong to void 429 x = v 430 k = ulong 1 431 while ge x 10 bound 21 432 x = div x 10 433 k = add k 1 434 end 435 while lt k w bound 64 436 putb 32 437 k = add k 1 438 end 439 num v 440 end 441 442 note Write the whole buffer to fd 1 with a partial-write loop, then empty it. 443 fn flush to long 444 n = get obn 0 445 o = ulong 0 446 while lt o n bound 262145 447 w = write 1 ob o sub n o 448 if le w 0 449 put obn 0 0 450 ret w 451 end 452 o = add o ulong w 453 end 454 put obn 0 0 455 ret long n 456 end 457 458 fn csi to void 459 putb 27 460 putb 91 461 end 462 463 fn mv r ulong c ulong to void 464 csi 465 num r 466 putb 59 467 num c 468 putb 72 469 end 470 471 fn fg r ulong g ulong b ulong to void 472 csi 473 putb 51 474 putb 56 475 putb 59 476 putb 50 477 putb 59 478 num r 479 putb 59 480 num g 481 putb 59 482 num b 483 putb 109 484 end 485 486 fn bg r ulong g ulong b ulong to void 487 csi 488 putb 52 489 putb 56 490 putb 59 491 putb 50 492 putb 59 493 num r 494 putb 59 495 num g 496 putb 59 497 num b 498 putb 109 499 end 500 501 fn sgr0 to void 502 csi 503 putb 48 504 putb 109 505 end 506 507 fn bold to void 508 csi 509 putb 49 510 putb 109 511 end 512 513 note Erase from the cursor to the end of the line. 514 fn eol to void 515 csi 516 putb 75 517 end 518 519 fn cls to void 520 csi 521 putb 50 522 putb 74 523 end 524 525 note Cursor home with no parameters: every animation frame starts with it. 526 fn home to void 527 csi 528 putb 72 529 end 530 531 note Alternate screen and hidden cursor on (true) or the user's screen and cursor back (false). 532 fn scrn on bool to void 533 csi 534 putb 63 535 num 1049 536 if on 537 putb 104 538 csi 539 putb 63 540 num 25 541 putb 108 542 else 543 putb 108 544 csi 545 putb 63 546 num 25 547 putb 104 548 end 549 end 550 551 note The 64-entry sine table, sin(2 pi k / 64) scaled by 1000, computed with Wolfram: 552 note Table[Round[1000*Sin[2 Pi k/64]], {k, 0, 63}]. Only the first quadrant is stored by hand; 553 note the rest follows from sin(pi - x) = sin x and sin(x + pi) = -sin x. 554 fn sinit to void 555 q = new int 17 0 556 put q 1 98 557 put q 2 195 558 put q 3 290 559 put q 4 383 560 put q 5 471 561 put q 6 556 562 put q 7 634 563 put q 8 707 564 put q 9 773 565 put q 10 831 566 put q 11 882 567 put q 12 924 568 put q 13 957 569 put q 14 981 570 put q 15 995 571 put q 16 1000 572 for k ulong 17 573 put sn k get q k 574 put sn sub 32 k get q k 575 end 576 for k ulong 32 577 put sn add k 32 neg get sn k 578 end 579 end 580 581 fn isin k ulong to long 582 ret long get sn and k 63 583 end 584 585 fn icos k ulong to long 586 ret long get sn and add k 16 63 587 end 588 589 note Paths: pb is built piece by piece and handed to the host words with its length pbn. 590 fn pclr to void 591 put pbn 0 0 592 end 593 594 fn pstr t view uchar * to void 595 n = get pbn 0 596 if gt add n len t len pb 597 trap 3 598 end 599 for i ulong len t 600 put pb add n i get t i 601 end 602 put pbn 0 add n len t 603 end 604 605 fn pbyte b uchar to void 606 n = get pbn 0 607 put pb n b 608 put pbn 0 add n 1 609 end 610 611 fn pnum v ulong to void 612 d = new uchar 20 0 613 k = ulong 0 614 x = v 615 while true bound 21 616 put d k uchar add rem x 10 48 617 k = add k 1 618 x = div x 10 619 if eq x 0 620 break 621 end 622 end 623 for i ulong k 624 pbyte get d sub sub k 1 i 625 end 626 end 627 628 fn phome to void 629 for i ulong get hbn 0 630 pbyte get hb i 631 end 632 end 633 634 fn proot to void 635 for i ulong get rtn 0 636 pbyte get rt i 637 end 638 end 639 640 note A probe path: the test-only prefix AIENOS_PROBE_ROOT (empty in normal use) then t. 641 fn pprobe t view uchar * to void 642 pclr 643 for i ulong get prn 0 644 pbyte get pr i 645 end 646 pstr t 647 end 648 649 note Append rb[o .. o+n) to the path. 650 fn prb o ulong n ulong to void 651 for i ulong n 652 pbyte get rb add o i 653 end 654 end 655 656 fn pdrop k ulong to void 657 put pbn 0 sub get pbn 0 k 658 end 659 660 note Stat pb into sb. Returns 0 or minus errno. 661 fn pstat to long 662 ret stat pb 0 get pbn 0 sb 0 128 663 end 664 665 note File type bits of the last stat: 4 directory, 2 character device, 8 regular, 10 link. 666 fn stype to ulong 667 m = or or uint get sb 16 shl uint get sb 17 8 shl uint get sb 18 16 668 ret ulong shr and m 61440 12 669 end 670 671 fn ssize to ulong 672 x = ulong 0 673 for i ulong 8 674 x = or x shl ulong get sb add 48 i mul i 8 675 end 676 ret x 677 end 678 679 fn sino to ulong 680 x = ulong 0 681 for i ulong 8 682 x = or x shl ulong get sb add 8 i mul i 8 683 end 684 ret x 685 end 686 687 fn pexist to bool 688 ret eq pstat 0 689 end 690 691 note Read the whole file named by pb into rb (at most len rb bytes). Returns the count or -errno. 692 fn slurp to long 693 put rbn 0 0 694 fd = fopen pb 0 get pbn 0 524288 0 695 if lt fd 0 696 ret fd 697 end 698 n = ulong 0 699 while lt n len rb bound 524289 700 k = read int fd rb n sub len rb n 701 if lt k 0 702 c = fclose int fd 703 ret k 704 end 705 if eq k 0 706 break 707 end 708 n = add n ulong k 709 end 710 c = fclose int fd 711 put rbn 0 n 712 ret long n 713 end 714 715 note Write rb[0 .. n) to the file named by pb, created or truncated, mode 0644. 716 fn spill n ulong to long 717 fd = fopen pb 0 get pbn 0 525889 420 718 if lt fd 0 719 ret fd 720 end 721 o = ulong 0 722 while lt o n bound 524289 723 k = write int fd rb o sub n o 724 if le k 0 725 c = fclose int fd 726 ret -5 727 end 728 o = add o ulong k 729 end 730 c = fclose int fd 731 ret 0 732 end 733 734 note Does rb start, at offset o, with the bytes of t? 735 fn rbat o ulong t view uchar * to bool 736 if gt add o len t get rbn 0 737 ret false 738 end 739 for i ulong len t 740 if ne get rb add o i get t i 741 ret false 742 end 743 end 744 ret true 745 end 746 747 note First offset at or after o where t occurs in rb, or the length of rb's content when absent. 748 fn rbfind o ulong t view uchar * to ulong 749 n = get rbn 0 750 i = o 751 while lt i n bound 524289 752 if rbat i t 753 ret i 754 end 755 i = add i 1 756 end 757 ret n 758 end 759 760 note Does t occur inside rb[o .. e)? 761 fn rbin o ulong e ulong t view uchar * to bool 762 if lt e len t 763 ret false 764 end 765 i = o 766 while le add i len t e bound 524289 767 if rbat i t 768 ret true 769 end 770 i = add i 1 771 end 772 ret false 773 end 774 775 note Decimal number in rb at o; stops at the first non-digit. 776 fn rbnum o ulong to ulong 777 x = ulong 0 778 i = o 779 while lt i get rbn 0 bound 21 780 c = get rb i 781 if or lt c 48 gt c 57 782 break 783 end 784 x = add mul x 10 ulong sub c 48 785 i = add i 1 786 end 787 ret x 788 end 789 790 note Copy the environment entry KEY=value whose key is k into eb; returns the value length, or 791 note -1 when the key is absent. The value starts at eb[len k + 1]. 792 fn envget k view uchar * to long 793 c = envcnt 794 for i ulong ulong c 795 n = envread i eb 0 len eb 796 if gt n long len k 797 m = true 798 for j ulong len k 799 if ne get eb j get k j 800 m = false 801 end 802 end 803 if and m eq get eb len k 61 804 ret sub n add long len k 1 805 end 806 end 807 end 808 ret -1 809 end 810 811 note Read one line from fd 0 into ib (without its newline). Returns its length, or -1 at end of input. 812 fn rline to long 813 n = ulong 0 814 put ibn 0 0 815 while lt n sub len ib 1 bound 4096 816 k = read 0 ib n 1 817 if le k 0 818 if eq n 0 819 ret -1 820 end 821 break 822 end 823 if eq get ib n 10 824 break 825 end 826 n = add n 1 827 end 828 put ibn 0 n 829 ret long n 830 end 831 832 fn ibis t view uchar * to bool 833 if ne get ibn 0 len t 834 ret false 835 end 836 for i ulong len t 837 if ne get ib i get t i 838 ret false 839 end 840 end 841 ret true 842 end 843 844 note Packed argument lists for execprog: a little-endian u16 count, then u16 length + bytes records. 845 fn pkclr to void 846 put pk 0 0 847 put pk 1 0 848 put pkn 0 2 849 end 850 851 fn pkrec n ulong to ulong 852 c = add or uint get pk 0 shl uint get pk 1 8 1 853 put pk 0 uchar and c 255 854 put pk 1 uchar shr c 8 855 o = get pkn 0 856 put pk o uchar and n 255 857 put pk add o 1 uchar shr n 8 858 put pkn 0 add add o 2 n 859 ret add o 2 860 end 861 862 fn pkstr t view uchar * to void 863 o = pkrec len t 864 for i ulong len t 865 put pk add o i get t i 866 end 867 end 868 869 note The current path pb as one argument. 870 fn pkpath to void 871 o = pkrec get pbn 0 872 for i ulong get pbn 0 873 put pk add o i get pb i 874 end 875 end 876 877 fn pknum v ulong to void 878 pclr 879 pnum v 880 pkpath 881 end 882 883 note Exit status from the 4-byte wait status in ws: the exit code, or 128 + signal. 884 fn wcode to long 885 s = uint get ws 0 886 if ne and s 127 0 887 ret long add and s 127 128 888 end 889 ret long uint get ws 1 890 end 891 892 note Run the packed program in pk with fd 1 and 2 sent to the file named by pb (appended) or, when 893 note pb is empty, inherited. Returns the exit status or a negative errno from fork. 894 fn runpk to long 895 lfd = long -1 896 if gt get pbn 0 0 897 lfd = fopen pb 0 get pbn 0 525377 420 898 if lt lfd 0 899 ret lfd 900 end 901 end 902 pid = fork 903 if lt pid 0 904 ret pid 905 end 906 if eq pid 0 907 if ge lfd 0 908 d = dupfd int lfd 1 0 909 d = dupfd int lfd 2 0 910 end 911 r = execprog pk 0 get pkn 0 912 exit 127 913 end 914 if ge lfd 0 915 c = fclose int lfd 916 end 917 r = waitpid int pid ws 0 4 0 918 if ne r pid 919 ret -10 920 end 921 ret wcode 922 end 923 924 note Run pk with its stdout captured into rb (at most len rb bytes); stdin and stderr are inherited. 925 note Returns the exit status; rbn holds the captured length. 926 fn runcap to long 927 put rbn 0 0 928 r = pipefds ws 0 8 524288 929 if ne r 0 930 ret r 931 end 932 rd = or or uint get ws 0 shl uint get ws 1 8 shl uint get ws 2 16 933 wr = or or uint get ws 4 shl uint get ws 5 8 shl uint get ws 6 16 934 pid = fork 935 if lt pid 0 936 ret pid 937 end 938 if eq pid 0 939 d = dupfd int wr 1 0 940 r = execprog pk 0 get pkn 0 941 exit 127 942 end 943 c = fclose int wr 944 n = ulong 0 945 while lt n len rb bound 524289 946 k = read int rd rb n sub len rb n 947 if le k 0 948 break 949 end 950 n = add n ulong k 951 end 952 c = fclose int rd 953 put rbn 0 n 954 r = waitpid int pid ws 0 4 0 955 if ne r pid 956 ret -10 957 end 958 ret wcode 959 end 960 961 note Find a host helper by name in /usr/bin then /bin; leaves its path in pb. False when absent. 962 fn findbin t view uchar * to bool 963 pclr 964 pstr tusrbin 965 pstr t 966 if eq faccess pb 0 get pbn 0 1 0 967 ret true 968 end 969 pclr 970 pstr tbin 971 pstr t 972 ret eq faccess pb 0 get pbn 0 1 0 973 end 974 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 975 note hole.om: the animated black hole. Each terminal cell shows two square pixels with the upper 976 note half block (U+2580): the foreground colour is the upper pixel, the background the lower one. 977 note No floating point and no trigonometry beyond the 64-entry sine table: the angle around the 978 note hole is the integer "diamond angle" (0..255 for one turn), and every radius is compared squared. 979 980 global gm long 12 981 global tw ulong 1 982 global th ulong 1 983 global tick ulong 1 984 text lb0 "libcuda.so" 985 text lb1 "cuBLAS" 986 text lb2 "nvcc" 987 text lb3 "CUDA toolkit" 988 text lb4 "libcudart" 989 text lb5 "cuDNN" 990 text lb6 "NCCL" 991 text lb7 "TensorRT" 992 text tblk "▀" 993 994 note gm: 0 cx, 1 cy (pixels), 2 R, 3 horizon^2, 4 photon ring^2, 5 disk inner^2, 6 disk outer^2, 995 note 7 glow^2, 8 scene rows, 9 horizon radius, 10 lensed arc^2. 996 fn hgeom rows ulong to void 997 cx = long div get tw 0 2 998 cy = long rows 999 r = cx 1000 if lt cy r 1001 r = cy 1002 end 1003 r = div mul r 95 100 1004 rh = div mul r 44 100 1005 put gm 0 cx 1006 put gm 1 cy 1007 put gm 2 r 1008 put gm 3 mul rh rh 1009 rp = add rh add div r 16 1 1010 put gm 4 mul rp rp 1011 di = div mul rh 135 100 1012 put gm 5 mul di di 1013 ro = div mul r 26 10 1014 lim = div mul cx 92 100 1015 if gt ro lim 1016 ro = lim 1017 end 1018 put gm 6 mul ro ro 1019 gl = div mul rp 160 100 1020 put gm 7 mul gl gl 1021 put gm 8 long rows 1022 put gm 9 rh 1023 lz = div mul rh 150 100 1024 put gm 10 mul lz lz 1025 end 1026 1027 note Diamond angle of (x, y): 0..255 for one counter-clockwise turn, monotone in the true angle. 1028 fn dang x long y long to ulong 1029 ax = x 1030 if lt ax 0 1031 ax = neg ax 1032 end 1033 ay = y 1034 if lt ay 0 1035 ay = neg ay 1036 end 1037 s = add ax ay 1038 if eq s 0 1039 ret 0 1040 end 1041 if ge y 0 1042 if ge x 0 1043 ret ulong div mul 64 ay s 1044 end 1045 ret ulong add 64 div mul 64 ax s 1046 end 1047 if lt x 0 1048 ret ulong add 128 div mul 64 ay s 1049 end 1050 ret ulong add 192 div mul 64 ax s 1051 end 1052 1053 fn pack r long g long b long to ulong 1054 ret or or shl ulong r 16 shl ulong g 8 ulong b 1055 end 1056 1057 note Scale a packed colour by m/1000 and clamp each channel to 255. 1058 fn scale c ulong m long to ulong 1059 r = div mul long and shr c 16 255 m 1000 1060 g = div mul long and shr c 8 255 m 1000 1061 b = div mul long and c 255 m 1000 1062 if gt r 255 1063 r = 255 1064 end 1065 if gt g 255 1066 g = 255 1067 end 1068 if gt b 255 1069 b = 255 1070 end 1071 if lt r 0 1072 r = 0 1073 end 1074 if lt g 0 1075 g = 0 1076 end 1077 if lt b 0 1078 b = 0 1079 end 1080 ret pack r g b 1081 end 1082 1083 note One channel of a mix: (x u + y t) / 256. 1084 fn mixc x long y long u long t long to long 1085 ret div add mul x u mul y t 256 1086 end 1087 1088 note Mix two packed colours: t/256 of b over a. 1089 fn mix a ulong b ulong t long to ulong 1090 u = sub 256 t 1091 r = mixc long and shr a 16 255 long and shr b 16 255 u t 1092 g = mixc long and shr a 8 255 long and shr b 8 255 u t 1093 c = mixc long and a 255 long and b 255 u t 1094 ret pack r g c 1095 end 1096 1097 note Accretion disk at (dx, dyd) with dd2 = dx^2 + dyd^2: hot white at the inner edge through orange 1098 note to violet at the rim, three spiral arms that wind tighter inward, the approaching side brighter. 1099 fn dcol t long to ulong 1100 if ge t 128 1101 ret mix pack 255 132 36 pack 110 28 120 mul sub t 128 2 1102 end 1103 ret mix pack 255 240 210 pack 255 132 36 mul t 2 1104 end 1105 1106 fn dlum dx long dyd long tw2 long to long 1107 p = add div dang dx dyd 4 ulong tw2 1108 p = add p mul get tick 0 2 1109 ret add 640 div mul 360 isin mul p 3 1000 1110 end 1111 1112 fn diskc dx long dyd long dd2 long to ulong 1113 in2 = get gm 5 1114 t = div mul sub dd2 in2 256 add sub get gm 6 in2 1 1115 c = dcol t 1116 i = dlum dx dyd div mul in2 40 add dd2 1 1117 dop = sub 1000 div mul dx 350 add get gm 2 1 1118 ret scale c div mul i dop 1000 1119 end 1120 1121 fn shash x ulong y ulong to ulong 1122 h = xor mul x `374761393` mul y `668265263` 1123 h = mul xor h shr h 13 `1274126177` 1124 ret and shr xor h shr h 16 7 2047 1125 end 1126 1127 fn star x ulong y ulong to ulong 1128 h = shash x y 1129 if ge h 12 1130 ret pack 3 3 10 1131 end 1132 v = long add 70 mul h 15 1133 if eq and shr add get tick 0 mul h 5 3 1 1 1134 v = div mul v 2 3 1135 end 1136 ret pack v v add v 25 1137 end 1138 1139 note The far side of the disk, bent over and under the shadow by the hole's gravity. 1140 fn lensc dx long dy long d2 long to ulong 1141 rp2 = get gm 4 1142 t = div mul sub d2 rp2 256 add sub get gm 10 rp2 1 1143 c = dcol t 1144 ret scale c dlum dx mul dy 4 64 1145 end 1146 1147 note Faint orange halo just outside the photon ring, fading into the stars. 1148 fn glow x ulong y ulong d2 long to ulong 1149 g7 = get gm 7 1150 t = div mul sub g7 d2 200 sub g7 get gm 4 1151 ret mix star x y pack 160 60 20 t 1152 end 1153 1154 note Colour of pixel (x, y) of the scene. 1155 fn px x ulong y ulong to ulong 1156 dx = sub long x get gm 0 1157 dy = sub long y get gm 1 1158 d2 = add mul dx dx mul dy dy 1159 dyd = mul dy 4 1160 dd2 = add mul dx dx mul dyd dyd 1161 indisk = and ge dd2 get gm 5 le dd2 get gm 6 1162 if and indisk ge dy 0 1163 ret diskc dx dyd dd2 1164 end 1165 if lt d2 get gm 3 1166 ret 0 1167 end 1168 if lt d2 get gm 4 1169 f = add 820 div mul 180 isin add div dang dx dy 4 get tick 0 1000 1170 ret scale pack 255 226 170 f 1171 end 1172 if lt d2 get gm 10 1173 ret lensc dx dy d2 1174 end 1175 if indisk 1176 ret diskc dx dyd dd2 1177 end 1178 if lt d2 get gm 7 1179 ret glow x y d2 1180 end 1181 ret star x y 1182 end 1183 1184 fn hpix c ulong top bool to void 1185 r = and shr c 16 255 1186 g = and shr c 8 255 1187 b = and c 255 1188 if top 1189 fg r g b 1190 else 1191 bg r g b 1192 end 1193 end 1194 1195 note Draw the scene rows 1..rows at full terminal width into the output buffer. 1196 fn hdraw rows ulong to void 1197 lf = ulong `16777216` 1198 lb = ulong `16777216` 1199 for row ulong rows 1200 mv add row 1 1 1201 lf = `16777216` 1202 lb = `16777216` 1203 for x ulong get tw 0 1204 a = px x mul row 2 1205 b = px x add mul row 2 1 1206 if ne a lf 1207 hpix a true 1208 lf = a 1209 end 1210 if ne b lb 1211 hpix b false 1212 lb = b 1213 end 1214 emit tblk 1215 end 1216 sgr0 1217 end 1218 end 1219 1220 fn lemit i ulong o ulong k ulong to void 1221 if eq i 0 1222 emit part lb0 o k 1223 end 1224 if eq i 1 1225 emit part lb1 o k 1226 end 1227 if eq i 2 1228 emit part lb2 o k 1229 end 1230 if eq i 3 1231 emit part lb3 o k 1232 end 1233 if eq i 4 1234 emit part lb4 o k 1235 end 1236 if eq i 5 1237 emit part lb5 o k 1238 end 1239 if eq i 6 1240 emit part lb6 o k 1241 end 1242 if eq i 7 1243 emit part lb7 o k 1244 end 1245 end 1246 1247 fn llen i ulong to ulong 1248 if eq i 0 1249 ret len lb0 1250 end 1251 if eq i 1 1252 ret len lb1 1253 end 1254 if eq i 2 1255 ret len lb2 1256 end 1257 if eq i 3 1258 ret len lb3 1259 end 1260 if eq i 4 1261 ret len lb4 1262 end 1263 if eq i 5 1264 ret len lb5 1265 end 1266 if eq i 6 1267 ret len lb6 1268 end 1269 ret len lb7 1270 end 1271 1272 note Label i of the NVIDIA user-space stack spirals inward along the disk plane. It starts green 1273 note at the edge of the picture, turns red as it falls, loses letters at the horizon and is gone. 1274 fn lfrm i ulong to ulong 1275 ret rem add get tick 0 mul i 15 120 1276 end 1277 1278 fn lrad i ulong to long 1279 f = lfrm i 1280 ret div mul mul get gm 2 3 long sub 120 f 240 1281 end 1282 1283 fn lang i ulong to ulong 1284 f = lfrm i 1285 ret add add mul i 8 div mul f 3 2 div mul f f 90 1286 end 1287 1288 fn lpos i ulong to void 1289 r = lrad i 1290 a = lang i 1291 x = add get gm 0 div mul r icos a 1000 1292 y = add get gm 1 div mul mul r isin a 2 5000 1293 rh = get gm 9 1294 if or le r rh lt y 0 1295 ret 1296 end 1297 lshow i r x y 1298 end 1299 1300 fn lshow i ulong r long x long y long to void 1301 rh = get gm 9 1302 n = llen i 1303 k = n 1304 if lt r mul rh 2 1305 k = ulong div mul long n sub r rh rh 1306 end 1307 if eq k 0 1308 ret 1309 end 1310 row = add ulong div y 2 1 1311 if gt row ulong get gm 8 1312 ret 1313 end 1314 col = sub x long div k 2 1315 if or lt col 1 gt add ulong col k get tw 0 1316 ret 1317 end 1318 lpaint i sub n k k lfade r row ulong col 1319 end 1320 1321 fn lfade r long to long 1322 d = mul sub r get gm 9 256 1323 t = div d add mul get gm 2 2 1 1324 if gt t 256 1325 ret 256 1326 end 1327 ret t 1328 end 1329 1330 fn lpaint i ulong d ulong k ulong t long row ulong col ulong to void 1331 c = mix pack 255 70 30 pack 118 185 0 t 1332 mv row col 1333 fg and shr c 16 255 and shr c 8 255 and c 255 1334 bg 0 0 0 1335 bold 1336 lemit i div d 2 k 1337 sgr0 1338 end 1339 1340 fn hlabels to void 1341 for i ulong 8 1342 lpos i 1343 end 1344 end 1345 1346 note One complete frame of the scene: picture, then labels over it. 1347 fn hframe rows ulong to void 1348 hgeom rows 1349 hdraw rows 1350 hlabels 1351 put tick 0 add get tick 0 1 1352 end 1353 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 1354 note doctor.om: what this machine is, read only. Nothing here writes a file or loads a library. 1355 note Every absolute path goes through pprobe, so a test can point the doctor at a fake tree with 1356 note AIENOS_PROBE_ROOT; in normal use that prefix is empty. 1357 1358 const NCHK ulong 8 1359 global dk ulong 8 1360 global dt uchar 1536 1361 global dtn ulong 8 1362 global dci ulong 1 1363 global db uchar 32768 1364 global dv ulong 8 1365 text c_arch "/proc/sys/kernel/arch" 1366 text c_a64 "aarch64" 1367 text c_pci "/sys/bus/pci/devices" 1368 text c_vend "/vendor" 1369 text c_dev "/device" 1370 text c_nvv "0x10de" 1371 text c_gb10 "0x2e12" 1372 text c_dctl "/dev/nvidiactl" 1373 text c_dn0 "/dev/nvidia0" 1374 text c_duvm "/dev/nvidia-uvm" 1375 text c_pdrv "/proc/driver/nvidia/version" 1376 text c_mver "/sys/module/nvidia/version" 1377 text c_good "580.173.02" 1378 text c_mem "/proc/meminfo" 1379 text c_mtot "MemTotal:" 1380 text c_mav "MemAvailable:" 1381 text c_mmap "Mapped:" 1382 text c_lock "/tmp/aien-gb10.lock" 1383 text c_plk "/proc/locks" 1384 text c_cuda "/usr/local/cuda" 1385 text c_lcu "/usr/lib/aarch64-linux-gnu/libcuda.so.1" 1386 text c_smi "/usr/bin/nvidia-smi" 1387 text t_gb " GB" 1388 text t_nl "\n" 1389 text n_arch "CPU" 1390 text n_gpu "GPU" 1391 text n_drv "Driver" 1392 text n_mem "Memory" 1393 text n_disk "Disk" 1394 text n_inst "AienOS" 1395 text n_busy "GPU lock" 1396 text n_nv "NVIDIA" 1397 text d_a1 "arm64 (aarch64), Linux" 1398 text d_a2 "not arm64: this alpha needs Linux arm64" 1399 text d_g1 "NVIDIA GB10 found (PCI 10de:2e12), device nodes present" 1400 text d_g2 "no NVIDIA GB10 found: this alpha runs only on a DGX Spark (GB10)" 1401 text d_g3 "GB10 found but /dev/nvidiactl, /dev/nvidia0 or /dev/nvidia-uvm is missing" 1402 text d_d1 "kernel driver " 1403 text d_d2 " (the version this alpha was built and tested against)" 1404 text d_d3 " found; this alpha only knows 580.173.02, so it stops here" 1405 text d_d4 "no NVIDIA kernel module loaded (/sys/module/nvidia/version missing)" 1406 text d_m1 " GB memory, " 1407 text d_m2 " GB free for a model" 1408 text d_m3 "; another model is using memory, so the first chat waits until it is free" 1409 text d_m4 "; this alpha needs a 128 GB GB10" 1410 text h_df "df" 1411 text h_b1 "-B1" 1412 text h_av "--output=avail" 1413 text d_k1 " free in your home" 1414 text d_k2 "; the model needs " 1415 text d_k3 "unknown free space (df not found); the model needs " 1416 text d_i1 "not installed yet" 1417 text d_i2 "installed: " 1418 text d_i3 ", model verified" 1419 text d_i4 ", model not downloaded yet" 1420 text t_cur "/.local/share/aienos/current" 1421 text d_b1 "the GB10 lock (/tmp/aien-gb10.lock) is not held right now" 1422 text d_b2 "busy: process " 1423 text d_b3 " holds the GB10 lock, so I start no second model" 1424 text d_n1 "found " 1425 text d_n2 "libcuda" 1426 text d_n3 "the CUDA toolkit" 1427 text d_n4 "nvidia-smi" 1428 text d_n5 ": they stay installed and untouched, and AienOS never loads them" 1429 text d_nc ", " 1430 text d_n6 "no NVIDIA user-space libraries found; AienOS does not need them" 1431 text k_ok " ok " 1432 text k_wn " note " 1433 text k_no " no " 1434 text k_in " info " 1435 1436 note Detail line of check i, built with dstr/dnum/drb. 1437 fn dsel i ulong to void 1438 put dci 0 i 1439 put dtn i 0 1440 end 1441 1442 fn dstr t view uchar * to void 1443 i = get dci 0 1444 n = get dtn i 1445 for j ulong len t 1446 if lt add n j 190 1447 put dt add mul i 192 add n j get t j 1448 end 1449 end 1450 m = add n len t 1451 if gt m 190 1452 m = 190 1453 end 1454 put dtn i m 1455 end 1456 1457 fn dbyte b uchar to void 1458 i = get dci 0 1459 n = get dtn i 1460 if lt n 190 1461 put dt add mul i 192 n b 1462 put dtn i add n 1 1463 end 1464 end 1465 1466 fn dnum v ulong to void 1467 d = new uchar 20 0 1468 k = ulong 0 1469 x = v 1470 while true bound 21 1471 put d k uchar add rem x 10 48 1472 k = add k 1 1473 x = div x 10 1474 if eq x 0 1475 break 1476 end 1477 end 1478 for j ulong k 1479 dbyte get d sub sub k 1 j 1480 end 1481 end 1482 1483 note Bytes of rb[o ..) up to the first newline or n bytes. 1484 fn drb o ulong n ulong to void 1485 for j ulong n 1486 if ge add o j get rbn 0 1487 ret 1488 end 1489 c = get rb add o j 1490 if eq c 10 1491 ret 1492 end 1493 dbyte c 1494 end 1495 end 1496 1497 note Size in GB, rounded to one decimal, from a byte count (1 GB = 10^9 bytes). 1498 fn dgb v ulong to void 1499 r = add v `50000000` 1500 dnum div r `1000000000` 1501 dbyte 46 1502 dnum div rem r `1000000000` `100000000` 1503 dstr t_gb 1504 end 1505 1506 fn verdict i ulong k ulong to void 1507 put dk i k 1508 end 1509 1510 note 0 CPU architecture. The binary itself is aarch64 and static, so running at all proves the ISA; 1511 note the kernel's own word is shown when it has one. 1512 fn ckarch to void 1513 dsel 0 1514 pprobe c_arch 1515 n = slurp 1516 if lt n 0 1517 verdict 0 0 1518 dstr d_a1 1519 ret 1520 end 1521 if rbat 0 c_a64 1522 verdict 0 0 1523 dstr d_a1 1524 ret 1525 end 1526 verdict 0 2 1527 dstr d_a2 1528 end 1529 1530 note Is pci device directory entry rb-name a GB10? Builds devices/NAME/vendor and /device. 1531 fn pcidev o ulong n ulong to bool 1532 pprobe c_pci 1533 pbyte 47 1534 for j ulong n 1535 pbyte get db add o j 1536 end 1537 k = get pbn 0 1538 pstr c_vend 1539 r = slurp 1540 if or lt r 0 not rbat 0 c_nvv 1541 ret false 1542 end 1543 put pbn 0 k 1544 pstr c_dev 1545 r = slurp 1546 if lt r 0 1547 ret false 1548 end 1549 ret rbat 0 c_gb10 1550 end 1551 1552 fn dbu16 o ulong to ulong 1553 lo = ulong get db o 1554 hi = ulong get db add o 1 1555 ret or lo shl hi 8 1556 end 1557 1558 note Length of the zero-terminated name at db[o]. 1559 fn dname o ulong to ulong 1560 k = ulong 0 1561 while lt add o k len db bound 300 1562 if eq get db add o k 0 1563 ret k 1564 end 1565 k = add k 1 1566 end 1567 ret k 1568 end 1569 1570 note Count GB10 devices (PCI 10de:2e12) under /sys/bus/pci/devices. 1571 fn gbcount to ulong 1572 pprobe c_pci 1573 fd = fopen pb 0 get pbn 0 540672 0 1574 if lt fd 0 1575 ret 0 1576 end 1577 found = ulong 0 1578 while true bound 4096 1579 n = getdnts int fd db 0 len db 1580 if le n 0 1581 break 1582 end 1583 o = ulong 0 1584 while lt o ulong n bound 32768 1585 rl = dbu16 add o 16 1586 nl = dname add o 19 1587 if and gt nl 0 ne get db add o 19 46 1588 if pcidev add o 19 nl 1589 found = add found 1 1590 end 1591 end 1592 if eq rl 0 1593 break 1594 end 1595 o = add o rl 1596 end 1597 end 1598 c = fclose int fd 1599 ret found 1600 end 1601 1602 fn chrdev t view uchar * to bool 1603 pprobe t 1604 if ne pstat 0 1605 ret false 1606 end 1607 ret eq stype 2 1608 end 1609 1610 fn ckgpu to void 1611 dsel 1 1612 g = gbcount 1613 put dv 1 g 1614 if eq g 0 1615 verdict 1 2 1616 dstr d_g2 1617 ret 1618 end 1619 ok = and and chrdev c_dctl chrdev c_dn0 chrdev c_duvm 1620 pprobe c_pdrv 1621 if or not ok not pexist 1622 verdict 1 2 1623 dstr d_g3 1624 ret 1625 end 1626 verdict 1 0 1627 dstr d_g1 1628 end 1629 1630 fn ckdrv to void 1631 dsel 2 1632 pprobe c_mver 1633 n = slurp 1634 if lt n 0 1635 verdict 2 2 1636 dstr d_d4 1637 ret 1638 end 1639 dstr d_d1 1640 drb 0 40 1641 if rbat 0 c_good 1642 verdict 2 0 1643 dstr d_d2 1644 ret 1645 end 1646 verdict 2 2 1647 dstr d_d3 1648 end 1649 1650 note The kB value after key k in /proc/meminfo (rb), 0 when absent. 1651 fn memkb k view uchar * to ulong 1652 o = rbfind 0 k 1653 if ge o get rbn 0 1654 ret 0 1655 end 1656 o = add o len k 1657 while eq get rb o 32 bound 64 1658 o = add o 1 1659 end 1660 ret rbnum o 1661 end 1662 1663 fn ckmem to void 1664 dsel 3 1665 pprobe c_mem 1666 n = slurp 1667 if lt n 0 1668 verdict 3 2 1669 ret 1670 end 1671 tot = memkb c_mtot 1672 av = memkb c_mav 1673 mp = memkb c_mmap 1674 fr = ulong 0 1675 if gt av mp 1676 fr = sub av mp 1677 end 1678 put dv 3 fr 1679 dgbk tot 1680 dstr d_m1 1681 dgbk fr 1682 dstr d_m2 1683 if lt tot `67108864` 1684 verdict 3 2 1685 dstr d_m4 1686 ret 1687 end 1688 note 35B load need (Core qwen36_batch at `59b05a71`, live load log): 37254 MiB model + 8 rows x 1982.85 MiB 1689 note + 8192 MiB kept free = 61309 MiB = `62780416` kB (Wolfram: Ceiling[37254+8*1982.85+8192]*1024). 1690 if lt fr `62780416` 1691 verdict 3 1 1692 dstr d_m3 1693 ret 1694 end 1695 verdict 3 0 1696 end 1697 1698 fn dgbk kb ulong to void 1699 dnum div mul kb 1024 `1000000000` 1700 end 1701 1702 note Free bytes where the model will live, read with the host's df (Omega has no statfs word yet). 1703 fn dfree to ulong 1704 if not findbin h_df 1705 ret 0 1706 end 1707 pkclr 1708 pkpath 1709 pkstr h_b1 1710 pkstr h_av 1711 pclr 1712 phome 1713 pkpath 1714 r = runcap 1715 if ne r 0 1716 ret 0 1717 end 1718 o = rbfind 0 t_nl 1719 ret rbnum add o 1 1720 end 1721 1722 fn ckdisk need ulong to void 1723 dsel 4 1724 f = dfree 1725 put dv 4 f 1726 if eq f 0 1727 verdict 4 1 1728 dstr d_k3 1729 dgb need 1730 ret 1731 end 1732 dgb f 1733 dstr d_k1 1734 if lt f need 1735 verdict 4 2 1736 dstr d_k2 1737 dgb need 1738 ret 1739 end 1740 verdict 4 0 1741 end 1742 1743 fn ckinst to void 1744 dsel 5 1745 verdict 5 3 1746 pclr 1747 phome 1748 pstr t_cur 1749 n = readlnk pb 0 get pbn 0 rb 0 256 1750 if le n 0 1751 dstr d_i1 1752 ret 1753 end 1754 put rbn 0 ulong n 1755 dstr d_i2 1756 s = ulong 0 1757 for j ulong ulong n 1758 if eq get rb j 47 1759 s = add j 1 1760 end 1761 end 1762 drb s sub ulong n s 1763 if mdone 1764 dstr d_i3 1765 else 1766 dstr d_i4 1767 end 1768 end 1769 1770 note Is the GB10 lock file held? Its inode is looked up in /proc/locks. Returns the holder pid or 0. 1771 fn lockpid to ulong 1772 pprobe c_lock 1773 if ne pstat 0 1774 ret 0 1775 end 1776 ino = sino 1777 pprobe c_plk 1778 n = slurp 1779 if lt n 0 1780 ret 0 1781 end 1782 o = ulong 0 1783 while lt o get rbn 0 bound 524289 1784 e = rbfind o t_nl 1785 p = lkline o e ino 1786 if gt p 0 1787 ret p 1788 end 1789 o = add e 1 1790 end 1791 ret 0 1792 end 1793 1794 note One /proc/locks line in rb[o..e): "1: POSIX ADVISORY WRITE PID MAJ:MIN:INODE START END". 1795 note Returns PID when INODE equals ino. 1796 fn lkline o ulong e ulong ino ulong to ulong 1797 f = ulong 0 1798 i = o 1799 pid = ulong 0 1800 while lt i e bound 4096 1801 if eq get rb i 32 1802 while and lt i e eq get rb i 32 bound 4096 1803 i = add i 1 1804 end 1805 f = add f 1 1806 if eq f 4 1807 pid = rbnum i 1808 end 1809 if eq f 5 1810 ret lkino i e ino pid 1811 end 1812 else 1813 i = add i 1 1814 end 1815 end 1816 ret 0 1817 end 1818 1819 fn lkino i ulong e ulong ino ulong pid ulong to ulong 1820 j = i 1821 c = ulong 0 1822 while and lt j e lt c 2 bound 64 1823 if eq get rb j 58 1824 c = add c 1 1825 end 1826 j = add j 1 1827 end 1828 if eq rbnum j ino 1829 ret pid 1830 end 1831 ret 0 1832 end 1833 1834 fn ckbusy to void 1835 dsel 6 1836 p = lockpid 1837 put dv 6 p 1838 if eq p 0 1839 verdict 6 0 1840 dstr d_b1 1841 ret 1842 end 1843 verdict 6 1 1844 dstr d_b2 1845 dnum p 1846 dstr d_b3 1847 end 1848 1849 fn cknv to void 1850 dsel 7 1851 verdict 7 3 1852 k = ulong 0 1853 pprobe c_lcu 1854 a = pexist 1855 pprobe c_cuda 1856 b = pexist 1857 pprobe c_smi 1858 c = pexist 1859 if not or or a b c 1860 dstr d_n6 1861 ret 1862 end 1863 dstr d_n1 1864 if a 1865 dstr d_n2 1866 end 1867 if and a or b c 1868 dstr d_nc 1869 end 1870 if b 1871 dstr d_n3 1872 end 1873 if and b c 1874 dstr d_nc 1875 end 1876 if c 1877 dstr d_n4 1878 end 1879 dstr d_n5 1880 end 1881 1882 note Run every check. Returns true when the machine can take this alpha (no check failed). 1883 fn doctor need ulong to bool 1884 ckarch 1885 ckgpu 1886 ckdrv 1887 ckmem 1888 ckdisk need 1889 ckinst 1890 ckbusy 1891 cknv 1892 ok = true 1893 for i ulong NCHK 1894 if eq get dk i 2 1895 ok = false 1896 end 1897 end 1898 ret ok 1899 end 1900 1901 fn cname i ulong to void 1902 if eq i 0 1903 emit n_arch 1904 end 1905 if eq i 1 1906 emit n_gpu 1907 end 1908 if eq i 2 1909 emit n_drv 1910 end 1911 if eq i 3 1912 emit n_mem 1913 end 1914 if eq i 4 1915 emit n_disk 1916 end 1917 if eq i 5 1918 emit n_inst 1919 end 1920 if eq i 6 1921 emit n_busy 1922 end 1923 if eq i 7 1924 emit n_nv 1925 end 1926 end 1927 1928 fn ctag k ulong colour bool to void 1929 if colour 1930 if eq k 0 1931 fg 120 220 120 1932 end 1933 if eq k 1 1934 fg 250 200 80 1935 end 1936 if eq k 2 1937 fg 255 90 80 1938 end 1939 if eq k 3 1940 fg 140 170 255 1941 end 1942 end 1943 if eq k 0 1944 emit k_ok 1945 end 1946 if eq k 1 1947 emit k_wn 1948 end 1949 if eq k 2 1950 emit k_no 1951 end 1952 if eq k 3 1953 emit k_in 1954 end 1955 if colour 1956 sgr0 1957 end 1958 end 1959 1960 note One check as one line: [tag] name padded to 8, then the detail. 1961 fn cline i ulong colour bool to void 1962 putb 91 1963 ctag get dk i colour 1964 putb 93 1965 putb 32 1966 cname i 1967 n = cnlen i 1968 while lt n 9 bound 16 1969 putb 32 1970 n = add n 1 1971 end 1972 dline i 1973 end 1974 1975 fn dline i ulong to void 1976 for j ulong get dtn i 1977 putb get dt add mul i 192 j 1978 end 1979 end 1980 1981 fn cnlen i ulong to ulong 1982 if eq i 0 1983 ret len n_arch 1984 end 1985 if eq i 1 1986 ret len n_gpu 1987 end 1988 if eq i 2 1989 ret len n_drv 1990 end 1991 if eq i 3 1992 ret len n_mem 1993 end 1994 if eq i 4 1995 ret len n_disk 1996 end 1997 if eq i 5 1998 ret len n_inst 1999 end 2000 if eq i 6 2001 ret len n_busy 2002 end 2003 ret len n_nv 2004 end 2005 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2006 note net.om: a small HTTP/1.0 client for the engine on 127.0.0.1, written with the native socket 2007 note words, and the JSON string escaping it needs. No TLS: it only ever talks to the loopback door. 2008 note Chat replies are read as a server-sent event stream and shown token by token. 2009 2010 global qb uchar 65536 2011 global qbn ulong 1 2012 global hs uchar 262144 2013 global hsn ulong 1 2014 global ab uchar 65536 2015 global abn ulong 1 2016 global nt ulong 4 2017 text j_open "{\"stream\":true,\"max_tokens\":1024,\"messages\":[" 2018 text j_close "]}" 2019 text j_user "{\"role\":\"user\",\"content\":\"" 2020 text j_asst "{\"role\":\"assistant\",\"content\":\"" 2021 text j_end "\"}" 2022 text j_comma "," 2023 text h_post "POST /v1/chat/completions HTTP/1.0" 2024 text h_host "Host: 127.0.0.1" 2025 text h_ctype "Content-Type: application/json" 2026 text h_clen "Content-Length: " 2027 text h_get1 "GET " 2028 text h_get2 " HTTP/1.0" 2029 text h_data "data: " 2030 text h_done "[DONE]" 2031 text h_cont "\"content\":\"" 2032 text h_health "/health" 2033 2034 fn qstr t view uchar * to void 2035 n = get qbn 0 2036 if gt add n len t len qb 2037 trap 3 2038 end 2039 for i ulong len t 2040 put qb add n i get t i 2041 end 2042 put qbn 0 add n len t 2043 end 2044 2045 fn qcrlf to void 2046 qbyte 13 2047 qbyte 10 2048 end 2049 2050 fn qline t view uchar * to void 2051 qstr t 2052 qcrlf 2053 end 2054 2055 note Offset of the blank line that ends the headers in rb, or the content length when absent. 2056 fn hend to ulong 2057 e4 = new uchar 4 13 2058 put e4 1 10 2059 put e4 3 10 2060 ret rbfind 0 e4 2061 end 2062 2063 fn qbyte b uchar to void 2064 n = get qbn 0 2065 put qb n b 2066 put qbn 0 add n 1 2067 end 2068 2069 fn qnum v ulong to void 2070 d = new uchar 20 0 2071 k = ulong 0 2072 x = v 2073 while true bound 21 2074 put d k uchar add rem x 10 48 2075 k = add k 1 2076 x = div x 10 2077 if eq x 0 2078 break 2079 end 2080 end 2081 for i ulong k 2082 qbyte get d sub sub k 1 i 2083 end 2084 end 2085 2086 note Append one byte to the conversation history hs (JSON already escaped). 2087 fn hbyte b uchar to void 2088 n = get hsn 0 2089 if lt n len hs 2090 put hs n b 2091 put hsn 0 add n 1 2092 end 2093 end 2094 2095 fn hstr t view uchar * to void 2096 for i ulong len t 2097 hbyte get t i 2098 end 2099 end 2100 2101 fn hexd v ulong to uchar 2102 if lt v 10 2103 ret uchar add v 48 2104 end 2105 ret uchar add v 87 2106 end 2107 2108 note The user's line ib, escaped as a JSON string body, appended to the history. 2109 fn hesc to void 2110 for i ulong get ibn 0 2111 c = get ib i 2112 if or eq c 34 eq c 92 2113 hbyte 92 2114 hbyte c 2115 else 2116 if lt c 32 2117 hbyte 92 2118 hbyte 117 2119 hbyte 48 2120 hbyte 48 2121 hbyte hexd ulong shr c 4 2122 hbyte hexd ulong and c 15 2123 else 2124 hbyte c 2125 end 2126 end 2127 end 2128 end 2129 2130 note A loopback TCP connection to port p. Returns the descriptor or -errno. 2131 fn tcp p ulong to long 2132 a = new uchar 16 0 2133 put a 0 2 2134 put a 2 uchar shr p 8 2135 put a 3 uchar and p 255 2136 put a 4 127 2137 put a 7 1 2138 fd = socknew 2 524289 0 2139 if lt fd 0 2140 ret fd 2141 end 2142 r = connect int fd a 0 16 2143 if ne r 0 2144 c = fclose int fd 2145 ret r 2146 end 2147 ret fd 2148 end 2149 2150 fn sendq fd int to long 2151 n = get qbn 0 2152 o = ulong 0 2153 while lt o n bound 65537 2154 k = send fd qb o sub n o 0 2155 if le k 0 2156 ret -5 2157 end 2158 o = add o ulong k 2159 end 2160 ret 0 2161 end 2162 2163 note GET path on 127.0.0.1:p. Returns the HTTP status (200 ..), or a negative error. 2164 fn hget p ulong t view uchar * to long 2165 fd = tcp p 2166 if lt fd 0 2167 ret fd 2168 end 2169 put qbn 0 0 2170 qstr h_get1 2171 qstr t 2172 qline h_get2 2173 qline h_host 2174 qcrlf 2175 r = sendq int fd 2176 if ne r 0 2177 c = fclose int fd 2178 ret r 2179 end 2180 put rbn 0 0 2181 k = waitio int fd 1 `5000000000` 2182 if le k 0 2183 c = fclose int fd 2184 ret -110 2185 end 2186 k = recv int fd rb 0 64 0 2187 c = fclose int fd 2188 if lt k 12 2189 ret -71 2190 end 2191 put rbn 0 ulong k 2192 ret long rbnum 9 2193 end 2194 2195 fn alive p ulong to bool 2196 ret eq hget p h_health 200 2197 end 2198 2199 note Decode one \uXXXX escape's four hex digits at rb[o]. 2200 fn hex4 o ulong to ulong 2201 v = ulong 0 2202 for i ulong 4 2203 c = ulong get rb add o i 2204 d = ulong 0 2205 if and ge c 48 le c 57 2206 d = sub c 48 2207 end 2208 if and ge c 97 le c 102 2209 d = sub c 87 2210 end 2211 if and ge c 65 le c 70 2212 d = sub c 55 2213 end 2214 v = or shl v 4 d 2215 end 2216 ret v 2217 end 2218 2219 note UTF-8 of code point v to the output buffer. 2220 fn utf8 v ulong to void 2221 if lt v 128 2222 putb uchar v 2223 ret 2224 end 2225 if lt v 2048 2226 putb uchar or 192 shr v 6 2227 putb uchar or 128 and v 63 2228 ret 2229 end 2230 if lt v 65536 2231 putb uchar or 224 shr v 12 2232 putb uchar or 128 and shr v 6 63 2233 putb uchar or 128 and v 63 2234 ret 2235 end 2236 putb uchar or 240 shr v 18 2237 putb uchar or 128 and shr v 12 63 2238 putb uchar or 128 and shr v 6 63 2239 putb uchar or 128 and v 63 2240 end 2241 2242 note Print the JSON string body starting at rb[o] up to its closing quote, decoding escapes, and keep 2243 note the raw escaped bytes in ab for the history. Returns the offset after the closing quote. 2244 fn jshow o ulong e ulong to ulong 2245 i = o 2246 while lt i e bound 524289 2247 c = get rb i 2248 if eq c 34 2249 ret add i 1 2250 end 2251 abyte c 2252 if ne c 92 2253 putb c 2254 i = add i 1 2255 else 2256 i = jesc add i 1 e 2257 end 2258 end 2259 ret i 2260 end 2261 2262 fn abyte c uchar to void 2263 n = get abn 0 2264 if lt n len ab 2265 put ab n c 2266 put abn 0 add n 1 2267 end 2268 end 2269 2270 note One escape after a backslash at rb[i]; returns the offset after it. 2271 fn jesc i ulong e ulong to ulong 2272 if ge i e 2273 ret i 2274 end 2275 c = get rb i 2276 abyte c 2277 if eq c 110 2278 putb 10 2279 ret add i 1 2280 end 2281 if eq c 116 2282 putb 9 2283 ret add i 1 2284 end 2285 if eq c 114 2286 ret add i 1 2287 end 2288 if eq c 117 2289 if le add i 5 e 2290 for k ulong 4 2291 abyte get rb add add i 1 k 2292 end 2293 v = hex4 add i 1 2294 if and ge v 55296 lt v 56320 2295 ret jsur i e v 2296 end 2297 utf8 v 2298 ret add i 5 2299 end 2300 ret e 2301 end 2302 putb c 2303 ret add i 1 2304 end 2305 2306 note A high surrogate at rb[i-1..i+5) followed by \uDC00..\uDFFF. 2307 fn jsur i ulong e ulong v ulong to ulong 2308 if and le add i 11 e eq get rb add i 5 92 2309 for k ulong 6 2310 abyte get rb add add i 5 k 2311 end 2312 lo = hex4 add i 7 2313 utf8 add 65536 add shl sub v 55296 10 sub lo 56320 2314 ret add i 11 2315 end 2316 utf8 65533 2317 ret add i 5 2318 end 2319 2320 note Handle the complete event lines in rb[o .. e): print every content delta. Returns the offset of 2321 note the first incomplete line, or the length of rb's content plus one after [DONE]. 2322 fn events o ulong to ulong 2323 i = o 2324 while lt i get rbn 0 bound 524289 2325 nl = rbfind i t_nl 2326 if ge nl get rbn 0 2327 ret i 2328 end 2329 if rbat i h_data 2330 if rbat add i len h_data h_done 2331 ret add get rbn 0 1 2332 end 2333 c = rbfind i h_cont 2334 if lt c nl 2335 if eq get nt 0 0 2336 put nt 1 ulong sub monons long get nt 2 2337 end 2338 put nt 0 add get nt 0 1 2339 x = jshow add c len h_cont nl 2340 w = flush 2341 end 2342 end 2343 i = add nl 1 2344 end 2345 ret i 2346 end 2347 2348 note Send the history as one chat request and stream the answer to the screen. The answer's escaped 2349 note text is kept in ab for the history. Returns 0, a negative error, or the HTTP status when not 200. 2350 fn chatreq p ulong to long 2351 body = add add len j_open get hsn 0 len j_close 2352 put qbn 0 0 2353 qline h_post 2354 qline h_host 2355 qline h_ctype 2356 qstr h_clen 2357 qnum body 2358 qcrlf 2359 qcrlf 2360 if gt add get qbn 0 body len qb 2361 ret -7 2362 end 2363 qstr j_open 2364 for i ulong get hsn 0 2365 qbyte get hs i 2366 end 2367 qstr j_close 2368 fd = tcp p 2369 if lt fd 0 2370 ret fd 2371 end 2372 r = sendq int fd 2373 if ne r 0 2374 c = fclose int fd 2375 ret r 2376 end 2377 put abn 0 0 2378 put nt 0 0 2379 put nt 2 ulong monons 2380 r = chatrx int fd 2381 c = fclose int fd 2382 ret r 2383 end 2384 2385 note Receive the reply: status line, headers, then events until [DONE] or the server closes. 2386 fn chatrx fd int to long 2387 put rbn 0 0 2388 hb2 = ulong 0 2389 st = long 0 2390 o = ulong 0 2391 while lt get rbn 0 len rb bound 524289 2392 k = waitio fd 1 `600000000000` 2393 if le k 0 2394 ret -110 2395 end 2396 k = recv fd rb get rbn 0 sub len rb get rbn 0 0 2397 if le k 0 2398 break 2399 end 2400 put rbn 0 add get rbn 0 ulong k 2401 if eq hb2 0 2402 e = hend 2403 if lt e get rbn 0 2404 hb2 = add e 4 2405 st = long rbnum 9 2406 o = hb2 2407 if ne st 200 2408 ret st 2409 end 2410 end 2411 end 2412 if gt hb2 0 2413 o = events o 2414 if gt o get rbn 0 2415 ret 0 2416 end 2417 end 2418 end 2419 if eq hb2 0 2420 ret -71 2421 end 2422 ret 0 2423 end 2424 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2425 note steps.om: the screens of the wizard (welcome, doctor, plan, consent, install, model, first chat, 2426 note done), the panel under the black hole, the progress bar, file hashing with the Omega SHA-256 unit, 2427 note the model download and the engine's start and stop. 2428 note 2429 note Panel markup: byte 1 gold, 2 plain, 3 green, 4 red, 5 dim, 6 bright. A line ends at byte 10. 2430 2431 global ui ulong 12 2432 global pt uchar 8192 2433 global ptn ulong 1 2434 global pp uchar 256 2435 global ppn ulong 1 2436 global mf uchar 65536 2437 global mfn ulong 1 2438 global mnm uchar 128 2439 global mnn ulong 1 2440 global dg uchar 32 2441 global bs uchar 1024 2442 global bsn ulong 1 2443 global pidb uchar 32 2444 global ppt uchar 4096 2445 global pptn ulong 1 2446 text s_title " Sovereign Intelligence alpha " 2447 text s_step " step " 2448 text s_of " of 8 " 2449 text s_n0 "welcome" 2450 text s_n1 "doctor" 2451 text s_n2 "plan" 2452 text s_n3 "your yes" 2453 text s_n4 "install" 2454 text s_n5 "model" 2455 text s_n6 "first chat" 2456 text s_n7 "done" 2457 text s_omega " written in Omega (.om)" 2458 text t_tbase "~/.local/share/aienos" 2459 text t_files " files" 2460 text t_slash " / " 2461 text m_name "name " 2462 text m_url "url " 2463 text m_bytes "bytes " 2464 text m_files "files " 2465 text t_share "/share/aienos/model.manifest" 2466 text t_base "/.local/share/aienos" 2467 text t_models "/models/" 2468 text t_vfy "/.aienos-verified" 2469 text t_sums "/SHA256SUMS" 2470 text i_l1 "Checking every file of this release with SHA-256." 2471 text i_l2 "The hash runs in Omega (the sha256.om unit shipped beside me)." 2472 text i_ok " files match SHA256SUMS." 2473 text i_bad "A file does not match SHA256SUMS: " 2474 text i_bad2 "This copy is damaged or was changed. Install again with the curl command." 2475 text i_cut "Meanwhile the user-space stack falls into the hole: libcuda, cuBLAS, nvcc." 2476 text i_cut2 "That is the picture only. On disk those stay installed; AienOS just never loads them." 2477 text i_md1 "Created " 2478 text i_md2 " for the model." 2479 text t_mkfail "I could not create the model folder in ~/.local/share/aienos." 2480 text t_wait "working, please wait" 2481 text t_next "Press Enter to continue" 2482 text t_close "Press Enter to close" 2483 text h_curl "curl" 2484 text c_f "-fL" 2485 text c_s "-sS" 2486 text c_r "--retry" 2487 text c_5 "5" 2488 text c_c "-C" 2489 text c_dash "-" 2490 text c_o "-o" 2491 text c_ua "--user-agent" 2492 text c_uav "aienos-wizard/alpha" 2493 text t_part ".part" 2494 text t_curlog "/download.log" 2495 text m_have "The model is already here and verified. Nothing to download." 2496 text m_l1 "Downloading " 2497 text m_l2 "from Hugging Face: " 2498 text m_l3 " in " 2499 text m_l4 " files." 2500 text m_l5 "Every file is checked against its SHA-256 before it is used." 2501 text m_l6 "A cut connection resumes where it stopped. q is not read here; Ctrl+C stops." 2502 text m_fail "The download or a hash check failed. Nothing broken was kept." 2503 text m_fail2 "Run aienos again to resume. The log is ~/.local/share/aienos/download.log." 2504 text m_done "Every model file is downloaded and matches its SHA-256." 2505 text t_dlocal "/.local" 2506 text t_dshare "/share" 2507 2508 note ui: 0 animate, 1 scene rows, 2 step, 3 last frame ns, 4 bytes done, 5 bytes total, 2509 note 6 bar shown, 7 files done, 8 files total, 9 engine pid, 10 frames since step entry. 2510 2511 fn pclear to void 2512 put ptn 0 0 2513 end 2514 2515 fn pl t view uchar * to void 2516 n = get ptn 0 2517 for i ulong len t 2518 if lt add n i len pt 2519 put pt add n i get t i 2520 end 2521 end 2522 m = add n len t 2523 if gt m len pt 2524 m = len pt 2525 end 2526 put ptn 0 m 2527 end 2528 2529 fn pc b uchar to void 2530 n = get ptn 0 2531 if lt n len pt 2532 put pt n b 2533 put ptn 0 add n 1 2534 end 2535 end 2536 2537 fn pln to void 2538 pc 10 2539 end 2540 2541 fn plnum v ulong to void 2542 d = new uchar 20 0 2543 k = ulong 0 2544 x = v 2545 while true bound 21 2546 put d k uchar add rem x 10 48 2547 k = add k 1 2548 x = div x 10 2549 if eq x 0 2550 break 2551 end 2552 end 2553 for i ulong k 2554 pc get d sub sub k 1 i 2555 end 2556 end 2557 2558 note Gigabytes (10^9 bytes) rounded to one decimal. 2559 fn plgb v ulong to void 2560 r = add v `50000000` 2561 plnum div r `1000000000` 2562 pc 46 2563 plnum div rem r `1000000000` `100000000` 2564 pl t_gb 2565 end 2566 2567 note The base folder ~/.local/share/aienos as text in the panel, spelled with a tilde. 2568 fn plbase to void 2569 pl t_tbase 2570 end 2571 2572 fn prompt t view uchar * to void 2573 put ppn 0 0 2574 for i ulong len t 2575 if lt i len pp 2576 put pp i get t i 2577 end 2578 end 2579 put ppn 0 len t 2580 end 2581 2582 fn mark b uchar to void 2583 if eq b 1 2584 fg 255 196 90 2585 end 2586 if eq b 2 2587 sgr0 2588 end 2589 if eq b 3 2590 fg 120 220 120 2591 end 2592 if eq b 4 2593 fg 255 100 90 2594 end 2595 if eq b 5 2596 fg 140 140 165 2597 end 2598 if eq b 6 2599 bold 2600 fg 245 245 255 2601 end 2602 end 2603 2604 fn sname i ulong to void 2605 if eq i 0 2606 emit s_n0 2607 end 2608 if eq i 1 2609 emit s_n1 2610 end 2611 if eq i 2 2612 emit s_n2 2613 end 2614 if eq i 3 2615 emit s_n3 2616 end 2617 if eq i 4 2618 emit s_n4 2619 end 2620 if eq i 5 2621 emit s_n5 2622 end 2623 if eq i 6 2624 emit s_n6 2625 end 2626 if eq i 7 2627 emit s_n7 2628 end 2629 end 2630 2631 fn header row ulong to void 2632 mv row 1 2633 bg 18 16 28 2634 fg 255 196 90 2635 bold 2636 emit s_title 2637 sgr0 2638 bg 18 16 28 2639 fg 200 200 220 2640 emit s_step 2641 num add get ui 2 1 2642 emit s_of 2643 sname get ui 2 2644 fg 120 120 150 2645 emit s_omega 2646 eol 2647 sgr0 2648 end 2649 2650 note Draw the panel lines from row r0 on, at most rows lines, each cleared to the end of the line. 2651 note Put one panel byte at column col (counted from 3); bytes past the terminal's width are 2652 note dropped so a long line never wraps into the next one. Returns the new column. 2653 fn pput b uchar col ulong to ulong 2654 if ge col sub get tw 0 1 2655 ret col 2656 end 2657 putb b 2658 if eq and b 192 128 2659 ret col 2660 end 2661 ret add col 1 2662 end 2663 2664 fn pdraw r0 ulong rows ulong colour bool to void 2665 row = r0 2666 col = ulong 3 2667 i = ulong 0 2668 n = get ptn 0 2669 mv row 3 2670 eol 2671 while lt i n bound 8193 2672 b = get pt i 2673 if eq b 10 2674 row = add row 1 2675 if ge row add r0 rows 2676 ret 2677 end 2678 if colour 2679 sgr0 2680 end 2681 mv row 1 2682 eol 2683 mv row 3 2684 col = 3 2685 else 2686 if lt b 7 2687 if colour 2688 mark b 2689 end 2690 else 2691 col = pput b col 2692 end 2693 end 2694 i = add i 1 2695 end 2696 if colour 2697 sgr0 2698 end 2699 row = add row 1 2700 while lt row add r0 rows bound 256 2701 mv row 1 2702 eol 2703 row = add row 1 2704 end 2705 end 2706 2707 note The progress bar: done/total bytes as a gold bar, the percentage and the file count. 2708 fn pbar row ulong to void 2709 mv row 3 2710 eol 2711 if eq get ui 6 0 2712 ret 2713 end 2714 w = ulong 40 2715 tot = get ui 5 2716 if eq tot 0 2717 tot = 1 2718 end 2719 dn = get ui 4 2720 if gt dn tot 2721 dn = tot 2722 end 2723 f = div mul dn w tot 2724 fg 255 196 90 2725 for i ulong w 2726 if lt i f 2727 bg 255 170 60 2728 else 2729 bg 50 44 70 2730 end 2731 putb 32 2732 end 2733 sgr0 2734 putb 32 2735 numw div mul dn 100 tot 3 2736 putb 37 2737 putb 32 2738 putb 32 2739 num get ui 7 2740 emit t_slash 2741 num get ui 8 2742 emit t_files 2743 end 2744 2745 fn pprompt row ulong colour bool to void 2746 mv row 3 2747 eol 2748 if colour 2749 fg 255 196 90 2750 bold 2751 end 2752 putb 62 2753 putb 32 2754 for i ulong get ppn 0 2755 putb get pp i 2756 end 2757 if colour 2758 sgr0 2759 end 2760 end 2761 2762 note One animation frame: the scene, the header, the panel, the bar and the prompt. 2763 fn frame to void 2764 if eq get ui 0 0 2765 ret 2766 end 2767 sh = get ui 1 2768 t = get th 0 2769 home 2770 hframe sh 2771 header add sh 1 2772 pdraw add sh 2 sub sub t sh 4 true 2773 pbar sub t 1 2774 pprompt t true 2775 w = flush 2776 put ui 3 ulong monons 2777 put ui 10 add get ui 10 1 2778 end 2779 2780 note Draw a frame only when 80 ms have passed since the last one; used inside long loops. 2781 fn tickui to void 2782 if eq get ui 0 0 2783 ret 2784 end 2785 if gt sub ulong monons get ui 3 `80000000` 2786 frame 2787 end 2788 end 2789 2790 note Plain mode (no terminal or too small): print the panel once, without colour or animation. 2791 fn plainout to void 2792 putb 10 2793 emit s_title 2794 emit s_step 2795 num add get ui 2 1 2796 emit s_of 2797 sname get ui 2 2798 putb 10 2799 for i ulong get ptn 0 2800 b = get pt i 2801 if or ge b 7 eq b 10 2802 putb b 2803 end 2804 end 2805 putb 10 2806 if gt get ui 6 0 2807 pbarp 2808 end 2809 w = flush 2810 end 2811 2812 fn pbarp to void 2813 tot = get ui 5 2814 if eq tot 0 2815 tot = 1 2816 end 2817 num div mul get ui 4 100 tot 2818 putb 37 2819 putb 32 2820 num get ui 7 2821 emit t_slash 2822 num get ui 8 2823 emit t_files 2824 putb 10 2825 end 2826 2827 fn enter i ulong to void 2828 put ui 2 i 2829 put ui 6 0 2830 put ui 10 0 2831 if eq get ui 0 1 2832 cls 2833 end 2834 end 2835 2836 note Show the step: a frame, or in plain mode the panel text. 2837 fn show to void 2838 if eq get ui 0 1 2839 frame 2840 else 2841 plainout 2842 end 2843 end 2844 2845 note Wait for one line of input while the hole keeps turning. Returns its length or -1 at end of input. 2846 fn ask to long 2847 if eq get ui 0 1 2848 while true bound 999999 2849 frame 2850 k = waitio 0 1 `80000000` 2851 if ne k 0 2852 break 2853 end 2854 end 2855 else 2856 for i ulong get ppn 0 2857 putb get pp i 2858 end 2859 putb 58 2860 putb 32 2861 w = flush 2862 end 2863 ret rline 2864 end 2865 2866 note Keep animating for about ms milliseconds (plain mode returns at once). 2867 fn hold ms ulong to void 2868 if eq get ui 0 0 2869 ret 2870 end 2871 st = ulong monons 2872 while lt sub ulong monons st mul ms `1000000` bound 100000 2873 frame 2874 s = sleepns `60000000` 2875 end 2876 end 2877 2878 note ---------- SHA-256 of a file, with the Omega unit in sha256.om ---------- 2879 2880 note Hash the file named by pb into dg, adding its bytes to ui 4 as it goes. Returns the size or -errno. 2881 fn fhash to long 2882 c = new uchar 104 0 2883 buf = new uchar `1048576` 0 2884 o = new uchar 32 0 2885 fd = fopen pb 0 get pbn 0 524288 0 2886 if lt fd 0 2887 ret fd 2888 end 2889 sha256_init c 2890 tot = ulong 0 2891 while true bound 999999 2892 k = read int fd buf 0 len buf 2893 if lt k 0 2894 x = fclose int fd 2895 ret k 2896 end 2897 if eq k 0 2898 break 2899 end 2900 sha256_update c part buf 0 ulong k 2901 tot = add tot ulong k 2902 put ui 4 add get ui 4 ulong k 2903 tickui 2904 end 2905 x = fclose int fd 2906 sha256_final c o 2907 for i ulong 32 2908 put dg i get o i 2909 end 2910 ret long tot 2911 end 2912 2913 note Does dg equal the 64 lowercase hex digits at mf[o]? 2914 fn dgis o ulong to bool 2915 for i ulong 32 2916 b = get dg i 2917 if ne get mf add o mul i 2 hexd ulong shr b 4 2918 ret false 2919 end 2920 if ne get mf add add o mul i 2 1 hexd ulong and b 15 2921 ret false 2922 end 2923 end 2924 ret true 2925 end 2926 2927 note ---------- manifests ---------- 2928 2929 note Load the file named by pb into mf. Returns its length or -errno. 2930 fn mload to long 2931 n = slurp 2932 if lt n 0 2933 ret n 2934 end 2935 if gt get rbn 0 len mf 2936 ret -27 2937 end 2938 for i ulong get rbn 0 2939 put mf i get rb i 2940 end 2941 put mfn 0 get rbn 0 2942 ret n 2943 end 2944 2945 fn mfat o ulong t view uchar * to bool 2946 if gt add o len t get mfn 0 2947 ret false 2948 end 2949 for i ulong len t 2950 if ne get mf add o i get t i 2951 ret false 2952 end 2953 end 2954 ret true 2955 end 2956 2957 fn mfnl o ulong to ulong 2958 i = o 2959 while lt i get mfn 0 bound 65537 2960 if eq get mf i 10 2961 ret i 2962 end 2963 i = add i 1 2964 end 2965 ret get mfn 0 2966 end 2967 2968 fn mfnum o ulong to ulong 2969 x = ulong 0 2970 i = o 2971 while lt i get mfn 0 bound 21 2972 c = get mf i 2973 if or lt c 48 gt c 57 2974 ret x 2975 end 2976 x = add mul x 10 ulong sub c 48 2977 i = add i 1 2978 end 2979 ret x 2980 end 2981 2982 note Model manifest lines: "name N", "url U", "bytes B", "files F", then "SHA256 SIZE PATH" per file. 2983 2984 note Offset of the value after key t at the start of a manifest line, or the manifest length. 2985 fn mkey t view uchar * to ulong 2986 o = ulong 0 2987 while lt o get mfn 0 bound 65537 2988 if mfat o t 2989 ret add o len t 2990 end 2991 o = add mfnl o 1 2992 end 2993 ret get mfn 0 2994 end 2995 2996 fn mopen to bool 2997 pclr 2998 proot 2999 pstr t_share 3000 n = mload 3001 if lt n 0 3002 ret false 3003 end 3004 o = mkey m_name 3005 e = mfnl o 3006 if ge o e 3007 ret false 3008 end 3009 put mnn 0 0 3010 for i ulong sub e o 3011 if lt i len mnm 3012 put mnm i get mf add o i 3013 put mnn 0 add i 1 3014 end 3015 end 3016 ret true 3017 end 3018 3019 fn mbytes to ulong 3020 ret mfnum mkey m_bytes 3021 end 3022 3023 fn mfiles to ulong 3024 ret mfnum mkey m_files 3025 end 3026 3027 fn pbase to void 3028 pclr 3029 phome 3030 pstr t_base 3031 end 3032 3033 note pb = ~/.local/share/aienos/models/NAME 3034 fn pmodel to void 3035 pbase 3036 pstr t_models 3037 for i ulong get mnn 0 3038 pbyte get mnm i 3039 end 3040 end 3041 3042 fn mdone to bool 3043 if not mopen 3044 ret false 3045 end 3046 pmodel 3047 pstr t_vfy 3048 ret pexist 3049 end 3050 3051 note ---------- install step: verify this release ---------- 3052 3053 note Verify root/SHA256SUMS ("HEX PATH" lines). Returns the number of files checked, or the 3054 note negative offset+1 of the first bad line. 3055 fn sums to long 3056 pclr 3057 proot 3058 pstr t_sums 3059 n = mload 3060 if lt n 0 3061 ret -1 3062 end 3063 put ui 4 0 3064 put ui 5 sumbytes 3065 put ui 6 1 3066 put ui 7 0 3067 put ui 8 sumcount 3068 o = ulong 0 3069 k = long 0 3070 while lt o get mfn 0 bound 65537 3071 e = mfnl o 3072 if ishex o e 3073 r = sumline o e 3074 if not r 3075 ret neg long add o 1 3076 end 3077 k = add k 1 3078 put ui 7 ulong k 3079 end 3080 o = add e 1 3081 end 3082 ret k 3083 end 3084 3085 fn sumline o ulong e ulong to bool 3086 pclr 3087 proot 3088 pbyte 47 3089 for i ulong sub sub e o 66 3090 pbyte get mf add add o 66 i 3091 end 3092 r = fhash 3093 if lt r 0 3094 ret false 3095 end 3096 ret dgis o 3097 end 3098 3099 fn sumcount to ulong 3100 k = ulong 0 3101 o = ulong 0 3102 while lt o get mfn 0 bound 65537 3103 e = mfnl o 3104 if ishex o e 3105 k = add k 1 3106 end 3107 o = add e 1 3108 end 3109 ret k 3110 end 3111 3112 note Total size of the files listed in SHA256SUMS (for the progress bar). 3113 fn sumbytes to ulong 3114 t = ulong 0 3115 o = ulong 0 3116 while lt o get mfn 0 bound 65537 3117 e = mfnl o 3118 if ishex o e 3119 pclr 3120 proot 3121 pbyte 47 3122 for i ulong sub sub e o 66 3123 pbyte get mf add add o 66 i 3124 end 3125 if eq pstat 0 3126 t = add t ssize 3127 end 3128 end 3129 o = add e 1 3130 end 3131 ret t 3132 end 3133 3134 fn mkdirs to bool 3135 pclr 3136 phome 3137 pstr t_dlocal 3138 r = makedir pb 0 get pbn 0 493 3139 pstr t_dshare 3140 r = makedir pb 0 get pbn 0 493 3141 pbase 3142 r = makedir pb 0 get pbn 0 448 3143 pmodel 3144 pdrop add get mnn 0 1 3145 r = makedir pb 0 get pbn 0 448 3146 pmodel 3147 r = makedir pb 0 get pbn 0 448 3148 ret or eq r 0 eq r -17 3149 end 3150 3151 fn stinst to bool 3152 enter 4 3153 pclear 3154 pl i_l1 3155 pln 3156 pl i_l2 3157 pln 3158 pln 3159 pc 5 3160 pl i_cut 3161 pln 3162 pl i_cut2 3163 pc 2 3164 prompt t_wait 3165 show 3166 k = sums 3167 put ui 6 0 3168 pclear 3169 if lt k 0 3170 pc 4 3171 pl i_bad 3172 pc 2 3173 pln 3174 pl i_bad2 3175 prompt t_close 3176 show 3177 r = ask 3178 ret false 3179 end 3180 pc 3 3181 plnum ulong k 3182 pl i_ok 3183 pc 2 3184 pln 3185 if not mkdirs 3186 pc 4 3187 pl t_mkfail 3188 pc 2 3189 prompt t_close 3190 show 3191 r = ask 3192 ret false 3193 end 3194 pl i_md1 3195 plbase 3196 pl t_models 3197 for i ulong get mnn 0 3198 pc get mnm i 3199 end 3200 pl i_md2 3201 pln 3202 pln 3203 pc 5 3204 pl i_cut 3205 pln 3206 pl i_cut2 3207 pc 2 3208 prompt t_next 3209 hold 1500 3210 show 3211 r = ask 3212 ret ge r 0 3213 end 3214 3215 note ---------- model download ---------- 3216 3217 note Per file line at mf[o..e): "SHA SIZE PATH". Puts the path start in ui 11 and returns the size. 3218 fn fline o ulong e ulong to ulong 3219 s = add o 65 3220 sz = mfnum s 3221 i = s 3222 while and lt i e ne get mf i 32 bound 32 3223 i = add i 1 3224 end 3225 put ui 11 add i 1 3226 ret sz 3227 end 3228 3229 note pb = model folder / PATH (from mf[ui 11 .. e)). 3230 fn pmfile e ulong to void 3231 pmodel 3232 pbyte 47 3233 for i ulong sub e get ui 11 3234 pbyte get mf add get ui 11 i 3235 end 3236 end 3237 3238 note Run curl for URL base + PATH into pb + ".part", animating while it runs. Returns curl's status. 3239 fn fetch e ulong sz ulong to long 3240 pkclr 3241 if not findbin h_curl 3242 ret -2 3243 end 3244 pkpath 3245 pkstr c_f 3246 pkstr c_s 3247 pkstr c_r 3248 pkstr c_5 3249 pkstr c_ua 3250 pkstr c_uav 3251 pkstr c_c 3252 pkstr c_dash 3253 pkstr c_o 3254 pmfile e 3255 pstr t_part 3256 savep 3257 pkpath 3258 pkurl e 3259 pbase 3260 pstr t_curlog 3261 ret runbg sz 3262 end 3263 3264 note The URL: the manifest's url value, then PATH. 3265 fn pkurl e ulong to void 3266 u = mkey m_url 3267 ue = mfnl u 3268 pclr 3269 for i ulong sub ue u 3270 pbyte get mf add u i 3271 end 3272 for i ulong sub e get ui 11 3273 pbyte get mf add get ui 11 i 3274 end 3275 pkpath 3276 end 3277 3278 note Like runpk, but animates and follows the .part file's size while the child runs. 3279 fn runbg sz ulong to long 3280 lfd = fopen pb 0 get pbn 0 525377 384 3281 if lt lfd 0 3282 ret lfd 3283 end 3284 pid = fork 3285 if lt pid 0 3286 ret pid 3287 end 3288 if eq pid 0 3289 d = dupfd int lfd 1 0 3290 d = dupfd int lfd 2 0 3291 r = execprog pk 0 get pkn 0 3292 exit 127 3293 end 3294 c = fclose int lfd 3295 base = get ui 4 3296 while true bound 999999 3297 r = waitpid int pid ws 0 4 1 3298 if eq r pid 3299 ret wcode 3300 end 3301 if lt r 0 3302 ret r 3303 end 3304 put ui 4 add base partsz 3305 frame 3306 s = sleepns `200000000` 3307 end 3308 ret -4 3309 end 3310 3311 note Size of the .part file being written (its path was saved in ppt by fetch). 3312 fn partsz to ulong 3313 r = stat ppt 0 get pptn 0 sb 0 128 3314 if ne r 0 3315 ret 0 3316 end 3317 ret ssize 3318 end 3319 3320 fn savep to void 3321 for i ulong get pbn 0 3322 put ppt i get pb i 3323 end 3324 put pptn 0 get pbn 0 3325 end 3326 3327 fn mstep to bool 3328 enter 5 3329 if not mopen 3330 ret false 3331 end 3332 if mdone 3333 pclear 3334 pc 3 3335 pl m_have 3336 pc 2 3337 pln 3338 prompt t_next 3339 show 3340 r = ask 3341 ret ge r 0 3342 end 3343 pclear 3344 pl m_l1 3345 pc 6 3346 for i ulong get mnn 0 3347 pc get mnm i 3348 end 3349 pc 2 3350 pln 3351 pl m_l2 3352 plgb mbytes 3353 pl m_l3 3354 plnum mfiles 3355 pl m_l4 3356 pln 3357 pl m_l5 3358 pln 3359 pln 3360 pc 5 3361 pl m_l6 3362 pc 2 3363 prompt t_wait 3364 put ui 4 0 3365 put ui 5 mbytes 3366 put ui 6 1 3367 put ui 7 0 3368 put ui 8 mfiles 3369 show 3370 r = mall 3371 put ui 6 0 3372 if not r 3373 pclear 3374 pc 4 3375 pl m_fail 3376 pc 2 3377 pln 3378 pl m_fail2 3379 prompt t_close 3380 show 3381 x = ask 3382 ret false 3383 end 3384 pmodel 3385 pstr t_vfy 3386 put rb 0 111 3387 put rb 1 107 3388 put rb 2 10 3389 x = spill 3 3390 pclear 3391 pc 3 3392 pl m_done 3393 pc 2 3394 pln 3395 prompt t_next 3396 show 3397 x = ask 3398 ret ge x 0 3399 end 3400 3401 note Is mf[o..e) a file line: 64 lowercase hex digits, then a space? 3402 fn ishex o ulong e ulong to bool 3403 if le sub e o 66 3404 ret false 3405 end 3406 for i ulong 64 3407 c = get mf add o i 3408 if not or and ge c 48 le c 57 and ge c 97 le c 102 3409 ret false 3410 end 3411 end 3412 ret eq get mf add o 64 32 3413 end 3414 3415 note Fetch and verify every file of the model manifest. 3416 fn mall to bool 3417 o = ulong 0 3418 while lt o get mfn 0 bound 65537 3419 e = mfnl o 3420 if ishex o e 3421 if not mfile o e 3422 ret false 3423 end 3424 put ui 7 add get ui 7 1 3425 end 3426 o = add e 1 3427 end 3428 ret true 3429 end 3430 3431 note One model file: keep it if it is there and hashes right, else download to .part, check the 3432 note size and hash, then rename it into place. A file that fails its hash is deleted. 3433 fn mfile o ulong e ulong to bool 3434 sz = fline o e 3435 pmfile e 3436 if eq pstat 0 3437 if eq ssize sz 3438 r = fhash 3439 if and ge r 0 dgis o 3440 ret true 3441 end 3442 put ui 4 sub get ui 4 sz 3443 end 3444 r = unlink pb 0 get pbn 0 3445 end 3446 ret mget o e sz 3447 end 3448 3449 fn mget o ulong e ulong sz ulong to bool 3450 for tries ulong 2 3451 pmfile e 3452 pstr t_part 3453 st = get ui 4 3454 if eq pstat 0 3455 if gt ssize sz 3456 r = unlink pb 0 get pbn 0 3457 end 3458 end 3459 c = fetch e sz 3460 put ui 4 st 3461 pmfile e 3462 pstr t_part 3463 if and eq c 0 eq pstat 0 3464 if eq ssize sz 3465 h = fhash 3466 if dgis o 3467 ret mplace e 3468 end 3469 end 3470 end 3471 pmfile e 3472 pstr t_part 3473 r = unlink pb 0 get pbn 0 3474 end 3475 ret false 3476 end 3477 3478 note Rename model/PATH.part to model/PATH with renameat2 (packed list of the two paths). 3479 fn mplace e ulong to bool 3480 pkclr 3481 pmfile e 3482 pstr t_part 3483 pkpath 3484 pmfile e 3485 pkpath 3486 r = renames pk 0 get pkn 0 0 3487 ret eq r 0 3488 end 3489 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3490 note engine.om: start, watch and stop the engine (aien-serve-http, Core ship/motor-l387, engine omega) on 3491 note 127.0.0.1, check from /proc that it loaded no CUDA library, the first-chat screen, the done 3492 note screen, the uninstaller and the rollback. 3493 3494 const PORT ulong 18100 3495 text e_bin "/bin/aien-serve-http" 3496 text e_eng "--engine" 3497 text e_omega "omega" 3498 text e_mdir "--model-dir" 3499 text e_port "--port" 3500 text e_ctx "--max-context" 3501 text e_ctxv "49152" 3502 text e_cap "--max-tokens-cap" 3503 text e_capv "16384" 3504 text e_thk "--thinking" 3505 text e_off "off" 3506 text e_slot "--batch-slots" 3507 text e_slotv "8" 3508 text e_log "/engine.log" 3509 text e_pid "/engine.pid" 3510 text e_null "/dev/null" 3511 text e_proc "/proc/" 3512 text e_exe "/exe" 3513 text e_maps "/maps" 3514 text e_name "aien-serve-http" 3515 text e_cu1 "libcuda" 3516 text e_cu2 "libcublas" 3517 text e_cu3 "libcudart" 3518 text e_cu4 "libnvidia-" 3519 text f_skip1 "I am not starting the engine now: " 3520 text f_mem "another model is using this GB10's memory." 3521 text f_lock "another process holds the GB10 lock." 3522 text f_skip2 "Your model is installed. When the GPU is free, run: aienos chat" 3523 text f_load1 "Starting the engine (Core ship/motor-l387 `59b05a71`) and loading the 35B onto the GB10." 3524 text f_load2 "The first load reads about 37.5 GB, so it can take a few minutes." 3525 text f_fail1 "The engine stopped before it was ready. Its log: ~/.local/share/aienos/engine.log" 3526 text f_q "Say hello in one short sentence, and tell me what you are." 3527 text f_you "you " 3528 text f_ai "model " 3529 text f_ttf "first token after " 3530 text f_ms " ms" 3531 text f_cuda "CUDA libraries in the engine's memory map (/proc/" 3532 text f_cuda2 "/maps): " 3533 text f_run "The engine keeps running on 127.0.0.1:18100. Stop it with: aienos stop" 3534 text d_l1 "Your local model is ready." 3535 text d_l0 "Your model is installed and verified. Start it with aienos chat when the GPU is free." 3536 text d_l2 " aienos chat talk to it in this terminal" 3537 text d_l3 " aienos doctor check this machine again" 3538 text d_l4 " aienos stop stop the engine" 3539 text d_l5 " aienos source where my .om source lives" 3540 text d_l6 " aienos uninstall remove everything AienOS put on this machine" 3541 text d_l7 "OpenAI-style API: http://127.0.0.1:18100/v1/chat/completions" 3542 text u_list "/installed-files" 3543 text u_sure "This removes AienOS from this machine. Type yes to remove it" 3544 text u_keep "--keep-model" 3545 text u_yes "--yes" 3546 text u_done "AienOS is removed. NVIDIA's driver and CUDA were never touched." 3547 text u_kept "The model was kept in ~/.local/share/aienos/models." 3548 text u_no "Nothing was removed." 3549 text u_stop "The engine did not stop; nothing was removed." 3550 text u_dot ".." 3551 text u_mods "models" 3552 text r_rel "/releases" 3553 text r_cur "/current" 3554 text r_new "/current.new" 3555 text r_pre "releases/" 3556 text r_none "There is no other release to roll back to." 3557 text r_ok "current now points to " 3558 3559 note The packed argument list of the live 35B server's command (same flags), on PORT. 3560 fn eargs to void 3561 pkclr 3562 pclr 3563 proot 3564 pstr e_bin 3565 pkpath 3566 pkstr e_eng 3567 pkstr e_omega 3568 pkstr e_mdir 3569 pmodel 3570 pkpath 3571 pkstr e_port 3572 pknum PORT 3573 pkstr e_ctx 3574 pkstr e_ctxv 3575 pkstr e_cap 3576 pkstr e_capv 3577 pkstr e_thk 3578 pkstr e_off 3579 pkstr e_slot 3580 pkstr e_slotv 3581 end 3582 3583 note Start the engine in its own session, output appended to engine.log, pid in engine.pid. 3584 fn estart to long 3585 eargs 3586 pbase 3587 pstr e_log 3588 lfd = fopen pb 0 get pbn 0 525377 384 3589 if lt lfd 0 3590 ret lfd 3591 end 3592 nfd = fopen e_null 0 len e_null 524288 0 3593 pid = fork 3594 if lt pid 0 3595 ret pid 3596 end 3597 if eq pid 0 3598 s = setsid 3599 d = dupfd int nfd 0 0 3600 d = dupfd int lfd 1 0 3601 d = dupfd int lfd 2 0 3602 r = execprog pk 0 get pkn 0 3603 exit 127 3604 end 3605 c = fclose int lfd 3606 c = fclose int nfd 3607 put ui 9 ulong pid 3608 put rbn 0 0 3609 pclr 3610 pnum ulong pid 3611 for i ulong get pbn 0 3612 put rb i get pb i 3613 end 3614 put rb get pbn 0 10 3615 k = add get pbn 0 1 3616 pbase 3617 pstr e_pid 3618 r = spill k 3619 ret pid 3620 end 3621 3622 note The pid in engine.pid when that process is still aien-serve-http, else 0. 3623 fn epid to ulong 3624 pbase 3625 pstr e_pid 3626 n = slurp 3627 if le n 0 3628 ret 0 3629 end 3630 p = rbnum 0 3631 if eq p 0 3632 ret 0 3633 end 3634 pclr 3635 pstr e_proc 3636 pnum p 3637 pstr e_exe 3638 n = readlnk pb 0 get pbn 0 rb 0 4096 3639 if le n 0 3640 ret 0 3641 end 3642 put rbn 0 ulong n 3643 if lt ulong n len e_name 3644 ret 0 3645 end 3646 if rbat sub ulong n len e_name e_name 3647 ret p 3648 end 3649 ret 0 3650 end 3651 3652 note Stop the engine: SIGTERM, then wait up to 120 s for it to go. Returns true when it is gone. 3653 fn estop to bool 3654 p = epid 3655 if eq p 0 3656 ret true 3657 end 3658 r = killpid int p 15 3659 for i ulong 1200 3660 x = waitpid int p ws 0 4 1 3661 if eq epid 0 3662 pbase 3663 pstr e_pid 3664 x = unlink pb 0 get pbn 0 3665 ret true 3666 end 3667 s = sleepns `100000000` 3668 end 3669 ret false 3670 end 3671 3672 note Count the CUDA user-space libraries in /proc/PID/maps (libcuda, libcublas, libcudart, 3673 note libnvidia-*). Returns the count, or -1 when the maps could not be read. 3674 fn ecuda p ulong to long 3675 pclr 3676 pstr e_proc 3677 pnum p 3678 pstr e_maps 3679 n = slurp 3680 if lt n 0 3681 ret -1 3682 end 3683 k = long 0 3684 o = ulong 0 3685 while lt o get rbn 0 bound 524289 3686 e = rbfind o t_nl 3687 if culine o e 3688 k = add k 1 3689 end 3690 o = add e 1 3691 end 3692 ret k 3693 end 3694 3695 fn culine o ulong e ulong to bool 3696 a = or rbin o e e_cu1 rbin o e e_cu2 3697 b = or rbin o e e_cu3 rbin o e e_cu4 3698 ret or a b 3699 end 3700 3701 note Wait for the engine's /health while the hole turns. Gives up after limit seconds or when the 3702 note process exits. Returns true when it answers. 3703 fn ewait limit ulong to bool 3704 st = ulong monons 3705 p = get ui 9 3706 while lt sub ulong monons st mul limit `1000000000` bound 999999 3707 if alive PORT 3708 ret true 3709 end 3710 x = waitpid int p ws 0 4 1 3711 if eq x long p 3712 ret false 3713 end 3714 put ui 4 div sub ulong monons st `1000000000` 3715 for k ulong 20 3716 frame 3717 s = sleepns `100000000` 3718 end 3719 end 3720 ret false 3721 end 3722 3723 fn ckskip to bool 3724 if eq get dk 6 1 3725 pl f_skip1 3726 pl f_lock 3727 ret true 3728 end 3729 if eq get dk 3 1 3730 pl f_skip1 3731 pl f_mem 3732 ret true 3733 end 3734 ret false 3735 end 3736 3737 note The first-chat step. Returns false only when the engine failed to come up. 3738 fn stchat to bool 3739 enter 6 3740 pclear 3741 put ui 11 0 3742 if ckskip 3743 pln 3744 pln 3745 pl f_skip2 3746 prompt t_next 3747 show 3748 r = ask 3749 ret true 3750 end 3751 if not alive PORT 3752 pl f_load1 3753 pln 3754 pl f_load2 3755 prompt t_wait 3756 put ui 6 0 3757 show 3758 p = estart 3759 if lt p 0 3760 ret false 3761 end 3762 if not ewait 2400 3763 pclear 3764 pc 4 3765 pl f_fail1 3766 pc 2 3767 prompt t_close 3768 show 3769 r = ask 3770 ret false 3771 end 3772 end 3773 put ui 11 1 3774 firstq 3775 ret true 3776 end 3777 3778 note Ask the first question and stream the answer under the picture, then show the evidence lines. 3779 fn firstq to void 3780 put hsn 0 0 3781 hstr j_user 3782 put ibn 0 len f_q 3783 for i ulong len f_q 3784 put ib i get f_q i 3785 end 3786 hesc 3787 hstr j_end 3788 pclear 3789 pc 5 3790 pl f_you 3791 pc 2 3792 pl f_q 3793 pln 3794 pc 1 3795 pl f_ai 3796 pc 2 3797 prompt t_wait 3798 show 3799 if eq get ui 0 1 3800 mv add get ui 1 4 10 3801 end 3802 r = chatreq PORT 3803 w = flush 3804 ftail 3805 end 3806 3807 fn ftail to void 3808 pclear 3809 pc 3 3810 pl f_ttf 3811 plnum div get nt 1 `1000000` 3812 pl f_ms 3813 pc 2 3814 pln 3815 p = epid 3816 if gt p 0 3817 pl f_cuda 3818 plnum p 3819 pl f_cuda2 3820 c = ecuda p 3821 if eq c 0 3822 pc 3 3823 end 3824 plnum ulong c 3825 pc 2 3826 pln 3827 end 3828 pl f_run 3829 prompt t_next 3830 if eq get ui 0 1 3831 pdraw sub get th 0 4 3 true 3832 pprompt get th 0 true 3833 x = flush 3834 else 3835 plainout 3836 end 3837 r = rline 3838 end 3839 3840 fn stdone ready bool to void 3841 enter 7 3842 pclear 3843 pc 3 3844 if ready 3845 pl d_l1 3846 else 3847 pl d_l0 3848 end 3849 pc 2 3850 pln 3851 pln 3852 pl d_l2 3853 pln 3854 pl d_l3 3855 pln 3856 pl d_l4 3857 pln 3858 pl d_l5 3859 pln 3860 pl d_l6 3861 pln 3862 pln 3863 pc 5 3864 pl d_l7 3865 pc 2 3866 prompt t_close 3867 show 3868 r = ask 3869 end 3870 3871 note ---------- uninstall ---------- 3872 3873 note Is pb inside the home folder: HOME + "/" + something, with no ".." component? 3874 fn inhome to bool 3875 h = get hbn 0 3876 if le get pbn 0 add h 1 3877 ret false 3878 end 3879 if le h 1 3880 ret false 3881 end 3882 for i ulong h 3883 if ne get pb i get hb i 3884 ret false 3885 end 3886 end 3887 if ne get pb h 47 3888 ret false 3889 end 3890 for i ulong sub get pbn 0 1 3891 if and eq get pb i 46 eq get pb add i 1 46 3892 ret false 3893 end 3894 end 3895 ret true 3896 end 3897 3898 note Unlink every path in installed-files that lies inside the home folder. 3899 fn ulist to void 3900 pbase 3901 pstr u_list 3902 n = mload 3903 if lt n 0 3904 ret 3905 end 3906 o = ulong 0 3907 while lt o get mfn 0 bound 65537 3908 e = mfnl o 3909 pclr 3910 for i ulong sub e o 3911 pbyte get mf add o i 3912 end 3913 if inhome 3914 r = unlink pb 0 get pbn 0 3915 end 3916 o = add e 1 3917 end 3918 end 3919 3920 note Remove the tree at pb (not following links). depth guards the recursion; keep skips the 3921 note models folder at the top level. 3922 fn rmt depth ulong keep bool to void 3923 d = new uchar 8192 0 3924 if gt depth 32 3925 ret 3926 end 3927 for pass ulong 3 3928 fd = fopen pb 0 get pbn 0 573440 0 3929 if lt fd 0 3930 r = unlink pb 0 get pbn 0 3931 ret 3932 end 3933 while true bound 100000 3934 n = getdnts int fd d 0 8192 3935 if le n 0 3936 break 3937 end 3938 o = ulong 0 3939 while lt o ulong n bound 8192 3940 o = rment d o depth keep 3941 end 3942 end 3943 c = fclose int fd 3944 r = rmdir pb 0 get pbn 0 3945 if or eq r 0 eq r -2 3946 ret 3947 end 3948 end 3949 end 3950 3951 note One directory entry at d[o]: remove it (recursing into directories). Returns the next offset. 3952 fn rment d view uchar 8192 o ulong depth ulong keep bool to ulong 3953 rl = or ulong get d add o 16 shl ulong get d add o 17 8 3954 if eq rl 0 3955 ret 8192 3956 end 3957 k = ulong 0 3958 while ne get d add add o 19 k 0 bound 256 3959 k = add k 1 3960 end 3961 if isdot d add o 19 k 3962 ret add o rl 3963 end 3964 if and and keep eq depth 0 isname d add o 19 k 3965 ret add o rl 3966 end 3967 sv = get pbn 0 3968 pbyte 47 3969 for i ulong k 3970 pbyte get d add add o 19 i 3971 end 3972 if eq get d add o 18 4 3973 rmt add depth 1 keep 3974 else 3975 r = unlink pb 0 get pbn 0 3976 end 3977 put pbn 0 sv 3978 ret add o rl 3979 end 3980 3981 fn isdot d view uchar 8192 o ulong k ulong to bool 3982 if ne get d o 46 3983 ret false 3984 end 3985 if eq k 1 3986 ret true 3987 end 3988 ret and eq k 2 eq get d add o 1 46 3989 end 3990 3991 fn isname d view uchar 8192 o ulong k ulong to bool 3992 if ne k len u_mods 3993 ret false 3994 end 3995 for i ulong k 3996 if ne get d add o i get u_mods i 3997 ret false 3998 end 3999 end 4000 ret true 4001 end 4002 4003 note aienos uninstall [--keep-model] [--yes] 4004 fn uninst keep bool yes bool to int 4005 if not yes 4006 emit u_sure 4007 putb 58 4008 putb 32 4009 w = flush 4010 n = rline 4011 if not ibis t_yes 4012 emit u_no 4013 putb 10 4014 w = flush 4015 ret 0 4016 end 4017 end 4018 if not estop 4019 emit u_stop 4020 putb 10 4021 w = flush 4022 ret 1 4023 end 4024 ulist 4025 pbase 4026 rmt 0 keep 4027 emit u_done 4028 putb 10 4029 if keep 4030 emit u_kept 4031 putb 10 4032 end 4033 w = flush 4034 ret 0 4035 end 4036 4037 note ---------- rollback ---------- 4038 4039 note aienos rollback: point current at the newest other release in releases/. 4040 fn rollbk to int 4041 best = new uchar 256 0 4042 pbase 4043 pstr r_cur 4044 n = readlnk pb 0 get pbn 0 rb 0 512 4045 put rbn 0 0 4046 if gt n 0 4047 put rbn 0 ulong n 4048 end 4049 bn = rpick best 4050 if eq bn 0 4051 emit r_none 4052 putb 10 4053 w = flush 4054 ret 1 4055 end 4056 ret rswap best bn 4057 end 4058 4059 note Pick the greatest release name that is not the current target (rb holds the link text). 4060 fn rpick best edit uchar 256 to ulong 4061 d = new uchar 8192 0 4062 bn = ulong 0 4063 pbase 4064 pstr r_rel 4065 fd = fopen pb 0 get pbn 0 540672 0 4066 if lt fd 0 4067 ret 0 4068 end 4069 n = getdnts int fd d 0 8192 4070 c = fclose int fd 4071 if le n 0 4072 ret 0 4073 end 4074 o = ulong 0 4075 while lt o ulong n bound 8192 4076 rl = or ulong get d add o 16 shl ulong get d add o 17 8 4077 if eq rl 0 4078 break 4079 end 4080 bn = rcand d add o 19 best bn 4081 o = add o rl 4082 end 4083 ret bn 4084 end 4085 4086 note Consider entry name d[o..]: keep it in best when it is greater than best and not current. 4087 fn rcand d view uchar 8192 o ulong best edit uchar 256 bn ulong to ulong 4088 k = ulong 0 4089 while and ne get d add o k 0 lt k 200 bound 256 4090 k = add k 1 4091 end 4092 if eq get d o 46 4093 ret bn 4094 end 4095 if and eq get rbn 0 add len r_pre k rbat len r_pre part d o k 4096 ret bn 4097 end 4098 if not gtname d o k best bn 4099 ret bn 4100 end 4101 for i ulong k 4102 put best i get d add o i 4103 end 4104 ret k 4105 end 4106 4107 fn gtname d view uchar 8192 o ulong k ulong best view uchar 256 bn ulong to bool 4108 for i ulong k 4109 if ge i bn 4110 ret true 4111 end 4112 a = get d add o i 4113 b = get best i 4114 if ne a b 4115 ret gt a b 4116 end 4117 end 4118 ret false 4119 end 4120 4121 fn rswap best view uchar 256 bn ulong to int 4122 pkclr 4123 pclr 4124 pstr r_pre 4125 for i ulong bn 4126 pbyte get best i 4127 end 4128 pkpath 4129 pbase 4130 pstr r_new 4131 x = unlink pb 0 get pbn 0 4132 pkpath 4133 r = symlnk pk 0 get pkn 0 4134 if ne r 0 4135 ret 1 4136 end 4137 pkclr 4138 pbase 4139 pstr r_new 4140 pkpath 4141 pbase 4142 pstr r_cur 4143 pkpath 4144 r = renames pk 0 get pkn 0 0 4145 if ne r 0 4146 ret 1 4147 end 4148 emit r_ok 4149 emit r_pre 4150 for i ulong bn 4151 putb get best i 4152 end 4153 putb 10 4154 w = flush 4155 ret 0 4156 end 4157 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 4158 note main.om: the aienos command. With no argument (or "wizard") it runs the full-screen wizard; 4159 note "doctor", "chat", "start", "stop", "verify", "source", "about", "uninstall" and "rollback" are the 4160 note small commands beside it. Build: concatenate sha256.om lib.om hole.om doctor.om net.om steps.om 4161 note engine.om main.om, in that order, and compile the result with the pinned omc (see build.sh). 4162 4163 text v_tag "alpha-`20261026`.2" 4164 text a_l1 "Sovereign Intelligence alpha-`20261026`.2: the installer and the aienos command" 4165 text a_l2 "written in Omega (.om), compiled by omc sha256 `befb8199db8c4bca188a494dfaac2a6f0ee5c36fcea11188c75666c55fce8a1d`" 4166 text a_l3 " (aien-dev/omega-mv `3364a1dfd0ca50c1b82bf19ba34932d8bc10a7a9`, seed/out/omc)" 4167 text a_l4 "engine: aien-serve-http sha256 `19173f9ec3b609fe79af644f84741d8808b92ea8eb3ecec4bc945af6f22b3aeb`," 4168 text a_l5 " the build that serves the Spark's 35B: aien-dev/aien-sovereign-core-mv branch ship/motor-l387" 4169 text a_l6 " commit `59b05a71a33e4a2f1324db2f2b6407ee82b8c2c3` (a development build, not a Core release tag)" 4170 text a_l7 " evidence: Core evidence/l387-motor-ship (merge train 20261022T0244Z-`bfc41659`, timing runs)" 4171 text a_l8 "GPU path: the engine's statically linked libomega_gpu.a (omega ship/motor-l387 `6de999da`) talks to" 4172 text a_l9 " /dev/nvidiactl, /dev/nvidia0 and /dev/nvidia-uvm. There is no separate CUDA++ runtime." 4173 text a_l10 "model: Qwen/Qwen3.6-35B-A3B-FP8 revision `95a723d08a9490559dae23d0cff1d9466213d989` (37.5 GB)" 4174 text a_l11 " This is the only model offered. A 27B is to come; it is not offered in this release." 4175 text a_l12 "evidence: this engine binary serving the 35B on a GB10 EXERCISED (it is the live server's build);" 4176 text a_l13 " this installer's GB10 install and first token, and the 3x physical qualification: NOT_RUN." 4177 text a_l14 "signature: Ed25519 alpha release key `ff949504b427680039d53c33c85c448546b57d590eb1ecee3bb2ed6c2eaaf54a`" 4178 text a_l15 " (an alpha key; it is rotated to a ceremony key before beta)" 4179 text s_l1 "My Omega source ships with this release:" 4180 text s_l2 "/share/aienos/wizard/" 4181 text s_l3 " sha256.om lib.om hole.om doctor.om net.om steps.om engine.om main.om" 4182 text s_l4 "/share/aienos/aienos.om" 4183 text s_l5 " the same files concatenated in build order: one unit, one compile" 4184 text s_l6 "Also online: https://www.aienos.com/alpha/ and https://github.com/aien-dev/sovereign-intelligence" 4185 text w_l1 "Welcome. I am Drake, and this is Sovereign Intelligence, the AienOS alpha." 4186 text w_l2 "This installer is written in Omega, my own language. It sets up a local model on" 4187 text w_l3 "your DGX Spark that runs on my own engine: no CUDA toolkit, no libcuda, no cuBLAS." 4188 text w_l4 "NVIDIA's kernel driver stays. Everything else NVIDIA ships stays installed, unused." 4189 text w_l5 "Next: doctor, plan, your yes, install, model, first chat. Nothing changes before your yes." 4190 text w_l6 "Type about for versions and evidence, source for my .om source, q to quit." 4191 text w_go "Press Enter to run the doctor" 4192 text x_l1 "This alpha runs on Linux arm64 with an NVIDIA GB10 (DGX Spark) only." 4193 text x_l2 "Here is what is coming: https://www.aienos.com/alpha/" 4194 text x_l3 "I changed nothing. The files the installer unpacked go away with: aienos uninstall" 4195 text p_l1 "Here is exactly what changes, all inside your home folder:" 4196 text p_l2 "/releases/" 4197 text p_l3 " this release, already unpacked and checked" 4198 text p_l4 "/models/" 4199 text p_l5 "~/.local/bin/aienos, the menu entry and the desktop icon (already there)" 4200 text p_l6 "/engine.log the engine's log, when it runs" 4201 text p_l7 "Not touched: NVIDIA's driver, the CUDA toolkit, libcuda, cuBLAS, /usr, /etc. No sudo." 4202 text p_l8 "Undo everything at any time: aienos uninstall" 4203 text p_l9 " the model: " 4204 text p_ok "Press Enter for the last question" 4205 text c_l1 "Type yes to begin. Anything else stops here, and nothing changes." 4206 text c_q "yes or no" 4207 text c_stop "Stopped. Nothing was changed." 4208 text c_fail "Stopped. Run aienos again once the problem above is fixed; it picks up where it left off." 4209 text t_q "q" 4210 text t_about "about" 4211 text t_source "source" 4212 text t_probe "AIENOS_PROBE_ROOT" 4213 text t_home "HOME" 4214 text t_plain "--plain" 4215 text t_exe "/proc/self/exe" 4216 text h_stty "stty" 4217 text h_size "size" 4218 text k_wiz "wizard" 4219 text k_doc "doctor" 4220 text k_chat "chat" 4221 text k_start "start" 4222 text k_stop "stop" 4223 text k_vfy "verify" 4224 text k_unin "uninstall" 4225 text k_roll "rollback" 4226 text k_help "usage: aienos [wizard [--plain] | doctor | chat | start | stop | verify | source | about | uninstall [--keep-model] [--yes] | rollback]" 4227 text n_nohome "HOME is not set; I cannot tell where to install." 4228 text n_badrt "I cannot find my own folder (/proc/self/exe)." 4229 text n_vok " files match SHA256SUMS" 4230 text n_vbad "a file does not match SHA256SUMS" 4231 text n_start "engine started, pid " 4232 text n_ready "engine ready on http://127.0.0.1:18100/v1" 4233 text n_nostrt "engine did not become ready; see ~/.local/share/aienos/engine.log" 4234 text n_stopd "engine stopped" 4235 text n_chat1 "aienos chat: type a message and press Enter. /bye leaves." 4236 text n_bye "/bye" 4237 text n_you "you> " 4238 text n_ai "model> " 4239 text n_err "request failed: " 4240 text t_sp " " 4241 4242 note argument i into ib; returns its length or -1. 4243 fn arg i ulong to long 4244 if ge i ulong argcnt 4245 ret -1 4246 end 4247 n = argread i ib 0 len ib 4248 if lt n 0 4249 ret -1 4250 end 4251 put ibn 0 ulong n 4252 ret n 4253 end 4254 4255 note HOME, the probe prefix and this release's folder (the parent of bin/aienos). 4256 fn setup to bool 4257 sinit 4258 n = envget t_home 4259 if le n 0 4260 ret false 4261 end 4262 for i ulong ulong n 4263 put hb i get eb add len t_home add i 1 4264 end 4265 put hbn 0 ulong n 4266 n = envget t_probe 4267 if gt n 0 4268 for i ulong ulong n 4269 put pr i get eb add len t_probe add i 1 4270 end 4271 put prn 0 ulong n 4272 end 4273 ret selfdir 4274 end 4275 4276 fn selfdir to bool 4277 n = readlnk t_exe 0 len t_exe rt 0 len rt 4278 if or le n 0 ge n long len rt 4279 ret false 4280 end 4281 k = ulong n 4282 s = ulong 0 4283 for pass ulong 2 4284 while and gt k 0 ne get rt sub k 1 47 bound 1024 4285 k = sub k 1 4286 end 4287 if gt k 0 4288 k = sub k 1 4289 end 4290 end 4291 put rtn 0 k 4292 ret gt k 0 4293 end 4294 4295 note Terminal: animate when stdin and stdout are character devices and stty reports at least 4296 note 64 columns and 22 rows; the picture takes what the 12-line panel leaves. The size comes from the host's stty (Omega has no window-size word yet). 4297 fn term plain bool to void 4298 put ui 0 0 4299 put tw 0 80 4300 put th 0 24 4301 if plain 4302 ret 4303 end 4304 r = fstat 0 sb 0 128 4305 if or ne r 0 ne stype 2 4306 ret 4307 end 4308 r = fstat 1 sb 0 128 4309 if or ne r 0 ne stype 2 4310 ret 4311 end 4312 if not findbin h_stty 4313 ret 4314 end 4315 pkclr 4316 pkpath 4317 pkstr h_size 4318 r = runcap 4319 if ne r 0 4320 ret 4321 end 4322 rows = rbnum 0 4323 sp = rbfind 0 t_sp 4324 cols = rbnum add sp 1 4325 if or lt cols 64 lt rows 22 4326 ret 4327 end 4328 if gt cols 400 4329 cols = 400 4330 end 4331 put tw 0 cols 4332 put th 0 rows 4333 note The panel under the picture keeps 12 lines: the plan and the doctor must fit whole. 4334 sh = ulong 6 4335 if gt rows 22 4336 sh = sub rows 16 4337 end 4338 if gt sh 30 4339 sh = 30 4340 end 4341 put ui 1 sh 4342 put ui 0 1 4343 end 4344 4345 fn plines to void 4346 pl w_l1 4347 pln 4348 pln 4349 pl w_l2 4350 pln 4351 pl w_l3 4352 pln 4353 pl w_l4 4354 pln 4355 pln 4356 pl w_l5 4357 pln 4358 pc 5 4359 pl w_l6 4360 pc 2 4361 end 4362 4363 fn about to void 4364 pl a_l1 4365 pln 4366 pl a_l2 4367 pln 4368 pl a_l3 4369 pln 4370 pl a_l4 4371 pln 4372 pl a_l5 4373 pln 4374 pl a_l6 4375 pln 4376 pl a_l7 4377 pln 4378 pl a_l8 4379 pln 4380 pl a_l9 4381 pln 4382 pl a_l10 4383 pln 4384 pl a_l11 4385 pln 4386 pl a_l12 4387 pln 4388 pl a_l13 4389 pln 4390 pl a_l14 4391 pln 4392 pl a_l15 4393 end 4394 4395 fn source to void 4396 pl s_l1 4397 pln 4398 pc 6 4399 plroot 4400 pl s_l2 4401 pc 2 4402 pln 4403 pl s_l3 4404 pln 4405 pc 6 4406 plroot 4407 pl s_l4 4408 pc 2 4409 pln 4410 pl s_l5 4411 pln 4412 pln 4413 pl s_l6 4414 end 4415 4416 fn plroot to void 4417 for i ulong get rtn 0 4418 pc get rt i 4419 end 4420 end 4421 4422 note Welcome; loops on about and source. Returns false to quit. 4423 fn stwel to bool 4424 while true bound 1000 4425 enter 0 4426 pclear 4427 plines 4428 prompt w_go 4429 show 4430 r = ask 4431 if lt r 0 4432 ret false 4433 end 4434 if ibis t_q 4435 ret false 4436 end 4437 if ibis t_about 4438 sub1 true 4439 end 4440 if ibis t_source 4441 sub1 false 4442 end 4443 if not or ibis t_about ibis t_source 4444 ret true 4445 end 4446 end 4447 ret false 4448 end 4449 4450 fn sub1 isab bool to void 4451 pclear 4452 if isab 4453 about 4454 else 4455 source 4456 end 4457 prompt t_next 4458 show 4459 r = ask 4460 end 4461 4462 note Doctor screen. Returns true when the machine can take this alpha. 4463 fn stdoc to bool 4464 enter 1 4465 pclear 4466 need = mneed 4467 ok = doctor need 4468 for i ulong NCHK 4469 dpanel i 4470 end 4471 if not ok 4472 pln 4473 pc 4 4474 pl x_l1 4475 pc 2 4476 pln 4477 pl x_l2 4478 pln 4479 pl x_l3 4480 prompt t_close 4481 show 4482 r = ask 4483 ret false 4484 end 4485 prompt t_next 4486 show 4487 r = ask 4488 ret ge r 0 4489 end 4490 4491 note Bytes the model still needs on disk: none when verified, else its size plus 1 GB. 4492 fn mneed to ulong 4493 if not mopen 4494 ret 0 4495 end 4496 if mdone 4497 ret 0 4498 end 4499 ret add mbytes `1000000000` 4500 end 4501 4502 fn dpanel i ulong to void 4503 k = get dk i 4504 if eq k 0 4505 pc 3 4506 pl k_ok 4507 end 4508 if eq k 1 4509 pc 1 4510 pl k_wn 4511 end 4512 if eq k 2 4513 pc 4 4514 pl k_no 4515 end 4516 if eq k 3 4517 pc 5 4518 pl k_in 4519 end 4520 pc 2 4521 pc 32 4522 n = get ptn 0 4523 dnm i 4524 while lt sub get ptn 0 n 9 bound 16 4525 pc 32 4526 end 4527 for j ulong get dtn i 4528 pc get dt add mul i 192 j 4529 end 4530 pln 4531 end 4532 4533 fn dnm i ulong to void 4534 if eq i 0 4535 pl n_arch 4536 end 4537 if eq i 1 4538 pl n_gpu 4539 end 4540 if eq i 2 4541 pl n_drv 4542 end 4543 if eq i 3 4544 pl n_mem 4545 end 4546 if eq i 4 4547 pl n_disk 4548 end 4549 if eq i 5 4550 pl n_inst 4551 end 4552 if eq i 6 4553 pl n_busy 4554 end 4555 if eq i 7 4556 pl n_nv 4557 end 4558 end 4559 4560 fn stplan to bool 4561 enter 2 4562 pclear 4563 pl p_l1 4564 pln 4565 pln 4566 pc 6 4567 plbase 4568 pl p_l2 4569 pl v_tag 4570 pc 2 4571 pl p_l3 4572 pln 4573 pc 6 4574 plbase 4575 pl p_l4 4576 for i ulong get mnn 0 4577 pc get mnm i 4578 end 4579 pc 2 4580 pln 4581 pl p_l9 4582 plgb mbytes 4583 pl m_l3 4584 plnum mfiles 4585 pl m_l4 4586 pln 4587 pc 6 4588 plbase 4589 pc 2 4590 pl p_l6 4591 pln 4592 pl p_l5 4593 pln 4594 pln 4595 pl p_l7 4596 pln 4597 pc 1 4598 pl p_l8 4599 pc 2 4600 prompt p_ok 4601 show 4602 r = ask 4603 ret ge r 0 4604 end 4605 4606 fn styes to bool 4607 enter 3 4608 pclear 4609 pc 6 4610 pl c_l1 4611 pc 2 4612 prompt c_q 4613 show 4614 r = ask 4615 ret and ge r 0 ibis t_yes 4616 end 4617 4618 fn bye t view uchar * to void 4619 if eq get ui 0 1 4620 scrn false 4621 end 4622 sgr0 4623 putb 10 4624 emit t 4625 putb 10 4626 w = flush 4627 end 4628 4629 note The full wizard. Exit 0 for a finished run and for a friendly refusal; 1 when a step failed. 4630 fn wizard plain bool to int 4631 term plain 4632 if not mopen 4633 ret 3 4634 end 4635 if eq get ui 0 1 4636 scrn true 4637 w = flush 4638 end 4639 if not stwel 4640 bye c_stop 4641 ret 0 4642 end 4643 if not stdoc 4644 bye x_l3 4645 ret 0 4646 end 4647 if not stplan 4648 bye c_stop 4649 ret 0 4650 end 4651 if not styes 4652 bye c_stop 4653 ret 0 4654 end 4655 if not stinst 4656 bye c_fail 4657 ret 1 4658 end 4659 if not mstep 4660 bye c_fail 4661 ret 1 4662 end 4663 if not stchat 4664 bye c_fail 4665 ret 1 4666 end 4667 stdone eq get ui 11 1 4668 if eq get ui 11 1 4669 bye d_l1 4670 else 4671 bye d_l0 4672 end 4673 ret 0 4674 end 4675 4676 fn istty fd int to bool 4677 r = fstat fd sb 0 128 4678 ret and eq r 0 eq stype 2 4679 end 4680 4681 fn cdoctor to int 4682 need = mneed 4683 ok = doctor need 4684 col = istty 1 4685 for i ulong NCHK 4686 cline i col 4687 putb 10 4688 end 4689 w = flush 4690 if ok 4691 ret 0 4692 end 4693 emit x_l1 4694 putb 10 4695 emit x_l2 4696 putb 10 4697 w = flush 4698 ret 1 4699 end 4700 4701 fn cverify to int 4702 x = mopen 4703 k = sums 4704 if lt k 0 4705 emit n_vbad 4706 putb 10 4707 w = flush 4708 ret 1 4709 end 4710 num ulong k 4711 emit n_vok 4712 putb 10 4713 w = flush 4714 ret 0 4715 end 4716 4717 note Start the engine when the doctor allows it and wait until it answers. 4718 fn cstart to int 4719 x = mopen 4720 if alive PORT 4721 emit n_ready 4722 putb 10 4723 w = flush 4724 ret 0 4725 end 4726 ok = doctor 0 4727 pclear 4728 if ckskip 4729 for i ulong get ptn 0 4730 putb get pt i 4731 end 4732 putb 10 4733 w = flush 4734 ret 2 4735 end 4736 p = estart 4737 if lt p 0 4738 ret 1 4739 end 4740 emit n_start 4741 num ulong p 4742 putb 10 4743 w = flush 4744 if not ewait 2400 4745 emit n_nostrt 4746 putb 10 4747 w = flush 4748 ret 1 4749 end 4750 emit n_ready 4751 putb 10 4752 w = flush 4753 ret 0 4754 end 4755 4756 fn cstop to int 4757 if estop 4758 emit n_stopd 4759 putb 10 4760 w = flush 4761 ret 0 4762 end 4763 ret 1 4764 end 4765 4766 fn cchat to int 4767 r = cstart 4768 if ne r 0 4769 ret r 4770 end 4771 emit n_chat1 4772 putb 10 4773 put hsn 0 0 4774 while true bound 100000 4775 emit n_you 4776 w = flush 4777 n = rline 4778 if or lt n 0 ibis n_bye 4779 ret 0 4780 end 4781 if gt get hsn 0 0 4782 hstr j_comma 4783 end 4784 hstr j_user 4785 hesc 4786 hstr j_end 4787 emit n_ai 4788 w = flush 4789 q = chatreq PORT 4790 putb 10 4791 w = flush 4792 if ne q 0 4793 emit n_err 4794 snum q 4795 putb 10 4796 w = flush 4797 else 4798 hstr j_comma 4799 hstr j_asst 4800 for i ulong get abn 0 4801 hbyte get ab i 4802 end 4803 hstr j_end 4804 end 4805 end 4806 ret 0 4807 end 4808 4809 fn cprint to int 4810 for i ulong get ptn 0 4811 b = get pt i 4812 if or ge b 7 eq b 10 4813 putb b 4814 end 4815 end 4816 putb 10 4817 w = flush 4818 ret 0 4819 end 4820 4821 fn iskey t view uchar * to bool 4822 ret ibis t 4823 end 4824 4825 fn main to int 4826 if not setup 4827 emit n_nohome 4828 putb 10 4829 w = flush 4830 ret 2 4831 end 4832 if lt arg 1 0 4833 ret wizard false 4834 end 4835 if iskey k_wiz 4836 plain = false 4837 if ge arg 2 0 4838 plain = ibis t_plain 4839 end 4840 ret wizard plain 4841 end 4842 if iskey k_doc 4843 ret cdoctor 4844 end 4845 if iskey k_chat 4846 ret cchat 4847 end 4848 if iskey k_start 4849 ret cstart 4850 end 4851 if iskey k_stop 4852 ret cstop 4853 end 4854 if iskey k_vfy 4855 ret cverify 4856 end 4857 if iskey t_source 4858 pclear 4859 source 4860 ret cprint 4861 end 4862 if iskey t_about 4863 pclear 4864 about 4865 ret cprint 4866 end 4867 if iskey k_unin 4868 ret cunin 4869 end 4870 if iskey k_roll 4871 ret rollbk 4872 end 4873 emit k_help 4874 putb 10 4875 w = flush 4876 ret 2 4877 end 4878 4879 fn cunin to int 4880 keep = false 4881 yes = false 4882 for i ulong 2 4883 if ge arg add i 2 0 4884 if ibis u_keep 4885 keep = true 4886 end 4887 if ibis u_yes 4888 yes = true 4889 end 4890 end 4891 end 4892 x = mopen 4893 ret uninst keep yes 4894 end