Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/evidence/SECURITY-673/pure3/mut5.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / evidence / SECURITY-673 / pure3 / mut5.om` 4175 lines ยท 72968 bytes Raw Blame History 1 note omc: the Omega compiler written in Omega (the om4 subset). Reads Omegese on stdin, writes a runnable 2 note AArch64 Linux program (or bare function words) on stdout. Built first by om4; its codegen matches om4 3 note byte for byte on the original subset (seed chain rung 5, ledger L408). Native host operations 4 note extend that subset; om4 still builds this compiler, and the compiler rebuilds itself identically. 5 note All compiler state lives in fixed global pools (decision 24: no heap). Every working value is a ulong 6 note (raw 64 bits) so the language's checked conversions never fire on om4's untyped-register logic. 7 8 note ---- input, output, token ---- 9 global inp uchar `8388608` 10 global inlen ulong 1 11 global cur ulong 1 12 global line ulong 1 13 global tk ulong 1 14 global tw ulong 1 15 global tl ulong 1 16 global ts ulong 1 17 global tbig ulong 1 18 global out uchar `8388608` 19 global oc ulong 1 20 21 note ---- name table (1024 names in scope): packed name, register, type, length, kind, address ---- 22 global nm_name ulong 1024 23 global nm_reg uchar 1024 24 global nm_type uchar 1024 25 global nm_len ulong 1024 26 global nm_kind uchar 1024 27 global nm_addr ulong 1024 28 global nn ulong 1 29 30 note ---- function table (512): name, address (byte offset in out), return type, parameter count, 31 note per-parameter type/length/kind (6 each), name length, name offset in the input ---- 32 global fn_name ulong 512 33 global fn_addr ulong 512 34 global fn_ret uchar 512 35 global fn_np uchar 512 36 global fn_pt uchar 3072 37 global fn_pl ulong 3072 38 global fn_pk uchar 3072 39 global fn_nmlen ulong 512 40 global fn_off ulong 512 41 global nf ulong 1 42 global lastfn ulong 1 43 global scanning ulong 1 44 global ncalls ulong 1 45 global callsite ulong 65536 46 global callfrom ulong 65536 47 global callto ulong 65536 48 global settled uchar 512 49 50 51 note ---- compiler state ---- 52 global npar ulong 1 53 global held ulong 1 54 global nslot ulong 1 55 global curret ulong 1 56 global progmode ulong 1 57 global nglob ulong 1 58 global hostargs ulong 1 59 global stkbytes ulong 1 60 global dead ulong 1 61 global poolb ulong 1 62 63 note ======== leaf helpers ======== 64 65 note poolc: the i-th register of the pool x0..x6, x8..x15, x17 (x7 is the runtime, x16 scratch) 66 fn poolc i ulong to ulong 67 if lt i 7 68 ret i 69 end 70 if lt i 15 71 ret add i 1 72 end 73 ret 17 74 end 75 76 note ---- error reporting ---- 77 global msg uchar 64 78 global mc ulong 1 79 80 fn mputb b uchar to void 81 m = get mc 0 82 put msg m b 83 put mc 0 add m 1 84 end 85 86 fn mputn v ulong to void 87 d = new uchar 20 0 88 i = ulong 0 89 x = v 90 put d 0 uchar add rem x 10 48 91 x = div x 10 92 i = add i 1 93 while gt x 0 94 put d i uchar add rem x 10 48 95 x = div x 10 96 i = add i 1 97 end 98 j = i 99 while gt j 0 100 j = sub j 1 101 mputb get d j 102 end 103 end 104 105 note fail: write "omc: line N: error E" to stderr (fd 2) and exit with the code 106 fn fail code ulong to void 107 put mc 0 0 108 mputb 111 109 mputb 109 110 mputb 99 111 mputb 58 112 mputb 32 113 mputb 108 114 mputb 105 115 mputb 110 116 mputb 101 117 mputb 32 118 mputn get line 0 119 mputb 58 120 mputb 32 121 mputb 101 122 mputb 114 123 mputb 114 124 mputb 111 125 mputb 114 126 mputb 32 127 mputn code 128 mputb 10 129 w = write 2 msg 0 get mc 0 130 exit int code 131 end 132 133 note emitb / emit: one byte / one 32-bit word (little-endian) to the output; error 14 when it is full 134 note (om4 EMIT, EMITB: the 8 MiB output area) 135 fn emitb b uchar to void 136 o = get oc 0 137 if ge o `8388608` 138 fail 14 139 end 140 put out o b 141 put oc 0 add o 1 142 end 143 144 fn emit w ulong to void 145 if ge get oc 0 `8388608` 146 fail 14 147 end 148 emitb uchar and w 255 149 emitb uchar and shr w 8 255 150 emitb uchar and shr w 16 255 151 emitb uchar and shr w 24 255 152 end 153 154 note tok_num: the word at [ts,cur) is [-]decimal, at most 20 digits, from -2^63 to 2^64 - 1 (error 6 155 note bad number, 8 out of range). tw = its raw 64 bits (a negative one as two's complement); tbig = 1 156 note when it is 2^63 or more (only a ulong holds it), else 0. As om4's TK_NUM. 157 fn tok_num to void 158 p = get ts 0 159 e = get cur 0 160 minus = false 161 if eq get inp p 45 162 minus = true 163 p = add p 1 164 end 165 ndig = sub e p 166 if eq ndig 0 167 fail 6 168 end 169 if gt ndig 20 170 fail 6 171 end 172 v = ulong 0 173 lim = ulong `1844674407370955161` 174 i = p 175 while lt i e 176 d = sub ulong get inp i 48 177 if gt d 9 178 fail 6 179 end 180 if gt v lim 181 fail 8 182 end 183 if and eq v lim gt d 5 184 fail 8 185 end 186 v = add mul v 10 d 187 i = add i 1 188 end 189 half = shl ulong 1 63 190 put tbig 0 0 191 if minus 192 if gt v half 193 fail 8 194 end 195 put tw 0 sub ulong 0 v 196 else 197 if ge v half 198 put tbig 0 1 199 end 200 put tw 0 v 201 end 202 put tk 0 2 203 end 204 205 note tok_text: a text literal starting at the opening quote. tw = first byte offset, tl = source length 206 note (escapes not yet decoded). Ends at an unescaped '"' on the same line, followed by a blank/end. Err 22. 207 note (Loops over the input are two loops, the inner under `1000000` passes: om4 has no pass limit.) 208 fn tok_text to void 209 put cur 0 add get cur 0 1 210 put tw 0 get cur 0 211 go = true 212 while go 213 n = ulong 0 214 while and go lt n 999999 215 if ge get cur 0 get inlen 0 216 fail 22 217 end 218 b = get inp get cur 0 219 if eq b 10 220 fail 22 221 end 222 if eq b 34 223 go = false 224 else 225 put cur 0 add get cur 0 1 226 if eq b 92 227 if ge get cur 0 get inlen 0 228 fail 22 229 end 230 if eq get inp get cur 0 10 231 fail 22 232 end 233 put cur 0 add get cur 0 1 234 end 235 end 236 n = add n 1 237 end 238 end 239 put tl 0 sub get cur 0 get tw 0 240 put cur 0 add get cur 0 1 241 put tk 0 4 242 if lt get cur 0 get inlen 0 243 if gt get inp get cur 0 32 244 fail 22 245 end 246 end 247 end 248 249 note tok2: a word at cur with first byte c; packs 8 bytes into tw, sets tl and ts. A '"' is a text; a 250 note first byte '-' or a digit is a number. 251 fn tok2 c uchar to void 252 if eq c 34 253 tok_text 254 ret 255 end 256 put ts 0 get cur 0 257 w = ulong 0 258 sh = ulong 0 259 n = ulong 0 260 go = true 261 while go 262 m = ulong 0 263 while and go lt m 999999 264 if ge get cur 0 get inlen 0 265 go = false 266 else 267 b = get inp get cur 0 268 if le b 32 269 go = false 270 else 271 if lt n 8 272 w = or w shl ulong b sh 273 sh = add sh 8 274 end 275 n = add n 1 276 put cur 0 add get cur 0 1 277 end 278 end 279 m = add m 1 280 end 281 end 282 put tw 0 w 283 put tl 0 n 284 f = get inp get ts 0 285 isnum = false 286 if eq f 45 287 isnum = true 288 end 289 if and ge f 48 le f 57 290 isnum = true 291 end 292 if isnum 293 tok_num 294 else 295 put tk 0 1 296 end 297 end 298 299 note tok: next word, skipping blanks (space, tab, carriage return); newline is end of line (kind 0) and 300 note bumps the line number; another byte below 32 is error 16; the end of the input is kind 3. om4 TOK. 301 fn tok to void 302 go = true 303 while go 304 n = ulong 0 305 while and go lt n 999999 306 if ge get cur 0 get inlen 0 307 go = false 308 else 309 c = get inp get cur 0 310 if or or eq c 32 eq c 9 eq c 13 311 put cur 0 add get cur 0 1 312 else 313 if eq c 10 314 put cur 0 add get cur 0 1 315 put line 0 add get line 0 1 316 put tk 0 0 317 ret 318 end 319 if lt c 32 320 fail 16 321 end 322 tok2 c 323 ret 324 end 325 end 326 n = add n 1 327 end 328 end 329 put tk 0 3 330 end 331 332 note ======== keyword lookup (original om4 KWTAB plus hand-maintained native host words 100..135) ======== 333 note genkw.awk describes the original om4 table only; retain the native host extension on regeneration. 334 fn kw w ulong to ulong 335 if eq w `7310034270740117605` 336 ret 135 337 end 338 if eq w `6584163` 339 ret 132 340 end 341 packed = or ulong 114 shl ulong 101 8 342 packed = or packed shl ulong 97 16 343 packed = or packed shl ulong 100 24 344 packed = or packed shl ulong 108 32 345 packed = or packed shl ulong 110 40 346 packed = or packed shl ulong 107 48 347 if eq w packed 348 ret 133 349 end 350 packed = or ulong 115 shl ulong 111 8 351 packed = or packed shl ulong 99 16 352 packed = or packed shl ulong 107 24 353 packed = or packed shl ulong 111 32 354 packed = or packed shl ulong 112 40 355 packed = or packed shl ulong 116 48 356 if eq w packed 357 ret 134 358 end 359 if eq w `1819242338` 360 ret 1 361 end 362 if eq w `491260502901` 363 ret 2 364 end 365 if eq w 14453 366 ret 2 367 end 368 if eq w `128034844210037` 369 ret 3 370 end 371 if eq w `3551605` 372 ret 3 373 end 374 if eq w `1953393013` 375 ret 4 376 end 377 if eq w `3289973` 378 ret 4 379 end 380 if eq w `444234427509` 381 ret 5 382 end 383 if eq w `3421813` 384 ret 5 385 end 386 if eq w `1702132066` 387 ret 6 388 end 389 if eq w 14441 390 ret 6 391 end 392 if eq w `500136110195` 393 ret 7 394 end 395 if eq w `3551593` 396 ret 7 397 end 398 if eq w `7630441` 399 ret 8 400 end 401 if eq w `3289961` 402 ret 8 403 end 404 if eq w `1735290732` 405 ret 9 406 end 407 if eq w `3421801` 408 ret 9 409 end 410 if eq w `6579297` 411 ret 33 412 end 413 if eq w `6452595` 414 ret 34 415 end 416 if eq w `7107949` 417 ret 35 418 end 419 if eq w `7760228` 420 ret 36 421 end 422 if eq w `7169394` 423 ret 37 424 end 425 if eq w `6581857` 426 ret 38 427 end 428 if eq w 29295 429 ret 39 430 end 431 if eq w `7499640` 432 ret 40 433 end 434 if eq w `7104627` 435 ret 41 436 end 437 if eq w `7497843` 438 ret 42 439 end 440 if eq w 29029 441 ret 43 442 end 443 if eq w 25966 444 ret 44 445 end 446 if eq w 29804 447 ret 45 448 end 449 if eq w 25964 450 ret 46 451 end 452 if eq w 29799 453 ret 47 454 end 455 if eq w 25959 456 ret 48 457 end 458 if eq w `6776174` 459 ret 49 460 end 461 if eq w `7630702` 462 ret 50 463 end 464 if eq w `7628135` 465 ret 51 466 end 467 if eq w `7234924` 468 ret 52 469 end 470 if eq w `1684104562` 471 ret 53 472 end 473 if eq w `435744764535` 474 ret 54 475 end 476 if eq w `1702195828` 477 ret 55 478 end 479 if eq w `435728179558` 480 ret 56 481 end 482 if eq w `2003134838` 483 ret 57 484 end 485 if eq w `1953064037` 486 ret 58 487 end 488 if eq w 28262 489 ret 64 490 end 491 if eq w 28532 492 ret 65 493 end 494 if eq w `6581861` 495 ret 66 496 end 497 if eq w 26217 498 ret 67 499 end 500 if eq w `1702063205` 501 ret 68 502 end 503 if eq w `435610544247` 504 ret 69 505 end 506 if eq w `431349919586` 507 ret 70 508 end 509 if eq w `7499622` 510 ret 71 511 end 512 if eq w `7628146` 513 ret 72 514 end 515 if eq w 61 516 ret 73 517 end 518 if eq w 40 519 ret 74 520 end 521 if eq w 41 522 ret 75 523 end 524 if eq w `1684631414` 525 ret 76 526 end 527 if eq w `119165519096935` 528 ret 78 529 end 530 if eq w `1954047348` 531 ret 79 532 end 533 if eq w `7632240` 534 ret 80 535 end 536 if eq w `1701147238` 537 ret 81 538 end 539 if eq w `1953069157` 540 ret 82 541 end 542 if eq w `1702129518` 543 ret 83 544 end 545 if eq w `7824750` 546 ret 84 547 end 548 if eq w `461195539042` 549 ret 77 550 end 551 if eq w `1885434484` 552 ret 77 553 end 554 if eq w `7239535` 555 ret 77 556 end 557 if eq w `7308604897168158579` 558 ret 131 559 end 560 if eq w `126918101919090` 561 ret 130 562 end 563 if eq w `7453301735350958181` 564 ret 124 565 end 566 if eq w `32481142782190962` 567 ret 125 568 end 569 if eq w `491394461042` 570 ret 126 571 end 572 if eq w `28263429247363435` 573 ret 127 574 end 575 if eq w `32480013273033072` 576 ret 128 577 end 578 if eq w `110404021020007` 579 ret 129 580 end 581 if eq w `122498715312503` 582 ret 123 583 end 584 if eq w `32497639802299751` 585 ret 113 586 end 587 if eq w `32760384594014051` 588 ret 114 589 end 590 if eq w `1684957538` 591 ret 115 592 end 593 if eq w `28263429381382519` 594 ret 116 595 end 596 if eq w `499851228006` 597 ret 117 598 end 599 if eq w `1986225522` 600 ret 118 601 end 602 if eq w `1684956531` 603 ret 119 604 end 605 if eq w `32491051338263667` 606 ret 120 607 end 608 if eq w `128017462948449` 609 ret 121 610 end 611 if eq w `28254586010038881` 612 ret 122 613 end 614 if eq w `111546465018726` 615 ret 100 616 end 617 if eq w `427055215462` 618 ret 101 619 end 620 if eq w `110429739705190` 621 ret 102 622 end 623 if eq w `461262648166` 624 ret 103 625 end 626 if eq w `33607047151054707` 627 ret 104 628 end 629 if eq w `121382024472940` 630 ret 105 631 end 632 if eq w `128026086171489` 633 ret 106 634 end 635 if eq w `1802661734` 636 ret 107 637 end 638 if eq w `431215375716` 639 ret 108 640 end 641 if eq w `126918153105261` 642 ret 109 643 end 644 if eq w `474148269926` 645 ret 110 646 end 647 if eq w `118121959288437` 648 ret 111 649 end 650 if eq w `32204027264196973` 651 ret 112 652 end 653 ret 0 654 end 655 656 note ======== om4's small tables, as functions ======== 657 note twid: width in bits by type 0..9 (bool 1; uchar ushort uint ulong; byte short int long) 658 fn twid t ulong to ulong 659 if eq t 1 660 ret 1 661 end 662 if or eq t 2 eq t 6 663 ret 8 664 end 665 if or eq t 3 eq t 7 666 ret 16 667 end 668 if or eq t 4 eq t 8 669 ret 32 670 end 671 if or eq t 5 eq t 9 672 ret 64 673 end 674 ret 0 675 end 676 677 note tlog: log2 of the element size by type 678 fn tlog t ulong to ulong 679 if or eq t 3 eq t 7 680 ret 1 681 end 682 if or eq t 4 eq t 8 683 ret 2 684 end 685 if or eq t 5 eq t 9 686 ret 3 687 end 688 ret 0 689 end 690 691 note regidx: the pool index of register r (the inverse of poolc; 255 for x7 and x16) 692 fn regidx r ulong to ulong 693 if lt r 7 694 ret r 695 end 696 if eq r 7 697 ret 255 698 end 699 if lt r 16 700 ret sub r 1 701 end 702 if eq r 16 703 ret 255 704 end 705 ret 15 706 end 707 708 note conds: the condition for eq ne lt le gt ge (i = 2 (op - 43) + 1 when signed): EQ 0, NE 1, LO 3 / LT 11, 709 note LS 9 / LE 13, HI 8 / GT 12, HS 2 / GE 10 (Arm ARM Table C1-1). The opposite condition is cond xor 1. 710 fn conds i ulong to ulong 711 if lt i 2 712 ret 0 713 end 714 if lt i 4 715 ret 1 716 end 717 if eq i 4 718 ret 3 719 end 720 if eq i 5 721 ret 11 722 end 723 if eq i 6 724 ret 9 725 end 726 if eq i 7 727 ret 13 728 end 729 if eq i 8 730 ret 8 731 end 732 if eq i 9 733 ret 12 734 end 735 if eq i 10 736 ret 2 737 end 738 ret 10 739 end 740 741 note ldop / stop: register-offset load / store by element type (om4 LDOP, STOP tables) 742 fn ldop t ulong to ulong 743 note LDRB 0x38606800, LDRH 0x78607800, LDR w 0xb8607800, LDR x 0xf8607800, LDRSB 0x38a06800, 744 note LDRSH 0x78a07800, LDRSW 0xb8a07800 745 if eq t 2 746 ret `945842176` 747 end 748 if eq t 3 749 ret `2019588096` 750 end 751 if eq t 4 752 ret `3093329920` 753 end 754 if or eq t 5 eq t 9 755 ret `4167071744` 756 end 757 if eq t 6 758 ret `950036480` 759 end 760 if eq t 7 761 ret `2023782400` 762 end 763 if eq t 8 764 ret `3097524224` 765 end 766 ret 0 767 end 768 769 fn stop t ulong to ulong 770 note STRB 0x38206800, STRH 0x78207800, STR w 0xb8207800, STR x 0xf8207800 771 if or eq t 2 eq t 6 772 ret `941647872` 773 end 774 if or eq t 3 eq t 7 775 ret `2015393792` 776 end 777 if or eq t 4 eq t 8 778 ret `3089135616` 779 end 780 if or eq t 5 eq t 9 781 ret `4162877440` 782 end 783 ret 0 784 end 785 786 note ---- trap list (8192 sites per function): output offset of the branch, trap code ---- 787 global tsite ulong 8192 788 global tcode ulong 8192 789 global nt ulong 1 790 note ---- block stack (512): kind (1 if, 2 else, 3 while, 4 for), branch to patch, loop head, loop 791 note register, its type, names and held pool slots to restore at end, then-part ended (for else) ---- 792 global bkind ulong 512 793 global bbr ulong 512 794 global bhead ulong 512 795 global breg ulong 512 796 global btyp ulong 512 797 global bnames ulong 512 798 global bheld ulong 512 799 global bdead ulong 512 800 global nb ulong 1 801 global curfn ulong 1 802 803 note ======== names and functions ======== 804 note findname: packed name -> its index + 1 among the names in scope (0 none). om4 FINDNAME. 805 fn findname w ulong to ulong 806 i = ulong 0 807 n = get nn 0 808 while lt i n 809 if eq get nm_name i w 810 ret add i 1 811 end 812 i = add i 1 813 end 814 ret 0 815 end 816 817 note findfn: packed name w (first 8 bytes), length l (any value up to 8 for a short name), start s in the 818 note input (read only for a name over 8 bytes) -> function index + 1 (0 none). om4 FINDFN. 819 fn findfn w ulong l ulong s ulong to ulong 820 j = ulong 0 821 while lt j get nf 0 822 if eq get fn_name j w 823 fl = get fn_nmlen j 824 if le l 8 825 if le fl 8 826 ret add j 1 827 end 828 else 829 if eq fl l 830 o = get fn_off j 831 k = ulong 8 832 same = true 833 while and same lt k l 834 a = get inp add o k 835 if ne a get inp add s k 836 same = false 837 end 838 k = add k 1 839 end 840 if same 841 ret add j 1 842 end 843 end 844 end 845 end 846 j = add j 1 847 end 848 ret 0 849 end 850 851 note newname: the name must not be in use (a name in scope when 8 bytes or fewer, or a function): error 10 852 fn newname w ulong l ulong s ulong to void 853 if le l 8 854 if ne findname w 0 855 fail 10 856 end 857 end 858 if ne findfn w l s 0 859 fail 10 860 end 861 end 862 863 note addname: packed name, register, type, length, kind, address. om4 ADDNAME. 864 fn addname w ulong r ulong t ulong ln ulong k ulong a ulong to void 865 n = get nn 0 866 if ge n 1024 867 fail 14 868 end 869 put nm_name n w 870 put nm_reg n uchar r 871 put nm_type n uchar t 872 put nm_len n ln 873 put nm_kind n uchar k 874 put nm_addr n a 875 put nn 0 add n 1 876 end 877 878 note ======== registers and words ======== 879 note alloc: the next free register of the pool (after the parameters); error 12 when none is left 880 fn alloc to ulong 881 i = add get npar 0 get nslot 0 882 if ge i 16 883 fail 12 884 end 885 put nslot 0 add get nslot 0 1 886 ret poolc i 887 end 888 889 note destreg: d, or a new temporary when d is 255 890 fn destreg d ulong to ulong 891 if eq d 255 892 ret alloc 893 end 894 ret d 895 end 896 897 note e3: emit op | d | n << 5 | m << 16 898 fn e3 op ulong d ulong n ulong m ulong to void 899 emit or or or op d shl n 5 shl m 16 900 end 901 902 note trapsite: note the place and code of a branch to the trap stub, then emit it. trapc: B.cond, as om4. 903 fn trapsite w ulong code ulong to void 904 n = get nt 0 905 if ge n 8192 906 fail 14 907 end 908 put tsite n get oc 0 909 put tcode n code 910 put nt 0 add n 1 911 emit w 912 end 913 914 fn trapc cc ulong code ulong to void 915 trapsite or `1409286144` cc code 916 end 917 918 fn rdword at ulong to ulong 919 a = ulong get out at 920 b = shl ulong get out add at 1 8 921 c = shl ulong get out add at 2 16 922 d = shl ulong get out add at 3 24 923 ret or or or a b c d 924 end 925 926 fn wrword at ulong w ulong to void 927 put out at uchar and w 255 928 put out add at 1 uchar and shr w 8 255 929 put out add at 2 uchar and shr w 16 255 930 put out add at 3 uchar and shr w 24 255 931 end 932 933 note disp19: the checked word distance for a B.cond / CBZ / CBNZ: the target must be word aligned and 934 note at most 2^18 - 1 words forward or 2^18 words back, else error 24 before any artifact is accepted 935 fn disp19 at ulong target ulong to ulong 936 diff = sub target at 937 if ne and diff 3 0 938 fail 24 939 end 940 if and gt diff `1048572` lt diff `18446744073708503040` 941 fail 24 942 end 943 ret and shr diff 2 524287 944 end 945 946 note patch19: the word distance from a B.cond / CBZ / CBNZ at `at` to `target`, into bits 5..23 947 fn patch19 at ulong target ulong to void 948 d = disp19 at target 949 wrword at or rdword at shl d 5 950 end 951 952 note patch26: the word distance from a B at `at` to `target`, into bits 0..25. No range check is needed: 953 note the output pool is 8 MiB = 2^23 bytes, below the 2^25-word reach, and every position in it is a 954 note word boundary, so the displacement is aligned and inside the signed 26-bit field by construction. 955 fn patch26 at ulong target ulong to void 956 d = and shr sub target at 2 `67108863` 957 wrword at or rdword at d 958 end 959 960 note back: emit B to an earlier place (C6.2.35) 961 fn back addr ulong to void 962 emit or `335544320` and shr sub addr get oc 0 2 `67108863` 963 end 964 965 note matconst: put a 64-bit value in register r: MOVZ (C6.2.285) or, for a value with the top bit set, 966 note MOVN (C6.2.284) with the first halfword that differs from the fill, then MOVK (C6.2.283) for each 967 note other such halfword. om4 MATCONST. 968 fn matconst r ulong v ulong to void 969 fill = ulong 0 970 mop = ulong `3531603968` 971 if ne shr v 63 0 972 fill = ulong 65535 973 mop = ulong `2457862144` 974 end 975 started = false 976 hw = ulong 0 977 while lt hw 4 978 h = and shr v shl hw 4 65535 979 if ne h fill 980 if started 981 emit or or or `4068474880` shl h 5 shl hw 21 r 982 else 983 emit or or or mop shl xor h fill 5 shl hw 21 r 984 started = true 985 end 986 end 987 hw = add hw 1 988 end 989 if not started 990 emit or mop r 991 end 992 end 993 994 note canon: u8/u16/u32 UBFM Xr, Xr, #0, #w-1 (C6.2.487); i8/i16/i32 SBFM (C6.2.355); else nothing 995 fn canon r ulong t ulong to void 996 if lt t 2 997 ret 998 end 999 if eq t 5 1000 ret 1001 end 1002 if eq t 9 1003 ret 1004 end 1005 base = ulong `3544186880` 1006 if gt t 5 1007 base = ulong `2470445056` 1008 end 1009 emit or or or base shl sub twid t 1 10 r shl r 5 1010 end 1011 1012 note chkext: CMP Xr, Wr, SXTB/SXTH/SXTW (SUBS extended, C6.2.463), then B.NE trap code 1013 fn chkext r ulong t ulong code ulong to void 1014 emit or or or `3944742943` shl sub t 2 13 shl r 16 shl r 5 1015 trapc 1 code 1016 end 1017 1018 note range: error 8 unless v is a value of type t; big = the number was written as 2^63 or more 1019 fn range v ulong t ulong big ulong to void 1020 w = twid t 1021 if eq w 64 1022 if eq t 9 1023 if ne big 0 1024 fail 8 1025 end 1026 ret 1027 end 1028 if ne big 0 1029 ret 1030 end 1031 if ne shr v 63 0 1032 fail 8 1033 end 1034 ret 1035 end 1036 if ne big 0 1037 fail 8 1038 end 1039 lim = shl ulong 1 w 1040 if lt t 6 1041 if ge v lim 1042 fail 8 1043 end 1044 ret 1045 end 1046 half = shr lim 1 1047 if ge add v half lim 1048 fail 8 1049 end 1050 end 1051 1052 note cset: CSET Xr, cond = CSINC Xr, XZR, XZR, opposite cond (C6.2.141) 1053 fn cset r ulong cc ulong to void 1054 emit or or `2594113504` r shl xor cc 1 12 1055 end 1056 1057 note force: put a value (kind 1 register, 3 number, 4 flags) in register r; a bare number is error 11 1058 fn force k ulong v ulong t ulong r ulong to void 1059 if eq k 1 1060 if ne v r 1061 emit or or `2852127712` r shl v 16 1062 end 1063 ret 1064 end 1065 if eq k 3 1066 matconst r v 1067 ret 1068 end 1069 if eq k 4 1070 cset r v 1071 ret 1072 end 1073 fail 11 1074 end 1075 1076 note matreg: a register holding the value 1077 fn matreg k ulong v ulong t ulong to ulong 1078 if eq k 1 1079 ret v 1080 end 1081 r = alloc 1082 force k v t r 1083 ret r 1084 end 1085 1086 note spop: ADD (C6.2.5) / SUB (C6.2.457) SP, SP by a multiple of 16 below 2^24: low 12 bits, then the 1087 note high 12 bits LSL 12; nothing for a zero part 1088 fn spop base ulong bytes ulong to void 1089 lo = and bytes 4095 1090 if ne lo 0 1091 emit or or base 1023 shl lo 10 1092 end 1093 hi = and shr bytes 12 4095 1094 if ne hi 0 1095 emit or or base `4195327` shl hi 10 1096 end 1097 end 1098 1099 fn spadd bytes ulong to void 1100 spop `2432696320` bytes 1101 end 1102 1103 fn spsub bytes ulong to void 1104 spop `3506438144` bytes 1105 end 1106 1107 note stkchk: program mode only: CMP SP, X28 (C6.2.463); B.LO trap 6 1108 fn stkchk to void 1109 if ne get progmode 0 0 1110 emit `3946603519` 1111 trapc 3 6 1112 end 1113 end 1114 1115 note epi: give back the stack of the local arrays, then RET (C6.2.338) 1116 fn epi to void 1117 spadd get stkbytes 0 1118 emit `3596551104` 1119 end 1120 1121 fn dead1 to void 1122 put dead 0 1 1123 end 1124 1125 note pushb / pushnh: open a block (om4 PUSHB, split in two because a call takes at most 6 values) 1126 fn pushb br ulong k ulong head ulong reg ulong ty ulong to void 1127 n = get nb 0 1128 if ge n 512 1129 fail 14 1130 end 1131 put bkind n k 1132 put bbr n br 1133 put bhead n head 1134 put breg n reg 1135 put btyp n ty 1136 put bdead n 0 1137 put nb 0 add n 1 1138 end 1139 1140 fn pushnh names ulong hd ulong to void 1141 n = sub get nb 0 1 1142 put bnames n names 1143 put bheld n hd 1144 end 1145 1146 note ======== small readers ======== 1147 fn elemtype t ulong to void 1148 if lt t 2 1149 fail 9 1150 end 1151 end 1152 1153 note arrlen: an array length 1 .. `16777216` (error 8 below, 23 above, 23 when written as 2^63 or more) 1154 fn arrlen v ulong to void 1155 if ne get tbig 0 0 1156 fail 23 1157 end 1158 if or eq v 0 ne shr v 63 0 1159 fail 8 1160 end 1161 if gt v `16777216` 1162 fail 23 1163 end 1164 end 1165 1166 note typeword: read a type name -> 1..9 1167 fn typeword to ulong 1168 tok 1169 k = get tk 0 1170 if eq k 0 1171 fail 4 1172 end 1173 if ne k 1 1174 fail 16 1175 end 1176 if gt get tl 0 8 1177 fail 16 1178 end 1179 c = kw get tw 0 1180 if eq c 76 1181 fail 9 1182 end 1183 if gt sub c 1 8 1184 fail 16 1185 end 1186 ret c 1187 end 1188 1189 note eol: the line must end here 1190 fn eol to void 1191 tok 1192 k = get tk 0 1193 if and ne k 0 ne k 3 1194 fail 5 1195 end 1196 end 1197 1198 note arrname: read an array name -> its index + 1 1199 fn arrname to ulong 1200 tok 1201 k = get tk 0 1202 if eq k 0 1203 fail 4 1204 end 1205 if eq k 3 1206 fail 4 1207 end 1208 if ne k 1 1209 fail 16 1210 end 1211 if gt get tl 0 8 1212 fail 13 1213 end 1214 e = findname get tw 0 1215 if eq e 0 1216 fail 3 1217 end 1218 if eq get nm_kind sub e 1 0 1219 fail 7 1220 end 1221 ret e 1222 end 1223 1224 note topname: read a new name for a global or a text -> its packed word 1225 fn topname to ulong 1226 tok 1227 if ne get tk 0 1 1228 fail 16 1229 end 1230 if gt get tl 0 8 1231 fail 13 1232 end 1233 w = get tw 0 1234 if ne kw w 0 1235 fail 16 1236 end 1237 newname w get tl 0 get ts 0 1238 ret w 1239 end 1240 1241 note ---- value results (om4 x0 kind 1 register / 2 bare number / 3 typed number / 4 flags, x1 register, 1242 note number or condition, x2 type). fr: 32 cells per value nesting depth 0..1024: 0..5 the two operands of 1243 note a binary op (kind, value, type each), 8..25 a call's arguments (kind, value, array name each) ---- 1244 global rk ulong 1 1245 global rv ulong 1 1246 global rt ulong 1 1247 global fr ulong 32800 1248 global depth ulong 1 1249 1250 note ======== BINOP (om4 BINOP and its BO_* parts): two values already read, types settled ======== 1251 note bo_w3: emit fx | rd | ra << 5 | (imm12 << 10, or rb << 16) 1252 fn bo_w3 fx ulong rd ulong ra ulong rb ulong imm ulong to void 1253 if ne imm 0 1254 emit or or or fx rd shl ra 5 shl rb 10 1255 else 1256 emit or or or fx rd shl ra 5 shl rb 16 1257 end 1258 end 1259 1260 note bo_fix: after a 64-bit op on rd: u8/u16/u32 wrap (canon), i8/i16/i32 overflow check (trap 1) 1261 fn bo_fix rd ulong ty ulong to void 1262 if lt ty 6 1263 canon rd ty 1264 ret 1265 end 1266 if eq ty 9 1267 ret 1268 end 1269 chkext rd ty 1 1270 end 1271 1272 note bo_schk: a shift amount in a register must be below the width: CMP Xb, #w; B.HS trap 7 1273 fn bo_schk ty ulong rb ulong to void 1274 emit or or `4043309087` shl twid ty 10 shl rb 5 1275 trapc 2 7 1276 end 1277 1278 note add, sub: u32 the 32-bit form; i64 ADDS/SUBS + B.VS trap 1; others 64-bit then bo_fix (om4 BO_ADD) 1279 fn bo_add op ulong ty ulong ra ulong rb ulong imm ulong rd ulong to void 1280 fx = ulong `2332033024` 1281 if eq op 34 1282 fx = ulong `3405774848` 1283 end 1284 if ne imm 0 1285 fx = ulong `2432696320` 1286 if eq op 34 1287 fx = ulong `3506438144` 1288 end 1289 end 1290 if eq ty 4 1291 bo_w3 xor fx `2147483648` rd ra rb imm 1292 ret 1293 end 1294 if eq ty 9 1295 bo_w3 or fx `536870912` rd ra rb imm 1296 trapc 6 1 1297 ret 1298 end 1299 bo_w3 fx rd ra rb imm 1300 bo_fix rd ty 1301 end 1302 1303 note mul: i64 SMULH t, MUL, CMP t, rd, ASR #63, B.NE trap 1 (om4 BO_MUL) 1304 fn bo_mul ty ulong ra ulong rb ulong rd ulong to void 1305 if eq ty 9 1306 t = alloc 1307 e3 `2604694528` t ra rb 1308 bo_w3 `2600500224` rd ra rb 0 1309 e3 `3951098911` 0 t rd 1310 trapc 1 1 1311 ret 1312 end 1313 if eq ty 4 1314 bo_w3 `453016576` rd ra rb 0 1315 ret 1316 end 1317 bo_w3 `2600500224` rd ra rb 0 1318 bo_fix rd ty 1319 end 1320 1321 note div, rem (om4 BO_DIV, BO_SDIV): CBZ Xb trap 2 unless fl bit 1 (b a number other than 0); UDIV or 1322 note SDIV; rem: t = a / b, rd = a - t * b (MSUB); i64 div: CMN Xb, #1; B.NE +3; NEGS XZR, Xa; B.VS trap 1, 1323 note unless fl bit 2 (b a number other than -1) 1324 fn bo_div op ulong ty ulong ra ulong rb ulong rd ulong fl ulong to void 1325 if eq and fl 1 0 1326 trapsite or `3019898880` rb 2 1327 end 1328 if eq op 37 1329 t = alloc 1330 if ge ty 6 1331 e3 `2596277248` t ra rb 1332 else 1333 e3 `2596276224` t ra rb 1334 end 1335 e3 or `2600501248` shl ra 10 rd t rb 1336 ret 1337 end 1338 if lt ty 6 1339 bo_w3 `2596276224` rd ra rb 0 1340 ret 1341 end 1342 if eq ty 9 1343 if eq and fl 2 0 1344 emit or `2969568287` shl rb 5 1345 emit `1409286241` 1346 emit or `3942646783` shl ra 16 1347 trapc 6 1 1348 end 1349 end 1350 bo_w3 `2596277248` rd ra rb 0 1351 if ne ty 9 1352 bo_fix rd ty 1353 end 1354 end 1355 1356 note and, or, xor (om4 BO_LOG) 1357 fn bo_log op ulong ra ulong rb ulong rd ulong to void 1358 fx = ulong `2315255808` 1359 if eq op 39 1360 fx = ulong `2852126720` 1361 end 1362 if eq op 40 1363 fx = ulong `3388997632` 1364 end 1365 bo_w3 fx rd ra rb 0 1366 end 1367 1368 note bo_lsl: LSL Xd, Xn, #s as UBFM Xd, Xn, #(64-s) mod 64, #63-s 1369 fn bo_lsl ra ulong s ulong rd ulong to void 1370 r = shl and sub 64 s 63 16 1371 r = or r shl sub 63 s 10 1372 r = or r shl ra 5 1373 emit or or `3544186880` r rd 1374 end 1375 1376 note shl (om4 BO_SHL, BS_64): by a number s: UBFM Xd, Xn, #(64-s) mod 64, #63-s; by a register: the amount 1377 note check, LSLV; i64: t = a << s, X16 = t >> s arithmetic, CMP X16, Xa, B.NE trap 1, MOV Xd, Xt 1378 fn bo_shl ty ulong ra ulong rb ulong imm ulong rd ulong to void 1379 if eq ty 9 1380 t = alloc 1381 if ne imm 0 1382 bo_lsl ra rb t 1383 emit or or `2470509584` shl rb 16 shl t 5 1384 else 1385 bo_schk ty rb 1386 e3 `2596282368` t ra rb 1387 e3 `2596284432` 0 t rb 1388 end 1389 emit or `3942646303` shl ra 16 1390 trapc 1 1 1391 emit or or `2852127712` rd shl t 16 1392 ret 1393 end 1394 if ne imm 0 1395 bo_lsl ra rb rd 1396 bo_fix rd ty 1397 ret 1398 end 1399 bo_schk ty rb 1400 if eq ty 4 1401 bo_w3 `448798720` rd ra rb 0 1402 ret 1403 end 1404 bo_w3 `2596282368` rd ra rb 0 1405 bo_fix rd ty 1406 end 1407 1408 note shr: unsigned LSR, signed ASR; by a number UBFM / SBFM Xd, Xn, #s, #63; by a register the amount check 1409 note then LSRV / ASRV (om4 BO_SHR) 1410 fn bo_shr ty ulong ra ulong rb ulong imm ulong rd ulong to void 1411 if ne imm 0 1412 fi = ulong `3544251392` 1413 if ge ty 6 1414 fi = ulong `2470509568` 1415 end 1416 emit or or or fi shl rb 16 shl ra 5 rd 1417 ret 1418 end 1419 bo_schk ty rb 1420 fx = ulong `2596283392` 1421 if ge ty 6 1422 fx = ulong `2596284416` 1423 end 1424 bo_w3 fx rd ra rb 0 1425 end 1426 1427 note comparisons: CMP Xa, #imm or CMP Xa, Xb; the result is the flags and a condition (om4 BO_CMP) 1428 fn bo_cmp op ulong ty ulong ra ulong rb ulong imm ulong to void 1429 if ne imm 0 1430 emit or or `4043309087` shl rb 10 shl ra 5 1431 else 1432 emit or or `3942645791` shl rb 16 shl ra 5 1433 end 1434 i = mul sub op 43 2 1435 if ge ty 6 1436 i = add i 1 1437 end 1438 put rk 0 4 1439 put rv 0 conds i 1440 put rt 0 1 1441 end 1442 1443 note binop: op 33..48, destination (255 none), ix the fr slot of a (kind, number/register, type) then b. 1444 note Result in rk/rv/rt. om4 BINOP. 1445 fn binop op ulong dst ulong ix ulong to void 1446 ty = get fr add ix 2 1447 ra = matreg get fr ix get fr add ix 1 ty 1448 imm = ulong 0 1449 bk = get fr add ix 3 1450 bn = get fr add ix 4 1451 rb = ulong 0 1452 useimm = false 1453 if eq bk 3 1454 if or eq op 41 eq op 42 1455 if lt bn twid ty 1456 useimm = true 1457 end 1458 else 1459 if or lt op 35 ge op 43 1460 if le bn 4095 1461 useimm = true 1462 end 1463 end 1464 end 1465 end 1466 if useimm 1467 rb = bn 1468 imm = ulong 1 1469 else 1470 rb = matreg bk bn get fr add ix 5 1471 end 1472 if ge op 43 1473 bo_cmp op ty ra rb imm 1474 ret 1475 end 1476 if eq ty 1 1477 if gt sub op 38 2 1478 fail 7 1479 end 1480 end 1481 rd = destreg dst 1482 if lt op 35 1483 bo_add op ty ra rb imm rd 1484 else 1485 if eq op 35 1486 bo_mul ty ra rb rd 1487 else 1488 if lt op 38 1489 fl = ulong 0 1490 if and eq bk 3 ne bn 0 1491 fl = or fl 1 1492 end 1493 if and eq bk 3 ne bn `18446744073709551615` 1494 fl = or fl 2 1495 end 1496 bo_div op ty ra rb rd fl 1497 else 1498 if lt op 41 1499 bo_log op ra rb rd 1500 else 1501 if eq op 41 1502 bo_shl ty ra rb imm rd 1503 else 1504 bo_shr ty ra rb imm rd 1505 end 1506 end 1507 end 1508 end 1509 end 1510 put rk 0 1 1511 put rv 0 rd 1512 put rt 0 ty 1513 end 1514 1515 note ======== calls: registers saved around a call and loaded back ======== 1516 global svn ulong 1 1517 global sva ulong 1 1518 note save: n = registers in use (parameters + pool slots), A = 8 (n + 1) rounded up to 16: SUB SP, SP, #A 1519 note (C6.2.457); the stack check; STR Xr, [SP, #8j] for each (C6.2.415); STR X30, [SP, #8n]. Out: svn n, 1520 note sva A. om4 SAVE. 1521 fn save to void 1522 n = add get npar 0 get nslot 0 1523 a = shl shr add n 2 1 4 1524 put svn 0 n 1525 put sva 0 a 1526 spsub a 1527 stkchk 1528 j = ulong 0 1529 while lt j n 1530 emit or or `4177527776` poolc j shl j 10 1531 j = add j 1 1532 end 1533 emit or `4177527806` shl n 10 1534 end 1535 1536 note loadarg: register t from an argument: kind 1 or 5 a register v, read back from its save slot (LDR Xt, 1537 note [SP, #8 slot], C6.2.216); kind 3 or 6 the number or address v. om4 LOADARG. 1538 fn loadarg t ulong k ulong v ulong to void 1539 if or eq k 3 eq k 6 1540 matconst t v 1541 ret 1542 end 1543 emit or or `4181722080` t shl regidx v 10 1544 end 1545 1546 note basearg: register t = the base of array name e (index + 1): its register from the save area, or its 1547 note address. om4 BASEARG. 1548 fn basearg t ulong e ulong to void 1549 i = sub e 1 1550 if ge get nm_kind i 4 1551 matconst t get nm_addr i 1552 ret 1553 end 1554 loadarg t 1 ulong get nm_reg i 1555 end 1556 1557 note restore: d destination (255: a new temporary at pool slot `slot`), slot the pool slot before the 1558 note arguments, n saved count, a save bytes, res 1 if there is a result in X0. MOV Xd, X0 (C6.2.282); LDR 1559 note each register in use before the arguments except Xd (C6.2.216); LDR X30; ADD SP, SP, #A (C6.2.5). 1560 note Returns Xd (255 when no result). om4 RESTORE. 1561 fn restore d ulong slot ulong n ulong a ulong res ulong to ulong 1562 put nslot 0 slot 1563 rd = ulong 255 1564 if ne res 0 1565 rd = d 1566 if eq d 255 1567 rd = alloc 1568 end 1569 if ne rd 0 1570 emit or `2852127712` rd 1571 end 1572 end 1573 m = add get npar 0 slot 1574 j = ulong 0 1575 while lt j m 1576 r = poolc j 1577 if ne r rd 1578 emit or or `4181722080` r shl j 10 1579 end 1580 j = add j 1 1581 end 1582 emit or `4181722110` shl n 10 1583 spadd a 1584 ret rd 1585 end 1586 1587 note ca_bl: BL to function f (index + 1), C6.2.43 1588 fn ca_bl f ulong to void 1589 n = get ncalls 0 1590 if ge n 65536 1591 fail 14 1592 end 1593 put callsite n get oc 0 1594 put callfrom n get curfn 0 1595 put callto n f 1596 put ncalls 0 add n 1 1597 1598 emit or `2483027968` and shr sub get fn_addr sub f 1 get oc 0 2 `67108863` 1599 end 1600 1601 note ======== element addresses and array arguments ======== 1602 global ea_b ulong 1 1603 global ea_i ulong 1 1604 note elemaddr: array name e (index + 1), index value (kind, number or register, type). A number index must 1605 note be inside the array (error 21) and needs no check; a register index: CMP Xi, #len (C6.2.96) or CMP Xi, 1606 note Xt (C6.2.97), B.HS trap 3 (unsigned, so a negative signed index traps too). Out: ea_b base register 1607 note (the array's register, or a new one holding its address), ea_i index register. om4 ELEMADDR. 1608 fn elemaddr e ulong k ulong v ulong t ulong to void 1609 if eq t 1 1610 fail 7 1611 end 1612 i = sub e 1 1613 ln = get nm_len i 1614 x = v 1615 if eq k 3 1616 if ge v ln 1617 fail 21 1618 end 1619 x = alloc 1620 matconst x v 1621 else 1622 if le ln 4095 1623 emit or or `4043309087` shl ln 10 shl v 5 1624 else 1625 y = alloc 1626 matconst y ln 1627 emit or or `3942645791` shl y 16 shl v 5 1628 end 1629 trapc 2 3 1630 end 1631 put ea_i 0 x 1632 if ge get nm_kind i 4 1633 b = alloc 1634 matconst b get nm_addr i 1635 put ea_b 0 b 1636 else 1637 put ea_b 0 ulong get nm_reg i 1638 end 1639 end 1640 1641 note aa_word: the next word of an array argument must be a name of at most 8 bytes 1642 fn aa_word to void 1643 tok 1644 k = get tk 0 1645 if eq k 0 1646 fail 4 1647 end 1648 if ne k 1 1649 fail 16 1650 end 1651 if gt get tl 0 8 1652 fail 13 1653 end 1654 end 1655 1656 note arrarg: an array argument for parameter pi of function f (index + 1): [view | edit] NAME. Its type and 1657 note length must equal the parameter's; an edit parameter needs a writable array (local or edit, error 20; 1658 note a view passed to it is error 20, OMEGESE.md 9.4); a global is never passed (error 19). Out: rk 5 1659 note (register rv) or 6 (address rv, a text), rt the name entry. om4 ARRARG. 1660 fn arrarg f ulong pi ulong to void 1661 md = ulong 0 1662 aa_word 1663 w = get tw 0 1664 c = kw w 1665 if ne c 0 1666 if or lt c 57 gt c 58 1667 fail 16 1668 end 1669 md = c 1670 aa_word 1671 w = get tw 0 1672 end 1673 e = findname w 1674 if eq e 0 1675 fail 3 1676 end 1677 i = sub e 1 1678 k = ulong get nm_kind i 1679 if eq k 0 1680 fail 7 1681 end 1682 if eq k 4 1683 fail 19 1684 end 1685 p = add mul sub f 1 6 pi 1686 if eq get fn_pk p 3 1687 if eq md 57 1688 fail 20 1689 end 1690 if and ne k 1 ne k 3 1691 fail 20 1692 end 1693 else 1694 if eq md 58 1695 fail 7 1696 end 1697 end 1698 if ne get nm_type i get fn_pt p 1699 fail 7 1700 end 1701 if ne get nm_len i get fn_pl p 1702 fail 7 1703 end 1704 put rt 0 e 1705 if eq k 5 1706 put rk 0 6 1707 put rv 0 get nm_addr i 1708 else 1709 put rk 0 5 1710 put rv 0 ulong get nm_reg i 1711 end 1712 end 1713 1714 note ======== the parts of the value reader that read no further value ======== 1715 fn vdec to void 1716 put depth 0 sub get depth 0 1 1717 end 1718 1719 note vdone: a value's result, and one nesting level less (om4 VT_RET) 1720 fn vdone k ulong v ulong t ulong to void 1721 put rk 0 k 1722 put rv 0 v 1723 put rt 0 t 1724 vdec 1725 end 1726 1727 note vt_un: neg / not of the value in rk/rv/rt (a bare number already refused). neg: NEG Xd, Xm (SUB from 1728 note XZR, C6.2.458; the 32-bit form for u32), i64 NEGS + B.VS trap 1 (C6.2.465), then the wrap or the 1729 note sign check; not: bool EOR Xd, Xn, #1 (C6.2.155), else MVN (ORN from XZR, C6.2.300), then the wrap. 1730 note om4 VU1 .. VU_E. 1731 fn vt_un c ulong dst ulong to void 1732 ty = get rt 0 1733 ra = matreg get rk 0 get rv 0 ty 1734 rd = destreg dst 1735 if eq c 50 1736 if eq ty 1 1737 e3 `3527409664` rd ra 0 1738 else 1739 if eq ty 4 1740 e3 `706741216` rd 0 ra 1741 else 1742 e3 `2854224864` rd 0 ra 1743 if lt ty 6 1744 canon rd ty 1745 end 1746 end 1747 end 1748 else 1749 if eq ty 1 1750 fail 7 1751 end 1752 if eq ty 9 1753 e3 `3942646752` rd 0 ra 1754 trapc 6 1 1755 else 1756 if eq ty 4 1757 e3 `1258292192` rd 0 ra 1758 else 1759 e3 `3405775840` rd 0 ra 1760 if lt ty 6 1761 canon rd ty 1762 else 1763 chkext rd ty 1 1764 end 1765 end 1766 end 1767 end 1768 put rk 0 1 1769 put rv 0 rd 1770 put rt 0 ty 1771 end 1772 1773 note vt_conv: the value in rk/rv/rt converted to type tt (neither bool, error 9). Out of range when any bit 1774 note at or above s is set: LSR Xt, Xa, #s (UBFM, C6.2.487); CBNZ Xt trap 5 (C6.2.77); signed to a narrower 1775 note signed type: the sign-extension check, trap 5. om4 VTT1 .. VC_OK. 1776 fn vt_conv tt ulong to void 1777 ft = get rt 0 1778 ra = matreg get rk 0 get rv 0 ft 1779 if eq ft 1 1780 fail 9 1781 end 1782 if eq tt 1 1783 fail 9 1784 end 1785 wf = twid ft 1786 wt = twid tt 1787 s = ulong 99 1788 if lt ft 6 1789 if ge tt 6 1790 if ge wf wt 1791 s = sub wt 1 1792 end 1793 else 1794 if gt wf wt 1795 s = wt 1796 end 1797 end 1798 else 1799 if lt tt 6 1800 s = wt 1801 if gt s 63 1802 s = ulong 63 1803 end 1804 else 1805 if gt wf wt 1806 chkext ra tt 5 1807 end 1808 end 1809 end 1810 if ne s 99 1811 t = alloc 1812 emit or or or `3544251392` t shl s 16 shl ra 5 1813 trapsite or `3036676096` t 5 1814 end 1815 put rk 0 1 1816 put rv 0 ra 1817 put rt 0 tt 1818 end 1819 1820 note vt_get: get A i with the index value in rk/rv/rt: the element address, then the load of the element 1821 note type, register offset (LDOP table). om4 VT_GET. 1822 fn vt_get e ulong dst ulong to void 1823 elemaddr e get rk 0 get rv 0 get rt 0 1824 rd = destreg dst 1825 ty = ulong get nm_type sub e 1 1826 w = or ldop ty rd 1827 emit or or w shl get ea_b 0 5 shl get ea_i 0 16 1828 put rk 0 1 1829 put rv 0 rd 1830 put rt 0 ty 1831 end 1832 1833 note vs_chk: read / write bounds: n <= len A and off <= len A - n, else trap 3 (CMP C6.2.97, B.HI C6.2.34, 1834 note SUB C6.2.458). om4 VT_SYS. 1835 fn vs_chk e ulong ro ulong rn ulong to void 1836 t = alloc 1837 matconst t get nm_len sub e 1 1838 emit or or `3942645791` shl rn 5 shl t 16 1839 trapc 8 3 1840 e3 `3405774848` t t rn 1841 emit or or `3942645791` shl ro 5 shl t 16 1842 trapc 8 3 1843 end 1844 1845 note vs_call: save the registers in use, X0 = fd, X1 = A + off (ADD through X16, C6.2.6), X2 = n, X8 = 63 1846 note (read) or 64 (write) (MOVZ C6.2.285), SVC #0 (C6.2.466). om4 VT_SYS. 1847 fn vs_call c ulong fk ulong fv ulong e ulong ro ulong rn ulong to void 1848 save 1849 loadarg 0 fk fv 1850 basearg 1 e 1851 loadarg 16 1 ro 1852 emit `2333081633` 1853 loadarg 2 1 rn 1854 emit or `3531603976` shl add c 10 5 1855 emit `3556769793` 1856 end 1857 1858 note ca_scal: a scalar argument just read (rk/rv/rt) for parameter p: flags into a register; its type 1859 note must be the parameter's; stored at fr[q..q+2]. om4 CA1 .. CA_PUT. 1860 fn ca_scal p ulong q ulong to void 1861 if eq get rk 0 4 1862 put rv 0 matreg 4 get rv 0 get rt 0 1863 put rk 0 1 1864 put rt 0 1 1865 end 1866 if ne get rt 0 ulong get fn_pt p 1867 fail 7 1868 end 1869 put fr q get rk 0 1870 put fr add q 1 get rv 0 1871 put fr add q 2 0 1872 end 1873 1874 note ca_arr: an array argument i of function f, call frame cb: one array passed twice is error 19. 1875 note om4 CA_ARR .. CA_PUT. 1876 fn ca_arr f ulong i ulong cb ulong to void 1877 arrarg f i 1878 j = ulong 0 1879 while lt j i 1880 if eq get fr add add cb mul j 3 2 get rt 0 1881 fail 19 1882 end 1883 j = add j 1 1884 end 1885 q = add cb mul i 3 1886 put fr q get rk 0 1887 put fr add q 1 get rv 0 1888 put fr add q 2 get rt 0 1889 end 1890 1891 note ca_end: all arguments read: save, the arguments into X0.., BL, restore. Frame cb: 3 per argument, 1892 note then cb+18 the parameter count, cb+19 the pool slot before the arguments. om4 CA_DONE .. CA5. 1893 fn ca_end f ulong dst ulong cb ulong to void 1894 save 1895 np = get fr add cb 18 1896 i = ulong 0 1897 while lt i np 1898 q = add cb mul i 3 1899 loadarg i get fr q get fr add q 1 1900 i = add i 1 1901 end 1902 ca_bl f 1903 hr = ulong 1 1904 if eq get fn_ret sub f 1 10 1905 hr = ulong 0 1906 end 1907 n = get svn 0 1908 a = get sva 0 1909 sl = get fr add cb 19 1910 r = restore dst sl n a hr 1911 put rk 0 1 1912 put rv 0 r 1913 put rt 0 ulong get fn_ret sub f 1 1914 end 1915 1916 note vs_fd, vs_arr, vs_off, vs_end: the steps of read / write between the values it reads, with the fd 1917 note (kind, value), the offset register and the pool slot before kept in fr[x+8..x+11] (om4's VT_SYS 1918 note frame slots 4, 5, 7 and 14) 1919 fn vs_fd x ulong to void 1920 if ne get rt 0 8 1921 fail 7 1922 end 1923 put fr add x 9 get rk 0 1924 put fr add x 10 get rv 0 1925 end 1926 1927 fn vs_arr c ulong e ulong to void 1928 if eq c 53 1929 k = get nm_kind sub e 1 1930 if or eq k 2 eq k 5 1931 fail 20 1932 end 1933 end 1934 end 1935 1936 fn vs_off x ulong to void 1937 if ne get rt 0 5 1938 fail 7 1939 end 1940 put fr add x 11 matreg get rk 0 get rv 0 get rt 0 1941 end 1942 1943 fn vs_end c ulong e ulong dst ulong x ulong to void 1944 if ne get rt 0 5 1945 fail 7 1946 end 1947 rn = matreg get rk 0 get rv 0 get rt 0 1948 ro = get fr add x 11 1949 vs_chk e ro rn 1950 fk = get fr add x 9 1951 fv = get fr add x 10 1952 vs_call c fk fv e ro rn 1953 sl = get fr add x 8 1954 n = get svn 0 1955 a = get sva 0 1956 r = restore dst sl n a 1 1957 vdone 1 r 9 1958 end 1959 1960 note Native Linux ARM64 host operations. Encoding forms are those in seed/rung2/table.s2. 1961 note Syscall numbers and layouts: Linux asm-generic/unistd.h, fcntl.h and time.h. 1962 note No raw address or arbitrary syscall is exposed to an Omega program. 1963 fn hargc c ulong to ulong 1964 if or or eq c 107 eq c 109 eq c 129 1965 ret 0 1966 end 1967 if or eq c 100 eq c 101 1968 ret 1 1969 end 1970 if or or or eq c 102 eq c 105 eq c 106 eq c 127 1971 ret 2 1972 end 1973 ret 3 1974 end 1975 fn hsysno c ulong to ulong 1976 if eq c 127 1977 ret 129 1978 end 1979 if eq c 129 1980 ret 172 1981 end 1982 if eq c 100 1983 ret 57 1984 end 1985 if eq c 101 1986 ret 82 1987 end 1988 if eq c 102 1989 ret 52 1990 end 1991 if eq c 103 1992 ret 62 1993 end 1994 if eq c 104 1995 ret 198 1996 end 1997 if eq c 105 1998 ret 201 1999 end 2000 if eq c 106 2001 ret 242 2002 end 2003 if eq c 107 2004 ret 220 2005 end 2006 ret 24 2007 end 2008 fn harg x ulong i ulong ty ulong to void 2009 rdval 0 ty 255 0 2010 if ne get rt 0 ty 2011 fail 7 2012 end 2013 q = add add x 8 mul i 2 2014 put fr q get rk 0 2015 put fr add q 1 get rv 0 2016 end 2017 fn hload x ulong i ulong reg ulong to void 2018 q = add add x 8 mul i 2 2019 loadarg reg get fr q get fr add q 1 2020 end 2021 fn hsys n ulong to void 2022 matconst 8 n 2023 emit `3556769793` 2024 end 2025 fn hreturn dst ulong x ulong to void 2026 sl = get fr add x 7 2027 n = get svn 0 2028 a = get sva 0 2029 r = restore dst sl n a 1 2030 vdone 1 r 9 2031 end 2032 fn hscalar c ulong dst ulong x ulong to void 2033 np = hargc c 2034 for i ulong np 2035 ty = ulong 8 2036 if and eq c 103 eq i 1 2037 ty = ulong 9 2038 end 2039 harg x i ty 2040 end 2041 save 2042 for i ulong np 2043 hload x i i 2044 end 2045 if eq c 106 2046 hload x 1 3 2047 matconst 1 0 2048 matconst 2 0 2049 end 2050 if eq c 107 2051 matconst 0 17 2052 for i ulong 5 2053 matconst add i 1 0 2054 end 2055 end 2056 hsys hsysno c 2057 hreturn dst x 2058 end 2059 fn hclock c ulong dst ulong x ulong to void 2060 save 2061 spsub 16 2062 stkchk 2063 matconst 0 1 2064 if eq c 130 2065 matconst 0 0 2066 end 2067 emit `2432697313` 2068 hsys 113 2069 emit `4043309087` 2070 bad = get oc 0 2071 emit `1409286155` 2072 emit `4181722081` 2073 emit `4181723106` 2074 note Reject overflow before seconds are multiplied; clock result is a signed nanosecond count. 2075 matconst 3 `9223372036` 2076 e3 `3942645760` 31 1 3 2077 trapc 8 1 2078 matconst 3 `1000000000` 2079 e3 `2600500224` 1 1 3 2080 e3 `2868903936` 0 1 2 2081 trapc 6 1 2082 patch19 bad get oc 0 2083 spadd 16 2084 hreturn dst x 2085 end 2086 fn harray x ulong writable ulong to ulong 2087 e = arrname 2088 if ne get nm_type sub e 1 2 2089 fail 7 2090 end 2091 if ne writable 0 2092 vs_arr 53 e 2093 end 2094 put fr add x 20 e 2095 harg x 0 5 2096 harg x 1 5 2097 ro = matreg get fr add x 8 get fr add x 9 5 2098 rn = matreg get fr add x 10 get fr add x 11 5 2099 put fr add x 21 ro 2100 put fr add x 22 rn 2101 vs_chk e ro rn 2102 ret e 2103 end 2104 note Copy a checked path to a private 4096-byte stack buffer. Reject embedded zero bytes. 2105 note Public paths remain length-delimited; only the kernel-facing private copy has a terminator. 2106 fn hpathcp x ulong to void 2107 e = get fr add x 20 2108 save 2109 basearg 4 e 2110 loadarg 16 1 get fr add x 21 2111 e3 `2332033024` 4 4 16 2112 loadarg 5 1 get fr add x 22 2113 matconst 6 4095 2114 e3 `3942645760` 31 5 6 2115 trapc 8 3 2116 end 2117 fn hcopy to void 2118 spsub 4096 2119 stkchk 2120 emit `2432697313` 2121 head = get oc 0 2122 emit `4043309247` 2123 done = get oc 0 2124 emit `1409286144` 2125 emit `960495750` 2126 emit `4043309279` 2127 trapc 0 3 2128 emit `956301350` 2129 emit `2432697476` 2130 emit `2432697377` 2131 emit `3506439333` 2132 back head 2133 patch19 done get oc 0 2134 emit `956301375` 2135 emit `2432697313` 2136 matconst 0 `18446744073709551516` 2137 end 2138 fn hpath c ulong dst ulong x ulong to void 2139 e = harray x 0 2140 if eq c 110 2141 harg x 2 8 2142 harg x 3 8 2143 end 2144 if eq c 112 2145 harg x 2 8 2146 end 2147 hpathcp x 2148 if eq c 110 2149 hload x 2 2 2150 hload x 3 3 2151 end 2152 if eq c 111 2153 matconst 2 0 2154 end 2155 if eq c 126 2156 matconst 2 512 2157 end 2158 if eq c 112 2159 hload x 2 2 2160 end 2161 hcopy 2162 nr = ulong 56 2163 if or eq c 111 eq c 126 2164 nr = ulong 35 2165 end 2166 if eq c 112 2167 nr = ulong 34 2168 end 2169 hsys nr 2170 spadd 4096 2171 hreturn dst x 2172 end 2173 fn hbuffer c ulong dst ulong x ulong to void 2174 harg x 4 8 2175 wr = ulong 0 2176 if or or or or eq c 113 eq c 116 eq c 117 eq c 118 eq c 131 2177 wr = ulong 1 2178 end 2179 e = harray x wr 2180 if or or eq c 116 eq c 118 eq c 119 2181 harg x 2 8 2182 end 2183 if or eq c 116 eq c 117 2184 need = ulong 4 2185 if eq c 117 2186 need = ulong 128 2187 end 2188 tmp = alloc 2189 matconst tmp need 2190 e3 `3942645760` 31 get fr add x 22 tmp 2191 trapc 3 3 2192 end 2193 save 2194 hload x 4 0 2195 basearg 1 e 2196 loadarg 16 1 get fr add x 21 2197 e3 `2332033024` 1 1 16 2198 loadarg 2 1 get fr add x 22 2199 nr = ulong 61 2200 if eq c 114 2201 nr = ulong 203 2202 end 2203 if eq c 115 2204 nr = ulong 200 2205 end 2206 if eq c 116 2207 nr = ulong 260 2208 hload x 2 2 2209 matconst 3 0 2210 end 2211 if eq c 117 2212 nr = ulong 80 2213 end 2214 if or eq c 118 eq c 119 2215 nr = ulong 207 2216 hload x 2 3 2217 matconst 4 0 2218 matconst 5 0 2219 if eq c 119 2220 nr = ulong 206 2221 matconst 16 16384 2222 e3 `2852126720` 3 3 16 2223 end 2224 end 2225 2226 if eq c 131 2227 note getsockname uses a private 32-bit socklen. Success returns the full address length. 2228 spsub 16 2229 stkchk 2230 emit `3103785954` 2231 emit `2432697314` 2232 hsys 204 2233 emit `4043309087` 2234 failed = get oc 0 2235 emit `1409286155` 2236 emit `3107980256` 2237 patch19 failed get oc 0 2238 spadd 16 2239 else 2240 hsys nr 2241 end 2242 hreturn dst x 2243 end 2244 fn hsleep dst ulong x ulong to void 2245 harg x 0 9 2246 save 2247 hload x 0 2 2248 emit `4043309151` 2249 trapc 11 3 2250 spsub 16 2251 stkchk 2252 matconst 3 `1000000000` 2253 e3 `2596276224` 4 2 3 2254 note MSUB x5,x4,x3,x2 gives the subsecond remainder. 2255 emit `2600700037` 2256 emit `4177527780` 2257 emit `4177528805` 2258 emit `2432697312` 2259 matconst 1 0 2260 hsys 101 2261 spadd 16 2262 hreturn dst x 2263 end 2264 fn hargs c ulong dst ulong x ulong to void 2265 if eq c 121 2266 save 2267 emit `4181721952` 2268 hreturn dst x 2269 ret 2270 end 2271 harg x 4 5 2272 e = harray x 1 2273 save 2274 hload x 4 0 2275 emit `4181721953` 2276 e3 `3942645760` 31 0 1 2277 trapc 2 3 2278 emit `2432697344` 2279 matconst 16 8 2280 e3 `2600500224` 0 0 16 2281 e3 `2332033024` 3 27 0 2282 emit `4181721187` 2283 e3 `2852126720` 4 31 3 2284 matconst 5 0 2285 scan = get oc 0 2286 emit `960495750` 2287 emit `4043309279` 2288 done = get oc 0 2289 emit `1409286144` 2290 emit `2432697476` 2291 emit `2432697509` 2292 matconst 16 `1048576` 2293 e3 `3942645760` 31 5 16 2294 trapc 2 3 2295 back scan 2296 patch19 done get oc 0 2297 loadarg 2 1 get fr add x 22 2298 e3 `3942645760` 31 5 2 2299 small = get oc 0 2300 emit `1409286152` 2301 basearg 0 e 2302 loadarg 16 1 get fr add x 21 2303 e3 `2332033024` 0 0 16 2304 e3 `2852126720` 2 31 5 2305 copy = get oc 0 2306 emit `4043309247` 2307 endcp = get oc 0 2308 emit `1409286144` 2309 emit `960495718` 2310 emit `956301318` 2311 emit `2432697443` 2312 emit `2432697344` 2313 emit `3506439333` 2314 back copy 2315 patch19 endcp get oc 0 2316 e3 `2852126720` 0 31 2 2317 endbr = get oc 0 2318 emit `335544320` 2319 patch19 small get oc 0 2320 matconst 0 `18446744073709551511` 2321 patch26 endbr get oc 0 2322 hreturn dst x 2323 end 2324 2325 note waitio(fd int, events int, timeout_ns long): revents, 0 timeout, or negative errno. 2326 note ppoll uses one private pollfd and one private timespec. Negative timeout is infinite. 2327 fn hwaitio dst ulong x ulong to void 2328 harg x 0 8 2329 harg x 1 8 2330 harg x 2 9 2331 save 2332 hload x 0 0 2333 hload x 1 1 2334 hload x 2 2 2335 note pollfd.events is 16 bits; refuse truncation of the public int argument. 2336 emit `4043309119` 2337 trapc 11 3 2338 matconst 16 65535 2339 e3 `3942645760` 31 1 16 2340 trapc 8 3 2341 spsub 32 2342 stkchk 2343 emit `4177527807` 2344 emit `3103785952` 2345 emit `2030046177` 2346 matconst 3 `1000000000` 2347 emit `4043309151` 2348 forever = get oc 0 2349 emit `1409286155` 2350 e3 `2596276224` 4 2 3 2351 emit `2600700037` 2352 emit `4177528804` 2353 emit `4177529829` 2354 emit `2432705506` 2355 jump = get oc 0 2356 emit `335544320` 2357 patch19 forever get oc 0 2358 matconst 2 0 2359 patch26 jump get oc 0 2360 emit `2432697312` 2361 matconst 1 1 2362 matconst 3 0 2363 matconst 4 8 2364 hsys 73 2365 emit `4043309087` 2366 failed = get oc 0 2367 emit `1409286157` 2368 emit `2034241504` 2369 patch19 failed get oc 0 2370 spadd 32 2371 hreturn dst x 2372 end 2373 2374 note Strict stdio profile uses Linux UAPI layouts, not exposed native pointers. Guest scratch640 bytes. 2375 note sock_filter is u16 code,u8 jt,u8 jf,u32 k; sock_fprog length at0 and pointer at8 on AArch64. 2376 note Landlock path rule is packed u64 allowed_access plus s32 parent_fd. prlimit64 uses two u64s. 2377 fn hsptr reg ulong off ulong to void 2378 emit or or `2432697312` reg shl off 10 2379 end 2380 fn hstore off ulong value ulong to void 2381 matconst 0 value 2382 hsptr 16 off 2383 e3 `4177526784` 0 16 0 2384 end 2385 fn hbad to ulong 2386 emit `4043309087` 2387 at = get oc 0 2388 emit `1409286155` 2389 ret at 2390 end 2391 fn hlimit resource ulong soft ulong hard ulong to ulong 2392 hstore 48 soft 2393 hstore 56 hard 2394 matconst 0 0 2395 matconst 1 resource 2396 hsptr 2 48 2397 matconst 3 0 2398 hsys 261 2399 ret hbad 2400 end 2401 fn hfilter i ulong op ulong jt ulong jf ulong k ulong to void 2402 word = or or op shl jt 16 or shl jf 24 shl k 32 2403 hstore add 128 mul i 8 word 2404 end 2405 fn hpure to void 2406 errs = new ulong 24 0 2407 n = ulong 0 2408 spsub 640 2409 stkchk 2410 hsptr 16 632 2411 e3 `4177526784` 11 16 0 2412 note Extra descriptors have already been closed in a private table. Pin executable as descriptor3. 2413 matconst 0 `18446744073709551516` 2414 hsptr 1 640 2415 matconst 2 `2621440` 2416 matconst 3 0 2417 hsys 56 2418 put errs n hbad 2419 n = add n 1 2420 note ABI3 rights through TRUNCATE are all handled, with only read/execute of that one inode allowed. 2421 hstore 0 32767 2422 hsptr 0 0 2423 matconst 1 8 2424 matconst 2 0 2425 hsys 444 2426 put errs n hbad 2427 n = add n 1 2428 hstore 16 5 2429 hstore 24 3 2430 matconst 0 4 2431 matconst 1 1 2432 hsptr 2 16 2433 matconst 3 0 2434 hsys 445 2435 put errs n hbad 2436 n = add n 1 2437 matconst 0 38 2438 matconst 1 1 2439 matconst 2 0 2440 matconst 3 0 2441 matconst 4 0 2442 hsys 167 2443 put errs n hbad 2444 n = add n 1 2445 matconst 0 4 2446 matconst 1 0 2447 hsys 172 2448 put errs n hbad 2449 n = add n 1 2450 matconst 0 4 2451 hsys 57 2452 put errs n hbad 2453 n = add n 1 2454 note Per-process ceilings. Pipe-output and wall budgets additionally require the trusted supervisor. 2455 put errs n hlimit 0 1 2 2456 n = add n 1 2457 put errs n hlimit 1 `1048576` `1048576` 2458 n = add n 1 2459 put errs n hlimit 3 `8388608` `8388608` 2460 n = add n 1 2461 put errs n hlimit 4 0 0 2462 n = add n 1 2463 put errs n hlimit 6 0 0 2464 n = add n 1 2465 put errs n hlimit 7 4 4 2466 n = add n 1 2467 put errs n hlimit 9 `134217728` `134217728` 2468 n = add n 1 2469 note Validate architecture, then read only0,write only1/2,exit/exit_group. Everything else is EPERM. 2470 note execveat is restricted to descriptor3 and AT_EMPTY_PATH; Landlock also binds execution to inode3. 2471 note The inode rule is essential: an absolute execveat path otherwise ignores its dirfd argument. 2472 hfilter 0 32 0 0 4 2473 hfilter 1 21 1 0 `3221225655` 2474 hfilter 2 6 0 0 `2147483648` 2475 hfilter 3 32 0 0 0 2476 hfilter 4 21 0 3 63 2477 hfilter 5 32 0 0 16 2478 hfilter 6 21 0 1 0 2479 hfilter 7 6 0 0 `2147418112` 2480 hfilter 8 32 0 0 0 2481 hfilter 9 21 0 4 64 2482 hfilter 10 32 0 0 16 2483 hfilter 11 21 1 0 1 2484 hfilter 12 21 0 1 2 2485 hfilter 13 6 0 0 `2147418112` 2486 hfilter 14 32 0 0 0 2487 hfilter 15 21 0 1 93 2488 hfilter 16 6 0 0 `2147418112` 2489 hfilter 17 21 0 1 94 2490 hfilter 18 6 0 0 `2147418112` 2491 hfilter 19 32 0 0 0 2492 hfilter 20 21 0 5 281 2493 hfilter 21 32 0 0 16 2494 hfilter 22 21 0 3 3 2495 hfilter 23 32 0 0 48 2496 hfilter 24 21 0 1 4096 2497 hfilter 25 6 0 0 `2147418112` 2498 hfilter 26 6 0 0 327681 2499 hstore 80 27 2500 hsptr 0 128 2501 hsptr 16 88 2502 e3 `4177526784` 0 16 0 2503 matconst 0 1 2504 matconst 1 0 2505 hsptr 2 80 2506 hsys 277 2507 put errs n hbad 2508 n = add n 1 2509 note Restore original packet stack before entering pinned executable. Descriptor3 is CLOEXEC. 2510 hsptr 16 632 2511 e3 `4181721088` 11 16 0 2512 spadd 640 2513 matconst 0 3 2514 e3 `2852126720` 1 31 11 2515 emit `2436892642` 2516 e3 `2852126720` 3 31 11 2517 matconst 4 4096 2518 hsys 281 2519 finished = get oc 0 2520 emit `335544320` 2521 for i ulong n 2522 patch19 get errs i get oc 0 2523 end 2524 hsptr 16 632 2525 e3 `4181721088` 11 16 0 2526 spadd 640 2527 patch26 finished get oc 0 2528 end 2529 2530 note A packed argument list is u16 count followed by count (u16 length, bytes) records. 2531 note Byte order is little-endian. The packet is at most 4096 bytes and 64 records. 2532 note The decoder constructs kernel pointers only in private stack memory. 2533 fn hpack c ulong dst ulong x ulong to void 2534 e = harray x 0 2535 if eq c 125 2536 harg x 2 8 2537 end 2538 save 2539 basearg 4 e 2540 loadarg 16 1 get fr add x 21 2541 e3 `2332033024` 4 4 16 2542 loadarg 5 1 get fr add x 22 2543 matconst 16 4096 2544 e3 `3942645760` 31 5 16 2545 trapc 8 3 2546 emit `4043311295` 2547 trapc 3 3 2548 if eq c 125 2549 hload x 2 14 2550 end 2551 spsub 8192 2552 stkchk 2553 emit `2034237574` 2554 emit `2432698500` 2555 emit `3506440357` 2556 emit `4043309279` 2557 trapc 0 3 2558 matconst 16 64 2559 e3 `3942645760` 31 6 16 2560 trapc 8 3 2561 if eq c 125 2562 emit `4043311327` 2563 trapc 1 3 2564 end 2565 matconst 9 0 2566 emit `2432697322` 2567 emit `2436892651` 2568 outer = get oc 0 2569 e3 `3942645760` 31 9 6 2570 done = get oc 0 2571 emit `1409286146` 2572 emit `4043311295` 2573 trapc 3 3 2574 emit `2034237580` 2575 emit `2432698500` 2576 emit `3506440357` 2577 e3 `3942645760` 31 12 5 2578 trapc 8 3 2579 note A program path and both rename paths must be nonempty. 2580 if or eq c 124 eq c 135 2581 emit `4043309375` 2582 notfirst = get oc 0 2583 emit `1409286145` 2584 emit `4043309471` 2585 trapc 0 3 2586 patch19 notfirst get oc 0 2587 else 2588 emit `4043309471` 2589 trapc 0 3 2590 end 2591 emit `4177527146` 2592 emit `2432704875` 2593 inner = get oc 0 2594 emit `4043309471` 2595 endstr = get oc 0 2596 emit `1409286144` 2597 emit `960495757` 2598 emit `4043309503` 2599 trapc 0 3 2600 emit `956301645` 2601 emit `2432697476` 2602 emit `2432697674` 2603 emit `3506439333` 2604 emit `3506439564` 2605 back inner 2606 patch19 endstr get oc 0 2607 emit `956301663` 2608 emit `2432697674` 2609 emit `2432697641` 2610 back outer 2611 patch19 done get oc 0 2612 emit `4043309247` 2613 trapc 1 3 2614 emit `4177527167` 2615 if or eq c 124 eq c 135 2616 note Exec admits only the caller-assigned standard streams. Linux close_range with UNSHARE 2617 note closes every descriptor >=3 in a private table. Failure returns without executing a child; 2618 note no guessed descriptor ceiling or permissive fallback. This is not filesystem isolation. 2619 matconst 0 3 2620 matconst 1 `4294967295` 2621 matconst 2 2 2622 hsys 436 2623 emit `4043309087` 2624 noclose = get oc 0 2625 emit `1409286145` 2626 if eq c 135 2627 hpure 2628 else 2629 emit `2432697312` 2630 emit `2436892641` 2631 e3 `2852126720` 2 31 11 2632 hsys 221 2633 end 2634 patch19 noclose get oc 0 2635 else 2636 emit `2436892656` 2637 emit `4181721601` 2638 emit `4181722627` 2639 matconst 0 `18446744073709551516` 2640 matconst 2 `18446744073709551516` 2641 e3 `2852126720` 4 31 14 2642 hsys 276 2643 end 2644 spadd 8192 2645 hreturn dst x 2646 end 2647 fn hpipe dst ulong x ulong to void 2648 e = harray x 1 2649 harg x 2 8 2650 tmp = alloc 2651 matconst tmp 8 2652 e3 `3942645760` 31 get fr add x 22 tmp 2653 trapc 3 3 2654 save 2655 basearg 0 e 2656 loadarg 16 1 get fr add x 21 2657 e3 `2332033024` 0 0 16 2658 hload x 2 1 2659 hsys 59 2660 hreturn dst x 2661 end 2662 2663 fn hcwd dst ulong x ulong to void 2664 e = harray x 1 2665 save 2666 basearg 0 e 2667 loadarg 16 1 get fr add x 21 2668 e3 `2332033024` 0 0 16 2669 loadarg 1 1 get fr add x 22 2670 hsys 17 2671 hreturn dst x 2672 end 2673 fn hreadlnk dst ulong x ulong to void 2674 e = harray x 0 2675 put fr add x 23 e 2676 put fr add x 24 get fr add x 21 2677 put fr add x 25 get fr add x 22 2678 e = harray x 1 2679 put fr add x 26 e 2680 put fr add x 27 get fr add x 21 2681 put fr add x 28 get fr add x 22 2682 put fr add x 20 get fr add x 23 2683 put fr add x 21 get fr add x 24 2684 put fr add x 22 get fr add x 25 2685 hpathcp x 2686 note readlnk refuses an empty path before the kernel call. 2687 emit `4043309247` 2688 trapc 0 3 2689 basearg 2 get fr add x 26 2690 loadarg 16 1 get fr add x 27 2691 e3 `2332033024` 2 2 16 2692 loadarg 3 1 get fr add x 28 2693 hcopy 2694 hsys 78 2695 spadd 4096 2696 hreturn dst x 2697 end 2698 fn hsockopt dst ulong x ulong to void 2699 harg x 2 8 2700 harg x 3 8 2701 harg x 4 8 2702 e = harray x 0 2703 save 2704 hload x 2 0 2705 hload x 3 1 2706 hload x 4 2 2707 basearg 3 e 2708 loadarg 16 1 get fr add x 21 2709 e3 `2332033024` 3 3 16 2710 loadarg 4 1 get fr add x 22 2711 hsys 208 2712 hreturn dst x 2713 end 2714 2715 fn hostval c ulong dst ulong to void 2716 if eq get progmode 0 0 2717 fail 9 2718 end 2719 x = mul get depth 0 32 2720 put fr add x 7 get nslot 0 2721 if eq c 132 2722 hcwd dst x 2723 ret 2724 end 2725 if eq c 133 2726 hreadlnk dst x 2727 ret 2728 end 2729 if eq c 134 2730 hsockopt dst x 2731 ret 2732 end 2733 if or eq c 109 eq c 130 2734 hclock c dst x 2735 ret 2736 end 2737 if or and ge c 113 le c 119 eq c 131 2738 hbuffer c dst x 2739 ret 2740 end 2741 if eq c 120 2742 hsleep dst x 2743 ret 2744 end 2745 if eq c 123 2746 hwaitio dst x 2747 ret 2748 end 2749 if or or eq c 124 eq c 125 eq c 135 2750 hpack c dst x 2751 ret 2752 end 2753 if eq c 126 2754 hpath c dst x 2755 ret 2756 end 2757 if or eq c 127 eq c 129 2758 hscalar c dst x 2759 ret 2760 end 2761 if eq c 128 2762 hpipe dst x 2763 ret 2764 end 2765 if ge c 121 2766 put hostargs 0 1 2767 hargs c dst x 2768 ret 2769 end 2770 if ge c 110 2771 hpath c dst x 2772 ret 2773 end 2774 hscalar c dst x 2775 end 2776 2777 note ======== rdval: read one value (om4 VAL, VALTOK, CALL and the VT_ parts, one self-recursive 2778 note function because a function calls only earlier functions or itself) ======== 2779 note mode 0: read the first word; 1: the first word is the current token; 2: a call of function fe (index 2780 note + 1), its arguments still to read. exp the expected type (0 none), dst the destination register (255 2781 note none). Out: rk kind (1 register, 2 bare number, 3 typed number, 4 flags), rv register / number / 2782 note condition, rt type (for a bare number: 1 when written as 2^63 or more). Only the outermost op writes the 2783 note destination. Every value nests one level deeper (at most 1024, error 14); a call does not. 2784 fn rdval mode ulong exp ulong dst ulong fe ulong to void 2785 if eq mode 2 2786 cb = add mul get depth 0 32 8 2787 put fr add cb 18 ulong get fn_np sub fe 1 2788 put fr add cb 19 get nslot 0 2789 if eq get progmode 0 0 2790 if eq get curfn 0 fe 2791 fail 9 2792 end 2793 end 2794 i = ulong 0 2795 while lt i get fr add cb 18 2796 p = add mul sub fe 1 6 i 2797 if eq get fn_pk p 0 2798 rdval 0 ulong get fn_pt p 255 0 2799 ca_scal p add cb mul i 3 2800 else 2801 ca_arr fe i cb 2802 end 2803 i = add i 1 2804 end 2805 ca_end fe dst cb 2806 ret 2807 end 2808 if eq mode 0 2809 tok 2810 end 2811 put depth 0 add get depth 0 1 2812 if gt get depth 0 1024 2813 fail 14 2814 end 2815 if or eq get tk 0 0 eq get tk 0 3 2816 fail 4 2817 end 2818 if eq get tk 0 4 2819 fail 16 2820 end 2821 if eq get tk 0 2 2822 if eq exp 0 2823 vdone 2 get tw 0 get tbig 0 2824 ret 2825 end 2826 range get tw 0 exp get tbig 0 2827 vdone 3 get tw 0 exp 2828 ret 2829 end 2830 if gt get tl 0 8 2831 f = findfn get tw 0 get tl 0 get ts 0 2832 if eq f 0 2833 fail 13 2834 end 2835 if eq get fn_ret sub f 1 10 2836 fail 7 2837 end 2838 rdval 2 0 dst f 2839 vdec 2840 ret 2841 end 2842 c = kw get tw 0 2843 if eq c 0 2844 e = findname get tw 0 2845 if ne e 0 2846 if ne get nm_kind sub e 1 0 2847 fail 7 2848 end 2849 vdone 1 ulong get nm_reg sub e 1 ulong get nm_type sub e 1 2850 ret 2851 end 2852 f = findfn get tw 0 0 0 2853 if eq f 0 2854 fail 3 2855 end 2856 if eq get fn_ret sub f 1 10 2857 fail 7 2858 end 2859 rdval 2 0 dst f 2860 vdec 2861 ret 2862 end 2863 if le sub c 1 8 2864 tok 2865 if eq get tk 0 2 2866 range get tw 0 c get tbig 0 2867 vdone 3 get tw 0 c 2868 ret 2869 end 2870 rdval 1 0 255 0 2871 if eq get rk 0 2 2872 fail 11 2873 end 2874 vt_conv c 2875 vdec 2876 ret 2877 end 2878 if eq c 74 2879 rdval 0 exp dst 0 2880 tok 2881 if ne get tk 0 1 2882 fail 16 2883 end 2884 if gt get tl 0 8 2885 fail 16 2886 end 2887 if ne kw get tw 0 75 2888 fail 16 2889 end 2890 vdec 2891 ret 2892 end 2893 if eq c 77 2894 fail 9 2895 end 2896 if and ge c 100 le c 135 2897 hostval c dst 2898 ret 2899 end 2900 if eq c 51 2901 e = arrname 2902 rdval 0 5 255 0 2903 vt_get e dst 2904 vdec 2905 ret 2906 end 2907 if eq c 52 2908 e = arrname 2909 vdone 3 get nm_len sub e 1 5 2910 ret 2911 end 2912 if or eq c 53 eq c 54 2913 x = mul get depth 0 32 2914 put fr add x 8 get nslot 0 2915 rdval 0 8 255 0 2916 vs_fd x 2917 e = arrname 2918 vs_arr c e 2919 rdval 0 5 255 0 2920 vs_off x 2921 rdval 0 5 255 0 2922 vs_end c e dst x 2923 ret 2924 end 2925 if eq c 55 2926 vdone 3 1 1 2927 ret 2928 end 2929 if eq c 56 2930 vdone 3 0 1 2931 ret 2932 end 2933 if gt sub c 33 17 2934 fail 16 2935 end 2936 if ge c 49 2937 rdval 0 exp 255 0 2938 if and eq c 50 eq get rk 0 4 2939 put rv 0 xor get rv 0 1 2940 vdec 2941 ret 2942 end 2943 if eq get rk 0 2 2944 fail 11 2945 end 2946 vt_un c dst 2947 vdec 2948 ret 2949 end 2950 rdval 0 0 255 0 2951 ak = get rk 0 2952 av = get rv 0 2953 at = get rt 0 2954 if eq ak 4 2955 av = matreg 4 av at 2956 ak = ulong 1 2957 at = ulong 1 2958 end 2959 rdval 0 0 255 0 2960 bk = get rk 0 2961 bv = get rv 0 2962 bt = get rt 0 2963 if eq bk 4 2964 bv = matreg 4 bv bt 2965 bk = ulong 1 2966 bt = ulong 1 2967 end 2968 if eq ak 2 2969 if eq bk 2 2970 fail 11 2971 end 2972 range av bt at 2973 at = bt 2974 ak = ulong 3 2975 end 2976 if eq bk 2 2977 range bv at bt 2978 bt = at 2979 bk = ulong 3 2980 end 2981 if and ne c 41 ne c 42 2982 if ne at bt 2983 fail 7 2984 end 2985 end 2986 x = mul get depth 0 32 2987 put fr x ak 2988 put fr add x 1 av 2989 put fr add x 2 at 2990 put fr add x 3 bk 2991 put fr add x 4 bv 2992 put fr add x 5 bt 2993 binop c dst x 2994 vdec 2995 end 2996 2997 note cond: read a condition (a bool value); emit a branch taken when it is false: B.cond with the opposite 2998 note condition (C6.2.34), or CBZ Xr (C6.2.78). Returns that branch's place. om4 COND. 2999 fn cond to ulong 3000 rdval 0 1 255 0 3001 if ne get rt 0 1 3002 fail 7 3003 end 3004 if eq get rk 0 4 3005 at = get oc 0 3006 emit or `1409286144` xor get rv 0 1 3007 ret at 3008 end 3009 r = matreg get rk 0 get rv 0 get rt 0 3010 at = get oc 0 3011 emit or `3019898880` r 3012 ret at 3013 end 3014 3015 note ======== statements, one per line (om4 STMT and the S_ parts) ======== 3016 note skipnl: note ...: the rest of the line is not read (up to the newline, which tok reads). om4 S_NOTE. 3017 fn skipnl to void 3018 go = true 3019 while go 3020 n = ulong 0 3021 while and go lt n 999999 3022 if ge get cur 0 get inlen 0 3023 go = false 3024 else 3025 if eq get inp get cur 0 10 3026 go = false 3027 else 3028 put cur 0 add get cur 0 1 3029 end 3030 end 3031 n = add n 1 3032 end 3033 end 3034 end 3035 3036 note s_long: a word over 8 characters at the start of a line: only a call of a void function. om4 S_LONG. 3037 fn s_long to void 3038 if eq get curret 0 0 3039 fail 13 3040 end 3041 if ne get dead 0 0 3042 fail 17 3043 end 3044 f = findfn get tw 0 get tl 0 get ts 0 3045 if eq f 0 3046 fail 13 3047 end 3048 if ne get fn_ret sub f 1 10 3049 fail 7 3050 end 3051 rdval 2 0 255 f 3052 eol 3053 end 3054 3055 note blo: B.LO back to an earlier place (C6.2.34) 3056 fn blo at ulong to void 3057 d = disp19 get oc 0 at 3058 emit or `1409286147` shl d 5 3059 end 3060 3061 note sa_arr: x = new T N v: N elements of type T on the stack, each set to v; only in the function's 3062 note outermost block, so the stack held by local arrays is known at every ret. SUB SP (C6.2.457); program 3063 note mode: the stack check; MOV Xb, SP (ADD immediate, C6.2.5); then the fill loop: STR v, [Xb, Xi, LSL]; 3064 note ADD Xi, Xi, #1; CMP Xi, #N or Xn; B.LO back (C6.2.34). om4 SA_ARR. 3065 fn sa_arr w ulong to void 3066 if ne get nb 0 0 3067 fail 9 3068 end 3069 t = typeword 3070 elemtype t 3071 tok 3072 if ne get tk 0 2 3073 fail 16 3074 end 3075 n = get tw 0 3076 arrlen n 3077 by = shl shr add shl n tlog t 15 4 4 3078 s = add get stkbytes 0 by 3079 if gt s `4194304` 3080 fail 23 3081 end 3082 put stkbytes 0 s 3083 r = alloc 3084 put held 0 get nslot 0 3085 rdval 0 t 255 0 3086 if ne get rt 0 t 3087 fail 7 3088 end 3089 v = matreg get rk 0 get rv 0 get rt 0 3090 spsub by 3091 stkchk 3092 emit or `2432697312` r 3093 i = alloc 3094 emit or `3531603968` i 3095 m = ulong 0 3096 if gt n 4095 3097 m = alloc 3098 matconst m n 3099 end 3100 lp = get oc 0 3101 emit or or or stop t v shl r 5 shl i 16 3102 emit or or `2432697344` i shl i 5 3103 if le n 4095 3104 emit or or `4043309087` shl n 10 shl i 5 3105 else 3106 emit or or `3942645791` shl m 16 shl i 5 3107 end 3108 blo lp 3109 addname w r t n 1 0 3110 end 3111 3112 note s_assign: name [=] value (an existing scalar, or a new one), or name = new T N v. om4 S_ASSIGN. 3113 fn s_assign w ulong to void 3114 tok 3115 if eq get tk 0 1 3116 if le get tl 0 8 3117 if eq kw get tw 0 73 3118 tok 3119 end 3120 end 3121 end 3122 e = findname w 3123 if ne e 0 3124 i = sub e 1 3125 if ne get nm_kind i 0 3126 fail 7 3127 end 3128 r = ulong get nm_reg i 3129 t = ulong get nm_type i 3130 rdval 1 t r 0 3131 if ne get rt 0 t 3132 fail 7 3133 end 3134 force get rk 0 get rv 0 get rt 0 r 3135 eol 3136 ret 3137 end 3138 if ne findfn w 0 0 0 3139 fail 10 3140 end 3141 if eq get tk 0 1 3142 if le get tl 0 8 3143 if eq kw get tw 0 84 3144 sa_arr w 3145 eol 3146 ret 3147 end 3148 end 3149 end 3150 r = alloc 3151 put held 0 get nslot 0 3152 rdval 1 0 r 0 3153 if eq get rk 0 2 3154 fail 11 3155 end 3156 t = get rt 0 3157 force get rk 0 get rv 0 t r 3158 addname w r t 0 0 0 3159 eol 3160 end 3161 3162 note s_name: a name at the start of a line: a call of a void function, or name [=] value. om4 S_NAME. 3163 fn s_name w ulong to void 3164 if ne findname w 0 3165 s_assign w 3166 ret 3167 end 3168 f = findfn w get tl 0 0 3169 if eq f 0 3170 s_assign w 3171 ret 3172 end 3173 if ne get fn_ret sub f 1 10 3174 fail 7 3175 end 3176 rdval 2 0 255 f 3177 eol 3178 end 3179 3180 note fn_p: the type of parameter np (name pw) of function f (index): T, or view / edit T N (an array: 3181 note kind 2 / 3, element type, length 1 .. 2^24). om4 FN_P .. FN_ADD. 3182 fn fn_p f ulong np ulong pw ulong to void 3183 tok 3184 if ne get tk 0 1 3185 fail 16 3186 end 3187 if gt get tl 0 8 3188 fail 16 3189 end 3190 c = kw get tw 0 3191 t = ulong 0 3192 ln = ulong 0 3193 k = ulong 0 3194 if or eq c 57 eq c 58 3195 k = sub c 55 3196 t = typeword 3197 elemtype t 3198 tok 3199 if eq get tk 0 0 3200 fail 4 3201 end 3202 if ne get tk 0 2 3203 fail 16 3204 end 3205 ln = get tw 0 3206 arrlen ln 3207 else 3208 if gt sub c 1 8 3209 fail 16 3210 end 3211 t = c 3212 end 3213 addname pw poolc np t ln k 0 3214 p = add mul f 6 np 3215 put fn_pt p uchar t 3216 put fn_pl p ln 3217 put fn_pk p uchar k 3218 end 3219 3220 note fn_to: to T | to void at the end of a fn line; the function's state starts. om4 FN_TO .. FN_T2. 3221 fn fn_to f ulong np ulong to void 3222 tok 3223 if eq get tk 0 0 3224 fail 4 3225 end 3226 if ne get tk 0 1 3227 fail 16 3228 end 3229 if gt get tl 0 8 3230 fail 16 3231 end 3232 c = kw get tw 0 3233 r = c 3234 if eq c 76 3235 r = ulong 10 3236 else 3237 if gt sub c 1 8 3238 fail 16 3239 end 3240 end 3241 put curret 0 r 3242 put fn_ret f uchar r 3243 put fn_np f uchar np 3244 put stkbytes 0 0 3245 put dead 0 0 3246 put npar 0 np 3247 put nslot 0 0 3248 put held 0 0 3249 put nb 0 0 3250 put nt 0 0 3251 eol 3252 end 3253 3254 note s_fn: fn name (param type | param view T N | param edit T N)* to type | void. om4 S_FN. 3255 fn s_fn to void 3256 if ne get curret 0 0 3257 fail 15 3258 end 3259 tok 3260 if ne get tk 0 1 3261 fail 16 3262 end 3263 if gt get tl 0 63 3264 fail 13 3265 end 3266 w = get tw 0 3267 if ne kw w 0 3268 fail 16 3269 end 3270 l = get tl 0 3271 s = get ts 0 3272 f = ulong 0 3273 if eq get scanning 0 1 3274 newname w l s 3275 f = get nf 0 3276 if ge f 512 3277 fail 14 3278 end 3279 put nf 0 add f 1 3280 put curfn 0 add f 1 3281 put lastfn 0 add f 1 3282 put fn_name f w 3283 put fn_addr f get oc 0 3284 put fn_ret f 0 3285 put fn_np f 0 3286 put fn_nmlen f l 3287 put fn_off f s 3288 else 3289 f = sub findfn w l s 1 3290 put curfn 0 add f 1 3291 put lastfn 0 add f 1 3292 put fn_addr f get oc 0 3293 end 3294 put nn 0 get nglob 0 3295 np = ulong 0 3296 go = true 3297 while go 3298 tok 3299 if eq get tk 0 0 3300 fail 4 3301 end 3302 if ne get tk 0 1 3303 fail 16 3304 end 3305 if gt get tl 0 8 3306 fail 13 3307 end 3308 pw = get tw 0 3309 c = kw pw 3310 if eq c 65 3311 go = false 3312 else 3313 if ne c 0 3314 fail 16 3315 end 3316 newname pw get tl 0 get ts 0 3317 if ge np 6 3318 fail 9 3319 end 3320 fn_p f np pw 3321 np = add np 1 3322 end 3323 end 3324 fn_to f np 3325 if eq get scanning 0 1 3326 put curret 0 0 3327 put nn 0 0 3328 end 3329 end 3330 3331 note s_ret: ret [value]: the value into X0, give back the local arrays' stack, RET. om4 S_RET. 3332 fn s_ret to void 3333 r = get curret 0 3334 if eq r 10 3335 eol 3336 epi 3337 dead1 3338 ret 3339 end 3340 rdval 0 r 0 0 3341 if ne get rt 0 r 3342 fail 7 3343 end 3344 force get rk 0 get rv 0 get rt 0 0 3345 epi 3346 dead1 3347 eol 3348 end 3349 3350 note s_exit: exit value (int): Linux exit (system call 93: MOVZ X8, #93, C6.2.285; SVC #0, C6.2.466); the 3351 note path ends. om4 S_EXIT. 3352 fn s_exit to void 3353 rdval 0 8 255 0 3354 if ne get rt 0 8 3355 fail 7 3356 end 3357 force get rk 0 get rv 0 get rt 0 0 3358 emit `3531606952` 3359 emit `3556769793` 3360 dead1 3361 eol 3362 end 3363 3364 note stel: the checked store of v (type t) at ea_b / ea_i (the STOP table: register offset, scaled) 3365 fn stel t ulong v ulong to void 3366 b = shl get ea_b 0 5 3367 i = shl get ea_i 0 16 3368 emit or or or stop t v b i 3369 end 3370 3371 note s_put: put A i v: index, then value, then the checked store (STOP table). om4 S_PUT. 3372 fn s_put to void 3373 e = arrname 3374 k = get nm_kind sub e 1 3375 if or eq k 2 eq k 5 3376 fail 20 3377 end 3378 rdval 0 5 255 0 3379 ik = get rk 0 3380 iv = get rv 0 3381 it = get rt 0 3382 t = ulong get nm_type sub e 1 3383 rdval 0 t 255 0 3384 if ne get rt 0 t 3385 fail 7 3386 end 3387 v = matreg get rk 0 get rv 0 get rt 0 3388 elemaddr e ik iv it 3389 stel t v 3390 eol 3391 end 3392 3393 note s_global: global NAME T N: a fixed pool of N elements, zero at start, in the read/write part of the 3394 note program image after the 8 MiB stack pool (address 0x10800000 + pool bytes so far); at most 1 GiB of 3395 note pools (error 23). om4 S_GLOBAL. 3396 fn s_global to void 3397 w = topname 3398 t = typeword 3399 elemtype t 3400 tok 3401 if ne get tk 0 2 3402 fail 16 3403 end 3404 n = get tw 0 3405 arrlen n 3406 by = shl shr add shl n tlog t 15 4 4 3407 pb = get poolb 0 3408 a = add `276824064` pb 3409 s = add pb by 3410 if gt s `1073741824` 3411 fail 23 3412 end 3413 put poolb 0 s 3414 addname w 0 t n 4 a 3415 put nglob 0 get nn 0 3416 eol 3417 end 3418 3419 note s_text: text NAME "...": read-only bytes in the program image (escapes \n \t \\ \", any other is error 3420 note 22), padded to a word, with their length; address 0x400000 + its place. om4 S_TEXT. 3421 fn s_text to void 3422 w = topname 3423 tok 3424 if ne get tk 0 4 3425 fail 16 3426 end 3427 a = add get oc 0 `4194304` 3428 p = get tw 0 3429 e = add p get tl 0 3430 n = ulong 0 3431 go = true 3432 while go 3433 m = ulong 0 3434 while and go lt m 999999 3435 if ge p e 3436 go = false 3437 else 3438 b = get inp p 3439 p = add p 1 3440 if eq b 92 3441 b = get inp p 3442 p = add p 1 3443 if eq b 110 3444 b = uchar 10 3445 else 3446 if eq b 116 3447 b = uchar 9 3448 else 3449 if and ne b 92 ne b 34 3450 fail 22 3451 end 3452 end 3453 end 3454 end 3455 emitb b 3456 n = add n 1 3457 end 3458 m = add m 1 3459 end 3460 end 3461 while ne and get oc 0 3 0 3462 emitb 0 3463 end 3464 addname w 0 2 n 5 a 3465 put nglob 0 get nn 0 3466 eol 3467 end 3468 3469 note s_if: if cond: the false branch is patched at else / end. om4 S_IF. 3470 fn s_if to void 3471 at = cond 3472 pushb at 1 0 0 0 3473 pushnh get nn 0 get held 0 3474 eol 3475 end 3476 3477 note s_else: jump over the else part (B, C6.2.35); the if's false branch lands after that jump. om4 S_ELSE. 3478 fn s_else to void 3479 n = get nb 0 3480 if eq n 0 3481 fail 15 3482 end 3483 i = sub n 1 3484 if ne get bkind i 1 3485 fail 15 3486 end 3487 b = get oc 0 3488 emit `335544320` 3489 patch19 get bbr i get oc 0 3490 put bkind i 2 3491 put bbr i b 3492 put nn 0 get bnames i 3493 put held 0 get bheld i 3494 put bdead i get dead 0 3495 put dead 0 0 3496 eol 3497 end 3498 3499 note lpcnt: the hidden counter check of a loop: CMP Xc, #N (C6.2.96) or CMP Xc, Xn (C6.2.97); B.HS trap 3500 note 4; ADD Xc, Xc, #1 (C6.2.5). om4 SW_NOB .. SW_G and the same in S_FOR. 3501 fn lpcnt c ulong n ulong to void 3502 if le n 4095 3503 emit or or `4043309087` shl n 10 shl c 5 3504 else 3505 m = alloc 3506 matconst m n 3507 emit or or `3942645791` shl c 5 shl m 16 3508 end 3509 trapc 2 4 3510 emit or or `2432697344` c shl c 5 3511 end 3512 3513 note s_while: while cond [bound N]: hidden counter = 0; head: cond false -> exit; counter >= N -> trap 4; 3514 note counter = counter + 1; body; B head. N is 1 .. 999999 (error 8), `1000000` with no bound. om4 S_WHILE. 3515 fn s_while to void 3516 sn = get nn 0 3517 sh = get held 0 3518 c = alloc 3519 put held 0 get nslot 0 3520 emit or `3531603968` c 3521 hd = get oc 0 3522 br = cond 3523 n = ulong `1000000` 3524 tok 3525 k = get tk 0 3526 if and ne k 0 ne k 3 3527 if ne k 1 3528 fail 5 3529 end 3530 if gt get tl 0 8 3531 fail 5 3532 end 3533 if ne kw get tw 0 70 3534 fail 5 3535 end 3536 tok 3537 if eq get tk 0 0 3538 fail 4 3539 end 3540 if ne get tk 0 2 3541 fail 16 3542 end 3543 if ge sub get tw 0 1 999999 3544 fail 8 3545 end 3546 n = get tw 0 3547 eol 3548 end 3549 lpcnt c n 3550 pushb br 3 hd c 0 3551 pushnh sn sh 3552 end 3553 3554 note sf_br: B.HS (unsigned) or B.GE (signed) to the loop exit, C6.2.34 (distance filled at end); returns 3555 note its place. om4 SF_BR. 3556 fn sf_br t ulong to ulong 3557 at = get oc 0 3558 if lt t 6 3559 emit `1409286146` 3560 else 3561 emit `1409286154` 3562 end 3563 ret at 3564 end 3565 3566 note sf_num: for i T K with K a number: i = 0 (MOVZ, C6.2.285); head: CMP Xi, #K or Xk; B.HS/B.GE exit. 3567 note om4 SF_NUM .. SF_PUSH. 3568 fn sf_num w ulong t ulong kk ulong sn ulong sh ulong to void 3569 eol 3570 i = alloc 3571 put held 0 get nslot 0 3572 addname w i t 0 0 0 3573 emit or `3531603968` i 3574 hd = get oc 0 3575 if le kk 4095 3576 emit or or `4043309087` shl kk 10 shl i 5 3577 else 3578 k = alloc 3579 matconst k kk 3580 emit or or `3942645791` shl i 5 shl k 16 3581 end 3582 br = sf_br t 3583 pushb br 4 hd i t 3584 pushnh sn sh 3585 end 3586 3587 note sf_val: for i T K with K a value of type T in register kr: i = 0; the hidden counter c = 0; head: CMP 3588 note Xi, Xk; B.HS/B.GE exit; the counter guard of a while with no bound. om4 SF_VAL. 3589 fn sf_val w ulong t ulong kr ulong sn ulong sh ulong to void 3590 eol 3591 i = alloc 3592 put held 0 get nslot 0 3593 addname w i t 0 0 0 3594 emit or `3531603968` i 3595 c = alloc 3596 put held 0 get nslot 0 3597 emit or `3531603968` c 3598 hd = get oc 0 3599 emit or or `3942645791` shl kr 16 shl i 5 3600 br = sf_br t 3601 m = alloc 3602 matconst m `1000000` 3603 emit or or `3942645791` shl c 5 shl m 16 3604 trapc 2 4 3605 emit or or `2432697344` c shl c 5 3606 pushb br 4 hd i t 3607 pushnh sn sh 3608 end 3609 3610 note s_for: for i T K: i = 0; head: not i < K -> exit; body; latch i = add i 1; B head. K a number, or a 3611 note value of type T: a name is read at every pass, another value once before the loop. om4 S_FOR. 3612 fn s_for to void 3613 sn = get nn 0 3614 sh = get held 0 3615 tok 3616 if eq get tk 0 0 3617 fail 4 3618 end 3619 if ne get tk 0 1 3620 fail 16 3621 end 3622 if gt get tl 0 8 3623 fail 13 3624 end 3625 w = get tw 0 3626 if ne kw w 0 3627 fail 16 3628 end 3629 newname w get tl 0 get ts 0 3630 t = typeword 3631 if eq t 1 3632 fail 7 3633 end 3634 tok 3635 if eq get tk 0 0 3636 fail 4 3637 end 3638 if eq get tk 0 2 3639 range get tw 0 t get tbig 0 3640 sf_num w t get tw 0 sn sh 3641 ret 3642 end 3643 rdval 1 t 255 0 3644 if ne get rt 0 t 3645 fail 7 3646 end 3647 if eq get rk 0 3 3648 sf_num w t get rv 0 sn sh 3649 ret 3650 end 3651 kr = matreg get rk 0 get rv 0 get rt 0 3652 sf_val w t kr sn sh 3653 end 3654 3655 note finish: end of a function: a function that needs a value must not reach its end (error 18), a void 3656 note one returns; then the trap stubs: shared tail, function mode MOV X0, X7; LDR X16, [X7, #16]; BR X16 3657 note (C6.2.282, C6.2.216, C6.2.46: OscRt.trap); program mode ADD X0, X1, #100; MOVZ X8, #93; SVC #0 (exit 3658 note 100 + code). Per trap code used: MOVZ X1, #code (C6.2.285); B tail. om4 FINISH. 3659 fn finish to void 3660 eol 3661 if eq get dead 0 0 3662 if ne get curret 0 10 3663 fail 18 3664 end 3665 epi 3666 end 3667 nt0 = get nt 0 3668 if ne nt0 0 3669 tail = get oc 0 3670 if eq get progmode 0 0 3671 emit `2852586464` 3672 emit `4181723376` 3673 emit `3592356352` 3674 else 3675 emit `2432798752` 3676 emit `3531606952` 3677 emit `3556769793` 3678 end 3679 code = ulong 1 3680 while le code 14 3681 st = ulong 0 3682 j = ulong 0 3683 while lt j nt0 3684 if eq get tcode j code 3685 if eq st 0 3686 st = get oc 0 3687 emit or `3531603969` shl code 5 3688 back tail 3689 end 3690 patch19 get tsite j st 3691 end 3692 j = add j 1 3693 end 3694 code = add code 1 3695 end 3696 end 3697 put curret 0 0 3698 put nn 0 get nglob 0 3699 put curfn 0 0 3700 end 3701 3702 note s_end: close the innermost block (if: patch its branch; else: patch its jump; while: B head; for: i = 3703 note add i 1, B head), or the function. om4 S_END. 3704 fn s_end to void 3705 n = get nb 0 3706 if eq n 0 3707 finish 3708 ret 3709 end 3710 i = sub n 1 3711 put nb 0 i 3712 k = get bkind i 3713 if eq k 2 3714 put dead 0 and get dead 0 get bdead i 3715 else 3716 put dead 0 0 3717 end 3718 if eq k 4 3719 put fr 0 1 3720 put fr 1 get breg i 3721 put fr 2 get btyp i 3722 put fr 3 3 3723 put fr 4 1 3724 put fr 5 get btyp i 3725 binop 33 get breg i 0 3726 end 3727 if ge k 3 3728 back get bhead i 3729 end 3730 if eq k 2 3731 patch26 get bbr i get oc 0 3732 else 3733 patch19 get bbr i get oc 0 3734 end 3735 put nn 0 get bnames i 3736 put held 0 get bheld i 3737 eol 3738 end 3739 3740 note ======== the end of the input: the output ======== 3741 note writeout: the output from byte st to the end, to stdout (error 2), then exit 0. om4 WRITEOUT. 3742 fn writeout st ulong to void 3743 p = st 3744 go = true 3745 while go 3746 m = ulong 0 3747 while and go lt m 999999 3748 if ge p get oc 0 3749 go = false 3750 else 3751 n = write 1 out p sub get oc 0 p 3752 if le n 0 3753 fail 2 3754 end 3755 p = add p ulong n 3756 end 3757 m = add m 1 3758 end 3759 end 3760 exit int 0 3761 end 3762 3763 note elfhdr: the 176-byte file header (om4 ELFHDR, 44 words): ELF64 little-endian, executable, AArch64, 3764 note entry 0x4000b0 (the word after the header), 2 program headers: code read+execute from 0x400000, and 3765 note the read/write pools from 0x10000000. Only the words that are not 0 (the output starts at 0). 3766 fn elfhdr to void 3767 wrword 0 `1179403647` 3768 wrword 4 65794 3769 wrword 16 `11993090` 3770 wrword 20 1 3771 wrword 24 `4194480` 3772 wrword 32 64 3773 wrword 52 `3670080` 3774 wrword 56 2 3775 wrword 64 1 3776 wrword 68 5 3777 wrword 80 `4194304` 3778 wrword 88 `4194304` 3779 wrword 112 4096 3780 wrword 120 1 3781 wrword 124 6 3782 wrword 136 `268435456` 3783 wrword 144 `268435456` 3784 wrword 168 4096 3785 end 3786 3787 note eof_prog: program mode: start code = MOVZ X28, #0x1000, LSL 16 (stack pool floor); MOVZ X16, #0x1080, 3788 note LSL 16; MOV SP, X16 (ADD immediate, C6.2.5); BL main (C6.2.43); [MOVZ X0, #0 for a void main]; MOVZ X8, 3789 note #93; SVC #0. The entry word after the header is a B to it; the header gets the file and pool sizes. 3790 note om4 EOF_PROG. 3791 fn eof_prog to void 3792 f = findfn `1852399981` 4 0 3793 if eq f 0 3794 fail 16 3795 end 3796 if ne get fn_np sub f 1 0 3797 fail 9 3798 end 3799 wrword 176 or `335544320` and shr sub get oc 0 176 2 `67108863` 3800 if ne get hostargs 0 0 3801 note Preserve Linux's initial argument stack privately before installing Omega's bounded stack. 3802 emit `2432697339` 3803 end 3804 emit `3533832220` 3805 emit `3533836304` 3806 emit `2432696863` 3807 emit or `2483027968` and shr sub get fn_addr sub f 1 get oc 0 2 `67108863` 3808 if eq get fn_ret sub f 1 10 3809 emit `3531603968` 3810 end 3811 emit `3531606952` 3812 emit `3556769793` 3813 elfhdr 3814 wrword 96 get oc 0 3815 wrword 104 get oc 0 3816 wrword 160 add get poolb 0 `8388608` 3817 writeout 0 3818 end 3819 3820 note s_eof: end of input: no open function (error 15), some function (16); function mode: no globals or 3821 note texts (9); one function: its bare words; more: the entry word, a B to the last function. om4 S_EOF. 3822 note Resolve every call after all addresses are known. In function mode remove leaves of the call 3823 note graph; any functions left after nf rounds form or reach a cycle (error 9). 3824 fn resolve to void 3825 n = get ncalls 0 3826 i = ulong 0 3827 while lt i n 3828 s = get callsite i 3829 f = sub get callto i 1 3830 wrword s or `2483027968` and shr sub get fn_addr f s 2 `67108863` 3831 i = add i 1 3832 end 3833 if eq get progmode 0 0 3834 pass = ulong 0 3835 while lt pass get nf 0 3836 f = ulong 0 3837 while lt f get nf 0 3838 if eq get settled f 0 3839 ok = true 3840 i = ulong 0 3841 while and ok lt i n 3842 if eq get callfrom i add f 1 3843 if eq get settled sub get callto i 1 0 3844 ok = false 3845 end 3846 end 3847 i = add i 1 3848 end 3849 if ok 3850 put settled f 1 3851 end 3852 end 3853 f = add f 1 3854 end 3855 pass = add pass 1 3856 end 3857 f = ulong 0 3858 while lt f get nf 0 3859 if eq get settled f 0 3860 fail 9 3861 end 3862 f = add f 1 3863 end 3864 end 3865 end 3866 3867 fn s_eof to void 3868 3869 if ne get curret 0 0 3870 fail 15 3871 end 3872 if eq get nf 0 0 3873 fail 16 3874 end 3875 resolve 3876 if ne get progmode 0 0 3877 eof_prog 3878 end 3879 if ne get nglob 0 0 3880 fail 9 3881 end 3882 if eq get nf 0 1 3883 writeout 180 3884 end 3885 a = get fn_addr sub get lastfn 0 1 3886 wrword 176 or `335544320` and shr sub a 176 2 `67108863` 3887 writeout 176 3888 end 3889 3890 note stmt: one line. Returns 1 at the end of the input. om4 STMT. 3891 fn stmt to ulong 3892 put nslot 0 get held 0 3893 tok 3894 k = get tk 0 3895 if eq k 0 3896 ret 0 3897 end 3898 if eq k 3 3899 s_eof 3900 ret 1 3901 end 3902 if ne k 1 3903 fail 16 3904 end 3905 if gt get tl 0 8 3906 s_long 3907 ret 0 3908 end 3909 w = get tw 0 3910 c = kw w 3911 if eq c 83 3912 skipnl 3913 ret 0 3914 end 3915 if eq c 64 3916 s_fn 3917 ret 0 3918 end 3919 if eq get curret 0 0 3920 if eq c 78 3921 s_global 3922 ret 0 3923 end 3924 if eq c 79 3925 s_text 3926 ret 0 3927 end 3928 fail 16 3929 end 3930 if eq c 66 3931 s_end 3932 ret 0 3933 end 3934 if eq c 68 3935 s_else 3936 ret 0 3937 end 3938 if ne get dead 0 0 3939 fail 17 3940 end 3941 if eq c 0 3942 s_name w 3943 ret 0 3944 end 3945 if eq c 67 3946 s_if 3947 ret 0 3948 end 3949 if eq c 69 3950 s_while 3951 ret 0 3952 end 3953 if eq c 71 3954 s_for 3955 ret 0 3956 end 3957 if eq c 72 3958 s_ret 3959 ret 0 3960 end 3961 if eq c 80 3962 s_put 3963 ret 0 3964 end 3965 if eq c 82 3966 s_exit 3967 ret 0 3968 end 3969 if or or or eq c 77 eq c 78 eq c 79 eq c 81 3970 fail 9 3971 end 3972 fail 16 3973 ret 0 3974 end 3975 3976 note ======== program mode: some line is `fn main` (blanks, fn, blanks, main, then a blank or the end) ======== 3977 note skipbl: the first place at or after q that is not a space or tab (or the end) 3978 fn skipbl q ulong to ulong 3979 e = get inlen 0 3980 p = q 3981 go = true 3982 while go 3983 m = ulong 0 3984 while and go lt m 999999 3985 if ge p e 3986 go = false 3987 else 3988 b = get inp p 3989 if or eq b 32 eq b 9 3990 p = add p 1 3991 else 3992 go = false 3993 end 3994 end 3995 m = add m 1 3996 end 3997 end 3998 ret p 3999 end 4000 4001 note skipln: the place after the next newline at or after q (or the end) 4002 fn skipln q ulong to ulong 4003 e = get inlen 0 4004 p = q 4005 go = true 4006 while go 4007 m = ulong 0 4008 while and go lt m 999999 4009 if ge p e 4010 go = false 4011 else 4012 b = get inp p 4013 p = add p 1 4014 if eq b 10 4015 go = false 4016 end 4017 end 4018 m = add m 1 4019 end 4020 end 4021 ret p 4022 end 4023 4024 note ps_at: the line's first byte that is not blank is at p: 1 when the line is `fn main`, 2 when the input 4025 note ends while deciding, else 0. om4 PS_LINE .. PS_YES. 4026 fn ps_at p ulong to ulong 4027 e = get inlen 0 4028 if ne get inp p 102 4029 ret 0 4030 end 4031 q = add p 1 4032 if ge q e 4033 ret 2 4034 end 4035 if ne get inp q 110 4036 ret 0 4037 end 4038 r = add q 1 4039 q = skipbl r 4040 if ge q e 4041 ret 2 4042 end 4043 if eq q r 4044 ret 0 4045 end 4046 if gt add q 4 e 4047 ret 0 4048 end 4049 if ne get inp q 109 4050 ret 0 4051 end 4052 if ne get inp add q 1 97 4053 ret 0 4054 end 4055 if ne get inp add q 2 105 4056 ret 0 4057 end 4058 if ne get inp add q 3 110 4059 ret 0 4060 end 4061 if ge add q 4 e 4062 ret 1 4063 end 4064 if gt get inp add q 4 32 4065 ret 0 4066 end 4067 ret 1 4068 end 4069 4070 fn prescan to void 4071 e = get inlen 0 4072 p = ulong 0 4073 go = true 4074 while go 4075 m = ulong 0 4076 while and go lt m 999999 4077 p = skipbl p 4078 if ge p e 4079 go = false 4080 else 4081 r = ps_at p 4082 if eq r 1 4083 put progmode 0 1 4084 go = false 4085 end 4086 if eq r 2 4087 go = false 4088 end 4089 if go 4090 p = skipln p 4091 if ge p e 4092 go = false 4093 end 4094 end 4095 end 4096 m = add m 1 4097 end 4098 end 4099 end 4100 4101 note First collect signatures. Only fn headers are parsed here; other lines are read in the body pass. 4102 fn namescan to void 4103 put scanning 0 1 4104 put line 0 1 4105 go = true 4106 while go 4107 n = ulong 0 4108 while and go lt n 999999 4109 tok 4110 if eq get tk 0 3 4111 go = false 4112 else 4113 if ne get tk 0 0 4114 if and eq get tk 0 1 eq get tw 0 28262 4115 s_fn 4116 else 4117 skipnl 4118 end 4119 end 4120 end 4121 n = add n 1 4122 end 4123 end 4124 put scanning 0 0 4125 put cur 0 0 4126 put line 0 1 4127 put nn 0 0 4128 put curfn 0 0 4129 put curret 0 0 4130 put npar 0 0 4131 put nslot 0 0 4132 put held 0 0 4133 end 4134 4135 note main: read all of stdin 4136 note (8 MiB at most, error 14; a read error is 1), find the mode, then one 4137 note statement per line from output byte 180 (om4 START .. STMT) 4138 fn main to int 4139 off = ulong 0 4140 go = true 4141 while go 4142 m = ulong 0 4143 while and go lt m 999999 4144 if ge off len inp 4145 fail 14 4146 end 4147 n = read 0 inp off sub len inp off 4148 if eq n 0 4149 go = false 4150 else 4151 if lt n 0 4152 fail 1 4153 end 4154 off = add off ulong n 4155 end 4156 m = add m 1 4157 end 4158 end 4159 put inlen 0 off 4160 prescan 4161 namescan 4162 put oc 0 180 4163 put line 0 1 4164 done = false 4165 while not done 4166 m = ulong 0 4167 while and not done lt m 999999 4168 if ne stmt 0 4169 done = true 4170 end 4171 m = add m 1 4172 end 4173 end 4174 ret 0 4175 end