sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / seed / omc / omc.om
| 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 irmode ulong 1 |
| 12 | global cur ulong 1 |
| 13 | global line ulong 1 |
| 14 | global tk ulong 1 |
| 15 | global tw ulong 1 |
| 16 | global tl ulong 1 |
| 17 | global ts ulong 1 |
| 18 | global tbig ulong 1 |
| 19 | global out uchar 16777216 |
| 20 | global oc ulong 1 |
| 21 | |
| 22 | note ---- OM-2 profile (spec/omegese-om2.md, OMEGESE.md 9.13). om2 is 1 in an OM-2 unit (its first line |
| 23 | note that is not a note or blank is exactly om2, om2 diag or om2 fmt); om2m 0 compile, 1 diag, 2 fmt; |
| 24 | note om2ln/om2pos the line number and offset of that line; fmtm 1 while a unit is formatted; lbase and |
| 25 | note sbase shift reported lines and bytes back to the original input in fmt mode; tka/tkb the byte span of |
| 26 | note the last token; dexp what was being read (0 word 1 value 2 type 3 name 4 number 5 end 6 newline); |
| 27 | note dsev 0 derived, 2 unknown (an undeclared function or struct), 3 error ---- |
| 28 | global om2 ulong 1 |
| 29 | global om2m ulong 1 |
| 30 | global om2ln ulong 1 |
| 31 | global om2pos ulong 1 |
| 32 | global fmtm ulong 1 |
| 33 | global chkmode ulong 1 |
| 34 | global chkln ulong 1 |
| 35 | global lbase ulong 1 |
| 36 | global sbase ulong 1 |
| 37 | global tka ulong 1 |
| 38 | global tkb ulong 1 |
| 39 | global dexp ulong 1 |
| 40 | global dsev ulong 1 |
| 41 | |
| 42 | note ---- executable contracts: OM-2 debug by default, release erases only validated pure predicates. |
| 43 | note Function prefixes are replayed at returns with their declaration scope, including inline frames. |
| 44 | global crel ulong 1 |
| 45 | global cpure ulong 1 |
| 46 | global cvalid ulong 1 |
| 47 | global clim ulong 1 |
| 48 | global crkind ulong 1 |
| 49 | global crval ulong 1 |
| 50 | global crtype ulong 1 |
| 51 | global cfpos ulong 8 |
| 52 | global cfline ulong 8 |
| 53 | global cflim ulong 8 |
| 54 | global cfhas ulong 8 |
| 55 | global csnap ulong 8 |
| 56 | global ckind ulong 1 |
| 57 | |
| 58 | note ---- OM-2 section 4 (unroll, inline, folding, bounds, sites). fn_inl/fn_body/fn_bln/fn_pn: a function's |
| 59 | note inline mark, its body offset and line, its parameter names. fstart: where the function being compiled |
| 60 | note starts (65536 words at most in OM-2). nmlo: names below it and at or above nglob are hidden while an |
| 61 | note inlined body is compiled (0 otherwise). fzone: open unrolled bodies and inline frames (folding is |
| 62 | note done only when it is above 0). inl and il_*: the inline frames (at most 4). ilp/nilp: the B words of |
| 63 | note an inlined ret, patched at its end. lastb/tgoc: the word after the last inlined ret's B and the last |
| 64 | note place a branch was patched to. u_*: the unrolled loop of each block. fok/fval/fty: a fold result. |
| 65 | note sitebuf/nsite: the omc-site records of om2 diag. |
| 66 | global fn_inl uchar 4096 |
| 67 | global fn_body ulong 4096 |
| 68 | global fn_bln ulong 4096 |
| 69 | global fn_pn ulong 24576 |
| 70 | global fstart ulong 1 |
| 71 | global nmlo ulong 1 |
| 72 | global fzone ulong 1 |
| 73 | global inl ulong 1 |
| 74 | global il_cur ulong 8 |
| 75 | global il_line ulong 8 |
| 76 | global il_ret ulong 8 |
| 77 | global il_nn ulong 8 |
| 78 | global il_lo ulong 8 |
| 79 | global il_held ulong 8 |
| 80 | global il_ns ulong 8 |
| 81 | global il_res ulong 8 |
| 82 | global il_fn ulong 8 |
| 83 | global il_p0 ulong 8 |
| 84 | global ilp ulong 4096 |
| 85 | global nilp ulong 1 |
| 86 | global lastb ulong 1 |
| 87 | global tgoc ulong 1 |
| 88 | global u_cur ulong 512 |
| 89 | global u_line ulong 512 |
| 90 | global u_it ulong 512 |
| 91 | global u_k ulong 512 |
| 92 | global u_nn ulong 512 |
| 93 | global u_held ulong 512 |
| 94 | note fuel (E14, E16): the expansion fuel used by the function being compiled: an unrolled loop costs K when |
| 95 | note it starts, an inline expansion 1, at most 65536 in all (error 14) |
| 96 | global fuel ulong 1 |
| 97 | global fok ulong 1 |
| 98 | global fval ulong 1 |
| 99 | global fty ulong 1 |
| 100 | global sitebuf uchar 8388608 |
| 101 | global nsite ulong 1 |
| 102 | global ie_from ulong 16384 |
| 103 | global ie_to ulong 16384 |
| 104 | global nie ulong 1 |
| 105 | global reach uchar 4096 |
| 106 | |
| 107 | note ---- name table (8192 names in scope): packed name, register, type, length, kind, address ---- |
| 108 | global nm_name ulong 8192 |
| 109 | global nm_reg uchar 8192 |
| 110 | global nm_type uchar 8192 |
| 111 | global nm_len ulong 8192 |
| 112 | global nm_kind uchar 8192 |
| 113 | global nm_addr ulong 8192 |
| 114 | global nm_fv uchar 8192 |
| 115 | global nn ulong 1 |
| 116 | note ---- floats in v registers: kind 9 is a float held in v(16 + pool index of x register rv), the twin of |
| 117 | note pool register rv; vsl marks each pool slot whose value lives in its twin (an f32/f64 local name, a |
| 118 | note kind 9 value), saved and loaded as D around a call. fpw asks the next value read for kind 9 (1: a new |
| 119 | note twin, 2 + r: the twin of r); fpo hands that request to the part that makes the value. A float local |
| 120 | note name (nm_fv 1) lives in its twin; its x register holds a copy only while a reader needs one. ---- |
| 121 | global vsl uchar 16 |
| 122 | global fpw ulong 1 |
| 123 | global fpo ulong 1 |
| 124 | note fwv: rdval's fpw request at each nesting depth (kept here, not in a register of rdval) |
| 125 | global fwv ulong 1026 |
| 126 | |
| 127 | note ---- function table (4096): name, address (byte offset in out), return type, parameter count, |
| 128 | note per-parameter type/length/kind (6 each), name length, name offset in the input ---- |
| 129 | global fn_name ulong 4096 |
| 130 | global fn_addr ulong 4096 |
| 131 | global fn_ret uchar 4096 |
| 132 | global fn_np uchar 4096 |
| 133 | global fn_pt uchar 24576 |
| 134 | global fn_pl ulong 24576 |
| 135 | global fn_pk uchar 24576 |
| 136 | global fn_nmlen ulong 4096 |
| 137 | global fn_off ulong 4096 |
| 138 | note x86 Linux retains the parser's sixteen logical slots in each native frame. |
| 139 | note No A64 instruction may pass emit once the explicit target is selected (error 25). |
| 140 | global xtarget ulong 1 |
| 141 | global xnaddr ulong 1 |
| 142 | global xasite ulong 65536 |
| 143 | global xavalue ulong 65536 |
| 144 | note x86efi (xtarget 2): exit-site jumps patched to the shared firmware return, the PE bss address, |
| 145 | note and the error/done branch lists of one efi operation (closed by xe 2). |
| 146 | global xexsite ulong 65536 |
| 147 | global xnexit ulong 1 |
| 148 | global xbss ulong 1 |
| 149 | global xenerr ulong 1 |
| 150 | global xerrpos ulong 256 |
| 151 | global xerrcode ulong 256 |
| 152 | global xenend ulong 1 |
| 153 | global xendpos ulong 256 |
| 154 | global nf ulong 1 |
| 155 | global lastfn ulong 1 |
| 156 | global scanning ulong 1 |
| 157 | global ncalls ulong 1 |
| 158 | global callsite ulong 524288 |
| 159 | global callfrom ulong 524288 |
| 160 | global callto ulong 524288 |
| 161 | global settled uchar 4096 |
| 162 | |
| 163 | |
| 164 | note ---- compiler state ---- |
| 165 | global npar ulong 1 |
| 166 | global held ulong 1 |
| 167 | global nslot ulong 1 |
| 168 | global curret ulong 1 |
| 169 | global progmode ulong 1 |
| 170 | global nglob ulong 1 |
| 171 | global hostargs ulong 1 |
| 172 | global maptab ulong 1 |
| 173 | global fdtab ulong 1 |
| 174 | global stkbytes ulong 1 |
| 175 | global dead ulong 1 |
| 176 | global poolb ulong 1 |
| 177 | |
| 178 | note ---- structs (16) and fields (256). R6. nm_type 16+index, kind 6 own, 7 edit, 8 view ---- |
| 179 | global st_name ulong 16 |
| 180 | global st_nf uchar 16 |
| 181 | global st_cells uchar 16 |
| 182 | global st_foff uchar 16 |
| 183 | global nst ulong 1 |
| 184 | global sf_name ulong 256 |
| 185 | global sf_type uchar 256 |
| 186 | global sf_len uchar 256 |
| 187 | global sf_off uchar 256 |
| 188 | global nsf ulong 1 |
| 189 | global svk ulong 16 |
| 190 | global svv ulong 16 |
| 191 | global svt ulong 16 |
| 192 | |
| 193 | note ---- OM-2 section 5 external layouts (16) and their fields (256): name, SIZE, first field, field count, |
| 194 | note the cursor and line after the block's end (the body pass jumps there). Field: name, type, COUNT (0 a |
| 195 | note scalar), byte offset, 1 big-endian. lymap marks the bytes taken while a layout is read. nm_lay / |
| 196 | note fn_play: the layout (index + 1) of a layout parameter name / parameter slot, else 0 ---- |
| 197 | global ly_name ulong 16 |
| 198 | global ly_size ulong 16 |
| 199 | global ly_fo ulong 16 |
| 200 | global ly_nf ulong 16 |
| 201 | global ly_ec ulong 16 |
| 202 | global ly_el ulong 16 |
| 203 | global nly ulong 1 |
| 204 | global lf_name ulong 256 |
| 205 | global lf_type uchar 256 |
| 206 | global lf_cnt ulong 256 |
| 207 | global lf_off ulong 256 |
| 208 | global lf_big uchar 256 |
| 209 | global nlf ulong 1 |
| 210 | global lymap uchar 4096 |
| 211 | global nm_lay uchar 8192 |
| 212 | global fn_play uchar 24576 |
| 213 | |
| 214 | note ---- OM-2 section 5 fresh scratch (erratum E8). fn_pfr: 1 for a `fresh` parameter slot. nm_fr: the |
| 215 | note written-set slot (index + 1) a name's elements are tracked in, else 0. fz_n slots in use by the |
| 216 | note function being compiled (16), fz_len their N, fz_cur the elements definitely written on the path |
| 217 | note being compiled (bit i for element i); fz_ent / fz_thn (16 per block): the sets when the block opened |
| 218 | note and at its else. il_fz: fz_n when an inline frame opened. dobx 1: error 14 reports obligation=init ---- |
| 219 | global fn_pfr uchar 24576 |
| 220 | global nm_fr uchar 8192 |
| 221 | global fz_n ulong 1 |
| 222 | global fz_len ulong 16 |
| 223 | global fz_cur ulong 16 |
| 224 | global fz_ent ulong 8192 |
| 225 | global fz_thn ulong 8192 |
| 226 | global il_fz ulong 8 |
| 227 | global dobx ulong 1 |
| 228 | |
| 229 | note ---- OM-2 section 5 abstract types (16; type 64 + index): name, its length, representation type (4 uint, |
| 230 | note 5 ulong), the preserving operations listed (1 rotr, 2 rotl, 4 and, 8 or, 16 xor), 1 when `holds NAME |
| 231 | note dup32` is declared. aw_*: the word reader of the exact-constructor test (place, packed word, length, |
| 232 | note newlines crossed before it) ---- |
| 233 | global ab_name ulong 16 |
| 234 | global ab_len ulong 16 |
| 235 | global ab_base uchar 16 |
| 236 | global ab_ops ulong 16 |
| 237 | global ab_holds uchar 16 |
| 238 | global nab ulong 1 |
| 239 | global aw_p ulong 1 |
| 240 | global aw_w ulong 1 |
| 241 | global aw_l ulong 1 |
| 242 | global aw_nl ulong 1 |
| 243 | |
| 244 | note ---- OM-2 section 6 unsized views (spec 4 slots, 6, erratum E2). An unsized `view T *` / `edit T *` |
| 245 | note name has length 0 in nm_len and its run-time element count in register nm_lr. Parameters take the |
| 246 | note registers x0..x5 by slots: an unsized array two (pointer, then count), every other parameter one |
| 247 | note (pwid, pslot); psl counts the slots of the fn line being read (6 at most, error 9). ul_k / ul_v: the |
| 248 | note count (kind 1 register / 3 number) of argument i of the call at value depth d, at d * 6 + i ---- |
| 249 | global nm_lr uchar 8192 |
| 250 | global psl ulong 1 |
| 251 | global ul_k ulong 6156 |
| 252 | global ul_v ulong 6156 |
| 253 | note ---- OM-2 section 6 multi-entry units: nexp `export fn` lines (32 at most, function mode only), fn_exp 1 |
| 254 | note for an exported function, expf 1 while an `export fn` line is read. With any export, words 0 .. E-1 |
| 255 | note of the code are B to each export in source order and the code starts at byte 176 + 4E ---- |
| 256 | global nexp ulong 1 |
| 257 | global expf ulong 1 |
| 258 | global fn_exp uchar 4096 |
| 259 | |
| 260 | note ======== leaf helpers ======== |
| 261 | |
| 262 | note poolc: the i-th register of the pool x0..x6, x8..x15, x17 (x7 is the runtime, x16 scratch) |
| 263 | fn poolc i ulong to ulong |
| 264 | if lt i 7 |
| 265 | ret i |
| 266 | end |
| 267 | if lt i 15 |
| 268 | ret add i 1 |
| 269 | end |
| 270 | ret 17 |
| 271 | end |
| 272 | |
| 273 | note pwid: the parameter slots of fn table entry p: 2 for an unsized array (pointer, count), else 1 |
| 274 | fn pwid p ulong to ulong |
| 275 | k = ulong get fn_pk p |
| 276 | if and or eq k 2 eq k 3 eq get fn_pl p 0 |
| 277 | ret 2 |
| 278 | end |
| 279 | ret 1 |
| 280 | end |
| 281 | |
| 282 | note unsz: 1 when name entry i is an unsized array (nm_len 0, its count in register nm_lr), else 0. A text |
| 283 | note (kind 5) of length 0 (`text e ""`) is sized: its count is the number 0 and it has no count register. |
| 284 | fn unsz i ulong to ulong |
| 285 | if and eq get nm_len i 0 ne get nm_kind i 5 |
| 286 | ret 1 |
| 287 | end |
| 288 | ret 0 |
| 289 | end |
| 290 | |
| 291 | note pslot: the first slot (register) of parameter i of function f (index) |
| 292 | fn pslot f ulong i ulong to ulong |
| 293 | s = ulong 0 |
| 294 | j = ulong 0 |
| 295 | while lt j i |
| 296 | s = add s pwid add mul f 6 j |
| 297 | j = add j 1 |
| 298 | end |
| 299 | ret s |
| 300 | end |
| 301 | |
| 302 | note ---- error reporting ---- |
| 303 | global msg uchar 65536 |
| 304 | global mc ulong 1 |
| 305 | |
| 306 | note mflush: complete a diagnostic/query stdout chunk or report compiler output error 2. |
| 307 | fn mflush to void |
| 308 | off = ulong 0 |
| 309 | n = get mc 0 |
| 310 | while lt off n |
| 311 | w = write 1 msg off sub n off |
| 312 | if le w 0 |
| 313 | exit int 2 |
| 314 | end |
| 315 | off = add off ulong w |
| 316 | end |
| 317 | put mc 0 0 |
| 318 | end |
| 319 | |
| 320 | fn mputb b uchar to void |
| 321 | m = get mc 0 |
| 322 | put msg m b |
| 323 | put mc 0 add m 1 |
| 324 | end |
| 325 | |
| 326 | fn mputn v ulong to void |
| 327 | d = new uchar 20 0 |
| 328 | i = ulong 0 |
| 329 | x = v |
| 330 | put d 0 uchar add rem x 10 48 |
| 331 | x = div x 10 |
| 332 | i = add i 1 |
| 333 | while gt x 0 |
| 334 | put d i uchar add rem x 10 48 |
| 335 | x = div x 10 |
| 336 | i = add i 1 |
| 337 | end |
| 338 | j = i |
| 339 | while gt j 0 |
| 340 | j = sub j 1 |
| 341 | mputb get d j |
| 342 | end |
| 343 | end |
| 344 | |
| 345 | note fail: write "omc: line N: error E" to stderr (fd 2) and exit with the code |
| 346 | fn fail code ulong to void |
| 347 | put mc 0 0 |
| 348 | mputb 111 |
| 349 | mputb 109 |
| 350 | mputb 99 |
| 351 | mputb 58 |
| 352 | mputb 32 |
| 353 | mputb 108 |
| 354 | mputb 105 |
| 355 | mputb 110 |
| 356 | mputb 101 |
| 357 | mputb 32 |
| 358 | mputn add get line 0 get lbase 0 |
| 359 | mputb 58 |
| 360 | mputb 32 |
| 361 | mputb 101 |
| 362 | mputb 114 |
| 363 | mputb 114 |
| 364 | mputb 111 |
| 365 | mputb 114 |
| 366 | mputb 32 |
| 367 | mputn code |
| 368 | mputb 10 |
| 369 | w = write 2 msg 0 get mc 0 |
| 370 | if ne get om2 0 0 |
| 371 | if eq get om2m 0 1 |
| 372 | drec code |
| 373 | end |
| 374 | end |
| 375 | if ne get chkmode 0 0 |
| 376 | diagrec code |
| 377 | end |
| 378 | exit int code |
| 379 | end |
| 380 | |
| 381 | note mputw: the first n bytes (at most 8) of the little-endian packed word w |
| 382 | fn mputw w ulong n ulong to void |
| 383 | i = ulong 0 |
| 384 | x = w |
| 385 | while lt i n |
| 386 | mputb uchar and x 255 |
| 387 | x = shr x 8 |
| 388 | i = add i 1 |
| 389 | end |
| 390 | end |
| 391 | |
| 392 | note dcol: the 1-based column of byte a in its line |
| 393 | fn dcol a ulong to ulong |
| 394 | j = a |
| 395 | go = true |
| 396 | while go |
| 397 | m = ulong 0 |
| 398 | while and go lt m 999999 |
| 399 | if eq j 0 |
| 400 | go = false |
| 401 | else |
| 402 | if eq get inp sub j 1 10 |
| 403 | go = false |
| 404 | else |
| 405 | j = sub j 1 |
| 406 | end |
| 407 | end |
| 408 | m = add m 1 |
| 409 | end |
| 410 | end |
| 411 | ret add sub a j 1 |
| 412 | end |
| 413 | |
| 414 | note dsev_w: sev= incomplete when the failure is on the end-of-input token (or inside a text literal cut by |
| 415 | note the end), unknown for an undeclared function or struct, else error |
| 416 | fn dsev_w code ulong to void |
| 417 | s = get dsev 0 |
| 418 | if eq s 0 |
| 419 | if eq get tk 0 3 |
| 420 | s = ulong 1 |
| 421 | end |
| 422 | if and eq code 22 ge get cur 0 get inlen 0 |
| 423 | s = ulong 1 |
| 424 | end |
| 425 | end |
| 426 | if eq s 1 |
| 427 | mputw 7308339910638005865 8 |
| 428 | mputw 25972 2 |
| 429 | ret |
| 430 | end |
| 431 | if eq s 2 |
| 432 | mputw 31093567915781749 7 |
| 433 | ret |
| 434 | end |
| 435 | mputw 491496043109 5 |
| 436 | end |
| 437 | |
| 438 | note dexp_w: expect= the class of token being read (end for an open function at the end of the input) |
| 439 | fn dexp_w code ulong to void |
| 440 | e = get dexp 0 |
| 441 | if eq code 15 |
| 442 | e = ulong 5 |
| 443 | end |
| 444 | if or eq code 6 eq code 8 |
| 445 | e = ulong 4 |
| 446 | end |
| 447 | if eq e 1 |
| 448 | mputw 435761734006 5 |
| 449 | ret |
| 450 | end |
| 451 | if eq e 2 |
| 452 | mputw 1701869940 4 |
| 453 | ret |
| 454 | end |
| 455 | if eq e 3 |
| 456 | mputw 1701667182 4 |
| 457 | ret |
| 458 | end |
| 459 | if eq e 4 |
| 460 | mputw 125779768604014 6 |
| 461 | ret |
| 462 | end |
| 463 | if eq e 5 |
| 464 | mputw 6581861 3 |
| 465 | ret |
| 466 | end |
| 467 | if eq e 6 |
| 468 | mputw 28550371718161774 7 |
| 469 | ret |
| 470 | end |
| 471 | mputw 1685221239 4 |
| 472 | end |
| 473 | |
| 474 | note dobl_w: obligation= from the code: 27 init, 28 ctor, 29 layout, 21 bounds, 14 growth, 12 regs, else - |
| 475 | fn dobl_w code ulong to void |
| 476 | if eq code 30 |
| 477 | mputw 8386654075301556067 8 |
| 478 | ret |
| 479 | end |
| 480 | if eq code 27 |
| 481 | mputw 1953066601 4 |
| 482 | ret |
| 483 | end |
| 484 | if eq code 28 |
| 485 | mputw 1919906915 4 |
| 486 | ret |
| 487 | end |
| 488 | if eq code 29 |
| 489 | mputw 128047730221420 6 |
| 490 | ret |
| 491 | end |
| 492 | if eq code 21 |
| 493 | mputw 126875187113826 6 |
| 494 | ret |
| 495 | end |
| 496 | if and eq code 14 ne get dobx 0 0 |
| 497 | mputw 1953066601 4 |
| 498 | ret |
| 499 | end |
| 500 | if eq code 14 |
| 501 | mputw 114849429287527 6 |
| 502 | ret |
| 503 | end |
| 504 | if eq code 12 |
| 505 | mputw 1936156018 4 |
| 506 | ret |
| 507 | end |
| 508 | mputb 45 |
| 509 | end |
| 510 | |
| 511 | note mputh: one byte as two lowercase hex digits |
| 512 | fn mputh b ulong to void |
| 513 | hi = shr b 4 |
| 514 | lo = and b 15 |
| 515 | if lt hi 10 |
| 516 | mputb uchar add hi 48 |
| 517 | else |
| 518 | mputb uchar add hi 87 |
| 519 | end |
| 520 | if lt lo 10 |
| 521 | mputb uchar add lo 48 |
| 522 | else |
| 523 | mputb uchar add lo 87 |
| 524 | end |
| 525 | end |
| 526 | |
| 527 | note drec: the om2 diag machine record after the human line (spec 1): code, sev, line (the human line), |
| 528 | note col, the half-open byte span of the token being read, expect, found (at most 32 bytes, hex), |
| 529 | note obligation, profile |
| 530 | fn drec code ulong to void |
| 531 | put mc 0 0 |
| 532 | mputw 7449351137626647919 8 |
| 533 | mputw 4424052638528581920 8 |
| 534 | mputn code |
| 535 | mputw 263979365152 5 |
| 536 | dsev_w code |
| 537 | mputw 67505853393952 6 |
| 538 | mputn add get line 0 get lbase 0 |
| 539 | a = get tka 0 |
| 540 | b = get tkb 0 |
| 541 | if le b a |
| 542 | b = a |
| 543 | if gt get cur 0 a |
| 544 | b = get cur 0 |
| 545 | end |
| 546 | end |
| 547 | if gt b get inlen 0 |
| 548 | b = get inlen 0 |
| 549 | end |
| 550 | mputw 263812244256 5 |
| 551 | mputn dcol a |
| 552 | mputw 67544290456352 6 |
| 553 | mputn add a get sbase 0 |
| 554 | mputb 45 |
| 555 | mputn add b get sbase 0 |
| 556 | mputw 4428273620941825312 8 |
| 557 | dexp_w code |
| 558 | mputw 17280399158765088 7 |
| 559 | if eq a b |
| 560 | mputb 45 |
| 561 | end |
| 562 | i = a |
| 563 | while and lt i b lt sub i a 32 |
| 564 | mputh ulong get inp i |
| 565 | i = add i 1 |
| 566 | end |
| 567 | mputw 8386097683628191520 8 |
| 568 | mputw 1030647657 4 |
| 569 | dobl_w code |
| 570 | mputw 7308332183992823840 8 |
| 571 | mputw 11210624683837 6 |
| 572 | w = write 2 msg 0 get mc 0 |
| 573 | end |
| 574 | |
| 575 | note emitb / emit: one byte / one 32-bit word (little-endian) to the output; error 14 when it is full |
| 576 | note AArch64 retains its 8 MiB output ceiling; x86 byte sequences use the full output pool. |
| 577 | fn emitb b uchar to void |
| 578 | o = get oc 0 |
| 579 | if or ge o len out and eq get xtarget 0 0 ge o 8388608 |
| 580 | fail 14 |
| 581 | end |
| 582 | note Charge x86's variable-width encoding to the same OM-2 emitted-storage budget as emit. |
| 583 | if and ne get xtarget 0 0 ne get om2 0 0 |
| 584 | if ne get curret 0 0 |
| 585 | if ge sub o get fstart 0 262144 |
| 586 | fail 14 |
| 587 | end |
| 588 | end |
| 589 | end |
| 590 | put out o b |
| 591 | put oc 0 add o 1 |
| 592 | end |
| 593 | |
| 594 | fn emit w ulong to void |
| 595 | if ne get xtarget 0 0 |
| 596 | fail 25 |
| 597 | end |
| 598 | if ge get oc 0 8388608 |
| 599 | fail 14 |
| 600 | end |
| 601 | if ne get om2 0 0 |
| 602 | if ne get curret 0 0 |
| 603 | if ge sub get oc 0 get fstart 0 262144 |
| 604 | fail 14 |
| 605 | end |
| 606 | end |
| 607 | end |
| 608 | emitb uchar and w 255 |
| 609 | emitb uchar and shr w 8 255 |
| 610 | emitb uchar and shr w 16 255 |
| 611 | emitb uchar and shr w 24 255 |
| 612 | end |
| 613 | |
| 614 | note tok_num: the word at [ts,cur) is [-]decimal, at most 20 digits, from -2^63 to 2^64 - 1 (error 6 |
| 615 | note bad number, 8 out of range). tw = its raw 64 bits (a negative one as two's complement); tbig = 1 |
| 616 | note when it is 2^63 or more (only a ulong holds it), else 0. As om4's TK_NUM. |
| 617 | note The float-marker scan walks the word in chunks of at most 999999 bytes: a single loop's hidden |
| 618 | note 1000000-pass guard trapped 4 on a decimal word of 1000001 digits, which must refuse with error 6 (#671). |
| 619 | fn tok_num to void |
| 620 | if ne get om2 0 0 |
| 621 | if ne tok_hex 0 |
| 622 | ret |
| 623 | end |
| 624 | end |
| 625 | p = get ts 0 |
| 626 | e = get cur 0 |
| 627 | fl = false |
| 628 | i = p |
| 629 | while lt i e |
| 630 | c = sub e i |
| 631 | if gt c 999999 |
| 632 | c = ulong 999999 |
| 633 | end |
| 634 | for k ulong c |
| 635 | b = get inp add i k |
| 636 | if or or or eq b 46 eq b 101 eq b 69 eq b 102 |
| 637 | fl = true |
| 638 | end |
| 639 | end |
| 640 | i = add i c |
| 641 | end |
| 642 | if fl |
| 643 | put tk 0 5 |
| 644 | ret |
| 645 | end |
| 646 | minus = false |
| 647 | if eq get inp p 45 |
| 648 | minus = true |
| 649 | p = add p 1 |
| 650 | end |
| 651 | ndig = sub e p |
| 652 | if eq ndig 0 |
| 653 | nfail 6 |
| 654 | end |
| 655 | if gt ndig 20 |
| 656 | nfail 6 |
| 657 | end |
| 658 | v = ulong 0 |
| 659 | lim = ulong 1844674407370955161 |
| 660 | i = p |
| 661 | while lt i e |
| 662 | d = sub ulong get inp i 48 |
| 663 | if gt d 9 |
| 664 | nfail 6 |
| 665 | end |
| 666 | if gt v lim |
| 667 | nfail 8 |
| 668 | end |
| 669 | if and eq v lim gt d 5 |
| 670 | nfail 8 |
| 671 | end |
| 672 | v = add mul v 10 d |
| 673 | i = add i 1 |
| 674 | end |
| 675 | half = shl ulong 1 63 |
| 676 | put tbig 0 0 |
| 677 | if minus |
| 678 | if gt v half |
| 679 | nfail 8 |
| 680 | end |
| 681 | put tw 0 sub ulong 0 v |
| 682 | else |
| 683 | if ge v half |
| 684 | put tbig 0 1 |
| 685 | end |
| 686 | put tw 0 v |
| 687 | end |
| 688 | put tk 0 2 |
| 689 | end |
| 690 | |
| 691 | note tok_text: a text literal starting at the opening quote. tw = first byte offset, tl = source length |
| 692 | note (escapes not yet decoded). Ends at an unescaped '"' on the same line, followed by a blank/end. Err 22. |
| 693 | note (Loops over the input are two loops, the inner under 1000000 passes: om4 has no pass limit.) |
| 694 | fn tok_text to void |
| 695 | put cur 0 add get cur 0 1 |
| 696 | put tw 0 get cur 0 |
| 697 | go = true |
| 698 | while go |
| 699 | n = ulong 0 |
| 700 | while and go lt n 999999 |
| 701 | if ge get cur 0 get inlen 0 |
| 702 | fail 22 |
| 703 | end |
| 704 | b = get inp get cur 0 |
| 705 | if eq b 10 |
| 706 | fail 22 |
| 707 | end |
| 708 | if eq b 34 |
| 709 | go = false |
| 710 | else |
| 711 | put cur 0 add get cur 0 1 |
| 712 | if eq b 92 |
| 713 | if ge get cur 0 get inlen 0 |
| 714 | fail 22 |
| 715 | end |
| 716 | if eq get inp get cur 0 10 |
| 717 | fail 22 |
| 718 | end |
| 719 | put cur 0 add get cur 0 1 |
| 720 | end |
| 721 | end |
| 722 | n = add n 1 |
| 723 | end |
| 724 | end |
| 725 | put tl 0 sub get cur 0 get tw 0 |
| 726 | put cur 0 add get cur 0 1 |
| 727 | put tk 0 4 |
| 728 | if lt get cur 0 get inlen 0 |
| 729 | if gt get inp get cur 0 32 |
| 730 | fail 22 |
| 731 | end |
| 732 | end |
| 733 | end |
| 734 | |
| 735 | note tok2: a word at cur with first byte c; packs 8 bytes into tw, sets tl and ts. A '"' is a text; a |
| 736 | note first byte '-' or a digit is a number. |
| 737 | fn tok2 c uchar to void |
| 738 | if eq c 34 |
| 739 | tok_text |
| 740 | ret |
| 741 | end |
| 742 | put ts 0 get cur 0 |
| 743 | if or eq c 40 eq c 41 |
| 744 | put tw 0 ulong c |
| 745 | put tl 0 1 |
| 746 | put cur 0 add get cur 0 1 |
| 747 | put tk 0 1 |
| 748 | ret |
| 749 | end |
| 750 | w = ulong 0 |
| 751 | sh = ulong 0 |
| 752 | n = ulong 0 |
| 753 | go = true |
| 754 | while go |
| 755 | m = ulong 0 |
| 756 | while and go lt m 999999 |
| 757 | if ge get cur 0 get inlen 0 |
| 758 | go = false |
| 759 | else |
| 760 | b = get inp get cur 0 |
| 761 | if le b 32 |
| 762 | go = false |
| 763 | else |
| 764 | if or eq b 40 eq b 41 |
| 765 | go = false |
| 766 | else |
| 767 | if lt n 8 |
| 768 | w = or w shl ulong b sh |
| 769 | sh = add sh 8 |
| 770 | end |
| 771 | n = add n 1 |
| 772 | put cur 0 add get cur 0 1 |
| 773 | end |
| 774 | end |
| 775 | end |
| 776 | m = add m 1 |
| 777 | end |
| 778 | end |
| 779 | put tw 0 w |
| 780 | put tl 0 n |
| 781 | f = get inp get ts 0 |
| 782 | isnum = false |
| 783 | if eq f 45 |
| 784 | isnum = true |
| 785 | end |
| 786 | if and ge f 48 le f 57 |
| 787 | isnum = true |
| 788 | end |
| 789 | if isnum |
| 790 | tok_num |
| 791 | else |
| 792 | put tk 0 1 |
| 793 | end |
| 794 | end |
| 795 | |
| 796 | note tok: next word, skipping blanks (space, tab, carriage return); newline is end of line (kind 0) and |
| 797 | note bumps the line number; another byte below 32 is error 16; the end of the input is kind 3. om4 TOK. |
| 798 | fn tok to void |
| 799 | go = true |
| 800 | while go |
| 801 | n = ulong 0 |
| 802 | while and go lt n 999999 |
| 803 | if ge get cur 0 get inlen 0 |
| 804 | go = false |
| 805 | else |
| 806 | c = get inp get cur 0 |
| 807 | if or or eq c 32 eq c 9 eq c 13 |
| 808 | put cur 0 add get cur 0 1 |
| 809 | else |
| 810 | if eq c 10 |
| 811 | put tka 0 get cur 0 |
| 812 | put tkb 0 add get cur 0 1 |
| 813 | put cur 0 add get cur 0 1 |
| 814 | put line 0 add get line 0 1 |
| 815 | put tk 0 0 |
| 816 | ret |
| 817 | end |
| 818 | put tka 0 get cur 0 |
| 819 | put tkb 0 add get cur 0 1 |
| 820 | if lt c 32 |
| 821 | fail 16 |
| 822 | end |
| 823 | put tka 0 get cur 0 |
| 824 | put tkb 0 get cur 0 |
| 825 | tok2 c |
| 826 | put tkb 0 get cur 0 |
| 827 | ret |
| 828 | end |
| 829 | end |
| 830 | n = add n 1 |
| 831 | end |
| 832 | end |
| 833 | put tka 0 get inlen 0 |
| 834 | put tkb 0 get inlen 0 |
| 835 | put tk 0 3 |
| 836 | end |
| 837 | |
| 838 | note ======== keyword lookup (original om4 KWTAB plus native host words 100..177, flock 197, execpure 198 and execenv 233) ======== |
| 839 | note genkw.awk describes the original om4 table only; retain the native host extension on regeneration. |
| 840 | note efi (178) is a keyword only under `target x86efi`; gate18 checks that scoped entry separately. |
| 841 | fn kw w ulong to ulong |
| 842 | if and eq w 6907493 eq get xtarget 0 2 |
| 843 | ret 178 |
| 844 | end |
| 845 | if eq w 7310034270740117605 |
| 846 | ret 198 |
| 847 | end |
| 848 | if eq w 6584163 |
| 849 | ret 132 |
| 850 | end |
| 851 | packed = or ulong 114 shl ulong 101 8 |
| 852 | packed = or packed shl ulong 97 16 |
| 853 | packed = or packed shl ulong 100 24 |
| 854 | packed = or packed shl ulong 108 32 |
| 855 | packed = or packed shl ulong 110 40 |
| 856 | packed = or packed shl ulong 107 48 |
| 857 | if eq w packed |
| 858 | ret 133 |
| 859 | end |
| 860 | packed = or ulong 115 shl ulong 111 8 |
| 861 | packed = or packed shl ulong 99 16 |
| 862 | packed = or packed shl ulong 107 24 |
| 863 | packed = or packed shl ulong 111 32 |
| 864 | packed = or packed shl ulong 112 40 |
| 865 | packed = or packed shl ulong 116 48 |
| 866 | if eq w packed |
| 867 | ret 134 |
| 868 | end |
| 869 | if eq w 120325193752946 |
| 870 | ret 135 |
| 871 | end |
| 872 | if eq w 128017463930469 |
| 873 | ret 136 |
| 874 | end |
| 875 | if eq w 28254586011020901 |
| 876 | ret 137 |
| 877 | end |
| 878 | if eq w 491394459747 |
| 879 | ret 138 |
| 880 | end |
| 881 | if eq w 109326067987558 |
| 882 | ret 139 |
| 883 | end |
| 884 | if eq w 1952543859 |
| 885 | ret 140 |
| 886 | end |
| 887 | if eq w 1802398060 |
| 888 | ret 141 |
| 889 | end |
| 890 | if eq w 118122009688435 |
| 891 | ret 142 |
| 892 | end |
| 893 | if eq w 431366170723 |
| 894 | ret 143 |
| 895 | end |
| 896 | if eq w 32496501618073958 |
| 897 | ret 144 |
| 898 | end |
| 899 | if eq w 110404104906087 |
| 900 | ret 145 |
| 901 | end |
| 902 | if eq w 28263450605282663 |
| 903 | ret 146 |
| 904 | end |
| 905 | if eq w 110403870025063 |
| 906 | ret 147 |
| 907 | end |
| 908 | if eq w 28263390475740519 |
| 909 | ret 148 |
| 910 | end |
| 911 | if eq w 499851228012 |
| 912 | ret 149 |
| 913 | end |
| 914 | if eq w 7310575174812004980 |
| 915 | ret 150 |
| 916 | end |
| 917 | if eq w 474450192483 |
| 918 | ret 151 |
| 919 | end |
| 920 | if eq w 500152823651 |
| 921 | ret 152 |
| 922 | end |
| 923 | if eq w 125796981695334 |
| 924 | ret 153 |
| 925 | end |
| 926 | if eq w 28263429314995559 |
| 927 | ret 154 |
| 928 | end |
| 929 | if eq w 461497265525 |
| 930 | ret 155 |
| 931 | end |
| 932 | if eq w 109326135157862 |
| 933 | ret 156 |
| 934 | end |
| 935 | if eq w 431215175021 |
| 936 | ret 157 |
| 937 | end |
| 938 | if eq w 110404071351667 |
| 939 | ret 158 |
| 940 | end |
| 941 | if eq w 28263390660289895 |
| 942 | ret 159 |
| 943 | end |
| 944 | if eq w 28263390660289907 |
| 945 | ret 160 |
| 946 | end |
| 947 | if eq w 431130767984 |
| 948 | ret 161 |
| 949 | end |
| 950 | if eq w 111550659721072 |
| 951 | ret 162 |
| 952 | end |
| 953 | if eq w 110404071351655 |
| 954 | ret 163 |
| 955 | end |
| 956 | if eq w 126883592042867 |
| 957 | ret 164 |
| 958 | end |
| 959 | if eq w 7959953343641905267 |
| 960 | ret 165 |
| 961 | end |
| 962 | if eq w 119247140709732 |
| 963 | ret 166 |
| 964 | end |
| 965 | if eq w 131277528260973 |
| 966 | ret 167 |
| 967 | end |
| 968 | if eq w 31647734493634925 |
| 969 | ret 168 |
| 970 | end |
| 971 | if eq w 28254586010624365 |
| 972 | ret 169 |
| 973 | end |
| 974 | if eq w 7310584035480199533 |
| 975 | ret 170 |
| 976 | end |
| 977 | if eq w 30518463021081956 |
| 978 | ret 171 |
| 979 | end |
| 980 | if eq w 119247140124277 |
| 981 | ret 172 |
| 982 | end |
| 983 | if eq w 32198529639276909 |
| 984 | ret 173 |
| 985 | end |
| 986 | if eq w 127978875937133 |
| 987 | ret 174 |
| 988 | end |
| 989 | if eq w 127979077263725 |
| 990 | ret 175 |
| 991 | end |
| 992 | if eq w 28266723420430701 |
| 993 | ret 176 |
| 994 | end |
| 995 | if eq w 28268896573219181 |
| 996 | ret 177 |
| 997 | end |
| 998 | if eq w 30527267904513654 |
| 999 | ret 228 |
| 1000 | end |
| 1001 | if eq w 31632320040101494 |
| 1002 | ret 229 |
| 1003 | end |
| 1004 | if eq w 8606486010553525878 |
| 1005 | ret 230 |
| 1006 | end |
| 1007 | if eq w 28260147925448293 |
| 1008 | ret 231 |
| 1009 | end |
| 1010 | if eq w 31932469534615158 |
| 1011 | ret 232 |
| 1012 | end |
| 1013 | if eq w 461229747302 |
| 1014 | ret 197 |
| 1015 | end |
| 1016 | if eq w 1819242338 |
| 1017 | ret 1 |
| 1018 | end |
| 1019 | if eq w 491260502901 |
| 1020 | ret 2 |
| 1021 | end |
| 1022 | if eq w 14453 |
| 1023 | ret 2 |
| 1024 | end |
| 1025 | if eq w 128034844210037 |
| 1026 | ret 3 |
| 1027 | end |
| 1028 | if eq w 3551605 |
| 1029 | ret 3 |
| 1030 | end |
| 1031 | if eq w 1953393013 |
| 1032 | ret 4 |
| 1033 | end |
| 1034 | if eq w 3289973 |
| 1035 | ret 4 |
| 1036 | end |
| 1037 | if eq w 444234427509 |
| 1038 | ret 5 |
| 1039 | end |
| 1040 | if eq w 3421813 |
| 1041 | ret 5 |
| 1042 | end |
| 1043 | if eq w 1702132066 |
| 1044 | ret 6 |
| 1045 | end |
| 1046 | if eq w 14441 |
| 1047 | ret 6 |
| 1048 | end |
| 1049 | if eq w 500136110195 |
| 1050 | ret 7 |
| 1051 | end |
| 1052 | if eq w 3551593 |
| 1053 | ret 7 |
| 1054 | end |
| 1055 | if eq w 7630441 |
| 1056 | ret 8 |
| 1057 | end |
| 1058 | if eq w 3289961 |
| 1059 | ret 8 |
| 1060 | end |
| 1061 | if eq w 1735290732 |
| 1062 | ret 9 |
| 1063 | end |
| 1064 | if eq w 3421801 |
| 1065 | ret 9 |
| 1066 | end |
| 1067 | if eq w 6579297 |
| 1068 | ret 33 |
| 1069 | end |
| 1070 | if eq w 6452595 |
| 1071 | ret 34 |
| 1072 | end |
| 1073 | if eq w 7107949 |
| 1074 | ret 35 |
| 1075 | end |
| 1076 | if eq w 7760228 |
| 1077 | ret 36 |
| 1078 | end |
| 1079 | if eq w 7169394 |
| 1080 | ret 37 |
| 1081 | end |
| 1082 | if eq w 6581857 |
| 1083 | ret 38 |
| 1084 | end |
| 1085 | if eq w 29295 |
| 1086 | ret 39 |
| 1087 | end |
| 1088 | if eq w 7499640 |
| 1089 | ret 40 |
| 1090 | end |
| 1091 | if eq w 7104627 |
| 1092 | ret 41 |
| 1093 | end |
| 1094 | if eq w 7497843 |
| 1095 | ret 42 |
| 1096 | end |
| 1097 | if eq w 29029 |
| 1098 | ret 43 |
| 1099 | end |
| 1100 | if eq w 25966 |
| 1101 | ret 44 |
| 1102 | end |
| 1103 | if eq w 29804 |
| 1104 | ret 45 |
| 1105 | end |
| 1106 | if eq w 25964 |
| 1107 | ret 46 |
| 1108 | end |
| 1109 | if eq w 29799 |
| 1110 | ret 47 |
| 1111 | end |
| 1112 | if eq w 25959 |
| 1113 | ret 48 |
| 1114 | end |
| 1115 | if eq w 6776174 |
| 1116 | ret 49 |
| 1117 | end |
| 1118 | if eq w 7630702 |
| 1119 | ret 50 |
| 1120 | end |
| 1121 | if eq w 7628135 |
| 1122 | ret 51 |
| 1123 | end |
| 1124 | if eq w 7234924 |
| 1125 | ret 52 |
| 1126 | end |
| 1127 | if eq w 1684104562 |
| 1128 | ret 53 |
| 1129 | end |
| 1130 | if eq w 435744764535 |
| 1131 | ret 54 |
| 1132 | end |
| 1133 | if eq w 1702195828 |
| 1134 | ret 55 |
| 1135 | end |
| 1136 | if eq w 435728179558 |
| 1137 | ret 56 |
| 1138 | end |
| 1139 | if eq w 2003134838 |
| 1140 | ret 57 |
| 1141 | end |
| 1142 | if eq w 1953064037 |
| 1143 | ret 58 |
| 1144 | end |
| 1145 | if eq w 28262 |
| 1146 | ret 64 |
| 1147 | end |
| 1148 | if eq w 28532 |
| 1149 | ret 65 |
| 1150 | end |
| 1151 | if eq w 6581861 |
| 1152 | ret 66 |
| 1153 | end |
| 1154 | if eq w 26217 |
| 1155 | ret 67 |
| 1156 | end |
| 1157 | if eq w 1702063205 |
| 1158 | ret 68 |
| 1159 | end |
| 1160 | if eq w 435610544247 |
| 1161 | ret 69 |
| 1162 | end |
| 1163 | if eq w 431349919586 |
| 1164 | ret 70 |
| 1165 | end |
| 1166 | if eq w 7499622 |
| 1167 | ret 71 |
| 1168 | end |
| 1169 | if eq w 7628146 |
| 1170 | ret 72 |
| 1171 | end |
| 1172 | if eq w 61 |
| 1173 | ret 73 |
| 1174 | end |
| 1175 | if eq w 40 |
| 1176 | ret 74 |
| 1177 | end |
| 1178 | if eq w 41 |
| 1179 | ret 75 |
| 1180 | end |
| 1181 | if eq w 1684631414 |
| 1182 | ret 76 |
| 1183 | end |
| 1184 | if eq w 119165519096935 |
| 1185 | ret 78 |
| 1186 | end |
| 1187 | if eq w 1954047348 |
| 1188 | ret 79 |
| 1189 | end |
| 1190 | if eq w 7632240 |
| 1191 | ret 80 |
| 1192 | end |
| 1193 | if eq w 1701147238 |
| 1194 | ret 81 |
| 1195 | end |
| 1196 | if eq w 1953069157 |
| 1197 | ret 82 |
| 1198 | end |
| 1199 | if eq w 1702129518 |
| 1200 | ret 83 |
| 1201 | end |
| 1202 | if eq w 7824750 |
| 1203 | ret 84 |
| 1204 | end |
| 1205 | if eq w 461195539042 |
| 1206 | ret 86 |
| 1207 | end |
| 1208 | if eq w 1885434484 |
| 1209 | ret 87 |
| 1210 | end |
| 1211 | if eq w 7239535 |
| 1212 | ret 77 |
| 1213 | end |
| 1214 | if eq w 7308604897168158579 |
| 1215 | ret 131 |
| 1216 | end |
| 1217 | if eq w 126918101919090 |
| 1218 | ret 130 |
| 1219 | end |
| 1220 | if eq w 7453301735350958181 |
| 1221 | ret 124 |
| 1222 | end |
| 1223 | if eq w 32481142782190962 |
| 1224 | ret 125 |
| 1225 | end |
| 1226 | if eq w 491394461042 |
| 1227 | ret 126 |
| 1228 | end |
| 1229 | if eq w 28263429247363435 |
| 1230 | ret 127 |
| 1231 | end |
| 1232 | if eq w 32480013273033072 |
| 1233 | ret 128 |
| 1234 | end |
| 1235 | if eq w 110404021020007 |
| 1236 | ret 129 |
| 1237 | end |
| 1238 | if eq w 122498715312503 |
| 1239 | ret 123 |
| 1240 | end |
| 1241 | if eq w 32497639802299751 |
| 1242 | ret 113 |
| 1243 | end |
| 1244 | if eq w 32760384594014051 |
| 1245 | ret 114 |
| 1246 | end |
| 1247 | if eq w 1684957538 |
| 1248 | ret 115 |
| 1249 | end |
| 1250 | if eq w 28263429381382519 |
| 1251 | ret 116 |
| 1252 | end |
| 1253 | if eq w 499851228006 |
| 1254 | ret 117 |
| 1255 | end |
| 1256 | if eq w 1986225522 |
| 1257 | ret 118 |
| 1258 | end |
| 1259 | if eq w 1684956531 |
| 1260 | ret 119 |
| 1261 | end |
| 1262 | if eq w 32491051338263667 |
| 1263 | ret 120 |
| 1264 | end |
| 1265 | if eq w 128017462948449 |
| 1266 | ret 121 |
| 1267 | end |
| 1268 | if eq w 28254586010038881 |
| 1269 | ret 122 |
| 1270 | end |
| 1271 | if eq w 111546465018726 |
| 1272 | ret 100 |
| 1273 | end |
| 1274 | if eq w 427055215462 |
| 1275 | ret 101 |
| 1276 | end |
| 1277 | if eq w 110429739705190 |
| 1278 | ret 102 |
| 1279 | end |
| 1280 | if eq w 461262648166 |
| 1281 | ret 103 |
| 1282 | end |
| 1283 | if eq w 33607047151054707 |
| 1284 | ret 104 |
| 1285 | end |
| 1286 | if eq w 121382024472940 |
| 1287 | ret 105 |
| 1288 | end |
| 1289 | if eq w 128026086171489 |
| 1290 | ret 106 |
| 1291 | end |
| 1292 | if eq w 1802661734 |
| 1293 | ret 107 |
| 1294 | end |
| 1295 | if eq w 431215375716 |
| 1296 | ret 108 |
| 1297 | end |
| 1298 | if eq w 126918153105261 |
| 1299 | ret 109 |
| 1300 | end |
| 1301 | if eq w 474148269926 |
| 1302 | ret 110 |
| 1303 | end |
| 1304 | if eq w 118121959288437 |
| 1305 | ret 111 |
| 1306 | end |
| 1307 | if eq w 32204027264196973 |
| 1308 | ret 112 |
| 1309 | end |
| 1310 | if eq w 127970521019507 |
| 1311 | ret 85 |
| 1312 | end |
| 1313 | if eq w 3289958 |
| 1314 | ret 88 |
| 1315 | end |
| 1316 | if eq w 3421798 |
| 1317 | ret 89 |
| 1318 | end |
| 1319 | if eq w 32777959416031586 |
| 1320 | ret 90 |
| 1321 | end |
| 1322 | if eq w 500136244070 |
| 1323 | ret 91 |
| 1324 | end |
| 1325 | if eq w 1935827302 |
| 1326 | ret 92 |
| 1327 | end |
| 1328 | if eq w 1852403046 |
| 1329 | ret 93 |
| 1330 | end |
| 1331 | if eq w 2019650918 |
| 1332 | ret 94 |
| 1333 | end |
| 1334 | if eq w 112628629924211 |
| 1335 | ret 95 |
| 1336 | end |
| 1337 | if eq w 7381246293360141935 |
| 1338 | ret 96 |
| 1339 | end |
| 1340 | if eq w 7310870969309884259 |
| 1341 | ret 97 |
| 1342 | end |
| 1343 | if eq w 7234314147887146352 |
| 1344 | ret 220 |
| 1345 | end |
| 1346 | if eq w 32480013390212976 |
| 1347 | ret 221 |
| 1348 | end |
| 1349 | if eq w 29118836274783603 |
| 1350 | ret 222 |
| 1351 | end |
| 1352 | if eq w 7959665 |
| 1353 | ret 223 |
| 1354 | end |
| 1355 | if eq w 7305804402314801251 |
| 1356 | ret 199 |
| 1357 | end |
| 1358 | if eq w 8674333540260081763 |
| 1359 | ret 200 |
| 1360 | end |
| 1361 | if eq w 7308604897285727600 |
| 1362 | ret 224 |
| 1363 | end |
| 1364 | if eq w 6384998 |
| 1365 | ret 227 |
| 1366 | end |
| 1367 | if eq w 33335428990204005 |
| 1368 | ret 233 |
| 1369 | end |
| 1370 | if eq get om2 0 0 |
| 1371 | ret 0 |
| 1372 | end |
| 1373 | ret kw2 w |
| 1374 | end |
| 1375 | |
| 1376 | note ======== OM-2 words (spec/omegese-om2.md): reserved only in an OM-2 unit. rotr 59, rotl 60 are |
| 1377 | note binary operators; dit 225 and scrub 226 are program-mode value words (OMEGESE 9.13.1); count 179 is a |
| 1378 | note value word (cnt_word); the rest are statement and declaration words of later sections. ======== |
| 1379 | fn kw2 w ulong to ulong |
| 1380 | if eq w 1920233330 |
| 1381 | ret 59 |
| 1382 | end |
| 1383 | if eq w 1819570034 |
| 1384 | ret 60 |
| 1385 | end |
| 1386 | if eq w 119212982038133 |
| 1387 | ret 181 |
| 1388 | end |
| 1389 | if eq w 111524889521769 |
| 1390 | ret 182 |
| 1391 | end |
| 1392 | if eq w 448612627046 |
| 1393 | ret 183 |
| 1394 | end |
| 1395 | if eq w 8386654075301880417 |
| 1396 | ret 184 |
| 1397 | end |
| 1398 | if eq w 1818322291 |
| 1399 | ret 185 |
| 1400 | end |
| 1401 | if eq w 1852141679 |
| 1402 | ret 186 |
| 1403 | end |
| 1404 | if eq w 495606067048 |
| 1405 | ret 187 |
| 1406 | end |
| 1407 | if eq w 128047730221420 |
| 1408 | ret 188 |
| 1409 | end |
| 1410 | if eq w 431315315046 |
| 1411 | ret 189 |
| 1412 | end |
| 1413 | if eq w 29793 |
| 1414 | ret 190 |
| 1415 | end |
| 1416 | if eq w 111516484659564 |
| 1417 | ret 191 |
| 1418 | end |
| 1419 | if eq w 6777186 |
| 1420 | ret 192 |
| 1421 | end |
| 1422 | if eq w 1953653104 |
| 1423 | ret 193 |
| 1424 | end |
| 1425 | if eq w 7632239 |
| 1426 | ret 194 |
| 1427 | end |
| 1428 | if eq w 128034844735589 |
| 1429 | ret 195 |
| 1430 | end |
| 1431 | if eq w 7565423 |
| 1432 | ret 196 |
| 1433 | end |
| 1434 | if eq w 7629156 |
| 1435 | ret 225 |
| 1436 | end |
| 1437 | if eq w 422877225843 |
| 1438 | ret 226 |
| 1439 | end |
| 1440 | if eq w 500069396323 |
| 1441 | ret 179 |
| 1442 | end |
| 1443 | ret 0 |
| 1444 | end |
| 1445 | |
| 1446 | note nfail: a bad number (diag expect=number); unkfail: an undeclared function or struct (sev=unknown) |
| 1447 | fn nfail code ulong to void |
| 1448 | put dexp 0 4 |
| 1449 | fail code |
| 1450 | end |
| 1451 | |
| 1452 | fn unkfail code ulong to void |
| 1453 | put dsev 0 2 |
| 1454 | put dexp 0 3 |
| 1455 | fail code |
| 1456 | end |
| 1457 | |
| 1458 | note lineis: the n bytes at q are the packed word w and the line ends right after them |
| 1459 | fn lineis q ulong w ulong n ulong to ulong |
| 1460 | e = get inlen 0 |
| 1461 | if gt add q n e |
| 1462 | ret 0 |
| 1463 | end |
| 1464 | i = ulong 0 |
| 1465 | x = w |
| 1466 | while lt i n |
| 1467 | if ne ulong get inp add q i and x 255 |
| 1468 | ret 0 |
| 1469 | end |
| 1470 | x = shr x 8 |
| 1471 | i = add i 1 |
| 1472 | end |
| 1473 | r = add q n |
| 1474 | if lt r e |
| 1475 | if ne get inp r 10 |
| 1476 | ret 0 |
| 1477 | end |
| 1478 | end |
| 1479 | ret 1 |
| 1480 | end |
| 1481 | |
| 1482 | note isnote: the word at p is note (the lexer ends a word at a blank, a parenthesis or the end) |
| 1483 | fn isnote p ulong to ulong |
| 1484 | e = get inlen 0 |
| 1485 | if gt add p 4 e |
| 1486 | ret 0 |
| 1487 | end |
| 1488 | i = ulong 0 |
| 1489 | x = ulong 1702129518 |
| 1490 | while lt i 4 |
| 1491 | if ne ulong get inp add p i and x 255 |
| 1492 | ret 0 |
| 1493 | end |
| 1494 | x = shr x 8 |
| 1495 | i = add i 1 |
| 1496 | end |
| 1497 | r = add p 4 |
| 1498 | if lt r e |
| 1499 | b = get inp r |
| 1500 | if and gt b 32 and ne b 40 ne b 41 |
| 1501 | ret 0 |
| 1502 | end |
| 1503 | end |
| 1504 | ret 1 |
| 1505 | end |
| 1506 | |
| 1507 | fn chk_mode q ulong to ulong |
| 1508 | if ne lineis q 461229090915 5 0 |
| 1509 | ret 1 |
| 1510 | end |
| 1511 | if ne lineis q 1954047342 4 0 |
| 1512 | ret 2 |
| 1513 | end |
| 1514 | ret 0 |
| 1515 | end |
| 1516 | |
| 1517 | fn chk_lead to void |
| 1518 | e = get inlen 0 |
| 1519 | p = ulong 0 |
| 1520 | ln = ulong 1 |
| 1521 | go = true |
| 1522 | while go |
| 1523 | m = ulong 0 |
| 1524 | while and go lt m 999999 |
| 1525 | q = skipbl p |
| 1526 | if ge q e |
| 1527 | go = false |
| 1528 | else |
| 1529 | if eq get inp q 10 |
| 1530 | p = add q 1 |
| 1531 | ln = add ln 1 |
| 1532 | else |
| 1533 | if ne isnote q 0 |
| 1534 | p = skipln q |
| 1535 | ln = add ln 1 |
| 1536 | else |
| 1537 | k = chk_mode q |
| 1538 | if ne k 0 |
| 1539 | put chkmode 0 k |
| 1540 | put chkln 0 ln |
| 1541 | put sbase 0 skipln q |
| 1542 | end |
| 1543 | go = false |
| 1544 | end |
| 1545 | end |
| 1546 | end |
| 1547 | m = add m 1 |
| 1548 | end |
| 1549 | end |
| 1550 | end |
| 1551 | |
| 1552 | note om2lead: skip blank lines and note lines; when the next line is exactly om2 (1), om2 diag (2) or |
| 1553 | note om2 fmt (3) the unit is OM-2: om2, om2m, om2ln, om2pos. Anything else leaves the unit OM-1. |
| 1554 | fn om2lead to void |
| 1555 | e = get inlen 0 |
| 1556 | p = ulong 0 |
| 1557 | ln = ulong 1 |
| 1558 | if ne get chkmode 0 0 |
| 1559 | p = get sbase 0 |
| 1560 | ln = add get chkln 0 1 |
| 1561 | end |
| 1562 | go = true |
| 1563 | while go |
| 1564 | m = ulong 0 |
| 1565 | while and go lt m 999999 |
| 1566 | q = skipbl p |
| 1567 | if ge q e |
| 1568 | go = false |
| 1569 | else |
| 1570 | if eq get inp q 10 |
| 1571 | p = add q 1 |
| 1572 | ln = add ln 1 |
| 1573 | else |
| 1574 | if ne isnote q 0 |
| 1575 | p = skipln q |
| 1576 | ln = add ln 1 |
| 1577 | else |
| 1578 | r = ulong 0 |
| 1579 | if eq q p |
| 1580 | if ne lineis q 3304815 3 0 |
| 1581 | r = ulong 1 |
| 1582 | end |
| 1583 | if ne lineis q 7449351137405332847 8 0 |
| 1584 | r = ulong 2 |
| 1585 | end |
| 1586 | if ne lineis q 32771382692703599 7 0 |
| 1587 | r = ulong 3 |
| 1588 | end |
| 1589 | if eq r 0 |
| 1590 | r = cp_mode q |
| 1591 | end |
| 1592 | end |
| 1593 | if ne r 0 |
| 1594 | put om2 0 1 |
| 1595 | put om2m 0 sub r 1 |
| 1596 | put om2ln 0 ln |
| 1597 | put om2pos 0 q |
| 1598 | end |
| 1599 | go = false |
| 1600 | end |
| 1601 | end |
| 1602 | end |
| 1603 | m = add m 1 |
| 1604 | end |
| 1605 | end |
| 1606 | end |
| 1607 | |
| 1608 | note ---- om2 fmt (spec 2, errata E4, E6): only when the input's first line, at byte 0, is om2 fmt (an om2 |
| 1609 | note fmt line elsewhere is error 16). The rest (the bytes after the first LF) is compiled as a unit of |
| 1610 | note its own (OM-1 or OM-2 by its own first line) and, when it is accepted, its canonical text is written |
| 1611 | note instead of the artifact. A CR anywhere and blank lines at the end are error 6. Lines and spans are |
| 1612 | note reported against the whole input. |
| 1613 | global fst ulong 1 |
| 1614 | global fpend ulong 1 |
| 1615 | global fbo ulong 1 |
| 1616 | global fprp ulong 1 |
| 1617 | global flso ulong 1 |
| 1618 | |
| 1619 | note fmttail: blank lines at the end of the rest (n bytes) are error 6, at the first such line |
| 1620 | fn fmttail n ulong to void |
| 1621 | lnb = ulong 0 |
| 1622 | lnl = ulong 1 |
| 1623 | ln = ulong 1 |
| 1624 | i = ulong 0 |
| 1625 | go = true |
| 1626 | while go |
| 1627 | m = ulong 0 |
| 1628 | while and go lt m 999999 |
| 1629 | if ge i n |
| 1630 | go = false |
| 1631 | else |
| 1632 | b = get inp i |
| 1633 | if eq b 10 |
| 1634 | ln = add ln 1 |
| 1635 | else |
| 1636 | if and ne b 32 ne b 9 |
| 1637 | lnb = add i 1 |
| 1638 | lnl = ln |
| 1639 | end |
| 1640 | end |
| 1641 | i = add i 1 |
| 1642 | end |
| 1643 | m = add m 1 |
| 1644 | end |
| 1645 | end |
| 1646 | bad = false |
| 1647 | if eq lnb 0 |
| 1648 | if gt n 0 |
| 1649 | bad = true |
| 1650 | lnl = ulong 0 |
| 1651 | end |
| 1652 | end |
| 1653 | k = lnb |
| 1654 | fl = n |
| 1655 | go = true |
| 1656 | while go |
| 1657 | m = ulong 0 |
| 1658 | while and go lt m 999999 |
| 1659 | if ge k n |
| 1660 | go = false |
| 1661 | else |
| 1662 | if eq get inp k 10 |
| 1663 | fl = k |
| 1664 | go = false |
| 1665 | end |
| 1666 | k = add k 1 |
| 1667 | end |
| 1668 | m = add m 1 |
| 1669 | end |
| 1670 | end |
| 1671 | if lt add fl 1 n |
| 1672 | bad = true |
| 1673 | end |
| 1674 | if bad |
| 1675 | put line 0 add lnl 1 |
| 1676 | put tka 0 lnb |
| 1677 | put tkb 0 lnb |
| 1678 | fail 6 |
| 1679 | end |
| 1680 | end |
| 1681 | |
| 1682 | fn fmtprep to void |
| 1683 | if ne get om2pos 0 0 |
| 1684 | put line 0 get om2ln 0 |
| 1685 | put tka 0 get om2pos 0 |
| 1686 | put tkb 0 get om2pos 0 |
| 1687 | fail 16 |
| 1688 | end |
| 1689 | e = get inlen 0 |
| 1690 | ln = ulong 1 |
| 1691 | i = ulong 0 |
| 1692 | go = true |
| 1693 | while go |
| 1694 | m = ulong 0 |
| 1695 | while and go lt m 999999 |
| 1696 | if ge i e |
| 1697 | go = false |
| 1698 | else |
| 1699 | b = get inp i |
| 1700 | if eq b 13 |
| 1701 | put line 0 ln |
| 1702 | put tka 0 i |
| 1703 | put tkb 0 add i 1 |
| 1704 | fail 6 |
| 1705 | end |
| 1706 | if eq b 10 |
| 1707 | ln = add ln 1 |
| 1708 | end |
| 1709 | i = add i 1 |
| 1710 | end |
| 1711 | m = add m 1 |
| 1712 | end |
| 1713 | end |
| 1714 | r = skipln get om2pos 0 |
| 1715 | put lbase 0 get om2ln 0 |
| 1716 | put sbase 0 r |
| 1717 | n = sub e r |
| 1718 | j = ulong 0 |
| 1719 | go = true |
| 1720 | while go |
| 1721 | m = ulong 0 |
| 1722 | while and go lt m 999999 |
| 1723 | if ge j n |
| 1724 | go = false |
| 1725 | else |
| 1726 | put inp j get inp add r j |
| 1727 | j = add j 1 |
| 1728 | end |
| 1729 | m = add m 1 |
| 1730 | end |
| 1731 | end |
| 1732 | put inlen 0 n |
| 1733 | fmttail n |
| 1734 | put om2 0 0 |
| 1735 | put om2m 0 0 |
| 1736 | put om2ln 0 0 |
| 1737 | put fmtm 0 1 |
| 1738 | om2lead |
| 1739 | if eq get om2m 0 2 |
| 1740 | put line 0 get om2ln 0 |
| 1741 | put tka 0 get om2pos 0 |
| 1742 | put tkb 0 get om2pos 0 |
| 1743 | fail 16 |
| 1744 | end |
| 1745 | end |
| 1746 | |
| 1747 | note fmtbyte: one input byte of the canonical text. fst: 0 line start, 1 indentation (kept, dropped |
| 1748 | note again on a blank line), 2 note line (copied), 3 between words, 4 in a word, 5 in a text literal, 6 |
| 1749 | note after a backslash in a text literal. A run of blanks between words (fpend, starting at output byte |
| 1750 | note fbo) is written as it comes, then becomes one space unless a parenthesis is next to it (fprp: the |
| 1751 | note word before it was one); at the end of the line it is dropped. |
| 1752 | fn fmtbyte p ulong to void |
| 1753 | b = get inp p |
| 1754 | s = get fst 0 |
| 1755 | if eq b 10 |
| 1756 | if lt s 2 |
| 1757 | put oc 0 get flso 0 |
| 1758 | else |
| 1759 | if ne get fpend 0 0 |
| 1760 | put oc 0 get fbo 0 |
| 1761 | end |
| 1762 | end |
| 1763 | emitb 10 |
| 1764 | put fst 0 0 |
| 1765 | put fpend 0 0 |
| 1766 | put fprp 0 0 |
| 1767 | put flso 0 get oc 0 |
| 1768 | ret |
| 1769 | end |
| 1770 | if eq s 2 |
| 1771 | emitb b |
| 1772 | ret |
| 1773 | end |
| 1774 | if eq s 5 |
| 1775 | emitb b |
| 1776 | if eq b 92 |
| 1777 | put fst 0 6 |
| 1778 | end |
| 1779 | if eq b 34 |
| 1780 | put fst 0 3 |
| 1781 | put fprp 0 0 |
| 1782 | end |
| 1783 | ret |
| 1784 | end |
| 1785 | if eq s 6 |
| 1786 | emitb b |
| 1787 | put fst 0 5 |
| 1788 | ret |
| 1789 | end |
| 1790 | blank = or eq b 32 eq b 9 |
| 1791 | if lt s 2 |
| 1792 | if blank |
| 1793 | emitb b |
| 1794 | put fst 0 1 |
| 1795 | ret |
| 1796 | end |
| 1797 | if ne isnote p 0 |
| 1798 | emitb b |
| 1799 | put fst 0 2 |
| 1800 | ret |
| 1801 | end |
| 1802 | put fst 0 3 |
| 1803 | put fpend 0 0 |
| 1804 | end |
| 1805 | if blank |
| 1806 | if eq get fpend 0 0 |
| 1807 | put fbo 0 get oc 0 |
| 1808 | put fpend 0 1 |
| 1809 | end |
| 1810 | emitb b |
| 1811 | put fst 0 3 |
| 1812 | ret |
| 1813 | end |
| 1814 | paren = or eq b 40 eq b 41 |
| 1815 | if and eq get fst 0 4 not paren |
| 1816 | emitb b |
| 1817 | ret |
| 1818 | end |
| 1819 | if ne get fpend 0 0 |
| 1820 | if and eq get fprp 0 0 not paren |
| 1821 | put oc 0 get fbo 0 |
| 1822 | emitb 32 |
| 1823 | end |
| 1824 | end |
| 1825 | put fpend 0 0 |
| 1826 | emitb b |
| 1827 | if eq b 34 |
| 1828 | put fst 0 5 |
| 1829 | put fprp 0 0 |
| 1830 | ret |
| 1831 | end |
| 1832 | if paren |
| 1833 | put fst 0 3 |
| 1834 | put fprp 0 1 |
| 1835 | else |
| 1836 | put fst 0 4 |
| 1837 | put fprp 0 0 |
| 1838 | end |
| 1839 | end |
| 1840 | |
| 1841 | fn fmtout to void |
| 1842 | put oc 0 0 |
| 1843 | put fst 0 0 |
| 1844 | put fpend 0 0 |
| 1845 | put fprp 0 0 |
| 1846 | put flso 0 0 |
| 1847 | e = get inlen 0 |
| 1848 | p = ulong 0 |
| 1849 | go = true |
| 1850 | while go |
| 1851 | m = ulong 0 |
| 1852 | while and go lt m 999999 |
| 1853 | if ge p e |
| 1854 | go = false |
| 1855 | else |
| 1856 | fmtbyte p |
| 1857 | p = add p 1 |
| 1858 | end |
| 1859 | m = add m 1 |
| 1860 | end |
| 1861 | end |
| 1862 | if ge get fst 0 2 |
| 1863 | if ne get fpend 0 0 |
| 1864 | put oc 0 get fbo 0 |
| 1865 | end |
| 1866 | emitb 10 |
| 1867 | end |
| 1868 | put fmtm 0 0 |
| 1869 | put om2m 0 0 |
| 1870 | writeout 0 |
| 1871 | end |
| 1872 | |
| 1873 | note tok_hex (OM-2): 0x and 1..16 digits 0-9 a-f is the unsigned value (tk 2, tbig as tok_num). A - before |
| 1874 | note 0x, 0X, no digits, more than 16 digits, an uppercase or any other character is error 6. 0 when the |
| 1875 | note word is not a hex literal. |
| 1876 | fn tok_hex to ulong |
| 1877 | p = get ts 0 |
| 1878 | e = get cur 0 |
| 1879 | if eq get inp p 45 |
| 1880 | q = add p 1 |
| 1881 | if lt add q 1 e |
| 1882 | if eq get inp q 48 |
| 1883 | c = get inp add q 1 |
| 1884 | if or eq c 120 eq c 88 |
| 1885 | nfail 6 |
| 1886 | end |
| 1887 | end |
| 1888 | end |
| 1889 | ret 0 |
| 1890 | end |
| 1891 | if ge add p 1 e |
| 1892 | ret 0 |
| 1893 | end |
| 1894 | if ne get inp p 48 |
| 1895 | ret 0 |
| 1896 | end |
| 1897 | c = get inp add p 1 |
| 1898 | if eq c 88 |
| 1899 | nfail 6 |
| 1900 | end |
| 1901 | if ne c 120 |
| 1902 | ret 0 |
| 1903 | end |
| 1904 | n = sub e add p 2 |
| 1905 | if eq n 0 |
| 1906 | nfail 6 |
| 1907 | end |
| 1908 | if gt n 16 |
| 1909 | nfail 6 |
| 1910 | end |
| 1911 | v = ulong 0 |
| 1912 | i = add p 2 |
| 1913 | while lt i e |
| 1914 | d = ulong get inp i |
| 1915 | if and ge d 48 le d 57 |
| 1916 | v = or shl v 4 sub d 48 |
| 1917 | else |
| 1918 | if and ge d 97 le d 102 |
| 1919 | v = or shl v 4 sub d 87 |
| 1920 | else |
| 1921 | nfail 6 |
| 1922 | end |
| 1923 | end |
| 1924 | i = add i 1 |
| 1925 | end |
| 1926 | put tbig 0 shr v 63 |
| 1927 | put tw 0 v |
| 1928 | put tk 0 2 |
| 1929 | ret 1 |
| 1930 | end |
| 1931 | |
| 1932 | note ---- float literals: a token is the decimal value fsgn * fnd * 10^fp10, fsuf 0 none / 1 f32 / 2 f64. |
| 1933 | note fg_* hold the working state of the one literal being converted (see fparse/fbits/fnorm/fgen). |
| 1934 | global fsgn ulong 1 |
| 1935 | global fnd ulong 1 |
| 1936 | global fp10 long 1 |
| 1937 | global fsuf ulong 1 |
| 1938 | global fg_fl ulong 1 |
| 1939 | global fg_seen ulong 1 |
| 1940 | global fg_ex long 1 |
| 1941 | global fg_esign long 1 |
| 1942 | global fg_ed ulong 1 |
| 1943 | global fg_ty ulong 1 |
| 1944 | global fg_e long 1 |
| 1945 | global fg_q ulong 1 |
| 1946 | global fg_m ulong 1 |
| 1947 | global fg_stk ulong 1 |
| 1948 | global fbn ulong 80 |
| 1949 | |
| 1950 | note ======== float literals: decimal text to IEEE-754 binary32/binary64 ======== |
| 1951 | note The literal is fnd * 10^fp10 = A / D with A = fnd * 10^max(fp10,0) and D = 10^max(-fp10,0), both |
| 1952 | note held exactly as 40 32-bit limbs in fbn (A at 0, D at 40). The smaller of the two is shifted to the |
| 1953 | note other's bit length, then restoring division yields the first 64 quotient bits (fg_m, leading bit |
| 1954 | note set) and a remainder whose nonzero-ness is the sticky flag (fg_stk); froundsh rounds that exact |
| 1955 | note truncation once to nearest even and fpack packs it, subnormals included (#1024: the old converter |
| 1956 | note scaled one factor of ten at a time and dropped bits at every step). fp10 < -343 means a value |
| 1957 | note below (2^63-1)*10^-344 < 2^-1075, signed zero; fp10 > 308 means at least 10^309, above the |
| 1958 | note binary64 maximum (error 8). So A and D never exceed 1141 bits. |
| 1959 | |
| 1960 | note blen: bits needed for x (0 for zero) |
| 1961 | fn blen x ulong to ulong |
| 1962 | n = ulong 0 |
| 1963 | while ne x 0 |
| 1964 | x = shr x 1 |
| 1965 | n = add n 1 |
| 1966 | end |
| 1967 | ret n |
| 1968 | end |
| 1969 | |
| 1970 | note fparse: read the literal text inp[pos, pos+len) into fsgn, fnd, fp10, fsuf (0 none, 1 f32, 2 f64). |
| 1971 | note Grammar: [-]digits[.digits][(e|E)[+|-]digits][f32|f64]. At most 2^63-1 significant digits |
| 1972 | note (error 8), a dot with no digit after it is error 6, |exponent| <= 999 (error 8). |
| 1973 | note The digit scans here and in fexp run as nested 999999-pass loops: a literal of more than 1000000 |
| 1974 | note zero digits trapped 4 in a single loop's hidden 1000000-pass guard (#965). |
| 1975 | fn fparse pos ulong ln ulong to void |
| 1976 | p = pos |
| 1977 | e = add pos ln |
| 1978 | put fsgn 0 0 |
| 1979 | put fsuf 0 0 |
| 1980 | put fnd 0 0 |
| 1981 | put fg_fl 0 0 |
| 1982 | put fg_seen 0 0 |
| 1983 | if eq get inp p 45 |
| 1984 | put fsgn 0 1 |
| 1985 | p = add p 1 |
| 1986 | end |
| 1987 | go = true |
| 1988 | while go |
| 1989 | pos = ulong 0 |
| 1990 | while and go lt pos 999999 |
| 1991 | if ge p e |
| 1992 | go = false |
| 1993 | else |
| 1994 | d = sub ulong get inp p 48 |
| 1995 | if le d 9 |
| 1996 | if gt get fnd 0 922337203685477580 |
| 1997 | fail 8 |
| 1998 | end |
| 1999 | if eq get fnd 0 922337203685477580 |
| 2000 | if gt d 7 |
| 2001 | fail 8 |
| 2002 | end |
| 2003 | end |
| 2004 | put fnd 0 add mul get fnd 0 10 d |
| 2005 | if ne get fg_seen 0 0 |
| 2006 | put fg_fl 0 add get fg_fl 0 1 |
| 2007 | end |
| 2008 | p = add p 1 |
| 2009 | else |
| 2010 | go = false |
| 2011 | if eq get inp p 46 |
| 2012 | if eq get fg_seen 0 0 |
| 2013 | put fg_seen 0 1 |
| 2014 | p = add p 1 |
| 2015 | go = true |
| 2016 | end |
| 2017 | end |
| 2018 | end |
| 2019 | end |
| 2020 | pos = add pos 1 |
| 2021 | end |
| 2022 | end |
| 2023 | if and ne get fg_seen 0 0 eq get fg_fl 0 0 |
| 2024 | fail 6 |
| 2025 | end |
| 2026 | p = fexp p e |
| 2027 | p = fsufx p e |
| 2028 | if ne p e |
| 2029 | fail 6 |
| 2030 | end |
| 2031 | x = mul get fg_esign 0 get fg_ex 0 |
| 2032 | put fp10 0 sub x long get fg_fl 0 |
| 2033 | end |
| 2034 | |
| 2035 | note fexp: the exponent of the literal, if present: fg_ex, fg_esign, fg_ed. Returns the new position. |
| 2036 | fn fexp p ulong e ulong to ulong |
| 2037 | put fg_ex 0 0 |
| 2038 | put fg_esign 0 1 |
| 2039 | if and lt p e or eq get inp p 101 eq get inp p 69 |
| 2040 | p = add p 1 |
| 2041 | if lt p e |
| 2042 | if or eq get inp p 43 eq get inp p 45 |
| 2043 | if eq get inp p 45 |
| 2044 | put fg_esign 0 -1 |
| 2045 | end |
| 2046 | p = add p 1 |
| 2047 | end |
| 2048 | end |
| 2049 | put fg_ed 0 0 |
| 2050 | go = true |
| 2051 | while go |
| 2052 | m = ulong 0 |
| 2053 | while and go lt m 999999 |
| 2054 | if ge p e |
| 2055 | go = false |
| 2056 | else |
| 2057 | d = sub ulong get inp p 48 |
| 2058 | if gt d 9 |
| 2059 | go = false |
| 2060 | else |
| 2061 | put fg_ex 0 mul get fg_ex 0 10 |
| 2062 | put fg_ex 0 add get fg_ex 0 long d |
| 2063 | if gt get fg_ex 0 999 |
| 2064 | fail 8 |
| 2065 | end |
| 2066 | put fg_ed 0 add get fg_ed 0 1 |
| 2067 | p = add p 1 |
| 2068 | end |
| 2069 | end |
| 2070 | m = add m 1 |
| 2071 | end |
| 2072 | end |
| 2073 | if eq get fg_ed 0 0 |
| 2074 | fail 6 |
| 2075 | end |
| 2076 | end |
| 2077 | ret p |
| 2078 | end |
| 2079 | |
| 2080 | note fsufx: the optional f32/f64 suffix: fsuf 1 or 2. Returns the new position. |
| 2081 | fn fsufx p ulong e ulong to ulong |
| 2082 | if lt p e |
| 2083 | r = sub e p |
| 2084 | if ne r 3 |
| 2085 | fail 6 |
| 2086 | end |
| 2087 | if ne get inp p 102 |
| 2088 | fail 6 |
| 2089 | end |
| 2090 | if and eq get inp add p 1 51 eq get inp add p 2 50 |
| 2091 | put fsuf 0 1 |
| 2092 | else |
| 2093 | if and eq get inp add p 1 54 eq get inp add p 2 52 |
| 2094 | put fsuf 0 2 |
| 2095 | else |
| 2096 | fail 6 |
| 2097 | end |
| 2098 | end |
| 2099 | p = add p 3 |
| 2100 | end |
| 2101 | ret p |
| 2102 | end |
| 2103 | |
| 2104 | note fbmul: limbs fbn[o, o+40) times k (k < 2^32, so each limb step fits 64 bits); the product must fit |
| 2105 | note in 40 limbs. Returns its bit length, so fbmul o 1 only measures. |
| 2106 | fn fbmul o ulong k ulong to ulong |
| 2107 | c = ulong 0 |
| 2108 | t = ulong 0 |
| 2109 | i = ulong 0 |
| 2110 | while lt i 40 |
| 2111 | j = add o i |
| 2112 | v = add mul get fbn j k c |
| 2113 | put fbn j and v 4294967295 |
| 2114 | c = shr v 32 |
| 2115 | if ne and v 4294967295 0 |
| 2116 | t = add mul i 32 blen and v 4294967295 |
| 2117 | end |
| 2118 | i = add i 1 |
| 2119 | end |
| 2120 | ret t |
| 2121 | end |
| 2122 | |
| 2123 | note fbpow: fbn[o, o+40) times b^n (b 2 or 10), in factors that stay below 2^32. |
| 2124 | fn fbpow o ulong b ulong n ulong to void |
| 2125 | while gt n 0 |
| 2126 | m = ulong 1 |
| 2127 | c = ulong 0 |
| 2128 | while and lt c n le mul m b 4294967295 |
| 2129 | m = mul m b |
| 2130 | c = add c 1 |
| 2131 | end |
| 2132 | t = fbmul o m |
| 2133 | n = sub n c |
| 2134 | end |
| 2135 | end |
| 2136 | |
| 2137 | note fbsub: one restoring-division step. If A >= D then A = A - D and 1, else A is kept and 0. |
| 2138 | fn fbsub to ulong |
| 2139 | r = ulong 2 |
| 2140 | i = ulong 40 |
| 2141 | while and gt i 0 eq r 2 |
| 2142 | i = sub i 1 |
| 2143 | a = get fbn i |
| 2144 | d = get fbn add i 40 |
| 2145 | if lt a d |
| 2146 | r = ulong 0 |
| 2147 | end |
| 2148 | if gt a d |
| 2149 | r = ulong 1 |
| 2150 | end |
| 2151 | end |
| 2152 | if eq r 0 |
| 2153 | ret 0 |
| 2154 | end |
| 2155 | b = ulong 0 |
| 2156 | i = ulong 0 |
| 2157 | while lt i 40 |
| 2158 | v = sub sub get fbn i get fbn add i 40 b |
| 2159 | put fbn i and v 4294967295 |
| 2160 | b = shr v 63 |
| 2161 | i = add i 1 |
| 2162 | end |
| 2163 | ret 1 |
| 2164 | end |
| 2165 | |
| 2166 | note froundsh: round fg_m right by sh bits to fg_q, nearest even; the guard and every lower bit |
| 2167 | note (plus fg_stk) decide. sh may be 64 (then q is zero and bit 63 is the guard). |
| 2168 | fn froundsh sh ulong to void |
| 2169 | m = get fg_m 0 |
| 2170 | q = ulong 0 |
| 2171 | guard = ulong 0 |
| 2172 | lost = ulong 0 |
| 2173 | if eq sh 0 |
| 2174 | q = m |
| 2175 | else |
| 2176 | if ge sh 64 |
| 2177 | guard = shr m 63 |
| 2178 | lost = and m 9223372036854775807 |
| 2179 | else |
| 2180 | q = shr m sh |
| 2181 | guard = and shr m sub sh 1 1 |
| 2182 | if gt sub sh 1 0 |
| 2183 | lost = and m sub shl 1 sub sh 1 1 |
| 2184 | end |
| 2185 | end |
| 2186 | end |
| 2187 | sticky = or get fg_stk 0 lost |
| 2188 | if ne guard 0 |
| 2189 | if or ne sticky 0 eq and q 1 1 |
| 2190 | q = add q 1 |
| 2191 | end |
| 2192 | end |
| 2193 | put fg_q 0 q |
| 2194 | end |
| 2195 | |
| 2196 | note fpack: fg_m/fg_e to IEEE bits of fg_ty, including subnormals; a literal that rounds to infinity |
| 2197 | note is refused (error 8). |
| 2198 | fn fpack to ulong |
| 2199 | p = ulong 53 |
| 2200 | bias = long 1023 |
| 2201 | maxe = long 2047 |
| 2202 | emin = long -1022 |
| 2203 | mb = ulong 52 |
| 2204 | w = ulong 64 |
| 2205 | if eq get fg_ty 0 10 |
| 2206 | p = ulong 24 |
| 2207 | bias = long 127 |
| 2208 | maxe = long 255 |
| 2209 | emin = long -126 |
| 2210 | mb = ulong 23 |
| 2211 | w = ulong 32 |
| 2212 | end |
| 2213 | e = add get fg_e 0 63 |
| 2214 | if ge e emin |
| 2215 | sh = sub 64 p |
| 2216 | froundsh sh |
| 2217 | q = get fg_q 0 |
| 2218 | if eq q shl 1 p |
| 2219 | q = shr q 1 |
| 2220 | e = add e 1 |
| 2221 | end |
| 2222 | E = add e bias |
| 2223 | if ge E maxe |
| 2224 | fail 8 |
| 2225 | end |
| 2226 | q = and q sub shl 1 sub p 1 1 |
| 2227 | q = or q shl ulong E mb |
| 2228 | q = or q shl get fsgn 0 sub w 1 |
| 2229 | ret q |
| 2230 | end |
| 2231 | k = ulong sub emin e |
| 2232 | sh = add sub 64 p k |
| 2233 | if gt sh 64 |
| 2234 | ret shl get fsgn 0 sub w 1 |
| 2235 | end |
| 2236 | froundsh sh |
| 2237 | q = get fg_q 0 |
| 2238 | q = or q shl get fsgn 0 sub w 1 |
| 2239 | ret q |
| 2240 | end |
| 2241 | |
| 2242 | note fbits: the parsed literal as IEEE bits of type ty (10 f32, 11 f64). Zero keeps the sign (-0.0). |
| 2243 | fn fbits ty ulong to ulong |
| 2244 | put fg_ty 0 ty |
| 2245 | p = get fp10 0 |
| 2246 | if or eq get fnd 0 0 lt p -343 |
| 2247 | w = ulong 64 |
| 2248 | if eq ty 10 |
| 2249 | w = ulong 32 |
| 2250 | end |
| 2251 | b = ulong 0 |
| 2252 | if ne get fsgn 0 0 |
| 2253 | b = shl ulong 1 sub w 1 |
| 2254 | end |
| 2255 | ret b |
| 2256 | end |
| 2257 | if gt p 308 |
| 2258 | fail 8 |
| 2259 | end |
| 2260 | i = ulong 0 |
| 2261 | while lt i 80 |
| 2262 | put fbn i 0 |
| 2263 | i = add i 1 |
| 2264 | end |
| 2265 | put fbn 0 and get fnd 0 4294967295 |
| 2266 | put fbn 1 shr get fnd 0 32 |
| 2267 | put fbn 40 1 |
| 2268 | if gt p 0 |
| 2269 | fbpow 0 10 ulong p |
| 2270 | else |
| 2271 | fbpow 40 10 ulong sub 0 p |
| 2272 | end |
| 2273 | a = fbmul 0 1 |
| 2274 | d = fbmul 40 1 |
| 2275 | e = long 0 |
| 2276 | if lt a d |
| 2277 | fbpow 0 2 sub d a |
| 2278 | e = sub 0 long sub d a |
| 2279 | else |
| 2280 | fbpow 40 2 sub a d |
| 2281 | e = long sub a d |
| 2282 | end |
| 2283 | q = ulong 0 |
| 2284 | while lt q 9223372036854775808 |
| 2285 | q = or shl q 1 fbsub |
| 2286 | a = fbmul 0 2 |
| 2287 | e = sub e 1 |
| 2288 | end |
| 2289 | put fg_m 0 q |
| 2290 | put fg_e 0 add e 1 |
| 2291 | put fg_stk 0 fbmul 0 1 |
| 2292 | ret fpack |
| 2293 | end |
| 2294 | |
| 2295 | note fsizeof: sizeof T, or sizeof S for a struct: bytes. foffset: offsetof S f: the field's byte offset |
| 2296 | note in the struct's 8-byte-cell layout. Both are compile-time constants of type ulong. |
| 2297 | fn fsizeof dst ulong to void |
| 2298 | sid = peek_struct |
| 2299 | if ne sid 0 |
| 2300 | si = sub sid 1 |
| 2301 | n = ulong get st_cells si |
| 2302 | vdone 3 mul n 8 5 |
| 2303 | ret |
| 2304 | end |
| 2305 | t = typeword |
| 2306 | if ge t 64 |
| 2307 | fail 7 |
| 2308 | end |
| 2309 | v = shl 1 tlog t |
| 2310 | vdone 3 v 5 |
| 2311 | end |
| 2312 | |
| 2313 | fn foffset dst ulong to void |
| 2314 | tok |
| 2315 | if ne get tk 0 1 |
| 2316 | fail 16 |
| 2317 | end |
| 2318 | if gt get tl 0 8 |
| 2319 | fail 13 |
| 2320 | end |
| 2321 | sid = findstruct get tw 0 |
| 2322 | if eq sid 0 |
| 2323 | unkfail 3 |
| 2324 | end |
| 2325 | tok |
| 2326 | if ne get tk 0 1 |
| 2327 | fail 16 |
| 2328 | end |
| 2329 | if gt get tl 0 8 |
| 2330 | fail 13 |
| 2331 | end |
| 2332 | f = findfield sub sid 1 get tw 0 |
| 2333 | if eq f 0 |
| 2334 | fail 3 |
| 2335 | end |
| 2336 | off = ulong get sf_off sub f 1 |
| 2337 | vdone 3 mul off 8 5 |
| 2338 | end |
| 2339 | |
| 2340 | note fspan: a deferred literal stored as pos*16777216+len. Input stays below 2^23 bytes, so neither part |
| 2341 | note overflows its field; the old pos*64+len read a literal of 64 or more characters from the wrong span (#965). |
| 2342 | fn fspan ty ulong packed ulong to ulong |
| 2343 | fparse div packed 16777216 rem packed 16777216 |
| 2344 | ret fbits ty |
| 2345 | end |
| 2346 | |
| 2347 | fn isfloat t ulong to ulong |
| 2348 | if or eq t 10 eq t 11 |
| 2349 | ret 1 |
| 2350 | end |
| 2351 | ret 0 |
| 2352 | end |
| 2353 | |
| 2354 | note ======== om4's small tables, as functions ======== |
| 2355 | note twid: width in bits by type 0..9 (bool 1; uchar ushort uint ulong; byte short int long) |
| 2356 | fn twid t ulong to ulong |
| 2357 | if eq t 13 |
| 2358 | ret 64 |
| 2359 | end |
| 2360 | if eq t 10 |
| 2361 | ret 32 |
| 2362 | end |
| 2363 | if eq t 11 |
| 2364 | ret 64 |
| 2365 | end |
| 2366 | if eq t 1 |
| 2367 | ret 1 |
| 2368 | end |
| 2369 | if or eq t 2 eq t 6 |
| 2370 | ret 8 |
| 2371 | end |
| 2372 | if or eq t 3 eq t 7 |
| 2373 | ret 16 |
| 2374 | end |
| 2375 | if or eq t 4 eq t 8 |
| 2376 | ret 32 |
| 2377 | end |
| 2378 | if or eq t 5 eq t 9 |
| 2379 | ret 64 |
| 2380 | end |
| 2381 | ret 0 |
| 2382 | end |
| 2383 | |
| 2384 | note tlog: log2 of the element size by type |
| 2385 | fn tlog t ulong to ulong |
| 2386 | if eq t 13 |
| 2387 | ret 3 |
| 2388 | end |
| 2389 | if eq t 10 |
| 2390 | ret 2 |
| 2391 | end |
| 2392 | if eq t 11 |
| 2393 | ret 3 |
| 2394 | end |
| 2395 | if or eq t 3 eq t 7 |
| 2396 | ret 1 |
| 2397 | end |
| 2398 | if or eq t 4 eq t 8 |
| 2399 | ret 2 |
| 2400 | end |
| 2401 | if or eq t 5 eq t 9 |
| 2402 | ret 3 |
| 2403 | end |
| 2404 | ret 0 |
| 2405 | end |
| 2406 | |
| 2407 | note regidx: the pool index of register r (the inverse of poolc; 255 for x7 and x16) |
| 2408 | fn regidx r ulong to ulong |
| 2409 | if lt r 7 |
| 2410 | ret r |
| 2411 | end |
| 2412 | if eq r 7 |
| 2413 | ret 255 |
| 2414 | end |
| 2415 | if lt r 16 |
| 2416 | ret sub r 1 |
| 2417 | end |
| 2418 | if eq r 16 |
| 2419 | ret 255 |
| 2420 | end |
| 2421 | ret 15 |
| 2422 | end |
| 2423 | |
| 2424 | 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, |
| 2425 | 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. |
| 2426 | fn conds i ulong to ulong |
| 2427 | if lt i 2 |
| 2428 | ret 0 |
| 2429 | end |
| 2430 | if lt i 4 |
| 2431 | ret 1 |
| 2432 | end |
| 2433 | if eq i 4 |
| 2434 | ret 3 |
| 2435 | end |
| 2436 | if eq i 5 |
| 2437 | ret 11 |
| 2438 | end |
| 2439 | if eq i 6 |
| 2440 | ret 9 |
| 2441 | end |
| 2442 | if eq i 7 |
| 2443 | ret 13 |
| 2444 | end |
| 2445 | if eq i 8 |
| 2446 | ret 8 |
| 2447 | end |
| 2448 | if eq i 9 |
| 2449 | ret 12 |
| 2450 | end |
| 2451 | if eq i 10 |
| 2452 | ret 2 |
| 2453 | end |
| 2454 | ret 10 |
| 2455 | end |
| 2456 | |
| 2457 | note ldop / stop: register-offset load / store by element type (om4 LDOP, STOP tables) |
| 2458 | fn ldop t ulong to ulong |
| 2459 | note LDRB 0x38606800, LDRH 0x78607800, LDR w 0xb8607800, LDR x 0xf8607800, LDRSB 0x38a06800, |
| 2460 | note LDRSH 0x78a07800, LDRSW 0xb8a07800 |
| 2461 | if eq t 2 |
| 2462 | ret 945842176 |
| 2463 | end |
| 2464 | if eq t 3 |
| 2465 | ret 2019588096 |
| 2466 | end |
| 2467 | if eq t 4 |
| 2468 | ret 3093329920 |
| 2469 | end |
| 2470 | if or or eq t 5 eq t 9 eq t 13 |
| 2471 | ret 4167071744 |
| 2472 | end |
| 2473 | if eq t 10 |
| 2474 | ret 3093329920 |
| 2475 | end |
| 2476 | if eq t 11 |
| 2477 | ret 4167071744 |
| 2478 | end |
| 2479 | if eq t 6 |
| 2480 | ret 950036480 |
| 2481 | end |
| 2482 | if eq t 7 |
| 2483 | ret 2023782400 |
| 2484 | end |
| 2485 | if eq t 8 |
| 2486 | ret 3097524224 |
| 2487 | end |
| 2488 | ret 0 |
| 2489 | end |
| 2490 | |
| 2491 | fn stop t ulong to ulong |
| 2492 | note STRB 0x38206800, STRH 0x78207800, STR w 0xb8207800, STR x 0xf8207800 |
| 2493 | if or eq t 2 eq t 6 |
| 2494 | ret 941647872 |
| 2495 | end |
| 2496 | if or eq t 3 eq t 7 |
| 2497 | ret 2015393792 |
| 2498 | end |
| 2499 | if or eq t 4 eq t 8 |
| 2500 | ret 3089135616 |
| 2501 | end |
| 2502 | if or or eq t 5 eq t 9 eq t 13 |
| 2503 | ret 4162877440 |
| 2504 | end |
| 2505 | if eq t 10 |
| 2506 | ret 3089135616 |
| 2507 | end |
| 2508 | if eq t 11 |
| 2509 | ret 4162877440 |
| 2510 | end |
| 2511 | ret 0 |
| 2512 | end |
| 2513 | |
| 2514 | note ---- trap list (8192 sites per function): output offset of the branch, trap code ---- |
| 2515 | global tsite ulong 8192 |
| 2516 | global tcode ulong 8192 |
| 2517 | global nt ulong 1 |
| 2518 | note ---- block stack (512): kind (1 if, 2 else, 3 while, 4 for), branch to patch, loop head, loop |
| 2519 | note register, its type, names and held pool slots to restore at end, then-part ended (for else) ---- |
| 2520 | global bkind ulong 512 |
| 2521 | global bbr ulong 512 |
| 2522 | global bhead ulong 512 |
| 2523 | global breg ulong 512 |
| 2524 | global btyp ulong 512 |
| 2525 | global bnames ulong 512 |
| 2526 | global bheld ulong 512 |
| 2527 | global bdead ulong 512 |
| 2528 | global nb ulong 1 |
| 2529 | global curfn ulong 1 |
| 2530 | note ---- break fixups (1024): output offset of the branch, block index of the loop it leaves ---- |
| 2531 | global brkpos ulong 1024 |
| 2532 | global brkblk ulong 1024 |
| 2533 | global nbrk ulong 1 |
| 2534 | global cpos ulong 1024 |
| 2535 | global cblk ulong 1024 |
| 2536 | global ncont ulong 1 |
| 2537 | fn dcat_w code ulong to void |
| 2538 | if or or eq code 4 eq code 6 eq code 16 |
| 2539 | mputw 9104236865280339 7 |
| 2540 | ret |
| 2541 | end |
| 2542 | if or or eq code 7 eq code 11 eq code 19 |
| 2543 | mputw 138601847124 5 |
| 2544 | ret |
| 2545 | end |
| 2546 | if or eq code 17 eq code 18 |
| 2547 | mputw 138903768134 5 |
| 2548 | ret |
| 2549 | end |
| 2550 | if or or eq code 3 eq code 10 eq code 13 |
| 2551 | mputw 138601644366 5 |
| 2552 | ret |
| 2553 | end |
| 2554 | if or or or eq code 12 eq code 14 eq code 23 eq code 24 |
| 2555 | mputw 6436850320626696515 8 |
| 2556 | mputb 32 |
| 2557 | ret |
| 2558 | end |
| 2559 | if or eq code 8 eq code 21 |
| 2560 | mputw 35481921143122 6 |
| 2561 | ret |
| 2562 | end |
| 2563 | if or or or eq code 27 eq code 28 eq code 29 eq code 30 |
| 2564 | mputw 6071768544483102531 8 |
| 2565 | mputb 32 |
| 2566 | ret |
| 2567 | end |
| 2568 | mputw 9104236865280339 7 |
| 2569 | end |
| 2570 | |
| 2571 | fn dty_w t ulong to void |
| 2572 | if eq t 1 |
| 2573 | mputw 1819242338 4 |
| 2574 | ret |
| 2575 | end |
| 2576 | if eq t 2 |
| 2577 | mputw 491260502901 5 |
| 2578 | ret |
| 2579 | end |
| 2580 | if eq t 3 |
| 2581 | mputw 128034844210037 6 |
| 2582 | ret |
| 2583 | end |
| 2584 | if eq t 4 |
| 2585 | mputw 1953393013 4 |
| 2586 | ret |
| 2587 | end |
| 2588 | if eq t 5 |
| 2589 | mputw 444234427509 5 |
| 2590 | ret |
| 2591 | end |
| 2592 | if eq t 6 |
| 2593 | mputw 1702132066 4 |
| 2594 | ret |
| 2595 | end |
| 2596 | if eq t 7 |
| 2597 | mputw 500136110195 5 |
| 2598 | ret |
| 2599 | end |
| 2600 | if eq t 8 |
| 2601 | mputw 7630441 3 |
| 2602 | ret |
| 2603 | end |
| 2604 | if eq t 9 |
| 2605 | mputw 1735290732 4 |
| 2606 | ret |
| 2607 | end |
| 2608 | if eq t 10 |
| 2609 | mputw 3289958 3 |
| 2610 | ret |
| 2611 | end |
| 2612 | if eq t 11 |
| 2613 | mputw 3421798 3 |
| 2614 | ret |
| 2615 | end |
| 2616 | if eq t 12 |
| 2617 | mputw 1684631414 4 |
| 2618 | ret |
| 2619 | end |
| 2620 | if eq t 13 |
| 2621 | mputb 113 |
| 2622 | mputb 116 |
| 2623 | mputb 121 |
| 2624 | ret |
| 2625 | end |
| 2626 | mputw 2003134838 4 |
| 2627 | end |
| 2628 | |
| 2629 | fn dname_kind i ulong to void |
| 2630 | k = ulong get nm_kind i |
| 2631 | if eq k 4 |
| 2632 | mputw 119165519096935 6 |
| 2633 | ret |
| 2634 | end |
| 2635 | if eq k 5 |
| 2636 | mputw 1954047348 4 |
| 2637 | ret |
| 2638 | end |
| 2639 | if eq k 9 |
| 2640 | mputw 500152823651 5 |
| 2641 | ret |
| 2642 | end |
| 2643 | if or eq k 2 eq k 8 |
| 2644 | mputw 2003134838 4 |
| 2645 | ret |
| 2646 | end |
| 2647 | if or eq k 3 eq k 7 |
| 2648 | mputw 1953064037 4 |
| 2649 | ret |
| 2650 | end |
| 2651 | if ne get curfn 0 0 |
| 2652 | f = sub get curfn 0 1 |
| 2653 | np = ulong get fn_np f |
| 2654 | endp = add get nglob 0 np |
| 2655 | if and ge i get nglob 0 lt i endp |
| 2656 | mputw 469786321264 5 |
| 2657 | ret |
| 2658 | end |
| 2659 | end |
| 2660 | mputw 465490374508 5 |
| 2661 | end |
| 2662 | |
| 2663 | fn mput_name w ulong to void |
| 2664 | x = w |
| 2665 | go = true |
| 2666 | while go |
| 2667 | if eq x 0 |
| 2668 | go = false |
| 2669 | else |
| 2670 | b = and x 255 |
| 2671 | if eq b 0 |
| 2672 | go = false |
| 2673 | else |
| 2674 | mputb uchar b |
| 2675 | x = shr x 8 |
| 2676 | end |
| 2677 | end |
| 2678 | end |
| 2679 | end |
| 2680 | |
| 2681 | |
| 2682 | fn mput_tok a ulong b ulong to void |
| 2683 | if eq a b |
| 2684 | if eq get tk 0 3 |
| 2685 | mputw 6713189 3 |
| 2686 | ret |
| 2687 | end |
| 2688 | mputb 45 |
| 2689 | ret |
| 2690 | end |
| 2691 | i = a |
| 2692 | while and lt i b lt sub i a 16 |
| 2693 | c = ulong get inp i |
| 2694 | if and gt c 32 lt c 127 |
| 2695 | mputb uchar c |
| 2696 | else |
| 2697 | mputh c |
| 2698 | end |
| 2699 | i = add i 1 |
| 2700 | end |
| 2701 | end |
| 2702 | |
| 2703 | fn diagrec code ulong to void |
| 2704 | put mc 0 0 |
| 2705 | mputw 7594244768023276911 8 |
| 2706 | mputw 11207551510369 6 |
| 2707 | if eq get om2 0 0 |
| 2708 | mputw 3239279 3 |
| 2709 | mputb 32 |
| 2710 | else |
| 2711 | mputw 3304815 3 |
| 2712 | mputb 32 |
| 2713 | end |
| 2714 | dcat_w code |
| 2715 | a = get tka 0 |
| 2716 | b = get tkb 0 |
| 2717 | if le b a |
| 2718 | b = a |
| 2719 | if gt get cur 0 a |
| 2720 | b = get cur 0 |
| 2721 | end |
| 2722 | end |
| 2723 | if gt b get inlen 0 |
| 2724 | b = get inlen 0 |
| 2725 | end |
| 2726 | sa = a |
| 2727 | sb = b |
| 2728 | if ge sa get sbase 0 |
| 2729 | sa = sub sa get sbase 0 |
| 2730 | else |
| 2731 | sa = ulong 0 |
| 2732 | end |
| 2733 | if ge sb get sbase 0 |
| 2734 | sb = sub sb get sbase 0 |
| 2735 | else |
| 2736 | sb = ulong 0 |
| 2737 | end |
| 2738 | mputw 263844884595 5 |
| 2739 | mputn sa |
| 2740 | mputb 45 |
| 2741 | mputn sb |
| 2742 | mputb 32 |
| 2743 | s = get dsev 0 |
| 2744 | if eq s 0 |
| 2745 | if eq get tk 0 3 |
| 2746 | s = ulong 1 |
| 2747 | end |
| 2748 | if and eq code 22 ge get cur 0 get inlen 0 |
| 2749 | s = ulong 1 |
| 2750 | end |
| 2751 | end |
| 2752 | if eq s 1 |
| 2753 | mputw 4993454379819552329 8 |
| 2754 | mputw 2114900 3 |
| 2755 | else |
| 2756 | if eq s 2 |
| 2757 | mputw 2327894055524716117 8 |
| 2758 | else |
| 2759 | mputw 35511885252934 6 |
| 2760 | end |
| 2761 | end |
| 2762 | note Repairability is independent of prefix finality; only capacity failures are unrepairable. |
| 2763 | if or or or eq code 12 eq code 14 eq code 23 eq code 24 |
| 2764 | mputw 5929342197426179669 8 |
| 2765 | mputw 138601579073 4 |
| 2766 | else |
| 2767 | mputw 4774187554571306322 8 |
| 2768 | mputw 2114892 2 |
| 2769 | end |
| 2770 | mputw 67505686012704 6 |
| 2771 | mputn code |
| 2772 | mputw 67505853393952 6 |
| 2773 | hl = get line 0 |
| 2774 | if ne get chkmode 0 0 |
| 2775 | if gt hl get chkln 0 |
| 2776 | hl = sub hl get chkln 0 |
| 2777 | else |
| 2778 | hl = ulong 1 |
| 2779 | end |
| 2780 | end |
| 2781 | mputn hl |
| 2782 | mputw 4428273620941825312 8 |
| 2783 | dexp_w code |
| 2784 | mputw 17280399158765088 7 |
| 2785 | mput_tok a b |
| 2786 | mputb 10 |
| 2787 | mflush |
| 2788 | end |
| 2789 | |
| 2790 | fn emit_query to void |
| 2791 | put mc 0 0 |
| 2792 | mputw 8462595071175650671 8 |
| 2793 | mputw 2869133187838565 7 |
| 2794 | mputw 9071406607197043 7 |
| 2795 | if eq get curfn 0 0 |
| 2796 | mputw 7810779306727075700 8 |
| 2797 | mputb 10 |
| 2798 | mputw 7166760226508402531 8 |
| 2799 | mputw 7142830393916027764 8 |
| 2800 | mputw 8028905624785088111 8 |
| 2801 | mputw 8392569455039504738 8 |
| 2802 | mputw 2338603462594687776 8 |
| 2803 | mputw 44651802478 5 |
| 2804 | else |
| 2805 | mputw 7957695015192261990 8 |
| 2806 | mputb 10 |
| 2807 | mputw 7166760226508402531 8 |
| 2808 | mputw 2338605647353508724 8 |
| 2809 | mputw 7308332192711599721 8 |
| 2810 | mputw 7021802451731703328 8 |
| 2811 | mputw 8079585727842951280 8 |
| 2812 | mputw 9117624560546933 7 |
| 2813 | mputw 1702129518 4 |
| 2814 | in_loop = ulong 0 |
| 2815 | j = get nb 0 |
| 2816 | while and eq in_loop 0 gt j 0 |
| 2817 | j = sub j 1 |
| 2818 | if and ge get bkind j 3 le get bkind j 4 |
| 2819 | in_loop = ulong 1 |
| 2820 | end |
| 2821 | end |
| 2822 | if ne in_loop 0 |
| 2823 | mputw 7142827075067601440 8 |
| 2824 | mputw 749134030103146095 8 |
| 2825 | else |
| 2826 | mputb 10 |
| 2827 | end |
| 2828 | end |
| 2829 | mputw 2879017064423790 7 |
| 2830 | mflush |
| 2831 | i = ulong 0 |
| 2832 | while lt i get nn 0 |
| 2833 | if ne get nm_name i 0 |
| 2834 | mput_name get nm_name i |
| 2835 | mputb 32 |
| 2836 | dty_w ulong get nm_type i |
| 2837 | mputb 32 |
| 2838 | dname_kind i |
| 2839 | mputb 10 |
| 2840 | mflush |
| 2841 | end |
| 2842 | i = add i 1 |
| 2843 | end |
| 2844 | mputw 7957695015192261990 8 |
| 2845 | mputw 670323 3 |
| 2846 | mflush |
| 2847 | f = ulong 0 |
| 2848 | while lt f get nf 0 |
| 2849 | mputw 2125414 3 |
| 2850 | note Single caller: spell the function name here rather than spend a bootstrap function slot. |
| 2851 | o = get fn_off f |
| 2852 | l = get fn_nmlen f |
| 2853 | if and ne o 0 gt l 0 |
| 2854 | i = ulong 0 |
| 2855 | while lt i l |
| 2856 | mputb get inp add o i |
| 2857 | i = add i 1 |
| 2858 | end |
| 2859 | else |
| 2860 | mput_name get fn_name f |
| 2861 | end |
| 2862 | mputw 544175136 4 |
| 2863 | dty_w ulong get fn_ret f |
| 2864 | np = ulong get fn_np f |
| 2865 | p = ulong 0 |
| 2866 | while lt p np |
| 2867 | mputb 32 |
| 2868 | dty_w ulong get fn_pt add mul f 6 p |
| 2869 | p = add p 1 |
| 2870 | end |
| 2871 | mputb 10 |
| 2872 | mflush |
| 2873 | f = add f 1 |
| 2874 | end |
| 2875 | mflush |
| 2876 | exit int 0 |
| 2877 | end |
| 2878 | note ======== names and functions ======== |
| 2879 | note findname: packed name -> its index + 1 among the names in scope (0 none). om4 FINDNAME. |
| 2880 | fn findname w ulong to ulong |
| 2881 | i = ulong 0 |
| 2882 | n = get nn 0 |
| 2883 | if ne get cpure 0 0 |
| 2884 | n = get clim 0 |
| 2885 | end |
| 2886 | if eq i get nglob 0 |
| 2887 | if gt get nmlo 0 i |
| 2888 | i = get nmlo 0 |
| 2889 | end |
| 2890 | end |
| 2891 | while lt i n |
| 2892 | if eq get nm_name i w |
| 2893 | ret add i 1 |
| 2894 | end |
| 2895 | i = add i 1 |
| 2896 | if eq i get nglob 0 |
| 2897 | if gt get nmlo 0 i |
| 2898 | i = get nmlo 0 |
| 2899 | end |
| 2900 | end |
| 2901 | end |
| 2902 | ret 0 |
| 2903 | end |
| 2904 | |
| 2905 | note findfn: packed name w (first 8 bytes), length l (any value up to 8 for a short name), start s in the |
| 2906 | note input (read only for a name over 8 bytes) -> function index + 1 (0 none). om4 FINDFN. |
| 2907 | fn findfn w ulong l ulong s ulong to ulong |
| 2908 | j = ulong 0 |
| 2909 | while lt j get nf 0 |
| 2910 | if eq get fn_name j w |
| 2911 | fl = get fn_nmlen j |
| 2912 | if le l 8 |
| 2913 | if le fl 8 |
| 2914 | ret add j 1 |
| 2915 | end |
| 2916 | else |
| 2917 | if eq fl l |
| 2918 | o = get fn_off j |
| 2919 | k = ulong 8 |
| 2920 | same = true |
| 2921 | while and same lt k l |
| 2922 | a = get inp add o k |
| 2923 | if ne a get inp add s k |
| 2924 | same = false |
| 2925 | end |
| 2926 | k = add k 1 |
| 2927 | end |
| 2928 | if same |
| 2929 | ret add j 1 |
| 2930 | end |
| 2931 | end |
| 2932 | end |
| 2933 | end |
| 2934 | j = add j 1 |
| 2935 | end |
| 2936 | ret 0 |
| 2937 | end |
| 2938 | |
| 2939 | note newname: the name must not be in use (a name in scope when 8 bytes or fewer, or a function): error 10 |
| 2940 | fn newname w ulong l ulong s ulong to void |
| 2941 | if ne findstruct w 0 |
| 2942 | fail 10 |
| 2943 | end |
| 2944 | if le l 8 |
| 2945 | if ne findname w 0 |
| 2946 | fail 10 |
| 2947 | end |
| 2948 | if ne findlay w 0 |
| 2949 | fail 10 |
| 2950 | end |
| 2951 | if ne findab w 0 |
| 2952 | fail 10 |
| 2953 | end |
| 2954 | end |
| 2955 | if ne findfn w l s 0 |
| 2956 | fail 10 |
| 2957 | end |
| 2958 | end |
| 2959 | |
| 2960 | note addname: packed name, register, type, length, kind, address. om4 ADDNAME. |
| 2961 | fn addname w ulong r ulong t ulong ln ulong k ulong a ulong to void |
| 2962 | n = get nn 0 |
| 2963 | if ge n 8192 |
| 2964 | fail 14 |
| 2965 | end |
| 2966 | put nm_name n w |
| 2967 | put nm_reg n uchar r |
| 2968 | put nm_type n uchar t |
| 2969 | put nm_len n ln |
| 2970 | put nm_kind n uchar k |
| 2971 | put nm_addr n a |
| 2972 | put nm_fv n 0 |
| 2973 | put nm_lay n 0 |
| 2974 | put nm_fr n 0 |
| 2975 | put nm_lr n 0 |
| 2976 | put nn 0 add n 1 |
| 2977 | end |
| 2978 | |
| 2979 | note ======== registers and words ======== |
| 2980 | note alloc: the next free register of the pool (after the parameters); error 12 when none is left |
| 2981 | fn alloc to ulong |
| 2982 | i = add get npar 0 get nslot 0 |
| 2983 | if ge i 16 |
| 2984 | fail 12 |
| 2985 | end |
| 2986 | put vsl i 0 |
| 2987 | put nslot 0 add get nslot 0 1 |
| 2988 | ret poolc i |
| 2989 | end |
| 2990 | |
| 2991 | note destreg: d, or a new temporary when d is 255 |
| 2992 | fn destreg d ulong to ulong |
| 2993 | if eq d 255 |
| 2994 | ret alloc |
| 2995 | end |
| 2996 | ret d |
| 2997 | end |
| 2998 | |
| 2999 | note e3: emit op | d | n << 5 | m << 16 |
| 3000 | fn e3 op ulong d ulong n ulong m ulong to void |
| 3001 | emit or or or op d shl n 5 shl m 16 |
| 3002 | end |
| 3003 | |
| 3004 | note trapsite: note the place and code of a branch to the trap stub, then emit it. trapc: B.cond, as om4. |
| 3005 | fn trapsite w ulong code ulong to void |
| 3006 | n = get nt 0 |
| 3007 | if ge n 8192 |
| 3008 | fail 14 |
| 3009 | end |
| 3010 | put tsite n get oc 0 |
| 3011 | put tcode n code |
| 3012 | put nt 0 add n 1 |
| 3013 | emit w |
| 3014 | if eq get om2m 0 1 |
| 3015 | siterec |
| 3016 | end |
| 3017 | end |
| 3018 | |
| 3019 | fn trapc cc ulong code ulong to void |
| 3020 | if ne get xtarget 0 0 |
| 3021 | xtrap cc code |
| 3022 | ret |
| 3023 | end |
| 3024 | trapsite or 1409286144 cc code |
| 3025 | end |
| 3026 | |
| 3027 | fn rdword at ulong to ulong |
| 3028 | a = ulong get out at |
| 3029 | b = shl ulong get out add at 1 8 |
| 3030 | c = shl ulong get out add at 2 16 |
| 3031 | d = shl ulong get out add at 3 24 |
| 3032 | ret or or or a b c d |
| 3033 | end |
| 3034 | |
| 3035 | fn wrword at ulong w ulong to void |
| 3036 | put out at uchar and w 255 |
| 3037 | put out add at 1 uchar and shr w 8 255 |
| 3038 | put out add at 2 uchar and shr w 16 255 |
| 3039 | put out add at 3 uchar and shr w 24 255 |
| 3040 | end |
| 3041 | |
| 3042 | note bdisp: the checked word distance from a branch at `at` to `target` for its signed w-bit word field: |
| 3043 | note w 19 for B.cond / CBZ / CBNZ (C6.2.34, C6.2.78, C6.2.77), w 26 for B (C6.2.35) and BL. The |
| 3044 | note target must be word aligned and at most 2^(w-1) - 1 words forward or 2^(w-1) words back (w 19: 1048572 |
| 3045 | note bytes forward, 1048576 back; w 26: 134217724 forward, 134217728 back), else error 24 before any |
| 3046 | note artifact is accepted. Returns the distance masked to w bits. |
| 3047 | fn bdisp at ulong target ulong w ulong to ulong |
| 3048 | diff = sub target at |
| 3049 | if ne and diff 3 0 |
| 3050 | fail 24 |
| 3051 | end |
| 3052 | span = shl ulong 1 add w 1 |
| 3053 | if and gt diff sub span 4 lt diff sub ulong 0 span |
| 3054 | fail 24 |
| 3055 | end |
| 3056 | ret and shr diff 2 sub shl ulong 1 w 1 |
| 3057 | end |
| 3058 | |
| 3059 | note patch19: the word distance from a B.cond / CBZ / CBNZ at `at` to `target`, into bits 5..23 |
| 3060 | fn patch19 at ulong target ulong to void |
| 3061 | if ne get xtarget 0 0 |
| 3062 | xpatch at target |
| 3063 | if eq target get oc 0 |
| 3064 | put tgoc 0 target |
| 3065 | end |
| 3066 | ret |
| 3067 | end |
| 3068 | d = bdisp at target 19 |
| 3069 | wrword at or rdword at shl d 5 |
| 3070 | if eq target get oc 0 |
| 3071 | put tgoc 0 target |
| 3072 | end |
| 3073 | end |
| 3074 | |
| 3075 | note patch26: the word distance from a B at `at` to `target`, into bits 0..25, checked by bdisp. The AArch64 |
| 3076 | note output stops at 8 MiB = 2^23 bytes (emit, error 14), inside the 2^27-byte reach, so no legal program |
| 3077 | note reaches error 24 here; the check keeps a wrong B from ever being written if that ceiling changes. |
| 3078 | fn patch26 at ulong target ulong to void |
| 3079 | if ne get xtarget 0 0 |
| 3080 | xpatch at target |
| 3081 | if eq target get oc 0 |
| 3082 | put tgoc 0 target |
| 3083 | end |
| 3084 | ret |
| 3085 | end |
| 3086 | d = bdisp at target 26 |
| 3087 | wrword at or rdword at d |
| 3088 | if eq target get oc 0 |
| 3089 | put tgoc 0 target |
| 3090 | end |
| 3091 | end |
| 3092 | |
| 3093 | note back: emit B to an earlier place (C6.2.35) |
| 3094 | fn back addr ulong to void |
| 3095 | if ne get xtarget 0 0 |
| 3096 | p = xbranch 14 |
| 3097 | xpatch p addr |
| 3098 | ret |
| 3099 | end |
| 3100 | emit or 335544320 bdisp get oc 0 addr 26 |
| 3101 | end |
| 3102 | |
| 3103 | note matconst: put a 64-bit value in register r: MOVZ (C6.2.285) or, for a value with the top bit set, |
| 3104 | note MOVN (C6.2.284) with the first halfword that differs from the fill, then MOVK (C6.2.283) for each |
| 3105 | note other such halfword. om4 MATCONST. |
| 3106 | fn matconst r ulong v ulong to void |
| 3107 | if ne get xtarget 0 0 |
| 3108 | ximm 0 v |
| 3109 | xstore 0 r |
| 3110 | ret |
| 3111 | end |
| 3112 | fill = ulong 0 |
| 3113 | mop = ulong 3531603968 |
| 3114 | if ne shr v 63 0 |
| 3115 | fill = ulong 65535 |
| 3116 | mop = ulong 2457862144 |
| 3117 | end |
| 3118 | started = false |
| 3119 | hw = ulong 0 |
| 3120 | while lt hw 4 |
| 3121 | h = and shr v shl hw 4 65535 |
| 3122 | if ne h fill |
| 3123 | if started |
| 3124 | emit or or or 4068474880 shl h 5 shl hw 21 r |
| 3125 | else |
| 3126 | emit or or or mop shl xor h fill 5 shl hw 21 r |
| 3127 | started = true |
| 3128 | end |
| 3129 | end |
| 3130 | hw = add hw 1 |
| 3131 | end |
| 3132 | if not started |
| 3133 | emit or mop r |
| 3134 | end |
| 3135 | end |
| 3136 | |
| 3137 | note canon: u8/u16/u32 UBFM Xr, Xr, #0, #w-1 (C6.2.487); i8/i16/i32 SBFM (C6.2.355); else nothing |
| 3138 | fn canon r ulong t ulong to void |
| 3139 | canonto r r t |
| 3140 | end |
| 3141 | |
| 3142 | note canonto: canon of Xn written to Xd (the same UBFM / SBFM with Rd = d, Rn = n) |
| 3143 | fn canonto d ulong n ulong t ulong to void |
| 3144 | if ne get xtarget 0 0 |
| 3145 | xload 0 n |
| 3146 | xcanrax t |
| 3147 | xstore 0 d |
| 3148 | ret |
| 3149 | end |
| 3150 | if lt t 2 |
| 3151 | ret |
| 3152 | end |
| 3153 | if eq t 5 |
| 3154 | ret |
| 3155 | end |
| 3156 | if eq t 9 |
| 3157 | ret |
| 3158 | end |
| 3159 | base = ulong 3544186880 |
| 3160 | if gt t 5 |
| 3161 | base = ulong 2470445056 |
| 3162 | end |
| 3163 | emit or or or base shl sub twid t 1 10 d shl n 5 |
| 3164 | end |
| 3165 | |
| 3166 | note chkext: CMP Xr, Wr, SXTB/SXTH/SXTW (SUBS extended, C6.2.463), then B.NE trap code |
| 3167 | fn chkext r ulong t ulong code ulong to void |
| 3168 | if ne get xtarget 0 0 |
| 3169 | xext r t code |
| 3170 | ret |
| 3171 | end |
| 3172 | emit or or or 3944742943 shl sub t 2 13 shl r 16 shl r 5 |
| 3173 | trapc 1 code |
| 3174 | end |
| 3175 | |
| 3176 | note range: error 8 unless v is a value of type t; big = the number was written as 2^63 or more |
| 3177 | fn range v ulong t ulong big ulong to void |
| 3178 | w = twid t |
| 3179 | if eq w 64 |
| 3180 | if eq t 9 |
| 3181 | if ne big 0 |
| 3182 | fail 8 |
| 3183 | end |
| 3184 | ret |
| 3185 | end |
| 3186 | if ne big 0 |
| 3187 | ret |
| 3188 | end |
| 3189 | if ne shr v 63 0 |
| 3190 | fail 8 |
| 3191 | end |
| 3192 | ret |
| 3193 | end |
| 3194 | if ne big 0 |
| 3195 | fail 8 |
| 3196 | end |
| 3197 | lim = shl ulong 1 w |
| 3198 | if lt t 6 |
| 3199 | if ge v lim |
| 3200 | fail 8 |
| 3201 | end |
| 3202 | ret |
| 3203 | end |
| 3204 | half = shr lim 1 |
| 3205 | if ge add v half lim |
| 3206 | fail 8 |
| 3207 | end |
| 3208 | end |
| 3209 | |
| 3210 | note cset: CSET Xr, cond = CSINC Xr, XZR, XZR, opposite cond (C6.2.141) |
| 3211 | fn cset r ulong cc ulong to void |
| 3212 | if ne get xtarget 0 0 |
| 3213 | xb 15 add 144 xcc cc 192 |
| 3214 | xb 72 15 182 |
| 3215 | emitb 192 |
| 3216 | xstore 0 r |
| 3217 | ret |
| 3218 | end |
| 3219 | emit or or 2594113504 r shl xor cc 1 12 |
| 3220 | end |
| 3221 | |
| 3222 | note force: put a value (kind 1 register, 3 number, 4 flags, 9 float in a twin: FMOV Xr, Dn) in register |
| 3223 | note r; a bare number is error 11 |
| 3224 | fn force k ulong v ulong t ulong r ulong to void |
| 3225 | if ne get xtarget 0 0 |
| 3226 | if eq k 1 |
| 3227 | xload 0 v |
| 3228 | xstore 0 r |
| 3229 | ret |
| 3230 | end |
| 3231 | end |
| 3232 | if eq k 1 |
| 3233 | if ne v r |
| 3234 | emit or or 2852127712 r shl v 16 |
| 3235 | end |
| 3236 | ret |
| 3237 | end |
| 3238 | if or eq k 3 eq k 7 |
| 3239 | matconst r v |
| 3240 | ret |
| 3241 | end |
| 3242 | if eq k 4 |
| 3243 | cset r v |
| 3244 | ret |
| 3245 | end |
| 3246 | if eq k 9 |
| 3247 | fv2x t vtw v r |
| 3248 | ret |
| 3249 | end |
| 3250 | fail 11 |
| 3251 | end |
| 3252 | |
| 3253 | note matreg: a register holding the value |
| 3254 | fn matreg k ulong v ulong t ulong to ulong |
| 3255 | if eq k 1 |
| 3256 | ret v |
| 3257 | end |
| 3258 | if eq k 9 |
| 3259 | fv2x t vtw v v |
| 3260 | ret v |
| 3261 | end |
| 3262 | r = alloc |
| 3263 | force k v t r |
| 3264 | ret r |
| 3265 | end |
| 3266 | |
| 3267 | 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 |
| 3268 | note high 12 bits LSL 12; nothing for a zero part |
| 3269 | fn spop base ulong bytes ulong to void |
| 3270 | lo = and bytes 4095 |
| 3271 | if ne lo 0 |
| 3272 | emit or or base 1023 shl lo 10 |
| 3273 | end |
| 3274 | hi = and shr bytes 12 4095 |
| 3275 | if ne hi 0 |
| 3276 | emit or or base 4195327 shl hi 10 |
| 3277 | end |
| 3278 | end |
| 3279 | |
| 3280 | fn spadd bytes ulong to void |
| 3281 | if ne get xtarget 0 0 |
| 3282 | xsp 0 bytes |
| 3283 | ret |
| 3284 | end |
| 3285 | spop 2432696320 bytes |
| 3286 | end |
| 3287 | |
| 3288 | fn spsub bytes ulong to void |
| 3289 | if ne get xtarget 0 0 |
| 3290 | xsp 1 bytes |
| 3291 | ret |
| 3292 | end |
| 3293 | spop 3506438144 bytes |
| 3294 | end |
| 3295 | |
| 3296 | note stkchk: program mode only: CMP SP, X28 (C6.2.463); B.LO trap 6 |
| 3297 | fn stkchk to void |
| 3298 | if ne get xtarget 0 0 |
| 3299 | ret |
| 3300 | end |
| 3301 | if ne get progmode 0 0 |
| 3302 | emit 3946603519 |
| 3303 | trapc 3 6 |
| 3304 | end |
| 3305 | end |
| 3306 | |
| 3307 | note epi: give back the stack of the local arrays, then RET (C6.2.338) |
| 3308 | fn epi to void |
| 3309 | if ne get xtarget 0 0 |
| 3310 | xload 0 0 |
| 3311 | emitb 201 |
| 3312 | emitb 195 |
| 3313 | ret |
| 3314 | end |
| 3315 | spadd get stkbytes 0 |
| 3316 | emit 3596551104 |
| 3317 | end |
| 3318 | |
| 3319 | fn dead1 to void |
| 3320 | put dead 0 1 |
| 3321 | end |
| 3322 | |
| 3323 | note pushb / pushnh: open a block (om4 PUSHB, split in two because a call takes at most 6 values) |
| 3324 | fn pushb br ulong k ulong head ulong reg ulong ty ulong to void |
| 3325 | n = get nb 0 |
| 3326 | if ge n 512 |
| 3327 | fail 14 |
| 3328 | end |
| 3329 | put bkind n k |
| 3330 | put bbr n br |
| 3331 | put bhead n head |
| 3332 | put breg n reg |
| 3333 | put btyp n ty |
| 3334 | put bdead n 0 |
| 3335 | put nb 0 add n 1 |
| 3336 | note fz_push / fz_else / fz_join: the sets when block n opens; at its else (the then sets kept, the |
| 3337 | note opening sets back); at its end (kind k: 1 if, 2 else, 3 while, 4 for) |
| 3338 | j = ulong 0 |
| 3339 | while lt j get fz_n 0 |
| 3340 | put fz_ent add mul n 16 j get fz_cur j |
| 3341 | j = add j 1 |
| 3342 | end |
| 3343 | end |
| 3344 | |
| 3345 | fn pushnh names ulong hd ulong to void |
| 3346 | n = sub get nb 0 1 |
| 3347 | put bnames n names |
| 3348 | put bheld n hd |
| 3349 | end |
| 3350 | |
| 3351 | note ======== small readers ======== |
| 3352 | fn elemtype t ulong to void |
| 3353 | if lt t 2 |
| 3354 | fail 9 |
| 3355 | end |
| 3356 | if ge t 64 |
| 3357 | fail 7 |
| 3358 | end |
| 3359 | end |
| 3360 | |
| 3361 | note arrlen: an array length 1 .. 16777216 (error 8 below, 23 above, 23 when written as 2^63 or more) |
| 3362 | fn arrlen v ulong to void |
| 3363 | if ne get tbig 0 0 |
| 3364 | fail 23 |
| 3365 | end |
| 3366 | if or eq v 0 ne shr v 63 0 |
| 3367 | fail 8 |
| 3368 | end |
| 3369 | if gt v 16777216 |
| 3370 | fail 23 |
| 3371 | end |
| 3372 | end |
| 3373 | |
| 3374 | note lenval: an array length, loop bound or trap code token: a number, or an integer constant name (kind 9). |
| 3375 | note A name that is not an integer constant is error 16. When the line ends it is error eolc: 16 for a pool, |
| 3376 | note a new array or a parameter written without its length (OMEGESE s.7, as om4), 4 for trap and bound. |
| 3377 | fn lenval eolc ulong to ulong |
| 3378 | tok |
| 3379 | k = get tk 0 |
| 3380 | if eq k 0 |
| 3381 | fail eolc |
| 3382 | end |
| 3383 | if eq k 2 |
| 3384 | ret get tw 0 |
| 3385 | end |
| 3386 | if eq k 1 |
| 3387 | if le get tl 0 8 |
| 3388 | e = findname get tw 0 |
| 3389 | if ne e 0 |
| 3390 | if eq get nm_kind sub e 1 9 |
| 3391 | t = ulong get nm_type sub e 1 |
| 3392 | if ge t 10 |
| 3393 | fail 16 |
| 3394 | end |
| 3395 | put tbig 0 0 |
| 3396 | ret get nm_addr sub e 1 |
| 3397 | end |
| 3398 | end |
| 3399 | end |
| 3400 | end |
| 3401 | fail 16 |
| 3402 | ret 0 |
| 3403 | end |
| 3404 | |
| 3405 | note typeword: read a type name -> 1..9 |
| 3406 | fn typeword to ulong |
| 3407 | put dexp 0 2 |
| 3408 | tok |
| 3409 | k = get tk 0 |
| 3410 | if eq k 0 |
| 3411 | fail 4 |
| 3412 | end |
| 3413 | if ne k 1 |
| 3414 | fail 16 |
| 3415 | end |
| 3416 | if gt get tl 0 8 |
| 3417 | fail 16 |
| 3418 | end |
| 3419 | c = kw get tw 0 |
| 3420 | if eq c 0 |
| 3421 | a = findab get tw 0 |
| 3422 | if ne a 0 |
| 3423 | ret add a 63 |
| 3424 | end |
| 3425 | unkfail 16 |
| 3426 | end |
| 3427 | if eq c 76 |
| 3428 | fail 9 |
| 3429 | end |
| 3430 | if or eq c 88 eq c 89 |
| 3431 | if ne get irmode 0 0 |
| 3432 | fail 9 |
| 3433 | end |
| 3434 | end |
| 3435 | if eq c 88 |
| 3436 | ret 10 |
| 3437 | end |
| 3438 | if eq c 89 |
| 3439 | ret 11 |
| 3440 | end |
| 3441 | if eq c 223 |
| 3442 | ret 13 |
| 3443 | end |
| 3444 | if gt sub c 1 8 |
| 3445 | fail 16 |
| 3446 | end |
| 3447 | ret c |
| 3448 | end |
| 3449 | |
| 3450 | note eol: the line must end here |
| 3451 | fn eol to void |
| 3452 | put dexp 0 6 |
| 3453 | tok |
| 3454 | k = get tk 0 |
| 3455 | if and ne k 0 ne k 3 |
| 3456 | fail 5 |
| 3457 | end |
| 3458 | end |
| 3459 | |
| 3460 | note arrname: read an array name -> its index + 1 |
| 3461 | fn arrname to ulong |
| 3462 | put dexp 0 3 |
| 3463 | tok |
| 3464 | k = get tk 0 |
| 3465 | if eq k 0 |
| 3466 | fail 4 |
| 3467 | end |
| 3468 | if eq k 3 |
| 3469 | fail 4 |
| 3470 | end |
| 3471 | if ne k 1 |
| 3472 | fail 16 |
| 3473 | end |
| 3474 | if gt get tl 0 8 |
| 3475 | fail 13 |
| 3476 | end |
| 3477 | if eq kw get tw 0 193 |
| 3478 | fail 9 |
| 3479 | end |
| 3480 | e = findname get tw 0 |
| 3481 | if eq e 0 |
| 3482 | fail 3 |
| 3483 | end |
| 3484 | if eq get nm_kind sub e 1 0 |
| 3485 | fail 7 |
| 3486 | end |
| 3487 | ret e |
| 3488 | end |
| 3489 | |
| 3490 | note topname: read a new name for a global or a text -> its packed word |
| 3491 | fn topname to ulong |
| 3492 | tok |
| 3493 | if ne get tk 0 1 |
| 3494 | fail 16 |
| 3495 | end |
| 3496 | if gt get tl 0 8 |
| 3497 | fail 13 |
| 3498 | end |
| 3499 | w = get tw 0 |
| 3500 | if ne kw w 0 |
| 3501 | fail 16 |
| 3502 | end |
| 3503 | newname w get tl 0 get ts 0 |
| 3504 | ret w |
| 3505 | end |
| 3506 | |
| 3507 | note ---- value results (om4 x0 kind 1 register / 2 bare number / 3 typed number / 4 flags, x1 register, |
| 3508 | note number or condition, x2 type). fr: 32 cells per value nesting depth 0..1024: 0..5 the two operands of |
| 3509 | note a binary op (kind, value, type each), 8..25 a call's arguments (kind, value, array name each) ---- |
| 3510 | global rk ulong 1 |
| 3511 | global rv ulong 1 |
| 3512 | global rt ulong 1 |
| 3513 | global fr ulong 32800 |
| 3514 | global depth ulong 1 |
| 3515 | |
| 3516 | note ======== BINOP (om4 BINOP and its BO_* parts): two values already read, types settled ======== |
| 3517 | note bo_w3: emit fx | rd | ra << 5 | (imm12 << 10, or rb << 16) |
| 3518 | fn bo_w3 fx ulong rd ulong ra ulong rb ulong imm ulong to void |
| 3519 | if ne imm 0 |
| 3520 | emit or or or fx rd shl ra 5 shl rb 10 |
| 3521 | else |
| 3522 | emit or or or fx rd shl ra 5 shl rb 16 |
| 3523 | end |
| 3524 | end |
| 3525 | |
| 3526 | note bo_fix: after a 64-bit op on rd: u8/u16/u32 wrap (canon), i8/i16/i32 overflow check (trap 1) |
| 3527 | fn bo_fix rd ulong ty ulong to void |
| 3528 | if lt ty 6 |
| 3529 | canon rd ty |
| 3530 | ret |
| 3531 | end |
| 3532 | if eq ty 9 |
| 3533 | ret |
| 3534 | end |
| 3535 | chkext rd ty 1 |
| 3536 | end |
| 3537 | |
| 3538 | note bo_schk: a shift amount in a register must be below the width: CMP Xb, #w; B.HS trap 7 |
| 3539 | fn bo_schk ty ulong rb ulong to void |
| 3540 | if ne get xtarget 0 0 |
| 3541 | xload 0 rb |
| 3542 | ximm 1 twid ty |
| 3543 | xrr 57 0 1 |
| 3544 | xtrap 2 7 |
| 3545 | ret |
| 3546 | end |
| 3547 | emit or or 4043309087 shl twid ty 10 shl rb 5 |
| 3548 | trapc 2 7 |
| 3549 | end |
| 3550 | |
| 3551 | note add, sub: u32 the 32-bit form; i64 ADDS/SUBS + B.VS trap 1; others 64-bit then bo_fix (om4 BO_ADD) |
| 3552 | fn bo_add op ulong ty ulong ra ulong rb ulong imm ulong rd ulong to void |
| 3553 | if ne get xtarget 0 0 |
| 3554 | xarith op ty ra rb imm rd |
| 3555 | ret |
| 3556 | end |
| 3557 | fx = ulong 2332033024 |
| 3558 | if eq op 34 |
| 3559 | fx = ulong 3405774848 |
| 3560 | end |
| 3561 | if ne imm 0 |
| 3562 | fx = ulong 2432696320 |
| 3563 | if eq op 34 |
| 3564 | fx = ulong 3506438144 |
| 3565 | end |
| 3566 | end |
| 3567 | if eq ty 4 |
| 3568 | bo_w3 xor fx 2147483648 rd ra rb imm |
| 3569 | ret |
| 3570 | end |
| 3571 | if eq ty 9 |
| 3572 | bo_w3 or fx 536870912 rd ra rb imm |
| 3573 | trapc 6 1 |
| 3574 | ret |
| 3575 | end |
| 3576 | if eq ty 13 |
| 3577 | bo_w3 or fx 536870912 rd ra rb imm |
| 3578 | if eq op 34 |
| 3579 | trapc 3 1 |
| 3580 | else |
| 3581 | trapc 2 1 |
| 3582 | end |
| 3583 | ret |
| 3584 | end |
| 3585 | bo_w3 fx rd ra rb imm |
| 3586 | bo_fix rd ty |
| 3587 | end |
| 3588 | |
| 3589 | note mul: i64 SMULH t, MUL, CMP t, rd, ASR #63, B.NE trap 1 (om4 BO_MUL) |
| 3590 | fn bo_mul ty ulong ra ulong rb ulong rd ulong to void |
| 3591 | if ne get xtarget 0 0 |
| 3592 | xarith 35 ty ra rb 0 rd |
| 3593 | ret |
| 3594 | end |
| 3595 | if eq ty 9 |
| 3596 | t = alloc |
| 3597 | e3 2604694528 t ra rb |
| 3598 | bo_w3 2600500224 rd ra rb 0 |
| 3599 | e3 3951098911 0 t rd |
| 3600 | trapc 1 1 |
| 3601 | ret |
| 3602 | end |
| 3603 | if eq ty 13 |
| 3604 | t = alloc |
| 3605 | e3 2613083136 t ra rb |
| 3606 | bo_w3 2600500224 rd ra rb 0 |
| 3607 | emit or 4043309087 shl t 5 |
| 3608 | trapc 1 1 |
| 3609 | ret |
| 3610 | end |
| 3611 | if eq ty 4 |
| 3612 | bo_w3 453016576 rd ra rb 0 |
| 3613 | ret |
| 3614 | end |
| 3615 | bo_w3 2600500224 rd ra rb 0 |
| 3616 | bo_fix rd ty |
| 3617 | end |
| 3618 | |
| 3619 | note div, rem (om4 BO_DIV, BO_SDIV): CBZ Xb trap 2 unless fl bit 1 (b a number other than 0); UDIV or |
| 3620 | 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, |
| 3621 | note unless fl bit 2 (b a number other than -1) |
| 3622 | fn bo_div op ulong ty ulong ra ulong rb ulong rd ulong fl ulong to void |
| 3623 | if ne get xtarget 0 0 |
| 3624 | xdiv op ty ra rb rd fl |
| 3625 | ret |
| 3626 | end |
| 3627 | if eq and fl 1 0 |
| 3628 | trapsite or 3019898880 rb 2 |
| 3629 | end |
| 3630 | if eq op 37 |
| 3631 | t = alloc |
| 3632 | if and ge ty 6 le ty 9 |
| 3633 | e3 2596277248 t ra rb |
| 3634 | else |
| 3635 | e3 2596276224 t ra rb |
| 3636 | end |
| 3637 | e3 or 2600501248 shl ra 10 rd t rb |
| 3638 | ret |
| 3639 | end |
| 3640 | if or lt ty 6 eq ty 13 |
| 3641 | bo_w3 2596276224 rd ra rb 0 |
| 3642 | ret |
| 3643 | end |
| 3644 | if eq ty 9 |
| 3645 | if eq and fl 2 0 |
| 3646 | emit or 2969568287 shl rb 5 |
| 3647 | emit 1409286241 |
| 3648 | emit or 3942646783 shl ra 16 |
| 3649 | trapc 6 1 |
| 3650 | end |
| 3651 | end |
| 3652 | bo_w3 2596277248 rd ra rb 0 |
| 3653 | if ne ty 9 |
| 3654 | bo_fix rd ty |
| 3655 | end |
| 3656 | end |
| 3657 | |
| 3658 | note and, or, xor (om4 BO_LOG) |
| 3659 | fn bo_log op ulong ra ulong rb ulong rd ulong to void |
| 3660 | if ne get xtarget 0 0 |
| 3661 | xarith op 5 ra rb 0 rd |
| 3662 | ret |
| 3663 | end |
| 3664 | fx = ulong 2315255808 |
| 3665 | if eq op 39 |
| 3666 | fx = ulong 2852126720 |
| 3667 | end |
| 3668 | if eq op 40 |
| 3669 | fx = ulong 3388997632 |
| 3670 | end |
| 3671 | bo_w3 fx rd ra rb 0 |
| 3672 | end |
| 3673 | |
| 3674 | note bo_lsl: LSL Xd, Xn, #s as UBFM Xd, Xn, #(64-s) mod 64, #63-s |
| 3675 | fn bo_lsl ra ulong s ulong rd ulong to void |
| 3676 | if ne get xtarget 0 0 |
| 3677 | xshift 41 5 ra s 1 rd |
| 3678 | ret |
| 3679 | end |
| 3680 | r = shl and sub 64 s 63 16 |
| 3681 | r = or r shl sub 63 s 10 |
| 3682 | r = or r shl ra 5 |
| 3683 | emit or or 3544186880 r rd |
| 3684 | end |
| 3685 | |
| 3686 | 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 |
| 3687 | note check, LSLV; i64: t = a << s, X16 = t >> s arithmetic, CMP X16, Xa, B.NE trap 1, MOV Xd, Xt |
| 3688 | fn bo_shl ty ulong ra ulong rb ulong imm ulong rd ulong to void |
| 3689 | if ne get xtarget 0 0 |
| 3690 | xshift 41 ty ra rb imm rd |
| 3691 | ret |
| 3692 | end |
| 3693 | if eq ty 9 |
| 3694 | t = alloc |
| 3695 | if ne imm 0 |
| 3696 | bo_lsl ra rb t |
| 3697 | emit or or 2470509584 shl rb 16 shl t 5 |
| 3698 | else |
| 3699 | bo_schk ty rb |
| 3700 | e3 2596282368 t ra rb |
| 3701 | e3 2596284432 0 t rb |
| 3702 | end |
| 3703 | emit or 3942646303 shl ra 16 |
| 3704 | trapc 1 1 |
| 3705 | emit or or 2852127712 rd shl t 16 |
| 3706 | ret |
| 3707 | end |
| 3708 | if ne imm 0 |
| 3709 | bo_lsl ra rb rd |
| 3710 | bo_fix rd ty |
| 3711 | ret |
| 3712 | end |
| 3713 | bo_schk ty rb |
| 3714 | if eq ty 4 |
| 3715 | bo_w3 448798720 rd ra rb 0 |
| 3716 | ret |
| 3717 | end |
| 3718 | bo_w3 2596282368 rd ra rb 0 |
| 3719 | bo_fix rd ty |
| 3720 | end |
| 3721 | |
| 3722 | note shr: unsigned LSR, signed ASR; by a number UBFM / SBFM Xd, Xn, #s, #63; by a register the amount check |
| 3723 | note then LSRV / ASRV (om4 BO_SHR) |
| 3724 | fn bo_shr ty ulong ra ulong rb ulong imm ulong rd ulong to void |
| 3725 | if ne get xtarget 0 0 |
| 3726 | xshift 42 ty ra rb imm rd |
| 3727 | ret |
| 3728 | end |
| 3729 | if ne imm 0 |
| 3730 | fi = ulong 3544251392 |
| 3731 | if ge ty 6 |
| 3732 | fi = ulong 2470509568 |
| 3733 | end |
| 3734 | emit or or or fi shl rb 16 shl ra 5 rd |
| 3735 | ret |
| 3736 | end |
| 3737 | bo_schk ty rb |
| 3738 | fx = ulong 2596283392 |
| 3739 | if ge ty 6 |
| 3740 | fx = ulong 2596284416 |
| 3741 | end |
| 3742 | bo_w3 fx rd ra rb 0 |
| 3743 | end |
| 3744 | |
| 3745 | note comparisons: CMP Xa, #imm or CMP Xa, Xb; the result is the flags and a condition (om4 BO_CMP) |
| 3746 | fn bo_cmp op ulong ty ulong ra ulong rb ulong imm ulong to void |
| 3747 | if ne get xtarget 0 0 |
| 3748 | xcmp ra rb imm |
| 3749 | else |
| 3750 | if ne imm 0 |
| 3751 | emit or or 4043309087 shl rb 10 shl ra 5 |
| 3752 | else |
| 3753 | emit or or 3942645791 shl rb 16 shl ra 5 |
| 3754 | end |
| 3755 | end |
| 3756 | i = mul sub op 43 2 |
| 3757 | if and ge ty 6 le ty 9 |
| 3758 | i = add i 1 |
| 3759 | end |
| 3760 | put rk 0 4 |
| 3761 | put rv 0 conds i |
| 3762 | put rt 0 1 |
| 3763 | end |
| 3764 | |
| 3765 | note Baseline SSE2, Intel SDM MOVD/MOVQ, scalar SS/SD, UCOMIS, CVTSI and CVTT instructions. |
| 3766 | note WolframLanguageEvaluator: {2^31,2^63,2^22,2^51} -> {2147483648,9223372036854775808,4194304,2251799813685248}. |
| 3767 | note WolframLanguageEvaluator: FromDigits[#,16]& /@ {"7F800000","7FF0000000000000","7FC00000","7FF8000000000000"} |
| 3768 | note -> {2139095040,9218868437227405312,2143289344,9221120237041090560}. |
| 3769 | fn xfmask ty ulong kind ulong to ulong |
| 3770 | if eq ty 10 |
| 3771 | if eq kind 0 |
| 3772 | ret 2147483648 |
| 3773 | end |
| 3774 | if eq kind 1 |
| 3775 | ret 2147483647 |
| 3776 | end |
| 3777 | if eq kind 2 |
| 3778 | ret 4194304 |
| 3779 | end |
| 3780 | if eq kind 3 |
| 3781 | ret 2139095040 |
| 3782 | end |
| 3783 | ret 2143289344 |
| 3784 | end |
| 3785 | if eq kind 0 |
| 3786 | ret 9223372036854775808 |
| 3787 | end |
| 3788 | if eq kind 1 |
| 3789 | ret 9223372036854775807 |
| 3790 | end |
| 3791 | if eq kind 2 |
| 3792 | ret 2251799813685248 |
| 3793 | end |
| 3794 | if eq kind 3 |
| 3795 | ret 9218868437227405312 |
| 3796 | end |
| 3797 | ret 9221120237041090560 |
| 3798 | end |
| 3799 | |
| 3800 | note MOVD clears EAX's upper bits on extraction; no float sign extension. |
| 3801 | fn xfmov ty ulong op ulong vr ulong to void |
| 3802 | emitb 102 |
| 3803 | if eq ty 11 |
| 3804 | emitb 72 |
| 3805 | end |
| 3806 | xb 15 op add 192 shl vr 3 |
| 3807 | end |
| 3808 | |
| 3809 | fn xfsse ty ulong op ulong mr ulong to void |
| 3810 | if eq ty 10 |
| 3811 | emitb 243 |
| 3812 | else |
| 3813 | emitb 242 |
| 3814 | end |
| 3815 | xb 15 op mr |
| 3816 | end |
| 3817 | |
| 3818 | fn xfucom ty ulong mr ulong to void |
| 3819 | if eq ty 11 |
| 3820 | emitb 102 |
| 3821 | end |
| 3822 | xb 15 46 mr |
| 3823 | end |
| 3824 | |
| 3825 | note Raw Intel condition for parity: existing xbranch takes the A64 condition vocabulary. |
| 3826 | fn xfbranch cc ulong to ulong |
| 3827 | p = get oc 0 |
| 3828 | emitb 15 |
| 3829 | emitb uchar add 128 cc |
| 3830 | xword 0 |
| 3831 | ret p |
| 3832 | end |
| 3833 | |
| 3834 | note Leaves the raw value in RAX, magnitude in RCX, and unsigned magnitude-versus-infinity flags. |
| 3835 | fn xfclass ty ulong r ulong to void |
| 3836 | xload 0 r |
| 3837 | ximm 1 xfmask ty 1 |
| 3838 | xrr 33 1 0 |
| 3839 | ximm 2 xfmask ty 3 |
| 3840 | xrr 57 1 2 |
| 3841 | end |
| 3842 | |
| 3843 | note Arm FPProcessNaNs priority: first signaling NaN, second signaling NaN, then first quiet NaN. |
| 3844 | note minNum/maxNum additionally return the numeric argument when paired with one quiet NaN. |
| 3845 | note Return the selected-result jump for the caller to patch past its normal arithmetic. |
| 3846 | fn xfnans ty ulong a ulong b ulong num ulong d ulong to ulong |
| 3847 | note Emit shared result stubs first so each case patches immediately instead of retaining its own fixup. |
| 3848 | skip = xbranch 14 |
| 3849 | quiet = get oc 0 |
| 3850 | ximm 1 xfmask ty 2 |
| 3851 | xrr 9 0 1 |
| 3852 | store = get oc 0 |
| 3853 | xstore 0 d |
| 3854 | d = xbranch 14 |
| 3855 | xpatch skip get oc 0 |
| 3856 | xfclass ty a |
| 3857 | skip = xbranch 8 |
| 3858 | xfclass ty b |
| 3859 | bn = xbranch 8 |
| 3860 | none = xbranch 14 |
| 3861 | xpatch skip get oc 0 |
| 3862 | ximm 1 xfmask ty 2 |
| 3863 | xrr 133 0 1 |
| 3864 | p = xbranch 0 |
| 3865 | xpatch p quiet |
| 3866 | xfclass ty b |
| 3867 | skip = xbranch 9 |
| 3868 | ximm 1 xfmask ty 2 |
| 3869 | xrr 133 0 1 |
| 3870 | p = xbranch 0 |
| 3871 | xpatch p quiet |
| 3872 | xload 0 a |
| 3873 | p = xbranch 14 |
| 3874 | xpatch p store |
| 3875 | xpatch skip get oc 0 |
| 3876 | if ne num 0 |
| 3877 | xload 0 b |
| 3878 | else |
| 3879 | xload 0 a |
| 3880 | end |
| 3881 | p = xbranch 14 |
| 3882 | xpatch p store |
| 3883 | xpatch bn get oc 0 |
| 3884 | if ne num 0 |
| 3885 | ximm 1 xfmask ty 2 |
| 3886 | xrr 133 0 1 |
| 3887 | p = xbranch 0 |
| 3888 | xpatch p quiet |
| 3889 | xload 0 a |
| 3890 | p = xbranch 14 |
| 3891 | xpatch p store |
| 3892 | else |
| 3893 | p = xbranch 14 |
| 3894 | xpatch p quiet |
| 3895 | end |
| 3896 | xpatch none get oc 0 |
| 3897 | ret d |
| 3898 | end |
| 3899 | |
| 3900 | note SSE invalid arithmetic produces a negative indefinite NaN; Arm's default NaN is positive. |
| 3901 | note Operand NaNs have already bypassed arithmetic, retaining their sign and payload. |
| 3902 | fn xfdefnan ty ulong d ulong to void |
| 3903 | xfclass ty d |
| 3904 | ok = xbranch 9 |
| 3905 | ximm 0 xfmask ty 4 |
| 3906 | xstore 0 d |
| 3907 | xpatch ok get oc 0 |
| 3908 | end |
| 3909 | |
| 3910 | fn xfbin op ulong ty ulong a ulong b ulong d ulong to void |
| 3911 | nanend = xfnans ty a b 0 d |
| 3912 | f2v ty a 0 |
| 3913 | f2v ty b 1 |
| 3914 | code = ulong 89 |
| 3915 | if eq op 33 |
| 3916 | code = ulong 88 |
| 3917 | end |
| 3918 | if eq op 34 |
| 3919 | code = ulong 92 |
| 3920 | end |
| 3921 | if eq op 36 |
| 3922 | code = ulong 94 |
| 3923 | end |
| 3924 | xfsse ty code 193 |
| 3925 | fv2x ty 0 d |
| 3926 | xfdefnan ty d |
| 3927 | xpatch nanend get oc 0 |
| 3928 | end |
| 3929 | |
| 3930 | fn xfminmax c ulong ty ulong a ulong b ulong d ulong to void |
| 3931 | nanend = xfnans ty a b 1 d |
| 3932 | f2v ty a 0 |
| 3933 | f2v ty b 1 |
| 3934 | xfucom ty 193 |
| 3935 | cc = ulong 3 |
| 3936 | if eq c 94 |
| 3937 | cc = ulong 8 |
| 3938 | end |
| 3939 | takea = xbranch cc |
| 3940 | if eq c 94 |
| 3941 | cc = ulong 3 |
| 3942 | else |
| 3943 | cc = ulong 8 |
| 3944 | end |
| 3945 | takeb = xbranch cc |
| 3946 | note Equal finite operands have equal bits except signed zero: OR chooses -0, AND chooses +0. |
| 3947 | xload 0 a |
| 3948 | xload 1 b |
| 3949 | if eq c 94 |
| 3950 | xrr 33 0 1 |
| 3951 | else |
| 3952 | xrr 9 0 1 |
| 3953 | end |
| 3954 | xstore 0 d |
| 3955 | equalend = xbranch 14 |
| 3956 | xpatch takea get oc 0 |
| 3957 | xload 0 a |
| 3958 | xstore 0 d |
| 3959 | aend = xbranch 14 |
| 3960 | xpatch takeb get oc 0 |
| 3961 | xload 0 b |
| 3962 | xstore 0 d |
| 3963 | xpatch equalend get oc 0 |
| 3964 | xpatch aend get oc 0 |
| 3965 | xpatch nanend get oc 0 |
| 3966 | end |
| 3967 | |
| 3968 | note Normalize the predicate to TEST flags; callers retain the existing rk=4, rv=NE contract. |
| 3969 | fn xfcmp op ulong ty ulong a ulong b ulong to void |
| 3970 | f2v ty a 0 |
| 3971 | f2v ty b 1 |
| 3972 | xfucom ty 193 |
| 3973 | unord = xfbranch 10 |
| 3974 | cc = ulong 4 |
| 3975 | if eq op 44 |
| 3976 | cc = ulong 5 |
| 3977 | end |
| 3978 | if eq op 45 |
| 3979 | cc = ulong 2 |
| 3980 | end |
| 3981 | if eq op 46 |
| 3982 | cc = ulong 6 |
| 3983 | end |
| 3984 | if eq op 47 |
| 3985 | cc = ulong 7 |
| 3986 | end |
| 3987 | if eq op 48 |
| 3988 | cc = ulong 3 |
| 3989 | end |
| 3990 | xb 15 add 144 cc 192 |
| 3991 | done = xbranch 14 |
| 3992 | xpatch unord get oc 0 |
| 3993 | if eq op 44 |
| 3994 | ximm 0 1 |
| 3995 | else |
| 3996 | ximm 0 0 |
| 3997 | end |
| 3998 | xpatch done get oc 0 |
| 3999 | xb 72 15 182 |
| 4000 | emitb 192 |
| 4001 | xrr 133 0 0 |
| 4002 | put rk 0 4 |
| 4003 | put rv 0 1 |
| 4004 | put rt 0 1 |
| 4005 | end |
| 4006 | |
| 4007 | fn xfsito ty ulong to void |
| 4008 | if eq ty 10 |
| 4009 | emitb 243 |
| 4010 | else |
| 4011 | emitb 242 |
| 4012 | end |
| 4013 | emitb 72 |
| 4014 | xb 15 42 192 |
| 4015 | end |
| 4016 | |
| 4017 | fn xfint ft ulong tt ulong a ulong d ulong to void |
| 4018 | xload 0 a |
| 4019 | if eq ft 5 |
| 4020 | xrr 133 0 0 |
| 4021 | small = xbranch 10 |
| 4022 | note Sticky halve before signed conversion preserves nearest-even rounding for the unsigned high half. |
| 4023 | xrr 137 2 0 |
| 4024 | xb 72 209 234 |
| 4025 | ximm 1 1 |
| 4026 | xrr 33 0 1 |
| 4027 | xrr 9 0 2 |
| 4028 | xfsito tt |
| 4029 | xfsse tt 88 192 |
| 4030 | done = xbranch 14 |
| 4031 | xpatch small get oc 0 |
| 4032 | xfsito tt |
| 4033 | xpatch done get oc 0 |
| 4034 | else |
| 4035 | xfsito tt |
| 4036 | end |
| 4037 | fv2x tt 0 d |
| 4038 | end |
| 4039 | |
| 4040 | fn xfconst bits ulong to void |
| 4041 | ximm 0 bits |
| 4042 | xfmov 11 110 1 |
| 4043 | end |
| 4044 | |
| 4045 | fn xfcvtt to void |
| 4046 | emitb 242 |
| 4047 | emitb 72 |
| 4048 | xb 15 44 192 |
| 4049 | end |
| 4050 | |
| 4051 | |
| 4052 | note Widen f32 exactly, guard NaN and the destination's own bounds, then CVTT toward zero. |
| 4053 | note WolframLanguageEvaluator: Table[BitShiftLeft[1023+k,52],{k,{7,8,15,16,31,32,63,64}}] |
| 4054 | note -> {4638707616191610880,4643211215818981376,4674736413210574848,4679240012837945344,4746794007248502784,4751297606875873280,4890909195324358656,4895412794951729152}. |
| 4055 | fn xftoint ft ulong tt ulong d ulong to void |
| 4056 | n = twid tt |
| 4057 | sg = and ge tt 6 le tt 9 |
| 4058 | if eq ft 10 |
| 4059 | xfsse 10 90 192 |
| 4060 | end |
| 4061 | xfucom 11 192 |
| 4062 | nan = xfbranch 10 |
| 4063 | if sg |
| 4064 | n = sub n 1 |
| 4065 | end |
| 4066 | xfconst shl add ulong 1023 n 52 |
| 4067 | xfucom 11 193 |
| 4068 | above = xbranch 2 |
| 4069 | if sg |
| 4070 | xfconst or 9223372036854775808 shl add ulong 1023 n 52 |
| 4071 | else |
| 4072 | xfconst 0 |
| 4073 | end |
| 4074 | xfucom 11 193 |
| 4075 | below = xbranch 9 |
| 4076 | if and not sg eq n 64 |
| 4077 | xfconst 4890909195324358656 |
| 4078 | xfucom 11 193 |
| 4079 | small = xbranch 3 |
| 4080 | xfsse 11 92 193 |
| 4081 | xfcvtt |
| 4082 | ximm 1 9223372036854775808 |
| 4083 | xrr 9 0 1 |
| 4084 | done = xbranch 14 |
| 4085 | xpatch small get oc 0 |
| 4086 | xfcvtt |
| 4087 | xpatch done get oc 0 |
| 4088 | else |
| 4089 | xfcvtt |
| 4090 | end |
| 4091 | done = xbranch 14 |
| 4092 | xpatch nan get oc 0 |
| 4093 | ximm 0 0 |
| 4094 | nan = xbranch 14 |
| 4095 | xpatch above get oc 0 |
| 4096 | maxv = ulong 18446744073709551615 |
| 4097 | if sg |
| 4098 | maxv = sub shl ulong 1 n 1 |
| 4099 | else |
| 4100 | if lt n 64 |
| 4101 | maxv = sub shl ulong 1 n 1 |
| 4102 | end |
| 4103 | end |
| 4104 | ximm 0 maxv |
| 4105 | above = xbranch 14 |
| 4106 | xpatch below get oc 0 |
| 4107 | if sg |
| 4108 | ximm 0 sub ulong 0 shl ulong 1 n |
| 4109 | else |
| 4110 | ximm 0 0 |
| 4111 | end |
| 4112 | xpatch done get oc 0 |
| 4113 | xpatch nan get oc 0 |
| 4114 | xpatch above get oc 0 |
| 4115 | xstore 0 d |
| 4116 | end |
| 4117 | |
| 4118 | fn xfconv ft ulong tt ulong a ulong to ulong |
| 4119 | if or eq ft 1 eq tt 1 |
| 4120 | fail 9 |
| 4121 | end |
| 4122 | if or eq ft 13 eq tt 13 |
| 4123 | fail 7 |
| 4124 | end |
| 4125 | if eq ft tt |
| 4126 | ret a |
| 4127 | end |
| 4128 | d = alloc |
| 4129 | if ge ft 10 |
| 4130 | f2v ft a 0 |
| 4131 | if ge tt 10 |
| 4132 | xfsse ft 90 192 |
| 4133 | fv2x tt 0 d |
| 4134 | else |
| 4135 | xftoint ft tt d |
| 4136 | end |
| 4137 | else |
| 4138 | xfint ft tt a d |
| 4139 | end |
| 4140 | ret d |
| 4141 | end |
| 4142 | |
| 4143 | note xfbinop: binop's float arm on x86: both operands in x registers, a compare or one SSE operation. |
| 4144 | fn xfbinop op ulong dst ulong ix ulong ty ulong to void |
| 4145 | ra = matreg get fr ix get fr add ix 1 ty |
| 4146 | rb = matreg get fr add ix 3 get fr add ix 4 ty |
| 4147 | if ge op 43 |
| 4148 | xfcmp op ty ra rb |
| 4149 | ret |
| 4150 | end |
| 4151 | if or or lt op 33 gt op 36 ge op 41 |
| 4152 | fail 7 |
| 4153 | end |
| 4154 | rd = destreg dst |
| 4155 | xfbin op ty ra rb rd |
| 4156 | put rk 0 1 |
| 4157 | put rv 0 rd |
| 4158 | put rt 0 ty |
| 4159 | end |
| 4160 | |
| 4161 | note xfun1 / xfmm: fintr's and fminmax's x86 arms; the operand is in rk/rv (fminmax: the first in ak/av). |
| 4162 | fn xfun1 c ulong t ulong dst ulong to void |
| 4163 | ra = matreg get rk 0 get rv 0 t |
| 4164 | rd = destreg dst |
| 4165 | if eq c 91 |
| 4166 | nanend = xfnans t ra ra 0 rd |
| 4167 | f2v t ra 0 |
| 4168 | xfsse t 81 192 |
| 4169 | fv2x t 0 rd |
| 4170 | xfdefnan t rd |
| 4171 | xpatch nanend get oc 0 |
| 4172 | else |
| 4173 | xload 0 ra |
| 4174 | ximm 1 xfmask t 1 |
| 4175 | xrr 33 0 1 |
| 4176 | xstore 0 rd |
| 4177 | end |
| 4178 | put rk 0 1 |
| 4179 | put rv 0 rd |
| 4180 | put rt 0 t |
| 4181 | end |
| 4182 | |
| 4183 | fn xfmm c ulong at ulong ak ulong av ulong dst ulong to void |
| 4184 | ra = matreg ak av at |
| 4185 | rb = matreg get rk 0 get rv 0 at |
| 4186 | rd = destreg dst |
| 4187 | xfminmax c at ra rb rd |
| 4188 | put rk 0 1 |
| 4189 | put rv 0 rd |
| 4190 | put rt 0 at |
| 4191 | end |
| 4192 | |
| 4193 | note ---- floating point. A float value is its IEEE bit pattern: in an x register (kind 1, 7 a constant), |
| 4194 | note or in a v register (kind 9, the twin of a pool register; float local names live there). Arithmetic |
| 4195 | note runs one scalar FP instruction (round to nearest even, no fused op) on v registers: an x operand moves |
| 4196 | note to v0/v1 first; a result wanted in x moves back from v1/v2, one wanted as kind 9 stays in its twin. |
| 4197 | note f32 uses the S form (low 32 bits), f64 the D form. |
| 4198 | fn f2v ty ulong xr ulong vr ulong to void |
| 4199 | if ne get xtarget 0 0 |
| 4200 | xload 0 xr |
| 4201 | xfmov ty 110 vr |
| 4202 | ret |
| 4203 | end |
| 4204 | if eq ty 10 |
| 4205 | emit or or 505872384 shl xr 5 vr |
| 4206 | else |
| 4207 | emit or or 2657550336 shl xr 5 vr |
| 4208 | end |
| 4209 | end |
| 4210 | |
| 4211 | fn fv2x ty ulong vr ulong xr ulong to void |
| 4212 | if ne get xtarget 0 0 |
| 4213 | xfmov ty 126 vr |
| 4214 | xstore 0 xr |
| 4215 | ret |
| 4216 | end |
| 4217 | if eq ty 10 |
| 4218 | emit or or 505806848 shl vr 5 xr |
| 4219 | else |
| 4220 | emit or or 2657484800 shl vr 5 xr |
| 4221 | end |
| 4222 | end |
| 4223 | |
| 4224 | note vtw: the twin of pool register r, v(16 + its pool index): v16..v31, caller-saved in AAPCS64 |
| 4225 | fn vtw r ulong to ulong |
| 4226 | ret add 16 regidx r |
| 4227 | end |
| 4228 | |
| 4229 | note fv8d / fv8s: the FMOV (scalar, immediate) imm8 of f64 / f32 bits b, or 256 when there is none. imm8 is |
| 4230 | note the sign, then bits 54..48 (f64) / 25..19 (f32). Encodable only when the fraction bits below those are |
| 4231 | note zero and exponent bits 61..54 (f64) / 29..25 (f32) all equal NOT bit 62 / 30 (VFPExpandImm). |
| 4232 | fn fv8d b ulong to ulong |
| 4233 | if ne and b 281474976710655 0 |
| 4234 | ret 256 |
| 4235 | end |
| 4236 | e = and shr b 54 255 |
| 4237 | if and ne e 0 ne e 255 |
| 4238 | ret 256 |
| 4239 | end |
| 4240 | if eq and shr b 62 1 and e 1 |
| 4241 | ret 256 |
| 4242 | end |
| 4243 | s = shl shr b 63 7 |
| 4244 | s = or s shl and e 1 6 |
| 4245 | ret or s and shr b 48 63 |
| 4246 | end |
| 4247 | |
| 4248 | fn fv8s b ulong to ulong |
| 4249 | if ne and b 524287 0 |
| 4250 | ret 256 |
| 4251 | end |
| 4252 | e = and shr b 25 31 |
| 4253 | if and ne e 0 ne e 31 |
| 4254 | ret 256 |
| 4255 | end |
| 4256 | if eq and shr b 30 1 and e 1 |
| 4257 | ret 256 |
| 4258 | end |
| 4259 | s = shl and shr b 31 1 7 |
| 4260 | s = or s shl and e 1 6 |
| 4261 | ret or s and shr b 19 63 |
| 4262 | end |
| 4263 | |
| 4264 | note fvk: float bits b of type ty into v register vr: 0 FMOV from XZR (C7.2.131); a value with an 8-bit |
| 4265 | note form FMOV (scalar, immediate, C7.2.132); any other MOVZ/MOVK into X16, then FMOV from X16. |
| 4266 | fn fvk ty ulong b ulong vr ulong to void |
| 4267 | if eq b 0 |
| 4268 | f2v ty 31 vr |
| 4269 | ret |
| 4270 | end |
| 4271 | if eq ty 10 |
| 4272 | im = fv8s b |
| 4273 | if lt im 256 |
| 4274 | emit or or 505417728 shl im 13 vr |
| 4275 | ret |
| 4276 | end |
| 4277 | else |
| 4278 | im = fv8d b |
| 4279 | if lt im 256 |
| 4280 | emit or or 509612032 shl im 13 vr |
| 4281 | ret |
| 4282 | end |
| 4283 | end |
| 4284 | matconst 16 b |
| 4285 | f2v ty 16 vr |
| 4286 | end |
| 4287 | |
| 4288 | note fvop: the v register holding float operand (kind k, value v, type t): its twin for kind 9, else v |
| 4289 | note register s, filled from the constant or from the operand's x register. |
| 4290 | fn fvop k ulong v ulong t ulong s ulong to ulong |
| 4291 | if eq k 9 |
| 4292 | ret vtw v |
| 4293 | end |
| 4294 | if eq k 7 |
| 4295 | fvk t v s |
| 4296 | ret s |
| 4297 | end |
| 4298 | r = matreg k v t |
| 4299 | f2v t r s |
| 4300 | ret s |
| 4301 | end |
| 4302 | |
| 4303 | note fvdst: the pool register whose twin takes a kind 9 result for request o (fpw): 1 a new one, its slot |
| 4304 | note marked as living in v; 2 + r the twin of r (a float local name). |
| 4305 | fn fvdst o ulong to ulong |
| 4306 | if eq o 1 |
| 4307 | r = alloc |
| 4308 | put vsl regidx r uchar 1 |
| 4309 | ret r |
| 4310 | end |
| 4311 | ret sub o 2 |
| 4312 | end |
| 4313 | |
| 4314 | note fvset: float value (kind k, value v, type t) into the twin of r: FMOV Dd, Dn (C7.2.130), the constant, |
| 4315 | note or FMOV from its x register. Nothing when it is already there. |
| 4316 | fn fvset k ulong v ulong t ulong r ulong to void |
| 4317 | d = vtw r |
| 4318 | if eq k 9 |
| 4319 | if ne v r |
| 4320 | if eq t 10 |
| 4321 | emit or or 505430016 shl vtw v 5 d |
| 4322 | else |
| 4323 | emit or or 509624320 shl vtw v 5 d |
| 4324 | end |
| 4325 | end |
| 4326 | ret |
| 4327 | end |
| 4328 | if eq k 7 |
| 4329 | fvk t v d |
| 4330 | ret |
| 4331 | end |
| 4332 | x = matreg k v t |
| 4333 | f2v t x d |
| 4334 | end |
| 4335 | |
| 4336 | note fp_binop: one FP add / sub / mul / div of v registers va, vb into vd |
| 4337 | fn fp_binop op ulong ty ulong va ulong vb ulong vd ulong to void |
| 4338 | base = ulong 509609984 |
| 4339 | if eq ty 10 |
| 4340 | base = ulong 505415680 |
| 4341 | end |
| 4342 | if eq op 33 |
| 4343 | if eq ty 10 |
| 4344 | base = ulong 505423872 |
| 4345 | else |
| 4346 | base = ulong 509618176 |
| 4347 | end |
| 4348 | else |
| 4349 | if eq op 34 |
| 4350 | if eq ty 10 |
| 4351 | base = ulong 505427968 |
| 4352 | else |
| 4353 | base = ulong 509622272 |
| 4354 | end |
| 4355 | else |
| 4356 | if eq op 36 |
| 4357 | if eq ty 10 |
| 4358 | base = ulong 505419776 |
| 4359 | else |
| 4360 | base = ulong 509614080 |
| 4361 | end |
| 4362 | end |
| 4363 | end |
| 4364 | end |
| 4365 | emit or or or base shl vb 16 shl va 5 vd |
| 4366 | end |
| 4367 | |
| 4368 | fn fp_neg ty ulong va ulong vd ulong to void |
| 4369 | if eq ty 10 |
| 4370 | emit or or ulong 505495552 shl va 5 vd |
| 4371 | else |
| 4372 | emit or or ulong 509689856 shl va 5 vd |
| 4373 | end |
| 4374 | end |
| 4375 | |
| 4376 | note fp_un1: sqrt (c 91) or abs of v register va into vd |
| 4377 | fn fp_un1 c ulong ty ulong va ulong vd ulong to void |
| 4378 | if eq c 91 |
| 4379 | if eq ty 10 |
| 4380 | emit or or ulong 505528320 shl va 5 vd |
| 4381 | else |
| 4382 | emit or or ulong 509722624 shl va 5 vd |
| 4383 | end |
| 4384 | else |
| 4385 | if eq ty 10 |
| 4386 | emit or or ulong 505462784 shl va 5 vd |
| 4387 | else |
| 4388 | emit or or ulong 509657088 shl va 5 vd |
| 4389 | end |
| 4390 | end |
| 4391 | end |
| 4392 | |
| 4393 | note fp_minmax: FMINNM/FMAXNM, the IEEE minNum/maxNum rule: one quiet NaN returns the other operand, |
| 4394 | note and -0.0 orders below +0.0. |
| 4395 | fn fp_minmax c ulong ty ulong va ulong vb ulong vd ulong to void |
| 4396 | base = ulong 509638656 |
| 4397 | if eq c 94 |
| 4398 | base = ulong 509634560 |
| 4399 | end |
| 4400 | if eq ty 10 |
| 4401 | base = ulong 505444352 |
| 4402 | if eq c 94 |
| 4403 | base = ulong 505440256 |
| 4404 | end |
| 4405 | end |
| 4406 | emit or or or base shl vb 16 shl va 5 vd |
| 4407 | end |
| 4408 | |
| 4409 | note fintr: sqrt or abs of one float value; fminmax: min or max of two values of one float type. |
| 4410 | note Both refuse a bare integer operand and an unresolved literal, as everywhere else. A request o (fpo) |
| 4411 | note makes the result in a twin (kind 9); otherwise it moves to x register destreg dst (kind 1). |
| 4412 | fn fintr c ulong dst ulong to void |
| 4413 | o = get fpo 0 |
| 4414 | put fpo 0 0 |
| 4415 | if ne get irmode 0 0 |
| 4416 | fail 9 |
| 4417 | end |
| 4418 | put fpw 0 1 |
| 4419 | rdval 0 0 255 0 |
| 4420 | if eq get rk 0 2 |
| 4421 | fail 7 |
| 4422 | end |
| 4423 | if eq get rk 0 6 |
| 4424 | fail 11 |
| 4425 | end |
| 4426 | t = get rt 0 |
| 4427 | if eq isfloat t 0 |
| 4428 | fail 7 |
| 4429 | end |
| 4430 | if ne get xtarget 0 0 |
| 4431 | xfun1 c t dst |
| 4432 | vdec |
| 4433 | ret |
| 4434 | end |
| 4435 | va = fvop get rk 0 get rv 0 t 0 |
| 4436 | if eq o 0 |
| 4437 | rd = destreg dst |
| 4438 | fp_un1 c t va 1 |
| 4439 | fv2x t 1 rd |
| 4440 | put rk 0 1 |
| 4441 | put rv 0 rd |
| 4442 | else |
| 4443 | r = fvdst o |
| 4444 | fp_un1 c t va vtw r |
| 4445 | put rk 0 9 |
| 4446 | put rv 0 r |
| 4447 | end |
| 4448 | put rt 0 t |
| 4449 | vdec |
| 4450 | end |
| 4451 | |
| 4452 | fn fminmax c ulong dst ulong to void |
| 4453 | o = get fpo 0 |
| 4454 | put fpo 0 0 |
| 4455 | if ne get irmode 0 0 |
| 4456 | fail 9 |
| 4457 | end |
| 4458 | put fpw 0 1 |
| 4459 | rdval 0 0 255 0 |
| 4460 | if or eq get rk 0 2 eq get rk 0 6 |
| 4461 | fail 11 |
| 4462 | end |
| 4463 | at = get rt 0 |
| 4464 | ak = get rk 0 |
| 4465 | av = get rv 0 |
| 4466 | put fpw 0 1 |
| 4467 | rdval 0 0 255 0 |
| 4468 | if or eq get rk 0 2 eq get rk 0 6 |
| 4469 | fail 11 |
| 4470 | end |
| 4471 | if or eq isfloat at 0 eq isfloat get rt 0 0 |
| 4472 | fail 7 |
| 4473 | end |
| 4474 | if ne at get rt 0 |
| 4475 | fail 7 |
| 4476 | end |
| 4477 | if ne get xtarget 0 0 |
| 4478 | xfmm c at ak av dst |
| 4479 | vdec |
| 4480 | ret |
| 4481 | end |
| 4482 | va = fvop ak av at 0 |
| 4483 | vb = fvop get rk 0 get rv 0 at 1 |
| 4484 | if eq o 0 |
| 4485 | rd = destreg dst |
| 4486 | fp_minmax c at va vb 2 |
| 4487 | fv2x at 2 rd |
| 4488 | put rk 0 1 |
| 4489 | put rv 0 rd |
| 4490 | else |
| 4491 | r = fvdst o |
| 4492 | fp_minmax c at va vb vtw r |
| 4493 | put rk 0 9 |
| 4494 | put rv 0 r |
| 4495 | end |
| 4496 | put rt 0 at |
| 4497 | vdec |
| 4498 | end |
| 4499 | |
| 4500 | note FMADD (scalar), ARM C7: one rounded multiply-add, not FMUL followed by FADD. |
| 4501 | note The addend is Ra, bits 14..10; multiplicands Rn, Rm are bits 9..5, 20..16. |
| 4502 | fn ffma dst ulong to void |
| 4503 | o = get fpo 0 |
| 4504 | put fpo 0 0 |
| 4505 | put fpw 0 1 |
| 4506 | rdval 0 0 255 0 |
| 4507 | if eq get rk 0 6 |
| 4508 | fail 11 |
| 4509 | end |
| 4510 | at = get rt 0 |
| 4511 | if eq isfloat at 0 |
| 4512 | fail 7 |
| 4513 | end |
| 4514 | ak = get rk 0 |
| 4515 | av = get rv 0 |
| 4516 | put fpw 0 1 |
| 4517 | rdval 0 0 255 0 |
| 4518 | if eq get rk 0 6 |
| 4519 | fail 11 |
| 4520 | end |
| 4521 | if ne get rt 0 at |
| 4522 | fail 7 |
| 4523 | end |
| 4524 | bk = get rk 0 |
| 4525 | bv = get rv 0 |
| 4526 | put fpw 0 1 |
| 4527 | rdval 0 0 255 0 |
| 4528 | if eq get rk 0 6 |
| 4529 | fail 11 |
| 4530 | end |
| 4531 | if ne get rt 0 at |
| 4532 | fail 7 |
| 4533 | end |
| 4534 | note x86's baseline is SSE2, not FMA3. No unfused fallback is permitted. The operands are typed |
| 4535 | note first, so an ill-typed fma gets the same error 7 or 11 on every target; only a well-typed one |
| 4536 | note is refused here. |
| 4537 | if or ne get irmode 0 0 ne get xtarget 0 0 |
| 4538 | fail 9 |
| 4539 | end |
| 4540 | va = fvop ak av at 0 |
| 4541 | vb = fvop bk bv at 1 |
| 4542 | vc = fvop get rk 0 get rv 0 at 2 |
| 4543 | r = ulong 0 |
| 4544 | vd = ulong 3 |
| 4545 | if eq o 0 |
| 4546 | r = destreg dst |
| 4547 | else |
| 4548 | r = fvdst o |
| 4549 | vd = vtw r |
| 4550 | end |
| 4551 | b = ulong 520093696 |
| 4552 | if eq at 11 |
| 4553 | b = 524288000 |
| 4554 | end |
| 4555 | b = or b shl vb 16 |
| 4556 | b = or b shl vc 10 |
| 4557 | b = or b shl va 5 |
| 4558 | emit or b vd |
| 4559 | if eq o 0 |
| 4560 | fv2x at vd r |
| 4561 | put rk 0 1 |
| 4562 | else |
| 4563 | put rk 0 9 |
| 4564 | end |
| 4565 | put rv 0 r |
| 4566 | put rt 0 at |
| 4567 | vdec |
| 4568 | end |
| 4569 | |
| 4570 | note fcond: the condition for a float compare op: EQ, NE, MI (lt), LS (le), GT, GE. MI/LS/GT/GE are |
| 4571 | note false for NaN, so unordered comparisons come out as the IEEE rules require. |
| 4572 | fn fcond op ulong to ulong |
| 4573 | i = sub op 43 |
| 4574 | if eq i 0 |
| 4575 | ret 0 |
| 4576 | end |
| 4577 | if eq i 1 |
| 4578 | ret 1 |
| 4579 | end |
| 4580 | if eq i 2 |
| 4581 | ret 4 |
| 4582 | end |
| 4583 | if eq i 3 |
| 4584 | ret 9 |
| 4585 | end |
| 4586 | if eq i 4 |
| 4587 | ret 12 |
| 4588 | end |
| 4589 | ret 10 |
| 4590 | end |
| 4591 | |
| 4592 | note fp_cmp: FCMP Sn, Sm / Dn, Dm (scalar) of v registers va, vb: 0x1E202000 / 0x1E602000 with Rm and Rn |
| 4593 | note zero, so both fields come from va and vb alone (#861: the S word had Rm bit 0 set, and an even vb |
| 4594 | note read the next twin). |
| 4595 | fn fp_cmp op ulong ty ulong va ulong vb ulong to void |
| 4596 | if eq ty 10 |
| 4597 | emit or or 505421824 shl vb 16 shl va 5 |
| 4598 | else |
| 4599 | emit or or 509616128 shl vb 16 shl va 5 |
| 4600 | end |
| 4601 | put rk 0 4 |
| 4602 | put rv 0 fcond op |
| 4603 | put rt 0 1 |
| 4604 | end |
| 4605 | |
| 4606 | note fp_conv: one scalar conversion (int<->float, f32<->f64) into a new x register. Same type is a copy. |
| 4607 | note Returns the register. A float result is made in v(rd), or in v0 when rd is x17 (v17 is a twin). |
| 4608 | fn fp_conv ft ulong tt ulong ra ulong to ulong |
| 4609 | if ne get xtarget 0 0 |
| 4610 | ret xfconv ft tt ra |
| 4611 | end |
| 4612 | if eq ft tt |
| 4613 | ret ra |
| 4614 | end |
| 4615 | if eq ft 1 |
| 4616 | fail 9 |
| 4617 | end |
| 4618 | if eq tt 1 |
| 4619 | fail 9 |
| 4620 | end |
| 4621 | rd = alloc |
| 4622 | if eq isfloat tt 0 |
| 4623 | f2v ft ra 0 |
| 4624 | fp_toint ft tt rd |
| 4625 | ret rd |
| 4626 | end |
| 4627 | vs = rd |
| 4628 | if ge rd 16 |
| 4629 | vs = ulong 0 |
| 4630 | end |
| 4631 | fp_tov ft tt ra vs |
| 4632 | fv2x tt vs rd |
| 4633 | ret rd |
| 4634 | end |
| 4635 | |
| 4636 | note fp_tov: x register ra of type ft (an integer, or the other float type, moved to v0 first) converted |
| 4637 | note to float type tt in v register vd: SCVTF/UCVTF (C7.2.236/C7.2.355) by signedness, FCVT (C7.2.69). |
| 4638 | fn fp_tov ft ulong tt ulong ra ulong vd ulong to void |
| 4639 | if ne isfloat ft 0 |
| 4640 | f2v ft ra 0 |
| 4641 | if eq ft 10 |
| 4642 | emit or 505593856 vd |
| 4643 | else |
| 4644 | emit or 509755392 vd |
| 4645 | end |
| 4646 | ret |
| 4647 | end |
| 4648 | sgn = false |
| 4649 | if ge ft 6 |
| 4650 | sgn = true |
| 4651 | end |
| 4652 | if eq tt 10 |
| 4653 | if eq twid ft 32 |
| 4654 | if sgn |
| 4655 | emit or or 505544704 shl ra 5 vd |
| 4656 | else |
| 4657 | emit or or 505610240 shl ra 5 vd |
| 4658 | end |
| 4659 | else |
| 4660 | if sgn |
| 4661 | emit or or 2653028352 shl ra 5 vd |
| 4662 | else |
| 4663 | emit or or 2653093888 shl ra 5 vd |
| 4664 | end |
| 4665 | end |
| 4666 | else |
| 4667 | if eq twid ft 32 |
| 4668 | if sgn |
| 4669 | emit or or 509739008 shl ra 5 vd |
| 4670 | else |
| 4671 | emit or or 509804544 shl ra 5 vd |
| 4672 | end |
| 4673 | else |
| 4674 | if sgn |
| 4675 | emit or or 2657222656 shl ra 5 vd |
| 4676 | else |
| 4677 | emit or or 2657288192 shl ra 5 vd |
| 4678 | end |
| 4679 | end |
| 4680 | end |
| 4681 | end |
| 4682 | |
| 4683 | |
| 4684 | note fp_toint: float (v0) to integer rd: truncate toward zero, saturate to the destination's own range, NaN |
| 4685 | note to 0 (OMEGESE 9.9; spec/one-layer-format.md 10.3). 32/64-bit: FCVTZS/FCVTZU (C7.2.90/C7.2.94) by |
| 4686 | note signedness, int sign-extended (SXTW). 8/16-bit: the scalar SIMD FCVTZ[SU] in v0, then saturating |
| 4687 | note narrows (SQXTN/UQXTN, C7.2.311/C7.2.374) to the width, FMOV W (C7.2.130), then SXTB/SXTH for signed. |
| 4688 | fn fp_toint ft ulong tt ulong rd ulong to void |
| 4689 | if ne get xtarget 0 0 |
| 4690 | xftoint ft tt rd |
| 4691 | ret |
| 4692 | end |
| 4693 | w = twid tt |
| 4694 | sg = ge tt 6 |
| 4695 | if eq w 64 |
| 4696 | if sg |
| 4697 | if eq ft 10 |
| 4698 | emit or 2654470144 rd |
| 4699 | else |
| 4700 | emit or 2658664448 rd |
| 4701 | end |
| 4702 | else |
| 4703 | if eq ft 10 |
| 4704 | emit or 2654535680 rd |
| 4705 | else |
| 4706 | emit or 2658729984 rd |
| 4707 | end |
| 4708 | end |
| 4709 | ret |
| 4710 | end |
| 4711 | if eq w 32 |
| 4712 | if sg |
| 4713 | if eq ft 10 |
| 4714 | emit or 506986496 rd |
| 4715 | else |
| 4716 | emit or 511180800 rd |
| 4717 | end |
| 4718 | emit or or 2470476800 rd shl rd 5 |
| 4719 | else |
| 4720 | if eq ft 10 |
| 4721 | emit or 507052032 rd |
| 4722 | else |
| 4723 | emit or 511246336 rd |
| 4724 | end |
| 4725 | end |
| 4726 | ret |
| 4727 | end |
| 4728 | fp_narrow ft sg w |
| 4729 | emit or 505806848 rd |
| 4730 | if sg |
| 4731 | if eq w 8 |
| 4732 | emit or or 2470452224 rd shl rd 5 |
| 4733 | else |
| 4734 | emit or or 2470460416 rd shl rd 5 |
| 4735 | end |
| 4736 | end |
| 4737 | end |
| 4738 | |
| 4739 | note fp_narrow: convert v0 in place to a saturated integer of width w (8 or 16) in its low bits. |
| 4740 | fn fp_narrow ft ulong sg bool w ulong to void |
| 4741 | if eq ft 10 |
| 4742 | if sg |
| 4743 | emit 1587656704 |
| 4744 | emit 1583433728 |
| 4745 | else |
| 4746 | emit 2124527616 |
| 4747 | emit 2120304640 |
| 4748 | end |
| 4749 | else |
| 4750 | if sg |
| 4751 | emit 1591851008 |
| 4752 | emit 1587628032 |
| 4753 | emit 1583433728 |
| 4754 | else |
| 4755 | emit 2128721920 |
| 4756 | emit 2124498944 |
| 4757 | emit 2120304640 |
| 4758 | end |
| 4759 | end |
| 4760 | if eq w 8 |
| 4761 | if sg |
| 4762 | emit 1579239424 |
| 4763 | else |
| 4764 | emit 2116110336 |
| 4765 | end |
| 4766 | end |
| 4767 | end |
| 4768 | |
| 4769 | note ---- rotate (OM-2, spec 3): rotr 59 / rotl 60 of an unsigned uchar..ulong by the same type. uint and |
| 4770 | note ulong with a number below the width: ROR (immediate) = EXTR Rd, Rn, Rn, #s (C6.2.347, C6.2.160); |
| 4771 | note otherwise the shift amount check (trap 7) then RORV (C6.2.349); rotl by n is ror by w - n (a number) |
| 4772 | note or by NEG n (C6.2.295) since RORV takes the amount modulo the width. uchar/ushort first replicate the |
| 4773 | note value through W16 with ORR (shifted register, LSL, C6.2.302), rotate the 32-bit pattern, then canon. |
| 4774 | fn rotrep ty ulong ra ulong to void |
| 4775 | if eq ty 3 |
| 4776 | emit or or 704659472 shl ra 16 shl ra 5 |
| 4777 | ret |
| 4778 | end |
| 4779 | emit or or 704651280 shl ra 16 shl ra 5 |
| 4780 | emit 705708560 |
| 4781 | end |
| 4782 | |
| 4783 | fn rotimm ty ulong ra ulong s ulong rd ulong to void |
| 4784 | if ne get xtarget 0 0 |
| 4785 | xrot ty ra s 1 rd |
| 4786 | ret |
| 4787 | end |
| 4788 | if eq ty 5 |
| 4789 | emit or or or 2478833664 shl ra 16 shl s 10 or shl ra 5 rd |
| 4790 | ret |
| 4791 | end |
| 4792 | if eq ty 4 |
| 4793 | emit or or or 327155712 shl ra 16 shl s 10 or shl ra 5 rd |
| 4794 | ret |
| 4795 | end |
| 4796 | rotrep ty ra |
| 4797 | emit or or 328204800 shl s 10 rd |
| 4798 | canon rd ty |
| 4799 | end |
| 4800 | |
| 4801 | fn rotreg ty ulong ra ulong rr ulong rd ulong to void |
| 4802 | if ne get xtarget 0 0 |
| 4803 | xrot ty ra rr 0 rd |
| 4804 | ret |
| 4805 | end |
| 4806 | if eq ty 5 |
| 4807 | emit or or 2596285440 shl rr 16 or shl ra 5 rd |
| 4808 | ret |
| 4809 | end |
| 4810 | if eq ty 4 |
| 4811 | emit or or 448801792 shl rr 16 or shl ra 5 rd |
| 4812 | ret |
| 4813 | end |
| 4814 | rotrep ty ra |
| 4815 | emit or or 448802304 shl rr 16 rd |
| 4816 | canon rd ty |
| 4817 | end |
| 4818 | |
| 4819 | fn binrot op ulong dst ulong ix ulong to void |
| 4820 | ty = get fr add ix 2 |
| 4821 | if or lt ty 2 gt ty 5 |
| 4822 | fail 7 |
| 4823 | end |
| 4824 | ra = matreg get fr ix get fr add ix 1 ty |
| 4825 | bk = get fr add ix 3 |
| 4826 | bn = get fr add ix 4 |
| 4827 | w = twid ty |
| 4828 | rb = ulong 0 |
| 4829 | useimm = false |
| 4830 | if and eq bk 3 lt bn w |
| 4831 | useimm = true |
| 4832 | rb = bn |
| 4833 | else |
| 4834 | rb = matreg bk bn get fr add ix 5 |
| 4835 | bo_schk ty rb |
| 4836 | end |
| 4837 | rd = destreg dst |
| 4838 | if useimm |
| 4839 | s = rb |
| 4840 | if and eq op 60 ne s 0 |
| 4841 | s = sub w s |
| 4842 | end |
| 4843 | rotimm ty ra s rd |
| 4844 | else |
| 4845 | rr = rb |
| 4846 | if eq op 60 |
| 4847 | rr = alloc |
| 4848 | if ne get xtarget 0 0 |
| 4849 | xload 0 rb |
| 4850 | xb 72 247 216 |
| 4851 | xstore 0 rr |
| 4852 | else |
| 4853 | emit or or 3405775840 shl rb 16 rr |
| 4854 | end |
| 4855 | end |
| 4856 | rotreg ty ra rr rd |
| 4857 | end |
| 4858 | put rk 0 1 |
| 4859 | put rv 0 rd |
| 4860 | put rt 0 ty |
| 4861 | end |
| 4862 | |
| 4863 | note binop: op 33..48, destination (255 none), ix the fr slot of a (kind, number/register, type) then b. |
| 4864 | note Result in rk/rv/rt. om4 BINOP. A float op reads its operands as v registers; with a request (fpo) |
| 4865 | note the result stays in a twin (kind 9), else it moves to x (kind 1). |
| 4866 | fn binop op ulong dst ulong ix ulong to void |
| 4867 | if ne get fzone 0 0 |
| 4868 | if and eq get fr ix 3 eq get fr add ix 3 3 |
| 4869 | foldbin op get fr add ix 2 get fr add ix 1 get fr add ix 4 |
| 4870 | if ne get fok 0 0 |
| 4871 | put rk 0 3 |
| 4872 | put rv 0 get fval 0 |
| 4873 | put rt 0 get fty 0 |
| 4874 | ret |
| 4875 | end |
| 4876 | end |
| 4877 | end |
| 4878 | if or eq op 59 eq op 60 |
| 4879 | binrot op dst ix |
| 4880 | ret |
| 4881 | end |
| 4882 | ty = get fr add ix 2 |
| 4883 | if ne isfloat ty 0 |
| 4884 | if ne get xtarget 0 0 |
| 4885 | xfbinop op dst ix ty |
| 4886 | ret |
| 4887 | end |
| 4888 | o = get fpo 0 |
| 4889 | put fpo 0 0 |
| 4890 | va = fvop get fr ix get fr add ix 1 ty 0 |
| 4891 | vb = fvop get fr add ix 3 get fr add ix 4 ty 1 |
| 4892 | if ge op 43 |
| 4893 | fp_cmp op ty va vb |
| 4894 | ret |
| 4895 | end |
| 4896 | if or or lt op 33 gt op 36 ge op 41 |
| 4897 | fail 7 |
| 4898 | end |
| 4899 | if eq o 0 |
| 4900 | rd = destreg dst |
| 4901 | fp_binop op ty va vb 2 |
| 4902 | fv2x ty 2 rd |
| 4903 | put rk 0 1 |
| 4904 | put rv 0 rd |
| 4905 | else |
| 4906 | r = fvdst o |
| 4907 | fp_binop op ty va vb vtw r |
| 4908 | put rk 0 9 |
| 4909 | put rv 0 r |
| 4910 | end |
| 4911 | put rt 0 ty |
| 4912 | ret |
| 4913 | end |
| 4914 | ra = matreg get fr ix get fr add ix 1 ty |
| 4915 | if eq ty 13 |
| 4916 | if and ge op 38 le op 42 |
| 4917 | fail 7 |
| 4918 | end |
| 4919 | end |
| 4920 | imm = ulong 0 |
| 4921 | bk = get fr add ix 3 |
| 4922 | bn = get fr add ix 4 |
| 4923 | rb = ulong 0 |
| 4924 | useimm = false |
| 4925 | if eq bk 3 |
| 4926 | if or eq op 41 eq op 42 |
| 4927 | if lt bn twid ty |
| 4928 | useimm = true |
| 4929 | end |
| 4930 | else |
| 4931 | if or lt op 35 ge op 43 |
| 4932 | if le bn 4095 |
| 4933 | useimm = true |
| 4934 | end |
| 4935 | end |
| 4936 | end |
| 4937 | end |
| 4938 | if useimm |
| 4939 | rb = bn |
| 4940 | imm = ulong 1 |
| 4941 | else |
| 4942 | rb = matreg bk bn get fr add ix 5 |
| 4943 | end |
| 4944 | if ge op 43 |
| 4945 | bo_cmp op ty ra rb imm |
| 4946 | ret |
| 4947 | end |
| 4948 | if eq ty 1 |
| 4949 | if gt sub op 38 2 |
| 4950 | fail 7 |
| 4951 | end |
| 4952 | end |
| 4953 | rd = destreg dst |
| 4954 | if lt op 35 |
| 4955 | bo_add op ty ra rb imm rd |
| 4956 | else |
| 4957 | if eq op 35 |
| 4958 | bo_mul ty ra rb rd |
| 4959 | else |
| 4960 | if lt op 38 |
| 4961 | fl = ulong 0 |
| 4962 | if and eq bk 3 ne bn 0 |
| 4963 | fl = or fl 1 |
| 4964 | end |
| 4965 | if and eq bk 3 ne bn 18446744073709551615 |
| 4966 | fl = or fl 2 |
| 4967 | end |
| 4968 | bo_div op ty ra rb rd fl |
| 4969 | else |
| 4970 | if lt op 41 |
| 4971 | bo_log op ra rb rd |
| 4972 | else |
| 4973 | if eq op 41 |
| 4974 | bo_shl ty ra rb imm rd |
| 4975 | else |
| 4976 | bo_shr ty ra rb imm rd |
| 4977 | end |
| 4978 | end |
| 4979 | end |
| 4980 | end |
| 4981 | end |
| 4982 | put rk 0 1 |
| 4983 | put rv 0 rd |
| 4984 | put rt 0 ty |
| 4985 | end |
| 4986 | |
| 4987 | note ======== calls: registers saved around a call and loaded back ======== |
| 4988 | global svn ulong 1 |
| 4989 | global sva ulong 1 |
| 4990 | note save: n = registers in use (parameters + pool slots), A = 8 (n + 1) rounded up to 16: SUB SP, SP, #A |
| 4991 | note (C6.2.457); the stack check; STR Xr, [SP, #8j] for each (C6.2.415), or STR Dj+16 (SIMD&FP, C7.2.331) |
| 4992 | note for a slot living in its twin (vsl); STR X30, [SP, #8n]. Out: svn n, sva A. om4 SAVE. |
| 4993 | fn save to void |
| 4994 | if ne get xtarget 0 0 |
| 4995 | put svn 0 add get npar 0 get nslot 0 |
| 4996 | put sva 0 256 |
| 4997 | xsp 1 256 |
| 4998 | j = ulong 0 |
| 4999 | while lt j 18 |
| 5000 | xload 0 j |
| 5001 | xmem 137 0 4 mul j 8 |
| 5002 | j = add j 1 |
| 5003 | end |
| 5004 | note Reserve the callee's return address, frame pointer and slot area before CALL. |
| 5005 | xcheck 272 |
| 5006 | ret |
| 5007 | end |
| 5008 | n = add get npar 0 get nslot 0 |
| 5009 | a = shl shr add n 2 1 4 |
| 5010 | put svn 0 n |
| 5011 | put sva 0 a |
| 5012 | spsub a |
| 5013 | stkchk |
| 5014 | j = ulong 0 |
| 5015 | while lt j n |
| 5016 | if ne get vsl j 0 |
| 5017 | emit or or 4244636640 add j 16 shl j 10 |
| 5018 | else |
| 5019 | emit or or 4177527776 poolc j shl j 10 |
| 5020 | end |
| 5021 | j = add j 1 |
| 5022 | end |
| 5023 | emit or 4177527806 shl n 10 |
| 5024 | end |
| 5025 | |
| 5026 | note loadarg: register t from an argument: kind 1, 5 or 9 a register v, read back from its save slot (LDR |
| 5027 | note Xt, [SP, #8 slot], C6.2.216; a kind 9 slot holds the twin's D bits, the same bit pattern); kind 3, 6 |
| 5028 | note or 7 the number, address or float bits v. om4 LOADARG. |
| 5029 | fn loadarg t ulong k ulong v ulong to void |
| 5030 | if ne get xtarget 0 0 |
| 5031 | xarg t k v |
| 5032 | ret |
| 5033 | end |
| 5034 | if or or eq k 3 eq k 6 eq k 7 |
| 5035 | matconst t v |
| 5036 | ret |
| 5037 | end |
| 5038 | emit or or 4181722080 t shl regidx v 10 |
| 5039 | end |
| 5040 | |
| 5041 | note basearg: register t = the base of array name e (index + 1): its register from the save area, or its |
| 5042 | note address. om4 BASEARG. |
| 5043 | fn basearg t ulong e ulong to void |
| 5044 | i = sub e 1 |
| 5045 | if ge get nm_kind i 4 |
| 5046 | mataddr t get nm_addr i |
| 5047 | ret |
| 5048 | end |
| 5049 | loadarg t 1 ulong get nm_reg i |
| 5050 | end |
| 5051 | |
| 5052 | note restore: d destination (255: a new temporary at pool slot `slot`), slot the pool slot before the |
| 5053 | note arguments, n saved count, a save bytes, res 1 if there is a result in X0. MOV Xd, X0 (C6.2.282); LDR |
| 5054 | note each register in use before the arguments except Xd (C6.2.216), or LDR Dj+16 (C7.2.191) instead for a |
| 5055 | note slot living in its twin; LDR X30; ADD SP, SP, #A (C6.2.5). Returns Xd (255 when no result). om4 |
| 5056 | note RESTORE. |
| 5057 | fn restore d ulong slot ulong n ulong a ulong res ulong to ulong |
| 5058 | if ne get xtarget 0 0 |
| 5059 | ret xrestore d slot res |
| 5060 | end |
| 5061 | put nslot 0 slot |
| 5062 | rd = ulong 255 |
| 5063 | if ne res 0 |
| 5064 | rd = d |
| 5065 | if eq d 255 |
| 5066 | rd = alloc |
| 5067 | end |
| 5068 | if ne rd 0 |
| 5069 | emit or 2852127712 rd |
| 5070 | end |
| 5071 | end |
| 5072 | m = add get npar 0 slot |
| 5073 | j = ulong 0 |
| 5074 | while lt j m |
| 5075 | r = poolc j |
| 5076 | if ne get vsl j 0 |
| 5077 | emit or or 4248830944 add j 16 shl j 10 |
| 5078 | else |
| 5079 | if ne r rd |
| 5080 | emit or or 4181722080 r shl j 10 |
| 5081 | end |
| 5082 | end |
| 5083 | j = add j 1 |
| 5084 | end |
| 5085 | emit or 4181722110 shl n 10 |
| 5086 | spadd a |
| 5087 | ret rd |
| 5088 | end |
| 5089 | |
| 5090 | note ca_bl: BL to function f (index + 1), C6.2.43 |
| 5091 | fn ca_bl f ulong to void |
| 5092 | n = get ncalls 0 |
| 5093 | if ge n 524288 |
| 5094 | fail 14 |
| 5095 | end |
| 5096 | put callsite n get oc 0 |
| 5097 | put callfrom n get curfn 0 |
| 5098 | put callto n f |
| 5099 | put ncalls 0 add n 1 |
| 5100 | |
| 5101 | if ne get xtarget 0 0 |
| 5102 | emitb 232 |
| 5103 | xword 0 |
| 5104 | else |
| 5105 | emit or 2483027968 bdisp get oc 0 get fn_addr sub f 1 26 |
| 5106 | end |
| 5107 | end |
| 5108 | |
| 5109 | note ======== element addresses and array arguments ======== |
| 5110 | global ea_b ulong 1 |
| 5111 | global ea_i ulong 1 |
| 5112 | global ea_k ulong 1 |
| 5113 | |
| 5114 | note eaem: the load or store word base (LDOP / STOP register-offset form) of register rt at ea_b / ea_i. |
| 5115 | note ea_i 255 (OM-2, a number index k = ea_k up to 4095): the unsigned-offset form instead, same size, V |
| 5116 | note (bit 26, the SIMD&FP forms) and opc bits, imm12 = k scaled by the element size (LDR/STR (immediate), |
| 5117 | note C6.2.216 and its family; C7.2.191/C7.2.331). |
| 5118 | fn eaem wd ulong rg ulong to void |
| 5119 | b = get ea_b 0 |
| 5120 | if eq get ea_i 0 255 |
| 5121 | emit or or or or and wd 3300917248 956301312 shl get ea_k 0 10 shl b 5 rg |
| 5122 | ret |
| 5123 | end |
| 5124 | emit or or or wd rg shl b 5 shl get ea_i 0 16 |
| 5125 | end |
| 5126 | note elemaddr: array name e (index + 1), index value (kind, number or register, type). A number index must |
| 5127 | note be inside the array (error 21) and needs no check; a register index: CMP Xi, #len (C6.2.96) or CMP Xi, |
| 5128 | note Xt (C6.2.97), B.HS trap 3 (unsigned, so a negative signed index traps too). Out: ea_b base register |
| 5129 | note (the array's register, or a new one holding its address), ea_i index register. om4 ELEMADDR. |
| 5130 | note OM-2 unsized array (unsz): every index, a number too, is checked against its count register nm_lr |
| 5131 | note (CMP Xi, Xn; B.HS trap 3); none is eliminated (spec 4, 6). |
| 5132 | fn elemaddr e ulong k ulong v ulong t ulong to void |
| 5133 | if ne get xtarget 0 0 |
| 5134 | xelem e k v t |
| 5135 | ret |
| 5136 | end |
| 5137 | if or or eq t 1 eq t 10 eq t 11 |
| 5138 | fail 7 |
| 5139 | end |
| 5140 | i = sub e 1 |
| 5141 | ln = get nm_len i |
| 5142 | x = v |
| 5143 | if ne unsz i 0 |
| 5144 | x = matreg k v t |
| 5145 | emit or or 3942645791 shl ulong get nm_lr i 16 shl x 5 |
| 5146 | trapc 2 3 |
| 5147 | else |
| 5148 | if eq k 3 |
| 5149 | if ge v ln |
| 5150 | fail 21 |
| 5151 | end |
| 5152 | if and ne get om2 0 0 le v 4095 |
| 5153 | x = ulong 255 |
| 5154 | put ea_k 0 v |
| 5155 | else |
| 5156 | x = alloc |
| 5157 | matconst x v |
| 5158 | end |
| 5159 | else |
| 5160 | if le ln 4095 |
| 5161 | emit or or 4043309087 shl ln 10 shl v 5 |
| 5162 | else |
| 5163 | y = alloc |
| 5164 | matconst y ln |
| 5165 | emit or or 3942645791 shl y 16 shl v 5 |
| 5166 | end |
| 5167 | trapc 2 3 |
| 5168 | end |
| 5169 | end |
| 5170 | put ea_i 0 x |
| 5171 | if ge get nm_kind i 4 |
| 5172 | b = alloc |
| 5173 | matconst b get nm_addr i |
| 5174 | put ea_b 0 b |
| 5175 | else |
| 5176 | put ea_b 0 ulong get nm_reg i |
| 5177 | end |
| 5178 | end |
| 5179 | |
| 5180 | note aa_word: the next word of an array argument must be a name of at most 8 bytes |
| 5181 | fn aa_word to void |
| 5182 | tok |
| 5183 | k = get tk 0 |
| 5184 | if eq k 0 |
| 5185 | fail 4 |
| 5186 | end |
| 5187 | if ne k 1 |
| 5188 | fail 16 |
| 5189 | end |
| 5190 | if gt get tl 0 8 |
| 5191 | fail 13 |
| 5192 | end |
| 5193 | end |
| 5194 | |
| 5195 | note arrarg: an array argument for parameter pi of function f (index + 1): [view | edit] NAME. Its type and |
| 5196 | note length must equal the parameter's; an edit parameter needs a writable array (local or edit, error 20; |
| 5197 | note a view passed to it is error 20, OMEGESE.md 9.4); a global is never passed (error 19). Out: rk 5 |
| 5198 | note (register rv) or 6 (address rv, a text), rt the name entry. om4 ARRARG. |
| 5199 | note OM-2: an unsized parameter (length 0) takes an array of any length (erratum E2), whose count goes to |
| 5200 | note ul_k / ul_v at depth * 6 + pi: its count register, or its length as a number. `part` is read by arrpart. |
| 5201 | fn arrarg f ulong pi ulong to void |
| 5202 | md = ulong 0 |
| 5203 | aa_word |
| 5204 | w = get tw 0 |
| 5205 | c = kw w |
| 5206 | if ne c 0 |
| 5207 | if eq c 193 |
| 5208 | arrpart f pi 0 |
| 5209 | ret |
| 5210 | end |
| 5211 | if or lt c 57 gt c 58 |
| 5212 | fail 16 |
| 5213 | end |
| 5214 | md = c |
| 5215 | aa_word |
| 5216 | w = get tw 0 |
| 5217 | if eq kw w 193 |
| 5218 | arrpart f pi md |
| 5219 | ret |
| 5220 | end |
| 5221 | end |
| 5222 | e = findname w |
| 5223 | if eq e 0 |
| 5224 | fail 3 |
| 5225 | end |
| 5226 | i = sub e 1 |
| 5227 | k = ulong get nm_kind i |
| 5228 | if eq k 0 |
| 5229 | fail 7 |
| 5230 | end |
| 5231 | if ge k 6 |
| 5232 | fail 7 |
| 5233 | end |
| 5234 | if eq k 4 |
| 5235 | fail 19 |
| 5236 | end |
| 5237 | p = add mul sub f 1 6 pi |
| 5238 | if eq get fn_pk p 3 |
| 5239 | if eq md 57 |
| 5240 | fail 20 |
| 5241 | end |
| 5242 | if and ne k 1 ne k 3 |
| 5243 | fail 20 |
| 5244 | end |
| 5245 | else |
| 5246 | if eq md 58 |
| 5247 | fail 7 |
| 5248 | end |
| 5249 | end |
| 5250 | if ne get nm_type i get fn_pt p |
| 5251 | fail 7 |
| 5252 | end |
| 5253 | ux = add mul get depth 0 6 pi |
| 5254 | if eq get fn_pl p 0 |
| 5255 | if ne unsz i 0 |
| 5256 | put ul_k ux 1 |
| 5257 | put ul_v ux ulong get nm_lr i |
| 5258 | else |
| 5259 | put ul_k ux 3 |
| 5260 | put ul_v ux get nm_len i |
| 5261 | end |
| 5262 | else |
| 5263 | if ne get nm_len i get fn_pl p |
| 5264 | fail 7 |
| 5265 | end |
| 5266 | end |
| 5267 | put rt 0 e |
| 5268 | if eq k 5 |
| 5269 | put rk 0 6 |
| 5270 | put rv 0 get nm_addr i |
| 5271 | else |
| 5272 | put rk 0 5 |
| 5273 | put rv 0 ulong get nm_reg i |
| 5274 | end |
| 5275 | end |
| 5276 | |
| 5277 | note arrpart (OM-2, spec 6): `part A o k` as argument pi of function f (index + 1); md 57 / 58 when `view` / |
| 5278 | note `edit` was written before it. A is a name (a global is error 19, a fresh array 27); o, then k, are |
| 5279 | note ulong values. Checks, in this order: o <= len A (CMP Xo, Xlen; B.HI trap 3), then k <= len A - o (SUB, |
| 5280 | note CMP, B.HI trap 3); the wrapped o + k is never formed. The part is a view of A + o * size with count k: |
| 5281 | note an edit when A is writable (local or edit) and no `view` was written, else a view. It goes only to an |
| 5282 | note unsized parameter (error 7). Out as arrarg; rt is A, so for error 19 the part counts as its base. |
| 5283 | fn arrpart f ulong pi ulong md ulong to void |
| 5284 | p = add mul sub f 1 6 pi |
| 5285 | e = arrname |
| 5286 | i = sub e 1 |
| 5287 | k = ulong get nm_kind i |
| 5288 | if ge k 6 |
| 5289 | fail 7 |
| 5290 | end |
| 5291 | if eq k 4 |
| 5292 | fail 19 |
| 5293 | end |
| 5294 | fz_arg e |
| 5295 | if eq get fn_pk p 3 |
| 5296 | if eq md 57 |
| 5297 | fail 20 |
| 5298 | end |
| 5299 | if and ne k 1 ne k 3 |
| 5300 | fail 20 |
| 5301 | end |
| 5302 | else |
| 5303 | if eq md 58 |
| 5304 | fail 7 |
| 5305 | end |
| 5306 | end |
| 5307 | if ne ulong get nm_type i ulong get fn_pt p |
| 5308 | fail 7 |
| 5309 | end |
| 5310 | if ne get fn_pl p 0 |
| 5311 | fail 7 |
| 5312 | end |
| 5313 | rdval 0 5 255 0 |
| 5314 | k = get rt 0 |
| 5315 | if and ne k 5 ne k 13 |
| 5316 | fail 7 |
| 5317 | end |
| 5318 | ro = matreg get rk 0 get rv 0 k |
| 5319 | rdval 0 5 255 0 |
| 5320 | k = get rt 0 |
| 5321 | if and ne k 5 ne k 13 |
| 5322 | fail 7 |
| 5323 | end |
| 5324 | rn = matreg get rk 0 get rv 0 k |
| 5325 | d = partck i ro rn |
| 5326 | ux = add mul get depth 0 6 pi |
| 5327 | put ul_k ux 1 |
| 5328 | put ul_v ux rn |
| 5329 | put rt 0 e |
| 5330 | put rk 0 5 |
| 5331 | put rv 0 d |
| 5332 | end |
| 5333 | |
| 5334 | note partck: the two checks of part (name index i, o in ro, k in rn), then the part's base register |
| 5335 | fn partck i ulong ro ulong rn ulong to ulong |
| 5336 | rl = ulong get nm_lr i |
| 5337 | if eq unsz i 0 |
| 5338 | rl = alloc |
| 5339 | matconst rl get nm_len i |
| 5340 | end |
| 5341 | if ne get xtarget 0 0 |
| 5342 | xcmp ro rl 0 |
| 5343 | xtrap 8 3 |
| 5344 | d = alloc |
| 5345 | xarith 34 5 rl ro 0 d |
| 5346 | xcmp rn d 0 |
| 5347 | xtrap 8 3 |
| 5348 | b = ulong get nm_reg i |
| 5349 | if eq get nm_kind i 5 |
| 5350 | b = alloc |
| 5351 | mataddr b get nm_addr i |
| 5352 | end |
| 5353 | xload 0 ro |
| 5354 | xb 72 193 224 |
| 5355 | emitb uchar tlog ulong get nm_type i |
| 5356 | xload 1 b |
| 5357 | xrr 1 0 1 |
| 5358 | xstore 0 d |
| 5359 | ret d |
| 5360 | end |
| 5361 | emit or or 3942645791 shl rl 16 shl ro 5 |
| 5362 | trapc 8 3 |
| 5363 | d = alloc |
| 5364 | e3 3405774848 d rl ro |
| 5365 | emit or or 3942645791 shl d 16 shl rn 5 |
| 5366 | trapc 8 3 |
| 5367 | b = ulong get nm_reg i |
| 5368 | if eq get nm_kind i 5 |
| 5369 | b = alloc |
| 5370 | matconst b get nm_addr i |
| 5371 | end |
| 5372 | emit or or or or 2332033024 shl ro 16 shl tlog ulong get nm_type i 10 shl b 5 d |
| 5373 | ret d |
| 5374 | end |
| 5375 | |
| 5376 | note ======== the parts of the value reader that read no further value ======== |
| 5377 | fn vdec to void |
| 5378 | if and ne get cpure 0 0 ge get rt 0 10 |
| 5379 | fail 30 |
| 5380 | end |
| 5381 | put depth 0 sub get depth 0 1 |
| 5382 | end |
| 5383 | |
| 5384 | note vdone: a value's result, and one nesting level less (om4 VT_RET) |
| 5385 | fn vdone k ulong v ulong t ulong to void |
| 5386 | put rk 0 k |
| 5387 | put rv 0 v |
| 5388 | put rt 0 t |
| 5389 | vdec |
| 5390 | end |
| 5391 | |
| 5392 | note fwreq: hand this depth's fpw request to the part that makes the value (fpo) |
| 5393 | fn fwreq to void |
| 5394 | put fpo 0 get fwv get depth 0 |
| 5395 | end |
| 5396 | |
| 5397 | note vt_un: neg / not of the value in rk/rv/rt (a bare number already refused). neg: NEG Xd, Xm (SUB from |
| 5398 | 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 |
| 5399 | note sign check; not: bool EOR Xd, Xn, #1 (C6.2.155), else MVN (ORN from XZR, C6.2.300), then the wrap. |
| 5400 | note om4 VU1 .. VU_E. Float neg: FNEG (C7.2.144) of the operand's v register; with a request (fpo) the |
| 5401 | note result stays in a twin (kind 9). |
| 5402 | fn vt_un c ulong dst ulong to void |
| 5403 | o = get fpo 0 |
| 5404 | put fpo 0 0 |
| 5405 | if ne get fzone 0 0 |
| 5406 | if eq get rk 0 3 |
| 5407 | foldun c get rt 0 get rv 0 |
| 5408 | if ne get fok 0 0 |
| 5409 | put rv 0 get fval 0 |
| 5410 | ret |
| 5411 | end |
| 5412 | end |
| 5413 | end |
| 5414 | if ne get xtarget 0 0 |
| 5415 | xunary c dst |
| 5416 | ret |
| 5417 | end |
| 5418 | ty = get rt 0 |
| 5419 | if or eq ty 10 eq ty 11 |
| 5420 | if eq c 50 |
| 5421 | fail 7 |
| 5422 | end |
| 5423 | va = fvop get rk 0 get rv 0 ty 0 |
| 5424 | if eq o 0 |
| 5425 | rd = destreg dst |
| 5426 | fp_neg ty va 1 |
| 5427 | fv2x ty 1 rd |
| 5428 | put rk 0 1 |
| 5429 | put rv 0 rd |
| 5430 | else |
| 5431 | r = fvdst o |
| 5432 | fp_neg ty va vtw r |
| 5433 | put rk 0 9 |
| 5434 | put rv 0 r |
| 5435 | end |
| 5436 | put rt 0 ty |
| 5437 | ret |
| 5438 | end |
| 5439 | ra = matreg get rk 0 get rv 0 ty |
| 5440 | rd = destreg dst |
| 5441 | if eq c 50 |
| 5442 | if eq ty 13 |
| 5443 | fail 7 |
| 5444 | end |
| 5445 | if eq ty 1 |
| 5446 | e3 3527409664 rd ra 0 |
| 5447 | else |
| 5448 | if eq ty 4 |
| 5449 | e3 706741216 rd 0 ra |
| 5450 | else |
| 5451 | e3 2854224864 rd 0 ra |
| 5452 | if lt ty 6 |
| 5453 | canon rd ty |
| 5454 | end |
| 5455 | end |
| 5456 | end |
| 5457 | else |
| 5458 | if or eq ty 1 eq ty 13 |
| 5459 | fail 7 |
| 5460 | end |
| 5461 | if eq ty 9 |
| 5462 | e3 3942646752 rd 0 ra |
| 5463 | trapc 6 1 |
| 5464 | else |
| 5465 | if eq ty 4 |
| 5466 | e3 1258292192 rd 0 ra |
| 5467 | else |
| 5468 | e3 3405775840 rd 0 ra |
| 5469 | if lt ty 6 |
| 5470 | canon rd ty |
| 5471 | else |
| 5472 | chkext rd ty 1 |
| 5473 | end |
| 5474 | end |
| 5475 | end |
| 5476 | end |
| 5477 | put rk 0 1 |
| 5478 | put rv 0 rd |
| 5479 | put rt 0 ty |
| 5480 | end |
| 5481 | |
| 5482 | note vt_conv: the value in rk/rv/rt converted to type tt (neither bool, error 9). Out of range when any bit |
| 5483 | 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 |
| 5484 | note signed type: the sign-extension check, trap 5. om4 VTT1 .. VC_OK. To a float with a request (fpo): the |
| 5485 | note conversion is made in a twin (kind 9); the same float type is left as it is. |
| 5486 | fn vt_conv tt ulong to void |
| 5487 | if ne get xtarget 0 0 |
| 5488 | xconv tt |
| 5489 | ret |
| 5490 | end |
| 5491 | o = get fpo 0 |
| 5492 | put fpo 0 0 |
| 5493 | ft = get rt 0 |
| 5494 | if or or or eq ft 10 eq ft 11 eq tt 10 eq tt 11 |
| 5495 | if or eq ft 13 eq tt 13 |
| 5496 | fail 7 |
| 5497 | end |
| 5498 | if eq ft 1 |
| 5499 | fail 9 |
| 5500 | end |
| 5501 | if eq tt 1 |
| 5502 | fail 9 |
| 5503 | end |
| 5504 | if and ne o 0 ne isfloat tt 0 |
| 5505 | if eq ft tt |
| 5506 | ret |
| 5507 | end |
| 5508 | ra = matreg get rk 0 get rv 0 ft |
| 5509 | r = fvdst o |
| 5510 | fp_tov ft tt ra vtw r |
| 5511 | put rk 0 9 |
| 5512 | put rv 0 r |
| 5513 | put rt 0 tt |
| 5514 | ret |
| 5515 | end |
| 5516 | ra = matreg get rk 0 get rv 0 ft |
| 5517 | rd = fp_conv ft tt ra |
| 5518 | put rk 0 1 |
| 5519 | put rv 0 rd |
| 5520 | put rt 0 tt |
| 5521 | ret |
| 5522 | end |
| 5523 | ra = matreg get rk 0 get rv 0 ft |
| 5524 | if eq ft 1 |
| 5525 | fail 9 |
| 5526 | end |
| 5527 | if eq tt 1 |
| 5528 | fail 9 |
| 5529 | end |
| 5530 | wf = twid ft |
| 5531 | wt = twid tt |
| 5532 | s = ulong 99 |
| 5533 | sgf = and ge ft 6 le ft 9 |
| 5534 | sgt = and ge tt 6 le tt 9 |
| 5535 | if eq sgf 0 |
| 5536 | if ne sgt 0 |
| 5537 | if ge wf wt |
| 5538 | s = sub wt 1 |
| 5539 | end |
| 5540 | else |
| 5541 | if gt wf wt |
| 5542 | s = wt |
| 5543 | end |
| 5544 | end |
| 5545 | else |
| 5546 | if eq sgt 0 |
| 5547 | s = wt |
| 5548 | if gt s 63 |
| 5549 | s = ulong 63 |
| 5550 | end |
| 5551 | else |
| 5552 | if gt wf wt |
| 5553 | chkext ra tt 5 |
| 5554 | end |
| 5555 | end |
| 5556 | end |
| 5557 | if ne s 99 |
| 5558 | t = alloc |
| 5559 | emit or or or 3544251392 t shl s 16 shl ra 5 |
| 5560 | trapsite or 3036676096 t 5 |
| 5561 | end |
| 5562 | put rk 0 1 |
| 5563 | put rv 0 ra |
| 5564 | put rt 0 tt |
| 5565 | end |
| 5566 | |
| 5567 | note vt_get: get A i with the index value in rk/rv/rt: the element address, then the load of the element |
| 5568 | note type, register offset (LDOP table). om4 VT_GET. A float element with a request (fpo) loads straight |
| 5569 | note into a twin: the same word with V (bit 26), LDR St/Dt (C7.2.192) (kind 9). |
| 5570 | fn vt_get e ulong dst ulong to void |
| 5571 | if ne get xtarget 0 0 |
| 5572 | elemaddr e get rk 0 get rv 0 get rt 0 |
| 5573 | st_ld get ea_b 0 get ea_i 0 ulong get nm_type sub e 1 dst |
| 5574 | ret |
| 5575 | end |
| 5576 | o = get fpo 0 |
| 5577 | put fpo 0 0 |
| 5578 | elemaddr e get rk 0 get rv 0 get rt 0 |
| 5579 | ty = ulong get nm_type sub e 1 |
| 5580 | if and ne o 0 ne isfloat ty 0 |
| 5581 | r = fvdst o |
| 5582 | eaem or ldop ty 67108864 vtw r |
| 5583 | put rk 0 9 |
| 5584 | put rv 0 r |
| 5585 | put rt 0 ty |
| 5586 | ret |
| 5587 | end |
| 5588 | rd = destreg dst |
| 5589 | eaem ldop ty rd |
| 5590 | put rk 0 1 |
| 5591 | put rv 0 rd |
| 5592 | put rt 0 ty |
| 5593 | end |
| 5594 | |
| 5595 | 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, |
| 5596 | note SUB C6.2.458). om4 VT_SYS. |
| 5597 | fn vs_chk e ulong ro ulong rn ulong to void |
| 5598 | if ne get xtarget 0 0 |
| 5599 | if ne get nm_type sub e 1 2 |
| 5600 | fail 7 |
| 5601 | end |
| 5602 | xload 1 rn |
| 5603 | if ne unsz sub e 1 0 |
| 5604 | xload 0 ulong get nm_lr sub e 1 |
| 5605 | else |
| 5606 | ximm 0 get nm_len sub e 1 |
| 5607 | end |
| 5608 | xrr 57 1 0 |
| 5609 | xtrap 8 3 |
| 5610 | xrr 41 0 1 |
| 5611 | xload 1 ro |
| 5612 | xrr 57 1 0 |
| 5613 | xtrap 8 3 |
| 5614 | ret |
| 5615 | end |
| 5616 | if ne get nm_type sub e 1 2 |
| 5617 | fail 7 |
| 5618 | end |
| 5619 | t = alloc |
| 5620 | l = ulong get nm_lr sub e 1 |
| 5621 | if eq unsz sub e 1 0 |
| 5622 | l = t |
| 5623 | matconst t get nm_len sub e 1 |
| 5624 | end |
| 5625 | emit or or 3942645791 shl rn 5 shl l 16 |
| 5626 | trapc 8 3 |
| 5627 | e3 3405774848 t l rn |
| 5628 | emit or or 3942645791 shl ro 5 shl t 16 |
| 5629 | trapc 8 3 |
| 5630 | end |
| 5631 | |
| 5632 | note vs_call: save the registers in use, X0 = fd, X1 = A + off (ADD through X16, C6.2.6), X2 = n, X8 = 63 |
| 5633 | note (read) or 64 (write) (MOVZ C6.2.285), SVC #0 (C6.2.466). om4 VT_SYS. |
| 5634 | fn vs_call c ulong fk ulong fv ulong e ulong ro ulong rn ulong to void |
| 5635 | if ne get xtarget 0 0 |
| 5636 | xio c fk fv e ro rn |
| 5637 | ret |
| 5638 | end |
| 5639 | save |
| 5640 | loadarg 0 fk fv |
| 5641 | basearg 1 e |
| 5642 | loadarg 16 1 ro |
| 5643 | emit 2333081633 |
| 5644 | loadarg 2 1 rn |
| 5645 | emit or 3531603976 shl add c 10 5 |
| 5646 | emit 3556769793 |
| 5647 | end |
| 5648 | |
| 5649 | note ca_scal: a scalar argument just read (rk/rv/rt) for parameter p: flags into a register; its type |
| 5650 | note must be the parameter's; stored at fr[q..q+2]. om4 CA1 .. CA_PUT. |
| 5651 | fn ca_scal p ulong q ulong to void |
| 5652 | if eq get rk 0 4 |
| 5653 | put rv 0 matreg 4 get rv 0 get rt 0 |
| 5654 | put rk 0 1 |
| 5655 | put rt 0 1 |
| 5656 | end |
| 5657 | if ne get rt 0 ulong get fn_pt p |
| 5658 | fail 7 |
| 5659 | end |
| 5660 | put fr q get rk 0 |
| 5661 | put fr add q 1 get rv 0 |
| 5662 | put fr add q 2 0 |
| 5663 | end |
| 5664 | |
| 5665 | note ca_arr: an array argument i of function f, call frame cb: one array passed twice is error 19. |
| 5666 | note om4 CA_ARR .. CA_PUT. |
| 5667 | fn ca_arr f ulong i ulong cb ulong to void |
| 5668 | arrarg f i |
| 5669 | j = ulong 0 |
| 5670 | while lt j i |
| 5671 | if eq get fr add add cb mul j 3 2 get rt 0 |
| 5672 | fail 19 |
| 5673 | end |
| 5674 | j = add j 1 |
| 5675 | end |
| 5676 | q = add cb mul i 3 |
| 5677 | put fr q get rk 0 |
| 5678 | put fr add q 1 get rv 0 |
| 5679 | put fr add q 2 get rt 0 |
| 5680 | end |
| 5681 | |
| 5682 | note ca_end: all arguments read: save, the arguments into X0.., BL, restore. Frame cb: 3 per argument, |
| 5683 | note then cb+18 the parameter count, cb+19 the pool slot before the arguments. om4 CA_DONE .. CA5. |
| 5684 | fn ca_end f ulong dst ulong cb ulong to void |
| 5685 | save |
| 5686 | np = get fr add cb 18 |
| 5687 | i = ulong 0 |
| 5688 | while lt i np |
| 5689 | q = add cb mul i 3 |
| 5690 | s = pslot sub f 1 i |
| 5691 | loadarg s get fr q get fr add q 1 |
| 5692 | if eq pwid add mul sub f 1 6 i 2 |
| 5693 | ux = add mul div cb 32 6 i |
| 5694 | loadarg add s 1 get ul_k ux get ul_v ux |
| 5695 | end |
| 5696 | i = add i 1 |
| 5697 | end |
| 5698 | ca_bl f |
| 5699 | hr = ulong 1 |
| 5700 | if eq get fn_ret sub f 1 12 |
| 5701 | hr = ulong 0 |
| 5702 | end |
| 5703 | n = get svn 0 |
| 5704 | a = get sva 0 |
| 5705 | sl = get fr add cb 19 |
| 5706 | r = restore dst sl n a hr |
| 5707 | put rk 0 1 |
| 5708 | put rv 0 r |
| 5709 | put rt 0 ulong get fn_ret sub f 1 |
| 5710 | end |
| 5711 | |
| 5712 | note vs_fd, vs_arr, vs_off, vs_end: the steps of read / write between the values it reads, with the fd |
| 5713 | note (kind, value), the offset register and the pool slot before kept in fr[x+8..x+11] (om4's VT_SYS |
| 5714 | note frame slots 4, 5, 7 and 14) |
| 5715 | fn vs_fd x ulong to void |
| 5716 | if ne get rt 0 8 |
| 5717 | fail 7 |
| 5718 | end |
| 5719 | put fr add x 9 get rk 0 |
| 5720 | put fr add x 10 get rv 0 |
| 5721 | end |
| 5722 | |
| 5723 | fn vs_arr c ulong e ulong to void |
| 5724 | fz_arg e |
| 5725 | if ge get nm_kind sub e 1 6 |
| 5726 | fail 7 |
| 5727 | end |
| 5728 | if eq c 53 |
| 5729 | k = get nm_kind sub e 1 |
| 5730 | if or eq k 2 eq k 5 |
| 5731 | fail 20 |
| 5732 | end |
| 5733 | end |
| 5734 | end |
| 5735 | |
| 5736 | fn vs_off x ulong to void |
| 5737 | if ne get rt 0 5 |
| 5738 | fail 7 |
| 5739 | end |
| 5740 | put fr add x 11 matreg get rk 0 get rv 0 get rt 0 |
| 5741 | end |
| 5742 | |
| 5743 | fn vs_end c ulong e ulong dst ulong x ulong to void |
| 5744 | if ne get rt 0 5 |
| 5745 | fail 7 |
| 5746 | end |
| 5747 | rn = matreg get rk 0 get rv 0 get rt 0 |
| 5748 | ro = get fr add x 11 |
| 5749 | vs_chk e ro rn |
| 5750 | fk = get fr add x 9 |
| 5751 | fv = get fr add x 10 |
| 5752 | vs_call c fk fv e ro rn |
| 5753 | sl = get fr add x 8 |
| 5754 | n = get svn 0 |
| 5755 | a = get sva 0 |
| 5756 | r = restore dst sl n a 1 |
| 5757 | vdone 1 r 9 |
| 5758 | end |
| 5759 | |
| 5760 | note cnt_word: OM-2 `count A off n v`, a ulong: how many of the n uchar elements of A from off equal v. |
| 5761 | note A is an array name (a local, global, text, or a view or edit parameter, sized or unsized); off and n |
| 5762 | note are ulong, v is uchar. The four values are read left to right; then the slice is checked exactly as |
| 5763 | note read and write check theirs (vs_chk: a non-uchar A is error 7; n <= len A and off <= len A - n, else |
| 5764 | note trap 3), and only then is any element read, so an out-of-bounds slice traps 3 whatever v is and an |
| 5765 | note in-bounds one never traps. A tracked fresh array (error 27, fz_arg), a struct or layout (error 7) and |
| 5766 | note a contract clause (error 30, cp_token) are refused; an IR unit is never OM-2, so count is no word there |
| 5767 | note (error 3), and the irmode guard (error 9, as dit) only keeps it so. Code (AArch64): P = A + off |
| 5768 | note (ADD, C6.2.6), M = n (MOV = ORR), V0 = v in all 16 byte lanes (DUP), S = 0 (MOVZ, C6.2.285); then |
| 5769 | note while M >= 16 (CMP, C6.2.96; B.LO, C6.2.34): a block of K = min(M >> 4, 255) chunks (LSR = UBFM, |
| 5770 | note C6.2.487; CMP; B.LS; MOVZ X16, #255; V1 = 0 by MOVI, C7.2.247), each chunk LD1 {V2.16B}, [P], #16 |
| 5771 | note (post-index), CMEQ V2, V2, V0 (0xff where equal), SUB V1.16B, V1, V2 (+1 per equal lane; 255 chunks |
| 5772 | note keep each lane <= 255), SUB M, M, #16, SUBS X16, X16, #1, B.NE; then UADDLV H2, V1.16B (the 16 lanes, |
| 5773 | note at most 4080), UMOV W16, V2.H[0], ADD S, S, X16, B back (C6.2.35). The last M < 16 bytes one at a |
| 5774 | note time: CBZ M (C6.2.78), UMOV WK, V0.B[0], LDRB W16, [P], #1 (post-index), CMP W16, WK, CINC S, S, EQ |
| 5775 | note (CSINC), SUBS M, M, #1, B.NE. Every word is a fixed part from the instruction's Arm ARM encoding ORed |
| 5776 | note with register fields; each fixed part was checked against llvm-mc 18 at two or more register |
| 5777 | note choices. P, M, S and K are new temporaries, so no name's register changes; X16 is scratch; |
| 5778 | note V0-V2 carry nothing between operations (see scrub). The result moves to the destination after the |
| 5779 | note temporaries are given back. |
| 5780 | fn cnt_word dst ulong to void |
| 5781 | if ne get irmode 0 0 |
| 5782 | fail 9 |
| 5783 | end |
| 5784 | x = mul get depth 0 32 |
| 5785 | sl = get nslot 0 |
| 5786 | put fr add x 8 sl |
| 5787 | e = arrname |
| 5788 | fz_arg e |
| 5789 | if ge get nm_kind sub e 1 6 |
| 5790 | fail 7 |
| 5791 | end |
| 5792 | rdval 0 5 255 0 |
| 5793 | vs_off x |
| 5794 | rdval 0 5 255 0 |
| 5795 | if ne get rt 0 5 |
| 5796 | fail 7 |
| 5797 | end |
| 5798 | put fr add x 12 matreg get rk 0 get rv 0 get rt 0 |
| 5799 | rdval 0 2 255 0 |
| 5800 | if ne get rt 0 2 |
| 5801 | fail 7 |
| 5802 | end |
| 5803 | v = matreg get rk 0 get rv 0 get rt 0 |
| 5804 | ro = get fr add x 11 |
| 5805 | rn = get fr add x 12 |
| 5806 | vs_chk e ro rn |
| 5807 | if ne get xtarget 0 0 |
| 5808 | xcount e ro rn v |
| 5809 | put nslot 0 sl |
| 5810 | d = destreg dst |
| 5811 | xrr 137 0 2 |
| 5812 | xstore 0 d |
| 5813 | vdone 1 d 5 |
| 5814 | ret |
| 5815 | end |
| 5816 | s = cnt_a64 e ro rn v |
| 5817 | put nslot 0 sl |
| 5818 | d = destreg dst |
| 5819 | if ne d s |
| 5820 | emit or or 2852127712 d shl s 16 |
| 5821 | end |
| 5822 | vdone 1 d 5 |
| 5823 | end |
| 5824 | |
| 5825 | note cnt_a64: the AArch64 loop of cnt_word (see there), after vs_chk; gives S, the register of the count |
| 5826 | fn cnt_a64 e ulong ro ulong rn ulong v ulong to ulong |
| 5827 | i = sub e 1 |
| 5828 | p = alloc |
| 5829 | if ge get nm_kind i 4 |
| 5830 | matconst p get nm_addr i |
| 5831 | e3 2332033024 p p ro |
| 5832 | else |
| 5833 | e3 2332033024 p ulong get nm_reg i ro |
| 5834 | end |
| 5835 | m = alloc |
| 5836 | emit or or 2852127712 m shl rn 16 |
| 5837 | emit or 1308691456 shl v 5 |
| 5838 | s = alloc |
| 5839 | emit or 3531603968 s |
| 5840 | k = alloc |
| 5841 | emit or 4043325471 shl m 5 |
| 5842 | emit 1409286659 |
| 5843 | emit or 3544513552 shl m 5 |
| 5844 | emit 4043570719 |
| 5845 | emit 1409286217 |
| 5846 | emit 3531612144 |
| 5847 | emit 1862329345 |
| 5848 | emit or 1289711618 shl p 5 |
| 5849 | emit 1847626818 |
| 5850 | emit 1847755809 |
| 5851 | emit or or 3506454528 m shl m 5 |
| 5852 | emit 4043310608 |
| 5853 | emit 1426063201 |
| 5854 | emit 1848653858 |
| 5855 | emit 235027536 |
| 5856 | emit or or 2333081600 s shl s 5 |
| 5857 | emit 402653168 |
| 5858 | emit or 3019899104 m |
| 5859 | emit or 234961920 k |
| 5860 | emit or 943723536 shl p 5 |
| 5861 | emit or 1795162655 shl k 16 |
| 5862 | emit or or or 2592084992 s shl s 5 shl s 16 |
| 5863 | emit or or 4043310080 m shl m 5 |
| 5864 | emit 1426063233 |
| 5865 | ret s |
| 5866 | end |
| 5867 | |
| 5868 | note Native Linux ARM64 host operations. Encoding forms are those in seed/rung2/table.s2. |
| 5869 | note Syscall numbers and layouts: Linux asm-generic/unistd.h, fcntl.h and time.h. |
| 5870 | note No raw address or arbitrary syscall is exposed to an Omega program. |
| 5871 | fn hargc c ulong to ulong |
| 5872 | if eq c 107 |
| 5873 | ret 0 |
| 5874 | end |
| 5875 | if eq c 109 |
| 5876 | ret 0 |
| 5877 | end |
| 5878 | if eq c 129 |
| 5879 | ret 0 |
| 5880 | end |
| 5881 | if eq c 145 |
| 5882 | ret 0 |
| 5883 | end |
| 5884 | if eq c 146 |
| 5885 | ret 0 |
| 5886 | end |
| 5887 | if eq c 147 |
| 5888 | ret 0 |
| 5889 | end |
| 5890 | if eq c 148 |
| 5891 | ret 0 |
| 5892 | end |
| 5893 | if eq c 154 |
| 5894 | ret 0 |
| 5895 | end |
| 5896 | if eq c 158 |
| 5897 | ret 0 |
| 5898 | end |
| 5899 | if eq c 100 |
| 5900 | ret 1 |
| 5901 | end |
| 5902 | if eq c 101 |
| 5903 | ret 1 |
| 5904 | end |
| 5905 | if eq c 153 |
| 5906 | ret 1 |
| 5907 | end |
| 5908 | if eq c 155 |
| 5909 | ret 1 |
| 5910 | end |
| 5911 | if eq c 156 |
| 5912 | ret 1 |
| 5913 | end |
| 5914 | if eq c 159 |
| 5915 | ret 1 |
| 5916 | end |
| 5917 | if eq c 163 |
| 5918 | ret 1 |
| 5919 | end |
| 5920 | if eq c 164 |
| 5921 | ret 1 |
| 5922 | end |
| 5923 | if eq c 102 |
| 5924 | ret 2 |
| 5925 | end |
| 5926 | if eq c 105 |
| 5927 | ret 2 |
| 5928 | end |
| 5929 | if eq c 106 |
| 5930 | ret 2 |
| 5931 | end |
| 5932 | if eq c 127 |
| 5933 | ret 2 |
| 5934 | end |
| 5935 | if eq c 139 |
| 5936 | ret 2 |
| 5937 | end |
| 5938 | if eq c 160 |
| 5939 | ret 2 |
| 5940 | end |
| 5941 | if eq c 165 |
| 5942 | ret 2 |
| 5943 | end |
| 5944 | if eq c 197 |
| 5945 | ret 2 |
| 5946 | end |
| 5947 | ret 3 |
| 5948 | end |
| 5949 | fn hsysno c ulong to ulong |
| 5950 | if eq c 127 |
| 5951 | ret 129 |
| 5952 | end |
| 5953 | if eq c 129 |
| 5954 | ret 172 |
| 5955 | end |
| 5956 | if eq c 100 |
| 5957 | ret 57 |
| 5958 | end |
| 5959 | if eq c 101 |
| 5960 | ret 82 |
| 5961 | end |
| 5962 | if eq c 102 |
| 5963 | ret 52 |
| 5964 | end |
| 5965 | if eq c 103 |
| 5966 | ret 62 |
| 5967 | end |
| 5968 | if eq c 104 |
| 5969 | ret 198 |
| 5970 | end |
| 5971 | if eq c 139 |
| 5972 | ret 46 |
| 5973 | end |
| 5974 | if eq c 145 |
| 5975 | ret 174 |
| 5976 | end |
| 5977 | if eq c 146 |
| 5978 | ret 175 |
| 5979 | end |
| 5980 | if eq c 147 |
| 5981 | ret 176 |
| 5982 | end |
| 5983 | if eq c 148 |
| 5984 | ret 177 |
| 5985 | end |
| 5986 | if eq c 144 |
| 5987 | ret 48 |
| 5988 | end |
| 5989 | if eq c 153 |
| 5990 | ret 50 |
| 5991 | end |
| 5992 | if eq c 154 |
| 5993 | ret 173 |
| 5994 | end |
| 5995 | if eq c 155 |
| 5996 | ret 166 |
| 5997 | end |
| 5998 | if eq c 156 |
| 5999 | ret 83 |
| 6000 | end |
| 6001 | if eq c 157 |
| 6002 | ret 279 |
| 6003 | end |
| 6004 | if eq c 158 |
| 6005 | ret 157 |
| 6006 | end |
| 6007 | if eq c 159 |
| 6008 | ret 155 |
| 6009 | end |
| 6010 | if eq c 160 |
| 6011 | ret 154 |
| 6012 | end |
| 6013 | if eq c 163 |
| 6014 | ret 156 |
| 6015 | end |
| 6016 | if eq c 164 |
| 6017 | ret 267 |
| 6018 | end |
| 6019 | if eq c 165 |
| 6020 | ret 210 |
| 6021 | end |
| 6022 | if eq c 197 |
| 6023 | ret 32 |
| 6024 | end |
| 6025 | if eq c 105 |
| 6026 | ret 201 |
| 6027 | end |
| 6028 | if eq c 106 |
| 6029 | ret 242 |
| 6030 | end |
| 6031 | if eq c 107 |
| 6032 | ret 220 |
| 6033 | end |
| 6034 | ret 24 |
| 6035 | end |
| 6036 | fn harg x ulong i ulong ty ulong to void |
| 6037 | rdval 0 ty 255 0 |
| 6038 | if ne get rt 0 ty |
| 6039 | fail 7 |
| 6040 | end |
| 6041 | q = add add x 8 mul i 2 |
| 6042 | put fr q get rk 0 |
| 6043 | put fr add q 1 get rv 0 |
| 6044 | end |
| 6045 | fn hload x ulong i ulong reg ulong to void |
| 6046 | q = add add x 8 mul i 2 |
| 6047 | loadarg reg get fr q get fr add q 1 |
| 6048 | end |
| 6049 | fn hsys n ulong to void |
| 6050 | matconst 8 n |
| 6051 | emit 3556769793 |
| 6052 | end |
| 6053 | fn hreturn dst ulong x ulong to void |
| 6054 | sl = get fr add x 7 |
| 6055 | n = get svn 0 |
| 6056 | a = get sva 0 |
| 6057 | r = restore dst sl n a 1 |
| 6058 | vdone 1 r 9 |
| 6059 | end |
| 6060 | fn hscalar c ulong dst ulong x ulong to void |
| 6061 | np = hargc c |
| 6062 | for i ulong np |
| 6063 | ty = ulong 8 |
| 6064 | if or and eq c 103 eq i 1 and eq c 139 eq i 1 |
| 6065 | ty = ulong 9 |
| 6066 | end |
| 6067 | harg x i ty |
| 6068 | end |
| 6069 | note VFIO descriptor-kind state exists only in standalone programs, never in OM-2 unit contexts. |
| 6070 | if and ne get progmode 0 0 or eq c 100 eq c 108 |
| 6071 | if eq get fdtab 0 0 |
| 6072 | fdpool = get poolb 0 |
| 6073 | if gt fdpool 1073739776 |
| 6074 | fail 23 |
| 6075 | end |
| 6076 | put fdtab 0 add 276824064 fdpool |
| 6077 | put poolb 0 add fdpool 2048 |
| 6078 | end |
| 6079 | end |
| 6080 | save |
| 6081 | if and ne get progmode 0 0 eq c 100 |
| 6082 | hload x 0 10 |
| 6083 | fdforget |
| 6084 | end |
| 6085 | for i ulong np |
| 6086 | hload x i i |
| 6087 | end |
| 6088 | if eq c 106 |
| 6089 | hload x 1 3 |
| 6090 | matconst 1 0 |
| 6091 | matconst 2 0 |
| 6092 | end |
| 6093 | if eq c 107 |
| 6094 | matconst 0 17 |
| 6095 | for i ulong 5 |
| 6096 | matconst add i 1 0 |
| 6097 | end |
| 6098 | end |
| 6099 | hsys hsysno c |
| 6100 | if and ne get progmode 0 0 eq c 108 |
| 6101 | mimmed 4043309056 31 0 0 |
| 6102 | baddup = mbranch 11 |
| 6103 | hload x 1 10 |
| 6104 | fdforget |
| 6105 | patch19 baddup get oc 0 |
| 6106 | end |
| 6107 | hreturn dst x |
| 6108 | end |
| 6109 | fn hclock c ulong dst ulong x ulong to void |
| 6110 | save |
| 6111 | spsub 16 |
| 6112 | stkchk |
| 6113 | matconst 0 1 |
| 6114 | if eq c 130 |
| 6115 | matconst 0 0 |
| 6116 | end |
| 6117 | emit 2432697313 |
| 6118 | hsys 113 |
| 6119 | emit 4043309087 |
| 6120 | bad = get oc 0 |
| 6121 | emit 1409286155 |
| 6122 | emit 4181722081 |
| 6123 | emit 4181723106 |
| 6124 | note Reject overflow before seconds are multiplied; clock result is a signed nanosecond count. |
| 6125 | matconst 3 9223372036 |
| 6126 | e3 3942645760 31 1 3 |
| 6127 | trapc 8 1 |
| 6128 | matconst 3 1000000000 |
| 6129 | e3 2600500224 1 1 3 |
| 6130 | e3 2868903936 0 1 2 |
| 6131 | trapc 6 1 |
| 6132 | patch19 bad get oc 0 |
| 6133 | spadd 16 |
| 6134 | hreturn dst x |
| 6135 | end |
| 6136 | fn harray x ulong writable ulong to ulong |
| 6137 | e = arrname |
| 6138 | if ne get nm_type sub e 1 2 |
| 6139 | fail 7 |
| 6140 | end |
| 6141 | if ne writable 0 |
| 6142 | vs_arr 53 e |
| 6143 | end |
| 6144 | fz_arg e |
| 6145 | put fr add x 20 e |
| 6146 | harg x 0 5 |
| 6147 | harg x 1 5 |
| 6148 | ro = matreg get fr add x 8 get fr add x 9 5 |
| 6149 | rn = matreg get fr add x 10 get fr add x 11 5 |
| 6150 | put fr add x 21 ro |
| 6151 | put fr add x 22 rn |
| 6152 | vs_chk e ro rn |
| 6153 | ret e |
| 6154 | end |
| 6155 | note Copy a checked path to a private 4096-byte stack buffer. Reject embedded zero bytes. |
| 6156 | note Public paths remain length-delimited; only the kernel-facing private copy has a terminator. |
| 6157 | fn hpathcp x ulong to void |
| 6158 | e = get fr add x 20 |
| 6159 | save |
| 6160 | basearg 4 e |
| 6161 | loadarg 16 1 get fr add x 21 |
| 6162 | e3 2332033024 4 4 16 |
| 6163 | loadarg 5 1 get fr add x 22 |
| 6164 | matconst 6 4095 |
| 6165 | e3 3942645760 31 5 6 |
| 6166 | trapc 8 3 |
| 6167 | end |
| 6168 | fn hcopy to void |
| 6169 | spsub 4096 |
| 6170 | stkchk |
| 6171 | emit 2432697313 |
| 6172 | head = get oc 0 |
| 6173 | emit 4043309247 |
| 6174 | done = get oc 0 |
| 6175 | emit 1409286144 |
| 6176 | emit 960495750 |
| 6177 | emit 4043309279 |
| 6178 | trapc 0 3 |
| 6179 | emit 956301350 |
| 6180 | emit 2432697476 |
| 6181 | emit 2432697377 |
| 6182 | emit 3506439333 |
| 6183 | back head |
| 6184 | patch19 done get oc 0 |
| 6185 | emit 956301375 |
| 6186 | emit 2432697313 |
| 6187 | matconst 0 18446744073709551516 |
| 6188 | end |
| 6189 | fn hpath c ulong dst ulong x ulong to void |
| 6190 | e = harray x 0 |
| 6191 | if or eq c 110 eq c 151 |
| 6192 | harg x 2 8 |
| 6193 | harg x 3 8 |
| 6194 | end |
| 6195 | if or or or eq c 112 eq c 143 eq c 144 eq c 157 |
| 6196 | harg x 2 8 |
| 6197 | end |
| 6198 | if eq c 150 |
| 6199 | harg x 2 9 |
| 6200 | end |
| 6201 | hpathcp x |
| 6202 | if or eq c 110 eq c 151 |
| 6203 | hload x 2 2 |
| 6204 | hload x 3 3 |
| 6205 | end |
| 6206 | if eq c 111 |
| 6207 | matconst 2 0 |
| 6208 | end |
| 6209 | if eq c 126 |
| 6210 | matconst 2 512 |
| 6211 | end |
| 6212 | if eq c 112 |
| 6213 | hload x 2 2 |
| 6214 | end |
| 6215 | if or eq c 143 eq c 144 |
| 6216 | hload x 2 2 |
| 6217 | matconst 3 0 |
| 6218 | end |
| 6219 | if eq c 157 |
| 6220 | hload x 2 2 |
| 6221 | end |
| 6222 | if eq c 150 |
| 6223 | hload x 2 2 |
| 6224 | end |
| 6225 | hcopy |
| 6226 | nr = ulong 56 |
| 6227 | if or eq c 111 eq c 126 |
| 6228 | nr = ulong 35 |
| 6229 | end |
| 6230 | if eq c 112 |
| 6231 | nr = ulong 34 |
| 6232 | end |
| 6233 | if eq c 143 |
| 6234 | nr = ulong 53 |
| 6235 | end |
| 6236 | if eq c 144 |
| 6237 | nr = ulong 48 |
| 6238 | end |
| 6239 | if eq c 157 |
| 6240 | nr = ulong 279 |
| 6241 | end |
| 6242 | if eq c 150 |
| 6243 | nr = ulong 45 |
| 6244 | end |
| 6245 | if eq c 151 |
| 6246 | nr = ulong 54 |
| 6247 | end |
| 6248 | if eq c 138 |
| 6249 | nr = ulong 49 |
| 6250 | note hcopy leaves AT_FDCWD in X0 and the path in X1; chdir takes the path in X0. |
| 6251 | e3 2852126720 0 31 1 |
| 6252 | end |
| 6253 | if eq c 150 |
| 6254 | note truncate takes the path in X0 and the length in X1. |
| 6255 | e3 2852126720 0 31 1 |
| 6256 | e3 2852126720 1 31 2 |
| 6257 | end |
| 6258 | if eq c 151 |
| 6259 | note fchownat(dirfd, path, uid, gid, 0): X2/X3 are the ids, X4 is set after the copy. |
| 6260 | matconst 4 0 |
| 6261 | end |
| 6262 | if eq c 157 |
| 6263 | note memfd_create(name, flags): X0 = name, X1 = flags. |
| 6264 | e3 2852126720 0 31 1 |
| 6265 | e3 2852126720 1 31 2 |
| 6266 | end |
| 6267 | hsys nr |
| 6268 | spadd 4096 |
| 6269 | hreturn dst x |
| 6270 | end |
| 6271 | fn hbuffer c ulong dst ulong x ulong to void |
| 6272 | harg x 4 8 |
| 6273 | wr = ulong 0 |
| 6274 | if or or or or or eq c 113 eq c 116 eq c 117 eq c 118 eq c 131 eq c 224 |
| 6275 | wr = ulong 1 |
| 6276 | end |
| 6277 | e = harray x wr |
| 6278 | if or or eq c 116 eq c 118 eq c 119 |
| 6279 | harg x 2 8 |
| 6280 | end |
| 6281 | if or eq c 116 eq c 117 |
| 6282 | need = ulong 4 |
| 6283 | if eq c 117 |
| 6284 | need = ulong 128 |
| 6285 | end |
| 6286 | tmp = alloc |
| 6287 | matconst tmp need |
| 6288 | e3 3942645760 31 get fr add x 22 tmp |
| 6289 | trapc 3 3 |
| 6290 | end |
| 6291 | save |
| 6292 | hload x 4 0 |
| 6293 | basearg 1 e |
| 6294 | loadarg 16 1 get fr add x 21 |
| 6295 | e3 2332033024 1 1 16 |
| 6296 | loadarg 2 1 get fr add x 22 |
| 6297 | nr = ulong 61 |
| 6298 | if eq c 114 |
| 6299 | nr = ulong 203 |
| 6300 | end |
| 6301 | if eq c 115 |
| 6302 | nr = ulong 200 |
| 6303 | end |
| 6304 | if eq c 116 |
| 6305 | nr = ulong 260 |
| 6306 | hload x 2 2 |
| 6307 | matconst 3 0 |
| 6308 | end |
| 6309 | if eq c 117 |
| 6310 | nr = ulong 80 |
| 6311 | end |
| 6312 | if or eq c 118 eq c 119 |
| 6313 | nr = ulong 207 |
| 6314 | hload x 2 3 |
| 6315 | matconst 4 0 |
| 6316 | matconst 5 0 |
| 6317 | if eq c 119 |
| 6318 | nr = ulong 206 |
| 6319 | matconst 16 16384 |
| 6320 | e3 2852126720 3 3 16 |
| 6321 | end |
| 6322 | end |
| 6323 | |
| 6324 | if or eq c 131 eq c 224 |
| 6325 | note Socket-name queries use a private 32-bit socklen and return the full length. |
| 6326 | spsub 16 |
| 6327 | stkchk |
| 6328 | emit 3103785954 |
| 6329 | emit 2432697314 |
| 6330 | if eq c 224 |
| 6331 | hsys 205 |
| 6332 | else |
| 6333 | hsys 204 |
| 6334 | end |
| 6335 | emit 4043309087 |
| 6336 | failed = get oc 0 |
| 6337 | emit 1409286155 |
| 6338 | emit 3107980256 |
| 6339 | patch19 failed get oc 0 |
| 6340 | spadd 16 |
| 6341 | else |
| 6342 | hsys nr |
| 6343 | end |
| 6344 | hreturn dst x |
| 6345 | end |
| 6346 | fn hargs c ulong dst ulong x ulong to void |
| 6347 | if eq c 121 |
| 6348 | save |
| 6349 | emit 4181721952 |
| 6350 | hreturn dst x |
| 6351 | ret |
| 6352 | end |
| 6353 | if eq c 136 |
| 6354 | note envcnt: walk the environment vector X27 + 8*(argc+2) (after argv's own null word) until the |
| 6355 | note terminating null. |
| 6356 | save |
| 6357 | emit 4181721953 |
| 6358 | emit 2432698401 |
| 6359 | bo_lsl 1 3 1 |
| 6360 | e3 2332033024 0 27 1 |
| 6361 | matconst 2 0 |
| 6362 | lb = get oc 0 |
| 6363 | emit 4181721091 |
| 6364 | brend = get oc 0 |
| 6365 | emit 3019898883 |
| 6366 | emit 2432697410 |
| 6367 | emit 2432704512 |
| 6368 | back lb |
| 6369 | patch19 brend get oc 0 |
| 6370 | emit 2852258784 |
| 6371 | hreturn dst x |
| 6372 | ret |
| 6373 | end |
| 6374 | harg x 4 5 |
| 6375 | e = harray x 1 |
| 6376 | save |
| 6377 | hload x 4 0 |
| 6378 | if eq c 137 |
| 6379 | note envread: envp[index] lives at X27 + 8*(argc+2+index); scan the entries before it so an |
| 6380 | note index at or past the count traps 3 even when the vector is sparse or empty. |
| 6381 | emit 2852127714 |
| 6382 | emit 4181721953 |
| 6383 | emit 2432698401 |
| 6384 | e3 2852126720 0 31 1 |
| 6385 | matconst 16 8 |
| 6386 | emit 2601548800 |
| 6387 | e3 2332033024 3 27 0 |
| 6388 | lb = get oc 0 |
| 6389 | brend = get oc 0 |
| 6390 | emit 3019898882 |
| 6391 | emit 4181721188 |
| 6392 | emit 4043309215 |
| 6393 | trapc 0 3 |
| 6394 | emit 2432704611 |
| 6395 | emit 3506439234 |
| 6396 | back lb |
| 6397 | patch19 brend get oc 0 |
| 6398 | emit 4181721187 |
| 6399 | emit 4043309183 |
| 6400 | trapc 0 3 |
| 6401 | else |
| 6402 | emit 4181721953 |
| 6403 | e3 3942645760 31 0 1 |
| 6404 | trapc 2 3 |
| 6405 | emit 2432697344 |
| 6406 | matconst 16 8 |
| 6407 | e3 2600500224 0 0 16 |
| 6408 | e3 2332033024 3 27 0 |
| 6409 | emit 4181721187 |
| 6410 | end |
| 6411 | e3 2852126720 4 31 3 |
| 6412 | matconst 5 0 |
| 6413 | scan = get oc 0 |
| 6414 | emit 960495750 |
| 6415 | emit 4043309279 |
| 6416 | done = get oc 0 |
| 6417 | emit 1409286144 |
| 6418 | emit 2432697476 |
| 6419 | emit 2432697509 |
| 6420 | matconst 16 1048576 |
| 6421 | e3 3942645760 31 5 16 |
| 6422 | trapc 2 3 |
| 6423 | back scan |
| 6424 | patch19 done get oc 0 |
| 6425 | loadarg 2 1 get fr add x 22 |
| 6426 | e3 3942645760 31 5 2 |
| 6427 | small = get oc 0 |
| 6428 | emit 1409286152 |
| 6429 | basearg 0 e |
| 6430 | loadarg 16 1 get fr add x 21 |
| 6431 | e3 2332033024 0 0 16 |
| 6432 | e3 2852126720 2 31 5 |
| 6433 | copy = get oc 0 |
| 6434 | emit 4043309247 |
| 6435 | endcp = get oc 0 |
| 6436 | emit 1409286144 |
| 6437 | emit 960495718 |
| 6438 | emit 956301318 |
| 6439 | emit 2432697443 |
| 6440 | emit 2432697344 |
| 6441 | emit 3506439333 |
| 6442 | back copy |
| 6443 | patch19 endcp get oc 0 |
| 6444 | e3 2852126720 0 31 2 |
| 6445 | endbr = get oc 0 |
| 6446 | emit 335544320 |
| 6447 | patch19 small get oc 0 |
| 6448 | matconst 0 18446744073709551511 |
| 6449 | patch26 endbr get oc 0 |
| 6450 | hreturn dst x |
| 6451 | end |
| 6452 | |
| 6453 | note waitio(fd int, events int, timeout_ns long): revents, 0 timeout, or negative errno. |
| 6454 | note ppoll uses one private pollfd and one private timespec. Negative timeout is infinite. |
| 6455 | fn hwaitio dst ulong x ulong to void |
| 6456 | harg x 0 8 |
| 6457 | harg x 1 8 |
| 6458 | harg x 2 9 |
| 6459 | save |
| 6460 | hload x 0 0 |
| 6461 | hload x 1 1 |
| 6462 | hload x 2 2 |
| 6463 | note pollfd.events is 16 bits; refuse truncation of the public int argument. |
| 6464 | emit 4043309119 |
| 6465 | trapc 11 3 |
| 6466 | matconst 16 65535 |
| 6467 | e3 3942645760 31 1 16 |
| 6468 | trapc 8 3 |
| 6469 | spsub 32 |
| 6470 | stkchk |
| 6471 | emit 4177527807 |
| 6472 | emit 3103785952 |
| 6473 | emit 2030046177 |
| 6474 | matconst 3 1000000000 |
| 6475 | emit 4043309151 |
| 6476 | forever = get oc 0 |
| 6477 | emit 1409286155 |
| 6478 | e3 2596276224 4 2 3 |
| 6479 | emit 2600700037 |
| 6480 | emit 4177528804 |
| 6481 | emit 4177529829 |
| 6482 | emit 2432705506 |
| 6483 | jump = get oc 0 |
| 6484 | emit 335544320 |
| 6485 | patch19 forever get oc 0 |
| 6486 | matconst 2 0 |
| 6487 | patch26 jump get oc 0 |
| 6488 | emit 2432697312 |
| 6489 | matconst 1 1 |
| 6490 | matconst 3 0 |
| 6491 | matconst 4 8 |
| 6492 | hsys 73 |
| 6493 | emit 4043309087 |
| 6494 | failed = get oc 0 |
| 6495 | emit 1409286157 |
| 6496 | emit 2034241504 |
| 6497 | patch19 failed get oc 0 |
| 6498 | spadd 32 |
| 6499 | hreturn dst x |
| 6500 | end |
| 6501 | |
| 6502 | note A packed argument list is u16 count followed by count (u16 length, bytes) records. |
| 6503 | note Byte order is little-endian. The packet is at most 4096 bytes and 64 records. |
| 6504 | note The decoder constructs kernel pointers only in private stack memory. |
| 6505 | note execenv 233 (execenv A off n B off m) decodes a second packet, the environment, with the same |
| 6506 | note rules except that every record must be nonempty. Its base and length are loaded into x14/x15 |
| 6507 | note before SPSUB (save-area reads are SP-relative) and both packets are checked before any fd closes. |
| 6508 | note Stack: argv strings SP, argv pointers SP+4096, env strings SP+8192, env pointers SP+12288. |
| 6509 | fn hpack c ulong dst ulong x ulong to void |
| 6510 | errs = new ulong 16 0 |
| 6511 | tbl = new ulong 27 0 |
| 6512 | e = harray x 0 |
| 6513 | if eq c 125 |
| 6514 | harg x 2 8 |
| 6515 | end |
| 6516 | if eq c 233 |
| 6517 | put fr add x 23 e |
| 6518 | put fr add x 24 get fr add x 21 |
| 6519 | put fr add x 25 get fr add x 22 |
| 6520 | e = harray x 0 |
| 6521 | put fr add x 26 e |
| 6522 | put fr add x 27 get fr add x 21 |
| 6523 | put fr add x 28 get fr add x 22 |
| 6524 | put fr add x 20 get fr add x 23 |
| 6525 | put fr add x 21 get fr add x 24 |
| 6526 | put fr add x 22 get fr add x 25 |
| 6527 | e = get fr add x 23 |
| 6528 | end |
| 6529 | save |
| 6530 | basearg 4 e |
| 6531 | loadarg 16 1 get fr add x 21 |
| 6532 | e3 2332033024 4 4 16 |
| 6533 | loadarg 5 1 get fr add x 22 |
| 6534 | matconst 16 4096 |
| 6535 | e3 3942645760 31 5 16 |
| 6536 | trapc 8 3 |
| 6537 | emit 4043311295 |
| 6538 | trapc 3 3 |
| 6539 | if eq c 125 |
| 6540 | hload x 2 14 |
| 6541 | end |
| 6542 | note stack is 8192 bytes per packet: one packet pass, or two for execenv (the pass bound is stack >> 13). |
| 6543 | stack = ulong 8192 |
| 6544 | if eq c 233 |
| 6545 | note x14 = env base + off (ADD), x15 = env length; length 2..4096 (CMP x15,x16 B.HI; CMP x15,#2 B.LO). |
| 6546 | basearg 14 get fr add x 26 |
| 6547 | loadarg 16 1 get fr add x 27 |
| 6548 | e3 2332033024 14 14 16 |
| 6549 | loadarg 15 1 get fr add x 28 |
| 6550 | matconst 16 4096 |
| 6551 | e3 3942645760 31 15 16 |
| 6552 | trapc 8 3 |
| 6553 | emit 4043311615 |
| 6554 | trapc 3 3 |
| 6555 | stack = ulong 16384 |
| 6556 | end |
| 6557 | spsub stack |
| 6558 | stkchk |
| 6559 | pass = ulong 0 |
| 6560 | while lt pass shr stack 13 |
| 6561 | if eq pass 1 |
| 6562 | note MOV x4,x14; MOV x5,x15 (ORR with XZR): the environment packet. |
| 6563 | e3 2852126720 4 31 14 |
| 6564 | e3 2852126720 5 31 15 |
| 6565 | end |
| 6566 | emit 2034237574 |
| 6567 | emit 2432698500 |
| 6568 | emit 3506440357 |
| 6569 | emit 4043309279 |
| 6570 | trapc 0 3 |
| 6571 | matconst 16 64 |
| 6572 | e3 3942645760 31 6 16 |
| 6573 | trapc 8 3 |
| 6574 | if or or eq c 125 eq c 141 eq c 142 |
| 6575 | emit 4043311327 |
| 6576 | trapc 1 3 |
| 6577 | end |
| 6578 | matconst 9 0 |
| 6579 | if eq pass 0 |
| 6580 | emit 2432697322 |
| 6581 | emit 2436892651 |
| 6582 | else |
| 6583 | note ADD x10,SP,#2,LSL12; ADD x11,SP,#3,LSL12: env strings and env pointers. |
| 6584 | emit 2436893674 |
| 6585 | emit 2436894699 |
| 6586 | end |
| 6587 | outer = get oc 0 |
| 6588 | e3 3942645760 31 9 6 |
| 6589 | done = get oc 0 |
| 6590 | emit 1409286146 |
| 6591 | emit 4043311295 |
| 6592 | trapc 3 3 |
| 6593 | emit 2034237580 |
| 6594 | emit 2432698500 |
| 6595 | emit 3506440357 |
| 6596 | e3 3942645760 31 12 5 |
| 6597 | trapc 8 3 |
| 6598 | note A program path and both rename paths must be nonempty; every environment record is nonempty. |
| 6599 | note (Nested conditions keep om4 within its 16 live registers.) |
| 6600 | if eq pass 0 |
| 6601 | if or or eq c 124 eq c 198 eq c 233 |
| 6602 | emit 4043309375 |
| 6603 | notfirst = get oc 0 |
| 6604 | emit 1409286145 |
| 6605 | emit 4043309471 |
| 6606 | trapc 0 3 |
| 6607 | patch19 notfirst get oc 0 |
| 6608 | else |
| 6609 | emit 4043309471 |
| 6610 | trapc 0 3 |
| 6611 | end |
| 6612 | else |
| 6613 | emit 4043309471 |
| 6614 | trapc 0 3 |
| 6615 | end |
| 6616 | emit 4177527146 |
| 6617 | emit 2432704875 |
| 6618 | inner = get oc 0 |
| 6619 | emit 4043309471 |
| 6620 | endstr = get oc 0 |
| 6621 | emit 1409286144 |
| 6622 | emit 960495757 |
| 6623 | emit 4043309503 |
| 6624 | trapc 0 3 |
| 6625 | emit 956301645 |
| 6626 | emit 2432697476 |
| 6627 | emit 2432697674 |
| 6628 | emit 3506439333 |
| 6629 | emit 3506439564 |
| 6630 | back inner |
| 6631 | patch19 endstr get oc 0 |
| 6632 | emit 956301663 |
| 6633 | emit 2432697674 |
| 6634 | emit 2432697641 |
| 6635 | back outer |
| 6636 | patch19 done get oc 0 |
| 6637 | emit 4043309247 |
| 6638 | trapc 1 3 |
| 6639 | emit 4177527167 |
| 6640 | pass = add pass 1 |
| 6641 | end |
| 6642 | if or or eq c 124 eq c 198 eq c 233 |
| 6643 | note Exec admits only the caller-assigned standard streams. Linux close_range with UNSHARE |
| 6644 | note closes every descriptor >=3 in a private table. Failure returns without executing a child; |
| 6645 | note no guessed descriptor ceiling or permissive fallback. This is not filesystem isolation. |
| 6646 | matconst 0 3 |
| 6647 | matconst 1 4294967295 |
| 6648 | matconst 2 2 |
| 6649 | hsys 436 |
| 6650 | emit 4043309087 |
| 6651 | note outer and done are dead after the packet scan; they are reused for the two branch sites here. |
| 6652 | done = get oc 0 |
| 6653 | emit 1409286145 |
| 6654 | if eq c 198 |
| 6655 | note execpure strict stdio profile: Linux UAPI layouts in 640 private guest stack bytes, never an |
| 6656 | note exposed native pointer. sock_filter is u16 code,u8 jt,u8 jf,u32 k; sock_fprog has its length at |
| 6657 | note 0 and its pointer at 8 on AArch64. A Landlock path rule is a packed u64 allowed_access plus an |
| 6658 | note s32 parent_fd; prlimit64 takes two u64s. Each step that returns a negative value branches (B.LT) |
| 6659 | note to the common restore with the kernel error in x0. ADD x16,SP,#k then STR x0,[x16] stores a word. |
| 6660 | n = ulong 0 |
| 6661 | spsub 640 |
| 6662 | stkchk |
| 6663 | mimmed 2432697312 16 0 632 |
| 6664 | e3 4177526784 11 16 0 |
| 6665 | note Extra descriptors are already closed in a private table. Pin the executable as descriptor 3. |
| 6666 | matconst 0 18446744073709551516 |
| 6667 | mimmed 2432697312 1 0 640 |
| 6668 | matconst 2 2621440 |
| 6669 | matconst 3 0 |
| 6670 | hsys 56 |
| 6671 | emit 4043309087 |
| 6672 | put errs n get oc 0 |
| 6673 | emit 1409286155 |
| 6674 | n = add n 1 |
| 6675 | note ABI3 rights through TRUNCATE are all handled, with only read/execute of that one inode allowed. |
| 6676 | matconst 0 32767 |
| 6677 | mimmed 2432697312 16 0 0 |
| 6678 | e3 4177526784 0 16 0 |
| 6679 | mimmed 2432697312 0 0 0 |
| 6680 | matconst 1 8 |
| 6681 | matconst 2 0 |
| 6682 | hsys 444 |
| 6683 | emit 4043309087 |
| 6684 | put errs n get oc 0 |
| 6685 | emit 1409286155 |
| 6686 | n = add n 1 |
| 6687 | matconst 0 5 |
| 6688 | mimmed 2432697312 16 0 16 |
| 6689 | e3 4177526784 0 16 0 |
| 6690 | matconst 0 3 |
| 6691 | mimmed 2432697312 16 0 24 |
| 6692 | e3 4177526784 0 16 0 |
| 6693 | matconst 0 4 |
| 6694 | matconst 1 1 |
| 6695 | mimmed 2432697312 2 0 16 |
| 6696 | matconst 3 0 |
| 6697 | hsys 445 |
| 6698 | emit 4043309087 |
| 6699 | put errs n get oc 0 |
| 6700 | emit 1409286155 |
| 6701 | n = add n 1 |
| 6702 | matconst 0 38 |
| 6703 | matconst 1 1 |
| 6704 | matconst 2 0 |
| 6705 | matconst 3 0 |
| 6706 | matconst 4 0 |
| 6707 | hsys 167 |
| 6708 | emit 4043309087 |
| 6709 | put errs n get oc 0 |
| 6710 | emit 1409286155 |
| 6711 | n = add n 1 |
| 6712 | matconst 0 4 |
| 6713 | matconst 1 0 |
| 6714 | hsys 446 |
| 6715 | emit 4043309087 |
| 6716 | put errs n get oc 0 |
| 6717 | emit 1409286155 |
| 6718 | n = add n 1 |
| 6719 | matconst 0 4 |
| 6720 | hsys 57 |
| 6721 | emit 4043309087 |
| 6722 | put errs n get oc 0 |
| 6723 | emit 1409286155 |
| 6724 | n = add n 1 |
| 6725 | note Per-process ceilings as (resource, soft, hard): CPU, FSIZE, STACK, CORE, NPROC, NOFILE, AS. |
| 6726 | note Pipe-output and wall budgets additionally require the trusted supervisor. |
| 6727 | put tbl 1 1 |
| 6728 | put tbl 2 2 |
| 6729 | put tbl 3 1 |
| 6730 | put tbl 4 1048576 |
| 6731 | put tbl 5 1048576 |
| 6732 | put tbl 6 3 |
| 6733 | put tbl 7 8388608 |
| 6734 | put tbl 8 8388608 |
| 6735 | put tbl 9 4 |
| 6736 | put tbl 12 6 |
| 6737 | put tbl 15 7 |
| 6738 | put tbl 16 4 |
| 6739 | put tbl 17 4 |
| 6740 | put tbl 18 9 |
| 6741 | put tbl 19 134217728 |
| 6742 | put tbl 20 134217728 |
| 6743 | for i ulong 7 |
| 6744 | matconst 0 get tbl add mul i 3 1 |
| 6745 | mimmed 2432697312 16 0 48 |
| 6746 | e3 4177526784 0 16 0 |
| 6747 | matconst 0 get tbl add mul i 3 2 |
| 6748 | mimmed 2432697312 16 0 56 |
| 6749 | e3 4177526784 0 16 0 |
| 6750 | matconst 0 0 |
| 6751 | matconst 1 get tbl mul i 3 |
| 6752 | mimmed 2432697312 2 0 48 |
| 6753 | matconst 3 0 |
| 6754 | hsys 261 |
| 6755 | emit 4043309087 |
| 6756 | put errs n get oc 0 |
| 6757 | emit 1409286155 |
| 6758 | n = add n 1 |
| 6759 | end |
| 6760 | note Validate architecture, then read only 0, write only 1/2, exit/exit_group. Everything else is EPERM. |
| 6761 | note execveat is restricted to descriptor 3 and AT_EMPTY_PATH; Landlock also binds execution to inode 3. |
| 6762 | note The inode rule is essential: an absolute execveat path otherwise ignores its dirfd argument. |
| 6763 | note Entry i = code | jt<<16 | jf<<24 | k<<32, stored at SP+128+8i. (code jt jf k) rows in order: |
| 6764 | note (32 0 0 4) (21 1 0 3221225655) (6 0 0 2147483648) (32 0 0 0) (21 0 3 63) (32 0 0 16) (21 0 1 0) (6 0 0 2147418112) (32 0 0 0) |
| 6765 | note (21 0 4 64) (32 0 0 16) (21 1 0 1) (21 0 1 2) (6 0 0 2147418112) (32 0 0 0) (21 0 1 93) (6 0 0 2147418112) (21 0 1 94) |
| 6766 | note (6 0 0 2147418112) (32 0 0 0) (21 0 5 281) (32 0 0 16) (21 0 3 3) (32 0 0 48) (21 0 1 4096) (6 0 0 2147418112) (6 0 0 327681) |
| 6767 | put tbl 0 ulong 17179869216 |
| 6768 | put tbl 1 ulong 13835058841261244437 |
| 6769 | put tbl 2 ulong 9223372036854775814 |
| 6770 | put tbl 3 ulong 32 |
| 6771 | put tbl 4 ulong 270633271317 |
| 6772 | put tbl 5 ulong 68719476768 |
| 6773 | put tbl 6 ulong 16777237 |
| 6774 | put tbl 7 ulong 9223090561878065158 |
| 6775 | put tbl 8 ulong 32 |
| 6776 | put tbl 9 ulong 274945015829 |
| 6777 | put tbl 10 ulong 68719476768 |
| 6778 | put tbl 11 ulong 4295032853 |
| 6779 | put tbl 12 ulong 8606711829 |
| 6780 | put tbl 13 ulong 9223090561878065158 |
| 6781 | put tbl 14 ulong 32 |
| 6782 | put tbl 15 ulong 399448735765 |
| 6783 | put tbl 16 ulong 9223090561878065158 |
| 6784 | put tbl 17 ulong 403743703061 |
| 6785 | put tbl 18 ulong 9223090561878065158 |
| 6786 | put tbl 19 ulong 32 |
| 6787 | put tbl 20 ulong 1206969696277 |
| 6788 | put tbl 21 ulong 68719476768 |
| 6789 | put tbl 22 ulong 12935233557 |
| 6790 | put tbl 23 ulong 206158430240 |
| 6791 | put tbl 24 ulong 17592202821653 |
| 6792 | put tbl 25 ulong 9223090561878065158 |
| 6793 | put tbl 26 ulong 1407379178520582 |
| 6794 | for i ulong 27 |
| 6795 | matconst 0 get tbl i |
| 6796 | mimmed 2432697312 16 0 add 128 mul i 8 |
| 6797 | e3 4177526784 0 16 0 |
| 6798 | end |
| 6799 | matconst 0 27 |
| 6800 | mimmed 2432697312 16 0 80 |
| 6801 | e3 4177526784 0 16 0 |
| 6802 | mimmed 2432697312 0 0 128 |
| 6803 | mimmed 2432697312 16 0 88 |
| 6804 | e3 4177526784 0 16 0 |
| 6805 | matconst 0 1 |
| 6806 | matconst 1 0 |
| 6807 | mimmed 2432697312 2 0 80 |
| 6808 | hsys 277 |
| 6809 | emit 4043309087 |
| 6810 | put errs n get oc 0 |
| 6811 | emit 1409286155 |
| 6812 | n = add n 1 |
| 6813 | note Restore the original packet stack before entering the pinned executable. Descriptor 3 is CLOEXEC. |
| 6814 | mimmed 2432697312 16 0 632 |
| 6815 | e3 4181721088 11 16 0 |
| 6816 | spadd 640 |
| 6817 | matconst 0 3 |
| 6818 | e3 2852126720 1 31 11 |
| 6819 | emit 2436892642 |
| 6820 | e3 2852126720 3 31 11 |
| 6821 | matconst 4 4096 |
| 6822 | hsys 281 |
| 6823 | outer = get oc 0 |
| 6824 | emit 335544320 |
| 6825 | while gt n 0 |
| 6826 | n = sub n 1 |
| 6827 | patch19 get errs n get oc 0 |
| 6828 | end |
| 6829 | mimmed 2432697312 16 0 632 |
| 6830 | e3 4181721088 11 16 0 |
| 6831 | spadd 640 |
| 6832 | patch26 outer get oc 0 |
| 6833 | else |
| 6834 | emit 2432697312 |
| 6835 | emit 2436892641 |
| 6836 | if eq c 233 |
| 6837 | note ADD x2,SP,#3,LSL12: envp is the private environment pointer list. |
| 6838 | emit 2436894690 |
| 6839 | else |
| 6840 | note MOV x2,x11: envp is the argv list's NULL terminator, an empty environment. |
| 6841 | e3 2852126720 2 31 11 |
| 6842 | end |
| 6843 | hsys 221 |
| 6844 | end |
| 6845 | patch19 done get oc 0 |
| 6846 | else |
| 6847 | if eq c 125 |
| 6848 | emit 2436892656 |
| 6849 | emit 4181721601 |
| 6850 | emit 4181722627 |
| 6851 | matconst 0 18446744073709551516 |
| 6852 | matconst 2 18446744073709551516 |
| 6853 | e3 2852126720 4 31 14 |
| 6854 | hsys 276 |
| 6855 | else |
| 6856 | note linkat/symlnk: the packed list's two records are pointer-list entries 0 and 1. |
| 6857 | emit 2436892656 |
| 6858 | emit 4181721601 |
| 6859 | emit 4181722627 |
| 6860 | if eq c 141 |
| 6861 | matconst 0 18446744073709551516 |
| 6862 | matconst 2 18446744073709551516 |
| 6863 | matconst 4 0 |
| 6864 | hsys 37 |
| 6865 | else |
| 6866 | e3 2852126720 2 31 3 |
| 6867 | e3 2852126720 0 31 1 |
| 6868 | matconst 1 18446744073709551516 |
| 6869 | hsys 36 |
| 6870 | end |
| 6871 | end |
| 6872 | end |
| 6873 | spadd stack |
| 6874 | hreturn dst x |
| 6875 | end |
| 6876 | |
| 6877 | fn hreadlnk dst ulong x ulong to void |
| 6878 | e = harray x 0 |
| 6879 | put fr add x 23 e |
| 6880 | put fr add x 24 get fr add x 21 |
| 6881 | put fr add x 25 get fr add x 22 |
| 6882 | e = harray x 1 |
| 6883 | put fr add x 26 e |
| 6884 | put fr add x 27 get fr add x 21 |
| 6885 | put fr add x 28 get fr add x 22 |
| 6886 | put fr add x 20 get fr add x 23 |
| 6887 | put fr add x 21 get fr add x 24 |
| 6888 | put fr add x 22 get fr add x 25 |
| 6889 | hpathcp x |
| 6890 | note readlnk refuses an empty path before the kernel call. |
| 6891 | emit 4043309247 |
| 6892 | trapc 0 3 |
| 6893 | basearg 2 get fr add x 26 |
| 6894 | loadarg 16 1 get fr add x 27 |
| 6895 | e3 2332033024 2 2 16 |
| 6896 | loadarg 3 1 get fr add x 28 |
| 6897 | hcopy |
| 6898 | hsys 78 |
| 6899 | spadd 4096 |
| 6900 | hreturn dst x |
| 6901 | end |
| 6902 | note stat: path slice (readonly) + output slice, at least 128 bytes for the ARM64 stat structure. |
| 6903 | note Linux newfstatat(AT_FDCWD, path, out, 0); returns 0 or -errno. A short output traps 3. |
| 6904 | note pread/pwrite: fd, byte slice (off, n), position long. The file offset is not moved. |
| 6905 | note pread (161) writes A, so A must be writable (error 20); pwrite (162) only reads A, so a text is allowed. |
| 6906 | fn hpread c ulong dst ulong x ulong to void |
| 6907 | harg x 4 8 |
| 6908 | wr = ulong 0 |
| 6909 | if eq c 161 |
| 6910 | wr = ulong 1 |
| 6911 | end |
| 6912 | e = harray x wr |
| 6913 | harg x 3 9 |
| 6914 | save |
| 6915 | hload x 4 0 |
| 6916 | basearg 1 e |
| 6917 | loadarg 16 1 get fr add x 21 |
| 6918 | e3 2332033024 1 1 16 |
| 6919 | loadarg 2 1 get fr add x 22 |
| 6920 | hload x 3 3 |
| 6921 | nr = ulong 67 |
| 6922 | if eq c 162 |
| 6923 | nr = ulong 68 |
| 6924 | end |
| 6925 | hsys nr |
| 6926 | hreturn dst x |
| 6927 | end |
| 6928 | |
| 6929 | fn hstat c ulong dst ulong x ulong to void |
| 6930 | e = harray x 0 |
| 6931 | put fr add x 23 e |
| 6932 | put fr add x 24 get fr add x 21 |
| 6933 | put fr add x 25 get fr add x 22 |
| 6934 | e = harray x 1 |
| 6935 | put fr add x 26 e |
| 6936 | put fr add x 27 get fr add x 21 |
| 6937 | put fr add x 28 get fr add x 22 |
| 6938 | put fr add x 20 get fr add x 23 |
| 6939 | put fr add x 21 get fr add x 24 |
| 6940 | put fr add x 22 get fr add x 25 |
| 6941 | hpathcp x |
| 6942 | note stat refuses an empty path before the kernel call. |
| 6943 | emit 4043309247 |
| 6944 | trapc 0 3 |
| 6945 | basearg 2 get fr add x 26 |
| 6946 | loadarg 16 1 get fr add x 27 |
| 6947 | e3 2332033024 2 2 16 |
| 6948 | loadarg 3 1 get fr add x 28 |
| 6949 | matconst 6 128 |
| 6950 | e3 3942645760 31 3 6 |
| 6951 | trapc 3 3 |
| 6952 | matconst 3 0 |
| 6953 | if eq c 149 |
| 6954 | matconst 3 256 |
| 6955 | end |
| 6956 | hcopy |
| 6957 | hsys 79 |
| 6958 | spadd 4096 |
| 6959 | hreturn dst x |
| 6960 | end |
| 6961 | fn hsockopt dst ulong x ulong to void |
| 6962 | harg x 2 8 |
| 6963 | harg x 3 8 |
| 6964 | harg x 4 8 |
| 6965 | e = harray x 0 |
| 6966 | save |
| 6967 | hload x 2 0 |
| 6968 | hload x 3 1 |
| 6969 | hload x 4 2 |
| 6970 | basearg 3 e |
| 6971 | loadarg 16 1 get fr add x 21 |
| 6972 | e3 2332033024 3 3 16 |
| 6973 | loadarg 4 1 get fr add x 22 |
| 6974 | note Only scalar transport options; no filters, devices, credentials or pointer-bearing options. |
| 6975 | hoptgate |
| 6976 | hreturn dst x |
| 6977 | end |
| 6978 | |
| 6979 | note Socket option allowlist. Linux asm-generic/socket.h and linux/tcp.h own these IDs. |
| 6980 | note Unknown options retain ENOPROTOOPT (-92); malformed scalar sizes return EINVAL (-22). |
| 6981 | fn hoptgate to void |
| 6982 | ok = new ulong 6 0 |
| 6983 | mimmed 4043309056 31 1 1 |
| 6984 | tcp = get oc 0 |
| 6985 | emit 1409286145 |
| 6986 | for j ulong 5 |
| 6987 | v = add j 5 |
| 6988 | if eq j 0 |
| 6989 | v = ulong 2 |
| 6990 | end |
| 6991 | if eq j 1 |
| 6992 | v = ulong 15 |
| 6993 | end |
| 6994 | mimmed 4043309056 31 2 v |
| 6995 | put ok j get oc 0 |
| 6996 | emit 1409286144 |
| 6997 | end |
| 6998 | badso = get oc 0 |
| 6999 | emit 335544320 |
| 7000 | patch19 tcp get oc 0 |
| 7001 | mimmed 4043309056 31 1 6 |
| 7002 | badtcp = get oc 0 |
| 7003 | emit 1409286145 |
| 7004 | mimmed 4043309056 31 2 1 |
| 7005 | put ok 5 get oc 0 |
| 7006 | emit 1409286144 |
| 7007 | patch26 badso get oc 0 |
| 7008 | patch19 badtcp get oc 0 |
| 7009 | matconst 0 sub ulong 0 92 |
| 7010 | done = get oc 0 |
| 7011 | emit 335544320 |
| 7012 | for j ulong 6 |
| 7013 | patch19 get ok j get oc 0 |
| 7014 | end |
| 7015 | mimmed 4043309056 31 4 4 |
| 7016 | sizeok = get oc 0 |
| 7017 | emit 1409286144 |
| 7018 | matconst 0 sub ulong 0 22 |
| 7019 | badsize = get oc 0 |
| 7020 | emit 335544320 |
| 7021 | patch19 sizeok get oc 0 |
| 7022 | hsys 208 |
| 7023 | patch26 done get oc 0 |
| 7024 | patch26 badsize get oc 0 |
| 7025 | end |
| 7026 | |
| 7027 | note SO_PEERCRED: fixed 12-byte ucred result, never a caller-chosen getsockopt operation. |
| 7028 | fn hpeercr dst ulong x ulong to void |
| 7029 | harg x 4 8 |
| 7030 | e = harray x 1 |
| 7031 | save |
| 7032 | hload x 4 0 |
| 7033 | basearg 3 e |
| 7034 | loadarg 16 1 get fr add x 21 |
| 7035 | e3 2332033024 3 3 16 |
| 7036 | loadarg 4 1 get fr add x 22 |
| 7037 | matconst 16 12 |
| 7038 | e3 3942645760 31 4 16 |
| 7039 | trapc 3 3 |
| 7040 | matconst 1 1 |
| 7041 | matconst 2 17 |
| 7042 | spsub 16 |
| 7043 | stkchk |
| 7044 | matconst 4 12 |
| 7045 | emit or ulong 3103785952 4 |
| 7046 | emit or ulong 2432697312 4 |
| 7047 | hsys 209 |
| 7048 | spadd 16 |
| 7049 | hreturn dst x |
| 7050 | end |
| 7051 | |
| 7052 | note pollfds uses packed Linux pollfd records; length is bytes, each record is 8 bytes. |
| 7053 | note Maximum 1024 records, checked before ppoll. Kernel writes only revents in the checked slice. |
| 7054 | fn hpollfds dst ulong x ulong to void |
| 7055 | e = harray x 1 |
| 7056 | harg x 2 9 |
| 7057 | save |
| 7058 | basearg 0 e |
| 7059 | loadarg 16 1 get fr add x 21 |
| 7060 | e3 2332033024 0 0 16 |
| 7061 | loadarg 1 1 get fr add x 22 |
| 7062 | matconst 16 7 |
| 7063 | e3 2315255808 17 1 16 |
| 7064 | mimmed 4043309056 31 17 0 |
| 7065 | trapc 1 3 |
| 7066 | matconst 16 8192 |
| 7067 | e3 3942645760 31 1 16 |
| 7068 | trapc 8 3 |
| 7069 | matconst 16 8 |
| 7070 | e3 2596276224 1 1 16 |
| 7071 | hload x 2 2 |
| 7072 | spsub 16 |
| 7073 | stkchk |
| 7074 | matconst 3 1000000000 |
| 7075 | emit 4043309151 |
| 7076 | forever = get oc 0 |
| 7077 | emit 1409286155 |
| 7078 | e3 2596276224 4 2 3 |
| 7079 | emit 2600700037 |
| 7080 | emit 4177527780 |
| 7081 | emit 4177528805 |
| 7082 | emit or ulong 2432697312 2 |
| 7083 | jump = get oc 0 |
| 7084 | emit 335544320 |
| 7085 | patch19 forever get oc 0 |
| 7086 | matconst 2 0 |
| 7087 | patch26 jump get oc 0 |
| 7088 | matconst 3 0 |
| 7089 | matconst 4 8 |
| 7090 | hsys 73 |
| 7091 | spadd 16 |
| 7092 | hreturn dst x |
| 7093 | end |
| 7094 | |
| 7095 | note sendmsg has one checked iovec and no ancillary data or exposed kernel pointers. |
| 7096 | note Arm ARM STR unsigned offset: imm12 scaled by 8, Rn=SP; private msghdr then iovec. |
| 7097 | fn hsendmsg dst ulong x ulong to void |
| 7098 | harg x 4 8 |
| 7099 | e = harray x 0 |
| 7100 | harg x 2 8 |
| 7101 | save |
| 7102 | hload x 4 0 |
| 7103 | hload x 2 2 |
| 7104 | matconst 16 16384 |
| 7105 | e3 2852126720 2 2 16 |
| 7106 | basearg 3 e |
| 7107 | loadarg 16 1 get fr add x 21 |
| 7108 | e3 2332033024 3 3 16 |
| 7109 | loadarg 4 1 get fr add x 22 |
| 7110 | spsub 80 |
| 7111 | stkchk |
| 7112 | for j ulong 10 |
| 7113 | emit or or ulong 4177527776 31 shl j 10 |
| 7114 | end |
| 7115 | emit or or ulong 4177527776 3 shl ulong 8 10 |
| 7116 | emit or or ulong 4177527776 4 shl ulong 9 10 |
| 7117 | emit or or ulong 2432697312 3 shl ulong 64 10 |
| 7118 | emit or or ulong 4177527776 3 shl ulong 2 10 |
| 7119 | matconst 3 1 |
| 7120 | emit or or ulong 4177527776 3 shl ulong 3 10 |
| 7121 | emit or ulong 2432697312 1 |
| 7122 | hsys 211 |
| 7123 | spadd 80 |
| 7124 | hreturn dst x |
| 7125 | end |
| 7126 | |
| 7127 | note Bounded mapping table belongs to the emitted program, not the compiler process. |
| 7128 | note 128 slots of address, byte length, generation, access. Only owned spans are accessible. |
| 7129 | note Function mode has no program image: the caller's runtime table supplies the zero-initialised |
| 7130 | note 4096-byte table at entry 31 (mcheck and mnew load it from [x7, #248]); nothing is reserved here. |
| 7131 | fn mtinit to void |
| 7132 | if eq get progmode 0 0 |
| 7133 | ret |
| 7134 | end |
| 7135 | if eq get maptab 0 0 |
| 7136 | p = get poolb 0 |
| 7137 | if gt p 1073737728 |
| 7138 | fail 23 |
| 7139 | end |
| 7140 | put maptab 0 add 276824064 p |
| 7141 | put poolb 0 add p 4096 |
| 7142 | end |
| 7143 | end |
| 7144 | note Instruction forms in seed/rung2/table.s2. ldr/str offsets count eight-byte cells. |
| 7145 | fn mload d ulong n ulong off ulong to void |
| 7146 | emit or or or 4181721088 d shl n 5 shl off 10 |
| 7147 | end |
| 7148 | fn mstore d ulong n ulong off ulong to void |
| 7149 | emit or or or 4177526784 d shl n 5 shl off 10 |
| 7150 | end |
| 7151 | fn mimmed op ulong d ulong n ulong k ulong to void |
| 7152 | emit or or or op d shl n 5 shl k 10 |
| 7153 | end |
| 7154 | fn mbranch cc ulong to ulong |
| 7155 | p = get oc 0 |
| 7156 | emit or 1409286144 cc |
| 7157 | ret p |
| 7158 | end |
| 7159 | |
| 7160 | note Descriptor-kind table is process local, not a sandbox. Full fd keys avoid high-fd cleanup resets. |
| 7161 | note Tags certify the current descriptor, not a generation-bearing stale integer reference. |
| 7162 | note X10 fd, X11 entry or end, X12 remaining. X0..X8 and X15..X17 preserved. |
| 7163 | fn fdscan kind ulong to void |
| 7164 | matconst 11 get fdtab 0 |
| 7165 | matconst 12 128 |
| 7166 | head = get oc 0 |
| 7167 | mload 14 11 1 |
| 7168 | mimmed 4043309056 31 14 kind |
| 7169 | next = mbranch 1 |
| 7170 | found = ulong 0 |
| 7171 | if ne kind 0 |
| 7172 | mload 13 11 0 |
| 7173 | e3 3942645760 31 13 10 |
| 7174 | found = mbranch 0 |
| 7175 | else |
| 7176 | found = mbranch 0 |
| 7177 | end |
| 7178 | patch19 next get oc 0 |
| 7179 | mimmed 2432696320 11 11 16 |
| 7180 | mimmed 3506438144 12 12 1 |
| 7181 | mimmed 4043309056 31 12 0 |
| 7182 | again = mbranch 1 |
| 7183 | patch19 again head |
| 7184 | patch19 found get oc 0 |
| 7185 | end |
| 7186 | fn fdcheck kind ulong to void |
| 7187 | fdscan kind |
| 7188 | mimmed 4043309056 31 12 0 |
| 7189 | trapc 0 3 |
| 7190 | end |
| 7191 | fn fdforget to void |
| 7192 | note Match either kind, clearing every matching key. No propagation through dupfd. |
| 7193 | for kind ulong 2 |
| 7194 | fdscan add kind 1 |
| 7195 | mimmed 4043309056 31 12 0 |
| 7196 | none = mbranch 0 |
| 7197 | mstore 31 11 1 |
| 7198 | patch19 none get oc 0 |
| 7199 | end |
| 7200 | end |
| 7201 | fn fdrecord kind ulong to void |
| 7202 | mimmed 4043309056 31 0 0 |
| 7203 | bad = mbranch 11 |
| 7204 | mstore 0 11 0 |
| 7205 | matconst 12 kind |
| 7206 | mstore 12 11 1 |
| 7207 | patch19 bad get oc 0 |
| 7208 | end |
| 7209 | |
| 7210 | |
| 7211 | |
| 7212 | note Validate a long handle in X10; produce entry X11, base X13, length X12. |
| 7213 | note The slot's generation defeats a stale handle after close and slot reuse. |
| 7214 | fn mcheck to void |
| 7215 | if eq get progmode 0 0 |
| 7216 | matconst 15 8191 |
| 7217 | else |
| 7218 | matconst 15 255 |
| 7219 | end |
| 7220 | e3 2315255808 11 10 15 |
| 7221 | mimmed 4043309056 31 11 1 |
| 7222 | trapc 3 3 |
| 7223 | if eq get progmode 0 0 |
| 7224 | mload 14 7 31 |
| 7225 | mload 14 14 0 |
| 7226 | mimmed 4043309056 31 14 1 |
| 7227 | trapc 3 3 |
| 7228 | matconst 15 4098 |
| 7229 | e3 3942645760 31 14 15 |
| 7230 | trapc 8 3 |
| 7231 | e3 3942645760 31 11 14 |
| 7232 | trapc 8 3 |
| 7233 | else |
| 7234 | mimmed 4043309056 31 11 128 |
| 7235 | trapc 8 3 |
| 7236 | end |
| 7237 | mimmed 3506438144 11 11 1 |
| 7238 | matconst 15 32 |
| 7239 | e3 2600500224 11 11 15 |
| 7240 | if eq get progmode 0 0 |
| 7241 | mload 15 7 31 |
| 7242 | mimmed 2432696320 15 15 32 |
| 7243 | else |
| 7244 | matconst 15 get maptab 0 |
| 7245 | end |
| 7246 | e3 2332033024 11 11 15 |
| 7247 | mload 14 11 2 |
| 7248 | mimmed 4043309056 31 14 0 |
| 7249 | trapc 0 3 |
| 7250 | if eq get progmode 0 0 |
| 7251 | matconst 15 13 |
| 7252 | else |
| 7253 | matconst 15 8 |
| 7254 | end |
| 7255 | e3 2596283392 10 10 15 |
| 7256 | e3 3942645760 31 10 14 |
| 7257 | trapc 1 3 |
| 7258 | mload 13 11 0 |
| 7259 | mimmed 4043309056 31 13 0 |
| 7260 | trapc 0 3 |
| 7261 | mload 12 11 1 |
| 7262 | end |
| 7263 | |
| 7264 | note mapnew fd:int offset:ulong bytes:ulong access:int mode:int -> long handle/errno. |
| 7265 | note Access 1 or 3 and modes 1/2/33/34 must be literal. No fixed address or executable map. |
| 7266 | note vfiomap fd:int A off n -> long handle/errno: n must be 32, a struct vfio_region_info the kernel |
| 7267 | note filled. Its flags need READ|MMAP (1|4); size and offset come from the span. Always read-only shared. |
| 7268 | note vfiomapw is the same with flags READ|WRITE|MMAP (7) and a read/write shared map, so mapset can store |
| 7269 | note to device registers (BAR0 MMIO). Only a span the kernel reported writable maps writable. |
| 7270 | fn mnew c ulong dst ulong x ulong to void |
| 7271 | acc = ulong 0 |
| 7272 | mode = ulong 1048610 |
| 7273 | if or eq c 229 eq c 230 |
| 7274 | harg x 4 8 |
| 7275 | put fr add x 20 harray x 0 |
| 7276 | put fr add x 23 alloc |
| 7277 | matconst get fr add x 23 32 |
| 7278 | e3 3942645760 31 get fr add x 22 get fr add x 23 |
| 7279 | trapc 1 3 |
| 7280 | acc = ulong 1 |
| 7281 | if eq c 230 |
| 7282 | acc = ulong 3 |
| 7283 | end |
| 7284 | mode = ulong 1 |
| 7285 | end |
| 7286 | if eq c 167 |
| 7287 | harg x 0 8 |
| 7288 | harg x 1 5 |
| 7289 | harg x 2 5 |
| 7290 | harg x 3 8 |
| 7291 | harg x 4 8 |
| 7292 | if or ne get fr add x 14 3 ne get fr add x 16 3 |
| 7293 | fail 9 |
| 7294 | end |
| 7295 | acc = get fr add x 15 |
| 7296 | mode = get fr add x 17 |
| 7297 | if and ne acc 1 ne acc 3 |
| 7298 | fail 9 |
| 7299 | end |
| 7300 | if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34 |
| 7301 | fail 9 |
| 7302 | end |
| 7303 | end |
| 7304 | if eq c 176 |
| 7305 | harg x 1 5 |
| 7306 | harg x 2 5 |
| 7307 | end |
| 7308 | save |
| 7309 | if or eq c 229 eq c 230 |
| 7310 | basearg 6 get fr add x 20 |
| 7311 | loadarg 16 1 get fr add x 21 |
| 7312 | e3 2332033024 6 6 16 |
| 7313 | mimmed 3107979264 15 6 1 |
| 7314 | matconst 14 or 5 sub acc 1 |
| 7315 | e3 2315255808 15 15 14 |
| 7316 | mimmed 4043309056 31 15 or 5 sub acc 1 |
| 7317 | trapc 1 3 |
| 7318 | mload 1 6 2 |
| 7319 | hload x 4 4 |
| 7320 | mload 5 6 3 |
| 7321 | else |
| 7322 | hload x 2 1 |
| 7323 | end |
| 7324 | mimmed 4043309056 31 1 0 |
| 7325 | trapc 0 3 |
| 7326 | matconst 15 68719476736 |
| 7327 | e3 3942645760 31 1 15 |
| 7328 | trapc 8 3 |
| 7329 | if eq c 167 |
| 7330 | hload x 0 4 |
| 7331 | hload x 1 5 |
| 7332 | if ge mode 32 |
| 7333 | matconst 15 18446744073709551615 |
| 7334 | e3 3942645760 31 4 15 |
| 7335 | trapc 1 3 |
| 7336 | mimmed 4043309056 31 5 0 |
| 7337 | trapc 1 3 |
| 7338 | end |
| 7339 | end |
| 7340 | if eq c 176 |
| 7341 | hload x 1 0 |
| 7342 | note Reservations are page aligned and bounded below the 40-bit GPU command limit. |
| 7343 | matconst 15 65536 |
| 7344 | e3 3942645760 31 0 15 |
| 7345 | trapc 3 3 |
| 7346 | matconst 15 1099511627776 |
| 7347 | e3 3405774848 15 15 1 |
| 7348 | e3 3942645760 31 0 15 |
| 7349 | trapc 8 3 |
| 7350 | matconst 15 4095 |
| 7351 | e3 2315255808 14 0 15 |
| 7352 | mimmed 4043309056 31 14 0 |
| 7353 | trapc 1 3 |
| 7354 | e3 2315255808 14 1 15 |
| 7355 | mimmed 4043309056 31 14 0 |
| 7356 | trapc 1 3 |
| 7357 | matconst 4 18446744073709551615 |
| 7358 | matconst 5 0 |
| 7359 | end |
| 7360 | if eq get progmode 0 0 |
| 7361 | mload 9 7 31 |
| 7362 | mload 12 9 0 |
| 7363 | mimmed 4043309056 31 12 1 |
| 7364 | trapc 3 3 |
| 7365 | matconst 15 4098 |
| 7366 | e3 3942645760 31 12 15 |
| 7367 | trapc 8 3 |
| 7368 | mload 14 9 2 |
| 7369 | mimmed 4043309056 31 14 1 |
| 7370 | trapc 3 3 |
| 7371 | matconst 15 1125899906842623 |
| 7372 | e3 3942645760 31 14 15 |
| 7373 | trapc 8 3 |
| 7374 | mimmed 2432696320 9 9 32 |
| 7375 | else |
| 7376 | matconst 9 get maptab 0 |
| 7377 | end |
| 7378 | matconst 10 1 |
| 7379 | head = get oc 0 |
| 7380 | mload 11 9 0 |
| 7381 | mimmed 4043309056 31 11 0 |
| 7382 | used = mbranch 1 |
| 7383 | mload 11 9 2 |
| 7384 | if eq get progmode 0 0 |
| 7385 | e3 3942645760 31 11 14 |
| 7386 | else |
| 7387 | matconst 15 36028797018963967 |
| 7388 | e3 3942645760 31 11 15 |
| 7389 | end |
| 7390 | vacant = mbranch 3 |
| 7391 | patch19 used get oc 0 |
| 7392 | mimmed 2432696320 9 9 32 |
| 7393 | mimmed 2432696320 10 10 1 |
| 7394 | if eq get progmode 0 0 |
| 7395 | e3 3942645760 31 10 12 |
| 7396 | else |
| 7397 | mimmed 4043309056 31 10 128 |
| 7398 | end |
| 7399 | again = mbranch 9 |
| 7400 | patch19 again head |
| 7401 | matconst 0 18446744073709551592 |
| 7402 | full = get oc 0 |
| 7403 | emit 335544320 |
| 7404 | patch19 vacant get oc 0 |
| 7405 | if eq c 176 |
| 7406 | hload x 1 0 |
| 7407 | else |
| 7408 | matconst 0 0 |
| 7409 | end |
| 7410 | matconst 2 acc |
| 7411 | matconst 3 mode |
| 7412 | hsys 222 |
| 7413 | mimmed 4043309056 31 0 0 |
| 7414 | failed = mbranch 11 |
| 7415 | if eq c 176 |
| 7416 | hload x 1 14 |
| 7417 | e3 3942645760 31 0 14 |
| 7418 | exact = mbranch 0 |
| 7419 | note Old kernels may ignore NOREPLACE; reject and unmap any displaced result. |
| 7420 | hsys 215 |
| 7421 | mimmed 4043309056 31 0 0 |
| 7422 | trapc 1 3 |
| 7423 | matconst 0 18446744073709551521 |
| 7424 | wrong = get oc 0 |
| 7425 | emit 335544320 |
| 7426 | patch19 exact get oc 0 |
| 7427 | put fr add x 23 wrong |
| 7428 | end |
| 7429 | mstore 0 9 0 |
| 7430 | mstore 1 9 1 |
| 7431 | mimmed 2432696320 11 11 1 |
| 7432 | mstore 11 9 2 |
| 7433 | matconst 15 acc |
| 7434 | mstore 15 9 3 |
| 7435 | if eq get progmode 0 0 |
| 7436 | matconst 15 13 |
| 7437 | else |
| 7438 | matconst 15 8 |
| 7439 | end |
| 7440 | e3 2596282368 0 11 15 |
| 7441 | e3 2852126720 0 0 10 |
| 7442 | patch19 failed get oc 0 |
| 7443 | patch26 full get oc 0 |
| 7444 | if eq c 176 |
| 7445 | head = get fr add x 23 |
| 7446 | patch26 head get oc 0 |
| 7447 | end |
| 7448 | hreturn dst x |
| 7449 | end |
| 7450 | |
| 7451 | note Replace only an entire owned PROT_NONE reservation. Failed binds retire the handle. |
| 7452 | fn mbind dst ulong x ulong to void |
| 7453 | harg x 0 9 |
| 7454 | harg x 1 8 |
| 7455 | harg x 2 5 |
| 7456 | harg x 3 8 |
| 7457 | if ne get fr add x 14 3 |
| 7458 | fail 9 |
| 7459 | end |
| 7460 | acc = get fr add x 15 |
| 7461 | if and ne acc 1 ne acc 3 |
| 7462 | fail 9 |
| 7463 | end |
| 7464 | save |
| 7465 | hload x 0 10 |
| 7466 | mcheck |
| 7467 | mload 15 11 3 |
| 7468 | mimmed 4043309056 31 15 0 |
| 7469 | trapc 1 3 |
| 7470 | e3 2852126720 0 31 13 |
| 7471 | e3 2852126720 1 31 12 |
| 7472 | matconst 2 acc |
| 7473 | matconst 3 17 |
| 7474 | hload x 1 4 |
| 7475 | hload x 2 5 |
| 7476 | hsys 222 |
| 7477 | mimmed 4043309056 31 0 0 |
| 7478 | failed = mbranch 11 |
| 7479 | e3 3942645760 31 0 13 |
| 7480 | trapc 1 3 |
| 7481 | matconst 15 acc |
| 7482 | mstore 15 11 3 |
| 7483 | matconst 0 0 |
| 7484 | done = get oc 0 |
| 7485 | emit 335544320 |
| 7486 | patch19 failed get oc 0 |
| 7487 | e3 2852126720 10 31 0 |
| 7488 | e3 2852126720 0 31 13 |
| 7489 | e3 2852126720 1 31 12 |
| 7490 | note Preserve a droppable owner but forbid a second bind if cleanup also fails. |
| 7491 | if eq get progmode 0 0 |
| 7492 | matconst 15 4 |
| 7493 | mstore 15 11 3 |
| 7494 | end |
| 7495 | hsys 215 |
| 7496 | mimmed 4043309056 31 0 0 |
| 7497 | trapc 1 3 |
| 7498 | mstore 31 11 0 |
| 7499 | mstore 31 11 1 |
| 7500 | mstore 31 11 3 |
| 7501 | e3 2852126720 0 31 10 |
| 7502 | patch26 done get oc 0 |
| 7503 | hreturn dst x |
| 7504 | end |
| 7505 | |
| 7506 | note Copies traverse only checked live mapped spans and normal bounded byte arrays. |
| 7507 | note mapread writes A; mapwrite reads A. Both return the count, with no pointer decay. |
| 7508 | fn mcopy c ulong dst ulong x ulong to void |
| 7509 | harg x 4 9 |
| 7510 | harg x 3 5 |
| 7511 | wr = ulong 0 |
| 7512 | if eq c 169 |
| 7513 | wr = ulong 1 |
| 7514 | end |
| 7515 | e = harray x wr |
| 7516 | save |
| 7517 | hload x 4 10 |
| 7518 | mcheck |
| 7519 | mload 15 11 3 |
| 7520 | mimmed 4043309056 31 15 0 |
| 7521 | trapc 0 3 |
| 7522 | if eq get progmode 0 0 |
| 7523 | mimmed 4043309056 31 15 3 |
| 7524 | trapc 8 3 |
| 7525 | end |
| 7526 | hload x 3 0 |
| 7527 | e3 3942645760 31 0 12 |
| 7528 | trapc 8 3 |
| 7529 | e3 3405774848 12 12 0 |
| 7530 | loadarg 2 1 get fr add x 22 |
| 7531 | e3 3942645760 31 2 12 |
| 7532 | trapc 8 3 |
| 7533 | e3 2332033024 0 13 0 |
| 7534 | basearg 1 e |
| 7535 | loadarg 16 1 get fr add x 21 |
| 7536 | e3 2332033024 1 1 16 |
| 7537 | if eq c 170 |
| 7538 | mload 15 11 3 |
| 7539 | mimmed 4043309056 31 15 3 |
| 7540 | trapc 1 3 |
| 7541 | e3 2852126720 15 31 0 |
| 7542 | e3 2852126720 0 31 1 |
| 7543 | e3 2852126720 1 31 15 |
| 7544 | end |
| 7545 | e3 2852126720 4 31 2 |
| 7546 | head = get oc 0 |
| 7547 | mimmed 4043309056 31 2 0 |
| 7548 | done = mbranch 0 |
| 7549 | emit 960495619 |
| 7550 | emit 956301347 |
| 7551 | mimmed 2432696320 0 0 1 |
| 7552 | mimmed 2432696320 1 1 1 |
| 7553 | mimmed 3506438144 2 2 1 |
| 7554 | back head |
| 7555 | patch19 done get oc 0 |
| 7556 | e3 2852126720 0 31 4 |
| 7557 | hreturn dst x |
| 7558 | end |
| 7559 | |
| 7560 | note NVRM NVOS21/NVOS54 parameter binding. The kernel sees one private header. |
| 7561 | note Pointer and length are derived from a checked byte span, never from user bytes. |
| 7562 | note Request is exactly the 32-byte RM_ALLOC or RM_CONTROL encoding. |
| 7563 | fn hdevcall dst ulong x ulong to void |
| 7564 | n = xhreq 171 x |
| 7565 | e = harray x 1 |
| 7566 | put fr add x 23 e |
| 7567 | put fr add x 24 get fr add x 21 |
| 7568 | t = alloc |
| 7569 | matconst t 32 |
| 7570 | e3 3942645760 31 get fr add x 22 t |
| 7571 | trapc 1 3 |
| 7572 | f = harray x 1 |
| 7573 | if eq e f |
| 7574 | fail 19 |
| 7575 | end |
| 7576 | t = alloc |
| 7577 | matconst t 1048576 |
| 7578 | e3 3942645760 31 get fr add x 22 t |
| 7579 | trapc 8 3 |
| 7580 | save |
| 7581 | hload x 4 0 |
| 7582 | hload x 2 1 |
| 7583 | basearg 10 get fr add x 23 |
| 7584 | loadarg 16 1 get fr add x 24 |
| 7585 | e3 2332033024 10 10 16 |
| 7586 | basearg 11 f |
| 7587 | loadarg 16 1 get fr add x 21 |
| 7588 | e3 2332033024 11 11 16 |
| 7589 | loadarg 12 1 get fr add x 22 |
| 7590 | note Refuse overlapping parameter/header spans even through distinct edit parameters. |
| 7591 | mimmed 4043309056 31 12 0 |
| 7592 | empty = mbranch 0 |
| 7593 | e3 2332033024 14 11 12 |
| 7594 | e3 3942645760 31 14 10 |
| 7595 | before = mbranch 9 |
| 7596 | mimmed 2432696320 14 10 32 |
| 7597 | e3 3942645760 31 11 14 |
| 7598 | trapc 3 3 |
| 7599 | patch19 before get oc 0 |
| 7600 | patch19 empty get oc 0 |
| 7601 | mload 13 10 2 |
| 7602 | mimmed 4043309056 31 13 0 |
| 7603 | trapc 1 3 |
| 7604 | mimmed 4043309056 31 12 0 |
| 7605 | nonzero = mbranch 1 |
| 7606 | matconst 11 0 |
| 7607 | patch19 nonzero get oc 0 |
| 7608 | spsub 32 |
| 7609 | stkchk |
| 7610 | for i ulong 4 |
| 7611 | mload 13 10 i |
| 7612 | mstore 13 31 i |
| 7613 | end |
| 7614 | mstore 11 31 2 |
| 7615 | emit 3103792108 |
| 7616 | emit 2432697314 |
| 7617 | hsys 29 |
| 7618 | for i ulong 4 |
| 7619 | if ne i 2 |
| 7620 | mload 13 31 i |
| 7621 | mstore 13 10 i |
| 7622 | end |
| 7623 | end |
| 7624 | spadd 32 |
| 7625 | hreturn dst x |
| 7626 | end |
| 7627 | |
| 7628 | |
| 7629 | note Mapped-address export for driver GPU VA serialization; no arbitrary-address access. |
| 7630 | note Aligned word access uses exactly one 32/64-bit load/store bracketed by DSB SY. |
| 7631 | fn mmapio c ulong dst ulong x ulong to void |
| 7632 | harg x 0 9 |
| 7633 | if eq c 173 |
| 7634 | save |
| 7635 | hload x 0 10 |
| 7636 | mcheck |
| 7637 | e3 2852126720 0 31 13 |
| 7638 | hreturn dst x |
| 7639 | put rt 0 5 |
| 7640 | ret |
| 7641 | end |
| 7642 | harg x 1 5 |
| 7643 | harg x 2 8 |
| 7644 | if ne get fr add x 12 3 |
| 7645 | fail 9 |
| 7646 | end |
| 7647 | w = get fr add x 13 |
| 7648 | if and ne w 4 ne w 8 |
| 7649 | fail 9 |
| 7650 | end |
| 7651 | if eq c 175 |
| 7652 | harg x 3 5 |
| 7653 | end |
| 7654 | save |
| 7655 | hload x 0 10 |
| 7656 | mcheck |
| 7657 | hload x 1 0 |
| 7658 | mload 15 11 3 |
| 7659 | mimmed 4043309056 31 15 0 |
| 7660 | trapc 0 3 |
| 7661 | if eq get progmode 0 0 |
| 7662 | mimmed 4043309056 31 15 3 |
| 7663 | trapc 8 3 |
| 7664 | end |
| 7665 | e3 3942645760 31 0 12 |
| 7666 | trapc 8 3 |
| 7667 | e3 3405774848 12 12 0 |
| 7668 | mimmed 4043309056 31 12 w |
| 7669 | trapc 3 3 |
| 7670 | matconst 15 sub w 1 |
| 7671 | e3 2315255808 14 0 15 |
| 7672 | mimmed 4043309056 31 14 0 |
| 7673 | trapc 1 3 |
| 7674 | e3 2332033024 13 13 0 |
| 7675 | if eq c 175 |
| 7676 | mload 15 11 3 |
| 7677 | mimmed 4043309056 31 15 3 |
| 7678 | trapc 1 3 |
| 7679 | hload x 3 2 |
| 7680 | if eq w 4 |
| 7681 | matconst 15 4294967295 |
| 7682 | e3 3942645760 31 2 15 |
| 7683 | trapc 8 3 |
| 7684 | end |
| 7685 | emit 3573759903 |
| 7686 | if eq w 4 |
| 7687 | mimmed 3103784960 2 13 0 |
| 7688 | else |
| 7689 | mstore 2 13 0 |
| 7690 | end |
| 7691 | emit 3573759903 |
| 7692 | matconst 0 0 |
| 7693 | hreturn dst x |
| 7694 | else |
| 7695 | emit 3573759903 |
| 7696 | if eq w 4 |
| 7697 | mimmed 3107979264 0 13 0 |
| 7698 | else |
| 7699 | mload 0 13 0 |
| 7700 | end |
| 7701 | emit 3573759903 |
| 7702 | hreturn dst x |
| 7703 | put rt 0 5 |
| 7704 | end |
| 7705 | end |
| 7706 | |
| 7707 | fn hostval c ulong dst ulong to void |
| 7708 | if eq get xtarget 0 1 |
| 7709 | if and ge c 228 le c 232 |
| 7710 | if eq get progmode 0 0 |
| 7711 | fail 9 |
| 7712 | end |
| 7713 | fail 25 |
| 7714 | end |
| 7715 | xhost c dst |
| 7716 | ret |
| 7717 | end |
| 7718 | if ne get xtarget 0 0 |
| 7719 | fail 25 |
| 7720 | end |
| 7721 | note Function mode (no program image: no argv in x27, no x28 stack floor, no globals) refuses host |
| 7722 | note words with error 9, except in an OM-2 unit the file and identity subset that needs none of the |
| 7723 | note image: fclose 100, fopen 110, fstat 117, stat 140, getuid 145, geteuid 146, getgid 147, getegid 148, |
| 7724 | note lstat 149 (OMEGESE.md 10, spec/omegese-om2.md); the clocks monons 109, realns 130 and sleepns 120; |
| 7725 | note and the device subset devctl 166, mapnew 167, mapdrop 168, mapread 169, mapwrite 170, devcall 171, |
| 7726 | note uvmctl 172, mapaddr 173, mapget 174, mapset 175, maphold 176 and mapbind 177. Fixed replacement |
| 7727 | note is only over a whole live PROT_NONE reservation owned by this table. Each is save, inline svc, |
| 7728 | note restore; x7 and x19..x28 are never written. Function-mode table entry31 points at a 32-byte |
| 7729 | note header (capacity1..4098, generation base, generation limit, reserved) then capacity32-byte slots. |
| 7730 | note Handles use13slot bits; program mode retains its raw128slots and8slot-bit handles. |
| 7731 | if eq get progmode 0 0 |
| 7732 | if eq get om2 0 0 |
| 7733 | fail 9 |
| 7734 | end |
| 7735 | ok = ulong 0 |
| 7736 | if or or eq c 100 eq c 110 or eq c 117 eq c 140 |
| 7737 | ok = ulong 1 |
| 7738 | end |
| 7739 | if and ge c 145 le c 149 |
| 7740 | ok = ulong 1 |
| 7741 | end |
| 7742 | if or or eq c 109 eq c 120 eq c 130 |
| 7743 | ok = ulong 1 |
| 7744 | end |
| 7745 | if and ge c 166 le c 177 |
| 7746 | ok = ulong 1 |
| 7747 | end |
| 7748 | if eq ok 0 |
| 7749 | fail 9 |
| 7750 | end |
| 7751 | end |
| 7752 | x = mul get depth 0 32 |
| 7753 | put fr add x 7 get nslot 0 |
| 7754 | note VFIO words are program-only. These IDs are disjoint from efi178, qty223 and peername224. |
| 7755 | if and ge c 228 le c 232 |
| 7756 | if eq get fdtab 0 0 |
| 7757 | fdpool = get poolb 0 |
| 7758 | if gt fdpool 1073739776 |
| 7759 | fail 23 |
| 7760 | end |
| 7761 | put fdtab 0 add 276824064 fdpool |
| 7762 | put poolb 0 add fdpool 2048 |
| 7763 | end |
| 7764 | if eq c 228 |
| 7765 | note VFIO container, group and device requests: _IO(';', 100 + k) from linux/vfio.h, exact allowlist and |
| 7766 | note shapes. GET_API_VERSION 15204 takes no argument (n 0). DEVICE_RESET 15215 is not allowed: W0 never |
| 7767 | note resets the device from Omega (Drake: W0a only, no FLR). CHECK_EXTENSION 15205 and |
| 7768 | note SET_IOMMU 15206 pass the 4-byte little-endian value in the span; SET_IOMMU accepts only TYPE1v2 (3). |
| 7769 | note GROUP_SET_CONTAINER 15208 points at a 4-byte fd. GROUP_GET_STATUS 15207 (8), DEVICE_GET_INFO 15211 |
| 7770 | note (24) and DEVICE_GET_REGION_INFO 15212 (32) point at the span after the compiler itself stores |
| 7771 | note argsz = n, so the kernel copies at most n bytes. GROUP_GET_DEVICE_FD 15210 passes a private zero- |
| 7772 | note terminated copy of a non-empty span (at most 4095 bytes, no embedded zero). |
| 7773 | note IOMMU_MAP_DMA 15217 (32) takes an Omega mapping handle in the vaddr field (bytes 8..15), never an |
| 7774 | note address: the compiler checks the handle like mapget, requires a read/write mapping and flags exactly |
| 7775 | note READ|WRITE (3), then stores the mapping's own base address and whole length into vaddr and size. |
| 7776 | note The caller chooses only the IOVA (bytes 16..23). IOMMU_UNMAP_DMA 15218 (24) requires flags 0 (no |
| 7777 | note dirty bitmap, no ALL, no VADDR) and unmaps only the caller's IOVA range in its own container. |
| 7778 | mtinit |
| 7779 | harg x 4 8 |
| 7780 | harg x 2 4 |
| 7781 | if ne get fr add x 12 3 |
| 7782 | fail 9 |
| 7783 | end |
| 7784 | q = get fr add x 13 |
| 7785 | if eq q 15210 |
| 7786 | e = harray x 0 |
| 7787 | hpathcp x |
| 7788 | emit 4043309247 |
| 7789 | trapc 0 3 |
| 7790 | fdscan 0 |
| 7791 | mimmed 4043309056 31 12 0 |
| 7792 | fdfound = mbranch 1 |
| 7793 | matconst 0 18446744073709551592 |
| 7794 | full = get oc 0 |
| 7795 | emit 335544320 |
| 7796 | patch19 fdfound get oc 0 |
| 7797 | hload x 4 3 |
| 7798 | hcopy |
| 7799 | e3 2852126720 0 31 3 |
| 7800 | e3 2852126720 2 31 1 |
| 7801 | matconst 1 15210 |
| 7802 | hsys 29 |
| 7803 | fdrecord 1 |
| 7804 | spadd 4096 |
| 7805 | patch26 full get oc 0 |
| 7806 | hreturn dst x |
| 7807 | ret |
| 7808 | end |
| 7809 | n = ulong 99 |
| 7810 | if eq q 15204 |
| 7811 | n = ulong 0 |
| 7812 | end |
| 7813 | if or or eq q 15205 eq q 15206 eq q 15208 |
| 7814 | n = ulong 4 |
| 7815 | end |
| 7816 | if eq q 15207 |
| 7817 | n = ulong 8 |
| 7818 | end |
| 7819 | if eq q 15211 |
| 7820 | n = ulong 24 |
| 7821 | end |
| 7822 | if eq q 15212 |
| 7823 | n = ulong 32 |
| 7824 | end |
| 7825 | if eq q 15217 |
| 7826 | n = ulong 32 |
| 7827 | end |
| 7828 | if eq q 15218 |
| 7829 | n = ulong 24 |
| 7830 | end |
| 7831 | if eq n 99 |
| 7832 | fail 9 |
| 7833 | end |
| 7834 | put fr add x 23 n |
| 7835 | e = harray x 1 |
| 7836 | t = alloc |
| 7837 | matconst t get fr add x 23 |
| 7838 | e3 3942645760 31 get fr add x 22 t |
| 7839 | trapc 1 3 |
| 7840 | save |
| 7841 | hload x 4 0 |
| 7842 | matconst 1 q |
| 7843 | basearg 2 e |
| 7844 | loadarg 16 1 get fr add x 21 |
| 7845 | e3 2332033024 2 2 16 |
| 7846 | if ge n 8 |
| 7847 | matconst 16 n |
| 7848 | mimmed 3103784960 16 2 0 |
| 7849 | end |
| 7850 | if eq q 15217 |
| 7851 | mimmed 3107979264 15 2 1 |
| 7852 | mimmed 4043309056 31 15 3 |
| 7853 | trapc 1 3 |
| 7854 | mload 10 2 1 |
| 7855 | mcheck |
| 7856 | mload 15 11 3 |
| 7857 | mimmed 4043309056 31 15 3 |
| 7858 | trapc 1 3 |
| 7859 | mstore 13 2 1 |
| 7860 | mstore 12 2 3 |
| 7861 | end |
| 7862 | if eq q 15218 |
| 7863 | mimmed 3107979264 15 2 1 |
| 7864 | mimmed 4043309056 31 15 0 |
| 7865 | trapc 1 3 |
| 7866 | end |
| 7867 | if or eq q 15205 eq q 15206 |
| 7868 | mimmed 3107979264 2 2 0 |
| 7869 | end |
| 7870 | if eq q 15206 |
| 7871 | mimmed 4043309056 31 2 3 |
| 7872 | trapc 1 3 |
| 7873 | end |
| 7874 | if eq n 0 |
| 7875 | matconst 2 0 |
| 7876 | end |
| 7877 | hsys 29 |
| 7878 | hreturn dst x |
| 7879 | end |
| 7880 | if or eq c 229 eq c 230 |
| 7881 | mtinit |
| 7882 | mnew c dst x |
| 7883 | end |
| 7884 | if eq c 231 |
| 7885 | note Fixed eventfd flags: CLOEXEC prevents exec leakage; NONBLOCK makes drained reads safe. |
| 7886 | harg x 0 4 |
| 7887 | save |
| 7888 | fdscan 0 |
| 7889 | mimmed 4043309056 31 12 0 |
| 7890 | fdfound = mbranch 1 |
| 7891 | matconst 0 18446744073709551592 |
| 7892 | full = get oc 0 |
| 7893 | emit 335544320 |
| 7894 | patch19 fdfound get oc 0 |
| 7895 | hload x 0 0 |
| 7896 | matconst 1 526336 |
| 7897 | hsys 19 |
| 7898 | fdrecord 2 |
| 7899 | patch26 full get oc 0 |
| 7900 | hreturn dst x |
| 7901 | end |
| 7902 | if eq c 232 |
| 7903 | note GET_IRQ_INFO and SET_IRQS only; caller bytes cannot introduce pointers or arbitrary ioctls. |
| 7904 | harg x 4 8 |
| 7905 | harg x 2 4 |
| 7906 | if ne get fr add x 12 3 |
| 7907 | fail 9 |
| 7908 | end |
| 7909 | q = get fr add x 13 |
| 7910 | if and ne q 15213 ne q 15214 |
| 7911 | fail 9 |
| 7912 | end |
| 7913 | e = harray x 1 |
| 7914 | save |
| 7915 | hload x 4 10 |
| 7916 | fdcheck 1 |
| 7917 | basearg 2 e |
| 7918 | loadarg 16 1 get fr add x 21 |
| 7919 | e3 2332033024 2 2 16 |
| 7920 | loadarg 3 1 get fr add x 22 |
| 7921 | if eq q 15213 |
| 7922 | mimmed 4043309056 31 3 16 |
| 7923 | trapc 1 3 |
| 7924 | else |
| 7925 | mimmed 4043309056 31 3 20 |
| 7926 | trapc 3 3 |
| 7927 | mimmed 4043309056 31 3 276 |
| 7928 | trapc 8 3 |
| 7929 | end |
| 7930 | mimmed 3107979264 4 2 0 |
| 7931 | e3 3942645760 31 4 3 |
| 7932 | trapc 1 3 |
| 7933 | if eq q 15214 |
| 7934 | mimmed 3107979264 5 2 4 |
| 7935 | mimmed 4043309056 31 5 64 |
| 7936 | trapc 8 3 |
| 7937 | mimmed 3107979264 6 2 3 |
| 7938 | matconst 7 4294967295 |
| 7939 | e3 3405774848 7 7 5 |
| 7940 | e3 3942645760 31 6 7 |
| 7941 | trapc 8 3 |
| 7942 | mimmed 3107979264 4 2 1 |
| 7943 | mimmed 4043309056 31 4 36 |
| 7944 | event = mbranch 0 |
| 7945 | mimmed 4043309056 31 3 20 |
| 7946 | trapc 1 3 |
| 7947 | mimmed 4043309056 31 4 33 |
| 7948 | disable = mbranch 0 |
| 7949 | note DATA_NONE MASK or UNMASK. Linux checks the device's MASKABLE capability. |
| 7950 | mimmed 4043309056 31 4 9 |
| 7951 | mask = mbranch 0 |
| 7952 | mimmed 4043309056 31 4 17 |
| 7953 | trapc 1 3 |
| 7954 | patch19 mask get oc 0 |
| 7955 | mimmed 4043309056 31 5 0 |
| 7956 | trapc 0 3 |
| 7957 | done = get oc 0 |
| 7958 | emit 335544320 |
| 7959 | patch19 disable get oc 0 |
| 7960 | mimmed 4043309056 31 5 0 |
| 7961 | trapc 1 3 |
| 7962 | mimmed 4043309056 31 6 0 |
| 7963 | trapc 1 3 |
| 7964 | disdone = get oc 0 |
| 7965 | emit 335544320 |
| 7966 | patch19 event get oc 0 |
| 7967 | mimmed 4043309056 31 5 0 |
| 7968 | trapc 0 3 |
| 7969 | matconst 7 4 |
| 7970 | e3 2600500224 7 5 7 |
| 7971 | mimmed 2432696320 7 7 20 |
| 7972 | e3 3942645760 31 7 3 |
| 7973 | trapc 1 3 |
| 7974 | mimmed 2432696320 6 2 20 |
| 7975 | head = get oc 0 |
| 7976 | mimmed 3107979264 10 6 0 |
| 7977 | matconst 7 4294967295 |
| 7978 | e3 3942645760 31 10 7 |
| 7979 | skip = mbranch 0 |
| 7980 | fdcheck 2 |
| 7981 | patch19 skip get oc 0 |
| 7982 | mimmed 2432696320 6 6 4 |
| 7983 | mimmed 3506438144 5 5 1 |
| 7984 | mimmed 4043309056 31 5 0 |
| 7985 | again = mbranch 1 |
| 7986 | patch19 again head |
| 7987 | patch26 done get oc 0 |
| 7988 | patch26 disdone get oc 0 |
| 7989 | end |
| 7990 | hload x 4 0 |
| 7991 | matconst 1 q |
| 7992 | hsys 29 |
| 7993 | hreturn dst x |
| 7994 | end |
| 7995 | ret |
| 7996 | end |
| 7997 | if eq c 197 |
| 7998 | hscalar c dst x |
| 7999 | ret |
| 8000 | end |
| 8001 | note execpure 198 and execenv 233 are dispatched here, before the ge c 173 mapped-memory range below |
| 8002 | note would claim them. |
| 8003 | if or eq c 198 eq c 233 |
| 8004 | hpack c dst x |
| 8005 | ret |
| 8006 | end |
| 8007 | if eq c 220 |
| 8008 | hpeercr dst x |
| 8009 | ret |
| 8010 | end |
| 8011 | if eq c 221 |
| 8012 | hpollfds dst x |
| 8013 | ret |
| 8014 | end |
| 8015 | if eq c 222 |
| 8016 | hsendmsg dst x |
| 8017 | ret |
| 8018 | end |
| 8019 | if eq c 224 |
| 8020 | hbuffer c dst x |
| 8021 | ret |
| 8022 | end |
| 8023 | if eq c 176 |
| 8024 | mtinit |
| 8025 | mnew c dst x |
| 8026 | ret |
| 8027 | end |
| 8028 | if eq c 177 |
| 8029 | mtinit |
| 8030 | mbind dst x |
| 8031 | ret |
| 8032 | end |
| 8033 | if ge c 173 |
| 8034 | mtinit |
| 8035 | mmapio c dst x |
| 8036 | ret |
| 8037 | end |
| 8038 | if eq c 172 |
| 8039 | note Linux UVM has unencoded commands. Exact allowlist and ABI580.173.02 byte sizes. |
| 8040 | put fr add x 23 xhreq 172 x |
| 8041 | e = harray x 1 |
| 8042 | t = alloc |
| 8043 | matconst t get fr add x 23 |
| 8044 | e3 3942645760 31 get fr add x 22 t |
| 8045 | trapc 1 3 |
| 8046 | save |
| 8047 | hload x 4 0 |
| 8048 | hload x 2 1 |
| 8049 | basearg 2 e |
| 8050 | loadarg 16 1 get fr add x 21 |
| 8051 | e3 2332033024 2 2 16 |
| 8052 | hsys 29 |
| 8053 | hreturn dst x |
| 8054 | ret |
| 8055 | end |
| 8056 | if eq c 171 |
| 8057 | hdevcall dst x |
| 8058 | ret |
| 8059 | end |
| 8060 | if ge c 167 |
| 8061 | mtinit |
| 8062 | if eq c 167 |
| 8063 | mnew c dst x |
| 8064 | ret |
| 8065 | end |
| 8066 | if eq c 168 |
| 8067 | harg x 0 9 |
| 8068 | save |
| 8069 | hload x 0 10 |
| 8070 | mcheck |
| 8071 | e3 2852126720 0 31 13 |
| 8072 | e3 2852126720 1 31 12 |
| 8073 | hsys 215 |
| 8074 | mimmed 4043309056 31 0 0 |
| 8075 | failed = mbranch 1 |
| 8076 | mstore 31 11 0 |
| 8077 | mstore 31 11 1 |
| 8078 | mstore 31 11 3 |
| 8079 | patch19 failed get oc 0 |
| 8080 | hreturn dst x |
| 8081 | ret |
| 8082 | end |
| 8083 | mcopy c dst x |
| 8084 | ret |
| 8085 | end |
| 8086 | if eq c 166 |
| 8087 | note Same bounded ioctl contract as L605 src/device/omc.om at 0dee699. |
| 8088 | note Compose with native host words instead of maintaining a second compiler. |
| 8089 | note Only literal FIONREAD, encoded read/write NVRM F, or five exact aien-gpu ABI1 A requests. |
| 8090 | put fr add x 23 xhreq 166 x |
| 8091 | e = harray x 1 |
| 8092 | t = alloc |
| 8093 | matconst t get fr add x 23 |
| 8094 | e3 3942645760 31 get fr add x 22 t |
| 8095 | trapc 1 3 |
| 8096 | save |
| 8097 | hload x 4 0 |
| 8098 | hload x 2 1 |
| 8099 | basearg 2 e |
| 8100 | loadarg 16 1 get fr add x 21 |
| 8101 | e3 2332033024 2 2 16 |
| 8102 | hsys 29 |
| 8103 | hreturn dst x |
| 8104 | ret |
| 8105 | end |
| 8106 | if eq c 132 |
| 8107 | e = harray x 1 |
| 8108 | save |
| 8109 | basearg 0 e |
| 8110 | loadarg 16 1 get fr add x 21 |
| 8111 | e3 2332033024 0 0 16 |
| 8112 | loadarg 1 1 get fr add x 22 |
| 8113 | hsys 17 |
| 8114 | hreturn dst x |
| 8115 | ret |
| 8116 | end |
| 8117 | if eq c 133 |
| 8118 | hreadlnk dst x |
| 8119 | ret |
| 8120 | end |
| 8121 | if eq c 134 |
| 8122 | hsockopt dst x |
| 8123 | ret |
| 8124 | end |
| 8125 | if eq c 135 |
| 8126 | note random A off n flags: Linux getrandom into a writable byte slice. Returns the bytes written or |
| 8127 | note minus the Linux error number. flags follows getrandom(2): 0 blocks until the pool is ready, |
| 8128 | note 1 (GRND_NONBLOCK) returns -EAGAIN instead, 2 (GRND_INSECURE) may return non-cryptographic bytes. |
| 8129 | e = harray x 1 |
| 8130 | harg x 2 8 |
| 8131 | save |
| 8132 | basearg 0 e |
| 8133 | loadarg 16 1 get fr add x 21 |
| 8134 | e3 2332033024 0 0 16 |
| 8135 | loadarg 1 1 get fr add x 22 |
| 8136 | hload x 2 2 |
| 8137 | hsys 278 |
| 8138 | hreturn dst x |
| 8139 | ret |
| 8140 | end |
| 8141 | if or eq c 109 eq c 130 |
| 8142 | hclock c dst x |
| 8143 | ret |
| 8144 | end |
| 8145 | if or and ge c 113 le c 119 eq c 131 |
| 8146 | hbuffer c dst x |
| 8147 | ret |
| 8148 | end |
| 8149 | if eq c 120 |
| 8150 | harg x 0 9 |
| 8151 | save |
| 8152 | hload x 0 2 |
| 8153 | emit 4043309151 |
| 8154 | trapc 11 3 |
| 8155 | spsub 16 |
| 8156 | stkchk |
| 8157 | matconst 3 1000000000 |
| 8158 | e3 2596276224 4 2 3 |
| 8159 | note MSUB x5,x4,x3,x2 gives the subsecond remainder. |
| 8160 | emit 2600700037 |
| 8161 | emit 4177527780 |
| 8162 | emit 4177528805 |
| 8163 | emit 2432697312 |
| 8164 | matconst 1 0 |
| 8165 | hsys 101 |
| 8166 | spadd 16 |
| 8167 | hreturn dst x |
| 8168 | ret |
| 8169 | end |
| 8170 | if eq c 123 |
| 8171 | hwaitio dst x |
| 8172 | ret |
| 8173 | end |
| 8174 | if or or or eq c 124 eq c 125 eq c 141 eq c 142 |
| 8175 | hpack c dst x |
| 8176 | ret |
| 8177 | end |
| 8178 | if or or or or or or eq c 126 eq c 138 eq c 143 eq c 144 eq c 150 eq c 151 eq c 157 |
| 8179 | hpath c dst x |
| 8180 | ret |
| 8181 | end |
| 8182 | if eq c 140 |
| 8183 | hstat 140 dst x |
| 8184 | ret |
| 8185 | end |
| 8186 | if eq c 149 |
| 8187 | hstat 149 dst x |
| 8188 | ret |
| 8189 | end |
| 8190 | if and ge c 145 le c 148 |
| 8191 | hscalar c dst x |
| 8192 | ret |
| 8193 | end |
| 8194 | if or or or eq c 153 eq c 154 eq c 155 eq c 156 |
| 8195 | hscalar c dst x |
| 8196 | ret |
| 8197 | end |
| 8198 | if and ge c 158 le c 160 |
| 8199 | hscalar c dst x |
| 8200 | ret |
| 8201 | end |
| 8202 | if or eq c 161 eq c 162 |
| 8203 | hpread c dst x |
| 8204 | ret |
| 8205 | end |
| 8206 | if and ge c 163 le c 165 |
| 8207 | hscalar c dst x |
| 8208 | ret |
| 8209 | end |
| 8210 | if or or eq c 127 eq c 129 eq c 139 |
| 8211 | hscalar c dst x |
| 8212 | ret |
| 8213 | end |
| 8214 | if eq c 128 |
| 8215 | e = harray x 1 |
| 8216 | harg x 2 8 |
| 8217 | tmp = alloc |
| 8218 | matconst tmp 8 |
| 8219 | e3 3942645760 31 get fr add x 22 tmp |
| 8220 | trapc 3 3 |
| 8221 | save |
| 8222 | basearg 0 e |
| 8223 | loadarg 16 1 get fr add x 21 |
| 8224 | e3 2332033024 0 0 16 |
| 8225 | hload x 2 1 |
| 8226 | hsys 59 |
| 8227 | hreturn dst x |
| 8228 | ret |
| 8229 | end |
| 8230 | if ge c 121 |
| 8231 | put hostargs 0 1 |
| 8232 | hargs c dst x |
| 8233 | ret |
| 8234 | end |
| 8235 | if ge c 110 |
| 8236 | hpath c dst x |
| 8237 | ret |
| 8238 | end |
| 8239 | hscalar c dst x |
| 8240 | end |
| 8241 | |
| 8242 | note ======== rdval: read one value (om4 VAL, VALTOK, CALL and the VT_ parts, one self-recursive |
| 8243 | note function because a function calls only earlier functions or itself) ======== |
| 8244 | note mode 0: read the first word; 1: the first word is the current token; 2: a call of function fe (index |
| 8245 | note + 1), its arguments still to read. exp the expected type (0 none), dst the destination register (255 |
| 8246 | note none). Out: rk kind (1 register, 2 bare number, 3 typed number, 4 flags, 9 a float in a twin, only when |
| 8247 | note asked for by fpw), rv register / number / condition, rt type (for a bare number: 1 when written as 2^63 |
| 8248 | note or more). Only the outermost op writes the destination. Every value nests one level deeper (at most |
| 8249 | note 1024, error 14); a call does not. |
| 8250 | fn rdval mode ulong exp ulong dst ulong fe ulong to void |
| 8251 | note fwtake: rdval's entry: keep the caller's fpw request for this depth (none on x86, which has no twins) |
| 8252 | if eq get xtarget 0 0 |
| 8253 | put fwv add get depth 0 1 get fpw 0 |
| 8254 | else |
| 8255 | put fwv add get depth 0 1 0 |
| 8256 | end |
| 8257 | put fpw 0 0 |
| 8258 | put dexp 0 1 |
| 8259 | if eq mode 2 |
| 8260 | if ne get cpure 0 0 |
| 8261 | fail 30 |
| 8262 | end |
| 8263 | if ne get om2 0 0 |
| 8264 | if ne get fn_inl sub fe 1 0 |
| 8265 | inl_call fe dst |
| 8266 | ret |
| 8267 | end |
| 8268 | end |
| 8269 | cb = add mul get depth 0 32 8 |
| 8270 | put fr add cb 18 ulong get fn_np sub fe 1 |
| 8271 | put fr add cb 19 get nslot 0 |
| 8272 | if eq get progmode 0 0 |
| 8273 | if eq get curfn 0 fe |
| 8274 | fail 9 |
| 8275 | end |
| 8276 | end |
| 8277 | i = ulong 0 |
| 8278 | while lt i get fr add cb 18 |
| 8279 | p = add mul sub fe 1 6 i |
| 8280 | if eq get fn_pk p 0 |
| 8281 | if ne isfloat ulong get fn_pt p 0 |
| 8282 | put fpw 0 1 |
| 8283 | end |
| 8284 | rdval 0 ulong get fn_pt p 255 0 |
| 8285 | ca_scal p add cb mul i 3 |
| 8286 | else |
| 8287 | if ge get fn_pk p 6 |
| 8288 | ca_st fe i cb |
| 8289 | else |
| 8290 | ca_arr fe i cb |
| 8291 | fz_arg get rt 0 |
| 8292 | end |
| 8293 | end |
| 8294 | i = add i 1 |
| 8295 | end |
| 8296 | ca_end fe dst cb |
| 8297 | ret |
| 8298 | end |
| 8299 | if eq mode 0 |
| 8300 | tok |
| 8301 | end |
| 8302 | if ne get cpure 0 0 |
| 8303 | cp_token |
| 8304 | end |
| 8305 | put depth 0 add get depth 0 1 |
| 8306 | if gt get depth 0 1024 |
| 8307 | fail 14 |
| 8308 | end |
| 8309 | if or eq get tk 0 0 eq get tk 0 3 |
| 8310 | fail 4 |
| 8311 | end |
| 8312 | if eq get tk 0 4 |
| 8313 | fail 16 |
| 8314 | end |
| 8315 | if eq get tk 0 5 |
| 8316 | if ne get irmode 0 0 |
| 8317 | fail 9 |
| 8318 | end |
| 8319 | if ge exp 64 |
| 8320 | fail 7 |
| 8321 | end |
| 8322 | fparse get ts 0 get tl 0 |
| 8323 | t = ulong 0 |
| 8324 | if eq get fsuf 0 0 |
| 8325 | if eq exp 0 |
| 8326 | vdone 6 add mul get ts 0 16777216 get tl 0 ulong 0 |
| 8327 | ret |
| 8328 | end |
| 8329 | if eq isfloat exp 0 |
| 8330 | fail 7 |
| 8331 | end |
| 8332 | t = exp |
| 8333 | else |
| 8334 | t = ulong 10 |
| 8335 | if eq get fsuf 0 2 |
| 8336 | t = ulong 11 |
| 8337 | end |
| 8338 | if and ne exp 0 ne exp t |
| 8339 | fail 7 |
| 8340 | end |
| 8341 | end |
| 8342 | v = fbits t |
| 8343 | vdone 7 v t |
| 8344 | ret |
| 8345 | end |
| 8346 | if eq get tk 0 2 |
| 8347 | if eq exp 0 |
| 8348 | vdone 2 get tw 0 get tbig 0 |
| 8349 | ret |
| 8350 | end |
| 8351 | note an integer literal where a float is expected is the mixing OMEGESE 9.9 refuses (error 7); before |
| 8352 | note this it was stored as raw bits (f64 x = 1 held 0x1). The conversion f64 1 reads it with exp 0. |
| 8353 | if or ge exp 64 ne isfloat exp 0 |
| 8354 | fail 7 |
| 8355 | end |
| 8356 | range get tw 0 exp get tbig 0 |
| 8357 | vdone 3 get tw 0 exp |
| 8358 | ret |
| 8359 | end |
| 8360 | if gt get tl 0 8 |
| 8361 | f = findfn get tw 0 get tl 0 get ts 0 |
| 8362 | if eq f 0 |
| 8363 | unkfail 13 |
| 8364 | end |
| 8365 | if eq get fn_ret sub f 1 12 |
| 8366 | fail 7 |
| 8367 | end |
| 8368 | rdval 2 0 dst f |
| 8369 | vdec |
| 8370 | ret |
| 8371 | end |
| 8372 | c = kw get tw 0 |
| 8373 | if eq c 178 |
| 8374 | xefival dst |
| 8375 | ret |
| 8376 | end |
| 8377 | if eq c 0 |
| 8378 | if ne get cpure 0 0 |
| 8379 | if eq get tw 0 128009175786866 |
| 8380 | if eq get crkind 0 0 |
| 8381 | fail 30 |
| 8382 | end |
| 8383 | vdone get crkind 0 get crval 0 get crtype 0 |
| 8384 | ret |
| 8385 | end |
| 8386 | end |
| 8387 | e = findname get tw 0 |
| 8388 | if ne e 0 |
| 8389 | if eq get nm_kind sub e 1 9 |
| 8390 | ct = ulong get nm_type sub e 1 |
| 8391 | cv = get nm_addr sub e 1 |
| 8392 | if ne isfloat ct 0 |
| 8393 | vdone 7 cv ct |
| 8394 | else |
| 8395 | vdone 3 cv ct |
| 8396 | end |
| 8397 | ret |
| 8398 | end |
| 8399 | if ne get nm_kind sub e 1 0 |
| 8400 | fail 7 |
| 8401 | end |
| 8402 | e1 = sub e 1 |
| 8403 | if ne get nm_fv e1 0 |
| 8404 | nr = ulong get nm_reg e1 |
| 8405 | if ne get fwv get depth 0 0 |
| 8406 | vdone 9 nr ulong get nm_type e1 |
| 8407 | else |
| 8408 | fv2x ulong get nm_type e1 vtw nr nr |
| 8409 | vdone 1 nr ulong get nm_type e1 |
| 8410 | end |
| 8411 | else |
| 8412 | vdone 1 ulong get nm_reg e1 ulong get nm_type e1 |
| 8413 | end |
| 8414 | if ne get cpure 0 0 |
| 8415 | if ge get rt 0 10 |
| 8416 | fail 30 |
| 8417 | end |
| 8418 | end |
| 8419 | ret |
| 8420 | end |
| 8421 | f = findfn get tw 0 0 0 |
| 8422 | if eq f 0 |
| 8423 | unkfail 3 |
| 8424 | end |
| 8425 | if eq get fn_ret sub f 1 12 |
| 8426 | fail 7 |
| 8427 | end |
| 8428 | rdval 2 0 dst f |
| 8429 | vdec |
| 8430 | ret |
| 8431 | end |
| 8432 | if or eq c 88 eq c 89 |
| 8433 | t = ulong 10 |
| 8434 | if eq c 89 |
| 8435 | t = ulong 11 |
| 8436 | end |
| 8437 | rdval 0 0 255 0 |
| 8438 | if ge get rt 0 64 |
| 8439 | fail 7 |
| 8440 | end |
| 8441 | if eq get rk 0 6 |
| 8442 | v = fspan t get rv 0 |
| 8443 | put rk 0 7 |
| 8444 | put rv 0 v |
| 8445 | put rt 0 t |
| 8446 | end |
| 8447 | if eq get rk 0 2 |
| 8448 | range get rv 0 9 get tbig 0 |
| 8449 | put rk 0 3 |
| 8450 | put rt 0 9 |
| 8451 | end |
| 8452 | if eq get rt 0 1 |
| 8453 | fail 7 |
| 8454 | end |
| 8455 | fwreq |
| 8456 | vt_conv t |
| 8457 | vdec |
| 8458 | ret |
| 8459 | end |
| 8460 | if eq c 90 |
| 8461 | if ne get irmode 0 0 |
| 8462 | fail 9 |
| 8463 | end |
| 8464 | tt = typeword |
| 8465 | rdval 0 0 255 0 |
| 8466 | if or eq get rk 0 6 eq get rk 0 2 |
| 8467 | fail 11 |
| 8468 | end |
| 8469 | ft = get rt 0 |
| 8470 | if eq ft 1 |
| 8471 | fail 7 |
| 8472 | end |
| 8473 | if or ge ft 64 ge tt 64 |
| 8474 | fail 7 |
| 8475 | end |
| 8476 | if ne twid ft twid tt |
| 8477 | fail 7 |
| 8478 | end |
| 8479 | r = matreg get rk 0 get rv 0 ft |
| 8480 | note A register holds an 8/16/32-bit unsigned value and an f32 zero-extended (canon, FMOV W) and a signed |
| 8481 | note one sign-extended, so a bitcast that changes the extension extends the bits again for tt, into a new |
| 8482 | note register (a name's register keeps its value). f32 takes the uint form. |
| 8483 | if ne twid tt 64 |
| 8484 | if ne and ge ft 6 le ft 8 and ge tt 6 le tt 8 |
| 8485 | ct = tt |
| 8486 | if eq tt 10 |
| 8487 | ct = ulong 4 |
| 8488 | end |
| 8489 | rd = destreg dst |
| 8490 | canonto rd r ct |
| 8491 | r = rd |
| 8492 | end |
| 8493 | end |
| 8494 | put rk 0 1 |
| 8495 | put rv 0 r |
| 8496 | put rt 0 tt |
| 8497 | vdec |
| 8498 | ret |
| 8499 | end |
| 8500 | if or or or eq c 91 eq c 92 eq c 93 eq c 94 |
| 8501 | fwreq |
| 8502 | if or eq c 91 eq c 92 |
| 8503 | fintr c dst |
| 8504 | else |
| 8505 | fminmax c dst |
| 8506 | end |
| 8507 | ret |
| 8508 | end |
| 8509 | if eq c 227 |
| 8510 | fwreq |
| 8511 | ffma dst |
| 8512 | ret |
| 8513 | end |
| 8514 | if eq c 95 |
| 8515 | fsizeof dst |
| 8516 | ret |
| 8517 | end |
| 8518 | if eq c 96 |
| 8519 | foffset dst |
| 8520 | ret |
| 8521 | end |
| 8522 | if le sub c 1 8 |
| 8523 | tok |
| 8524 | if eq get tk 0 2 |
| 8525 | range get tw 0 c get tbig 0 |
| 8526 | vdone 3 get tw 0 c |
| 8527 | ret |
| 8528 | end |
| 8529 | rdval 1 0 255 0 |
| 8530 | if ge get rt 0 64 |
| 8531 | fail 7 |
| 8532 | end |
| 8533 | if eq get rk 0 2 |
| 8534 | fail 11 |
| 8535 | end |
| 8536 | vt_conv c |
| 8537 | vdec |
| 8538 | ret |
| 8539 | end |
| 8540 | if eq c 223 |
| 8541 | tok |
| 8542 | if eq get tk 0 2 |
| 8543 | range get tw 0 13 get tbig 0 |
| 8544 | vdone 3 get tw 0 13 |
| 8545 | ret |
| 8546 | end |
| 8547 | rdval 1 0 255 0 |
| 8548 | if eq get rk 0 6 |
| 8549 | fail 7 |
| 8550 | end |
| 8551 | if ge get rt 0 64 |
| 8552 | fail 7 |
| 8553 | end |
| 8554 | if eq get rk 0 2 |
| 8555 | fail 11 |
| 8556 | end |
| 8557 | vt_conv 13 |
| 8558 | vdec |
| 8559 | ret |
| 8560 | end |
| 8561 | if eq c 74 |
| 8562 | put fpw 0 get fwv get depth 0 |
| 8563 | rdval 0 exp dst 0 |
| 8564 | tok |
| 8565 | if ne get tk 0 1 |
| 8566 | fail 16 |
| 8567 | end |
| 8568 | if gt get tl 0 8 |
| 8569 | fail 16 |
| 8570 | end |
| 8571 | if ne kw get tw 0 75 |
| 8572 | fail 16 |
| 8573 | end |
| 8574 | vdec |
| 8575 | ret |
| 8576 | end |
| 8577 | if or eq c 77 eq c 193 |
| 8578 | fail 9 |
| 8579 | end |
| 8580 | if or eq c 225 eq c 226 |
| 8581 | if or eq get progmode 0 0 ne get irmode 0 0 |
| 8582 | fail 9 |
| 8583 | end |
| 8584 | x = mul get depth 0 32 |
| 8585 | sl = get nslot 0 |
| 8586 | note dit and scrub are emitted inline here, not in helper functions: om4 holds 512 functions and omc.om |
| 8587 | note uses 511 of them (seed/omc/size-history.tsv). |
| 8588 | if eq c 225 |
| 8589 | note dit: OM-2 `dit v` (program mode): v is int, 0 or 1, else trap 3. Sets PSTATE.DIT (Arm ARM |
| 8590 | note C5.2.4: DIT is bit 24 of the special-purpose register; MRS/MSR <Xt>, DIT have op0 3, op1 3, CRn 4, |
| 8591 | note CRm 2, op2 5) and gives the previous bit as a long 0 or 1. CMP Xv, #1 = SUBS XZR (C6.2.464); B.HI |
| 8592 | note trap 3; LSL X16, Xv, #24 = UBFM X16, Xv, #40, #39 (C6.2.487), taken before the destination is |
| 8593 | note written because the destination may be v's own register; MRS Xd, DIT (C6.2.287); MSR DIT, X16 |
| 8594 | note (C6.2.289); UBFX Xd, Xd, #24, #1 = UBFM Xd, Xd, #24, #24. Writes to PSTATE are in program order |
| 8595 | note without further synchronization (C5.1), so the next instruction already runs under the new bit. |
| 8596 | harg x 0 8 |
| 8597 | r = matreg get fr add x 8 get fr add x 9 8 |
| 8598 | emit or 4043310111 shl r 5 |
| 8599 | trapc 8 3 |
| 8600 | emit or 3546848272 shl r 5 |
| 8601 | put nslot 0 sl |
| 8602 | d = destreg dst |
| 8603 | emit or 3577430688 d |
| 8604 | emit 3575333552 |
| 8605 | emit or or 3545784320 shl d 5 d |
| 8606 | vdone 1 d 9 |
| 8607 | ret |
| 8608 | end |
| 8609 | note scrub: OM-2 `scrub n` (program mode): n is ulong, a multiple of 16 and at most 1048576, else trap 3. |
| 8610 | note TST Xn, #15 = ANDS XZR (C6.2.16, N 1 immr 0 imms 3); B.NE trap 3; X16 = 1048576; CMP Xn, X16 = |
| 8611 | note SUBS XZR (C6.2.465); B.HI trap 3. X16 = SP - n: SUB X16, SP, Xn, UXTX (C6.2.456); CMP X16, X28 |
| 8612 | note (C6.2.465); B.LO trap 6, before any store. Loop: CMP SP, X16 = SUBS XZR, SP, X16, UXTX (C6.2.463); |
| 8613 | note B.LS out; STP XZR, XZR, [X16], #16 (C6.2.414, post-index); B back (C6.2.35). Then MOVZ Xr, #0 |
| 8614 | note (C6.2.319) for every pool register at index npar + nslot or above (no live value: parameters, |
| 8615 | note locals and the held parts of the expression sit below), X16, and X7, X18-X26, X29, which program |
| 8616 | note mode never names; then MOVI Vd.2D, #0 (C7.2.247) for V0-V15 and for every twin V16+j except those |
| 8617 | note of a live slot j (below npar + nslot) whose value lives in its twin (vsl: an f32/f64 local name or a |
| 8618 | note held kind 9 float, as save stores it); a twin of a free slot or of a slot whose value is in its x |
| 8619 | note register holds nothing live. V0-V15 carry a float only inside one operation. Never touched: SP, X27 |
| 8620 | note (the Linux initial stack under args), X28 (the stack floor), X30 (the return address), the live pool |
| 8621 | note registers and live twins, NZCV, FPCR, FPSR, and the SVE P registers and FFR. Gives long 0. |
| 8622 | harg x 0 5 |
| 8623 | r = matreg get fr add x 8 get fr add x 9 5 |
| 8624 | emit or 4064283679 shl r 5 |
| 8625 | trapc 1 3 |
| 8626 | matconst 16 1048576 |
| 8627 | emit or 3943694367 shl r 5 |
| 8628 | trapc 8 3 |
| 8629 | emit or 3407897584 shl r 16 |
| 8630 | emit 3944481311 |
| 8631 | trapc 3 6 |
| 8632 | top = get oc 0 |
| 8633 | emit 3945817087 |
| 8634 | at = get oc 0 |
| 8635 | emit 1409286153 |
| 8636 | emit 2827058719 |
| 8637 | back top |
| 8638 | patch19 at get oc 0 |
| 8639 | i = add get npar 0 sl |
| 8640 | while lt i 16 |
| 8641 | emit or 3531603968 poolc i |
| 8642 | i = add i 1 |
| 8643 | end |
| 8644 | emit 3531603984 |
| 8645 | emit 3531603975 |
| 8646 | i = ulong 18 |
| 8647 | while le i 26 |
| 8648 | emit or 3531603968 i |
| 8649 | i = add i 1 |
| 8650 | end |
| 8651 | emit 3531603997 |
| 8652 | at = add get npar 0 sl |
| 8653 | i = ulong 0 |
| 8654 | while lt i 32 |
| 8655 | top = and i 15 |
| 8656 | r = ulong get vsl top |
| 8657 | if or lt i 16 ge top at |
| 8658 | r = ulong 0 |
| 8659 | end |
| 8660 | if eq r 0 |
| 8661 | emit or 1862329344 i |
| 8662 | end |
| 8663 | i = add i 1 |
| 8664 | end |
| 8665 | put nslot 0 sl |
| 8666 | d = destreg dst |
| 8667 | matconst d 0 |
| 8668 | vdone 1 d 9 |
| 8669 | ret |
| 8670 | end |
| 8671 | if or or and ge c 100 le c 177 and ge c 197 le c 198 and ge c 220 le c 222 |
| 8672 | hostval c dst |
| 8673 | ret |
| 8674 | end |
| 8675 | if eq c 224 |
| 8676 | hostval c dst |
| 8677 | ret |
| 8678 | end |
| 8679 | if or and ge c 228 le c 232 eq c 233 |
| 8680 | hostval c dst |
| 8681 | ret |
| 8682 | end |
| 8683 | if eq c 186 |
| 8684 | rdval 0 0 255 0 |
| 8685 | ab_open |
| 8686 | vdec |
| 8687 | ret |
| 8688 | end |
| 8689 | if eq c 185 |
| 8690 | ab_seal |
| 8691 | vdec |
| 8692 | ret |
| 8693 | end |
| 8694 | if eq c 179 |
| 8695 | cnt_word dst |
| 8696 | ret |
| 8697 | end |
| 8698 | if eq c 51 |
| 8699 | e = arrname |
| 8700 | if ge get nm_kind sub e 1 6 |
| 8701 | vt_fget e dst |
| 8702 | vdec |
| 8703 | ret |
| 8704 | end |
| 8705 | if ne ly_get e dst 0 |
| 8706 | vdec |
| 8707 | ret |
| 8708 | end |
| 8709 | rdval 0 5 255 0 |
| 8710 | fz_get e |
| 8711 | fwreq |
| 8712 | vt_get e dst |
| 8713 | vdec |
| 8714 | ret |
| 8715 | end |
| 8716 | if eq c 52 |
| 8717 | e = arrname |
| 8718 | if ge get nm_kind sub e 1 6 |
| 8719 | fail 7 |
| 8720 | end |
| 8721 | if ne unsz sub e 1 0 |
| 8722 | vdone 1 ulong get nm_lr sub e 1 5 |
| 8723 | ret |
| 8724 | end |
| 8725 | vdone 3 get nm_len sub e 1 5 |
| 8726 | ret |
| 8727 | end |
| 8728 | if or eq c 53 eq c 54 |
| 8729 | x = mul get depth 0 32 |
| 8730 | put fr add x 8 get nslot 0 |
| 8731 | rdval 0 8 255 0 |
| 8732 | vs_fd x |
| 8733 | e = arrname |
| 8734 | vs_arr c e |
| 8735 | rdval 0 5 255 0 |
| 8736 | vs_off x |
| 8737 | rdval 0 5 255 0 |
| 8738 | vs_end c e dst x |
| 8739 | ret |
| 8740 | end |
| 8741 | if eq c 55 |
| 8742 | vdone 3 1 1 |
| 8743 | ret |
| 8744 | end |
| 8745 | if eq c 56 |
| 8746 | vdone 3 0 1 |
| 8747 | ret |
| 8748 | end |
| 8749 | if and gt sub c 33 17 gt sub c 59 1 |
| 8750 | fail 16 |
| 8751 | end |
| 8752 | if and ge c 49 le c 50 |
| 8753 | put fpw 0 1 |
| 8754 | rdval 0 exp 255 0 |
| 8755 | if ge get rt 0 64 |
| 8756 | fail 7 |
| 8757 | end |
| 8758 | if and eq c 50 eq get rk 0 4 |
| 8759 | put rv 0 xor get rv 0 1 |
| 8760 | vdec |
| 8761 | ret |
| 8762 | end |
| 8763 | if eq get rk 0 2 |
| 8764 | fail 11 |
| 8765 | end |
| 8766 | fwreq |
| 8767 | vt_un c dst |
| 8768 | vdec |
| 8769 | ret |
| 8770 | end |
| 8771 | put fpw 0 1 |
| 8772 | rdval 0 0 255 0 |
| 8773 | ak = get rk 0 |
| 8774 | av = get rv 0 |
| 8775 | at = get rt 0 |
| 8776 | if eq ak 4 |
| 8777 | av = matreg 4 av at |
| 8778 | ak = ulong 1 |
| 8779 | at = ulong 1 |
| 8780 | end |
| 8781 | put fpw 0 1 |
| 8782 | rdval 0 0 255 0 |
| 8783 | bk = get rk 0 |
| 8784 | bv = get rv 0 |
| 8785 | bt = get rt 0 |
| 8786 | if eq bk 4 |
| 8787 | bv = matreg 4 bv bt |
| 8788 | bk = ulong 1 |
| 8789 | bt = ulong 1 |
| 8790 | end |
| 8791 | if or ge at 64 ge bt 64 |
| 8792 | x = mul get depth 0 32 |
| 8793 | put fr x ak |
| 8794 | put fr add x 1 av |
| 8795 | put fr add x 2 at |
| 8796 | put fr add x 3 bk |
| 8797 | put fr add x 4 bv |
| 8798 | put fr add x 5 bt |
| 8799 | ab_bin c dst x |
| 8800 | vdec |
| 8801 | ret |
| 8802 | end |
| 8803 | if and eq ak 6 eq bk 6 |
| 8804 | fail 11 |
| 8805 | end |
| 8806 | if or ne isfloat at 0 ne isfloat bt 0 |
| 8807 | if eq ak 6 |
| 8808 | if eq bt 0 |
| 8809 | fail 11 |
| 8810 | end |
| 8811 | if eq isfloat bt 0 |
| 8812 | fail 7 |
| 8813 | end |
| 8814 | av = fspan bt av |
| 8815 | ak = ulong 7 |
| 8816 | at = bt |
| 8817 | end |
| 8818 | if eq bk 6 |
| 8819 | if eq at 0 |
| 8820 | fail 11 |
| 8821 | end |
| 8822 | if eq isfloat at 0 |
| 8823 | fail 7 |
| 8824 | end |
| 8825 | bv = fspan at bv |
| 8826 | bk = ulong 7 |
| 8827 | bt = at |
| 8828 | end |
| 8829 | if or eq ak 2 eq ak 3 |
| 8830 | fail 7 |
| 8831 | end |
| 8832 | if or eq bk 2 eq bk 3 |
| 8833 | fail 7 |
| 8834 | end |
| 8835 | end |
| 8836 | if or eq ak 6 eq bk 6 |
| 8837 | fail 7 |
| 8838 | end |
| 8839 | if eq ak 2 |
| 8840 | if eq bk 2 |
| 8841 | fail 11 |
| 8842 | end |
| 8843 | range av bt at |
| 8844 | at = bt |
| 8845 | ak = ulong 3 |
| 8846 | end |
| 8847 | if eq bk 2 |
| 8848 | range bv at bt |
| 8849 | bt = at |
| 8850 | bk = ulong 3 |
| 8851 | end |
| 8852 | if and ne c 41 ne c 42 |
| 8853 | if ne at bt |
| 8854 | fail 7 |
| 8855 | end |
| 8856 | end |
| 8857 | x = mul get depth 0 32 |
| 8858 | put fr x ak |
| 8859 | put fr add x 1 av |
| 8860 | put fr add x 2 at |
| 8861 | put fr add x 3 bk |
| 8862 | put fr add x 4 bv |
| 8863 | put fr add x 5 bt |
| 8864 | if ne isfloat at 0 |
| 8865 | fwreq |
| 8866 | end |
| 8867 | binop c dst x |
| 8868 | vdec |
| 8869 | end |
| 8870 | |
| 8871 | note cond: read a condition (a bool value); emit a branch taken when it is false: B.cond with the opposite |
| 8872 | note condition (C6.2.34), or CBZ Xr (C6.2.78). Returns that branch's place. om4 COND. |
| 8873 | fn cond to ulong |
| 8874 | if ne get xtarget 0 0 |
| 8875 | rdval 0 1 255 0 |
| 8876 | if ne get rt 0 1 |
| 8877 | fail 7 |
| 8878 | end |
| 8879 | if eq get rk 0 4 |
| 8880 | ret xbranch xor get rv 0 1 |
| 8881 | end |
| 8882 | r = matreg get rk 0 get rv 0 get rt 0 |
| 8883 | xcmp r 0 1 |
| 8884 | ret xbranch 0 |
| 8885 | end |
| 8886 | rdval 0 1 255 0 |
| 8887 | if ne get rt 0 1 |
| 8888 | fail 7 |
| 8889 | end |
| 8890 | if eq get rk 0 4 |
| 8891 | at = get oc 0 |
| 8892 | emit or 1409286144 xor get rv 0 1 |
| 8893 | ret at |
| 8894 | end |
| 8895 | r = matreg get rk 0 get rv 0 get rt 0 |
| 8896 | at = get oc 0 |
| 8897 | emit or 3019898880 r |
| 8898 | ret at |
| 8899 | end |
| 8900 | |
| 8901 | note ======== statements, one per line (om4 STMT and the S_ parts) ======== |
| 8902 | note skipnl: note ...: the rest of the line is not read (up to the newline, which tok reads). om4 S_NOTE. |
| 8903 | fn skipnl to void |
| 8904 | go = true |
| 8905 | while go |
| 8906 | n = ulong 0 |
| 8907 | while and go lt n 999999 |
| 8908 | if ge get cur 0 get inlen 0 |
| 8909 | go = false |
| 8910 | else |
| 8911 | if eq get inp get cur 0 10 |
| 8912 | go = false |
| 8913 | else |
| 8914 | put cur 0 add get cur 0 1 |
| 8915 | end |
| 8916 | end |
| 8917 | n = add n 1 |
| 8918 | end |
| 8919 | end |
| 8920 | end |
| 8921 | |
| 8922 | note blo: B.LO back to an earlier place (C6.2.34) |
| 8923 | fn blo at ulong to void |
| 8924 | if ne get xtarget 0 0 |
| 8925 | p = xbranch 3 |
| 8926 | xpatch p at |
| 8927 | ret |
| 8928 | end |
| 8929 | d = bdisp get oc 0 at 19 |
| 8930 | emit or 1409286147 shl d 5 |
| 8931 | end |
| 8932 | |
| 8933 | 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 |
| 8934 | note outermost block, so the stack held by local arrays is known at every ret. SUB SP (C6.2.457); program |
| 8935 | note mode: the stack check; MOV Xb, SP (ADD immediate, C6.2.5); then the fill loop: STR v, [Xb, Xi, LSL]; |
| 8936 | note ADD Xi, Xi, #1; CMP Xi, #N or Xn; B.LO back (C6.2.34). om4 SA_ARR. |
| 8937 | fn sa_arr w ulong to void |
| 8938 | if ne get xtarget 0 0 |
| 8939 | xarray w |
| 8940 | ret |
| 8941 | end |
| 8942 | if ne get nb 0 0 |
| 8943 | fail 9 |
| 8944 | end |
| 8945 | t = typeword |
| 8946 | elemtype t |
| 8947 | n = lenval 16 |
| 8948 | arrlen n |
| 8949 | by = shl shr add shl n tlog t 15 4 4 |
| 8950 | s = add get stkbytes 0 by |
| 8951 | if gt s 4194304 |
| 8952 | fail 23 |
| 8953 | end |
| 8954 | put stkbytes 0 s |
| 8955 | r = alloc |
| 8956 | put held 0 get nslot 0 |
| 8957 | rdval 0 t 255 0 |
| 8958 | if ne get rt 0 t |
| 8959 | fail 7 |
| 8960 | end |
| 8961 | v = matreg get rk 0 get rv 0 get rt 0 |
| 8962 | spsub by |
| 8963 | stkchk |
| 8964 | emit or 2432697312 r |
| 8965 | i = alloc |
| 8966 | emit or 3531603968 i |
| 8967 | m = ulong 0 |
| 8968 | if gt n 4095 |
| 8969 | m = alloc |
| 8970 | matconst m n |
| 8971 | end |
| 8972 | lp = get oc 0 |
| 8973 | emit or or or stop t v shl r 5 shl i 16 |
| 8974 | emit or or 2432697344 i shl i 5 |
| 8975 | if le n 4095 |
| 8976 | emit or or 4043309087 shl n 10 shl i 5 |
| 8977 | else |
| 8978 | emit or or 3942645791 shl m 16 shl i 5 |
| 8979 | end |
| 8980 | blo lp |
| 8981 | addname w r t n 1 0 |
| 8982 | end |
| 8983 | |
| 8984 | note s_assign: name [=] value (an existing scalar, or a new one), or name = new T N v. om4 S_ASSIGN. A new |
| 8985 | note f32/f64 name lives in the twin of its register (nm_fv, vsl): the value is made there when it can be. |
| 8986 | fn s_assign w ulong to void |
| 8987 | tok |
| 8988 | if eq get tk 0 1 |
| 8989 | if le get tl 0 8 |
| 8990 | if eq kw get tw 0 73 |
| 8991 | tok |
| 8992 | end |
| 8993 | end |
| 8994 | end |
| 8995 | e = findname w |
| 8996 | if ne e 0 |
| 8997 | i = sub e 1 |
| 8998 | if ne get nm_kind i 0 |
| 8999 | fail 7 |
| 9000 | end |
| 9001 | r = ulong get nm_reg i |
| 9002 | t = ulong get nm_type i |
| 9003 | if ne get nm_fv i 0 |
| 9004 | put fpw 0 add r 2 |
| 9005 | rdval 1 t 255 0 |
| 9006 | if ne get rt 0 t |
| 9007 | fail 7 |
| 9008 | end |
| 9009 | fvset get rk 0 get rv 0 t r |
| 9010 | eol |
| 9011 | ret |
| 9012 | end |
| 9013 | rdval 1 t r 0 |
| 9014 | if ne get rt 0 t |
| 9015 | fail 7 |
| 9016 | end |
| 9017 | force get rk 0 get rv 0 get rt 0 r |
| 9018 | eol |
| 9019 | ret |
| 9020 | end |
| 9021 | if ne findfn w 0 0 0 |
| 9022 | fail 10 |
| 9023 | end |
| 9024 | if eq get tk 0 1 |
| 9025 | if le get tl 0 8 |
| 9026 | if eq kw get tw 0 84 |
| 9027 | sa_new w |
| 9028 | eol |
| 9029 | ret |
| 9030 | end |
| 9031 | end |
| 9032 | end |
| 9033 | r = alloc |
| 9034 | put held 0 get nslot 0 |
| 9035 | put fpw 0 add r 2 |
| 9036 | rdval 1 0 r 0 |
| 9037 | if eq get rk 0 2 |
| 9038 | fail 11 |
| 9039 | end |
| 9040 | t = get rt 0 |
| 9041 | if and ne isfloat t 0 eq get xtarget 0 0 |
| 9042 | fvset get rk 0 get rv 0 t r |
| 9043 | put vsl regidx r uchar 1 |
| 9044 | addname w r t 0 0 0 |
| 9045 | put nm_fv sub get nn 0 1 uchar 1 |
| 9046 | else |
| 9047 | force get rk 0 get rv 0 t r |
| 9048 | addname w r t 0 0 0 |
| 9049 | end |
| 9050 | eol |
| 9051 | end |
| 9052 | |
| 9053 | note s_name: a name at the start of a line: a call of a void function, or name [=] value. om4 S_NAME. |
| 9054 | fn s_name w ulong to void |
| 9055 | if ne findname w 0 |
| 9056 | s_assign w |
| 9057 | ret |
| 9058 | end |
| 9059 | f = findfn w get tl 0 0 |
| 9060 | if eq f 0 |
| 9061 | s_assign w |
| 9062 | ret |
| 9063 | end |
| 9064 | if ne get fn_ret sub f 1 12 |
| 9065 | fail 7 |
| 9066 | end |
| 9067 | rdval 2 0 255 f |
| 9068 | eol |
| 9069 | end |
| 9070 | |
| 9071 | note fn_p: the type of parameter np (name pw) of function f (index): T, or view / edit T N (an array: |
| 9072 | note kind 2 / 3, element type, length 1 .. 2^24). om4 FN_P .. FN_ADD. |
| 9073 | fn fn_p f ulong np ulong pw ulong to void |
| 9074 | tok |
| 9075 | if ne get tk 0 1 |
| 9076 | fail 16 |
| 9077 | end |
| 9078 | if gt get tl 0 8 |
| 9079 | fail 16 |
| 9080 | end |
| 9081 | c = kw get tw 0 |
| 9082 | t = ulong 0 |
| 9083 | ln = ulong 0 |
| 9084 | k = ulong 0 |
| 9085 | if eq c 194 |
| 9086 | fn_p_out f np pw |
| 9087 | ret |
| 9088 | end |
| 9089 | if or eq c 57 eq c 58 |
| 9090 | k = sub c 55 |
| 9091 | sid = peek_struct |
| 9092 | if ne sid 0 |
| 9093 | fn_p_st f np pw sid k |
| 9094 | ret |
| 9095 | end |
| 9096 | if ne get om2 0 0 |
| 9097 | lid = peek_lay |
| 9098 | if ne lid 0 |
| 9099 | fn_p_ly f np pw lid k |
| 9100 | ret |
| 9101 | end |
| 9102 | end |
| 9103 | t = typeword |
| 9104 | elemtype t |
| 9105 | if and ne get om2 0 0 ne peekstar 0 |
| 9106 | tok |
| 9107 | else |
| 9108 | ln = lenval 16 |
| 9109 | arrlen ln |
| 9110 | if ne get om2 0 0 |
| 9111 | if eq peekw 183 |
| 9112 | tok |
| 9113 | fz_par f np k ln |
| 9114 | end |
| 9115 | end |
| 9116 | end |
| 9117 | else |
| 9118 | if eq c 88 |
| 9119 | t = ulong 10 |
| 9120 | else |
| 9121 | if eq c 89 |
| 9122 | t = ulong 11 |
| 9123 | else |
| 9124 | if eq c 223 |
| 9125 | t = ulong 13 |
| 9126 | else |
| 9127 | if gt sub c 1 8 |
| 9128 | t = abty |
| 9129 | else |
| 9130 | t = c |
| 9131 | end |
| 9132 | end |
| 9133 | end |
| 9134 | end |
| 9135 | end |
| 9136 | addname pw poolc get psl 0 t ln k 0 |
| 9137 | if and ne k 0 eq ln 0 |
| 9138 | put nm_lr sub get nn 0 1 uchar poolc add get psl 0 1 |
| 9139 | end |
| 9140 | fz_bind add mul f 6 np ln |
| 9141 | p = add mul f 6 np |
| 9142 | put fn_pt p uchar t |
| 9143 | put fn_pl p ln |
| 9144 | put fn_pk p uchar k |
| 9145 | end |
| 9146 | |
| 9147 | note fn_p_out (OM-2, spec 6, erratum E1): `NAME out T N`, a sized array the unit writes and the bridge owns |
| 9148 | note (copied out only after status 0). Inside the unit it is an edit of T N (kind 3) in one slot, its |
| 9149 | note pointer; a length `*` is error 16, and so is `fresh` after it. |
| 9150 | fn fn_p_out f ulong np ulong pw ulong to void |
| 9151 | t = typeword |
| 9152 | elemtype t |
| 9153 | ln = lenval 16 |
| 9154 | arrlen ln |
| 9155 | addname pw poolc get psl 0 t ln 3 0 |
| 9156 | p = add mul f 6 np |
| 9157 | put fn_pt p uchar t |
| 9158 | put fn_pl p ln |
| 9159 | put fn_pk p 3 |
| 9160 | end |
| 9161 | |
| 9162 | note fn_to: to T | to void at the end of a fn line; the function's state starts. om4 FN_TO .. FN_T2. |
| 9163 | fn fn_to f ulong np ulong to void |
| 9164 | tok |
| 9165 | if eq get tk 0 0 |
| 9166 | fail 4 |
| 9167 | end |
| 9168 | if ne get tk 0 1 |
| 9169 | fail 16 |
| 9170 | end |
| 9171 | if gt get tl 0 8 |
| 9172 | fail 16 |
| 9173 | end |
| 9174 | c = kw get tw 0 |
| 9175 | r = c |
| 9176 | if eq c 76 |
| 9177 | r = ulong 12 |
| 9178 | else |
| 9179 | if eq c 88 |
| 9180 | r = ulong 10 |
| 9181 | else |
| 9182 | if eq c 89 |
| 9183 | r = ulong 11 |
| 9184 | else |
| 9185 | if eq c 223 |
| 9186 | r = ulong 13 |
| 9187 | else |
| 9188 | if gt sub c 1 8 |
| 9189 | r = abty |
| 9190 | else |
| 9191 | r = c |
| 9192 | end |
| 9193 | end |
| 9194 | end |
| 9195 | end |
| 9196 | end |
| 9197 | put curret 0 r |
| 9198 | put fn_ret f uchar r |
| 9199 | put fn_np f uchar np |
| 9200 | put stkbytes 0 0 |
| 9201 | put dead 0 0 |
| 9202 | put npar 0 get psl 0 |
| 9203 | put nslot 0 0 |
| 9204 | for j ulong 16 |
| 9205 | put vsl j 0 |
| 9206 | end |
| 9207 | put held 0 0 |
| 9208 | put nb 0 0 |
| 9209 | put nt 0 0 |
| 9210 | fn_tail f |
| 9211 | if and ne get xtarget 0 0 eq get scanning 0 0 |
| 9212 | xpro get psl 0 |
| 9213 | end |
| 9214 | end |
| 9215 | |
| 9216 | note s_fn: fn name (param type | param view T N | param edit T N)* to type | void. om4 S_FN. |
| 9217 | note A name of 9..63 bytes is never a keyword: tw packs only its first 8 bytes (continue_x is not continue). |
| 9218 | fn s_fn to void |
| 9219 | if ne get curret 0 0 |
| 9220 | fail 15 |
| 9221 | end |
| 9222 | tok |
| 9223 | if ne get tk 0 1 |
| 9224 | fail 16 |
| 9225 | end |
| 9226 | if gt get tl 0 63 |
| 9227 | fail 13 |
| 9228 | end |
| 9229 | w = get tw 0 |
| 9230 | if le get tl 0 8 |
| 9231 | if ne kw w 0 |
| 9232 | fail 16 |
| 9233 | end |
| 9234 | end |
| 9235 | l = get tl 0 |
| 9236 | s = get ts 0 |
| 9237 | f = ulong 0 |
| 9238 | if eq get scanning 0 1 |
| 9239 | newname w l s |
| 9240 | f = get nf 0 |
| 9241 | if ge f 4096 |
| 9242 | fail 14 |
| 9243 | end |
| 9244 | put nf 0 add f 1 |
| 9245 | put curfn 0 add f 1 |
| 9246 | put lastfn 0 add f 1 |
| 9247 | put fn_name f w |
| 9248 | put fn_addr f get oc 0 |
| 9249 | put fn_ret f 0 |
| 9250 | put fn_np f 0 |
| 9251 | put fn_nmlen f l |
| 9252 | put fn_off f s |
| 9253 | put fn_exp f uchar get expf 0 |
| 9254 | else |
| 9255 | f = sub findfn w l s 1 |
| 9256 | put curfn 0 add f 1 |
| 9257 | put lastfn 0 add f 1 |
| 9258 | put fn_addr f get oc 0 |
| 9259 | put fstart 0 get oc 0 |
| 9260 | put fuel 0 0 |
| 9261 | put fz_n 0 0 |
| 9262 | end |
| 9263 | put nn 0 get nglob 0 |
| 9264 | put psl 0 0 |
| 9265 | np = ulong 0 |
| 9266 | go = true |
| 9267 | while go |
| 9268 | tok |
| 9269 | if eq get tk 0 0 |
| 9270 | fail 4 |
| 9271 | end |
| 9272 | if ne get tk 0 1 |
| 9273 | fail 16 |
| 9274 | end |
| 9275 | if gt get tl 0 8 |
| 9276 | fail 13 |
| 9277 | end |
| 9278 | pw = get tw 0 |
| 9279 | c = kw pw |
| 9280 | if eq c 65 |
| 9281 | go = false |
| 9282 | else |
| 9283 | if ne c 0 |
| 9284 | fail 16 |
| 9285 | end |
| 9286 | newname pw get tl 0 get ts 0 |
| 9287 | if ge get psl 0 6 |
| 9288 | fail 9 |
| 9289 | end |
| 9290 | fn_p f np pw |
| 9291 | put fn_pn add mul f 6 np pw |
| 9292 | put psl 0 add get psl 0 pwid add mul f 6 np |
| 9293 | if gt get psl 0 6 |
| 9294 | fail 9 |
| 9295 | end |
| 9296 | np = add np 1 |
| 9297 | end |
| 9298 | end |
| 9299 | fn_to f np |
| 9300 | ab_entry f |
| 9301 | if eq get scanning 0 0 |
| 9302 | cp_entry |
| 9303 | end |
| 9304 | if eq get scanning 0 1 |
| 9305 | put curret 0 0 |
| 9306 | note keep the top-level consts read so far: a later const must not take an earlier one's slot. |
| 9307 | put nn 0 get nglob 0 |
| 9308 | end |
| 9309 | end |
| 9310 | |
| 9311 | note s_ret: ret [value]: the value into X0, give back the local arrays' stack, RET. om4 S_RET. |
| 9312 | fn s_ret to void |
| 9313 | if ne get inl 0 0 |
| 9314 | s_iret |
| 9315 | ret |
| 9316 | end |
| 9317 | r = get curret 0 |
| 9318 | if eq r 12 |
| 9319 | eol |
| 9320 | cp_post 0 0 r |
| 9321 | epi |
| 9322 | dead1 |
| 9323 | ret |
| 9324 | end |
| 9325 | dst = ulong 0 |
| 9326 | if and ne get cfhas 0 0 eq get crel 0 0 |
| 9327 | dst = ulong 255 |
| 9328 | end |
| 9329 | rdval 0 r dst 0 |
| 9330 | if ne get rt 0 r |
| 9331 | fail 7 |
| 9332 | end |
| 9333 | if and ne get cfhas 0 0 eq get crel 0 0 |
| 9334 | rr = matreg get rk 0 get rv 0 r |
| 9335 | eol |
| 9336 | cp_post 1 rr r |
| 9337 | force 1 rr r 0 |
| 9338 | else |
| 9339 | force get rk 0 get rv 0 get rt 0 0 |
| 9340 | eol |
| 9341 | cp_post 1 0 r |
| 9342 | end |
| 9343 | epi |
| 9344 | dead1 |
| 9345 | end |
| 9346 | |
| 9347 | note s_break: leave the innermost loop: find the nearest block of kind 3 (while) or 4 (for), emit an |
| 9348 | note always-taken B.cond to the loop's exit and record the word for s_end to patch. Outside a loop the |
| 9349 | note line is error 9. Like ret, the line ends the path (a later line in the same block is error 17). |
| 9350 | fn s_break to void |
| 9351 | j = get nb 0 |
| 9352 | found = ulong 0 |
| 9353 | bi = ulong 0 |
| 9354 | while and eq found 0 gt j 0 |
| 9355 | j = sub j 1 |
| 9356 | if ge get bkind j 3 |
| 9357 | found = ulong 1 |
| 9358 | bi = j |
| 9359 | end |
| 9360 | end |
| 9361 | if eq found 0 |
| 9362 | fail 9 |
| 9363 | end |
| 9364 | if ge get bkind bi 5 |
| 9365 | fail 9 |
| 9366 | end |
| 9367 | n = get nbrk 0 |
| 9368 | if ge n 1024 |
| 9369 | fail 14 |
| 9370 | end |
| 9371 | put brkpos n get oc 0 |
| 9372 | put brkblk n bi |
| 9373 | put nbrk 0 add n 1 |
| 9374 | if ne get xtarget 0 0 |
| 9375 | p = xbranch 14 |
| 9376 | else |
| 9377 | emit 1409286158 |
| 9378 | end |
| 9379 | dead1 |
| 9380 | eol |
| 9381 | end |
| 9382 | |
| 9383 | note s_cont: continue: like break it finds the innermost loop, but its exit is the latch: the head of a |
| 9384 | note while, the increment of a for (patched by s_end). Outside a loop it is error 9; the line ends the |
| 9385 | note path (error 17 for a later line in the same block). |
| 9386 | fn s_cont to void |
| 9387 | j = get nb 0 |
| 9388 | found = ulong 0 |
| 9389 | bi = ulong 0 |
| 9390 | while and eq found 0 gt j 0 |
| 9391 | j = sub j 1 |
| 9392 | if ge get bkind j 3 |
| 9393 | found = ulong 1 |
| 9394 | bi = j |
| 9395 | end |
| 9396 | end |
| 9397 | if eq found 0 |
| 9398 | fail 9 |
| 9399 | end |
| 9400 | if ge get bkind bi 5 |
| 9401 | fail 9 |
| 9402 | end |
| 9403 | n = get ncont 0 |
| 9404 | if ge n 1024 |
| 9405 | fail 14 |
| 9406 | end |
| 9407 | put cpos n get oc 0 |
| 9408 | put cblk n bi |
| 9409 | put ncont 0 add n 1 |
| 9410 | if ne get xtarget 0 0 |
| 9411 | p = xbranch 14 |
| 9412 | else |
| 9413 | emit 1409286158 |
| 9414 | end |
| 9415 | dead1 |
| 9416 | eol |
| 9417 | end |
| 9418 | |
| 9419 | note stel: the checked store of v (type t) at ea_b / ea_i (the STOP table: register offset, scaled) |
| 9420 | fn stel t ulong v ulong to void |
| 9421 | if ne get xtarget 0 0 |
| 9422 | xmemval 1 get ea_b 0 get ea_i 0 t v |
| 9423 | ret |
| 9424 | end |
| 9425 | eaem stop t v |
| 9426 | end |
| 9427 | |
| 9428 | note s_put: put A i v: index, then value, then the checked store (STOP table). om4 S_PUT. |
| 9429 | fn s_put to void |
| 9430 | e = arrname |
| 9431 | k = get nm_kind sub e 1 |
| 9432 | if ge k 6 |
| 9433 | s_putf e |
| 9434 | ret |
| 9435 | end |
| 9436 | if or eq k 2 eq k 5 |
| 9437 | fail 20 |
| 9438 | end |
| 9439 | if ne ly_put e 0 |
| 9440 | ret |
| 9441 | end |
| 9442 | rdval 0 5 255 0 |
| 9443 | ik = get rk 0 |
| 9444 | iv = get rv 0 |
| 9445 | it = get rt 0 |
| 9446 | t = ulong get nm_type sub e 1 |
| 9447 | if ne isfloat t 0 |
| 9448 | put fpw 0 1 |
| 9449 | end |
| 9450 | rdval 0 t 255 0 |
| 9451 | if ne get rt 0 t |
| 9452 | fail 7 |
| 9453 | end |
| 9454 | if eq get rk 0 9 |
| 9455 | vv = vtw get rv 0 |
| 9456 | fz_put e ik iv |
| 9457 | elemaddr e ik iv it |
| 9458 | eaem or stop t 67108864 vv |
| 9459 | eol |
| 9460 | ret |
| 9461 | end |
| 9462 | v = matreg get rk 0 get rv 0 get rt 0 |
| 9463 | fz_put e ik iv |
| 9464 | elemaddr e ik iv it |
| 9465 | stel t v |
| 9466 | eol |
| 9467 | end |
| 9468 | |
| 9469 | note s_const: const NAME TYPE LITERAL at top level. The value is a typed number (integer or float) |
| 9470 | note read wherever a value goes; it may not be assigned and is refused in IR mode. |
| 9471 | fn s_const to void |
| 9472 | tok |
| 9473 | if ne get tk 0 1 |
| 9474 | fail 16 |
| 9475 | end |
| 9476 | if gt get tl 0 8 |
| 9477 | fail 13 |
| 9478 | end |
| 9479 | w = get tw 0 |
| 9480 | if ne kw w 0 |
| 9481 | fail 16 |
| 9482 | end |
| 9483 | newname w get tl 0 get ts 0 |
| 9484 | t = typeword |
| 9485 | if ge t 64 |
| 9486 | fail 7 |
| 9487 | end |
| 9488 | if ne isfloat t 0 |
| 9489 | note float constant: rdval reads the float token as a value (kind 6); fspan converts it to the |
| 9490 | note target type's bits and rdval has already balanced the nesting depth. |
| 9491 | rdval 0 0 255 0 |
| 9492 | if ne get rk 0 6 |
| 9493 | fail 16 |
| 9494 | end |
| 9495 | v = fspan t get rv 0 |
| 9496 | addname w 0 t 0 9 v |
| 9497 | put nglob 0 get nn 0 |
| 9498 | eol |
| 9499 | ret |
| 9500 | end |
| 9501 | tok |
| 9502 | if eq get tk 0 0 |
| 9503 | fail 4 |
| 9504 | end |
| 9505 | if eq get tk 0 5 |
| 9506 | fail 7 |
| 9507 | end |
| 9508 | if ne get tk 0 2 |
| 9509 | fail 16 |
| 9510 | end |
| 9511 | v = get tw 0 |
| 9512 | range v t get tbig 0 |
| 9513 | addname w 0 t 0 9 v |
| 9514 | put nglob 0 get nn 0 |
| 9515 | eol |
| 9516 | end |
| 9517 | |
| 9518 | note s_global: global NAME T N: a fixed pool of N elements, zero at start, in the read/write part of the |
| 9519 | note program image after the 8 MiB stack pool (address 0x10800000 + pool bytes so far); at most 1 GiB of |
| 9520 | note pools (error 23). om4 S_GLOBAL. |
| 9521 | fn s_global to void |
| 9522 | w = topname |
| 9523 | t = typeword |
| 9524 | elemtype t |
| 9525 | n = lenval 16 |
| 9526 | arrlen n |
| 9527 | by = shl shr add shl n tlog t 15 4 4 |
| 9528 | pb = get poolb 0 |
| 9529 | a = add 276824064 pb |
| 9530 | s = add pb by |
| 9531 | if gt s 1073741824 |
| 9532 | fail 23 |
| 9533 | end |
| 9534 | put poolb 0 s |
| 9535 | addname w 0 t n 4 a |
| 9536 | put nglob 0 get nn 0 |
| 9537 | eol |
| 9538 | end |
| 9539 | |
| 9540 | note s_text: text NAME "...": read-only bytes in the program image (escapes \n \t \\ \", any other is error |
| 9541 | note 22), padded to a word, with their length; address 0x400000 + its place. om4 S_TEXT. |
| 9542 | fn s_text to void |
| 9543 | w = topname |
| 9544 | tok |
| 9545 | if ne get tk 0 4 |
| 9546 | fail 16 |
| 9547 | end |
| 9548 | br = ulong 0 |
| 9549 | if and ne get xtarget 0 0 ne get tl 0 0 |
| 9550 | br = xbranch 14 |
| 9551 | end |
| 9552 | a = add get oc 0 4194304 |
| 9553 | p = get tw 0 |
| 9554 | e = add p get tl 0 |
| 9555 | n = ulong 0 |
| 9556 | go = true |
| 9557 | while go |
| 9558 | m = ulong 0 |
| 9559 | while and go lt m 999999 |
| 9560 | if ge p e |
| 9561 | go = false |
| 9562 | else |
| 9563 | b = get inp p |
| 9564 | p = add p 1 |
| 9565 | if eq b 92 |
| 9566 | b = get inp p |
| 9567 | p = add p 1 |
| 9568 | if eq b 110 |
| 9569 | b = uchar 10 |
| 9570 | else |
| 9571 | if eq b 116 |
| 9572 | b = uchar 9 |
| 9573 | else |
| 9574 | if and ne b 92 ne b 34 |
| 9575 | fail 22 |
| 9576 | end |
| 9577 | end |
| 9578 | end |
| 9579 | end |
| 9580 | emitb b |
| 9581 | n = add n 1 |
| 9582 | end |
| 9583 | m = add m 1 |
| 9584 | end |
| 9585 | end |
| 9586 | note Empty text carries no data or padding; its zero count forbids every access. |
| 9587 | if ne n 0 |
| 9588 | while ne and get oc 0 3 0 |
| 9589 | emitb 0 |
| 9590 | end |
| 9591 | end |
| 9592 | if ne br 0 |
| 9593 | xpatch br get oc 0 |
| 9594 | end |
| 9595 | addname w 0 2 n 5 a |
| 9596 | put nglob 0 get nn 0 |
| 9597 | eol |
| 9598 | end |
| 9599 | |
| 9600 | note s_else: jump over the else part (B, C6.2.35); the if's false branch lands after that jump. om4 S_ELSE. |
| 9601 | fn s_else to void |
| 9602 | n = get nb 0 |
| 9603 | if eq n 0 |
| 9604 | fail 15 |
| 9605 | end |
| 9606 | i = sub n 1 |
| 9607 | if ne get bkind i 1 |
| 9608 | fail 15 |
| 9609 | end |
| 9610 | b = get oc 0 |
| 9611 | if ne get xtarget 0 0 |
| 9612 | note A terminated then-path needs no skip jump, particularly at a bare unit's final byte. |
| 9613 | if eq get dead 0 0 |
| 9614 | p = xbranch 14 |
| 9615 | end |
| 9616 | else |
| 9617 | emit 335544320 |
| 9618 | end |
| 9619 | patch19 get bbr i get oc 0 |
| 9620 | put bkind i 2 |
| 9621 | put bbr i b |
| 9622 | fz_else i |
| 9623 | put nn 0 get bnames i |
| 9624 | put held 0 get bheld i |
| 9625 | put bdead i get dead 0 |
| 9626 | put dead 0 0 |
| 9627 | eol |
| 9628 | end |
| 9629 | |
| 9630 | 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 |
| 9631 | note 4; ADD Xc, Xc, #1 (C6.2.5). om4 SW_NOB .. SW_G and the same in S_FOR. |
| 9632 | fn lpcnt c ulong n ulong to void |
| 9633 | if ne get xtarget 0 0 |
| 9634 | xcmp c n 1 |
| 9635 | trapc 2 4 |
| 9636 | xarith 33 5 c 1 1 c |
| 9637 | ret |
| 9638 | end |
| 9639 | if le n 4095 |
| 9640 | emit or or 4043309087 shl n 10 shl c 5 |
| 9641 | else |
| 9642 | m = alloc |
| 9643 | matconst m n |
| 9644 | emit or or 3942645791 shl c 5 shl m 16 |
| 9645 | end |
| 9646 | trapc 2 4 |
| 9647 | emit or or 2432697344 c shl c 5 |
| 9648 | end |
| 9649 | |
| 9650 | note s_while: while cond [bound N]: hidden counter = 0; head: cond false -> exit; counter >= N -> trap 4; |
| 9651 | note counter = counter + 1; body; B head. N is 1 .. 9223372036854775807 (error 8), 1000000 with no bound. om4 S_WHILE. |
| 9652 | fn s_while to void |
| 9653 | sn = get nn 0 |
| 9654 | sh = get held 0 |
| 9655 | c = alloc |
| 9656 | put held 0 get nslot 0 |
| 9657 | if ne get xtarget 0 0 |
| 9658 | matconst c 0 |
| 9659 | else |
| 9660 | emit or 3531603968 c |
| 9661 | end |
| 9662 | hd = get oc 0 |
| 9663 | cp_head skipln get cur 0 add get line 0 1 |
| 9664 | br = cond |
| 9665 | n = ulong 1000000 |
| 9666 | tok |
| 9667 | k = get tk 0 |
| 9668 | if and ne k 0 ne k 3 |
| 9669 | if ne k 1 |
| 9670 | fail 5 |
| 9671 | end |
| 9672 | if gt get tl 0 8 |
| 9673 | fail 5 |
| 9674 | end |
| 9675 | if ne kw get tw 0 70 |
| 9676 | fail 5 |
| 9677 | end |
| 9678 | v = lenval 4 |
| 9679 | if ge sub v 1 9223372036854775807 |
| 9680 | fail 8 |
| 9681 | end |
| 9682 | n = v |
| 9683 | eol |
| 9684 | end |
| 9685 | lpcnt c n |
| 9686 | pushb br 3 hd c 0 |
| 9687 | pushnh sn sh |
| 9688 | cp_skip |
| 9689 | end |
| 9690 | |
| 9691 | note sf_br: B.HS (unsigned) or B.GE (signed) to the loop exit, C6.2.34 (distance filled at end); returns |
| 9692 | note its place. om4 SF_BR. |
| 9693 | fn sf_br t ulong to ulong |
| 9694 | if ne get xtarget 0 0 |
| 9695 | if lt t 6 |
| 9696 | ret xbranch 2 |
| 9697 | end |
| 9698 | ret xbranch 10 |
| 9699 | end |
| 9700 | at = get oc 0 |
| 9701 | if lt t 6 |
| 9702 | emit 1409286146 |
| 9703 | else |
| 9704 | emit 1409286154 |
| 9705 | end |
| 9706 | ret at |
| 9707 | end |
| 9708 | |
| 9709 | 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. |
| 9710 | note With `bound N` a hidden counter c = 0 is checked after the exit test, as in s_while. om4 SF_NUM .. SF_PUSH. |
| 9711 | note The optional `bound N` before the line's end: N a number or an integer constant, 1 .. |
| 9712 | note 9223372036854775807 (error 8, as s_while; 4 when N is missing); bn = 0 when no bound is written. |
| 9713 | fn sf_num w ulong t ulong kk ulong sn ulong sh ulong to void |
| 9714 | bn = ulong 0 |
| 9715 | if eq peekw 70 |
| 9716 | tok |
| 9717 | bn = lenval 4 |
| 9718 | if ge sub bn 1 9223372036854775807 |
| 9719 | fail 8 |
| 9720 | end |
| 9721 | end |
| 9722 | if ne get xtarget 0 0 |
| 9723 | xfornum w t kk sn sh bn |
| 9724 | ret |
| 9725 | end |
| 9726 | eol |
| 9727 | i = alloc |
| 9728 | put held 0 get nslot 0 |
| 9729 | addname w i t 0 0 0 |
| 9730 | emit or 3531603968 i |
| 9731 | c = ulong 0 |
| 9732 | if ne bn 0 |
| 9733 | c = alloc |
| 9734 | put held 0 get nslot 0 |
| 9735 | emit or 3531603968 c |
| 9736 | end |
| 9737 | hd = get oc 0 |
| 9738 | cp_head get cur 0 get line 0 |
| 9739 | if le kk 4095 |
| 9740 | emit or or 4043309087 shl kk 10 shl i 5 |
| 9741 | else |
| 9742 | k = alloc |
| 9743 | matconst k kk |
| 9744 | emit or or 3942645791 shl i 5 shl k 16 |
| 9745 | end |
| 9746 | br = sf_br t |
| 9747 | if ne bn 0 |
| 9748 | lpcnt c bn |
| 9749 | end |
| 9750 | pushb br 4 hd i t |
| 9751 | pushnh sn sh |
| 9752 | cp_skip |
| 9753 | end |
| 9754 | |
| 9755 | 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 |
| 9756 | note Xi, Xk; B.HS/B.GE exit; the counter guard of a while: `bound N` (read as in sf_num), else 1000000. |
| 9757 | note om4 SF_VAL. |
| 9758 | fn sf_val w ulong t ulong kr ulong sn ulong sh ulong to void |
| 9759 | n = ulong 1000000 |
| 9760 | if eq peekw 70 |
| 9761 | tok |
| 9762 | n = lenval 4 |
| 9763 | if ge sub n 1 9223372036854775807 |
| 9764 | fail 8 |
| 9765 | end |
| 9766 | end |
| 9767 | if ne get xtarget 0 0 |
| 9768 | xforval w t kr sn sh n |
| 9769 | ret |
| 9770 | end |
| 9771 | eol |
| 9772 | i = alloc |
| 9773 | put held 0 get nslot 0 |
| 9774 | addname w i t 0 0 0 |
| 9775 | emit or 3531603968 i |
| 9776 | c = alloc |
| 9777 | put held 0 get nslot 0 |
| 9778 | emit or 3531603968 c |
| 9779 | hd = get oc 0 |
| 9780 | cp_head get cur 0 get line 0 |
| 9781 | emit or or 3942645791 shl kr 16 shl i 5 |
| 9782 | br = sf_br t |
| 9783 | lpcnt c n |
| 9784 | pushb br 4 hd i t |
| 9785 | pushnh sn sh |
| 9786 | cp_skip |
| 9787 | end |
| 9788 | |
| 9789 | note s_for: for i T K [bound N]: i = 0; head: not i < K -> exit; body; latch i = add i 1; B head. K a number, |
| 9790 | note or a value of type T: a name is read at every pass, another value once before the loop. More than N |
| 9791 | note passes (default 1000000 for a value K, no limit for a number K) trap 4. om4 S_FOR. |
| 9792 | fn s_for to void |
| 9793 | sn = get nn 0 |
| 9794 | sh = get held 0 |
| 9795 | tok |
| 9796 | if eq get tk 0 0 |
| 9797 | fail 4 |
| 9798 | end |
| 9799 | if ne get tk 0 1 |
| 9800 | fail 16 |
| 9801 | end |
| 9802 | if gt get tl 0 8 |
| 9803 | fail 13 |
| 9804 | end |
| 9805 | w = get tw 0 |
| 9806 | if ne kw w 0 |
| 9807 | fail 16 |
| 9808 | end |
| 9809 | newname w get tl 0 get ts 0 |
| 9810 | t = typeword |
| 9811 | if or eq t 1 ge t 10 |
| 9812 | fail 7 |
| 9813 | end |
| 9814 | tok |
| 9815 | if eq get tk 0 0 |
| 9816 | fail 4 |
| 9817 | end |
| 9818 | if eq get tk 0 2 |
| 9819 | range get tw 0 t get tbig 0 |
| 9820 | if ne get om2 0 0 |
| 9821 | kk = get tw 0 |
| 9822 | if eq peekw 181 |
| 9823 | s_unroll w t kk sn sh |
| 9824 | ret |
| 9825 | end |
| 9826 | put tw 0 kk |
| 9827 | end |
| 9828 | sf_num w t get tw 0 sn sh |
| 9829 | ret |
| 9830 | end |
| 9831 | rdval 1 t 255 0 |
| 9832 | if ne get rt 0 t |
| 9833 | fail 7 |
| 9834 | end |
| 9835 | if ne get om2 0 0 |
| 9836 | if eq peekw 181 |
| 9837 | fail 16 |
| 9838 | end |
| 9839 | end |
| 9840 | if eq get rk 0 3 |
| 9841 | sf_num w t get rv 0 sn sh |
| 9842 | ret |
| 9843 | end |
| 9844 | kr = matreg get rk 0 get rv 0 get rt 0 |
| 9845 | sf_val w t kr sn sh |
| 9846 | end |
| 9847 | |
| 9848 | note ======== OM-2 section 4: unroll, inline, folding, the growth bound and trap-site records ======== |
| 9849 | note peekstar: 1 when the next word is `*` (an unsized array, OM-2), without reading it |
| 9850 | fn peekstar to ulong |
| 9851 | c0 = get cur 0 |
| 9852 | l0 = get line 0 |
| 9853 | a0 = get tka 0 |
| 9854 | b0 = get tkb 0 |
| 9855 | tok |
| 9856 | r = ulong 0 |
| 9857 | if and eq get tk 0 1 eq get tl 0 1 |
| 9858 | if eq get tw 0 42 |
| 9859 | r = ulong 1 |
| 9860 | end |
| 9861 | end |
| 9862 | put cur 0 c0 |
| 9863 | put line 0 l0 |
| 9864 | put tka 0 a0 |
| 9865 | put tkb 0 b0 |
| 9866 | ret r |
| 9867 | end |
| 9868 | |
| 9869 | note peekw: the keyword code of the next word (0 for anything else) without reading it |
| 9870 | fn peekw to ulong |
| 9871 | c0 = get cur 0 |
| 9872 | l0 = get line 0 |
| 9873 | a0 = get tka 0 |
| 9874 | b0 = get tkb 0 |
| 9875 | tok |
| 9876 | r = ulong 0 |
| 9877 | if eq get tk 0 1 |
| 9878 | if le get tl 0 8 |
| 9879 | r = kw get tw 0 |
| 9880 | end |
| 9881 | end |
| 9882 | put cur 0 c0 |
| 9883 | put line 0 l0 |
| 9884 | put tka 0 a0 |
| 9885 | put tkb 0 b0 |
| 9886 | ret r |
| 9887 | end |
| 9888 | |
| 9889 | note s_unroll: for i T K unroll (K a number 1..64, error 8 outside). i is a constant name (kind 9) bound to |
| 9890 | note 0..K-1 in turn; the body is read K times from its first line (s_unr). No branch is emitted. |
| 9891 | fn s_unroll w ulong t ulong kk ulong sn ulong sh ulong to void |
| 9892 | if or eq kk 0 gt kk 64 |
| 9893 | fail 8 |
| 9894 | end |
| 9895 | fuelc get line 0 kk |
| 9896 | tok |
| 9897 | eol |
| 9898 | addname w 0 t 0 9 0 |
| 9899 | n = get nb 0 |
| 9900 | pushb 0 5 0 sub get nn 0 1 t |
| 9901 | pushnh sn sh |
| 9902 | put u_cur n get cur 0 |
| 9903 | put u_line n get line 0 |
| 9904 | put u_it n 0 |
| 9905 | put u_k n kk |
| 9906 | put u_nn n get nn 0 |
| 9907 | put u_held n get held 0 |
| 9908 | put fzone 0 add get fzone 0 1 |
| 9909 | cp_head get cur 0 get line 0 |
| 9910 | cp_skip |
| 9911 | end |
| 9912 | |
| 9913 | note fuelc: charge n to the function's fuel at the construct on line ln, before anything of it expands; a |
| 9914 | note total above 65536 is error 14 on line ln (E14, E16) |
| 9915 | fn fuelc ln ulong n ulong to void |
| 9916 | if gt add get fuel 0 n 65536 |
| 9917 | put line 0 ln |
| 9918 | fail 14 |
| 9919 | end |
| 9920 | put fuel 0 add get fuel 0 n |
| 9921 | end |
| 9922 | |
| 9923 | note s_unr: the end of an unrolled body: read it again with the next value of i, or close the block |
| 9924 | fn s_unr i ulong to void |
| 9925 | eol |
| 9926 | it = add get u_it i 1 |
| 9927 | if lt it get u_k i |
| 9928 | put u_it i it |
| 9929 | put nm_addr get breg i it |
| 9930 | put nn 0 get u_nn i |
| 9931 | put held 0 get u_held i |
| 9932 | put nslot 0 get u_held i |
| 9933 | put dead 0 0 |
| 9934 | put cur 0 get u_cur i |
| 9935 | put line 0 get u_line i |
| 9936 | cp_head get cur 0 get line 0 |
| 9937 | cp_skip |
| 9938 | ret |
| 9939 | end |
| 9940 | put u_it i it |
| 9941 | put nm_addr get breg i it |
| 9942 | put nn 0 get u_nn i |
| 9943 | put nslot 0 get u_held i |
| 9944 | cp_head get u_cur i get u_line i |
| 9945 | put nb 0 i |
| 9946 | put nn 0 get bnames i |
| 9947 | put held 0 get bheld i |
| 9948 | put dead 0 0 |
| 9949 | put fzone 0 sub get fzone 0 1 |
| 9950 | end |
| 9951 | |
| 9952 | note fn_tail: the end of a fn line: an optional inline (OM-2), then the line ends; records the body start |
| 9953 | fn fn_tail f ulong to void |
| 9954 | tok |
| 9955 | k = get tk 0 |
| 9956 | if eq k 1 |
| 9957 | if ne get om2 0 0 |
| 9958 | if le get tl 0 8 |
| 9959 | if eq kw get tw 0 182 |
| 9960 | put fn_inl f 1 |
| 9961 | eol |
| 9962 | put fn_body f get cur 0 |
| 9963 | put fn_bln f get line 0 |
| 9964 | ret |
| 9965 | end |
| 9966 | end |
| 9967 | end |
| 9968 | end |
| 9969 | if and ne k 0 ne k 3 |
| 9970 | put dexp 0 6 |
| 9971 | fail 5 |
| 9972 | end |
| 9973 | put fn_body f get cur 0 |
| 9974 | put fn_bln f get line 0 |
| 9975 | end |
| 9976 | |
| 9977 | note inl_call: a call of an inline function fe (index + 1): the result register first (dst, or the next |
| 9978 | note pool slot), then the arguments left to right exactly as for a call, then the body in place. |
| 9979 | fn inl_call fe ulong dst ulong to void |
| 9980 | s0 = get nslot 0 |
| 9981 | rres = ulong 255 |
| 9982 | ns = s0 |
| 9983 | if ne get fn_ret sub fe 1 12 |
| 9984 | if eq dst 255 |
| 9985 | rres = alloc |
| 9986 | ns = add s0 1 |
| 9987 | else |
| 9988 | rres = dst |
| 9989 | end |
| 9990 | end |
| 9991 | cb = add mul get depth 0 32 8 |
| 9992 | np = ulong get fn_np sub fe 1 |
| 9993 | put fr add cb 18 np |
| 9994 | put fr add cb 19 get nslot 0 |
| 9995 | i = ulong 0 |
| 9996 | while lt i np |
| 9997 | p = add mul sub fe 1 6 i |
| 9998 | if eq get fn_pk p 0 |
| 9999 | rdval 0 ulong get fn_pt p 255 0 |
| 10000 | ca_scal p add cb mul i 3 |
| 10001 | else |
| 10002 | if ge get fn_pk p 6 |
| 10003 | ca_st fe i cb |
| 10004 | else |
| 10005 | ca_arr fe i cb |
| 10006 | end |
| 10007 | end |
| 10008 | i = add i 1 |
| 10009 | end |
| 10010 | inl_body fe cb ns rres |
| 10011 | end |
| 10012 | |
| 10013 | note inl_par: bind parameter i of inline function fe to its argument in frame cb. A scalar held in a |
| 10014 | note temporary register (pool index hb or above) is taken as it is; any other scalar is copied to a new |
| 10015 | note register. An array or struct takes its base register; a text's address is loaded into one. An |
| 10016 | note unsized array parameter also takes its count register, or a new one holding a number count. |
| 10017 | fn inl_par fe ulong cb ulong i ulong hb ulong to void |
| 10018 | p = add mul sub fe 1 6 i |
| 10019 | q = add cb mul i 3 |
| 10020 | k = get fr q |
| 10021 | v = get fr add q 1 |
| 10022 | r = ulong 0 |
| 10023 | if eq get fn_pk p 0 |
| 10024 | if and eq k 1 ge regidx v hb |
| 10025 | r = v |
| 10026 | else |
| 10027 | r = alloc |
| 10028 | force k v ulong get fn_pt p r |
| 10029 | end |
| 10030 | else |
| 10031 | if eq k 5 |
| 10032 | r = v |
| 10033 | else |
| 10034 | r = alloc |
| 10035 | matconst r v |
| 10036 | end |
| 10037 | end |
| 10038 | inl_add p r |
| 10039 | if eq pwid p 2 |
| 10040 | inl_lr add mul div cb 32 6 i |
| 10041 | end |
| 10042 | fz_inl p get fr add q 2 |
| 10043 | end |
| 10044 | |
| 10045 | note inl_lr: the unsized parameter name just added gets the count of argument ux (ul_k / ul_v): its |
| 10046 | note register, or a new one holding the number |
| 10047 | fn inl_lr ux ulong to void |
| 10048 | lr = get ul_v ux |
| 10049 | if ne get ul_k ux 1 |
| 10050 | lr = alloc |
| 10051 | matconst lr get ul_v ux |
| 10052 | end |
| 10053 | put nm_lr sub get nn 0 1 uchar lr |
| 10054 | end |
| 10055 | |
| 10056 | note inl_add: the name of parameter slot p on register r (a view struct is name kind 8, an edit one 7) |
| 10057 | fn inl_add p ulong r ulong to void |
| 10058 | pk = ulong get fn_pk p |
| 10059 | if eq pk 0 |
| 10060 | addname get fn_pn p r ulong get fn_pt p 0 0 0 |
| 10061 | ret |
| 10062 | end |
| 10063 | nk = pk |
| 10064 | if eq pk 6 |
| 10065 | nk = ulong 8 |
| 10066 | end |
| 10067 | addname get fn_pn p r ulong get fn_pt p get fn_pl p nk 0 |
| 10068 | put nm_lay sub get nn 0 1 get fn_play p |
| 10069 | end |
| 10070 | |
| 10071 | note inl_edge: record the call-graph edge (expanding function -> inline function) once (16384 edges, error 14) |
| 10072 | fn inl_edge a ulong b ulong to void |
| 10073 | n = get nie 0 |
| 10074 | j = ulong 0 |
| 10075 | while lt j n |
| 10076 | if and eq get ie_from j a eq get ie_to j b |
| 10077 | ret |
| 10078 | end |
| 10079 | j = add j 1 |
| 10080 | end |
| 10081 | if ge n 16384 |
| 10082 | fail 14 |
| 10083 | end |
| 10084 | put ie_from n a |
| 10085 | put ie_to n b |
| 10086 | put nie 0 add n 1 |
| 10087 | end |
| 10088 | |
| 10089 | note inl_body: at most 4 nested inline frames (error 14); an inline function reached again while it is |
| 10090 | note being inlined, or from its own body, is error 9. The caller's local names are hidden, the parameters |
| 10091 | note bound, and the body's lines compiled here until its end (s_inlx) closes the frame. |
| 10092 | note Each expansion costs one unit of the function's fuel (E14). |
| 10093 | fn inl_body fe ulong cb ulong ns ulong rres ulong to void |
| 10094 | lv = get inl 0 |
| 10095 | fuelc get line 0 1 |
| 10096 | if ge lv 4 |
| 10097 | fail 14 |
| 10098 | end |
| 10099 | if eq get curfn 0 fe |
| 10100 | fail 9 |
| 10101 | end |
| 10102 | j = ulong 0 |
| 10103 | while lt j lv |
| 10104 | if eq get il_fn j fe |
| 10105 | fail 9 |
| 10106 | end |
| 10107 | j = add j 1 |
| 10108 | end |
| 10109 | inl_edge get curfn 0 fe |
| 10110 | put il_cur lv get cur 0 |
| 10111 | put il_line lv get line 0 |
| 10112 | put il_ret lv get curret 0 |
| 10113 | put il_nn lv get nn 0 |
| 10114 | put il_lo lv get nmlo 0 |
| 10115 | put il_held lv get held 0 |
| 10116 | put il_ns lv ns |
| 10117 | put il_res lv rres |
| 10118 | put il_fn lv fe |
| 10119 | put il_p0 lv get nilp 0 |
| 10120 | put il_fz lv get fz_n 0 |
| 10121 | inl_bind fe cb |
| 10122 | pushb 0 6 0 fe 0 |
| 10123 | pushnh get il_nn lv get il_held lv |
| 10124 | put inl 0 add lv 1 |
| 10125 | put fzone 0 add get fzone 0 1 |
| 10126 | put curret 0 ulong get fn_ret sub fe 1 |
| 10127 | put dead 0 0 |
| 10128 | put cur 0 get fn_body sub fe 1 |
| 10129 | put line 0 get fn_bln sub fe 1 |
| 10130 | cp_entry |
| 10131 | inl_run lv |
| 10132 | end |
| 10133 | |
| 10134 | note inl_bind: hide the caller's local names, bind the parameters, protect every register in use |
| 10135 | fn inl_bind fe ulong cb ulong to void |
| 10136 | hb = add get npar 0 get held 0 |
| 10137 | put nmlo 0 get nn 0 |
| 10138 | np = ulong get fn_np sub fe 1 |
| 10139 | i = ulong 0 |
| 10140 | while lt i np |
| 10141 | inl_par fe cb i hb |
| 10142 | i = add i 1 |
| 10143 | end |
| 10144 | put held 0 get nslot 0 |
| 10145 | end |
| 10146 | |
| 10147 | note inl_run: compile the inlined body's lines until its frame (level lv) is closed |
| 10148 | fn inl_run lv ulong to void |
| 10149 | go = true |
| 10150 | while go |
| 10151 | m = ulong 0 |
| 10152 | while and go lt m 999999 |
| 10153 | if ne stmt 0 |
| 10154 | fail 15 |
| 10155 | end |
| 10156 | if le get inl 0 lv |
| 10157 | go = false |
| 10158 | end |
| 10159 | m = add m 1 |
| 10160 | end |
| 10161 | end |
| 10162 | end |
| 10163 | |
| 10164 | note inlb: the B of an inlined ret, patched to the frame's end |
| 10165 | fn inlb to void |
| 10166 | n = get nilp 0 |
| 10167 | if ge n 4096 |
| 10168 | fail 14 |
| 10169 | end |
| 10170 | put ilp n get oc 0 |
| 10171 | put nilp 0 add n 1 |
| 10172 | if ne get xtarget 0 0 |
| 10173 | p = xbranch 14 |
| 10174 | put ilp n p |
| 10175 | else |
| 10176 | emit 335544320 |
| 10177 | end |
| 10178 | put lastb 0 get oc 0 |
| 10179 | end |
| 10180 | |
| 10181 | note s_iret: ret inside an inlined body: the value into the frame's result register, then B to its end |
| 10182 | fn s_iret to void |
| 10183 | lv = sub get inl 0 1 |
| 10184 | r = get curret 0 |
| 10185 | if eq r 12 |
| 10186 | eol |
| 10187 | cp_post 0 0 r |
| 10188 | inlb |
| 10189 | dead1 |
| 10190 | ret |
| 10191 | end |
| 10192 | if and ne get cfhas get inl 0 0 eq get crel 0 0 |
| 10193 | rdval 0 r 255 0 |
| 10194 | if ne get rt 0 r |
| 10195 | fail 7 |
| 10196 | end |
| 10197 | rr = matreg get rk 0 get rv 0 r |
| 10198 | eol |
| 10199 | cp_post 1 rr r |
| 10200 | force 1 rr r get il_res lv |
| 10201 | else |
| 10202 | rdval 0 r get il_res lv 0 |
| 10203 | if ne get rt 0 r |
| 10204 | fail 7 |
| 10205 | end |
| 10206 | force get rk 0 get rv 0 get rt 0 get il_res lv |
| 10207 | eol |
| 10208 | cp_post 1 get il_res lv r |
| 10209 | end |
| 10210 | inlb |
| 10211 | dead1 |
| 10212 | end |
| 10213 | |
| 10214 | note s_inlx: the end of an inlined body: a value function must not reach it (error 18). A last ret's B |
| 10215 | note that is the last word, with no branch patched to the place after it, is taken back; the other rets |
| 10216 | note branch here. The caller's line, names, registers and return type come back; the result is in rk/rv/rt. |
| 10217 | fn s_inlx i ulong to void |
| 10218 | eol |
| 10219 | lv = sub get inl 0 1 |
| 10220 | fe = get il_fn lv |
| 10221 | if eq get dead 0 0 |
| 10222 | if ne get fn_ret sub fe 1 12 |
| 10223 | fail 18 |
| 10224 | end |
| 10225 | cp_post 0 0 12 |
| 10226 | end |
| 10227 | inl_pat get il_p0 lv |
| 10228 | put nb 0 i |
| 10229 | put cur 0 get il_cur lv |
| 10230 | put line 0 get il_line lv |
| 10231 | put curret 0 get il_ret lv |
| 10232 | put nn 0 get il_nn lv |
| 10233 | put nmlo 0 get il_lo lv |
| 10234 | put held 0 get il_held lv |
| 10235 | put nslot 0 get il_ns lv |
| 10236 | put dead 0 0 |
| 10237 | put inl 0 lv |
| 10238 | put fzone 0 sub get fzone 0 1 |
| 10239 | put fz_n 0 get il_fz lv |
| 10240 | put rk 0 1 |
| 10241 | put rv 0 get il_res lv |
| 10242 | put rt 0 ulong get fn_ret sub fe 1 |
| 10243 | end |
| 10244 | |
| 10245 | note inl_pat: patch the frame's ret B words (from p0) to here, after taking back a last one that is the |
| 10246 | note last word and that no branch was patched past |
| 10247 | fn inl_pat p0 ulong to void |
| 10248 | n = get nilp 0 |
| 10249 | o = get oc 0 |
| 10250 | if and ne get dead 0 0 gt n p0 |
| 10251 | if eq get lastb 0 o |
| 10252 | if ne get tgoc 0 o |
| 10253 | if eq get ilp sub n 1 sub o 4 |
| 10254 | put oc 0 sub o 4 |
| 10255 | n = sub n 1 |
| 10256 | end |
| 10257 | end |
| 10258 | end |
| 10259 | end |
| 10260 | j = p0 |
| 10261 | while lt j n |
| 10262 | patch26 get ilp j get oc 0 |
| 10263 | j = add j 1 |
| 10264 | end |
| 10265 | put nilp 0 p0 |
| 10266 | end |
| 10267 | |
| 10268 | note ---- folding (only while fzone is above 0): an operation on two typed numbers is computed with OM-1 |
| 10269 | note arithmetic: unsigned wraps to its width, signed results are sign-extended; an operation that would |
| 10270 | note trap (signed overflow, divide by 0, a shift or rotate amount at or above the width) is not folded. |
| 10271 | fn fmask w ulong to ulong |
| 10272 | if ge w 64 |
| 10273 | ret not ulong 0 |
| 10274 | end |
| 10275 | ret sub shl ulong 1 w 1 |
| 10276 | end |
| 10277 | |
| 10278 | fn fasr x ulong s ulong to ulong |
| 10279 | if eq shr x 63 0 |
| 10280 | ret shr x s |
| 10281 | end |
| 10282 | ret not shr not x s |
| 10283 | end |
| 10284 | |
| 10285 | fn fsext r ulong w ulong to ulong |
| 10286 | if ge w 64 |
| 10287 | ret r |
| 10288 | end |
| 10289 | ret fasr shl r sub 64 w sub 64 w |
| 10290 | end |
| 10291 | |
| 10292 | fn fyes v ulong t ulong to void |
| 10293 | put fval 0 v |
| 10294 | put fty 0 t |
| 10295 | put fok 0 1 |
| 10296 | end |
| 10297 | |
| 10298 | fn fb_cmp op ulong sg ulong a ulong b ulong to void |
| 10299 | x = a |
| 10300 | y = b |
| 10301 | if ne sg 0 |
| 10302 | x = xor a shl ulong 1 63 |
| 10303 | y = xor b shl ulong 1 63 |
| 10304 | end |
| 10305 | r = false |
| 10306 | if eq op 43 |
| 10307 | r = eq x y |
| 10308 | end |
| 10309 | if eq op 44 |
| 10310 | r = ne x y |
| 10311 | end |
| 10312 | if eq op 45 |
| 10313 | r = lt x y |
| 10314 | end |
| 10315 | if eq op 46 |
| 10316 | r = le x y |
| 10317 | end |
| 10318 | if eq op 47 |
| 10319 | r = gt x y |
| 10320 | end |
| 10321 | if eq op 48 |
| 10322 | r = ge x y |
| 10323 | end |
| 10324 | v = ulong 0 |
| 10325 | if r |
| 10326 | v = ulong 1 |
| 10327 | end |
| 10328 | fyes v 1 |
| 10329 | end |
| 10330 | |
| 10331 | fn fb_arith op ulong ty ulong w ulong sg ulong a ulong b ulong to void |
| 10332 | r = ulong 0 |
| 10333 | if eq op 33 |
| 10334 | r = add a b |
| 10335 | end |
| 10336 | if eq op 34 |
| 10337 | r = sub a b |
| 10338 | end |
| 10339 | if eq op 35 |
| 10340 | if ne sg 0 |
| 10341 | if ge add a shl ulong 1 31 shl ulong 1 32 |
| 10342 | ret |
| 10343 | end |
| 10344 | if ge add b shl ulong 1 31 shl ulong 1 32 |
| 10345 | ret |
| 10346 | end |
| 10347 | end |
| 10348 | r = mul a b |
| 10349 | end |
| 10350 | if eq sg 0 |
| 10351 | fyes and r fmask w ty |
| 10352 | ret |
| 10353 | end |
| 10354 | if eq w 64 |
| 10355 | if eq op 33 |
| 10356 | if ne shr and xor a r xor b r 63 0 |
| 10357 | ret |
| 10358 | end |
| 10359 | end |
| 10360 | if eq op 34 |
| 10361 | if ne shr and xor a b xor a r 63 0 |
| 10362 | ret |
| 10363 | end |
| 10364 | end |
| 10365 | fyes r ty |
| 10366 | ret |
| 10367 | end |
| 10368 | if ne fsext r w r |
| 10369 | ret |
| 10370 | end |
| 10371 | fyes r ty |
| 10372 | end |
| 10373 | |
| 10374 | fn fb_div op ulong ty ulong w ulong sg ulong a ulong b ulong to void |
| 10375 | if eq b 0 |
| 10376 | ret |
| 10377 | end |
| 10378 | if eq sg 0 |
| 10379 | if eq op 36 |
| 10380 | fyes div a b ty |
| 10381 | else |
| 10382 | fyes rem a b ty |
| 10383 | end |
| 10384 | ret |
| 10385 | end |
| 10386 | na = shr a 63 |
| 10387 | sb = shr b 63 |
| 10388 | ma = a |
| 10389 | if ne na 0 |
| 10390 | ma = sub 0 a |
| 10391 | end |
| 10392 | mb = b |
| 10393 | if ne sb 0 |
| 10394 | mb = sub 0 b |
| 10395 | end |
| 10396 | if eq op 37 |
| 10397 | rr = rem ma mb |
| 10398 | if ne na 0 |
| 10399 | rr = sub 0 rr |
| 10400 | end |
| 10401 | fyes rr ty |
| 10402 | ret |
| 10403 | end |
| 10404 | if eq w 64 |
| 10405 | if eq a shl ulong 1 63 |
| 10406 | if eq b not ulong 0 |
| 10407 | ret |
| 10408 | end |
| 10409 | end |
| 10410 | end |
| 10411 | q = div ma mb |
| 10412 | if ne xor na sb 0 |
| 10413 | q = sub 0 q |
| 10414 | end |
| 10415 | if ne fsext q w q |
| 10416 | ret |
| 10417 | end |
| 10418 | fyes q ty |
| 10419 | end |
| 10420 | |
| 10421 | fn fb_shift op ulong ty ulong w ulong sg ulong a ulong b ulong to void |
| 10422 | if ge b w |
| 10423 | ret |
| 10424 | end |
| 10425 | if eq op 42 |
| 10426 | if eq sg 0 |
| 10427 | fyes shr a b ty |
| 10428 | else |
| 10429 | fyes fasr a b ty |
| 10430 | end |
| 10431 | ret |
| 10432 | end |
| 10433 | r = shl a b |
| 10434 | if eq sg 0 |
| 10435 | fyes and r fmask w ty |
| 10436 | ret |
| 10437 | end |
| 10438 | if eq w 64 |
| 10439 | if ne fasr r b a |
| 10440 | ret |
| 10441 | end |
| 10442 | fyes r ty |
| 10443 | ret |
| 10444 | end |
| 10445 | if ne fsext r w r |
| 10446 | ret |
| 10447 | end |
| 10448 | fyes r ty |
| 10449 | end |
| 10450 | |
| 10451 | fn fb_rot op ulong ty ulong w ulong a ulong b ulong to void |
| 10452 | if ge b w |
| 10453 | ret |
| 10454 | end |
| 10455 | s = b |
| 10456 | if and eq op 60 ne s 0 |
| 10457 | s = sub w s |
| 10458 | end |
| 10459 | if eq s 0 |
| 10460 | fyes a ty |
| 10461 | ret |
| 10462 | end |
| 10463 | fyes and or shr a s shl a sub w s fmask w ty |
| 10464 | end |
| 10465 | |
| 10466 | note foldbin: op on the typed numbers a, b of type ty (b's own type for a shift); fok 1 when folded |
| 10467 | fn foldbin op ulong ty ulong a ulong b ulong to void |
| 10468 | put fok 0 0 |
| 10469 | if or eq ty 0 ge ty 10 |
| 10470 | ret |
| 10471 | end |
| 10472 | sg = ulong 0 |
| 10473 | if ge ty 6 |
| 10474 | sg = ulong 1 |
| 10475 | end |
| 10476 | if and ge op 43 le op 48 |
| 10477 | fb_cmp op sg a b |
| 10478 | ret |
| 10479 | end |
| 10480 | if and ge op 38 le op 40 |
| 10481 | r = and a b |
| 10482 | if eq op 39 |
| 10483 | r = or a b |
| 10484 | end |
| 10485 | if eq op 40 |
| 10486 | r = xor a b |
| 10487 | end |
| 10488 | fyes r ty |
| 10489 | ret |
| 10490 | end |
| 10491 | if eq ty 1 |
| 10492 | ret |
| 10493 | end |
| 10494 | w = twid ty |
| 10495 | if le op 35 |
| 10496 | fb_arith op ty w sg a b |
| 10497 | ret |
| 10498 | end |
| 10499 | if le op 37 |
| 10500 | fb_div op ty w sg a b |
| 10501 | ret |
| 10502 | end |
| 10503 | if le op 42 |
| 10504 | fb_shift op ty w sg a b |
| 10505 | ret |
| 10506 | end |
| 10507 | if or eq op 59 eq op 60 |
| 10508 | if le ty 5 |
| 10509 | fb_rot op ty w a b |
| 10510 | end |
| 10511 | end |
| 10512 | end |
| 10513 | |
| 10514 | note foldun: neg (49) / not (50) of the typed number a |
| 10515 | fn foldun c ulong ty ulong a ulong to void |
| 10516 | put fok 0 0 |
| 10517 | if or eq ty 0 ge ty 10 |
| 10518 | ret |
| 10519 | end |
| 10520 | if eq c 50 |
| 10521 | if eq ty 1 |
| 10522 | fyes xor a 1 ty |
| 10523 | ret |
| 10524 | end |
| 10525 | if lt ty 6 |
| 10526 | fyes and not a fmask twid ty ty |
| 10527 | ret |
| 10528 | end |
| 10529 | fyes not a ty |
| 10530 | ret |
| 10531 | end |
| 10532 | if eq ty 1 |
| 10533 | ret |
| 10534 | end |
| 10535 | r = sub 0 a |
| 10536 | if lt ty 6 |
| 10537 | fyes and r fmask twid ty ty |
| 10538 | ret |
| 10539 | end |
| 10540 | w = twid ty |
| 10541 | if eq w 64 |
| 10542 | if eq a shl ulong 1 63 |
| 10543 | ret |
| 10544 | end |
| 10545 | fyes r ty |
| 10546 | ret |
| 10547 | end |
| 10548 | if ne fsext r w r |
| 10549 | ret |
| 10550 | end |
| 10551 | fyes r ty |
| 10552 | end |
| 10553 | |
| 10554 | note ---- omc-site records (om2 diag): one per runtime trap site, in emission order, after the artifact |
| 10555 | note on stderr: omc-site 1 line=N iter=k, k the counters of the open unrolled loops outer to inner |
| 10556 | note joined by '.', or '-'. |
| 10557 | fn siteb b ulong to void |
| 10558 | n = get nsite 0 |
| 10559 | if ge n 8388608 |
| 10560 | fail 14 |
| 10561 | end |
| 10562 | put sitebuf n uchar b |
| 10563 | put nsite 0 add n 1 |
| 10564 | end |
| 10565 | |
| 10566 | fn sitew w ulong n ulong to void |
| 10567 | i = ulong 0 |
| 10568 | x = w |
| 10569 | while lt i n |
| 10570 | siteb and x 255 |
| 10571 | x = shr x 8 |
| 10572 | i = add i 1 |
| 10573 | end |
| 10574 | end |
| 10575 | |
| 10576 | fn siten v ulong to void |
| 10577 | d = new uchar 20 0 |
| 10578 | i = ulong 0 |
| 10579 | x = v |
| 10580 | put d 0 uchar add rem x 10 48 |
| 10581 | x = div x 10 |
| 10582 | i = add i 1 |
| 10583 | while gt x 0 |
| 10584 | put d i uchar add rem x 10 48 |
| 10585 | x = div x 10 |
| 10586 | i = add i 1 |
| 10587 | end |
| 10588 | j = i |
| 10589 | while gt j 0 |
| 10590 | j = sub j 1 |
| 10591 | siteb ulong get d j |
| 10592 | end |
| 10593 | end |
| 10594 | |
| 10595 | fn siterec to void |
| 10596 | sitew 7310584038532803951 8 |
| 10597 | sitew 4424063608026050848 8 |
| 10598 | siten add get line 0 get lbase 0 |
| 10599 | sitew 67561537693984 6 |
| 10600 | any = false |
| 10601 | j = ulong 0 |
| 10602 | while lt j get nb 0 |
| 10603 | if eq get bkind j 5 |
| 10604 | if any |
| 10605 | siteb 46 |
| 10606 | end |
| 10607 | siten get u_it j |
| 10608 | any = true |
| 10609 | end |
| 10610 | j = add j 1 |
| 10611 | end |
| 10612 | if not any |
| 10613 | siteb 45 |
| 10614 | end |
| 10615 | siteb 10 |
| 10616 | end |
| 10617 | |
| 10618 | fn sitesout to void |
| 10619 | p = ulong 0 |
| 10620 | go = true |
| 10621 | while go |
| 10622 | m = ulong 0 |
| 10623 | while and go lt m 999999 |
| 10624 | if ge p get nsite 0 |
| 10625 | go = false |
| 10626 | else |
| 10627 | n = write 2 sitebuf p sub get nsite 0 p |
| 10628 | if le n 0 |
| 10629 | go = false |
| 10630 | else |
| 10631 | p = add p ulong n |
| 10632 | end |
| 10633 | end |
| 10634 | m = add m 1 |
| 10635 | end |
| 10636 | end |
| 10637 | end |
| 10638 | |
| 10639 | note finish: end of a function: a function that needs a value must not reach its end (error 18), a void |
| 10640 | note one returns; then the trap stubs: shared tail, function mode MOV X0, X7; LDR X16, [X7, #16]; BR X16 |
| 10641 | note (C6.2.282, C6.2.216, C6.2.46: OscRt.trap); program mode ADD X0, X1, #100; MOVZ X8, #93; SVC #0 (exit |
| 10642 | note 100 + code). Per trap code used: MOVZ X1, #code (C6.2.285); B tail. om4 FINISH. |
| 10643 | fn finish to void |
| 10644 | if ne get xtarget 0 0 |
| 10645 | xfinish |
| 10646 | ret |
| 10647 | end |
| 10648 | eol |
| 10649 | if eq get dead 0 0 |
| 10650 | if ne get curret 0 12 |
| 10651 | fail 18 |
| 10652 | end |
| 10653 | cp_post 0 0 12 |
| 10654 | epi |
| 10655 | end |
| 10656 | nt0 = get nt 0 |
| 10657 | if ne nt0 0 |
| 10658 | tail = get oc 0 |
| 10659 | if eq get progmode 0 0 |
| 10660 | emit 2852586464 |
| 10661 | emit 4181723376 |
| 10662 | emit 3592356352 |
| 10663 | else |
| 10664 | emit 2432798752 |
| 10665 | emit 3531606952 |
| 10666 | emit 3556769793 |
| 10667 | end |
| 10668 | code = ulong 1 |
| 10669 | while le code 14 |
| 10670 | st = ulong 0 |
| 10671 | j = ulong 0 |
| 10672 | while lt j nt0 |
| 10673 | if eq get tcode j code |
| 10674 | if eq st 0 |
| 10675 | st = get oc 0 |
| 10676 | emit or 3531603969 shl code 5 |
| 10677 | back tail |
| 10678 | end |
| 10679 | patch19 get tsite j st |
| 10680 | end |
| 10681 | j = add j 1 |
| 10682 | end |
| 10683 | code = add code 1 |
| 10684 | end |
| 10685 | end |
| 10686 | put curret 0 0 |
| 10687 | put nn 0 get nglob 0 |
| 10688 | put curfn 0 0 |
| 10689 | put nbrk 0 0 |
| 10690 | put ncont 0 0 |
| 10691 | end |
| 10692 | |
| 10693 | note s_end: close the innermost block (if: patch its branch; else: patch its jump; while: B head; for: i = |
| 10694 | note add i 1, B head), or the function. om4 S_END. |
| 10695 | fn s_end to void |
| 10696 | n = get nb 0 |
| 10697 | if eq n 0 |
| 10698 | finish |
| 10699 | ret |
| 10700 | end |
| 10701 | i = sub n 1 |
| 10702 | if eq get bkind i 5 |
| 10703 | s_unr i |
| 10704 | ret |
| 10705 | end |
| 10706 | if eq get bkind i 6 |
| 10707 | s_inlx i |
| 10708 | ret |
| 10709 | end |
| 10710 | put nb 0 i |
| 10711 | k = get bkind i |
| 10712 | fz_join i k |
| 10713 | if eq k 2 |
| 10714 | put dead 0 and get dead 0 get bdead i |
| 10715 | else |
| 10716 | put dead 0 0 |
| 10717 | end |
| 10718 | if eq k 4 |
| 10719 | lat = get oc 0 |
| 10720 | j = ulong 0 |
| 10721 | while lt j get ncont 0 |
| 10722 | if eq get cblk j i |
| 10723 | patch19 get cpos j lat |
| 10724 | put cblk j 65535 |
| 10725 | end |
| 10726 | j = add j 1 |
| 10727 | end |
| 10728 | put fr 0 1 |
| 10729 | put fr 1 get breg i |
| 10730 | put fr 2 get btyp i |
| 10731 | put fr 3 3 |
| 10732 | put fr 4 1 |
| 10733 | put fr 5 get btyp i |
| 10734 | binop 33 get breg i 0 |
| 10735 | end |
| 10736 | if eq k 3 |
| 10737 | j = ulong 0 |
| 10738 | while lt j get ncont 0 |
| 10739 | if eq get cblk j i |
| 10740 | patch19 get cpos j get bhead i |
| 10741 | put cblk j 65535 |
| 10742 | end |
| 10743 | j = add j 1 |
| 10744 | end |
| 10745 | end |
| 10746 | if ge k 3 |
| 10747 | back get bhead i |
| 10748 | ex = get oc 0 |
| 10749 | j = ulong 0 |
| 10750 | while lt j get nbrk 0 |
| 10751 | if eq get brkblk j i |
| 10752 | patch19 get brkpos j ex |
| 10753 | put brkblk j 65535 |
| 10754 | end |
| 10755 | j = add j 1 |
| 10756 | end |
| 10757 | end |
| 10758 | if eq k 2 |
| 10759 | if or eq get xtarget 0 0 eq get bdead i 0 |
| 10760 | patch26 get bbr i get oc 0 |
| 10761 | end |
| 10762 | else |
| 10763 | patch19 get bbr i get oc 0 |
| 10764 | end |
| 10765 | put nn 0 get bnames i |
| 10766 | put held 0 get bheld i |
| 10767 | eol |
| 10768 | end |
| 10769 | |
| 10770 | note ======== the end of the input: the output ======== |
| 10771 | note writeout: the output from byte st to the end, to stdout (error 2), then exit 0. om4 WRITEOUT. |
| 10772 | fn writeout st ulong to void |
| 10773 | if eq get chkmode 0 1 |
| 10774 | put mc 0 0 |
| 10775 | mputw 7594244768023276911 8 |
| 10776 | mputw 11207551510369 6 |
| 10777 | mflush |
| 10778 | exit int 0 |
| 10779 | end |
| 10780 | if ne get fmtm 0 0 |
| 10781 | fmtout |
| 10782 | end |
| 10783 | p = st |
| 10784 | go = true |
| 10785 | while go |
| 10786 | m = ulong 0 |
| 10787 | while and go lt m 999999 |
| 10788 | if ge p get oc 0 |
| 10789 | go = false |
| 10790 | else |
| 10791 | n = write 1 out p sub get oc 0 p |
| 10792 | if le n 0 |
| 10793 | fail 2 |
| 10794 | end |
| 10795 | p = add p ulong n |
| 10796 | end |
| 10797 | m = add m 1 |
| 10798 | end |
| 10799 | end |
| 10800 | if eq get om2m 0 1 |
| 10801 | sitesout |
| 10802 | end |
| 10803 | exit int 0 |
| 10804 | end |
| 10805 | |
| 10806 | note elfhdr: the 176-byte file header (om4 ELFHDR, 44 words): ELF64 little-endian, executable, AArch64, |
| 10807 | note entry 0x4000b0 (the word after the header), 2 program headers: code read+execute from 0x400000, and |
| 10808 | note the read/write pools from 0x10000000. Only the words that are not 0 (the output starts at 0). |
| 10809 | fn elfhdr to void |
| 10810 | wrword 0 1179403647 |
| 10811 | wrword 4 65794 |
| 10812 | wrword 16 11993090 |
| 10813 | wrword 20 1 |
| 10814 | wrword 24 4194480 |
| 10815 | wrword 32 64 |
| 10816 | wrword 52 3670080 |
| 10817 | wrword 56 2 |
| 10818 | wrword 64 1 |
| 10819 | wrword 68 5 |
| 10820 | wrword 80 4194304 |
| 10821 | wrword 88 4194304 |
| 10822 | wrword 112 4096 |
| 10823 | wrword 120 1 |
| 10824 | wrword 124 6 |
| 10825 | wrword 136 268435456 |
| 10826 | wrword 144 268435456 |
| 10827 | wrword 168 4096 |
| 10828 | end |
| 10829 | |
| 10830 | note eof_prog: program mode: start code = MOVZ X28, #0x1000, LSL 16 (stack pool floor); MOVZ X16, #0x1080, |
| 10831 | 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, |
| 10832 | note #93; SVC #0. The entry word after the header is a B to it; the header gets the file and pool sizes. |
| 10833 | note om4 EOF_PROG. |
| 10834 | fn eof_prog to void |
| 10835 | if ne get xtarget 0 0 |
| 10836 | xeof |
| 10837 | ret |
| 10838 | end |
| 10839 | f = findfn 1852399981 4 0 |
| 10840 | if eq f 0 |
| 10841 | fail 16 |
| 10842 | end |
| 10843 | if ne get fn_np sub f 1 0 |
| 10844 | fail 9 |
| 10845 | end |
| 10846 | wrword 176 or 335544320 bdisp 176 get oc 0 26 |
| 10847 | if ne get hostargs 0 0 |
| 10848 | note Preserve Linux's initial argument stack privately before installing Omega's bounded stack. |
| 10849 | emit 2432697339 |
| 10850 | end |
| 10851 | emit 3533832220 |
| 10852 | emit 3533836304 |
| 10853 | emit 2432696863 |
| 10854 | emit or 2483027968 bdisp get oc 0 get fn_addr sub f 1 26 |
| 10855 | if eq get fn_ret sub f 1 12 |
| 10856 | emit 3531603968 |
| 10857 | end |
| 10858 | emit 3531606952 |
| 10859 | emit 3556769793 |
| 10860 | elfhdr |
| 10861 | wrword 96 get oc 0 |
| 10862 | wrword 104 get oc 0 |
| 10863 | wrword 160 add get poolb 0 8388608 |
| 10864 | writeout 0 |
| 10865 | end |
| 10866 | |
| 10867 | note s_eof: end of input: no open function (error 15), some function (16); function mode: no globals or |
| 10868 | note texts (9, fnstore; consts fold and are allowed); one function: its bare words; more: the entry word, a |
| 10869 | note B to the last function. om4 S_EOF. |
| 10870 | note Resolve every call after all addresses are known. In function mode remove leaves of the call |
| 10871 | note graph; any functions left after nf rounds form or reach a cycle (error 9). |
| 10872 | fn resolve to void |
| 10873 | n = get ncalls 0 |
| 10874 | i = ulong 0 |
| 10875 | while lt i n |
| 10876 | s = get callsite i |
| 10877 | f = sub get callto i 1 |
| 10878 | if ne get xtarget 0 0 |
| 10879 | wrword add s 1 sub get fn_addr f add s 5 |
| 10880 | else |
| 10881 | wrword s or 2483027968 bdisp s get fn_addr f 26 |
| 10882 | end |
| 10883 | i = add i 1 |
| 10884 | end |
| 10885 | if eq get progmode 0 0 |
| 10886 | pass = ulong 0 |
| 10887 | while lt pass get nf 0 |
| 10888 | f = ulong 0 |
| 10889 | while lt f get nf 0 |
| 10890 | if eq get settled f 0 |
| 10891 | ok = true |
| 10892 | i = ulong 0 |
| 10893 | while and ok lt i n |
| 10894 | if eq get callfrom i add f 1 |
| 10895 | if eq get settled sub get callto i 1 0 |
| 10896 | ok = false |
| 10897 | end |
| 10898 | end |
| 10899 | i = add i 1 |
| 10900 | end |
| 10901 | if ok |
| 10902 | put settled f 1 |
| 10903 | end |
| 10904 | end |
| 10905 | f = add f 1 |
| 10906 | end |
| 10907 | pass = add pass 1 |
| 10908 | end |
| 10909 | f = ulong 0 |
| 10910 | while lt f get nf 0 |
| 10911 | if eq get settled f 0 |
| 10912 | put dsev 0 3 |
| 10913 | fail 9 |
| 10914 | end |
| 10915 | f = add f 1 |
| 10916 | end |
| 10917 | end |
| 10918 | end |
| 10919 | |
| 10920 | note reachself: 1 when function f (index + 1) reaches itself |
| 10921 | fn reachself f ulong to ulong |
| 10922 | i = ulong 0 |
| 10923 | while lt i get nf 0 |
| 10924 | put reach i 0 |
| 10925 | i = add i 1 |
| 10926 | end |
| 10927 | put reach sub f 1 1 |
| 10928 | go = true |
| 10929 | pass = ulong 0 |
| 10930 | while and go le pass get nf 0 |
| 10931 | r = rscan f 0 |
| 10932 | if eq r 2 |
| 10933 | ret 1 |
| 10934 | end |
| 10935 | s = rscan f 1 |
| 10936 | if eq s 2 |
| 10937 | ret 1 |
| 10938 | end |
| 10939 | go = or ne r 0 ne s 0 |
| 10940 | pass = add pass 1 |
| 10941 | end |
| 10942 | ret 0 |
| 10943 | end |
| 10944 | |
| 10945 | note rscan: one pass over the calls (w 0) or the inline edges (w 1): 2 when an edge from a reached |
| 10946 | note function leads to f, 1 when a function was newly reached, else 0 |
| 10947 | fn rscan f ulong w ulong to ulong |
| 10948 | n = get ncalls 0 |
| 10949 | if ne w 0 |
| 10950 | n = get nie 0 |
| 10951 | end |
| 10952 | ch = ulong 0 |
| 10953 | j = ulong 0 |
| 10954 | while lt j n |
| 10955 | a = get callfrom j |
| 10956 | b = get callto j |
| 10957 | if ne w 0 |
| 10958 | a = get ie_from j |
| 10959 | b = get ie_to j |
| 10960 | end |
| 10961 | if ne get reach sub a 1 0 |
| 10962 | if eq b f |
| 10963 | ret 2 |
| 10964 | end |
| 10965 | if eq get reach sub b 1 0 |
| 10966 | put reach sub b 1 1 |
| 10967 | ch = ulong 1 |
| 10968 | end |
| 10969 | end |
| 10970 | j = add j 1 |
| 10971 | end |
| 10972 | ret ch |
| 10973 | end |
| 10974 | |
| 10975 | fn s_eof to void |
| 10976 | if eq get chkmode 0 2 |
| 10977 | emit_query |
| 10978 | end |
| 10979 | if ne get curret 0 0 |
| 10980 | fail 15 |
| 10981 | end |
| 10982 | if eq get nf 0 0 |
| 10983 | fail 16 |
| 10984 | end |
| 10985 | if ne get om2 0 0 |
| 10986 | note inlcyc (OM-2): an inline function that reaches itself through the whole call graph (the calls made, |
| 10987 | note plus an edge from each function to every inline function expanded in it) is error 9 at the end. |
| 10988 | f = ulong 1 |
| 10989 | while le f get nf 0 |
| 10990 | if ne get fn_inl sub f 1 0 |
| 10991 | if ne reachself f 0 |
| 10992 | put dsev 0 3 |
| 10993 | fail 9 |
| 10994 | end |
| 10995 | end |
| 10996 | f = add f 1 |
| 10997 | end |
| 10998 | end |
| 10999 | resolve |
| 11000 | if ne get progmode 0 0 |
| 11001 | eof_prog |
| 11002 | end |
| 11003 | if eq get progmode 0 0 |
| 11004 | note fnstore: function mode. A top-level global pool (kind 4) or text (kind 5) needs the program image and |
| 11005 | note is error 9; a const (kind 9) is folded to a typed number wherever it is read, so it composes here too. |
| 11006 | i = ulong 0 |
| 11007 | while lt i get nglob 0 |
| 11008 | if ne get nm_kind i 9 |
| 11009 | fail 9 |
| 11010 | end |
| 11011 | i = add i 1 |
| 11012 | end |
| 11013 | end |
| 11014 | if ne get xtarget 0 0 |
| 11015 | note Bare x86 units share the private frame ABI; exports have six-byte JMP/NOP slots. |
| 11016 | n = get nexp 0 |
| 11017 | p = ulong 512 |
| 11018 | f = ulong 0 |
| 11019 | while lt f get nf 0 |
| 11020 | take = ne get fn_exp f 0 |
| 11021 | if eq n 0 |
| 11022 | take = eq f sub get lastfn 0 1 |
| 11023 | end |
| 11024 | if take |
| 11025 | put out p 233 |
| 11026 | wrword add p 1 sub get fn_addr f add p 5 |
| 11027 | put out add p 5 144 |
| 11028 | p = add p 6 |
| 11029 | end |
| 11030 | f = add f 1 |
| 11031 | end |
| 11032 | writeout 512 |
| 11033 | end |
| 11034 | if ne get nexp 0 0 |
| 11035 | note expwords (OM-2, spec 6): words 0 .. E-1 of a multi-entry unit, B to each export in source order |
| 11036 | at = ulong 176 |
| 11037 | f = ulong 0 |
| 11038 | while lt f get nf 0 |
| 11039 | if ne get fn_exp f 0 |
| 11040 | wrword at or 335544320 bdisp at get fn_addr f 26 |
| 11041 | at = add at 4 |
| 11042 | end |
| 11043 | f = add f 1 |
| 11044 | end |
| 11045 | writeout 176 |
| 11046 | end |
| 11047 | if eq get nf 0 1 |
| 11048 | writeout 180 |
| 11049 | end |
| 11050 | a = get fn_addr sub get lastfn 0 1 |
| 11051 | wrword 176 or 335544320 bdisp 176 a 26 |
| 11052 | writeout 176 |
| 11053 | end |
| 11054 | |
| 11055 | note stmt: one line. Returns 1 at the end of the input. om4 STMT. |
| 11056 | fn stmt to ulong |
| 11057 | put dexp 0 0 |
| 11058 | put nslot 0 get held 0 |
| 11059 | tok |
| 11060 | k = get tk 0 |
| 11061 | if eq k 0 |
| 11062 | ret 0 |
| 11063 | end |
| 11064 | if eq k 3 |
| 11065 | s_eof |
| 11066 | ret 1 |
| 11067 | end |
| 11068 | if ne k 1 |
| 11069 | fail 16 |
| 11070 | end |
| 11071 | if and ne get chkmode 0 0 eq get line 0 get chkln 0 |
| 11072 | skipnl |
| 11073 | ret 0 |
| 11074 | end |
| 11075 | if and ne get om2 0 0 eq get line 0 get om2ln 0 |
| 11076 | skipnl |
| 11077 | ret 0 |
| 11078 | end |
| 11079 | if ne cp_kind 0 |
| 11080 | fail 30 |
| 11081 | end |
| 11082 | if gt get tl 0 8 |
| 11083 | note s_long: a word over 8 characters at the start of a line: only a call of a void function. om4 S_LONG. |
| 11084 | if eq get curret 0 0 |
| 11085 | fail 13 |
| 11086 | end |
| 11087 | if ne get dead 0 0 |
| 11088 | fail 17 |
| 11089 | end |
| 11090 | f = findfn get tw 0 get tl 0 get ts 0 |
| 11091 | if eq f 0 |
| 11092 | unkfail 13 |
| 11093 | end |
| 11094 | if ne get fn_ret sub f 1 12 |
| 11095 | fail 7 |
| 11096 | end |
| 11097 | rdval 2 0 255 f |
| 11098 | eol |
| 11099 | ret 0 |
| 11100 | end |
| 11101 | w = get tw 0 |
| 11102 | c = kw w |
| 11103 | if eq c 83 |
| 11104 | skipnl |
| 11105 | ret 0 |
| 11106 | end |
| 11107 | if eq c 64 |
| 11108 | s_fn |
| 11109 | ret 0 |
| 11110 | end |
| 11111 | if eq get curret 0 0 |
| 11112 | if eq c 78 |
| 11113 | s_global |
| 11114 | ret 0 |
| 11115 | end |
| 11116 | if eq c 79 |
| 11117 | s_text |
| 11118 | ret 0 |
| 11119 | end |
| 11120 | if eq c 152 |
| 11121 | s_const |
| 11122 | ret 0 |
| 11123 | end |
| 11124 | if eq c 85 |
| 11125 | skipnl |
| 11126 | ret 0 |
| 11127 | end |
| 11128 | if eq c 195 |
| 11129 | s_export |
| 11130 | ret 0 |
| 11131 | end |
| 11132 | if eq c 188 |
| 11133 | note s_lyskip: the body pass jumps to the place after the layout's end (read in the names pass) |
| 11134 | tok |
| 11135 | li = sub findlay get tw 0 1 |
| 11136 | put cur 0 get ly_ec li |
| 11137 | put line 0 get ly_el li |
| 11138 | ret 0 |
| 11139 | end |
| 11140 | if or eq c 184 eq c 187 |
| 11141 | skipnl |
| 11142 | ret 0 |
| 11143 | end |
| 11144 | fail 16 |
| 11145 | end |
| 11146 | if eq c 66 |
| 11147 | s_end |
| 11148 | ret 0 |
| 11149 | end |
| 11150 | if eq c 68 |
| 11151 | s_else |
| 11152 | ret 0 |
| 11153 | end |
| 11154 | if ne get dead 0 0 |
| 11155 | fail 17 |
| 11156 | end |
| 11157 | if eq c 0 |
| 11158 | s_name w |
| 11159 | ret 0 |
| 11160 | end |
| 11161 | if eq c 67 |
| 11162 | note s_if: if cond: the false branch is patched at else / end. om4 S_IF. |
| 11163 | at = cond |
| 11164 | pushb at 1 0 0 0 |
| 11165 | pushnh get nn 0 get held 0 |
| 11166 | eol |
| 11167 | ret 0 |
| 11168 | end |
| 11169 | if eq c 69 |
| 11170 | s_while |
| 11171 | ret 0 |
| 11172 | end |
| 11173 | if eq c 71 |
| 11174 | s_for |
| 11175 | ret 0 |
| 11176 | end |
| 11177 | if eq c 72 |
| 11178 | s_ret |
| 11179 | ret 0 |
| 11180 | end |
| 11181 | if eq c 80 |
| 11182 | s_put |
| 11183 | ret 0 |
| 11184 | end |
| 11185 | if eq c 82 |
| 11186 | note s_exit: exit value (int): Linux exit (system call 93: MOVZ X8, #93, C6.2.285; SVC #0, C6.2.466); the |
| 11187 | note path ends. om4 S_EXIT. |
| 11188 | rdval 0 8 255 0 |
| 11189 | if ne get rt 0 8 |
| 11190 | fail 7 |
| 11191 | end |
| 11192 | force get rk 0 get rv 0 get rt 0 0 |
| 11193 | if ne get xtarget 0 0 |
| 11194 | xload 0 0 |
| 11195 | xleave |
| 11196 | else |
| 11197 | emit 3531606952 |
| 11198 | emit 3556769793 |
| 11199 | end |
| 11200 | dead1 |
| 11201 | eol |
| 11202 | ret 0 |
| 11203 | end |
| 11204 | if eq c 86 |
| 11205 | s_break |
| 11206 | ret 0 |
| 11207 | end |
| 11208 | if eq c 87 |
| 11209 | note s_trap: trap N (1 .. 14): an always-taken branch to the trap stub for code N, which finish makes. |
| 11210 | note Program mode exits 100 + N; function mode calls OscRt.trap (OMEGESE 9.1). The line ends the path. |
| 11211 | v = lenval 4 |
| 11212 | if or lt v 1 gt v 14 |
| 11213 | fail 8 |
| 11214 | end |
| 11215 | trapc 14 v |
| 11216 | dead1 |
| 11217 | eol |
| 11218 | ret 0 |
| 11219 | end |
| 11220 | note cpufence (keyword 199, a statement without operands): the host CPU publication barrier. AArch64: |
| 11221 | note DSB SY (d5033f9f, the full-system barrier mapget/mapset already bracket their access with). x86-64: |
| 11222 | note MFENCE (0F AE F0), the fence the x86 mapget/mapset use. Every earlier load and store completes before |
| 11223 | note any later one, so a GPU or another CPU that observes a later store also observes the earlier ones. |
| 11224 | note Inline here, not a function: om4 builds omc and holds at most 512 functions, 511 in use. |
| 11225 | if eq c 199 |
| 11226 | eol |
| 11227 | if ne get xtarget 0 0 |
| 11228 | xb 15 174 240 |
| 11229 | else |
| 11230 | emit 3573759903 |
| 11231 | end |
| 11232 | ret 0 |
| 11233 | end |
| 11234 | note cpurelax (keyword 200, a statement without operands): spin-wait hint, no ordering. AArch64: YIELD |
| 11235 | note (d503203f). x86-64: PAUSE (F3 90). Use it in a bounded poll loop; pair it with cpufence for order. |
| 11236 | if eq c 200 |
| 11237 | eol |
| 11238 | if ne get xtarget 0 0 |
| 11239 | emitb 243 |
| 11240 | emitb 144 |
| 11241 | else |
| 11242 | emit 3573751871 |
| 11243 | end |
| 11244 | ret 0 |
| 11245 | end |
| 11246 | if eq c 97 |
| 11247 | s_cont |
| 11248 | ret 0 |
| 11249 | end |
| 11250 | if or or or eq c 77 eq c 78 eq c 79 eq c 81 |
| 11251 | fail 9 |
| 11252 | end |
| 11253 | if or eq c 85 eq c 193 |
| 11254 | fail 9 |
| 11255 | end |
| 11256 | fail 16 |
| 11257 | ret 0 |
| 11258 | end |
| 11259 | |
| 11260 | note ======== program mode: some line is `fn main` (blanks, fn, blanks, main, then a blank or the end) ======== |
| 11261 | note skipbl: the first place at or after q that is not a space or tab (or the end) |
| 11262 | fn skipbl q ulong to ulong |
| 11263 | e = get inlen 0 |
| 11264 | p = q |
| 11265 | go = true |
| 11266 | while go |
| 11267 | m = ulong 0 |
| 11268 | while and go lt m 999999 |
| 11269 | if ge p e |
| 11270 | go = false |
| 11271 | else |
| 11272 | b = get inp p |
| 11273 | if or eq b 32 eq b 9 |
| 11274 | p = add p 1 |
| 11275 | else |
| 11276 | go = false |
| 11277 | end |
| 11278 | end |
| 11279 | m = add m 1 |
| 11280 | end |
| 11281 | end |
| 11282 | ret p |
| 11283 | end |
| 11284 | |
| 11285 | note skipln: the place after the next newline at or after q (or the end) |
| 11286 | fn skipln q ulong to ulong |
| 11287 | e = get inlen 0 |
| 11288 | p = q |
| 11289 | go = true |
| 11290 | while go |
| 11291 | m = ulong 0 |
| 11292 | while and go lt m 999999 |
| 11293 | if ge p e |
| 11294 | go = false |
| 11295 | else |
| 11296 | b = get inp p |
| 11297 | p = add p 1 |
| 11298 | if eq b 10 |
| 11299 | go = false |
| 11300 | end |
| 11301 | end |
| 11302 | m = add m 1 |
| 11303 | end |
| 11304 | end |
| 11305 | ret p |
| 11306 | end |
| 11307 | |
| 11308 | 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 |
| 11309 | note ends while deciding, else 0. om4 PS_LINE .. PS_YES. |
| 11310 | fn ps_at p ulong to ulong |
| 11311 | e = get inlen 0 |
| 11312 | if ne get inp p 102 |
| 11313 | ret 0 |
| 11314 | end |
| 11315 | q = add p 1 |
| 11316 | if ge q e |
| 11317 | ret 2 |
| 11318 | end |
| 11319 | if ne get inp q 110 |
| 11320 | ret 0 |
| 11321 | end |
| 11322 | r = add q 1 |
| 11323 | q = skipbl r |
| 11324 | if ge q e |
| 11325 | ret 2 |
| 11326 | end |
| 11327 | if eq q r |
| 11328 | ret 0 |
| 11329 | end |
| 11330 | if gt add q 4 e |
| 11331 | ret 0 |
| 11332 | end |
| 11333 | if ne get inp q 109 |
| 11334 | ret 0 |
| 11335 | end |
| 11336 | if ne get inp add q 1 97 |
| 11337 | ret 0 |
| 11338 | end |
| 11339 | if ne get inp add q 2 105 |
| 11340 | ret 0 |
| 11341 | end |
| 11342 | if ne get inp add q 3 110 |
| 11343 | ret 0 |
| 11344 | end |
| 11345 | if ge add q 4 e |
| 11346 | ret 1 |
| 11347 | end |
| 11348 | if gt get inp add q 4 32 |
| 11349 | ret 0 |
| 11350 | end |
| 11351 | ret 1 |
| 11352 | end |
| 11353 | |
| 11354 | fn prescan to void |
| 11355 | e = get inlen 0 |
| 11356 | p = ulong 0 |
| 11357 | go = true |
| 11358 | while go |
| 11359 | m = ulong 0 |
| 11360 | while and go lt m 999999 |
| 11361 | p = skipbl p |
| 11362 | if ge p e |
| 11363 | go = false |
| 11364 | else |
| 11365 | r = ps_at p |
| 11366 | if eq r 1 |
| 11367 | put progmode 0 1 |
| 11368 | go = false |
| 11369 | end |
| 11370 | if eq r 2 |
| 11371 | go = false |
| 11372 | end |
| 11373 | if go |
| 11374 | p = skipln p |
| 11375 | if ge p e |
| 11376 | go = false |
| 11377 | end |
| 11378 | end |
| 11379 | end |
| 11380 | m = add m 1 |
| 11381 | end |
| 11382 | end |
| 11383 | end |
| 11384 | |
| 11385 | note First collect signatures. Only fn headers are parsed here; other lines are read in the body pass. |
| 11386 | fn namescan to void |
| 11387 | put scanning 0 1 |
| 11388 | put line 0 1 |
| 11389 | go = true |
| 11390 | while go |
| 11391 | n = ulong 0 |
| 11392 | while and go lt n 999999 |
| 11393 | tok |
| 11394 | if eq get tk 0 3 |
| 11395 | go = false |
| 11396 | else |
| 11397 | if ne get tk 0 0 |
| 11398 | if and eq get tk 0 1 eq get tw 0 28262 |
| 11399 | s_fn |
| 11400 | else |
| 11401 | if and eq get tk 0 1 eq get tw 0 127970521019507 |
| 11402 | s_struct |
| 11403 | else |
| 11404 | if and eq get tk 0 1 eq get tw 0 500152823651 |
| 11405 | s_const |
| 11406 | else |
| 11407 | if eq ns_om2 0 |
| 11408 | skipnl |
| 11409 | end |
| 11410 | end |
| 11411 | end |
| 11412 | end |
| 11413 | end |
| 11414 | end |
| 11415 | n = add n 1 |
| 11416 | end |
| 11417 | end |
| 11418 | put scanning 0 0 |
| 11419 | put cur 0 0 |
| 11420 | put line 0 1 |
| 11421 | put nn 0 0 |
| 11422 | put nglob 0 0 |
| 11423 | put curfn 0 0 |
| 11424 | put curret 0 0 |
| 11425 | put npar 0 0 |
| 11426 | put nslot 0 0 |
| 11427 | for j ulong 16 |
| 11428 | put vsl j 0 |
| 11429 | end |
| 11430 | put held 0 0 |
| 11431 | end |
| 11432 | |
| 11433 | note ======== R6 structs (omc only; om4 stays the parent that rebuilds this file) ======== |
| 11434 | note A struct is 8-byte cells, declaration order, no padding (OSC-2). new is a stack slot, given |
| 11435 | note back at ret, like a local array. There is no free (decision 24). Field scale: cell << (3 - tlog) |
| 11436 | note so a typed store lands on cell * 8. Pack of struct is 127970521019507 (Wolfram, little-endian). |
| 11437 | |
| 11438 | note findstruct: packed name -> index + 1, or 0 |
| 11439 | fn findstruct w ulong to ulong |
| 11440 | i = ulong 0 |
| 11441 | n = get nst 0 |
| 11442 | while lt i n |
| 11443 | if eq get st_name i w |
| 11444 | ret add i 1 |
| 11445 | end |
| 11446 | i = add i 1 |
| 11447 | end |
| 11448 | ret 0 |
| 11449 | end |
| 11450 | |
| 11451 | note findfield: struct index, packed field name -> field-table index + 1, or 0 |
| 11452 | fn findfield si ulong w ulong to ulong |
| 11453 | fo = ulong get st_foff si |
| 11454 | nfd = ulong get st_nf si |
| 11455 | i = ulong 0 |
| 11456 | while lt i nfd |
| 11457 | j = add fo i |
| 11458 | if eq get sf_name j w |
| 11459 | ret add j 1 |
| 11460 | end |
| 11461 | i = add i 1 |
| 11462 | end |
| 11463 | ret 0 |
| 11464 | end |
| 11465 | |
| 11466 | note field_dup: 1 if w is already a field of the struct being read (fields fo .. nsf) |
| 11467 | fn field_dup fo ulong w ulong to ulong |
| 11468 | i = fo |
| 11469 | e = get nsf 0 |
| 11470 | while lt i e |
| 11471 | if eq get sf_name i w |
| 11472 | ret 1 |
| 11473 | end |
| 11474 | i = add i 1 |
| 11475 | end |
| 11476 | ret 0 |
| 11477 | end |
| 11478 | |
| 11479 | note s_field: the current word is a field name of struct w. Returns the cell count after this field. |
| 11480 | fn s_field w ulong fo ulong cells ulong to ulong |
| 11481 | if gt get tl 0 8 |
| 11482 | fail 13 |
| 11483 | end |
| 11484 | if ne kw get tw 0 0 |
| 11485 | fail 16 |
| 11486 | end |
| 11487 | fw = get tw 0 |
| 11488 | if eq fw w |
| 11489 | fail 10 |
| 11490 | end |
| 11491 | if ne findstruct fw 0 |
| 11492 | fail 10 |
| 11493 | end |
| 11494 | if ne field_dup fo fw 0 |
| 11495 | fail 10 |
| 11496 | end |
| 11497 | t = typeword |
| 11498 | if ge t 64 |
| 11499 | fail 7 |
| 11500 | end |
| 11501 | ln = ulong 0 |
| 11502 | p = get cur 0 |
| 11503 | ln0 = get line 0 |
| 11504 | tok |
| 11505 | k = get tk 0 |
| 11506 | if eq k 2 |
| 11507 | ln = get tw 0 |
| 11508 | if ne get tbig 0 0 |
| 11509 | fail 14 |
| 11510 | end |
| 11511 | if or eq ln 0 gt ln 64 |
| 11512 | fail 14 |
| 11513 | end |
| 11514 | else |
| 11515 | if eq k 1 |
| 11516 | e = findname get tw 0 |
| 11517 | if ne e 0 |
| 11518 | if eq get nm_kind sub e 1 9 |
| 11519 | ct = ulong get nm_type sub e 1 |
| 11520 | if ge ct 10 |
| 11521 | fail 14 |
| 11522 | end |
| 11523 | ln = get nm_addr sub e 1 |
| 11524 | if or eq ln 0 gt ln 64 |
| 11525 | fail 14 |
| 11526 | end |
| 11527 | else |
| 11528 | put cur 0 p |
| 11529 | put line 0 ln0 |
| 11530 | end |
| 11531 | else |
| 11532 | put cur 0 p |
| 11533 | put line 0 ln0 |
| 11534 | end |
| 11535 | else |
| 11536 | put cur 0 p |
| 11537 | put line 0 ln0 |
| 11538 | end |
| 11539 | end |
| 11540 | addc = ulong 1 |
| 11541 | if ne ln 0 |
| 11542 | addc = ln |
| 11543 | end |
| 11544 | if gt add cells addc 64 |
| 11545 | fail 14 |
| 11546 | end |
| 11547 | put sf_name get nsf 0 fw |
| 11548 | put sf_type get nsf 0 uchar t |
| 11549 | put sf_len get nsf 0 uchar ln |
| 11550 | put sf_off get nsf 0 uchar cells |
| 11551 | put nsf 0 add get nsf 0 1 |
| 11552 | ret add cells addc |
| 11553 | end |
| 11554 | |
| 11555 | note s_struct: struct Name (field type [len])* end. Before any fn (namescan). 1..16 fields, <= 64 cells. |
| 11556 | fn s_struct to void |
| 11557 | if ne get nf 0 0 |
| 11558 | fail 9 |
| 11559 | end |
| 11560 | tok |
| 11561 | if ne get tk 0 1 |
| 11562 | fail 16 |
| 11563 | end |
| 11564 | if gt get tl 0 8 |
| 11565 | fail 13 |
| 11566 | end |
| 11567 | if ne kw get tw 0 0 |
| 11568 | fail 16 |
| 11569 | end |
| 11570 | w = get tw 0 |
| 11571 | if ne findstruct w 0 |
| 11572 | fail 10 |
| 11573 | end |
| 11574 | if ne findfn w get tl 0 get ts 0 0 |
| 11575 | fail 10 |
| 11576 | end |
| 11577 | if ge get nst 0 16 |
| 11578 | fail 14 |
| 11579 | end |
| 11580 | sid = get nst 0 |
| 11581 | fo = get nsf 0 |
| 11582 | cells = ulong 0 |
| 11583 | nfld = ulong 0 |
| 11584 | go = true |
| 11585 | while go |
| 11586 | tok |
| 11587 | if eq get tk 0 0 |
| 11588 | fail 4 |
| 11589 | end |
| 11590 | if ne get tk 0 1 |
| 11591 | fail 16 |
| 11592 | end |
| 11593 | if eq kw get tw 0 66 |
| 11594 | go = false |
| 11595 | else |
| 11596 | if ge nfld 16 |
| 11597 | fail 14 |
| 11598 | end |
| 11599 | cells = s_field w fo cells |
| 11600 | nfld = add nfld 1 |
| 11601 | end |
| 11602 | end |
| 11603 | if eq nfld 0 |
| 11604 | fail 16 |
| 11605 | end |
| 11606 | put st_name sid w |
| 11607 | put st_nf sid uchar nfld |
| 11608 | put st_cells sid uchar cells |
| 11609 | put st_foff sid uchar fo |
| 11610 | put nst 0 add sid 1 |
| 11611 | eol |
| 11612 | end |
| 11613 | |
| 11614 | note peek_struct: if the next word is a struct name, consume it and return index + 1; else rewind |
| 11615 | fn peek_struct to ulong |
| 11616 | p = get cur 0 |
| 11617 | ln = get line 0 |
| 11618 | tok |
| 11619 | if ne get tk 0 1 |
| 11620 | put cur 0 p |
| 11621 | put line 0 ln |
| 11622 | ret 0 |
| 11623 | end |
| 11624 | sid = findstruct get tw 0 |
| 11625 | if eq sid 0 |
| 11626 | put cur 0 p |
| 11627 | put line 0 ln |
| 11628 | ret 0 |
| 11629 | end |
| 11630 | ret sid |
| 11631 | end |
| 11632 | |
| 11633 | note fn_p_st: parameter pw is view (k 2, name kind 8) or edit (k 3, name kind 7). fn_pk is 6 or 7. |
| 11634 | fn fn_p_st f ulong np ulong pw ulong sid ulong k ulong to void |
| 11635 | si = sub sid 1 |
| 11636 | t = add si 16 |
| 11637 | ln = ulong get st_cells si |
| 11638 | sk = add k 4 |
| 11639 | if eq k 2 |
| 11640 | addname pw poolc get psl 0 t ln 8 0 |
| 11641 | else |
| 11642 | addname pw poolc get psl 0 t ln 7 0 |
| 11643 | end |
| 11644 | p = add mul f 6 np |
| 11645 | put fn_pt p uchar t |
| 11646 | put fn_pl p ln |
| 11647 | put fn_pk p uchar sk |
| 11648 | end |
| 11649 | |
| 11650 | note sa_new: name = new <type or struct>. Rewind unless the next word is a struct name. |
| 11651 | fn sa_new w ulong to void |
| 11652 | if ne get om2 0 0 |
| 11653 | if ne get inl 0 0 |
| 11654 | fail 9 |
| 11655 | end |
| 11656 | if ne get fn_inl sub get curfn 0 1 0 |
| 11657 | fail 9 |
| 11658 | end |
| 11659 | end |
| 11660 | p = get cur 0 |
| 11661 | ln = get line 0 |
| 11662 | tok |
| 11663 | sid = ulong 0 |
| 11664 | if eq get tk 0 1 |
| 11665 | sid = findstruct get tw 0 |
| 11666 | end |
| 11667 | if ne sid 0 |
| 11668 | sa_st w sid |
| 11669 | ret |
| 11670 | end |
| 11671 | put cur 0 p |
| 11672 | put line 0 ln |
| 11673 | sa_arr w |
| 11674 | end |
| 11675 | |
| 11676 | note st_read: one value per field, saved in svk/svv/svt. An array field takes one value. |
| 11677 | fn st_read si ulong to void |
| 11678 | fo = ulong get st_foff si |
| 11679 | nfd = ulong get st_nf si |
| 11680 | i = ulong 0 |
| 11681 | while lt i nfd |
| 11682 | ft = ulong get sf_type add fo i |
| 11683 | rdval 0 ft 255 0 |
| 11684 | if ne get rt 0 ft |
| 11685 | fail 7 |
| 11686 | end |
| 11687 | put svk i get rk 0 |
| 11688 | put svv i get rv 0 |
| 11689 | put svt i get rt 0 |
| 11690 | i = add i 1 |
| 11691 | end |
| 11692 | end |
| 11693 | |
| 11694 | note st_store: STR of v at cell, scaled so the typed store lands on cell * 8. ADD is not used; the |
| 11695 | note index register holds cell << (3 - tlog). STR register-offset is the STOP table (om4). |
| 11696 | fn st_store base ulong idx ulong cell ulong t ulong v ulong to void |
| 11697 | matconst idx shl cell sub 3 tlog t |
| 11698 | put ea_b 0 base |
| 11699 | put ea_i 0 idx |
| 11700 | stel t v |
| 11701 | end |
| 11702 | |
| 11703 | note st_ixreg: runtime element index iv, field length fl, cell offset off. CMP + B.HS trap 3 |
| 11704 | note (elemaddr, C6.2.96 / C6.2.34), then ADD Xidx, Xiv, #off (C6.2.5, base word 2432696320) and |
| 11705 | note LSL by 3 - tlog (bo_lsl) so the STOP store lands on (off + i) * 8. |
| 11706 | fn st_ixreg idx ulong iv ulong off ulong fl ulong t ulong to void |
| 11707 | if ne get xtarget 0 0 |
| 11708 | xcmp iv fl 1 |
| 11709 | trapc 2 3 |
| 11710 | xarith 33 5 iv off 1 idx |
| 11711 | sh = sub 3 tlog t |
| 11712 | if ne sh 0 |
| 11713 | bo_lsl idx sh idx |
| 11714 | end |
| 11715 | ret |
| 11716 | end |
| 11717 | emit or or 4043309087 shl fl 10 shl iv 5 |
| 11718 | trapc 2 3 |
| 11719 | emit or or or 2432696320 idx shl iv 5 shl off 10 |
| 11720 | sh = sub 3 tlog t |
| 11721 | if ne sh 0 |
| 11722 | bo_lsl idx sh idx |
| 11723 | end |
| 11724 | end |
| 11725 | |
| 11726 | note st_ld: LDR of type t from base + idx into dst (or a new register). LDOP table, as vt_get. |
| 11727 | fn st_ld base ulong idx ulong t ulong dst ulong to void |
| 11728 | rd = destreg dst |
| 11729 | if ne get xtarget 0 0 |
| 11730 | xmemval 0 base idx t rd |
| 11731 | else |
| 11732 | w = or ldop t rd |
| 11733 | emit or or w shl base 5 shl idx 16 |
| 11734 | end |
| 11735 | put rk 0 1 |
| 11736 | put rv 0 rd |
| 11737 | put rt 0 t |
| 11738 | end |
| 11739 | |
| 11740 | note st_write1: store field j (value saved at sv* i) into the struct at base. |
| 11741 | fn st_write1 base ulong tmp ulong idx ulong j ulong i ulong to void |
| 11742 | ft = ulong get sf_type j |
| 11743 | fl = ulong get sf_len j |
| 11744 | off = ulong get sf_off j |
| 11745 | force get svk i get svv i get svt i tmp |
| 11746 | if eq fl 0 |
| 11747 | st_store base idx off ft tmp |
| 11748 | else |
| 11749 | k = ulong 0 |
| 11750 | while lt k fl |
| 11751 | st_store base idx add off k ft tmp |
| 11752 | k = add k 1 |
| 11753 | end |
| 11754 | end |
| 11755 | end |
| 11756 | |
| 11757 | note st_write: store each field value. An array field is filled with its one value. |
| 11758 | fn st_write base ulong tmp ulong idx ulong si ulong to void |
| 11759 | fo = ulong get st_foff si |
| 11760 | nfd = ulong get st_nf si |
| 11761 | i = ulong 0 |
| 11762 | while lt i nfd |
| 11763 | st_write1 base tmp idx add fo i i |
| 11764 | i = add i 1 |
| 11765 | end |
| 11766 | end |
| 11767 | |
| 11768 | note sa_st: p = new S v1 .. vn. Stack slot of the cell count, 16-byte aligned, outermost block only. |
| 11769 | fn sa_st w ulong sid ulong to void |
| 11770 | if ne get nb 0 0 |
| 11771 | fail 9 |
| 11772 | end |
| 11773 | si = sub sid 1 |
| 11774 | cells = ulong get st_cells si |
| 11775 | by = shl shr add shl cells 3 15 4 4 |
| 11776 | s = add get stkbytes 0 by |
| 11777 | if gt s 4194304 |
| 11778 | fail 23 |
| 11779 | end |
| 11780 | put stkbytes 0 s |
| 11781 | r = alloc |
| 11782 | put held 0 get nslot 0 |
| 11783 | st_read si |
| 11784 | spsub by |
| 11785 | stkchk |
| 11786 | if ne get xtarget 0 0 |
| 11787 | xmovsp r |
| 11788 | else |
| 11789 | emit or 2432697312 r |
| 11790 | end |
| 11791 | tmp = alloc |
| 11792 | idx = alloc |
| 11793 | st_write r tmp idx si |
| 11794 | addname w r add si 16 cells 6 0 |
| 11795 | end |
| 11796 | |
| 11797 | note ======== OM-2 section 5: abstract types (spec 5, errata E8, E9). `abstract NAME T [ops W..]` and |
| 11798 | note `holds NAME dup32` at top level before the first fn (names pass). NAME is type 64 + index: a value of |
| 11799 | note it comes only from `seal NAME v` inside the function NAMEmk returning NAME (else error 28), `open v` |
| 11800 | note gives the T value, and the listed operations (rotr/rotl with a T count, and/or/xor of two NAME |
| 11801 | note values) keep NAME; anything else on it, a T value or a number where NAME is needed, an array of it and |
| 11802 | note the entry function's parameters and result are error 7. With holds, seal checks high32 == low32 |
| 11803 | note (LSR, CMP ..., UXTW, B.NE trap 10) unless the constructor body is exactly `ret seal NAME or shl ulong |
| 11804 | note x 32 ulong x` with x a uint parameter (rule dup32: uint values are held zero-extended). om2 diag |
| 11805 | note reports each check as omc-check 1 kept|erased line=N rule=dup32|-. ======== |
| 11806 | fn findab w ulong to ulong |
| 11807 | i = ulong 0 |
| 11808 | while lt i get nab 0 |
| 11809 | if eq get ab_name i w |
| 11810 | ret add i 1 |
| 11811 | end |
| 11812 | i = add i 1 |
| 11813 | end |
| 11814 | ret 0 |
| 11815 | end |
| 11816 | |
| 11817 | note abty: the current word (not a type word) as an abstract type; anything else is error 16 |
| 11818 | fn abty to ulong |
| 11819 | a = findab get tw 0 |
| 11820 | if eq a 0 |
| 11821 | fail 16 |
| 11822 | end |
| 11823 | ret add a 63 |
| 11824 | end |
| 11825 | |
| 11826 | note opbit: the ops bit of a preserving operation (rotr rotl and or xor), else 0 |
| 11827 | fn opbit c ulong to ulong |
| 11828 | if eq c 59 |
| 11829 | ret 1 |
| 11830 | end |
| 11831 | if eq c 60 |
| 11832 | ret 2 |
| 11833 | end |
| 11834 | if eq c 38 |
| 11835 | ret 4 |
| 11836 | end |
| 11837 | if eq c 39 |
| 11838 | ret 8 |
| 11839 | end |
| 11840 | if eq c 40 |
| 11841 | ret 16 |
| 11842 | end |
| 11843 | ret 0 |
| 11844 | end |
| 11845 | |
| 11846 | note s_abstract: abstract NAME uint|ulong [ops W ..] (another type is error 7, another op word 16) |
| 11847 | fn s_abstract to void |
| 11848 | if ne get nf 0 0 |
| 11849 | fail 9 |
| 11850 | end |
| 11851 | tok |
| 11852 | if ne get tk 0 1 |
| 11853 | fail 16 |
| 11854 | end |
| 11855 | if gt get tl 0 8 |
| 11856 | fail 13 |
| 11857 | end |
| 11858 | w = get tw 0 |
| 11859 | if ne kw w 0 |
| 11860 | fail 16 |
| 11861 | end |
| 11862 | newname w get tl 0 get ts 0 |
| 11863 | n = get nab 0 |
| 11864 | if ge n 16 |
| 11865 | fail 14 |
| 11866 | end |
| 11867 | put ab_len n get tl 0 |
| 11868 | t = typeword |
| 11869 | if and ne t 4 ne t 5 |
| 11870 | fail 7 |
| 11871 | end |
| 11872 | ops = ulong 0 |
| 11873 | tok |
| 11874 | if eq get tk 0 1 |
| 11875 | if or gt get tl 0 8 ne kw get tw 0 196 |
| 11876 | fail 5 |
| 11877 | end |
| 11878 | go = true |
| 11879 | while go |
| 11880 | tok |
| 11881 | k = get tk 0 |
| 11882 | if or eq k 0 eq k 3 |
| 11883 | go = false |
| 11884 | else |
| 11885 | if or ne k 1 gt get tl 0 8 |
| 11886 | fail 16 |
| 11887 | end |
| 11888 | b = opbit kw get tw 0 |
| 11889 | if eq b 0 |
| 11890 | fail 16 |
| 11891 | end |
| 11892 | ops = or ops b |
| 11893 | end |
| 11894 | end |
| 11895 | else |
| 11896 | if and ne get tk 0 0 ne get tk 0 3 |
| 11897 | fail 5 |
| 11898 | end |
| 11899 | end |
| 11900 | put ab_name n w |
| 11901 | put ab_base n uchar t |
| 11902 | put ab_ops n ops |
| 11903 | put nab 0 add n 1 |
| 11904 | end |
| 11905 | |
| 11906 | note ab_entry: function f (index) is the entry of a function-mode unit: no abstract parameter or result |
| 11907 | fn ab_entry f ulong to void |
| 11908 | if eq get om2 0 0 |
| 11909 | ret |
| 11910 | end |
| 11911 | if ne get scanning 0 0 |
| 11912 | ret |
| 11913 | end |
| 11914 | if ne get progmode 0 0 |
| 11915 | ret |
| 11916 | end |
| 11917 | if ne get nexp 0 0 |
| 11918 | if eq get fn_exp f 0 |
| 11919 | ret |
| 11920 | end |
| 11921 | else |
| 11922 | if ne add f 1 get nf 0 |
| 11923 | ret |
| 11924 | end |
| 11925 | end |
| 11926 | if ge get fn_ret f 64 |
| 11927 | fail 7 |
| 11928 | end |
| 11929 | i = ulong 0 |
| 11930 | while lt i ulong get fn_np f |
| 11931 | if ge get fn_pt add mul f 6 i 64 |
| 11932 | fail 7 |
| 11933 | end |
| 11934 | i = add i 1 |
| 11935 | end |
| 11936 | end |
| 11937 | |
| 11938 | note ab_open: open v (the value read): an abstract value becomes its representation type |
| 11939 | fn ab_open to void |
| 11940 | t = get rt 0 |
| 11941 | if lt t 64 |
| 11942 | fail 7 |
| 11943 | end |
| 11944 | put rt 0 ulong get ab_base sub t 64 |
| 11945 | end |
| 11946 | |
| 11947 | note ab_seal: seal NAME v, only in the function NAMEmk (inlined or not) returning NAME (else error 28) |
| 11948 | fn ab_seal to void |
| 11949 | tok |
| 11950 | if or eq get tk 0 0 eq get tk 0 3 |
| 11951 | fail 4 |
| 11952 | end |
| 11953 | a = ulong 0 |
| 11954 | if and eq get tk 0 1 le get tl 0 8 |
| 11955 | a = findab get tw 0 |
| 11956 | end |
| 11957 | if eq a 0 |
| 11958 | fail 16 |
| 11959 | end |
| 11960 | a = sub a 1 |
| 11961 | fe = get curfn 0 |
| 11962 | if ne get inl 0 0 |
| 11963 | fe = get il_fn sub get inl 0 1 |
| 11964 | end |
| 11965 | if eq ab_ctor fe a 0 |
| 11966 | fail 28 |
| 11967 | end |
| 11968 | t = ulong get ab_base a |
| 11969 | rdval 0 t 255 0 |
| 11970 | if ne get rt 0 t |
| 11971 | fail 7 |
| 11972 | end |
| 11973 | r = matreg get rk 0 get rv 0 get rt 0 |
| 11974 | if ne get ab_holds a 0 |
| 11975 | ab_check fe a r |
| 11976 | end |
| 11977 | put rk 0 1 |
| 11978 | put rv 0 r |
| 11979 | put rt 0 add a 64 |
| 11980 | end |
| 11981 | |
| 11982 | note ab_ctor: 1 when function fe (index + 1) is NAMEmk for abstract a and returns it |
| 11983 | fn ab_ctor fe ulong a ulong to ulong |
| 11984 | if eq fe 0 |
| 11985 | ret 0 |
| 11986 | end |
| 11987 | f = sub fe 1 |
| 11988 | if ne ulong get fn_ret f add a 64 |
| 11989 | ret 0 |
| 11990 | end |
| 11991 | l = get ab_len a |
| 11992 | if ne get fn_nmlen f add l 2 |
| 11993 | ret 0 |
| 11994 | end |
| 11995 | o = get fn_off f |
| 11996 | w = get ab_name a |
| 11997 | i = ulong 0 |
| 11998 | while lt i l |
| 11999 | if ne ulong get inp add o i and shr w shl i 3 255 |
| 12000 | ret 0 |
| 12001 | end |
| 12002 | i = add i 1 |
| 12003 | end |
| 12004 | if ne get inp add o l 109 |
| 12005 | ret 0 |
| 12006 | end |
| 12007 | if ne get inp add add o l 1 107 |
| 12008 | ret 0 |
| 12009 | end |
| 12010 | ret 1 |
| 12011 | end |
| 12012 | |
| 12013 | note ab_check: the dup32 check of a seal (value in r): erased for the exact body, else LSR Xt, Xr, #32 |
| 12014 | note (UBFM, C6.2.487); CMP Xt, Wr, UXTW (SUBS extended, C6.2.463); B.NE trap 10 |
| 12015 | fn ab_check fe ulong a ulong r ulong to void |
| 12016 | ex = ab_exact fe a |
| 12017 | if eq get om2m 0 1 |
| 12018 | note ab_rec: omc-check 1 kept|erased line=N rule=dup32|- (om2 diag, with the omc-site records) |
| 12019 | sitew 7162245557575183727 8 |
| 12020 | sitew 540090475 4 |
| 12021 | if ne ex 0 |
| 12022 | sitew 110386890240613 6 |
| 12023 | else |
| 12024 | sitew 1953523051 4 |
| 12025 | end |
| 12026 | sitew 67505853393952 6 |
| 12027 | siten add get line 0 get lbase 0 |
| 12028 | sitew 67505820627488 6 |
| 12029 | if ne ex 0 |
| 12030 | sitew 215611372900 5 |
| 12031 | else |
| 12032 | siteb 45 |
| 12033 | end |
| 12034 | siteb 10 |
| 12035 | end |
| 12036 | if eq ex 0 |
| 12037 | t = alloc |
| 12038 | if ne get xtarget 0 0 |
| 12039 | xload 0 r |
| 12040 | xload 1 r |
| 12041 | emitb 137 |
| 12042 | emitb 192 |
| 12043 | xb 72 193 233 |
| 12044 | emitb 32 |
| 12045 | xrr 57 0 1 |
| 12046 | xtrap 1 10 |
| 12047 | else |
| 12048 | emit or or 3546348544 t shl r 5 |
| 12049 | emit or or 3944759327 shl r 16 shl t 5 |
| 12050 | trapc 1 10 |
| 12051 | end |
| 12052 | end |
| 12053 | end |
| 12054 | |
| 12055 | note aw_next: the next word of the input from aw_p (blanks skipped, newlines counted in aw_nl) |
| 12056 | fn aw_next to void |
| 12057 | p = get aw_p 0 |
| 12058 | e = get inlen 0 |
| 12059 | nl = ulong 0 |
| 12060 | go = true |
| 12061 | while and go lt p e |
| 12062 | b = get inp p |
| 12063 | if or eq b 32 eq b 9 |
| 12064 | p = add p 1 |
| 12065 | else |
| 12066 | if eq b 10 |
| 12067 | nl = add nl 1 |
| 12068 | p = add p 1 |
| 12069 | else |
| 12070 | go = false |
| 12071 | end |
| 12072 | end |
| 12073 | end |
| 12074 | w = ulong 0 |
| 12075 | l = ulong 0 |
| 12076 | go2 = true |
| 12077 | while and go2 lt p e |
| 12078 | c = get inp p |
| 12079 | if or or eq c 32 eq c 9 eq c 10 |
| 12080 | go2 = false |
| 12081 | else |
| 12082 | if lt l 8 |
| 12083 | w = or w shl ulong c shl l 3 |
| 12084 | end |
| 12085 | l = add l 1 |
| 12086 | p = add p 1 |
| 12087 | end |
| 12088 | end |
| 12089 | put aw_p 0 p |
| 12090 | put aw_w 0 w |
| 12091 | put aw_l 0 l |
| 12092 | put aw_nl 0 nl |
| 12093 | end |
| 12094 | |
| 12095 | note aw_is: the next word is w (length l) after exactly nl newlines |
| 12096 | fn aw_is w ulong l ulong nl ulong to ulong |
| 12097 | aw_next |
| 12098 | if ne get aw_w 0 w |
| 12099 | ret 0 |
| 12100 | end |
| 12101 | if ne get aw_l 0 l |
| 12102 | ret 0 |
| 12103 | end |
| 12104 | if ne get aw_nl 0 nl |
| 12105 | ret 0 |
| 12106 | end |
| 12107 | ret 1 |
| 12108 | end |
| 12109 | |
| 12110 | note ab_upar: x (length xl) is a uint scalar parameter of function f (index) |
| 12111 | fn ab_upar f ulong x ulong xl ulong to ulong |
| 12112 | if gt xl 8 |
| 12113 | ret 0 |
| 12114 | end |
| 12115 | i = ulong 0 |
| 12116 | while lt i ulong get fn_np f |
| 12117 | p = add mul f 6 i |
| 12118 | if eq get fn_pn p x |
| 12119 | if eq get fn_pk p 0 |
| 12120 | if eq get fn_pt p 4 |
| 12121 | ret 1 |
| 12122 | end |
| 12123 | end |
| 12124 | end |
| 12125 | i = add i 1 |
| 12126 | end |
| 12127 | ret 0 |
| 12128 | end |
| 12129 | |
| 12130 | note ab_exact: the body of constructor fe is exactly `ret seal NAME or shl ulong x 32 ulong x` then `end` |
| 12131 | fn ab_exact fe ulong a ulong to ulong |
| 12132 | f = sub fe 1 |
| 12133 | put aw_p 0 get fn_body f |
| 12134 | if eq aw_is 7628146 3 0 0 |
| 12135 | ret 0 |
| 12136 | end |
| 12137 | if eq aw_is 1818322291 4 0 0 |
| 12138 | ret 0 |
| 12139 | end |
| 12140 | if eq aw_is get ab_name a get ab_len a 0 0 |
| 12141 | ret 0 |
| 12142 | end |
| 12143 | if eq aw_is 29295 2 0 0 |
| 12144 | ret 0 |
| 12145 | end |
| 12146 | if eq aw_is 7104627 3 0 0 |
| 12147 | ret 0 |
| 12148 | end |
| 12149 | if eq aw_is 444234427509 5 0 0 |
| 12150 | ret 0 |
| 12151 | end |
| 12152 | aw_next |
| 12153 | if ne get aw_nl 0 0 |
| 12154 | ret 0 |
| 12155 | end |
| 12156 | x = get aw_w 0 |
| 12157 | xl = get aw_l 0 |
| 12158 | if eq ab_upar f x xl 0 |
| 12159 | ret 0 |
| 12160 | end |
| 12161 | if eq aw_is 12851 2 0 0 |
| 12162 | ret 0 |
| 12163 | end |
| 12164 | if eq aw_is 444234427509 5 0 0 |
| 12165 | ret 0 |
| 12166 | end |
| 12167 | if eq aw_is x xl 0 0 |
| 12168 | ret 0 |
| 12169 | end |
| 12170 | if eq aw_is 6581861 3 1 0 |
| 12171 | ret 0 |
| 12172 | end |
| 12173 | aw_next |
| 12174 | if and ne get aw_l 0 0 eq get aw_nl 0 0 |
| 12175 | ret 0 |
| 12176 | end |
| 12177 | ret 1 |
| 12178 | end |
| 12179 | |
| 12180 | note ab_bin: a binary operation whose operand (fr[x..x+5]) is abstract: only a listed preserving one, run |
| 12181 | note on the representation type T and giving NAME; rotr/rotl take a T count (E9), and/or/xor two NAME values |
| 12182 | fn ab_bin c ulong dst ulong x ulong to void |
| 12183 | at = get fr add x 2 |
| 12184 | if lt at 64 |
| 12185 | fail 7 |
| 12186 | end |
| 12187 | a = sub at 64 |
| 12188 | b = opbit c |
| 12189 | if eq b 0 |
| 12190 | fail 7 |
| 12191 | end |
| 12192 | if eq and get ab_ops a b 0 |
| 12193 | fail 7 |
| 12194 | end |
| 12195 | t = ulong get ab_base a |
| 12196 | bk = get fr add x 3 |
| 12197 | bt = get fr add x 5 |
| 12198 | if or eq c 59 eq c 60 |
| 12199 | if eq bk 2 |
| 12200 | range get fr add x 4 t bt |
| 12201 | put fr add x 3 3 |
| 12202 | else |
| 12203 | if ne bt t |
| 12204 | fail 7 |
| 12205 | end |
| 12206 | end |
| 12207 | else |
| 12208 | if ne bt at |
| 12209 | fail 7 |
| 12210 | end |
| 12211 | end |
| 12212 | put fr add x 2 t |
| 12213 | put fr add x 5 t |
| 12214 | binop c dst x |
| 12215 | put rt 0 at |
| 12216 | end |
| 12217 | |
| 12218 | note ======== OM-2 section 5: fresh scratch (spec 5, erratum E8). `NAME edit T N fresh` (N <= 64): the |
| 12219 | note incoming elements are unspecified. Each such array has a written set (bit i: element i definitely |
| 12220 | note written on the path being compiled). A put with a number index (after unrolling and inlining) sets |
| 12221 | note its bit; a get with a number index needs its bit, any other get all N bits (else error 27, |
| 12222 | note obligation=init). Joins: an if without else, a while and a rolled for keep the set they opened with; |
| 12223 | note an if/else takes the intersection of its arms (or the arm that does not end in ret); an unrolled |
| 12224 | note body and an inlined body keep what they wrote. Passing the array to a non-inline call, read, write or |
| 12225 | note a host operation is error 27; an inline callee works on the same set. ======== |
| 12226 | note fz_par: parameter slot f*6+np of kind k with N = ln is fresh: an edit only (else 16), N <= 64 (else 14) |
| 12227 | fn fz_par f ulong np ulong k ulong ln ulong to void |
| 12228 | if ne k 3 |
| 12229 | fail 16 |
| 12230 | end |
| 12231 | if gt ln 64 |
| 12232 | put dobx 0 1 |
| 12233 | fail 14 |
| 12234 | end |
| 12235 | put fn_pfr add mul f 6 np 1 |
| 12236 | end |
| 12237 | |
| 12238 | note fz_bind: the parameter name just added for slot p gets a new written set in the body pass |
| 12239 | fn fz_bind p ulong ln ulong to void |
| 12240 | if eq get fn_pfr p 0 |
| 12241 | ret |
| 12242 | end |
| 12243 | if ne get scanning 0 0 |
| 12244 | ret |
| 12245 | end |
| 12246 | fz_new sub get nn 0 1 ln |
| 12247 | end |
| 12248 | |
| 12249 | note fz_new: a new, empty written set of N elements for name index n (16 per function, error 14) |
| 12250 | fn fz_new n ulong ln ulong to void |
| 12251 | s = get fz_n 0 |
| 12252 | if ge s 16 |
| 12253 | put dobx 0 1 |
| 12254 | fail 14 |
| 12255 | end |
| 12256 | put fz_len s ln |
| 12257 | put fz_cur s 0 |
| 12258 | put nm_fr n uchar add s 1 |
| 12259 | put fz_n 0 add s 1 |
| 12260 | end |
| 12261 | |
| 12262 | note fz_inl: an inline parameter slot p bound to array name e: its own fresh set, or e's set |
| 12263 | fn fz_inl p ulong e ulong to void |
| 12264 | pk = ulong get fn_pk p |
| 12265 | if or eq pk 0 ge pk 6 |
| 12266 | ret |
| 12267 | end |
| 12268 | n = sub get nn 0 1 |
| 12269 | if ne get fn_pfr p 0 |
| 12270 | fz_new n get fn_pl p |
| 12271 | ret |
| 12272 | end |
| 12273 | put nm_fr n get nm_fr sub e 1 |
| 12274 | end |
| 12275 | |
| 12276 | fn fz_else i ulong to void |
| 12277 | j = ulong 0 |
| 12278 | while lt j get fz_n 0 |
| 12279 | x = add mul i 16 j |
| 12280 | put fz_thn x get fz_cur j |
| 12281 | put fz_cur j get fz_ent x |
| 12282 | j = add j 1 |
| 12283 | end |
| 12284 | end |
| 12285 | |
| 12286 | fn fz_join i ulong k ulong to void |
| 12287 | td = get bdead i |
| 12288 | ed = get dead 0 |
| 12289 | j = ulong 0 |
| 12290 | while lt j get fz_n 0 |
| 12291 | x = add mul i 16 j |
| 12292 | if eq k 2 |
| 12293 | v = and get fz_cur j get fz_thn x |
| 12294 | if and ne td 0 eq ed 0 |
| 12295 | v = get fz_cur j |
| 12296 | end |
| 12297 | if and ne ed 0 eq td 0 |
| 12298 | v = get fz_thn x |
| 12299 | end |
| 12300 | put fz_cur j v |
| 12301 | else |
| 12302 | put fz_cur j get fz_ent x |
| 12303 | end |
| 12304 | j = add j 1 |
| 12305 | end |
| 12306 | end |
| 12307 | |
| 12308 | note fz_get: get e i with the index in rk/rv/rt |
| 12309 | fn fz_get e ulong to void |
| 12310 | if ne get cvalid 0 0 |
| 12311 | ret |
| 12312 | end |
| 12313 | s = ulong get nm_fr sub e 1 |
| 12314 | if eq s 0 |
| 12315 | ret |
| 12316 | end |
| 12317 | s = sub s 1 |
| 12318 | n = get fz_len s |
| 12319 | if eq get rk 0 3 |
| 12320 | v = get rv 0 |
| 12321 | if lt v n |
| 12322 | if eq and shr get fz_cur s v 1 0 |
| 12323 | fail 27 |
| 12324 | end |
| 12325 | end |
| 12326 | ret |
| 12327 | end |
| 12328 | if ne get fz_cur s fmask n |
| 12329 | fail 27 |
| 12330 | end |
| 12331 | end |
| 12332 | |
| 12333 | note fz_put: put e i v with index (k, v): a number index sets its bit |
| 12334 | fn fz_put e ulong k ulong v ulong to void |
| 12335 | s = ulong get nm_fr sub e 1 |
| 12336 | if eq s 0 |
| 12337 | ret |
| 12338 | end |
| 12339 | s = sub s 1 |
| 12340 | if eq k 3 |
| 12341 | if lt v get fz_len s |
| 12342 | put fz_cur s or get fz_cur s shl ulong 1 v |
| 12343 | end |
| 12344 | end |
| 12345 | end |
| 12346 | |
| 12347 | note fz_arg: array name e leaves the analysis (a non-inline call, read, write, a host operation): error 27 |
| 12348 | note when it is tracked |
| 12349 | fn fz_arg e ulong to void |
| 12350 | if ne get nm_fr sub e 1 0 |
| 12351 | fail 27 |
| 12352 | end |
| 12353 | end |
| 12354 | |
| 12355 | note ======== OM-2 section 5: external layouts (spec 5, errata E5, E8, E9). `layout NAME SIZE`, then one |
| 12356 | note `field F T [COUNT] at OFF little|big` per line, then `end`, before the first fn. Read in the names pass; |
| 12357 | note the body pass jumps over the block. A parameter `c view|edit NAME` is a uchar array of SIZE bytes (one |
| 12358 | note pointer); `get c F [i]` / `put c F [i] v` load / store the field at its width and byte order: |
| 12359 | note LDR/STR (register, unscaled offset; C6.2.216 family) at base + OFF + i * width, REV16 / REV (C6.2.333, |
| 12360 | note C6.2.331) for big, a run-time index checked like an array's (CMP, B.HS trap 3) ======== |
| 12361 | note findlay: packed name -> layout index + 1, or 0 |
| 12362 | fn findlay w ulong to ulong |
| 12363 | i = ulong 0 |
| 12364 | while lt i get nly 0 |
| 12365 | if eq get ly_name i w |
| 12366 | ret add i 1 |
| 12367 | end |
| 12368 | i = add i 1 |
| 12369 | end |
| 12370 | ret 0 |
| 12371 | end |
| 12372 | |
| 12373 | note findlf: layout index li, packed field name -> field-table index + 1, or 0 |
| 12374 | fn findlf li ulong w ulong to ulong |
| 12375 | fo = get ly_fo li |
| 12376 | i = ulong 0 |
| 12377 | while lt i get ly_nf li |
| 12378 | if eq get lf_name add fo i w |
| 12379 | ret add add fo i 1 |
| 12380 | end |
| 12381 | i = add i 1 |
| 12382 | end |
| 12383 | ret 0 |
| 12384 | end |
| 12385 | |
| 12386 | note ns_om2: an OM-2 declaration line in the names pass (1 when it was read), else 0 |
| 12387 | fn ns_om2 to ulong |
| 12388 | if eq get om2 0 0 |
| 12389 | ret 0 |
| 12390 | end |
| 12391 | if ne get tk 0 1 |
| 12392 | ret 0 |
| 12393 | end |
| 12394 | if gt get tl 0 8 |
| 12395 | ret 0 |
| 12396 | end |
| 12397 | if eq get tw 0 128047730221420 |
| 12398 | s_layout |
| 12399 | ret 1 |
| 12400 | end |
| 12401 | if eq get tw 0 8386654075301880417 |
| 12402 | s_abstract |
| 12403 | ret 1 |
| 12404 | end |
| 12405 | if eq get tw 0 495606067048 |
| 12406 | note s_holds: holds NAME dup32 (ulong representation only); any other predicate is error 28 on this line |
| 12407 | if ne get nf 0 0 |
| 12408 | fail 9 |
| 12409 | end |
| 12410 | tok |
| 12411 | if ne get tk 0 1 |
| 12412 | fail 16 |
| 12413 | end |
| 12414 | a = ulong 0 |
| 12415 | if le get tl 0 8 |
| 12416 | a = findab get tw 0 |
| 12417 | end |
| 12418 | if eq a 0 |
| 12419 | fail 16 |
| 12420 | end |
| 12421 | a = sub a 1 |
| 12422 | tok |
| 12423 | if or eq get tk 0 0 eq get tk 0 3 |
| 12424 | fail 4 |
| 12425 | end |
| 12426 | if ne get tk 0 1 |
| 12427 | fail 28 |
| 12428 | end |
| 12429 | if or ne get tl 0 5 ne get tw 0 215611372900 |
| 12430 | fail 28 |
| 12431 | end |
| 12432 | if ne get ab_base a 5 |
| 12433 | fail 28 |
| 12434 | end |
| 12435 | if ne get ab_holds a 0 |
| 12436 | fail 10 |
| 12437 | end |
| 12438 | put ab_holds a 1 |
| 12439 | eol |
| 12440 | ret 1 |
| 12441 | end |
| 12442 | if eq get tw 0 128034844735589 |
| 12443 | s_export |
| 12444 | ret 1 |
| 12445 | end |
| 12446 | ret 0 |
| 12447 | end |
| 12448 | |
| 12449 | note s_export (OM-2, spec 6): `export fn ...` at top level: the fn line of an exported entry, in both |
| 12450 | note passes. Function mode only (error 9), at most 32 (error 14), counted and marked in the names pass. |
| 12451 | fn s_export to void |
| 12452 | tok |
| 12453 | if or ne get tk 0 1 ne get tw 0 28262 |
| 12454 | fail 16 |
| 12455 | end |
| 12456 | if eq get scanning 0 1 |
| 12457 | if ne get progmode 0 0 |
| 12458 | fail 9 |
| 12459 | end |
| 12460 | if ge get nexp 0 32 |
| 12461 | fail 14 |
| 12462 | end |
| 12463 | put nexp 0 add get nexp 0 1 |
| 12464 | end |
| 12465 | put expf 0 1 |
| 12466 | s_fn |
| 12467 | put expf 0 0 |
| 12468 | end |
| 12469 | |
| 12470 | note ly_num: the next token must be a number (error 4 at the line end, 16 for another token, 29 when it |
| 12471 | note was written as 2^63 or more) |
| 12472 | fn ly_num to ulong |
| 12473 | tok |
| 12474 | if or eq get tk 0 0 eq get tk 0 3 |
| 12475 | fail 4 |
| 12476 | end |
| 12477 | if ne get tk 0 2 |
| 12478 | fail 16 |
| 12479 | end |
| 12480 | if ne get tbig 0 0 |
| 12481 | fail 29 |
| 12482 | end |
| 12483 | ret get tw 0 |
| 12484 | end |
| 12485 | |
| 12486 | note s_layout: SIZE 1..4096 and a layout after the first fn are error 29 on the layout line |
| 12487 | fn s_layout to void |
| 12488 | if ne get nf 0 0 |
| 12489 | fail 29 |
| 12490 | end |
| 12491 | tok |
| 12492 | if ne get tk 0 1 |
| 12493 | fail 16 |
| 12494 | end |
| 12495 | if gt get tl 0 8 |
| 12496 | fail 13 |
| 12497 | end |
| 12498 | w = get tw 0 |
| 12499 | if ne kw w 0 |
| 12500 | fail 16 |
| 12501 | end |
| 12502 | newname w get tl 0 get ts 0 |
| 12503 | if ge get nly 0 16 |
| 12504 | fail 14 |
| 12505 | end |
| 12506 | sz = ly_num |
| 12507 | if or eq sz 0 gt sz 4096 |
| 12508 | fail 29 |
| 12509 | end |
| 12510 | eol |
| 12511 | li = get nly 0 |
| 12512 | fo = get nlf 0 |
| 12513 | i = ulong 0 |
| 12514 | while lt i sz |
| 12515 | put lymap i 0 |
| 12516 | i = add i 1 |
| 12517 | end |
| 12518 | go = true |
| 12519 | while go |
| 12520 | tok |
| 12521 | k = get tk 0 |
| 12522 | if eq k 3 |
| 12523 | fail 4 |
| 12524 | end |
| 12525 | if eq k 1 |
| 12526 | c = ulong 0 |
| 12527 | if le get tl 0 8 |
| 12528 | c = kw get tw 0 |
| 12529 | end |
| 12530 | if eq c 66 |
| 12531 | eol |
| 12532 | go = false |
| 12533 | else |
| 12534 | if eq c 83 |
| 12535 | skipnl |
| 12536 | else |
| 12537 | if ne c 189 |
| 12538 | fail 16 |
| 12539 | end |
| 12540 | ly_field fo sz |
| 12541 | end |
| 12542 | end |
| 12543 | else |
| 12544 | if ne k 0 |
| 12545 | fail 16 |
| 12546 | end |
| 12547 | end |
| 12548 | end |
| 12549 | put ly_name li w |
| 12550 | put ly_size li sz |
| 12551 | put ly_fo li fo |
| 12552 | put ly_nf li sub get nlf 0 fo |
| 12553 | put ly_ec li get cur 0 |
| 12554 | put ly_el li get line 0 |
| 12555 | put nly 0 add li 1 |
| 12556 | end |
| 12557 | |
| 12558 | note ly_field: F T [COUNT] at OFF little|big. A field over SIZE, a COUNT outside 1..4096, an OFF out of range |
| 12559 | note or two fields sharing a byte are error 29 on the field line. Field types are the integer types. |
| 12560 | fn ly_field fo ulong sz ulong to void |
| 12561 | tok |
| 12562 | if or eq get tk 0 0 eq get tk 0 3 |
| 12563 | fail 4 |
| 12564 | end |
| 12565 | if ne get tk 0 1 |
| 12566 | fail 16 |
| 12567 | end |
| 12568 | if gt get tl 0 8 |
| 12569 | fail 13 |
| 12570 | end |
| 12571 | fw = get tw 0 |
| 12572 | if ne kw fw 0 |
| 12573 | fail 16 |
| 12574 | end |
| 12575 | n = get nlf 0 |
| 12576 | i = fo |
| 12577 | while lt i n |
| 12578 | if eq get lf_name i fw |
| 12579 | fail 10 |
| 12580 | end |
| 12581 | i = add i 1 |
| 12582 | end |
| 12583 | if ge n 256 |
| 12584 | fail 14 |
| 12585 | end |
| 12586 | t = typeword |
| 12587 | if or lt t 2 gt t 9 |
| 12588 | fail 7 |
| 12589 | end |
| 12590 | cnt = ulong 0 |
| 12591 | tok |
| 12592 | if eq get tk 0 2 |
| 12593 | if ne get tbig 0 0 |
| 12594 | fail 29 |
| 12595 | end |
| 12596 | cnt = get tw 0 |
| 12597 | if or eq cnt 0 gt cnt 4096 |
| 12598 | fail 29 |
| 12599 | end |
| 12600 | tok |
| 12601 | end |
| 12602 | if or eq get tk 0 0 eq get tk 0 3 |
| 12603 | fail 4 |
| 12604 | end |
| 12605 | if ne get tk 0 1 |
| 12606 | fail 16 |
| 12607 | end |
| 12608 | if ne kw get tw 0 190 |
| 12609 | fail 16 |
| 12610 | end |
| 12611 | off = ly_num |
| 12612 | big = ly_end |
| 12613 | ly_mark off cnt t sz |
| 12614 | eol |
| 12615 | put lf_name n fw |
| 12616 | put lf_type n uchar t |
| 12617 | put lf_cnt n cnt |
| 12618 | put lf_off n off |
| 12619 | put lf_big n uchar big |
| 12620 | put nlf 0 add n 1 |
| 12621 | end |
| 12622 | |
| 12623 | note ly_end: little (0) or big (1) |
| 12624 | fn ly_end to ulong |
| 12625 | tok |
| 12626 | if or eq get tk 0 0 eq get tk 0 3 |
| 12627 | fail 4 |
| 12628 | end |
| 12629 | if ne get tk 0 1 |
| 12630 | fail 16 |
| 12631 | end |
| 12632 | c = kw get tw 0 |
| 12633 | if eq c 191 |
| 12634 | ret 0 |
| 12635 | end |
| 12636 | if eq c 192 |
| 12637 | ret 1 |
| 12638 | end |
| 12639 | fail 16 |
| 12640 | ret 0 |
| 12641 | end |
| 12642 | |
| 12643 | note ly_mark: the bytes OFF .. OFF + max(COUNT, 1) * width must lie inside SIZE and be free (error 29) |
| 12644 | fn ly_mark off ulong cnt ulong t ulong sz ulong to void |
| 12645 | n = cnt |
| 12646 | if eq n 0 |
| 12647 | n = ulong 1 |
| 12648 | end |
| 12649 | by = shl n tlog t |
| 12650 | if gt off sz |
| 12651 | fail 29 |
| 12652 | end |
| 12653 | e = add off by |
| 12654 | if gt e sz |
| 12655 | fail 29 |
| 12656 | end |
| 12657 | i = off |
| 12658 | while lt i e |
| 12659 | if ne get lymap i 0 |
| 12660 | fail 29 |
| 12661 | end |
| 12662 | put lymap i 1 |
| 12663 | i = add i 1 |
| 12664 | end |
| 12665 | end |
| 12666 | |
| 12667 | note peek_lay: if the next word is a layout name, consume it and return index + 1; else rewind |
| 12668 | fn peek_lay to ulong |
| 12669 | p = get cur 0 |
| 12670 | ln = get line 0 |
| 12671 | tok |
| 12672 | if eq get tk 0 1 |
| 12673 | if le get tl 0 8 |
| 12674 | lid = findlay get tw 0 |
| 12675 | if ne lid 0 |
| 12676 | ret lid |
| 12677 | end |
| 12678 | end |
| 12679 | end |
| 12680 | put cur 0 p |
| 12681 | put line 0 ln |
| 12682 | ret 0 |
| 12683 | end |
| 12684 | |
| 12685 | note fn_p_ly: parameter pw is a layout (view k 2 / edit k 3): a uchar array of SIZE bytes, name kind 2 / 3 |
| 12686 | fn fn_p_ly f ulong np ulong pw ulong lid ulong k ulong to void |
| 12687 | ln = get ly_size sub lid 1 |
| 12688 | addname pw poolc get psl 0 2 ln k 0 |
| 12689 | put nm_lay sub get nn 0 1 uchar lid |
| 12690 | p = add mul f 6 np |
| 12691 | put fn_pt p 2 |
| 12692 | put fn_pl p ln |
| 12693 | put fn_pk p uchar k |
| 12694 | put fn_play p uchar lid |
| 12695 | end |
| 12696 | |
| 12697 | note ly_fld: for a layout name e, when the next word is one of its fields: consume it, return the field-table |
| 12698 | note index + 1; otherwise rewind and return 0 (the name is then an ordinary uchar array) |
| 12699 | fn ly_fld e ulong to ulong |
| 12700 | lid = ulong get nm_lay sub e 1 |
| 12701 | if eq lid 0 |
| 12702 | ret 0 |
| 12703 | end |
| 12704 | p = get cur 0 |
| 12705 | ln = get line 0 |
| 12706 | tok |
| 12707 | if eq get tk 0 1 |
| 12708 | if le get tl 0 8 |
| 12709 | j = findlf sub lid 1 get tw 0 |
| 12710 | if ne j 0 |
| 12711 | ret j |
| 12712 | end |
| 12713 | end |
| 12714 | end |
| 12715 | put cur 0 p |
| 12716 | put line 0 ln |
| 12717 | ret 0 |
| 12718 | end |
| 12719 | |
| 12720 | note ldun / stun: LDRB / LDRH / LDR w / LDR x and the stores, register offset, LSL #0 (S = 0) |
| 12721 | fn ldun t ulong to ulong |
| 12722 | if or eq t 2 eq t 6 |
| 12723 | ret 945842176 |
| 12724 | end |
| 12725 | if or eq t 3 eq t 7 |
| 12726 | ret 2019584000 |
| 12727 | end |
| 12728 | if or eq t 4 eq t 8 |
| 12729 | ret 3093325824 |
| 12730 | end |
| 12731 | ret 4167067648 |
| 12732 | end |
| 12733 | |
| 12734 | fn stun t ulong to ulong |
| 12735 | if or eq t 2 eq t 6 |
| 12736 | ret 941647872 |
| 12737 | end |
| 12738 | if or eq t 3 eq t 7 |
| 12739 | ret 2015389696 |
| 12740 | end |
| 12741 | if or eq t 4 eq t 8 |
| 12742 | ret 3089131520 |
| 12743 | end |
| 12744 | ret 4162873344 |
| 12745 | end |
| 12746 | |
| 12747 | note ly_rev: Rd = the bytes of Rs reversed at width t: REV16 Wd (C6.2.333), REV Wd, REV Xd (C6.2.331) |
| 12748 | fn ly_rev t ulong s ulong d ulong to void |
| 12749 | if ne get xtarget 0 0 |
| 12750 | xload 0 s |
| 12751 | if or eq t 2 eq t 6 |
| 12752 | xstore 0 d |
| 12753 | ret |
| 12754 | end |
| 12755 | if or eq t 3 eq t 7 |
| 12756 | emitb 102 |
| 12757 | xb 193 200 8 |
| 12758 | else |
| 12759 | if or eq t 5 eq t 9 |
| 12760 | emitb 72 |
| 12761 | end |
| 12762 | emitb 15 |
| 12763 | emitb 200 |
| 12764 | end |
| 12765 | xstore 0 d |
| 12766 | ret |
| 12767 | end |
| 12768 | if or eq t 3 eq t 7 |
| 12769 | emit or or 1522533376 d shl s 5 |
| 12770 | end |
| 12771 | if or eq t 4 eq t 8 |
| 12772 | emit or or 1522534400 d shl s 5 |
| 12773 | end |
| 12774 | if or eq t 5 eq t 9 |
| 12775 | emit or or 3670019072 d shl s 5 |
| 12776 | end |
| 12777 | end |
| 12778 | |
| 12779 | note ly_ix: the byte-offset register of element (k, v, t) of array field j: a number index must be below |
| 12780 | note COUNT (error 21); a register index: CMP Xi, #COUNT or Xc (C6.2.96 / C6.2.97), B.HS trap 3, then |
| 12781 | note Xo = OFF; ADD Xo, Xo, Xi, LSL #log2 width (C6.2.6) |
| 12782 | fn ly_ix j ulong k ulong v ulong t ulong to ulong |
| 12783 | if or eq t 1 ge t 10 |
| 12784 | fail 7 |
| 12785 | end |
| 12786 | cnt = get lf_cnt j |
| 12787 | sh = tlog ulong get lf_type j |
| 12788 | x = alloc |
| 12789 | if eq k 3 |
| 12790 | if ge v cnt |
| 12791 | fail 21 |
| 12792 | end |
| 12793 | matconst x add get lf_off j shl v sh |
| 12794 | ret x |
| 12795 | end |
| 12796 | r = matreg k v t |
| 12797 | if ne get xtarget 0 0 |
| 12798 | xcmp r cnt 1 |
| 12799 | xtrap 2 3 |
| 12800 | xload 0 r |
| 12801 | xb 72 193 224 |
| 12802 | emitb uchar sh |
| 12803 | ximm 1 get lf_off j |
| 12804 | xrr 1 0 1 |
| 12805 | xstore 0 x |
| 12806 | ret x |
| 12807 | end |
| 12808 | if le cnt 4095 |
| 12809 | emit or or 4043309087 shl cnt 10 shl r 5 |
| 12810 | else |
| 12811 | y = alloc |
| 12812 | matconst y cnt |
| 12813 | emit or or 3942645791 shl y 16 shl r 5 |
| 12814 | end |
| 12815 | trapc 2 3 |
| 12816 | matconst x get lf_off j |
| 12817 | emit or or or or 2332033024 x shl x 5 shl r 16 shl sh 10 |
| 12818 | ret x |
| 12819 | end |
| 12820 | |
| 12821 | note ly_get: get c F [i] on a layout name e (1 when it was a field, the value in rk/rv/rt), else 0 |
| 12822 | fn ly_get e ulong dst ulong to ulong |
| 12823 | j = ly_fld e |
| 12824 | if eq j 0 |
| 12825 | ret 0 |
| 12826 | end |
| 12827 | j = sub j 1 |
| 12828 | ft = ulong get lf_type j |
| 12829 | x = ulong 0 |
| 12830 | if eq get lf_cnt j 0 |
| 12831 | x = alloc |
| 12832 | matconst x get lf_off j |
| 12833 | else |
| 12834 | rdval 0 5 255 0 |
| 12835 | x = ly_ix j get rk 0 get rv 0 get rt 0 |
| 12836 | end |
| 12837 | rd = destreg dst |
| 12838 | if ne get xtarget 0 0 |
| 12839 | xlayout 0 ulong get nm_reg sub e 1 x ft rd |
| 12840 | else |
| 12841 | emit or or or ldun ft rd shl ulong get nm_reg sub e 1 5 shl x 16 |
| 12842 | end |
| 12843 | if ne get lf_big j 0 |
| 12844 | ly_rev ft rd rd |
| 12845 | end |
| 12846 | if gt ft 5 |
| 12847 | canon rd ft |
| 12848 | end |
| 12849 | put rk 0 1 |
| 12850 | put rv 0 rd |
| 12851 | put rt 0 ft |
| 12852 | ret 1 |
| 12853 | end |
| 12854 | |
| 12855 | note ly_put: put c F [i] v on a layout name e (an edit; a view was refused 20 before): index, value, then |
| 12856 | note the store; 1 when it was a field, else 0 |
| 12857 | fn ly_put e ulong to ulong |
| 12858 | j = ly_fld e |
| 12859 | if eq j 0 |
| 12860 | ret 0 |
| 12861 | end |
| 12862 | j = sub j 1 |
| 12863 | if ne get lf_cnt j 0 |
| 12864 | rdval 0 5 255 0 |
| 12865 | put svk 0 get rk 0 |
| 12866 | put svv 0 get rv 0 |
| 12867 | put svt 0 get rt 0 |
| 12868 | end |
| 12869 | ly_st e j |
| 12870 | eol |
| 12871 | ret 1 |
| 12872 | end |
| 12873 | |
| 12874 | note ly_st: the value of field j (index saved in svk/svv/svt), then the store through layout name e |
| 12875 | fn ly_st e ulong j ulong to void |
| 12876 | ft = ulong get lf_type j |
| 12877 | cnt = get lf_cnt j |
| 12878 | rdval 0 ft 255 0 |
| 12879 | if ne get rt 0 ft |
| 12880 | fail 7 |
| 12881 | end |
| 12882 | v = matreg get rk 0 get rv 0 get rt 0 |
| 12883 | x = ulong 0 |
| 12884 | if eq cnt 0 |
| 12885 | x = alloc |
| 12886 | matconst x get lf_off j |
| 12887 | else |
| 12888 | x = ly_ix j get svk 0 get svv 0 get svt 0 |
| 12889 | end |
| 12890 | if and ne get lf_big j 0 ne tlog ft 0 |
| 12891 | y = alloc |
| 12892 | ly_rev ft v y |
| 12893 | v = y |
| 12894 | end |
| 12895 | if ne get xtarget 0 0 |
| 12896 | xlayout 1 ulong get nm_reg sub e 1 x ft v |
| 12897 | else |
| 12898 | emit or or or stun ft v shl ulong get nm_reg sub e 1 5 shl x 16 |
| 12899 | end |
| 12900 | end |
| 12901 | |
| 12902 | note vt_fget_go: field j of struct name e. Scalar, or an index then the element. |
| 12903 | fn vt_fget_go e ulong dst ulong j ulong to void |
| 12904 | fl = ulong get sf_len j |
| 12905 | ft = ulong get sf_type j |
| 12906 | off = ulong get sf_off j |
| 12907 | base = ulong get nm_reg sub e 1 |
| 12908 | idx = alloc |
| 12909 | if eq fl 0 |
| 12910 | st_store_ld base idx off ft dst |
| 12911 | else |
| 12912 | rdval 0 5 255 0 |
| 12913 | if eq get rt 0 1 |
| 12914 | fail 7 |
| 12915 | end |
| 12916 | if eq get rk 0 3 |
| 12917 | if ge get rv 0 fl |
| 12918 | fail 21 |
| 12919 | end |
| 12920 | st_store_ld base idx add off get rv 0 ft dst |
| 12921 | else |
| 12922 | if ne get rk 0 1 |
| 12923 | fail 7 |
| 12924 | end |
| 12925 | st_ixreg idx get rv 0 off fl ft |
| 12926 | st_ld base idx ft dst |
| 12927 | end |
| 12928 | end |
| 12929 | end |
| 12930 | |
| 12931 | note vt_fget: get p f, or get p f i for an array field. Kind 6 own, 7 edit, 8 view; all may be read. |
| 12932 | fn vt_fget e ulong dst ulong to void |
| 12933 | i = sub e 1 |
| 12934 | tok |
| 12935 | if ne get tk 0 1 |
| 12936 | fail 16 |
| 12937 | end |
| 12938 | if gt get tl 0 8 |
| 12939 | fail 13 |
| 12940 | end |
| 12941 | si = sub ulong get nm_type i 16 |
| 12942 | fid = findfield si get tw 0 |
| 12943 | if eq fid 0 |
| 12944 | fail 3 |
| 12945 | end |
| 12946 | vt_fget_go e dst sub fid 1 |
| 12947 | end |
| 12948 | |
| 12949 | note st_store_ld: constant cell, then load. Split out so vt_fget stays under 16 registers. |
| 12950 | fn st_store_ld base ulong idx ulong cell ulong t ulong dst ulong to void |
| 12951 | matconst idx shl cell sub 3 tlog t |
| 12952 | st_ld base idx t dst |
| 12953 | end |
| 12954 | |
| 12955 | note s_putf_go: field j of struct name e. Read the value (and the index, if an array field) and store. |
| 12956 | fn s_putf_go e ulong j ulong to void |
| 12957 | fl = ulong get sf_len j |
| 12958 | ft = ulong get sf_type j |
| 12959 | off = ulong get sf_off j |
| 12960 | base = ulong get nm_reg sub e 1 |
| 12961 | if ne fl 0 |
| 12962 | rdval 0 5 255 0 |
| 12963 | if eq get rt 0 1 |
| 12964 | fail 7 |
| 12965 | end |
| 12966 | put svk 0 get rk 0 |
| 12967 | put svv 0 get rv 0 |
| 12968 | put svt 0 get rt 0 |
| 12969 | end |
| 12970 | rdval 0 ft 255 0 |
| 12971 | if ne get rt 0 ft |
| 12972 | fail 7 |
| 12973 | end |
| 12974 | v = matreg get rk 0 get rv 0 get rt 0 |
| 12975 | idx = alloc |
| 12976 | if eq fl 0 |
| 12977 | st_store base idx off ft v |
| 12978 | else |
| 12979 | s_putf_ix base idx v off fl ft |
| 12980 | end |
| 12981 | eol |
| 12982 | end |
| 12983 | |
| 12984 | note s_putf: put p f v, or put p f i v. A view struct is error 20. |
| 12985 | fn s_putf e ulong to void |
| 12986 | i = sub e 1 |
| 12987 | if eq ulong get nm_kind i 8 |
| 12988 | fail 20 |
| 12989 | end |
| 12990 | tok |
| 12991 | if ne get tk 0 1 |
| 12992 | fail 16 |
| 12993 | end |
| 12994 | if gt get tl 0 8 |
| 12995 | fail 13 |
| 12996 | end |
| 12997 | si = sub ulong get nm_type i 16 |
| 12998 | fid = findfield si get tw 0 |
| 12999 | if eq fid 0 |
| 13000 | fail 3 |
| 13001 | end |
| 13002 | s_putf_go e sub fid 1 |
| 13003 | end |
| 13004 | |
| 13005 | note s_putf_ix: the index was saved in svk/svv/svt before the value was read |
| 13006 | fn s_putf_ix base ulong idx ulong v ulong off ulong fl ulong ft ulong to void |
| 13007 | ik = get svk 0 |
| 13008 | iv = get svv 0 |
| 13009 | if eq get svt 0 1 |
| 13010 | fail 7 |
| 13011 | end |
| 13012 | if eq ik 3 |
| 13013 | if ge iv fl |
| 13014 | fail 21 |
| 13015 | end |
| 13016 | st_store base idx add off iv ft v |
| 13017 | else |
| 13018 | if ne ik 1 |
| 13019 | fail 7 |
| 13020 | end |
| 13021 | st_ixreg idx iv off fl ft |
| 13022 | put ea_b 0 base |
| 13023 | put ea_i 0 idx |
| 13024 | stel ft v |
| 13025 | end |
| 13026 | end |
| 13027 | |
| 13028 | note ca_st_ok: read one struct argument of parameter i of function f. Returns the name entry. |
| 13029 | fn ca_st_ok f ulong i ulong to ulong |
| 13030 | md = ulong 0 |
| 13031 | aa_word |
| 13032 | w = get tw 0 |
| 13033 | c = kw w |
| 13034 | if ne c 0 |
| 13035 | if or lt c 57 gt c 58 |
| 13036 | fail 16 |
| 13037 | end |
| 13038 | md = c |
| 13039 | aa_word |
| 13040 | w = get tw 0 |
| 13041 | end |
| 13042 | e = findname w |
| 13043 | if eq e 0 |
| 13044 | fail 3 |
| 13045 | end |
| 13046 | ni = sub e 1 |
| 13047 | k = ulong get nm_kind ni |
| 13048 | if lt k 6 |
| 13049 | fail 7 |
| 13050 | end |
| 13051 | p = add mul sub f 1 6 i |
| 13052 | pk = ulong get fn_pk p |
| 13053 | if eq pk 7 |
| 13054 | if eq md 57 |
| 13055 | fail 20 |
| 13056 | end |
| 13057 | if eq k 8 |
| 13058 | fail 20 |
| 13059 | end |
| 13060 | else |
| 13061 | if eq md 58 |
| 13062 | fail 7 |
| 13063 | end |
| 13064 | end |
| 13065 | if ne ulong get nm_type ni ulong get fn_pt p |
| 13066 | fail 7 |
| 13067 | end |
| 13068 | ret e |
| 13069 | end |
| 13070 | |
| 13071 | note ca_st: a struct argument. edit (fn_pk 7) needs own or edit; view takes any. Same struct. |
| 13072 | fn ca_st f ulong i ulong cb ulong to void |
| 13073 | e = ca_st_ok f i |
| 13074 | note ca_dist: the same struct name passed twice in one call is error 19. |
| 13075 | j = ulong 0 |
| 13076 | while lt j i |
| 13077 | if eq get fr add add cb mul j 3 2 e |
| 13078 | fail 19 |
| 13079 | end |
| 13080 | j = add j 1 |
| 13081 | end |
| 13082 | q = add cb mul i 3 |
| 13083 | put fr q 5 |
| 13084 | put fr add q 1 ulong get nm_reg sub e 1 |
| 13085 | put fr add q 2 e |
| 13086 | end |
| 13087 | note ---- R6 IR. A leading line `ir` writes OSC IR version 1. The AArch64 path is not taken. |
| 13088 | note Worksheet ir_match.py matched omega_emit on the 10 dev programs; this is that algorithm. |
| 13089 | |
| 13090 | global ir_rty uchar 64 |
| 13091 | global ir_nreg ulong 1 |
| 13092 | global ir_nm ulong 32 |
| 13093 | global ir_nrr uchar 32 |
| 13094 | global ir_nn ulong 1 |
| 13095 | global ir_cty uchar 32 |
| 13096 | global ir_cm ulong 32 |
| 13097 | global ir_cr uchar 32 |
| 13098 | global ir_nc ulong 1 |
| 13099 | global ir_bord ulong 32 |
| 13100 | global ir_nord ulong 1 |
| 13101 | global ir_cur ulong 1 |
| 13102 | global ir_dead ulong 1 |
| 13103 | global ir_nb ulong 1 |
| 13104 | global ir_ok uchar 256 |
| 13105 | global ir_oa ulong 256 |
| 13106 | global ir_ob ulong 256 |
| 13107 | global ir_oc ulong 256 |
| 13108 | global ir_od ulong 256 |
| 13109 | global ir_obl ulong 256 |
| 13110 | global ir_no ulong 1 |
| 13111 | global ir_bf ulong 32 |
| 13112 | global ir_bc ulong 32 |
| 13113 | global ir_fk uchar 8 |
| 13114 | global ir_fa ulong 8 |
| 13115 | global ir_fb ulong 8 |
| 13116 | global ir_fc ulong 8 |
| 13117 | global ir_fd ulong 8 |
| 13118 | global ir_nf ulong 1 |
| 13119 | global ir_ret ulong 1 |
| 13120 | global ir_npar ulong 1 |
| 13121 | global ir_rr ulong 1 |
| 13122 | global ir_vt ulong 1 |
| 13123 | global ir_bare ulong 1 |
| 13124 | global ir_isb ulong 1 |
| 13125 | global ir_ns ulong 1 |
| 13126 | global ir_nl ulong 1 |
| 13127 | global ir_have ulong 1 |
| 13128 | global irrec uchar 2620252 |
| 13129 | global irrlen ulong 1 |
| 13130 | global irnf ulong 1 |
| 13131 | global irf_nm ulong 32 |
| 13132 | global irf_ns ulong 32 |
| 13133 | global irf_nl ulong 32 |
| 13134 | global irf_np ulong 32 |
| 13135 | global irf_ret uchar 32 |
| 13136 | global irf_pt uchar 192 |
| 13137 | global irf_n ulong 1 |
| 13138 | global ir_args ulong 6 |
| 13139 | global ir_oarg ulong 1536 |
| 13140 | global ir_miss ulong 1 |
| 13141 | global ir_cl ulong 1 |
| 13142 | global ir_cs ulong 1 |
| 13143 | note per open block frame, the local count when it opened (names bound inside go out of scope at else / end) |
| 13144 | global ir_fnn ulong 8 |
| 13145 | note ir_bbig: tbig of the bare number in ir_bare, for the range check once its type is known (error 8). |
| 13146 | global ir_bbig ulong 1 |
| 13147 | |
| 13148 | note ir_lead: 1 when the first line is "ir" (after blanks). Both scans run as nested 999999-pass loops, |
| 13149 | note so more than 1000000 leading blanks or first-line bytes are read, not trapped 4 (#671). |
| 13150 | fn ir_lead to ulong |
| 13151 | p = ulong 0 |
| 13152 | go = true |
| 13153 | while go |
| 13154 | m = ulong 0 |
| 13155 | while and go lt m 999999 |
| 13156 | if ge p get inlen 0 |
| 13157 | go = false |
| 13158 | else |
| 13159 | c = get inp p |
| 13160 | if gt c 32 |
| 13161 | go = false |
| 13162 | else |
| 13163 | if eq c 10 |
| 13164 | ret 0 |
| 13165 | end |
| 13166 | p = add p 1 |
| 13167 | end |
| 13168 | end |
| 13169 | m = add m 1 |
| 13170 | end |
| 13171 | end |
| 13172 | if ge add p 3 get inlen 0 |
| 13173 | ret 0 |
| 13174 | end |
| 13175 | if ne get inp p 105 |
| 13176 | ret 0 |
| 13177 | end |
| 13178 | if ne get inp add p 1 114 |
| 13179 | ret 0 |
| 13180 | end |
| 13181 | if gt get inp add p 2 32 |
| 13182 | ret 0 |
| 13183 | end |
| 13184 | q = add p 2 |
| 13185 | go = true |
| 13186 | while go |
| 13187 | m = ulong 0 |
| 13188 | while and go lt m 999999 |
| 13189 | if ge q get inlen 0 |
| 13190 | go = false |
| 13191 | else |
| 13192 | if eq get inp q 10 |
| 13193 | go = false |
| 13194 | else |
| 13195 | q = add q 1 |
| 13196 | end |
| 13197 | end |
| 13198 | m = add m 1 |
| 13199 | end |
| 13200 | end |
| 13201 | if lt q get inlen 0 |
| 13202 | q = add q 1 |
| 13203 | end |
| 13204 | put cur 0 q |
| 13205 | put line 0 2 |
| 13206 | ret 1 |
| 13207 | end |
| 13208 | |
| 13209 | fn ir_w16 v ulong to void |
| 13210 | emitb uchar and v 255 |
| 13211 | emitb uchar and shr v 8 255 |
| 13212 | end |
| 13213 | |
| 13214 | fn ir_w32 v ulong to void |
| 13215 | ir_w16 v |
| 13216 | ir_w16 shr v 16 |
| 13217 | end |
| 13218 | |
| 13219 | fn ir_w64 v ulong to void |
| 13220 | ir_w32 v |
| 13221 | ir_w32 shr v 32 |
| 13222 | end |
| 13223 | |
| 13224 | fn ir_newreg ty ulong to ulong |
| 13225 | r = get ir_nreg 0 |
| 13226 | if ge r 64 |
| 13227 | fail 14 |
| 13228 | end |
| 13229 | put ir_rty r uchar ty |
| 13230 | put ir_nreg 0 add r 1 |
| 13231 | ret r |
| 13232 | end |
| 13233 | |
| 13234 | fn ir_block to ulong |
| 13235 | b = get ir_nb 0 |
| 13236 | if ge b 32 |
| 13237 | fail 14 |
| 13238 | end |
| 13239 | put ir_bord b 65535 |
| 13240 | put ir_nb 0 add b 1 |
| 13241 | ret b |
| 13242 | end |
| 13243 | |
| 13244 | fn ir_start b ulong to void |
| 13245 | put ir_bord b get ir_nord 0 |
| 13246 | put ir_nord 0 add get ir_nord 0 1 |
| 13247 | put ir_cur 0 b |
| 13248 | put ir_dead 0 0 |
| 13249 | end |
| 13250 | |
| 13251 | fn ir_op k ulong a ulong b ulong c ulong d ulong to void |
| 13252 | if ne get ir_dead 0 0 |
| 13253 | fail 17 |
| 13254 | end |
| 13255 | n = get ir_no 0 |
| 13256 | if ge n 256 |
| 13257 | fail 14 |
| 13258 | end |
| 13259 | put ir_ok n uchar k |
| 13260 | put ir_oa n a |
| 13261 | put ir_ob n b |
| 13262 | put ir_oc n c |
| 13263 | put ir_od n d |
| 13264 | put ir_obl n get ir_cur 0 |
| 13265 | put ir_no 0 add n 1 |
| 13266 | end |
| 13267 | |
| 13268 | fn ir_lit mag ulong ty ulong to ulong |
| 13269 | i = ulong 0 |
| 13270 | n = get ir_nc 0 |
| 13271 | while lt i n |
| 13272 | if and eq ulong get ir_cty i ty eq get ir_cm i mag |
| 13273 | ret ulong get ir_cr i |
| 13274 | end |
| 13275 | i = add i 1 |
| 13276 | end |
| 13277 | if ge n 32 |
| 13278 | fail 14 |
| 13279 | end |
| 13280 | r = ir_newreg ty |
| 13281 | put ir_cty n uchar ty |
| 13282 | put ir_cm n mag |
| 13283 | put ir_cr n uchar r |
| 13284 | put ir_nc 0 add n 1 |
| 13285 | ret r |
| 13286 | end |
| 13287 | |
| 13288 | note ir_find: the local in scope named w (packed) -> its index + 1, or 0. Locals are at most 8 bytes, so a |
| 13289 | note word of length l over 8 is never one (its packed first 8 bytes may equal a local's name). |
| 13290 | fn ir_find w ulong l ulong to ulong |
| 13291 | if gt l 8 |
| 13292 | ret 0 |
| 13293 | end |
| 13294 | i = ulong 0 |
| 13295 | while lt i get ir_nn 0 |
| 13296 | if eq get ir_nm i w |
| 13297 | ret add i 1 |
| 13298 | end |
| 13299 | i = add i 1 |
| 13300 | end |
| 13301 | ret 0 |
| 13302 | end |
| 13303 | |
| 13304 | fn ir_bind w ulong r ulong to void |
| 13305 | n = get ir_nn 0 |
| 13306 | if ge n 32 |
| 13307 | fail 14 |
| 13308 | end |
| 13309 | put ir_nm n w |
| 13310 | put ir_nrr n uchar r |
| 13311 | put ir_nn 0 add n 1 |
| 13312 | end |
| 13313 | |
| 13314 | note ir_kwt: the keyword number of the current word, or 0 for a word over 8 bytes (only 8 are packed). |
| 13315 | fn ir_kwt to ulong |
| 13316 | if gt get tl 0 8 |
| 13317 | ret 0 |
| 13318 | end |
| 13319 | ret kw get tw 0 |
| 13320 | end |
| 13321 | |
| 13322 | note ir_newname: a new local, parameter or function name must not be a keyword (16), a local in scope, a |
| 13323 | note constant, or a function of the unit so far, the current one included (10, as newname). Function |
| 13324 | note names compare in full (up to 63 bytes). |
| 13325 | fn ir_newname w ulong s ulong l ulong to void |
| 13326 | if le l 8 |
| 13327 | if ne kw w 0 |
| 13328 | fail 16 |
| 13329 | end |
| 13330 | if ne findname w 0 |
| 13331 | fail 10 |
| 13332 | end |
| 13333 | end |
| 13334 | if ne ir_find w l 0 |
| 13335 | fail 10 |
| 13336 | end |
| 13337 | put ir_cl 0 l |
| 13338 | put ir_cs 0 s |
| 13339 | j = ulong 0 |
| 13340 | while lt j get irf_n 0 |
| 13341 | if eq get irf_nm j w |
| 13342 | if ne ir_nameeq j 0 |
| 13343 | fail 10 |
| 13344 | end |
| 13345 | end |
| 13346 | j = add j 1 |
| 13347 | end |
| 13348 | end |
| 13349 | |
| 13350 | note ir_newloc: a new local, parameter or for counter: at most 8 bytes (13, as native), then ir_newname. |
| 13351 | fn ir_newloc w ulong s ulong l ulong to void |
| 13352 | if gt l 8 |
| 13353 | fail 13 |
| 13354 | end |
| 13355 | ir_newname w s l |
| 13356 | end |
| 13357 | |
| 13358 | note ir_type: a type word IR v1 lowers: 1 .. 9, or void (76) when isret is 1. A float, a view / edit array or |
| 13359 | note void elsewhere is error 9 (as typeword in IR mode); no word is 4; another word 16. |
| 13360 | fn ir_type isret ulong to ulong |
| 13361 | tok |
| 13362 | if or eq get tk 0 0 eq get tk 0 3 |
| 13363 | fail 4 |
| 13364 | end |
| 13365 | if ne get tk 0 1 |
| 13366 | fail 16 |
| 13367 | end |
| 13368 | c = ir_kwt |
| 13369 | if and ge c 1 le c 9 |
| 13370 | ret c |
| 13371 | end |
| 13372 | if and eq c 76 eq isret 1 |
| 13373 | ret c |
| 13374 | end |
| 13375 | if or or eq c 76 eq c 88 eq c 89 |
| 13376 | fail 9 |
| 13377 | end |
| 13378 | if or eq c 57 eq c 58 |
| 13379 | fail 9 |
| 13380 | end |
| 13381 | fail 16 |
| 13382 | ret 0 |
| 13383 | end |
| 13384 | |
| 13385 | fn ir_push k ulong a ulong b ulong c ulong d ulong to void |
| 13386 | n = get ir_nf 0 |
| 13387 | if ge n 8 |
| 13388 | fail 14 |
| 13389 | end |
| 13390 | put ir_fk n uchar k |
| 13391 | put ir_fa n a |
| 13392 | put ir_fb n b |
| 13393 | put ir_fc n c |
| 13394 | put ir_fd n d |
| 13395 | put ir_fnn n get ir_nn 0 |
| 13396 | put ir_nf 0 add n 1 |
| 13397 | end |
| 13398 | |
| 13399 | fn ir_set dst ulong r ulong ty ulong to void |
| 13400 | put ir_isb 0 0 |
| 13401 | if eq dst 65534 |
| 13402 | put ir_rr 0 r |
| 13403 | put ir_vt 0 ty |
| 13404 | ret |
| 13405 | end |
| 13406 | d = dst |
| 13407 | if eq dst 65535 |
| 13408 | d = ir_newreg ty |
| 13409 | end |
| 13410 | ir_op 2 d r 0 0 |
| 13411 | put ir_rr 0 d |
| 13412 | put ir_vt 0 ty |
| 13413 | end |
| 13414 | |
| 13415 | fn ir_ord id ulong to ulong |
| 13416 | ret get ir_bord id |
| 13417 | end |
| 13418 | |
| 13419 | |
| 13420 | |
| 13421 | |
| 13422 | fn ir_wins k ulong to void |
| 13423 | if eq k 0 |
| 13424 | i = ulong 0 |
| 13425 | while lt i get ir_nc 0 |
| 13426 | emitb 1 |
| 13427 | ir_w16 ulong get ir_cr i |
| 13428 | ir_w64 get ir_cm i |
| 13429 | i = add i 1 |
| 13430 | end |
| 13431 | end |
| 13432 | i = ulong 0 |
| 13433 | while lt i get ir_no 0 |
| 13434 | if eq ir_ord get ir_obl i k |
| 13435 | op = ulong get ir_ok i |
| 13436 | emitb uchar op |
| 13437 | if eq op 1 |
| 13438 | ir_w16 get ir_oa i |
| 13439 | ir_w64 get ir_ob i |
| 13440 | end |
| 13441 | if eq op 2 |
| 13442 | ir_w16 get ir_oa i |
| 13443 | ir_w16 get ir_ob i |
| 13444 | end |
| 13445 | if eq op 3 |
| 13446 | emitb uchar get ir_oa i |
| 13447 | ir_w16 get ir_ob i |
| 13448 | ir_w16 get ir_oc i |
| 13449 | ir_w16 get ir_od i |
| 13450 | end |
| 13451 | if eq op 4 |
| 13452 | emitb uchar get ir_oa i |
| 13453 | ir_w16 get ir_ob i |
| 13454 | ir_w16 get ir_oc i |
| 13455 | end |
| 13456 | if eq op 5 |
| 13457 | emitb uchar get ir_oa i |
| 13458 | ir_w16 get ir_ob i |
| 13459 | ir_w16 get ir_oc i |
| 13460 | ir_w16 get ir_od i |
| 13461 | end |
| 13462 | if eq op 6 |
| 13463 | ir_w16 get ir_oa i |
| 13464 | ir_w16 get ir_ob i |
| 13465 | end |
| 13466 | if eq op 11 |
| 13467 | ir_w16 get ir_oa i |
| 13468 | ir_w16 get ir_ob i |
| 13469 | emitb uchar get ir_oc i |
| 13470 | j = ulong 0 |
| 13471 | while lt j get ir_oc i |
| 13472 | ir_w16 get ir_oarg add mul i 6 j |
| 13473 | j = add j 1 |
| 13474 | end |
| 13475 | end |
| 13476 | if eq op 12 |
| 13477 | emitb uchar get ir_oa i |
| 13478 | end |
| 13479 | if eq op 13 |
| 13480 | ir_w16 ir_ord get ir_oa i |
| 13481 | end |
| 13482 | if eq op 14 |
| 13483 | ir_w16 get ir_oa i |
| 13484 | ir_w16 ir_ord get ir_ob i |
| 13485 | ir_w16 ir_ord get ir_oc i |
| 13486 | end |
| 13487 | if eq op 15 |
| 13488 | ir_w16 get ir_oa i |
| 13489 | end |
| 13490 | end |
| 13491 | i = add i 1 |
| 13492 | end |
| 13493 | end |
| 13494 | |
| 13495 | fn ir_record to void |
| 13496 | emitb uchar get ir_nl 0 |
| 13497 | p = get ir_ns 0 |
| 13498 | e = add p get ir_nl 0 |
| 13499 | while lt p e |
| 13500 | emitb get inp p |
| 13501 | p = add p 1 |
| 13502 | end |
| 13503 | emitb uchar get ir_npar 0 |
| 13504 | if eq get ir_ret 0 76 |
| 13505 | emitb 0 |
| 13506 | else |
| 13507 | emitb uchar get ir_ret 0 |
| 13508 | end |
| 13509 | ir_w16 get ir_nreg 0 |
| 13510 | i = ulong 0 |
| 13511 | while lt i get ir_nreg 0 |
| 13512 | emitb get ir_rty i |
| 13513 | i = add i 1 |
| 13514 | end |
| 13515 | note Lay out blocks and count their instructions here, preserving constant records in block zero. |
| 13516 | k = ulong 0 |
| 13517 | at = ulong 0 |
| 13518 | while lt k get ir_nord 0 |
| 13519 | put ir_bf k at |
| 13520 | c = ulong 0 |
| 13521 | if eq k 0 |
| 13522 | c = get ir_nc 0 |
| 13523 | end |
| 13524 | i = ulong 0 |
| 13525 | while lt i get ir_no 0 |
| 13526 | if eq ir_ord get ir_obl i k |
| 13527 | c = add c 1 |
| 13528 | end |
| 13529 | i = add i 1 |
| 13530 | end |
| 13531 | put ir_bc k c |
| 13532 | at = add at c |
| 13533 | k = add k 1 |
| 13534 | end |
| 13535 | put ir_no 0 get ir_no 0 |
| 13536 | ir_w16 get ir_nord 0 |
| 13537 | k = ulong 0 |
| 13538 | while lt k get ir_nord 0 |
| 13539 | ir_w32 get ir_bf k |
| 13540 | ir_w32 get ir_bc k |
| 13541 | k = add k 1 |
| 13542 | end |
| 13543 | tot = ulong 0 |
| 13544 | k = ulong 0 |
| 13545 | while lt k get ir_nord 0 |
| 13546 | tot = add tot get ir_bc k |
| 13547 | k = add k 1 |
| 13548 | end |
| 13549 | ir_w32 tot |
| 13550 | k = ulong 0 |
| 13551 | while lt k get ir_nord 0 |
| 13552 | ir_wins k |
| 13553 | k = add k 1 |
| 13554 | end |
| 13555 | ir_w16 0 |
| 13556 | ir_w16 0 |
| 13557 | end |
| 13558 | |
| 13559 | note ir_emit_record: encode the current function into irrec and count it. The per-function IR state is |
| 13560 | note reset by ir_fn, so this must run before the next fn line. |
| 13561 | fn ir_emit_record to void |
| 13562 | if ge get irnf 0 32 |
| 13563 | fail 14 |
| 13564 | end |
| 13565 | put oc 0 0 |
| 13566 | ir_record |
| 13567 | n = get oc 0 |
| 13568 | base = get irrlen 0 |
| 13569 | i = ulong 0 |
| 13570 | while lt i n |
| 13571 | put irrec add base i get out i |
| 13572 | i = add i 1 |
| 13573 | end |
| 13574 | put irrlen 0 add base n |
| 13575 | put irnf 0 add get irnf 0 1 |
| 13576 | end |
| 13577 | |
| 13578 | |
| 13579 | note ir_nameeq: table entry j's name equals the current source name token (length and bytes past 8). |
| 13580 | fn ir_nameeq j ulong to ulong |
| 13581 | fl = get irf_nl j |
| 13582 | if ne fl get ir_cl 0 |
| 13583 | ret 0 |
| 13584 | end |
| 13585 | k = ulong 8 |
| 13586 | same = ulong 1 |
| 13587 | while and eq same 1 lt k get ir_cl 0 |
| 13588 | left = get inp add get irf_ns j k |
| 13589 | right = get inp add get ir_cs 0 k |
| 13590 | if ne left right |
| 13591 | same = 0 |
| 13592 | end |
| 13593 | k = add k 1 |
| 13594 | end |
| 13595 | ret same |
| 13596 | end |
| 13597 | |
| 13598 | note ir_findfn: packed name -> earlier function index + 1, or 0. The current function is the newest |
| 13599 | note table entry and is never returned, so self and forward calls fail. |
| 13600 | fn ir_findfn w ulong to ulong |
| 13601 | if le get irf_n 0 1 |
| 13602 | ret 0 |
| 13603 | end |
| 13604 | fc = sub get irf_n 0 1 |
| 13605 | j = ulong 0 |
| 13606 | while lt j fc |
| 13607 | if eq get irf_nm j w |
| 13608 | if ne ir_nameeq j 0 |
| 13609 | ret add j 1 |
| 13610 | end |
| 13611 | end |
| 13612 | j = add j 1 |
| 13613 | end |
| 13614 | ret 0 |
| 13615 | end |
| 13616 | |
| 13617 | note ir_callop: CALL in the IR's five-field form; the argument registers live in ir_args[0..nargs). |
| 13618 | fn ir_callop dst ulong callee ulong nargs ulong to void |
| 13619 | if ne get ir_dead 0 0 |
| 13620 | fail 17 |
| 13621 | end |
| 13622 | n = get ir_no 0 |
| 13623 | if ge n 256 |
| 13624 | fail 14 |
| 13625 | end |
| 13626 | put ir_ok n 11 |
| 13627 | put ir_oa n dst |
| 13628 | put ir_ob n callee |
| 13629 | put ir_oc n nargs |
| 13630 | put ir_od n 0 |
| 13631 | put ir_obl n get ir_cur 0 |
| 13632 | j = ulong 0 |
| 13633 | while lt j nargs |
| 13634 | put ir_oarg add mul n 6 j get ir_args j |
| 13635 | j = add j 1 |
| 13636 | end |
| 13637 | put ir_no 0 add n 1 |
| 13638 | end |
| 13639 | |
| 13640 | fn ir_name to void |
| 13641 | e = ir_find get tw 0 get tl 0 |
| 13642 | if eq e 0 |
| 13643 | if le get tl 0 8 |
| 13644 | e = findname get tw 0 |
| 13645 | end |
| 13646 | if ne e 0 |
| 13647 | if eq get nm_kind sub e 1 9 |
| 13648 | t = ulong get nm_type sub e 1 |
| 13649 | if ge t 10 |
| 13650 | fail 9 |
| 13651 | end |
| 13652 | r = ir_lit get nm_addr sub e 1 t |
| 13653 | ir_set 65534 r t |
| 13654 | ret |
| 13655 | end |
| 13656 | end |
| 13657 | put ir_miss 0 1 |
| 13658 | ret |
| 13659 | end |
| 13660 | r = ulong get ir_nrr sub e 1 |
| 13661 | ir_set 65534 r ulong get ir_rty r |
| 13662 | end |
| 13663 | |
| 13664 | fn ir_un c ulong dst ulong to void |
| 13665 | ir_val 65534 0 |
| 13666 | if ne get ir_isb 0 0 |
| 13667 | fail 11 |
| 13668 | end |
| 13669 | ty = get ir_vt 0 |
| 13670 | if and eq c 49 eq ty 1 |
| 13671 | fail 7 |
| 13672 | end |
| 13673 | d = dst |
| 13674 | if or eq dst 65534 eq dst 65535 |
| 13675 | d = ir_newreg ty |
| 13676 | end |
| 13677 | su = ulong 1 |
| 13678 | if eq c 50 |
| 13679 | su = ulong 3 |
| 13680 | if ne ty 1 |
| 13681 | su = ulong 2 |
| 13682 | end |
| 13683 | end |
| 13684 | ir_op 4 su d get ir_rr 0 0 |
| 13685 | put ir_rr 0 d |
| 13686 | put ir_vt 0 ty |
| 13687 | put ir_isb 0 0 |
| 13688 | end |
| 13689 | |
| 13690 | fn ir_bin_r left ulong lty ulong c ulong dst ulong to void |
| 13691 | exp2 = lty |
| 13692 | if or eq c 41 eq c 42 |
| 13693 | exp2 = ulong 0 |
| 13694 | end |
| 13695 | ir_val 65534 exp2 |
| 13696 | ir_bin_done left lty c dst |
| 13697 | end |
| 13698 | |
| 13699 | fn ir_bin_done left ulong lty ulong c ulong dst ulong to void |
| 13700 | isb2 = get ir_isb 0 |
| 13701 | ty2 = get ir_vt 0 |
| 13702 | if or eq c 41 eq c 42 |
| 13703 | if or ge lty 10 eq lty 1 |
| 13704 | fail 7 |
| 13705 | end |
| 13706 | if eq isb2 0 |
| 13707 | if or ge ty2 10 eq ty2 1 |
| 13708 | fail 7 |
| 13709 | end |
| 13710 | end |
| 13711 | else |
| 13712 | if ge lty 10 |
| 13713 | fail 7 |
| 13714 | end |
| 13715 | if and eq isb2 0 ne ty2 lty |
| 13716 | fail 7 |
| 13717 | end |
| 13718 | if and and ge c 33 le c 37 eq lty 1 |
| 13719 | fail 7 |
| 13720 | end |
| 13721 | end |
| 13722 | right = get ir_rr 0 |
| 13723 | if ne isb2 0 |
| 13724 | range get ir_bare 0 lty get ir_bbig 0 |
| 13725 | right = ir_lit get ir_bare 0 lty |
| 13726 | end |
| 13727 | if ge c 43 |
| 13728 | d = dst |
| 13729 | if or eq dst 65534 eq dst 65535 |
| 13730 | d = ir_newreg 1 |
| 13731 | end |
| 13732 | ir_op 5 sub c 42 d left right |
| 13733 | put ir_rr 0 d |
| 13734 | put ir_vt 0 1 |
| 13735 | ret |
| 13736 | end |
| 13737 | d = dst |
| 13738 | if or eq dst 65534 eq dst 65535 |
| 13739 | d = ir_newreg lty |
| 13740 | end |
| 13741 | ir_op 3 sub c 32 d left right |
| 13742 | put ir_rr 0 d |
| 13743 | put ir_vt 0 lty |
| 13744 | put ir_isb 0 0 |
| 13745 | end |
| 13746 | |
| 13747 | fn ir_bin c ulong dst ulong to void |
| 13748 | ir_val 65534 0 |
| 13749 | if ne get ir_isb 0 0 |
| 13750 | mag = get ir_bare 0 |
| 13751 | bg = get ir_bbig 0 |
| 13752 | ir_val 65534 0 |
| 13753 | if ne get ir_isb 0 0 |
| 13754 | fail 11 |
| 13755 | end |
| 13756 | ty = get ir_vt 0 |
| 13757 | range mag ty bg |
| 13758 | left = ir_lit mag ty |
| 13759 | ir_bin_done left ty c dst |
| 13760 | ret |
| 13761 | end |
| 13762 | left = get ir_rr 0 |
| 13763 | lty = get ir_vt 0 |
| 13764 | ir_bin_r left lty c dst |
| 13765 | end |
| 13766 | |
| 13767 | note ir_cast: TYPE v. The operand keeps its own type (as native rdval reads it, exp 0); a bare number is |
| 13768 | note checked against TYPE (8). bool converts to and from numbers only by comparison (9, as vt_conv). |
| 13769 | note Only a constant of TYPE is the value itself; any other same-type value is a mov, as the C oracle. |
| 13770 | fn ir_cast c ulong dst ulong to void |
| 13771 | ir_val 65534 0 |
| 13772 | if ne get ir_isb 0 0 |
| 13773 | range get ir_bare 0 c get ir_bbig 0 |
| 13774 | r = ir_lit get ir_bare 0 c |
| 13775 | ir_set dst r c |
| 13776 | ret |
| 13777 | end |
| 13778 | src = get ir_rr 0 |
| 13779 | sty = get ir_vt 0 |
| 13780 | if xor eq sty 1 eq c 1 |
| 13781 | fail 9 |
| 13782 | end |
| 13783 | k = ulong 0 |
| 13784 | if and eq sty c eq dst 65534 |
| 13785 | i = ulong 0 |
| 13786 | while lt i get ir_nc 0 |
| 13787 | if eq ulong get ir_cr i src |
| 13788 | k = ulong 1 |
| 13789 | end |
| 13790 | i = add i 1 |
| 13791 | end |
| 13792 | end |
| 13793 | if ne k 0 |
| 13794 | put ir_rr 0 src |
| 13795 | put ir_vt 0 c |
| 13796 | put ir_isb 0 0 |
| 13797 | ret |
| 13798 | end |
| 13799 | d = dst |
| 13800 | if or eq dst 65534 eq dst 65535 |
| 13801 | d = ir_newreg c |
| 13802 | end |
| 13803 | if eq sty c |
| 13804 | ir_op 2 d src 0 0 |
| 13805 | else |
| 13806 | ir_op 6 d src 0 0 |
| 13807 | end |
| 13808 | put ir_rr 0 d |
| 13809 | put ir_vt 0 c |
| 13810 | put ir_isb 0 0 |
| 13811 | end |
| 13812 | |
| 13813 | fn ir_val dst ulong exp ulong to void |
| 13814 | put ir_isb 0 0 |
| 13815 | put ir_miss 0 0 |
| 13816 | tok |
| 13817 | if or eq get tk 0 0 eq get tk 0 3 |
| 13818 | fail 4 |
| 13819 | end |
| 13820 | if or eq get tk 0 4 eq get tk 0 5 |
| 13821 | fail 9 |
| 13822 | end |
| 13823 | if eq get tk 0 2 |
| 13824 | if eq exp 0 |
| 13825 | put ir_bare 0 get tw 0 |
| 13826 | put ir_bbig 0 get tbig 0 |
| 13827 | put ir_isb 0 1 |
| 13828 | ret |
| 13829 | end |
| 13830 | range get tw 0 exp get tbig 0 |
| 13831 | r = ir_lit get tw 0 exp |
| 13832 | ir_set dst r exp |
| 13833 | ret |
| 13834 | end |
| 13835 | c = ir_kwt |
| 13836 | if and ge c 1 le c 9 |
| 13837 | ir_cast c dst |
| 13838 | ret |
| 13839 | end |
| 13840 | if and ge c 33 le c 48 |
| 13841 | ir_bin c dst |
| 13842 | if and ne exp 0 ne get ir_vt 0 exp |
| 13843 | fail 7 |
| 13844 | end |
| 13845 | ret |
| 13846 | end |
| 13847 | if or eq c 49 eq c 50 |
| 13848 | ir_un c dst |
| 13849 | if and ne exp 0 ne get ir_vt 0 exp |
| 13850 | fail 7 |
| 13851 | end |
| 13852 | ret |
| 13853 | end |
| 13854 | if eq c 55 |
| 13855 | if and ne exp 0 ne exp 1 |
| 13856 | fail 7 |
| 13857 | end |
| 13858 | r = ir_lit 1 1 |
| 13859 | ir_set dst r 1 |
| 13860 | ret |
| 13861 | end |
| 13862 | if eq c 56 |
| 13863 | if and ne exp 0 ne exp 1 |
| 13864 | fail 7 |
| 13865 | end |
| 13866 | r = ir_lit 0 1 |
| 13867 | ir_set dst r 1 |
| 13868 | ret |
| 13869 | end |
| 13870 | ir_name |
| 13871 | if ne get ir_miss 0 0 |
| 13872 | put ir_cl 0 get tl 0 |
| 13873 | put ir_cs 0 get ts 0 |
| 13874 | f = ir_findfn get tw 0 |
| 13875 | if eq f 0 |
| 13876 | fail 3 |
| 13877 | end |
| 13878 | j = sub f 1 |
| 13879 | rtv = ulong get irf_ret j |
| 13880 | if eq rtv 76 |
| 13881 | fail 7 |
| 13882 | end |
| 13883 | np = get irf_np j |
| 13884 | i = ulong 0 |
| 13885 | while lt i np |
| 13886 | ty = ulong get irf_pt add mul j 6 i |
| 13887 | ir_val 65534 ty |
| 13888 | if ne get ir_vt 0 ty |
| 13889 | fail 7 |
| 13890 | end |
| 13891 | put ir_args i get ir_rr 0 |
| 13892 | i = add i 1 |
| 13893 | end |
| 13894 | r = dst |
| 13895 | if or eq dst 65534 eq dst 65535 |
| 13896 | r = ir_newreg rtv |
| 13897 | end |
| 13898 | ir_callop r j np |
| 13899 | put ir_rr 0 r |
| 13900 | put ir_vt 0 rtv |
| 13901 | ret |
| 13902 | end |
| 13903 | if ne dst 65534 |
| 13904 | ir_set dst get ir_rr 0 get ir_vt 0 |
| 13905 | end |
| 13906 | end |
| 13907 | |
| 13908 | fn ir_end to void |
| 13909 | n = sub get ir_nf 0 1 |
| 13910 | put ir_nf 0 n |
| 13911 | k = ulong get ir_fk n |
| 13912 | put ir_nn 0 get ir_fnn n |
| 13913 | if eq k 1 |
| 13914 | if eq get ir_fc n 0 |
| 13915 | if eq get ir_dead 0 0 |
| 13916 | ir_op 13 get ir_fb n 0 0 0 |
| 13917 | put ir_dead 0 1 |
| 13918 | end |
| 13919 | ir_start get ir_fb n |
| 13920 | else |
| 13921 | if eq get ir_dead 0 0 |
| 13922 | if eq get ir_fd n 65535 |
| 13923 | j = ir_block |
| 13924 | put ir_fd n j |
| 13925 | end |
| 13926 | ir_op 13 get ir_fd n 0 0 0 |
| 13927 | put ir_dead 0 1 |
| 13928 | end |
| 13929 | if ne get ir_fd n 65535 |
| 13930 | ir_start get ir_fd n |
| 13931 | end |
| 13932 | end |
| 13933 | end |
| 13934 | if eq k 2 |
| 13935 | if eq get ir_dead 0 0 |
| 13936 | ir_op 13 get ir_fa n 0 0 0 |
| 13937 | put ir_dead 0 1 |
| 13938 | end |
| 13939 | ir_start get ir_fb n |
| 13940 | end |
| 13941 | if eq k 3 |
| 13942 | if eq get ir_dead 0 0 |
| 13943 | one = ir_lit 1 ulong get ir_rty get ir_fc n |
| 13944 | ir_op 3 1 get ir_fc n get ir_fc n one |
| 13945 | ir_op 13 get ir_fa n 0 0 0 |
| 13946 | put ir_dead 0 1 |
| 13947 | end |
| 13948 | ir_start get ir_fb n |
| 13949 | end |
| 13950 | if eq k 4 |
| 13951 | if eq get ir_dead 0 0 |
| 13952 | if ne get ir_ret 0 76 |
| 13953 | fail 18 |
| 13954 | end |
| 13955 | ir_op 15 65535 0 0 0 |
| 13956 | put ir_dead 0 1 |
| 13957 | end |
| 13958 | put ir_have 0 1 |
| 13959 | end |
| 13960 | eol |
| 13961 | end |
| 13962 | |
| 13963 | note ir_bound: the rest of a while or for line: `bound N` (1 .. 1000000, error 8: the C oracle's range, |
| 13964 | note omegese.c, and the guard range checker2 proves) -> N, or 0 when the line ends there. |
| 13965 | fn ir_bound to ulong |
| 13966 | tok |
| 13967 | if or eq get tk 0 0 eq get tk 0 3 |
| 13968 | ret 0 |
| 13969 | end |
| 13970 | if or ne get tk 0 1 ne ir_kwt 70 |
| 13971 | fail 5 |
| 13972 | end |
| 13973 | bnd = lenval 4 |
| 13974 | if ge sub bnd 1 1000000 |
| 13975 | fail 8 |
| 13976 | end |
| 13977 | eol |
| 13978 | ret bnd |
| 13979 | end |
| 13980 | |
| 13981 | fn ir_while to void |
| 13982 | z = ir_lit 0 5 |
| 13983 | one = ir_lit 1 5 |
| 13984 | cnt = ir_newreg 5 |
| 13985 | ir_op 2 cnt z 0 0 |
| 13986 | h = ir_block |
| 13987 | g = ir_block |
| 13988 | tb = ir_block |
| 13989 | body = ir_block |
| 13990 | ex = ir_block |
| 13991 | ir_op 13 h 0 0 0 |
| 13992 | put ir_dead 0 1 |
| 13993 | ir_start h |
| 13994 | ir_val 65534 1 |
| 13995 | if ne get ir_vt 0 1 |
| 13996 | fail 7 |
| 13997 | end |
| 13998 | lim = ir_bound |
| 13999 | if eq lim 0 |
| 14000 | lim = ulong 1000000 |
| 14001 | end |
| 14002 | lim = ir_lit lim 5 |
| 14003 | ir_op 14 get ir_rr 0 g ex 0 |
| 14004 | ir_start g |
| 14005 | ger = ir_newreg 1 |
| 14006 | ir_op 5 6 ger cnt lim |
| 14007 | ir_op 14 ger tb body 0 |
| 14008 | ir_start tb |
| 14009 | ir_op 12 4 0 0 0 |
| 14010 | ir_op 13 ex 0 0 0 |
| 14011 | put ir_dead 0 1 |
| 14012 | ir_start body |
| 14013 | ir_op 3 1 cnt cnt one |
| 14014 | ir_push 2 h ex cnt 0 |
| 14015 | end |
| 14016 | |
| 14017 | note ir_for: for name type count [bound N]. The counter is bound after the count is read, so the count cannot |
| 14018 | note name it. nc: 1 when the count is a number or an integer constant name (not a local), seen ahead without |
| 14019 | note reading it. Such a count must be 0..1000000 (error 8 otherwise, a minus sign included): the C oracle's |
| 14020 | note count range (omegese.c for_line), so a plain loop never counts past what checker2 proves. Such a count |
| 14021 | note with no bound opens the plain loop (ir_forg with N = 0); any other count, and any count with a bound, |
| 14022 | note opens the guarded loop with N, default 1000000. The counter leaves scope at its end. |
| 14023 | fn ir_for to void |
| 14024 | tok |
| 14025 | if or eq get tk 0 0 eq get tk 0 3 |
| 14026 | fail 4 |
| 14027 | end |
| 14028 | if ne get tk 0 1 |
| 14029 | fail 16 |
| 14030 | end |
| 14031 | w = get tw 0 |
| 14032 | ir_newloc w get ts 0 get tl 0 |
| 14033 | ty = ir_type 0 |
| 14034 | if eq ty 1 |
| 14035 | fail 7 |
| 14036 | end |
| 14037 | c0 = get cur 0 |
| 14038 | l0 = get line 0 |
| 14039 | a0 = get tka 0 |
| 14040 | b0 = get tkb 0 |
| 14041 | tok |
| 14042 | nc = ulong 0 |
| 14043 | if eq get tk 0 2 |
| 14044 | nc = ulong 1 |
| 14045 | if eq get inp get ts 0 45 |
| 14046 | fail 8 |
| 14047 | end |
| 14048 | if gt get tw 0 1000000 |
| 14049 | fail 8 |
| 14050 | end |
| 14051 | end |
| 14052 | if and eq get tk 0 1 le get tl 0 8 |
| 14053 | if eq ir_find get tw 0 get tl 0 0 |
| 14054 | e = findname get tw 0 |
| 14055 | if ne e 0 |
| 14056 | if eq get nm_kind sub e 1 9 |
| 14057 | nc = ulong 1 |
| 14058 | if lt get nm_type sub e 1 10 |
| 14059 | if gt get nm_addr sub e 1 1000000 |
| 14060 | fail 8 |
| 14061 | end |
| 14062 | end |
| 14063 | end |
| 14064 | end |
| 14065 | end |
| 14066 | end |
| 14067 | put cur 0 c0 |
| 14068 | put line 0 l0 |
| 14069 | put tka 0 a0 |
| 14070 | put tkb 0 b0 |
| 14071 | if eq nc 1 |
| 14072 | z = ir_lit 0 ty |
| 14073 | end |
| 14074 | ir_val 65534 ty |
| 14075 | if ne get ir_vt 0 ty |
| 14076 | fail 7 |
| 14077 | end |
| 14078 | kr = get ir_rr 0 |
| 14079 | bn = ir_bound |
| 14080 | if and eq bn 0 eq nc 0 |
| 14081 | bn = ulong 1000000 |
| 14082 | end |
| 14083 | ir_forg w ty kr bn |
| 14084 | end |
| 14085 | |
| 14086 | note ir_forg: the for loop over counter ctr = 0 below kr. N = 0: the plain loop, head: lt ctr kr -> body | exit. |
| 14087 | note Else the guarded loop, the C oracle's shape (omegese.c guarded_loop): a ulong counter cnt = 0 as well; head: |
| 14088 | note lt ctr kr -> guard | exit; guard: ge cnt N -> trap 4 | body; body starts with cnt = add cnt 1. Literals and |
| 14089 | note blocks are made in the oracle's order (literals are shared). The latch adds 1 to ctr (ir_end kind 3). The |
| 14090 | note for frame (kind 3: head h, exit ex, counter ctr): the counter, bound last, leaves scope at the end. |
| 14091 | note The literals 0 and 1 are made first (shared; ir_lit returns the same register again), then the counters. |
| 14092 | note om4 holds 16 registers per function, so the guard blocks reuse names already dead: ty is the guard block |
| 14093 | note and w the trap block (both after ir_bind); cnt is 0 only in the plain loop (two literals precede it). |
| 14094 | fn ir_forg w ulong ty ulong kr ulong bn ulong to void |
| 14095 | cnt = ulong 0 |
| 14096 | if ne bn 0 |
| 14097 | cnt = ir_lit 0 5 |
| 14098 | cnt = ir_lit 1 5 |
| 14099 | cnt = ir_newreg 5 |
| 14100 | end |
| 14101 | ctr = ir_lit 0 ty |
| 14102 | ctr = ir_lit 1 ty |
| 14103 | ctr = ir_newreg ty |
| 14104 | ir_op 2 ctr ir_lit 0 ty 0 0 |
| 14105 | ir_bind w ctr |
| 14106 | h = ir_block |
| 14107 | if ne bn 0 |
| 14108 | ir_op 2 cnt ir_lit 0 5 0 0 |
| 14109 | ty = ir_block |
| 14110 | w = ir_block |
| 14111 | end |
| 14112 | body = ir_block |
| 14113 | ex = ir_block |
| 14114 | ir_op 13 h 0 0 0 |
| 14115 | put ir_dead 0 1 |
| 14116 | ir_start h |
| 14117 | c = ir_newreg 1 |
| 14118 | ir_op 5 3 c ctr kr |
| 14119 | if eq bn 0 |
| 14120 | ir_op 14 c body ex 0 |
| 14121 | else |
| 14122 | bn = ir_lit bn 5 |
| 14123 | ir_op 14 c ty ex 0 |
| 14124 | ir_start ty |
| 14125 | c = ir_newreg 1 |
| 14126 | ir_op 5 6 c cnt bn |
| 14127 | ir_op 14 c w body 0 |
| 14128 | ir_start w |
| 14129 | ir_op 12 4 0 0 0 |
| 14130 | ir_op 13 ex 0 0 0 |
| 14131 | put ir_dead 0 1 |
| 14132 | end |
| 14133 | ir_start body |
| 14134 | if ne cnt 0 |
| 14135 | ir_op 3 1 cnt cnt ir_lit 1 5 |
| 14136 | end |
| 14137 | ir_push 3 h ex ctr 0 |
| 14138 | kr = sub get ir_nf 0 1 |
| 14139 | put ir_fnn kr sub get ir_nn 0 1 |
| 14140 | end |
| 14141 | |
| 14142 | note ir_stmtcall: a void call as a statement; f is the table index + 1. |
| 14143 | fn ir_stmtcall f ulong to void |
| 14144 | j = sub f 1 |
| 14145 | if ne get irf_ret j 76 |
| 14146 | fail 7 |
| 14147 | end |
| 14148 | np = get irf_np j |
| 14149 | i = ulong 0 |
| 14150 | while lt i np |
| 14151 | ty = ulong get irf_pt add mul j 6 i |
| 14152 | ir_val 65534 ty |
| 14153 | if ne get ir_vt 0 ty |
| 14154 | fail 7 |
| 14155 | end |
| 14156 | put ir_args i get ir_rr 0 |
| 14157 | i = add i 1 |
| 14158 | end |
| 14159 | ir_callop 65535 j np |
| 14160 | eol |
| 14161 | end |
| 14162 | |
| 14163 | note ir_assign: name [=] value for a local in scope, a void call, or a new typed local (a new name that is |
| 14164 | note a keyword, constant, local or function is refused; a bare number has no type, error 11). |
| 14165 | fn ir_assign w ulong to void |
| 14166 | p = get ts 0 |
| 14167 | l = get tl 0 |
| 14168 | c0 = get cur 0 |
| 14169 | tok |
| 14170 | eqs = false |
| 14171 | if and eq get tk 0 1 eq ir_kwt 73 |
| 14172 | eqs = true |
| 14173 | else |
| 14174 | put cur 0 c0 |
| 14175 | if eq get tk 0 0 |
| 14176 | put line 0 sub get line 0 1 |
| 14177 | end |
| 14178 | end |
| 14179 | e = ir_find w l |
| 14180 | if ne e 0 |
| 14181 | r = ulong get ir_nrr sub e 1 |
| 14182 | ir_val r ulong get ir_rty r |
| 14183 | if ne get ir_vt 0 ulong get ir_rty r |
| 14184 | fail 7 |
| 14185 | end |
| 14186 | eol |
| 14187 | ret |
| 14188 | end |
| 14189 | put ir_cl 0 l |
| 14190 | put ir_cs 0 p |
| 14191 | f = ir_findfn w |
| 14192 | if ne f 0 |
| 14193 | if eqs |
| 14194 | fail 7 |
| 14195 | end |
| 14196 | ir_stmtcall f |
| 14197 | ret |
| 14198 | end |
| 14199 | if le l 8 |
| 14200 | if ne findname w 0 |
| 14201 | fail 7 |
| 14202 | end |
| 14203 | end |
| 14204 | ir_newloc w p l |
| 14205 | ir_val 65535 0 |
| 14206 | if ne get ir_isb 0 0 |
| 14207 | fail 11 |
| 14208 | end |
| 14209 | eol |
| 14210 | ir_bind w get ir_rr 0 |
| 14211 | end |
| 14212 | |
| 14213 | note ir_loopexit: innermost loop block's exit + 1, or 0 outside a loop. |
| 14214 | fn ir_loopexit to ulong |
| 14215 | i = get ir_nf 0 |
| 14216 | while gt i 0 |
| 14217 | i = sub i 1 |
| 14218 | k = ulong get ir_fk i |
| 14219 | if or eq k 2 eq k 3 |
| 14220 | ret add get ir_fb i 1 |
| 14221 | end |
| 14222 | end |
| 14223 | ret 0 |
| 14224 | end |
| 14225 | |
| 14226 | note ir_stmt: one line. The end of the input inside a function is error 15; a line starting with a number |
| 14227 | note is 16; a note is skipped even after the path ended; a statement IR v1 does not lower is 9. |
| 14228 | fn ir_stmt to ulong |
| 14229 | tok |
| 14230 | if eq get tk 0 0 |
| 14231 | ret 0 |
| 14232 | end |
| 14233 | if eq get tk 0 3 |
| 14234 | fail 15 |
| 14235 | end |
| 14236 | if ne get tk 0 1 |
| 14237 | fail 16 |
| 14238 | end |
| 14239 | c = ir_kwt |
| 14240 | if eq c 83 |
| 14241 | skipnl |
| 14242 | ret 0 |
| 14243 | end |
| 14244 | if and ne c 66 ne c 68 |
| 14245 | if ne get ir_dead 0 0 |
| 14246 | fail 17 |
| 14247 | end |
| 14248 | end |
| 14249 | if eq c 77 |
| 14250 | fail 9 |
| 14251 | end |
| 14252 | if eq c 87 |
| 14253 | note ir_trap: OMEGESE section 4. A trap ends the path but the IR still |
| 14254 | note needs an unreachable ret terminator (zero of the return type, or void). |
| 14255 | note trap is packed little endian 1885434484; independently checked in Wolfram. |
| 14256 | code = lenval 4 |
| 14257 | if or lt code 1 gt code 14 |
| 14258 | fail 8 |
| 14259 | end |
| 14260 | tok |
| 14261 | if not or eq get tk 0 0 eq get tk 0 3 |
| 14262 | fail 4 |
| 14263 | end |
| 14264 | ir_op 12 code 0 0 0 |
| 14265 | z = ulong 65535 |
| 14266 | if ne get ir_ret 0 76 |
| 14267 | z = ir_lit 0 get ir_ret 0 |
| 14268 | end |
| 14269 | ir_op 15 z 0 0 0 |
| 14270 | put ir_dead 0 1 |
| 14271 | ret 0 |
| 14272 | end |
| 14273 | if eq c 86 |
| 14274 | note ir_break: BR to the innermost loop's exit, then the path is dead. The if/loop closes skip the |
| 14275 | note unreachable join exactly as they do after ret or trap. |
| 14276 | ex = ir_loopexit |
| 14277 | if eq ex 0 |
| 14278 | fail 9 |
| 14279 | end |
| 14280 | ir_op 13 sub ex 1 0 0 0 |
| 14281 | put ir_dead 0 1 |
| 14282 | eol |
| 14283 | ret 0 |
| 14284 | end |
| 14285 | if eq c 66 |
| 14286 | ir_end |
| 14287 | ret 0 |
| 14288 | end |
| 14289 | if eq c 68 |
| 14290 | n = sub get ir_nf 0 1 |
| 14291 | if or ne get ir_fk n 1 ne get ir_fc n 0 |
| 14292 | fail 15 |
| 14293 | end |
| 14294 | eol |
| 14295 | put ir_nn 0 get ir_fnn n |
| 14296 | if eq get ir_dead 0 0 |
| 14297 | j = ir_block |
| 14298 | ir_op 13 j 0 0 0 |
| 14299 | put ir_dead 0 1 |
| 14300 | put ir_fd n j |
| 14301 | else |
| 14302 | put ir_fd n 65535 |
| 14303 | end |
| 14304 | put ir_fc n 1 |
| 14305 | ir_start get ir_fb n |
| 14306 | ret 0 |
| 14307 | end |
| 14308 | if eq c 67 |
| 14309 | ir_val 65534 1 |
| 14310 | if ne get ir_vt 0 1 |
| 14311 | fail 7 |
| 14312 | end |
| 14313 | eol |
| 14314 | th = ir_block |
| 14315 | el = ir_block |
| 14316 | ir_op 14 get ir_rr 0 th el 0 |
| 14317 | ir_push 1 th el 0 65535 |
| 14318 | ir_start th |
| 14319 | ret 0 |
| 14320 | end |
| 14321 | if eq c 69 |
| 14322 | ir_while |
| 14323 | ret 0 |
| 14324 | end |
| 14325 | if eq c 71 |
| 14326 | ir_for |
| 14327 | ret 0 |
| 14328 | end |
| 14329 | if eq c 72 |
| 14330 | note ir_doret: ret alone in a void function, ret value otherwise (4 when the value is missing, 5 for a |
| 14331 | note value or any other word after it); the value is read from just after ret. |
| 14332 | c0 = get cur 0 |
| 14333 | tok |
| 14334 | if or eq get tk 0 0 eq get tk 0 3 |
| 14335 | if ne get ir_ret 0 76 |
| 14336 | fail 4 |
| 14337 | end |
| 14338 | ir_op 15 65535 0 0 0 |
| 14339 | else |
| 14340 | if eq get ir_ret 0 76 |
| 14341 | fail 5 |
| 14342 | end |
| 14343 | put cur 0 c0 |
| 14344 | ir_val 65534 get ir_ret 0 |
| 14345 | if ne get ir_vt 0 get ir_ret 0 |
| 14346 | fail 7 |
| 14347 | end |
| 14348 | eol |
| 14349 | ir_op 15 get ir_rr 0 0 0 0 |
| 14350 | end |
| 14351 | put ir_dead 0 1 |
| 14352 | ret 0 |
| 14353 | end |
| 14354 | if eq c 64 |
| 14355 | fail 15 |
| 14356 | end |
| 14357 | if ne c 0 |
| 14358 | if eq c 97 |
| 14359 | note continue keeps its documented IR refusal, error 3 (gate-ir.sh continue_use) |
| 14360 | fail 3 |
| 14361 | end |
| 14362 | if or eq c 80 eq c 82 |
| 14363 | fail 9 |
| 14364 | end |
| 14365 | if or or or eq c 78 eq c 79 eq c 81 eq c 85 |
| 14366 | fail 9 |
| 14367 | end |
| 14368 | if eq c 193 |
| 14369 | fail 9 |
| 14370 | end |
| 14371 | fail 16 |
| 14372 | end |
| 14373 | note a contract clause (requires, ensures, invariant not followed by =) is not an IR v1 statement: refuse it, never |
| 14374 | note read it as a local (#791). `ensures = v` assigns a local of that name, as the C oracle and native mode accept. |
| 14375 | if ne cp_kind 0 |
| 14376 | p = get ts 0 |
| 14377 | l = get line 0 |
| 14378 | tok |
| 14379 | eqs = and eq get tk 0 1 eq ir_kwt 73 |
| 14380 | put cur 0 p |
| 14381 | put line 0 l |
| 14382 | tok |
| 14383 | if not eqs |
| 14384 | fail 30 |
| 14385 | end |
| 14386 | end |
| 14387 | ir_assign get tw 0 |
| 14388 | ret 0 |
| 14389 | end |
| 14390 | |
| 14391 | note ir_param: parameter np of function f, named by the current word: a new name and an IR v1 type. |
| 14392 | fn ir_param f ulong to void |
| 14393 | w = get tw 0 |
| 14394 | s = get ts 0 |
| 14395 | l = get tl 0 |
| 14396 | ir_newloc w s l |
| 14397 | np = get irf_np f |
| 14398 | if ge np 6 |
| 14399 | fail 9 |
| 14400 | end |
| 14401 | ty = ir_type 0 |
| 14402 | put irf_pt add mul f 6 np uchar ty |
| 14403 | put irf_np f add np 1 |
| 14404 | r = ir_newreg ty |
| 14405 | ir_bind w r |
| 14406 | end |
| 14407 | |
| 14408 | note ir_fn: fn name (param type)* to type | void, then the body. The name is checked (16, 13 over 63 |
| 14409 | note bytes, 10 when in use) and entered before the parameters, so a parameter cannot reuse it. |
| 14410 | fn ir_fn to void |
| 14411 | tok |
| 14412 | if ne get tk 0 1 |
| 14413 | fail 16 |
| 14414 | end |
| 14415 | if gt get tl 0 63 |
| 14416 | fail 13 |
| 14417 | end |
| 14418 | fcur = get irf_n 0 |
| 14419 | if ge fcur 32 |
| 14420 | fail 14 |
| 14421 | end |
| 14422 | put ir_nn 0 0 |
| 14423 | ir_newname get tw 0 get ts 0 get tl 0 |
| 14424 | put irf_nm fcur get tw 0 |
| 14425 | put irf_ns fcur get ts 0 |
| 14426 | put irf_nl fcur get tl 0 |
| 14427 | put irf_np fcur 0 |
| 14428 | put irf_n 0 add fcur 1 |
| 14429 | put ir_ns 0 get ts 0 |
| 14430 | put ir_nl 0 get tl 0 |
| 14431 | put ir_nreg 0 0 |
| 14432 | put ir_nc 0 0 |
| 14433 | put ir_nb 0 0 |
| 14434 | put ir_nord 0 0 |
| 14435 | put ir_no 0 0 |
| 14436 | put ir_nf 0 0 |
| 14437 | put ir_dead 0 0 |
| 14438 | go = true |
| 14439 | while go |
| 14440 | tok |
| 14441 | if or eq get tk 0 0 eq get tk 0 3 |
| 14442 | fail 4 |
| 14443 | end |
| 14444 | if ne get tk 0 1 |
| 14445 | fail 16 |
| 14446 | end |
| 14447 | if eq ir_kwt 65 |
| 14448 | go = false |
| 14449 | else |
| 14450 | ir_param fcur |
| 14451 | end |
| 14452 | end |
| 14453 | put ir_ret 0 ir_type 1 |
| 14454 | eol |
| 14455 | put irf_ret fcur uchar get ir_ret 0 |
| 14456 | put ir_npar 0 get ir_nreg 0 |
| 14457 | b = ir_block |
| 14458 | ir_start b |
| 14459 | ir_push 4 0 0 0 0 |
| 14460 | put ir_have 0 0 |
| 14461 | while eq get ir_have 0 0 |
| 14462 | ignored = ir_stmt |
| 14463 | end |
| 14464 | end |
| 14465 | |
| 14466 | fn ir_run to void |
| 14467 | go = true |
| 14468 | while go |
| 14469 | tok |
| 14470 | k = get tk 0 |
| 14471 | if eq k 3 |
| 14472 | go = false |
| 14473 | else |
| 14474 | if eq k 0 |
| 14475 | else |
| 14476 | if ne k 1 |
| 14477 | fail 16 |
| 14478 | end |
| 14479 | c = kw get tw 0 |
| 14480 | if eq c 64 |
| 14481 | ir_fn |
| 14482 | ir_emit_record |
| 14483 | else |
| 14484 | if eq c 83 |
| 14485 | skipnl |
| 14486 | else |
| 14487 | if eq c 152 |
| 14488 | s_const |
| 14489 | else |
| 14490 | if or or eq c 85 eq c 78 eq c 79 |
| 14491 | fail 9 |
| 14492 | end |
| 14493 | fail 16 |
| 14494 | end |
| 14495 | end |
| 14496 | end |
| 14497 | end |
| 14498 | end |
| 14499 | end |
| 14500 | note ir_encode: header (magic, version 1, nfuncs) followed by every collected function record. |
| 14501 | put oc 0 0 |
| 14502 | emitb 79 |
| 14503 | emitb 83 |
| 14504 | emitb 67 |
| 14505 | emitb 49 |
| 14506 | emitb 73 |
| 14507 | emitb 82 |
| 14508 | emitb 0 |
| 14509 | emitb 1 |
| 14510 | ir_w16 get irnf 0 |
| 14511 | i = ulong 0 |
| 14512 | while lt i get irrlen 0 |
| 14513 | emitb get irrec i |
| 14514 | i = add i 1 |
| 14515 | end |
| 14516 | if ne get fmtm 0 0 |
| 14517 | fmtout |
| 14518 | end |
| 14519 | n = write 1 out 0 get oc 0 |
| 14520 | exit 0 |
| 14521 | end |
| 14522 | |
| 14523 | note ======== executable contract predicates (OM-2, native targets) ======== |
| 14524 | note Token packs below: Wolfram FromDigits[Reverse[ToCharacterCode[word]],256]. |
| 14525 | note Contract words are contextual: OM-1 name meanings and keyword-table bytes do not change. |
| 14526 | note Explicit native build policy, with syntax and purity checked in both policies. |
| 14527 | note om2 debug / om2 release and om2 diag debug / om2 diag release; fmt stays canonical. |
| 14528 | fn cp_mode q ulong to ulong |
| 14529 | if gt add q 4 get inlen 0 |
| 14530 | ret 0 |
| 14531 | end |
| 14532 | if ne get inp q 111 |
| 14533 | ret 0 |
| 14534 | end |
| 14535 | if ne get inp add q 1 109 |
| 14536 | ret 0 |
| 14537 | end |
| 14538 | if ne get inp add q 2 50 |
| 14539 | ret 0 |
| 14540 | end |
| 14541 | if ne get inp add q 3 32 |
| 14542 | ret 0 |
| 14543 | end |
| 14544 | p = add q 4 |
| 14545 | m = ulong 1 |
| 14546 | if le add p 5 get inlen 0 |
| 14547 | if and eq get inp p 100 eq get inp add p 1 105 |
| 14548 | if and eq get inp add p 2 97 eq get inp add p 3 103 |
| 14549 | if eq get inp add p 4 32 |
| 14550 | p = add p 5 |
| 14551 | m = ulong 2 |
| 14552 | end |
| 14553 | end |
| 14554 | end |
| 14555 | end |
| 14556 | if ne lineis p 28555834798400882 7 0 |
| 14557 | put crel 0 1 |
| 14558 | ret m |
| 14559 | end |
| 14560 | if ne lineis p 444351014244 5 0 |
| 14561 | ret m |
| 14562 | end |
| 14563 | ret 0 |
| 14564 | end |
| 14565 | |
| 14566 | fn cp_kind to ulong |
| 14567 | if and eq get om2 0 0 eq get irmode 0 0 |
| 14568 | ret 0 |
| 14569 | end |
| 14570 | if ne get tk 0 1 |
| 14571 | ret 0 |
| 14572 | end |
| 14573 | if and eq get tl 0 8 eq get tw 0 8315178084276987250 |
| 14574 | ret 1 |
| 14575 | end |
| 14576 | if and eq get tl 0 7 eq get tw 0 32481164592901733 |
| 14577 | ret 2 |
| 14578 | end |
| 14579 | if and eq get tl 0 9 eq get tw 0 7953754356895346281 |
| 14580 | if eq get inp add get ts 0 8 116 |
| 14581 | ret 3 |
| 14582 | end |
| 14583 | end |
| 14584 | ret 0 |
| 14585 | end |
| 14586 | |
| 14587 | note cp_next reads the next prefix clause, ignoring comments and blanks; a nonclause is unread. |
| 14588 | fn cp_next to ulong |
| 14589 | p = get cur 0 |
| 14590 | l = get line 0 |
| 14591 | go = true |
| 14592 | while go |
| 14593 | tok |
| 14594 | if eq get tk 0 1 |
| 14595 | if and eq get tl 0 4 eq get tw 0 1702129518 |
| 14596 | skipnl |
| 14597 | else |
| 14598 | go = false |
| 14599 | end |
| 14600 | else |
| 14601 | if ne get tk 0 0 |
| 14602 | go = false |
| 14603 | end |
| 14604 | end |
| 14605 | end |
| 14606 | k = cp_kind |
| 14607 | if eq k 0 |
| 14608 | put cur 0 p |
| 14609 | put line 0 l |
| 14610 | end |
| 14611 | ret k |
| 14612 | end |
| 14613 | |
| 14614 | note Recursive purity allowlist, before rdval dispatch. No calls, floats, host or mapped operations. |
| 14615 | fn cp_token to void |
| 14616 | if eq get tk 0 2 |
| 14617 | ret |
| 14618 | end |
| 14619 | if ne get tk 0 1 |
| 14620 | fail 30 |
| 14621 | end |
| 14622 | if gt get tl 0 8 |
| 14623 | fail 30 |
| 14624 | end |
| 14625 | c = kw get tw 0 |
| 14626 | if eq c 0 |
| 14627 | ret |
| 14628 | end |
| 14629 | if le sub c 1 8 |
| 14630 | ret |
| 14631 | end |
| 14632 | if le sub c 33 19 |
| 14633 | ret |
| 14634 | end |
| 14635 | if or eq c 55 eq c 56 |
| 14636 | ret |
| 14637 | end |
| 14638 | if or or eq c 59 eq c 60 eq c 74 |
| 14639 | ret |
| 14640 | end |
| 14641 | fail 30 |
| 14642 | end |
| 14643 | |
| 14644 | fn cp_erase to void |
| 14645 | put oc 0 get csnap 0 |
| 14646 | put nt 0 get csnap 1 |
| 14647 | put nsite 0 get csnap 2 |
| 14648 | put tgoc 0 get csnap 5 |
| 14649 | put lastb 0 get csnap 6 |
| 14650 | end |
| 14651 | |
| 14652 | fn cp_eval code ulong erase ulong to void |
| 14653 | ln = get line 0 |
| 14654 | rule = ulong 0 |
| 14655 | note Pure evaluation changes no names, calls, inline frames or writes. |
| 14656 | note Snapshot emission effects, including trap records, diagnostic sites and branch targets. |
| 14657 | put csnap 0 get oc 0 |
| 14658 | put csnap 1 get nt 0 |
| 14659 | put csnap 2 get nsite 0 |
| 14660 | put csnap 3 get nslot 0 |
| 14661 | put csnap 4 get fzone 0 |
| 14662 | put csnap 5 get tgoc 0 |
| 14663 | put csnap 6 get lastb 0 |
| 14664 | put cpure 0 1 |
| 14665 | put fzone 0 1 |
| 14666 | rdval 0 1 255 0 |
| 14667 | if ne get rt 0 1 |
| 14668 | fail 7 |
| 14669 | end |
| 14670 | eol |
| 14671 | nextln = get line 0 |
| 14672 | put line 0 ln |
| 14673 | if and eq get rk 0 3 ne get rv 0 0 |
| 14674 | rule = ulong 1 |
| 14675 | cp_erase |
| 14676 | else |
| 14677 | if or ne erase 0 ne get crel 0 0 |
| 14678 | rule = ulong 2 |
| 14679 | cp_erase |
| 14680 | else |
| 14681 | if eq get rk 0 3 |
| 14682 | trapc 14 code |
| 14683 | else |
| 14684 | if eq get rk 0 4 |
| 14685 | trapc xor get rv 0 1 code |
| 14686 | else |
| 14687 | r = matreg get rk 0 get rv 0 get rt 0 |
| 14688 | trapsite or 3019898880 r code |
| 14689 | end |
| 14690 | end |
| 14691 | end |
| 14692 | end |
| 14693 | if and eq get om2m 0 1 eq erase 0 |
| 14694 | cp_rec rule |
| 14695 | end |
| 14696 | put line 0 nextln |
| 14697 | put cpure 0 0 |
| 14698 | put cvalid 0 0 |
| 14699 | put fzone 0 get csnap 4 |
| 14700 | put nslot 0 get csnap 3 |
| 14701 | end |
| 14702 | |
| 14703 | note omc-check distinguishes a proof from release policy; initial deferred validation is silent. |
| 14704 | fn cp_rec rule ulong to void |
| 14705 | sitew 7162245557575183727 8 |
| 14706 | sitew 540090475 4 |
| 14707 | if eq rule 0 |
| 14708 | sitew 1953523051 4 |
| 14709 | else |
| 14710 | sitew 110386890240613 6 |
| 14711 | end |
| 14712 | sitew 67505853393952 6 |
| 14713 | siten add get line 0 get lbase 0 |
| 14714 | sitew 67505820627488 6 |
| 14715 | if eq rule 0 |
| 14716 | sitew 28549272340166002 7 |
| 14717 | end |
| 14718 | if eq rule 1 |
| 14719 | sitew 8389750308618530659 8 |
| 14720 | sitew 435762132013 5 |
| 14721 | end |
| 14722 | if eq rule 2 |
| 14723 | sitew 28555834798400882 7 |
| 14724 | end |
| 14725 | sitew 67501558426400 6 |
| 14726 | if eq get ckind 0 1 |
| 14727 | sitew 8315178084276987250 8 |
| 14728 | end |
| 14729 | if eq get ckind 0 2 |
| 14730 | sitew 32481164592901733 7 |
| 14731 | end |
| 14732 | if eq get ckind 0 3 |
| 14733 | sitew 7953754356895346281 8 |
| 14734 | siteb 116 |
| 14735 | end |
| 14736 | siteb 10 |
| 14737 | end |
| 14738 | |
| 14739 | note Function prefix predicates bind only globals and parameters visible on entry. |
| 14740 | fn cp_entry to void |
| 14741 | lv = get inl 0 |
| 14742 | put cfhas lv 0 |
| 14743 | if eq get om2 0 0 |
| 14744 | ret |
| 14745 | end |
| 14746 | put cfpos lv get cur 0 |
| 14747 | put cfline lv get line 0 |
| 14748 | put cflim lv get nn 0 |
| 14749 | put clim 0 get nn 0 |
| 14750 | k = cp_next |
| 14751 | n = ulong 0 |
| 14752 | while ne k 0 |
| 14753 | put ckind 0 k |
| 14754 | if ge n 64 |
| 14755 | fail 14 |
| 14756 | end |
| 14757 | if eq k 3 |
| 14758 | fail 30 |
| 14759 | end |
| 14760 | put crkind 0 0 |
| 14761 | if eq k 1 |
| 14762 | cp_eval 9 0 |
| 14763 | else |
| 14764 | put cfhas lv 1 |
| 14765 | ns = get nslot 0 |
| 14766 | put crtype 0 get curret 0 |
| 14767 | if ne get curret 0 12 |
| 14768 | put crkind 0 1 |
| 14769 | put crval 0 alloc |
| 14770 | end |
| 14771 | put cvalid 0 1 |
| 14772 | cp_eval 10 1 |
| 14773 | put nslot 0 ns |
| 14774 | end |
| 14775 | n = add n 1 |
| 14776 | k = cp_next |
| 14777 | end |
| 14778 | end |
| 14779 | |
| 14780 | note Return expressions are evaluated once, before postconditions, without overwriting argument X0. |
| 14781 | fn cp_post kind ulong value ulong ty ulong to void |
| 14782 | lv = get inl 0 |
| 14783 | if eq get cfhas lv 0 |
| 14784 | ret |
| 14785 | end |
| 14786 | p = get cur 0 |
| 14787 | l = get line 0 |
| 14788 | put cur 0 get cfpos lv |
| 14789 | put line 0 get cfline lv |
| 14790 | put clim 0 get cflim lv |
| 14791 | put crkind 0 kind |
| 14792 | put crval 0 value |
| 14793 | put crtype 0 ty |
| 14794 | k = cp_next |
| 14795 | while ne k 0 |
| 14796 | if eq k 2 |
| 14797 | put ckind 0 2 |
| 14798 | cp_eval 10 0 |
| 14799 | else |
| 14800 | skipnl |
| 14801 | end |
| 14802 | k = cp_next |
| 14803 | end |
| 14804 | put cur 0 p |
| 14805 | put line 0 l |
| 14806 | end |
| 14807 | |
| 14808 | note Loop invariants execute at the head, including zero trips and final false condition. |
| 14809 | note Continue reaches the checked head (for increments first); break bypasses it. |
| 14810 | fn cp_head pos ulong ln ulong to void |
| 14811 | if eq get om2 0 0 |
| 14812 | ret |
| 14813 | end |
| 14814 | p = get cur 0 |
| 14815 | l = get line 0 |
| 14816 | put cur 0 pos |
| 14817 | put line 0 ln |
| 14818 | put clim 0 get nn 0 |
| 14819 | put crkind 0 0 |
| 14820 | k = cp_next |
| 14821 | n = ulong 0 |
| 14822 | while eq k 3 |
| 14823 | put ckind 0 3 |
| 14824 | if ge n 64 |
| 14825 | fail 14 |
| 14826 | end |
| 14827 | cp_eval 10 0 |
| 14828 | n = add n 1 |
| 14829 | k = cp_next |
| 14830 | end |
| 14831 | put cur 0 p |
| 14832 | put line 0 l |
| 14833 | end |
| 14834 | |
| 14835 | note Head clauses have already been checked and emitted before the condition, never at body entry. |
| 14836 | fn cp_skip to void |
| 14837 | if eq get om2 0 0 |
| 14838 | ret |
| 14839 | end |
| 14840 | p = get cur 0 |
| 14841 | l = get line 0 |
| 14842 | k = cp_next |
| 14843 | while eq k 3 |
| 14844 | skipnl |
| 14845 | p = get cur 0 |
| 14846 | l = get line 0 |
| 14847 | k = cp_next |
| 14848 | end |
| 14849 | put cur 0 p |
| 14850 | put line 0 l |
| 14851 | end |
| 14852 | |
| 14853 | note main: read all of stdin |
| 14854 | note (8 MiB at most, error 14; a read error is 1), find the mode, then one |
| 14855 | note statement per line from output byte 180 (om4 START .. STMT) |
| 14856 | fn main to int |
| 14857 | off = ulong 0 |
| 14858 | go = true |
| 14859 | while go |
| 14860 | m = ulong 0 |
| 14861 | while and go lt m 999999 |
| 14862 | if ge off len inp |
| 14863 | fail 14 |
| 14864 | end |
| 14865 | n = read 0 inp off sub len inp off |
| 14866 | if eq n 0 |
| 14867 | go = false |
| 14868 | else |
| 14869 | if lt n 0 |
| 14870 | fail 1 |
| 14871 | end |
| 14872 | off = add off ulong n |
| 14873 | end |
| 14874 | m = add m 1 |
| 14875 | end |
| 14876 | end |
| 14877 | put inlen 0 off |
| 14878 | xlead |
| 14879 | chk_lead |
| 14880 | om2lead |
| 14881 | if eq get om2m 0 2 |
| 14882 | fmtprep |
| 14883 | end |
| 14884 | if ne ir_lead 0 |
| 14885 | put irmode 0 1 |
| 14886 | ir_run |
| 14887 | end |
| 14888 | prescan |
| 14889 | namescan |
| 14890 | if eq get nexp 0 0 |
| 14891 | put oc 0 180 |
| 14892 | else |
| 14893 | put oc 0 add 176 shl get nexp 0 2 |
| 14894 | end |
| 14895 | if ne get xtarget 0 0 |
| 14896 | put oc 0 512 |
| 14897 | if eq get xtarget 0 2 |
| 14898 | if eq get progmode 0 0 |
| 14899 | fail 25 |
| 14900 | end |
| 14901 | note The PE headers fill 520 bytes; code is mapped from file offset 512 at RVA 4096 (xefx 2). |
| 14902 | put oc 0 520 |
| 14903 | end |
| 14904 | if eq get progmode 0 0 |
| 14905 | m = get nexp 0 |
| 14906 | if eq m 0 |
| 14907 | m = ulong 1 |
| 14908 | end |
| 14909 | put oc 0 add 512 mul m 6 |
| 14910 | end |
| 14911 | end |
| 14912 | put line 0 1 |
| 14913 | done = false |
| 14914 | while not done |
| 14915 | m = ulong 0 |
| 14916 | while and not done lt m 999999 |
| 14917 | if ne stmt 0 |
| 14918 | done = true |
| 14919 | end |
| 14920 | m = add m 1 |
| 14921 | end |
| 14922 | end |
| 14923 | ret 0 |
| 14924 | end |
| 14925 | |
| 14926 | note Linux x86-64 host ABI: Linux v6.17 arch/x86/entry/syscalls/syscall_64.tbl. |
| 14927 | note RBX anchors the saved slot snapshot; preserve R13 (initial argument stack) in its spare tail. |
| 14928 | note R12 (nonlocal native return), R14 (runtime dispatch), R15 (stack floor) are never scratch. |
| 14929 | fn xhbegin to void |
| 14930 | save |
| 14931 | xmem 137 13 4 144 |
| 14932 | xrr 137 3 4 |
| 14933 | end |
| 14934 | fn xha x ulong i ulong r ulong to void |
| 14935 | q = add add x 8 mul i 2 |
| 14936 | k = get fr q |
| 14937 | v = get fr add q 1 |
| 14938 | if or eq k 3 eq k 7 |
| 14939 | ximm r v |
| 14940 | else |
| 14941 | if eq k 6 |
| 14942 | xaddr r v |
| 14943 | else |
| 14944 | xmem 139 r 3 mul v 8 |
| 14945 | end |
| 14946 | end |
| 14947 | end |
| 14948 | fn xhs r ulong s ulong to void |
| 14949 | xmem 139 r 3 mul s 8 |
| 14950 | end |
| 14951 | fn xhb r ulong e ulong off ulong to void |
| 14952 | if ge get nm_kind sub e 1 4 |
| 14953 | xaddr r get nm_addr sub e 1 |
| 14954 | else |
| 14955 | xhs r ulong get nm_reg sub e 1 |
| 14956 | end |
| 14957 | xhs 0 off |
| 14958 | xrr 1 r 0 |
| 14959 | end |
| 14960 | fn xhcall n ulong to void |
| 14961 | ximm 0 n |
| 14962 | emitb 15 |
| 14963 | emitb 5 |
| 14964 | end |
| 14965 | fn xhdone dst ulong x ulong bytes ulong to void |
| 14966 | xsp 0 bytes |
| 14967 | xmem 139 13 3 144 |
| 14968 | hreturn dst x |
| 14969 | end |
| 14970 | fn xhcmp r ulong v ulong to void |
| 14971 | ximm 11 v |
| 14972 | xrr 57 r 11 |
| 14973 | end |
| 14974 | fn xhadd r ulong v ulong to void |
| 14975 | ximm 11 v |
| 14976 | xrr 1 r 11 |
| 14977 | end |
| 14978 | fn xhsub r ulong v ulong to void |
| 14979 | ximm 11 v |
| 14980 | xrr 41 r 11 |
| 14981 | end |
| 14982 | fn xhraw r ulong b ulong off ulong size ulong to void |
| 14983 | emitb uchar add add 64 shl shr r 3 2 shr b 3 |
| 14984 | if lt size 4 |
| 14985 | emitb 15 |
| 14986 | if eq size 1 |
| 14987 | emitb 182 |
| 14988 | else |
| 14989 | emitb 183 |
| 14990 | end |
| 14991 | else |
| 14992 | emitb 139 |
| 14993 | end |
| 14994 | emitb uchar add add 128 shl and r 7 3 and b 7 |
| 14995 | if eq and b 7 4 |
| 14996 | emitb 36 |
| 14997 | end |
| 14998 | xword off |
| 14999 | end |
| 15000 | fn xhput r ulong b ulong off ulong size ulong to void |
| 15001 | if eq size 2 |
| 15002 | emitb 102 |
| 15003 | end |
| 15004 | emitb uchar add add 64 shl shr r 3 2 shr b 3 |
| 15005 | if eq size 1 |
| 15006 | emitb 136 |
| 15007 | else |
| 15008 | emitb 137 |
| 15009 | end |
| 15010 | emitb uchar add add 128 shl and r 7 3 and b 7 |
| 15011 | if eq and b 7 4 |
| 15012 | emitb 36 |
| 15013 | end |
| 15014 | xword off |
| 15015 | end |
| 15016 | fn xhpath x ulong to void |
| 15017 | xhb 6 get fr add x 20 get fr add x 21 |
| 15018 | xhs 2 get fr add x 22 |
| 15019 | xhcmp 2 4095 |
| 15020 | xtrap 8 3 |
| 15021 | xsp 1 4096 |
| 15022 | xrr 137 7 4 |
| 15023 | loop = get oc 0 |
| 15024 | xrr 133 2 2 |
| 15025 | done = xbranch 0 |
| 15026 | xhraw 0 6 0 1 |
| 15027 | xrr 133 0 0 |
| 15028 | xtrap 0 3 |
| 15029 | xhput 0 7 0 1 |
| 15030 | xhadd 6 1 |
| 15031 | xhadd 7 1 |
| 15032 | xhsub 2 1 |
| 15033 | p = xbranch 14 |
| 15034 | xpatch p loop |
| 15035 | xpatch done get oc 0 |
| 15036 | ximm 0 0 |
| 15037 | xhput 0 7 0 1 |
| 15038 | end |
| 15039 | fn xhscalar c ulong dst ulong x ulong to void |
| 15040 | np = hargc c |
| 15041 | for i ulong np |
| 15042 | ty = ulong 8 |
| 15043 | if or and eq c 103 eq i 1 and eq c 139 eq i 1 |
| 15044 | ty = ulong 9 |
| 15045 | end |
| 15046 | harg x i ty |
| 15047 | end |
| 15048 | xhbegin |
| 15049 | for i ulong np |
| 15050 | r = ulong 7 |
| 15051 | if eq i 1 |
| 15052 | r = ulong 6 |
| 15053 | end |
| 15054 | if eq i 2 |
| 15055 | r = ulong 2 |
| 15056 | end |
| 15057 | xha x i r |
| 15058 | end |
| 15059 | nr = ulong 292 |
| 15060 | if eq c 100 |
| 15061 | nr = ulong 3 |
| 15062 | end |
| 15063 | if eq c 101 |
| 15064 | nr = ulong 74 |
| 15065 | end |
| 15066 | if eq c 102 |
| 15067 | nr = ulong 91 |
| 15068 | end |
| 15069 | if eq c 103 |
| 15070 | nr = ulong 8 |
| 15071 | end |
| 15072 | if eq c 104 |
| 15073 | nr = ulong 41 |
| 15074 | end |
| 15075 | if eq c 105 |
| 15076 | nr = ulong 50 |
| 15077 | end |
| 15078 | if eq c 106 |
| 15079 | nr = ulong 288 |
| 15080 | xha x 1 10 |
| 15081 | ximm 6 0 |
| 15082 | ximm 2 0 |
| 15083 | end |
| 15084 | if eq c 107 |
| 15085 | nr = ulong 57 |
| 15086 | end |
| 15087 | if eq c 127 |
| 15088 | nr = ulong 62 |
| 15089 | end |
| 15090 | if eq c 129 |
| 15091 | nr = ulong 39 |
| 15092 | end |
| 15093 | if eq c 139 |
| 15094 | nr = ulong 77 |
| 15095 | end |
| 15096 | if eq c 145 |
| 15097 | nr = ulong 102 |
| 15098 | end |
| 15099 | if eq c 146 |
| 15100 | nr = ulong 107 |
| 15101 | end |
| 15102 | if eq c 147 |
| 15103 | nr = ulong 104 |
| 15104 | end |
| 15105 | if eq c 148 |
| 15106 | nr = ulong 108 |
| 15107 | end |
| 15108 | if eq c 153 |
| 15109 | nr = ulong 81 |
| 15110 | end |
| 15111 | if eq c 154 |
| 15112 | nr = ulong 110 |
| 15113 | end |
| 15114 | if eq c 155 |
| 15115 | nr = ulong 95 |
| 15116 | end |
| 15117 | if eq c 156 |
| 15118 | nr = ulong 75 |
| 15119 | end |
| 15120 | if eq c 158 |
| 15121 | nr = ulong 112 |
| 15122 | end |
| 15123 | if eq c 159 |
| 15124 | nr = ulong 121 |
| 15125 | end |
| 15126 | if eq c 160 |
| 15127 | nr = ulong 109 |
| 15128 | end |
| 15129 | if eq c 163 |
| 15130 | nr = ulong 124 |
| 15131 | end |
| 15132 | if eq c 164 |
| 15133 | nr = ulong 306 |
| 15134 | end |
| 15135 | if eq c 165 |
| 15136 | nr = ulong 48 |
| 15137 | end |
| 15138 | if eq c 197 |
| 15139 | nr = ulong 73 |
| 15140 | end |
| 15141 | xhcall nr |
| 15142 | xhdone dst x 0 |
| 15143 | end |
| 15144 | fn xhpaths c ulong dst ulong x ulong to void |
| 15145 | e = harray x 0 |
| 15146 | if or eq c 110 eq c 151 |
| 15147 | harg x 2 8 |
| 15148 | harg x 3 8 |
| 15149 | end |
| 15150 | if or or or eq c 112 eq c 143 eq c 144 eq c 157 |
| 15151 | harg x 2 8 |
| 15152 | end |
| 15153 | if eq c 150 |
| 15154 | harg x 2 9 |
| 15155 | end |
| 15156 | xhbegin |
| 15157 | xhpath x |
| 15158 | ximm 7 18446744073709551516 |
| 15159 | xrr 137 6 4 |
| 15160 | nr = ulong 257 |
| 15161 | if eq c 110 |
| 15162 | xha x 2 2 |
| 15163 | xha x 3 10 |
| 15164 | end |
| 15165 | if or eq c 111 eq c 126 |
| 15166 | nr = ulong 263 |
| 15167 | ximm 2 0 |
| 15168 | if eq c 126 |
| 15169 | ximm 2 512 |
| 15170 | end |
| 15171 | end |
| 15172 | if eq c 112 |
| 15173 | nr = ulong 258 |
| 15174 | xha x 2 2 |
| 15175 | end |
| 15176 | if eq c 138 |
| 15177 | nr = ulong 80 |
| 15178 | xrr 137 7 6 |
| 15179 | end |
| 15180 | if or eq c 143 eq c 144 |
| 15181 | nr = ulong 268 |
| 15182 | if eq c 144 |
| 15183 | nr = ulong 269 |
| 15184 | end |
| 15185 | xha x 2 2 |
| 15186 | ximm 10 0 |
| 15187 | end |
| 15188 | if eq c 150 |
| 15189 | nr = ulong 76 |
| 15190 | xrr 137 7 6 |
| 15191 | xha x 2 6 |
| 15192 | end |
| 15193 | if eq c 151 |
| 15194 | nr = ulong 260 |
| 15195 | xha x 2 2 |
| 15196 | xha x 3 10 |
| 15197 | ximm 8 0 |
| 15198 | end |
| 15199 | if eq c 157 |
| 15200 | nr = ulong 319 |
| 15201 | xrr 137 7 6 |
| 15202 | xha x 2 6 |
| 15203 | end |
| 15204 | xhcall nr |
| 15205 | xhdone dst x 4096 |
| 15206 | end |
| 15207 | note Native x86 struct stat is private; output remains Omega's 128-byte asm-generic ABI. |
| 15208 | fn xhstatcv to void |
| 15209 | xrr 133 0 0 |
| 15210 | bad = xbranch 11 |
| 15211 | ximm 2 0 |
| 15212 | for j ulong 16 |
| 15213 | xmem 137 2 13 mul j 8 |
| 15214 | end |
| 15215 | for j ulong 2 |
| 15216 | xmem 139 2 4 mul j 8 |
| 15217 | xmem 137 2 13 mul j 8 |
| 15218 | end |
| 15219 | xhraw 2 4 24 4 |
| 15220 | xhput 2 13 16 4 |
| 15221 | xhraw 2 4 16 4 |
| 15222 | xhput 2 13 20 4 |
| 15223 | xmem 139 2 4 28 |
| 15224 | xmem 137 2 13 24 |
| 15225 | xmem 139 2 4 40 |
| 15226 | xmem 137 2 13 32 |
| 15227 | xmem 139 2 4 48 |
| 15228 | xmem 137 2 13 48 |
| 15229 | xhraw 2 4 56 4 |
| 15230 | xhput 2 13 56 4 |
| 15231 | for j ulong 7 |
| 15232 | xmem 139 2 4 add 64 mul j 8 |
| 15233 | xmem 137 2 13 add 64 mul j 8 |
| 15234 | end |
| 15235 | ximm 0 0 |
| 15236 | xpatch bad get oc 0 |
| 15237 | end |
| 15238 | fn xhbuffer c ulong dst ulong x ulong to void |
| 15239 | harg x 4 8 |
| 15240 | wr = ulong 0 |
| 15241 | if or or or or or eq c 113 eq c 116 eq c 117 eq c 118 eq c 131 eq c 161 |
| 15242 | wr = ulong 1 |
| 15243 | end |
| 15244 | if eq c 224 |
| 15245 | wr = ulong 1 |
| 15246 | end |
| 15247 | e = harray x wr |
| 15248 | if or or eq c 116 eq c 118 eq c 119 |
| 15249 | harg x 2 8 |
| 15250 | end |
| 15251 | if or eq c 161 eq c 162 |
| 15252 | harg x 3 9 |
| 15253 | end |
| 15254 | xhbegin |
| 15255 | xha x 4 7 |
| 15256 | xhb 6 e get fr add x 21 |
| 15257 | xhs 2 get fr add x 22 |
| 15258 | nr = ulong 217 |
| 15259 | if or eq c 114 eq c 115 |
| 15260 | nr = ulong 42 |
| 15261 | if eq c 115 |
| 15262 | nr = ulong 49 |
| 15263 | end |
| 15264 | end |
| 15265 | if eq c 116 |
| 15266 | xhcmp 2 4 |
| 15267 | xtrap 3 3 |
| 15268 | nr = ulong 61 |
| 15269 | xha x 2 2 |
| 15270 | ximm 10 0 |
| 15271 | end |
| 15272 | if eq c 117 |
| 15273 | xhcmp 2 128 |
| 15274 | xtrap 3 3 |
| 15275 | xrr 137 13 6 |
| 15276 | xsp 1 144 |
| 15277 | xrr 137 6 4 |
| 15278 | xhcall 5 |
| 15279 | xhstatcv |
| 15280 | xhdone dst x 144 |
| 15281 | ret |
| 15282 | end |
| 15283 | if or eq c 118 eq c 119 |
| 15284 | nr = ulong 45 |
| 15285 | xha x 2 10 |
| 15286 | ximm 8 0 |
| 15287 | ximm 9 0 |
| 15288 | if eq c 119 |
| 15289 | nr = ulong 44 |
| 15290 | ximm 0 16384 |
| 15291 | xrr 9 10 0 |
| 15292 | end |
| 15293 | end |
| 15294 | if or eq c 131 eq c 224 |
| 15295 | note peername shares the private 32-bit socklen; x86-64 getsockname 51, getpeername 52. |
| 15296 | xsp 1 16 |
| 15297 | xhput 2 4 0 4 |
| 15298 | xrr 137 2 4 |
| 15299 | if eq c 224 |
| 15300 | xhcall 52 |
| 15301 | else |
| 15302 | xhcall 51 |
| 15303 | end |
| 15304 | xrr 133 0 0 |
| 15305 | bad = xbranch 11 |
| 15306 | xhraw 0 4 0 4 |
| 15307 | xpatch bad get oc 0 |
| 15308 | xhdone dst x 16 |
| 15309 | ret |
| 15310 | end |
| 15311 | if or eq c 161 eq c 162 |
| 15312 | nr = ulong 17 |
| 15313 | if eq c 162 |
| 15314 | nr = ulong 18 |
| 15315 | end |
| 15316 | xha x 3 10 |
| 15317 | end |
| 15318 | xhcall nr |
| 15319 | xhdone dst x 0 |
| 15320 | end |
| 15321 | fn xhstats c ulong dst ulong x ulong to void |
| 15322 | e = harray x 0 |
| 15323 | put fr add x 23 e |
| 15324 | put fr add x 24 get fr add x 21 |
| 15325 | put fr add x 25 get fr add x 22 |
| 15326 | e = harray x 1 |
| 15327 | put fr add x 26 e |
| 15328 | put fr add x 27 get fr add x 21 |
| 15329 | put fr add x 28 get fr add x 22 |
| 15330 | put fr add x 20 get fr add x 23 |
| 15331 | put fr add x 21 get fr add x 24 |
| 15332 | put fr add x 22 get fr add x 25 |
| 15333 | xhbegin |
| 15334 | xhs 2 get fr add x 22 |
| 15335 | xrr 133 2 2 |
| 15336 | xtrap 0 3 |
| 15337 | xhpath x |
| 15338 | xhb 13 e get fr add x 27 |
| 15339 | xhs 2 get fr add x 28 |
| 15340 | xhcmp 2 128 |
| 15341 | xtrap 3 3 |
| 15342 | ximm 7 18446744073709551516 |
| 15343 | xrr 137 6 4 |
| 15344 | xsp 1 144 |
| 15345 | xrr 137 2 4 |
| 15346 | ximm 10 0 |
| 15347 | if eq c 149 |
| 15348 | ximm 10 256 |
| 15349 | end |
| 15350 | xhcall 262 |
| 15351 | xhstatcv |
| 15352 | xhdone dst x 4240 |
| 15353 | end |
| 15354 | fn xhtime c ulong dst ulong x ulong to void |
| 15355 | if eq c 120 |
| 15356 | harg x 0 9 |
| 15357 | end |
| 15358 | xhbegin |
| 15359 | xsp 1 16 |
| 15360 | if eq c 120 |
| 15361 | xha x 0 0 |
| 15362 | xrr 133 0 0 |
| 15363 | xtrap 11 3 |
| 15364 | ximm 1 1000000000 |
| 15365 | ximm 2 0 |
| 15366 | xb 72 247 241 |
| 15367 | xmem 137 0 4 0 |
| 15368 | xmem 137 2 4 8 |
| 15369 | xrr 137 7 4 |
| 15370 | ximm 6 0 |
| 15371 | xhcall 35 |
| 15372 | else |
| 15373 | ximm 7 1 |
| 15374 | if eq c 130 |
| 15375 | ximm 7 0 |
| 15376 | end |
| 15377 | xrr 137 6 4 |
| 15378 | xhcall 228 |
| 15379 | xrr 133 0 0 |
| 15380 | bad = xbranch 11 |
| 15381 | xmem 139 2 4 0 |
| 15382 | xhcmp 2 9223372036 |
| 15383 | xtrap 8 1 |
| 15384 | ximm 0 1000000000 |
| 15385 | xb 72 15 175 |
| 15386 | emitb 194 |
| 15387 | xmem 139 2 4 8 |
| 15388 | xrr 1 0 2 |
| 15389 | xtrap 6 1 |
| 15390 | xpatch bad get oc 0 |
| 15391 | end |
| 15392 | xhdone dst x 16 |
| 15393 | end |
| 15394 | |
| 15395 | fn xrot ty ulong ra ulong b ulong imm ulong rd ulong to void |
| 15396 | xload 0 ra |
| 15397 | if ne imm 0 |
| 15398 | ximm 1 b |
| 15399 | else |
| 15400 | xload 1 b |
| 15401 | end |
| 15402 | if eq ty 3 |
| 15403 | emitb 102 |
| 15404 | end |
| 15405 | if eq ty 5 |
| 15406 | emitb 72 |
| 15407 | end |
| 15408 | if eq ty 2 |
| 15409 | emitb 210 |
| 15410 | else |
| 15411 | emitb 211 |
| 15412 | end |
| 15413 | emitb 200 |
| 15414 | xstore 0 rd |
| 15415 | canon rd ty |
| 15416 | end |
| 15417 | |
| 15418 | fn xhts off ulong to void |
| 15419 | xrr 133 2 2 |
| 15420 | forever = xbranch 11 |
| 15421 | xrr 137 0 2 |
| 15422 | ximm 1 1000000000 |
| 15423 | ximm 2 0 |
| 15424 | xb 72 247 241 |
| 15425 | xmem 137 0 4 off |
| 15426 | xmem 137 2 4 add off 8 |
| 15427 | xmem 141 2 4 off |
| 15428 | jump = xbranch 14 |
| 15429 | xpatch forever get oc 0 |
| 15430 | ximm 2 0 |
| 15431 | xpatch jump get oc 0 |
| 15432 | end |
| 15433 | fn xhpoll c ulong dst ulong x ulong to void |
| 15434 | if eq c 123 |
| 15435 | harg x 0 8 |
| 15436 | harg x 1 8 |
| 15437 | harg x 2 9 |
| 15438 | xhbegin |
| 15439 | xha x 0 7 |
| 15440 | xha x 1 6 |
| 15441 | xha x 2 2 |
| 15442 | xrr 133 6 6 |
| 15443 | xtrap 11 3 |
| 15444 | xhcmp 6 65535 |
| 15445 | xtrap 8 3 |
| 15446 | xsp 1 32 |
| 15447 | ximm 0 0 |
| 15448 | xmem 137 0 4 0 |
| 15449 | xhput 7 4 0 4 |
| 15450 | xhput 6 4 4 2 |
| 15451 | xhts 16 |
| 15452 | xrr 137 7 4 |
| 15453 | ximm 6 1 |
| 15454 | else |
| 15455 | e = harray x 1 |
| 15456 | harg x 2 9 |
| 15457 | xhbegin |
| 15458 | xhb 7 e get fr add x 21 |
| 15459 | xhs 6 get fr add x 22 |
| 15460 | xhcmp 6 8192 |
| 15461 | xtrap 8 3 |
| 15462 | xrr 137 0 6 |
| 15463 | ximm 1 7 |
| 15464 | xrr 33 0 1 |
| 15465 | xrr 133 0 0 |
| 15466 | xtrap 1 3 |
| 15467 | xb 72 193 238 |
| 15468 | emitb 3 |
| 15469 | xha x 2 2 |
| 15470 | xsp 1 32 |
| 15471 | xhts 16 |
| 15472 | end |
| 15473 | ximm 10 0 |
| 15474 | ximm 8 8 |
| 15475 | xhcall 271 |
| 15476 | if eq c 123 |
| 15477 | xrr 133 0 0 |
| 15478 | bad = xbranch 13 |
| 15479 | xhraw 0 4 6 2 |
| 15480 | xpatch bad get oc 0 |
| 15481 | end |
| 15482 | xhdone dst x 32 |
| 15483 | end |
| 15484 | fn xhargs c ulong dst ulong x ulong to void |
| 15485 | put hostargs 0 1 |
| 15486 | if or eq c 121 eq c 136 |
| 15487 | xhbegin |
| 15488 | xmem 139 0 13 0 |
| 15489 | if eq c 136 |
| 15490 | xmem 141 6 13 16 |
| 15491 | xb 72 193 224 |
| 15492 | emitb 3 |
| 15493 | xrr 1 6 0 |
| 15494 | ximm 0 0 |
| 15495 | loop = get oc 0 |
| 15496 | xmem 139 2 6 0 |
| 15497 | xrr 133 2 2 |
| 15498 | done = xbranch 0 |
| 15499 | xhadd 6 8 |
| 15500 | xhadd 0 1 |
| 15501 | p = xbranch 14 |
| 15502 | xpatch p loop |
| 15503 | xpatch done get oc 0 |
| 15504 | end |
| 15505 | xhdone dst x 0 |
| 15506 | ret |
| 15507 | end |
| 15508 | harg x 4 5 |
| 15509 | e = harray x 1 |
| 15510 | xhbegin |
| 15511 | xha x 4 2 |
| 15512 | xmem 139 1 13 0 |
| 15513 | xmem 141 6 13 8 |
| 15514 | if eq c 137 |
| 15515 | xhadd 1 1 |
| 15516 | xb 72 193 225 |
| 15517 | emitb 3 |
| 15518 | xrr 1 6 1 |
| 15519 | loop = get oc 0 |
| 15520 | xmem 139 0 6 0 |
| 15521 | xrr 133 0 0 |
| 15522 | xtrap 0 3 |
| 15523 | xrr 133 2 2 |
| 15524 | done = xbranch 0 |
| 15525 | xhsub 2 1 |
| 15526 | xhadd 6 8 |
| 15527 | p = xbranch 14 |
| 15528 | xpatch p loop |
| 15529 | xpatch done get oc 0 |
| 15530 | else |
| 15531 | xrr 57 2 1 |
| 15532 | xtrap 2 3 |
| 15533 | xb 72 193 226 |
| 15534 | emitb 3 |
| 15535 | xrr 1 6 2 |
| 15536 | end |
| 15537 | xmem 139 6 6 0 |
| 15538 | xrr 137 13 6 |
| 15539 | ximm 2 0 |
| 15540 | scan = get oc 0 |
| 15541 | xhraw 0 6 0 1 |
| 15542 | xrr 133 0 0 |
| 15543 | found = xbranch 0 |
| 15544 | xhadd 6 1 |
| 15545 | xhadd 2 1 |
| 15546 | xhcmp 2 1048576 |
| 15547 | xtrap 2 3 |
| 15548 | p = xbranch 14 |
| 15549 | xpatch p scan |
| 15550 | xpatch found get oc 0 |
| 15551 | xhs 1 get fr add x 22 |
| 15552 | xrr 57 2 1 |
| 15553 | small = xbranch 8 |
| 15554 | xhb 7 e get fr add x 21 |
| 15555 | xrr 137 6 13 |
| 15556 | xrr 137 1 2 |
| 15557 | emitb 243 |
| 15558 | emitb 164 |
| 15559 | xrr 137 0 2 |
| 15560 | tail = xbranch 14 |
| 15561 | xpatch small get oc 0 |
| 15562 | ximm 0 18446744073709551511 |
| 15563 | xpatch tail get oc 0 |
| 15564 | xhdone dst x 0 |
| 15565 | end |
| 15566 | fn xhsimple c ulong dst ulong x ulong to void |
| 15567 | e = harray x 1 |
| 15568 | if or eq c 128 eq c 135 |
| 15569 | harg x 2 8 |
| 15570 | end |
| 15571 | xhbegin |
| 15572 | xhb 7 e get fr add x 21 |
| 15573 | xhs 6 get fr add x 22 |
| 15574 | nr = ulong 79 |
| 15575 | if eq c 128 |
| 15576 | xhcmp 6 8 |
| 15577 | xtrap 3 3 |
| 15578 | xha x 2 6 |
| 15579 | nr = ulong 293 |
| 15580 | end |
| 15581 | if eq c 135 |
| 15582 | xha x 2 2 |
| 15583 | nr = ulong 318 |
| 15584 | end |
| 15585 | xhcall nr |
| 15586 | xhdone dst x 0 |
| 15587 | end |
| 15588 | fn xhreadln dst ulong x ulong to void |
| 15589 | e = harray x 0 |
| 15590 | put fr add x 23 e |
| 15591 | put fr add x 24 get fr add x 21 |
| 15592 | put fr add x 25 get fr add x 22 |
| 15593 | e = harray x 1 |
| 15594 | put fr add x 26 e |
| 15595 | put fr add x 27 get fr add x 21 |
| 15596 | put fr add x 28 get fr add x 22 |
| 15597 | put fr add x 20 get fr add x 23 |
| 15598 | put fr add x 21 get fr add x 24 |
| 15599 | put fr add x 22 get fr add x 25 |
| 15600 | xhbegin |
| 15601 | xhs 2 get fr add x 22 |
| 15602 | xrr 133 2 2 |
| 15603 | xtrap 0 3 |
| 15604 | xhpath x |
| 15605 | xhb 2 e get fr add x 27 |
| 15606 | xhs 10 get fr add x 28 |
| 15607 | ximm 7 18446744073709551516 |
| 15608 | xrr 137 6 4 |
| 15609 | xhcall 267 |
| 15610 | xhdone dst x 4096 |
| 15611 | end |
| 15612 | fn xhsock c ulong dst ulong x ulong to void |
| 15613 | ok = new ulong 6 0 |
| 15614 | if eq c 134 |
| 15615 | harg x 2 8 |
| 15616 | harg x 3 8 |
| 15617 | harg x 4 8 |
| 15618 | e = harray x 0 |
| 15619 | xhbegin |
| 15620 | xha x 2 7 |
| 15621 | xha x 3 6 |
| 15622 | xha x 4 2 |
| 15623 | xhb 10 e get fr add x 21 |
| 15624 | xhs 8 get fr add x 22 |
| 15625 | xhcmp 6 1 |
| 15626 | tcp = xbranch 1 |
| 15627 | for j ulong 5 |
| 15628 | v = add j 5 |
| 15629 | if eq j 0 |
| 15630 | v = ulong 2 |
| 15631 | end |
| 15632 | if eq j 1 |
| 15633 | v = ulong 15 |
| 15634 | end |
| 15635 | xhcmp 2 v |
| 15636 | put ok j xbranch 0 |
| 15637 | end |
| 15638 | badso = xbranch 14 |
| 15639 | xpatch tcp get oc 0 |
| 15640 | xhcmp 6 6 |
| 15641 | badtcp = xbranch 1 |
| 15642 | xhcmp 2 1 |
| 15643 | put ok 5 xbranch 0 |
| 15644 | xpatch badso get oc 0 |
| 15645 | xpatch badtcp get oc 0 |
| 15646 | ximm 0 sub ulong 0 92 |
| 15647 | done = xbranch 14 |
| 15648 | for j ulong 6 |
| 15649 | xpatch get ok j get oc 0 |
| 15650 | end |
| 15651 | xhcmp 8 4 |
| 15652 | sizeok = xbranch 0 |
| 15653 | ximm 0 sub ulong 0 22 |
| 15654 | badsize = xbranch 14 |
| 15655 | xpatch sizeok get oc 0 |
| 15656 | xhcall 54 |
| 15657 | xpatch done get oc 0 |
| 15658 | xpatch badsize get oc 0 |
| 15659 | xhdone dst x 0 |
| 15660 | ret |
| 15661 | end |
| 15662 | harg x 4 8 |
| 15663 | if eq c 220 |
| 15664 | e = harray x 1 |
| 15665 | xhbegin |
| 15666 | xha x 4 7 |
| 15667 | xhb 10 e get fr add x 21 |
| 15668 | xhs 8 get fr add x 22 |
| 15669 | xhcmp 8 12 |
| 15670 | xtrap 3 3 |
| 15671 | ximm 6 1 |
| 15672 | ximm 2 17 |
| 15673 | xsp 1 16 |
| 15674 | ximm 8 12 |
| 15675 | xhput 8 4 0 4 |
| 15676 | xrr 137 8 4 |
| 15677 | xhcall 55 |
| 15678 | xhdone dst x 16 |
| 15679 | ret |
| 15680 | end |
| 15681 | e = harray x 0 |
| 15682 | harg x 2 8 |
| 15683 | xhbegin |
| 15684 | xha x 4 7 |
| 15685 | xha x 2 2 |
| 15686 | ximm 0 16384 |
| 15687 | xrr 9 2 0 |
| 15688 | xhb 6 e get fr add x 21 |
| 15689 | xhs 8 get fr add x 22 |
| 15690 | xsp 1 80 |
| 15691 | ximm 0 0 |
| 15692 | for j ulong 10 |
| 15693 | xmem 137 0 4 mul j 8 |
| 15694 | end |
| 15695 | xmem 137 6 4 64 |
| 15696 | xmem 137 8 4 72 |
| 15697 | xmem 141 6 4 64 |
| 15698 | xmem 137 6 4 16 |
| 15699 | ximm 6 1 |
| 15700 | xmem 137 6 4 24 |
| 15701 | xrr 137 6 4 |
| 15702 | xhcall 46 |
| 15703 | xhdone dst x 80 |
| 15704 | end |
| 15705 | note execenv 233 on x86-64: as on AArch64, a second pass decodes the environment packet (every record |
| 15706 | note nonempty) into env strings at RSP+8192 and env pointers at RSP+12288; both checks precede close_range. |
| 15707 | fn xhpack c ulong dst ulong x ulong to void |
| 15708 | e = harray x 0 |
| 15709 | if eq c 125 |
| 15710 | harg x 2 8 |
| 15711 | end |
| 15712 | if eq c 233 |
| 15713 | put fr add x 23 e |
| 15714 | put fr add x 24 get fr add x 21 |
| 15715 | put fr add x 25 get fr add x 22 |
| 15716 | e = harray x 0 |
| 15717 | put fr add x 26 e |
| 15718 | put fr add x 27 get fr add x 21 |
| 15719 | put fr add x 28 get fr add x 22 |
| 15720 | put fr add x 20 get fr add x 23 |
| 15721 | put fr add x 21 get fr add x 24 |
| 15722 | put fr add x 22 get fr add x 25 |
| 15723 | e = get fr add x 23 |
| 15724 | end |
| 15725 | xhbegin |
| 15726 | note stack is 8192 bytes per packet; the pass bound is stack >> 13 (two passes for execenv). |
| 15727 | stack = ulong 8192 |
| 15728 | if eq c 233 |
| 15729 | stack = ulong 16384 |
| 15730 | end |
| 15731 | pass = ulong 0 |
| 15732 | while lt pass shr stack 13 |
| 15733 | if eq pass 0 |
| 15734 | xhb 6 e get fr add x 21 |
| 15735 | xhs 2 get fr add x 22 |
| 15736 | else |
| 15737 | note The slot snapshot is RBX-relative, so the environment slice is read after the RSP move. |
| 15738 | xhb 6 get fr add x 26 get fr add x 27 |
| 15739 | xhs 2 get fr add x 28 |
| 15740 | end |
| 15741 | xhcmp 2 4096 |
| 15742 | xtrap 8 3 |
| 15743 | xhcmp 2 2 |
| 15744 | xtrap 3 3 |
| 15745 | xhraw 8 6 0 2 |
| 15746 | xhadd 6 2 |
| 15747 | xhsub 2 2 |
| 15748 | xrr 133 8 8 |
| 15749 | xtrap 0 3 |
| 15750 | xhcmp 8 64 |
| 15751 | xtrap 8 3 |
| 15752 | if or or eq c 125 eq c 141 eq c 142 |
| 15753 | xhcmp 8 2 |
| 15754 | xtrap 1 3 |
| 15755 | end |
| 15756 | if eq pass 0 |
| 15757 | xsp 1 stack |
| 15758 | xrr 137 10 4 |
| 15759 | xmem 141 13 4 4096 |
| 15760 | else |
| 15761 | xmem 141 10 4 8192 |
| 15762 | xmem 141 13 4 12288 |
| 15763 | end |
| 15764 | ximm 9 0 |
| 15765 | outer = get oc 0 |
| 15766 | xrr 57 9 8 |
| 15767 | done = xbranch 2 |
| 15768 | xhcmp 2 2 |
| 15769 | xtrap 3 3 |
| 15770 | xhraw 1 6 0 2 |
| 15771 | xhadd 6 2 |
| 15772 | xhsub 2 2 |
| 15773 | xrr 57 1 2 |
| 15774 | xtrap 8 3 |
| 15775 | if and eq pass 0 or eq c 124 eq c 233 |
| 15776 | xrr 133 9 9 |
| 15777 | notfirst = xbranch 1 |
| 15778 | xrr 133 1 1 |
| 15779 | xtrap 0 3 |
| 15780 | xpatch notfirst get oc 0 |
| 15781 | else |
| 15782 | xrr 133 1 1 |
| 15783 | xtrap 0 3 |
| 15784 | end |
| 15785 | xmem 137 10 13 0 |
| 15786 | xhadd 13 8 |
| 15787 | xrr 41 2 1 |
| 15788 | inner = get oc 0 |
| 15789 | xrr 133 1 1 |
| 15790 | endstr = xbranch 0 |
| 15791 | xhraw 0 6 0 1 |
| 15792 | xrr 133 0 0 |
| 15793 | xtrap 0 3 |
| 15794 | xhput 0 10 0 1 |
| 15795 | xhadd 6 1 |
| 15796 | xhadd 10 1 |
| 15797 | xhsub 1 1 |
| 15798 | p = xbranch 14 |
| 15799 | xpatch p inner |
| 15800 | xpatch endstr get oc 0 |
| 15801 | ximm 0 0 |
| 15802 | xhput 0 10 0 1 |
| 15803 | xhadd 10 1 |
| 15804 | xhadd 9 1 |
| 15805 | p = xbranch 14 |
| 15806 | xpatch p outer |
| 15807 | xpatch done get oc 0 |
| 15808 | xrr 133 2 2 |
| 15809 | xtrap 1 3 |
| 15810 | ximm 0 0 |
| 15811 | xmem 137 0 13 0 |
| 15812 | pass = add pass 1 |
| 15813 | end |
| 15814 | if or eq c 124 eq c 233 |
| 15815 | note As on AArch64: close_range(3, ~0U, CLOSE_RANGE_UNSHARE) first; a nonzero result skips execve |
| 15816 | note and returns that kernel error. RDI/RSI/RDX are reloaded after the call; R13 holds the argv end. |
| 15817 | ximm 7 3 |
| 15818 | ximm 6 4294967295 |
| 15819 | ximm 2 2 |
| 15820 | xhcall 436 |
| 15821 | xrr 133 0 0 |
| 15822 | p = xbranch 1 |
| 15823 | xmem 139 7 4 4096 |
| 15824 | xmem 141 6 4 4096 |
| 15825 | if eq c 233 |
| 15826 | xmem 141 2 4 12288 |
| 15827 | else |
| 15828 | xrr 137 2 13 |
| 15829 | end |
| 15830 | xhcall 59 |
| 15831 | xpatch p get oc 0 |
| 15832 | else |
| 15833 | xmem 139 6 4 4096 |
| 15834 | xmem 139 10 4 4104 |
| 15835 | ximm 7 18446744073709551516 |
| 15836 | ximm 2 18446744073709551516 |
| 15837 | ximm 8 0 |
| 15838 | if eq c 125 |
| 15839 | xha x 2 8 |
| 15840 | xhcall 316 |
| 15841 | else |
| 15842 | if eq c 141 |
| 15843 | xhcall 265 |
| 15844 | else |
| 15845 | xrr 137 7 6 |
| 15846 | ximm 6 18446744073709551516 |
| 15847 | xrr 137 2 10 |
| 15848 | xhcall 266 |
| 15849 | end |
| 15850 | end |
| 15851 | end |
| 15852 | xhdone dst x stack |
| 15853 | end |
| 15854 | note Hosted handles use the entry31 context header and 13 slot bits; programs retain raw128 slots. |
| 15855 | fn xhmcheck to void |
| 15856 | xrr 137 13 10 |
| 15857 | if eq get progmode 0 0 |
| 15858 | ximm 0 8191 |
| 15859 | else |
| 15860 | ximm 0 255 |
| 15861 | end |
| 15862 | xrr 33 13 0 |
| 15863 | xhcmp 13 1 |
| 15864 | xtrap 3 3 |
| 15865 | if eq get progmode 0 0 |
| 15866 | xmem 139 0 14 248 |
| 15867 | xmem 139 0 0 0 |
| 15868 | xhcmp 0 1 |
| 15869 | xtrap 3 3 |
| 15870 | xhcmp 0 4098 |
| 15871 | xtrap 8 3 |
| 15872 | xrr 57 13 0 |
| 15873 | xtrap 8 3 |
| 15874 | else |
| 15875 | xhcmp 13 128 |
| 15876 | xtrap 8 3 |
| 15877 | end |
| 15878 | xhsub 13 1 |
| 15879 | xb 73 193 229 |
| 15880 | emitb 5 |
| 15881 | if eq get progmode 0 0 |
| 15882 | xmem 139 0 14 248 |
| 15883 | xhadd 0 32 |
| 15884 | else |
| 15885 | xaddr 0 get maptab 0 |
| 15886 | end |
| 15887 | xrr 1 13 0 |
| 15888 | xmem 139 9 13 16 |
| 15889 | xrr 133 9 9 |
| 15890 | xtrap 0 3 |
| 15891 | xb 73 193 234 |
| 15892 | if eq get progmode 0 0 |
| 15893 | emitb 13 |
| 15894 | else |
| 15895 | emitb 8 |
| 15896 | end |
| 15897 | xrr 57 10 9 |
| 15898 | xtrap 1 3 |
| 15899 | xmem 139 8 13 0 |
| 15900 | xrr 133 8 8 |
| 15901 | xtrap 0 3 |
| 15902 | xmem 139 9 13 8 |
| 15903 | end |
| 15904 | fn xhmnew c ulong dst ulong x ulong to void |
| 15905 | acc = ulong 0 |
| 15906 | mode = ulong 1048610 |
| 15907 | if eq c 167 |
| 15908 | harg x 0 8 |
| 15909 | harg x 1 5 |
| 15910 | harg x 2 5 |
| 15911 | harg x 3 8 |
| 15912 | harg x 4 8 |
| 15913 | if or ne get fr add x 14 3 ne get fr add x 16 3 |
| 15914 | fail 9 |
| 15915 | end |
| 15916 | acc = get fr add x 15 |
| 15917 | mode = get fr add x 17 |
| 15918 | if and ne acc 1 ne acc 3 |
| 15919 | fail 9 |
| 15920 | end |
| 15921 | if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34 |
| 15922 | fail 9 |
| 15923 | end |
| 15924 | else |
| 15925 | harg x 1 5 |
| 15926 | harg x 2 5 |
| 15927 | end |
| 15928 | xhbegin |
| 15929 | xha x 2 6 |
| 15930 | xrr 133 6 6 |
| 15931 | xtrap 0 3 |
| 15932 | xhcmp 6 68719476736 |
| 15933 | xtrap 8 3 |
| 15934 | if eq c 167 |
| 15935 | xha x 0 8 |
| 15936 | xha x 1 9 |
| 15937 | if ge mode 32 |
| 15938 | xhcmp 8 18446744073709551615 |
| 15939 | xtrap 1 3 |
| 15940 | xrr 133 9 9 |
| 15941 | xtrap 1 3 |
| 15942 | end |
| 15943 | else |
| 15944 | xha x 1 7 |
| 15945 | xhcmp 7 65536 |
| 15946 | xtrap 3 3 |
| 15947 | ximm 0 1099511627776 |
| 15948 | xrr 41 0 6 |
| 15949 | xrr 57 7 0 |
| 15950 | xtrap 8 3 |
| 15951 | ximm 0 4095 |
| 15952 | xrr 137 1 7 |
| 15953 | xrr 33 1 0 |
| 15954 | xrr 133 1 1 |
| 15955 | xtrap 1 3 |
| 15956 | xrr 137 1 6 |
| 15957 | xrr 33 1 0 |
| 15958 | xrr 133 1 1 |
| 15959 | xtrap 1 3 |
| 15960 | ximm 8 18446744073709551615 |
| 15961 | ximm 9 0 |
| 15962 | end |
| 15963 | if eq get progmode 0 0 |
| 15964 | xmem 139 13 14 248 |
| 15965 | xmem 139 0 13 0 |
| 15966 | xhcmp 0 1 |
| 15967 | xtrap 3 3 |
| 15968 | xhcmp 0 4098 |
| 15969 | xtrap 8 3 |
| 15970 | xmem 139 0 13 16 |
| 15971 | xhcmp 0 1 |
| 15972 | xtrap 3 3 |
| 15973 | xhcmp 0 1125899906842623 |
| 15974 | xtrap 8 3 |
| 15975 | xhadd 13 32 |
| 15976 | else |
| 15977 | xaddr 13 get maptab 0 |
| 15978 | end |
| 15979 | ximm 2 1 |
| 15980 | head = get oc 0 |
| 15981 | xmem 139 0 13 0 |
| 15982 | xrr 133 0 0 |
| 15983 | used = xbranch 1 |
| 15984 | xmem 139 10 13 16 |
| 15985 | if eq get progmode 0 0 |
| 15986 | xmem 139 11 14 248 |
| 15987 | xmem 139 11 11 16 |
| 15988 | xrr 57 10 11 |
| 15989 | else |
| 15990 | xhcmp 10 36028797018963967 |
| 15991 | end |
| 15992 | vacant = xbranch 3 |
| 15993 | xpatch used get oc 0 |
| 15994 | xhadd 13 32 |
| 15995 | xhadd 2 1 |
| 15996 | if eq get progmode 0 0 |
| 15997 | xmem 139 11 14 248 |
| 15998 | xmem 139 11 11 0 |
| 15999 | xrr 57 2 11 |
| 16000 | else |
| 16001 | xhcmp 2 128 |
| 16002 | end |
| 16003 | again = xbranch 9 |
| 16004 | xpatch again head |
| 16005 | ximm 0 sub ulong 0 24 |
| 16006 | full = xbranch 14 |
| 16007 | xpatch vacant get oc 0 |
| 16008 | xsp 1 32 |
| 16009 | xmem 137 2 4 0 |
| 16010 | xmem 137 6 4 8 |
| 16011 | xmem 137 10 4 16 |
| 16012 | if eq c 167 |
| 16013 | ximm 7 0 |
| 16014 | else |
| 16015 | xha x 1 7 |
| 16016 | end |
| 16017 | ximm 2 acc |
| 16018 | ximm 10 mode |
| 16019 | xhcall 9 |
| 16020 | xrr 133 0 0 |
| 16021 | failed = xbranch 11 |
| 16022 | wrong = ulong 0 |
| 16023 | if eq c 176 |
| 16024 | xha x 1 2 |
| 16025 | xrr 57 0 2 |
| 16026 | exact = xbranch 0 |
| 16027 | xrr 137 7 0 |
| 16028 | xmem 139 6 4 8 |
| 16029 | xhcall 11 |
| 16030 | xrr 133 0 0 |
| 16031 | xtrap 1 3 |
| 16032 | ximm 0 sub ulong 0 95 |
| 16033 | wrong = xbranch 14 |
| 16034 | xpatch exact get oc 0 |
| 16035 | end |
| 16036 | xmem 137 0 13 0 |
| 16037 | xmem 139 2 4 8 |
| 16038 | xmem 137 2 13 8 |
| 16039 | xmem 139 2 4 16 |
| 16040 | xhadd 2 1 |
| 16041 | xmem 137 2 13 16 |
| 16042 | ximm 0 acc |
| 16043 | xmem 137 0 13 24 |
| 16044 | xrr 137 0 2 |
| 16045 | xb 72 193 224 |
| 16046 | if eq get progmode 0 0 |
| 16047 | emitb 13 |
| 16048 | else |
| 16049 | emitb 8 |
| 16050 | end |
| 16051 | xmem 139 2 4 0 |
| 16052 | xrr 9 0 2 |
| 16053 | xpatch failed get oc 0 |
| 16054 | if ne wrong 0 |
| 16055 | xpatch wrong get oc 0 |
| 16056 | end |
| 16057 | xsp 0 32 |
| 16058 | xpatch full get oc 0 |
| 16059 | xhdone dst x 0 |
| 16060 | end |
| 16061 | fn xhmbind dst ulong x ulong to void |
| 16062 | harg x 0 9 |
| 16063 | harg x 1 8 |
| 16064 | harg x 2 5 |
| 16065 | harg x 3 8 |
| 16066 | if ne get fr add x 14 3 |
| 16067 | fail 9 |
| 16068 | end |
| 16069 | acc = get fr add x 15 |
| 16070 | if and ne acc 1 ne acc 3 |
| 16071 | fail 9 |
| 16072 | end |
| 16073 | xhbegin |
| 16074 | xha x 0 10 |
| 16075 | xhmcheck |
| 16076 | xmem 139 0 13 24 |
| 16077 | xrr 133 0 0 |
| 16078 | xtrap 1 3 |
| 16079 | xsp 1 32 |
| 16080 | xmem 137 8 4 0 |
| 16081 | xmem 137 9 4 8 |
| 16082 | xrr 137 7 8 |
| 16083 | xrr 137 6 9 |
| 16084 | xha x 1 8 |
| 16085 | xha x 2 9 |
| 16086 | ximm 2 acc |
| 16087 | ximm 10 17 |
| 16088 | xhcall 9 |
| 16089 | xrr 133 0 0 |
| 16090 | failed = xbranch 11 |
| 16091 | xmem 139 2 4 0 |
| 16092 | xrr 57 0 2 |
| 16093 | xtrap 1 3 |
| 16094 | ximm 0 acc |
| 16095 | xmem 137 0 13 24 |
| 16096 | ximm 0 0 |
| 16097 | done = xbranch 14 |
| 16098 | xpatch failed get oc 0 |
| 16099 | xmem 137 0 4 16 |
| 16100 | ximm 0 4 |
| 16101 | xmem 137 0 13 24 |
| 16102 | xmem 139 7 4 0 |
| 16103 | xmem 139 6 4 8 |
| 16104 | xhcall 11 |
| 16105 | xrr 133 0 0 |
| 16106 | xtrap 1 3 |
| 16107 | ximm 0 0 |
| 16108 | xmem 137 0 13 0 |
| 16109 | xmem 137 0 13 8 |
| 16110 | xmem 137 0 13 24 |
| 16111 | xmem 139 0 4 16 |
| 16112 | xpatch done get oc 0 |
| 16113 | xhdone dst x 32 |
| 16114 | end |
| 16115 | fn xhmcopy c ulong dst ulong x ulong to void |
| 16116 | harg x 4 9 |
| 16117 | harg x 3 5 |
| 16118 | wr = ulong 0 |
| 16119 | if eq c 169 |
| 16120 | wr = ulong 1 |
| 16121 | end |
| 16122 | e = harray x wr |
| 16123 | xhbegin |
| 16124 | xha x 4 10 |
| 16125 | xhmcheck |
| 16126 | xmem 139 0 13 24 |
| 16127 | xrr 133 0 0 |
| 16128 | xtrap 0 3 |
| 16129 | xhcmp 0 3 |
| 16130 | xtrap 8 3 |
| 16131 | xha x 3 2 |
| 16132 | xrr 57 2 9 |
| 16133 | xtrap 8 3 |
| 16134 | xrr 41 9 2 |
| 16135 | xhs 1 get fr add x 22 |
| 16136 | xrr 57 1 9 |
| 16137 | xtrap 8 3 |
| 16138 | xrr 1 8 2 |
| 16139 | xhb 7 e get fr add x 21 |
| 16140 | xrr 137 6 8 |
| 16141 | if eq c 170 |
| 16142 | xmem 139 0 13 24 |
| 16143 | xhcmp 0 3 |
| 16144 | xtrap 1 3 |
| 16145 | xrr 137 6 7 |
| 16146 | xrr 137 7 8 |
| 16147 | end |
| 16148 | xrr 137 2 1 |
| 16149 | emitb 243 |
| 16150 | emitb 164 |
| 16151 | xrr 137 0 2 |
| 16152 | xhdone dst x 0 |
| 16153 | end |
| 16154 | fn xhmmio c ulong dst ulong x ulong to void |
| 16155 | harg x 0 9 |
| 16156 | if eq c 173 |
| 16157 | xhbegin |
| 16158 | xha x 0 10 |
| 16159 | xhmcheck |
| 16160 | xrr 137 0 8 |
| 16161 | xhdone dst x 0 |
| 16162 | put rt 0 5 |
| 16163 | ret |
| 16164 | end |
| 16165 | harg x 1 5 |
| 16166 | harg x 2 8 |
| 16167 | if ne get fr add x 12 3 |
| 16168 | fail 9 |
| 16169 | end |
| 16170 | w = get fr add x 13 |
| 16171 | if and ne w 4 ne w 8 |
| 16172 | fail 9 |
| 16173 | end |
| 16174 | if eq c 175 |
| 16175 | harg x 3 5 |
| 16176 | end |
| 16177 | xhbegin |
| 16178 | xha x 0 10 |
| 16179 | xhmcheck |
| 16180 | xha x 1 2 |
| 16181 | xmem 139 0 13 24 |
| 16182 | xrr 133 0 0 |
| 16183 | xtrap 0 3 |
| 16184 | xhcmp 0 3 |
| 16185 | xtrap 8 3 |
| 16186 | xrr 57 2 9 |
| 16187 | xtrap 8 3 |
| 16188 | xrr 41 9 2 |
| 16189 | xhcmp 9 w |
| 16190 | xtrap 3 3 |
| 16191 | xrr 137 0 2 |
| 16192 | ximm 1 sub w 1 |
| 16193 | xrr 33 0 1 |
| 16194 | xrr 133 0 0 |
| 16195 | xtrap 1 3 |
| 16196 | xrr 1 8 2 |
| 16197 | if eq c 175 |
| 16198 | xmem 139 0 13 24 |
| 16199 | xhcmp 0 3 |
| 16200 | xtrap 1 3 |
| 16201 | xha x 3 2 |
| 16202 | if eq w 4 |
| 16203 | xhcmp 2 4294967295 |
| 16204 | xtrap 8 3 |
| 16205 | end |
| 16206 | xb 15 174 240 |
| 16207 | if eq w 4 |
| 16208 | xhput 2 8 0 4 |
| 16209 | else |
| 16210 | xmem 137 2 8 0 |
| 16211 | end |
| 16212 | xb 15 174 240 |
| 16213 | ximm 0 0 |
| 16214 | xhdone dst x 0 |
| 16215 | else |
| 16216 | xb 15 174 240 |
| 16217 | if eq w 4 |
| 16218 | xhraw 0 8 0 4 |
| 16219 | else |
| 16220 | xmem 139 0 8 0 |
| 16221 | end |
| 16222 | xb 15 174 240 |
| 16223 | xhdone dst x 0 |
| 16224 | put rt 0 5 |
| 16225 | end |
| 16226 | end |
| 16227 | note One compile-time ioctl allowlist is shared by both native Linux backends. |
| 16228 | fn xhreq c ulong x ulong to ulong |
| 16229 | harg x 4 8 |
| 16230 | harg x 2 4 |
| 16231 | if ne get fr add x 12 3 |
| 16232 | fail 9 |
| 16233 | end |
| 16234 | q = get fr add x 13 |
| 16235 | n = ulong 4 |
| 16236 | if eq c 166 |
| 16237 | if ne q 21531 |
| 16238 | if ne and q 3221290752 3221243392 |
| 16239 | ok = eq q 2154840336 |
| 16240 | ok = or ok eq q 3224387873 |
| 16241 | ok = or ok eq q 3222815010 |
| 16242 | ok = or ok eq q 3225960739 |
| 16243 | ok = or ok eq q 3222815012 |
| 16244 | if not ok |
| 16245 | fail 9 |
| 16246 | end |
| 16247 | end |
| 16248 | n = and shr q 16 16383 |
| 16249 | if eq n 0 |
| 16250 | fail 9 |
| 16251 | end |
| 16252 | end |
| 16253 | end |
| 16254 | if eq c 172 |
| 16255 | n = ulong 0 |
| 16256 | if eq q 805306369 |
| 16257 | n = ulong 16 |
| 16258 | end |
| 16259 | if eq q 75 |
| 16260 | n = ulong 8 |
| 16261 | end |
| 16262 | if eq q 37 |
| 16263 | n = ulong 40 |
| 16264 | end |
| 16265 | if or eq q 38 eq q 26 |
| 16266 | n = ulong 20 |
| 16267 | end |
| 16268 | if eq q 25 |
| 16269 | n = ulong 32 |
| 16270 | end |
| 16271 | if eq q 27 |
| 16272 | n = ulong 56 |
| 16273 | end |
| 16274 | if eq q 28 |
| 16275 | n = ulong 28 |
| 16276 | end |
| 16277 | if eq q 33 |
| 16278 | n = ulong 9264 |
| 16279 | end |
| 16280 | if or eq q 34 eq q 73 |
| 16281 | n = ulong 24 |
| 16282 | end |
| 16283 | if eq n 0 |
| 16284 | fail 9 |
| 16285 | end |
| 16286 | end |
| 16287 | if eq c 171 |
| 16288 | if and ne q 3223340586 ne q 3223340587 |
| 16289 | fail 9 |
| 16290 | end |
| 16291 | n = ulong 32 |
| 16292 | end |
| 16293 | ret n |
| 16294 | end |
| 16295 | fn xhdev c ulong dst ulong x ulong to void |
| 16296 | n = xhreq c x |
| 16297 | put fr add x 23 n |
| 16298 | e = harray x 1 |
| 16299 | if ne c 171 |
| 16300 | xhbegin |
| 16301 | xhs 2 get fr add x 22 |
| 16302 | xhcmp 2 get fr add x 23 |
| 16303 | xtrap 1 3 |
| 16304 | xha x 4 7 |
| 16305 | xha x 2 6 |
| 16306 | xhb 2 e get fr add x 21 |
| 16307 | xhcall 16 |
| 16308 | xhdone dst x 0 |
| 16309 | ret |
| 16310 | end |
| 16311 | put fr add x 23 e |
| 16312 | put fr add x 24 get fr add x 21 |
| 16313 | put fr add x 25 get fr add x 22 |
| 16314 | f = harray x 1 |
| 16315 | if eq e f |
| 16316 | fail 19 |
| 16317 | end |
| 16318 | xhbegin |
| 16319 | xhs 2 get fr add x 25 |
| 16320 | xhcmp 2 32 |
| 16321 | xtrap 1 3 |
| 16322 | xhs 9 get fr add x 22 |
| 16323 | xhcmp 9 1048576 |
| 16324 | xtrap 8 3 |
| 16325 | xhb 13 e get fr add x 24 |
| 16326 | xhb 8 f get fr add x 21 |
| 16327 | xrr 133 9 9 |
| 16328 | empty = xbranch 0 |
| 16329 | xrr 137 2 8 |
| 16330 | xrr 1 2 9 |
| 16331 | xrr 57 2 13 |
| 16332 | before = xbranch 9 |
| 16333 | xmem 141 2 13 32 |
| 16334 | xrr 57 8 2 |
| 16335 | xtrap 3 3 |
| 16336 | xpatch before get oc 0 |
| 16337 | xpatch empty get oc 0 |
| 16338 | xmem 139 2 13 16 |
| 16339 | xrr 133 2 2 |
| 16340 | xtrap 1 3 |
| 16341 | xrr 133 9 9 |
| 16342 | nonzero = xbranch 1 |
| 16343 | ximm 8 0 |
| 16344 | xpatch nonzero get oc 0 |
| 16345 | xsp 1 32 |
| 16346 | for j ulong 4 |
| 16347 | xmem 139 0 13 mul j 8 |
| 16348 | xmem 137 0 4 mul j 8 |
| 16349 | end |
| 16350 | xmem 137 8 4 16 |
| 16351 | xhput 9 4 24 4 |
| 16352 | xha x 4 7 |
| 16353 | xha x 2 6 |
| 16354 | xrr 137 2 4 |
| 16355 | xhcall 16 |
| 16356 | for j ulong 4 |
| 16357 | if ne j 2 |
| 16358 | xmem 139 2 4 mul j 8 |
| 16359 | xmem 137 2 13 mul j 8 |
| 16360 | end |
| 16361 | end |
| 16362 | xhdone dst x 32 |
| 16363 | end |
| 16364 | fn xhost c ulong dst ulong to void |
| 16365 | if ne get xtarget 0 1 |
| 16366 | fail 25 |
| 16367 | end |
| 16368 | if eq 0 get progmode 0 |
| 16369 | if eq 0 get om2 0 |
| 16370 | fail 9 |
| 16371 | end |
| 16372 | ok = ulong 0 |
| 16373 | if or or eq c 100 eq c 110 or eq c 117 eq c 140 |
| 16374 | ok = ulong 1 |
| 16375 | end |
| 16376 | if and le c 149 ge c 145 |
| 16377 | ok = ulong 1 |
| 16378 | end |
| 16379 | if or or eq c 130 eq c 109 eq c 120 |
| 16380 | ok = ulong 1 |
| 16381 | end |
| 16382 | if and le c 177 ge c 166 |
| 16383 | ok = ulong 1 |
| 16384 | end |
| 16385 | if eq ok 0 |
| 16386 | fail 9 |
| 16387 | end |
| 16388 | end |
| 16389 | note execpure (198) has no x86 strict-profile lowering; refuse it rather than run an unconfined exec. |
| 16390 | if eq c 198 |
| 16391 | fail 25 |
| 16392 | end |
| 16393 | x = mul get depth 0 32 |
| 16394 | put fr add x 7 get nslot 0 |
| 16395 | if or eq c 220 eq c 222 |
| 16396 | xhsock c dst x |
| 16397 | ret |
| 16398 | end |
| 16399 | if or eq c 123 eq c 221 |
| 16400 | xhpoll c dst x |
| 16401 | ret |
| 16402 | end |
| 16403 | if and ge c 167 le c 177 |
| 16404 | if or eq c 171 eq c 172 |
| 16405 | xhdev c dst x |
| 16406 | ret |
| 16407 | end |
| 16408 | mtinit |
| 16409 | if or eq c 167 eq c 176 |
| 16410 | xhmnew c dst x |
| 16411 | ret |
| 16412 | end |
| 16413 | if eq c 177 |
| 16414 | xhmbind dst x |
| 16415 | ret |
| 16416 | end |
| 16417 | if eq c 168 |
| 16418 | harg x 0 9 |
| 16419 | xhbegin |
| 16420 | xha x 0 10 |
| 16421 | xhmcheck |
| 16422 | xrr 137 7 8 |
| 16423 | xrr 137 6 9 |
| 16424 | xhcall 11 |
| 16425 | xrr 133 0 0 |
| 16426 | failed = xbranch 1 |
| 16427 | xmem 137 0 13 0 |
| 16428 | xmem 137 0 13 8 |
| 16429 | xmem 137 0 13 24 |
| 16430 | xpatch failed get oc 0 |
| 16431 | xhdone dst x 0 |
| 16432 | ret |
| 16433 | end |
| 16434 | if or eq c 169 eq c 170 |
| 16435 | xhmcopy c dst x |
| 16436 | ret |
| 16437 | end |
| 16438 | xhmmio c dst x |
| 16439 | ret |
| 16440 | end |
| 16441 | if eq c 166 |
| 16442 | xhdev c dst x |
| 16443 | ret |
| 16444 | end |
| 16445 | if or eq c 132 eq c 128 |
| 16446 | xhsimple c dst x |
| 16447 | ret |
| 16448 | end |
| 16449 | if eq c 135 |
| 16450 | xhsimple c dst x |
| 16451 | ret |
| 16452 | end |
| 16453 | if eq c 133 |
| 16454 | xhreadln dst x |
| 16455 | ret |
| 16456 | end |
| 16457 | if eq c 134 |
| 16458 | xhsock c dst x |
| 16459 | ret |
| 16460 | end |
| 16461 | if or or eq c 109 eq c 130 eq c 120 |
| 16462 | xhtime c dst x |
| 16463 | ret |
| 16464 | end |
| 16465 | if or or or and ge c 113 le c 119 eq c 131 or eq c 161 eq c 162 eq c 224 |
| 16466 | xhbuffer c dst x |
| 16467 | ret |
| 16468 | end |
| 16469 | if or or or eq c 121 eq c 122 eq c 136 eq c 137 |
| 16470 | xhargs c dst x |
| 16471 | ret |
| 16472 | end |
| 16473 | if or or or or eq c 124 eq c 125 eq c 141 eq c 142 eq c 233 |
| 16474 | xhpack c dst x |
| 16475 | ret |
| 16476 | end |
| 16477 | if or eq c 140 eq c 149 |
| 16478 | xhstats c dst x |
| 16479 | ret |
| 16480 | end |
| 16481 | if or or or or eq c 110 eq c 111 eq c 112 eq c 126 eq c 138 |
| 16482 | xhpaths c dst x |
| 16483 | ret |
| 16484 | end |
| 16485 | if or or or or eq c 143 eq c 144 eq c 150 eq c 151 eq c 157 |
| 16486 | xhpaths c dst x |
| 16487 | ret |
| 16488 | end |
| 16489 | xhscalar c dst x |
| 16490 | end |
| 16491 | |
| 16492 | note ======== Native x86-64 semantic backend ======== |
| 16493 | note Intel SDM volume 2 instruction entries MOV, LEA, CALL, RET, Jcc, SETcc, MOVSX, |
| 16494 | note MOVZX, ADD, SUB, IMUL, DIV, IDIV, SHL, SHR, SAR, SYSCALL; volume 2 chapter 2 |
| 16495 | note supplies REX, ModRM and SIB. No A64 word decoding occurs in this backend. |
| 16496 | fn xb a ulong b ulong c ulong to void |
| 16497 | emitb uchar a |
| 16498 | emitb uchar b |
| 16499 | emitb uchar c |
| 16500 | end |
| 16501 | |
| 16502 | fn xword v ulong to void |
| 16503 | emitb uchar and v 255 |
| 16504 | emitb uchar and shr v 8 255 |
| 16505 | emitb uchar and shr v 16 255 |
| 16506 | emitb uchar and shr v 24 255 |
| 16507 | end |
| 16508 | |
| 16509 | fn ximm r ulong v ulong to void |
| 16510 | emitb uchar add 72 shr r 3 |
| 16511 | emitb uchar add 184 and r 7 |
| 16512 | xword v |
| 16513 | xword shr v 32 |
| 16514 | end |
| 16515 | |
| 16516 | note Hardware registers are private emitter operands. Language values are RBP slots. |
| 16517 | fn xrr op ulong d ulong s ulong to void |
| 16518 | emitb uchar add add 72 shl shr s 3 2 shr d 3 |
| 16519 | emitb uchar op |
| 16520 | emitb uchar add add 192 shl and s 7 3 and d 7 |
| 16521 | end |
| 16522 | |
| 16523 | fn xmem op ulong r ulong b ulong off ulong to void |
| 16524 | emitb uchar add add 72 shl shr r 3 2 shr b 3 |
| 16525 | emitb uchar op |
| 16526 | emitb uchar add add 128 shl and r 7 3 and b 7 |
| 16527 | if eq and b 7 4 |
| 16528 | emitb 36 |
| 16529 | end |
| 16530 | xword off |
| 16531 | end |
| 16532 | |
| 16533 | fn xload r ulong s ulong to void |
| 16534 | xmem 139 r 5 sub ulong 0 mul add s 1 8 |
| 16535 | end |
| 16536 | |
| 16537 | fn xstore r ulong s ulong to void |
| 16538 | xmem 137 r 5 sub ulong 0 mul add s 1 8 |
| 16539 | end |
| 16540 | |
| 16541 | fn xcc cc ulong to ulong |
| 16542 | if eq cc 0 |
| 16543 | ret 4 |
| 16544 | end |
| 16545 | if eq cc 1 |
| 16546 | ret 5 |
| 16547 | end |
| 16548 | if eq cc 2 |
| 16549 | ret 3 |
| 16550 | end |
| 16551 | if eq cc 3 |
| 16552 | ret 2 |
| 16553 | end |
| 16554 | if eq cc 6 |
| 16555 | ret 0 |
| 16556 | end |
| 16557 | if eq cc 7 |
| 16558 | ret 1 |
| 16559 | end |
| 16560 | if eq cc 8 |
| 16561 | ret 7 |
| 16562 | end |
| 16563 | if eq cc 9 |
| 16564 | ret 6 |
| 16565 | end |
| 16566 | if eq cc 10 |
| 16567 | ret 13 |
| 16568 | end |
| 16569 | if eq cc 11 |
| 16570 | ret 12 |
| 16571 | end |
| 16572 | if eq cc 12 |
| 16573 | ret 15 |
| 16574 | end |
| 16575 | if eq cc 13 |
| 16576 | ret 14 |
| 16577 | end |
| 16578 | fail 25 |
| 16579 | ret 0 |
| 16580 | end |
| 16581 | |
| 16582 | note Every branch reserves six bytes; all targets are byte offsets, not word offsets. |
| 16583 | fn xbranch cc ulong to ulong |
| 16584 | p = get oc 0 |
| 16585 | if eq cc 14 |
| 16586 | emitb 233 |
| 16587 | xword 0 |
| 16588 | emitb 144 |
| 16589 | else |
| 16590 | emitb 15 |
| 16591 | emitb uchar add 128 xcc cc |
| 16592 | xword 0 |
| 16593 | end |
| 16594 | ret p |
| 16595 | end |
| 16596 | |
| 16597 | fn xpatch p ulong dest ulong to void |
| 16598 | if eq get out p 233 |
| 16599 | wrword add p 1 sub dest add p 5 |
| 16600 | else |
| 16601 | wrword add p 2 sub dest add p 6 |
| 16602 | end |
| 16603 | end |
| 16604 | |
| 16605 | fn xtrap cc ulong code ulong to void |
| 16606 | n = get nt 0 |
| 16607 | if ge n 8192 |
| 16608 | fail 14 |
| 16609 | end |
| 16610 | put tcode n code |
| 16611 | put tsite n xbranch cc |
| 16612 | put nt 0 add n 1 |
| 16613 | if eq get om2m 0 1 |
| 16614 | siterec |
| 16615 | end |
| 16616 | end |
| 16617 | |
| 16618 | fn xcmp a ulong b ulong imm ulong to void |
| 16619 | xload 0 a |
| 16620 | if ne imm 0 |
| 16621 | ximm 1 b |
| 16622 | else |
| 16623 | xload 1 b |
| 16624 | end |
| 16625 | xrr 57 0 1 |
| 16626 | end |
| 16627 | |
| 16628 | note Canonicalization uses shifts, preserving the checked language's signed widths. |
| 16629 | fn xcanrax t ulong to void |
| 16630 | if eq t 10 |
| 16631 | emitb 137 |
| 16632 | emitb 192 |
| 16633 | ret |
| 16634 | end |
| 16635 | w = twid t |
| 16636 | if eq w 64 |
| 16637 | ret |
| 16638 | end |
| 16639 | xb 72 193 224 |
| 16640 | emitb uchar sub 64 w |
| 16641 | xb 72 193 232 |
| 16642 | if ge t 6 |
| 16643 | put out sub get oc 0 1 248 |
| 16644 | end |
| 16645 | emitb uchar sub 64 w |
| 16646 | end |
| 16647 | |
| 16648 | fn xext r ulong t ulong code ulong to void |
| 16649 | xload 0 r |
| 16650 | xrr 137 2 0 |
| 16651 | xcanrax t |
| 16652 | xrr 57 0 2 |
| 16653 | xtrap 1 code |
| 16654 | end |
| 16655 | |
| 16656 | fn xarith op ulong ty ulong a ulong b ulong imm ulong d ulong to void |
| 16657 | if or eq ty 10 eq ty 11 |
| 16658 | if or lt op 33 gt op 35 |
| 16659 | fail 7 |
| 16660 | end |
| 16661 | if ne imm 0 |
| 16662 | matconst 16 b |
| 16663 | b = ulong 16 |
| 16664 | end |
| 16665 | xfbin op ty a b d |
| 16666 | ret |
| 16667 | end |
| 16668 | xload 0 a |
| 16669 | if ne imm 0 |
| 16670 | ximm 1 b |
| 16671 | else |
| 16672 | xload 1 b |
| 16673 | end |
| 16674 | if eq op 33 |
| 16675 | xrr 1 0 1 |
| 16676 | if eq ty 13 |
| 16677 | xtrap 3 1 |
| 16678 | end |
| 16679 | end |
| 16680 | if eq op 34 |
| 16681 | xrr 41 0 1 |
| 16682 | if eq ty 13 |
| 16683 | xtrap 3 1 |
| 16684 | end |
| 16685 | end |
| 16686 | if eq op 35 |
| 16687 | if eq ty 13 |
| 16688 | xb 72 247 225 |
| 16689 | xrr 133 2 2 |
| 16690 | xtrap 1 1 |
| 16691 | else |
| 16692 | xb 72 15 175 |
| 16693 | emitb 193 |
| 16694 | end |
| 16695 | end |
| 16696 | if eq op 38 |
| 16697 | xrr 33 0 1 |
| 16698 | end |
| 16699 | if eq op 39 |
| 16700 | xrr 9 0 1 |
| 16701 | end |
| 16702 | if eq op 40 |
| 16703 | xrr 49 0 1 |
| 16704 | end |
| 16705 | if and eq ty 9 le op 35 |
| 16706 | xtrap 6 1 |
| 16707 | end |
| 16708 | xstore 0 d |
| 16709 | if le op 35 |
| 16710 | bo_fix d ty |
| 16711 | end |
| 16712 | end |
| 16713 | |
| 16714 | fn xdiv op ulong ty ulong a ulong b ulong d ulong fl ulong to void |
| 16715 | if or eq ty 10 eq ty 11 |
| 16716 | if ne op 36 |
| 16717 | fail 7 |
| 16718 | end |
| 16719 | xfbin op ty a b d |
| 16720 | ret |
| 16721 | end |
| 16722 | xload 0 a |
| 16723 | xload 1 b |
| 16724 | note Match bo_div's constant-divisor proofs and source trap sites. |
| 16725 | if eq and fl 1 0 |
| 16726 | xrr 133 1 1 |
| 16727 | xtrap 0 2 |
| 16728 | end |
| 16729 | done = ulong 0 |
| 16730 | if and ge ty 6 le ty 9 |
| 16731 | if and eq ty 9 eq and fl 2 0 |
| 16732 | note Only 64-bit IDIV can fault on MIN/-1; remainder must bypass with zero. |
| 16733 | ximm 2 18446744073709551615 |
| 16734 | xrr 57 1 2 |
| 16735 | other = xbranch 1 |
| 16736 | if eq op 37 |
| 16737 | ximm 0 0 |
| 16738 | done = xbranch 14 |
| 16739 | else |
| 16740 | xb 72 247 216 |
| 16741 | xtrap 6 1 |
| 16742 | done = xbranch 14 |
| 16743 | end |
| 16744 | xpatch other get oc 0 |
| 16745 | end |
| 16746 | xb 72 153 144 |
| 16747 | xb 72 247 249 |
| 16748 | else |
| 16749 | xrr 49 2 2 |
| 16750 | xb 72 247 241 |
| 16751 | end |
| 16752 | if eq op 37 |
| 16753 | xrr 137 0 2 |
| 16754 | end |
| 16755 | if ne done 0 |
| 16756 | xpatch done get oc 0 |
| 16757 | end |
| 16758 | xstore 0 d |
| 16759 | note Narrow signed quotients can overflow; remainders and unsigned quotients cannot. |
| 16760 | if and eq op 36 and ge ty 6 lt ty 9 |
| 16761 | bo_fix d ty |
| 16762 | end |
| 16763 | end |
| 16764 | |
| 16765 | fn xshift op ulong ty ulong a ulong b ulong imm ulong d ulong to void |
| 16766 | xload 0 a |
| 16767 | if ne imm 0 |
| 16768 | ximm 1 b |
| 16769 | else |
| 16770 | xload 1 b |
| 16771 | end |
| 16772 | note imm is set only for a statically valid shift amount, as in bo_shl/bo_shr. |
| 16773 | if eq imm 0 |
| 16774 | ximm 2 twid ty |
| 16775 | xrr 57 1 2 |
| 16776 | xtrap 2 7 |
| 16777 | end |
| 16778 | xrr 137 2 0 |
| 16779 | if eq op 41 |
| 16780 | xb 72 211 224 |
| 16781 | if eq ty 9 |
| 16782 | xrr 137 8 0 |
| 16783 | xb 73 211 248 |
| 16784 | xrr 57 8 2 |
| 16785 | xtrap 1 1 |
| 16786 | end |
| 16787 | else |
| 16788 | if ge ty 6 |
| 16789 | xb 72 211 248 |
| 16790 | else |
| 16791 | xb 72 211 232 |
| 16792 | end |
| 16793 | end |
| 16794 | xstore 0 d |
| 16795 | if eq op 41 |
| 16796 | bo_fix d ty |
| 16797 | end |
| 16798 | end |
| 16799 | |
| 16800 | fn xunary op ulong dst ulong to void |
| 16801 | ty = get rt 0 |
| 16802 | if eq ty 13 |
| 16803 | fail 7 |
| 16804 | end |
| 16805 | if or eq ty 10 eq ty 11 |
| 16806 | if eq op 50 |
| 16807 | fail 7 |
| 16808 | end |
| 16809 | fa = matreg get rk 0 get rv 0 ty |
| 16810 | fd = destreg dst |
| 16811 | note xfneg / xfsqrt / xfabs: the x86 forms of fp_neg / fp_un1 on x registers ra into rd (sign mask, SQRTS). |
| 16812 | xload 0 fa |
| 16813 | ximm 1 xfmask ty 0 |
| 16814 | xrr 49 0 1 |
| 16815 | xstore 0 fd |
| 16816 | put rk 0 1 |
| 16817 | put rv 0 fd |
| 16818 | put rt 0 ty |
| 16819 | ret |
| 16820 | end |
| 16821 | a = matreg get rk 0 get rv 0 ty |
| 16822 | d = destreg dst |
| 16823 | xload 0 a |
| 16824 | if eq op 50 |
| 16825 | if eq ty 1 |
| 16826 | ximm 1 1 |
| 16827 | xrr 49 0 1 |
| 16828 | else |
| 16829 | xb 72 247 208 |
| 16830 | end |
| 16831 | else |
| 16832 | if eq ty 1 |
| 16833 | fail 7 |
| 16834 | end |
| 16835 | xb 72 247 216 |
| 16836 | if eq ty 9 |
| 16837 | xtrap 6 1 |
| 16838 | end |
| 16839 | end |
| 16840 | xstore 0 d |
| 16841 | if eq op 50 |
| 16842 | canon d ty |
| 16843 | else |
| 16844 | bo_fix d ty |
| 16845 | end |
| 16846 | put rk 0 1 |
| 16847 | put rv 0 d |
| 16848 | put rt 0 ty |
| 16849 | end |
| 16850 | |
| 16851 | fn xconv tt ulong to void |
| 16852 | ft = get rt 0 |
| 16853 | if or or or eq ft 10 eq ft 11 eq tt 10 eq tt 11 |
| 16854 | if or eq ft 13 eq tt 13 |
| 16855 | fail 7 |
| 16856 | end |
| 16857 | if or eq ft 1 eq tt 1 |
| 16858 | fail 9 |
| 16859 | end |
| 16860 | fa = matreg get rk 0 get rv 0 ft |
| 16861 | fd = fp_conv ft tt fa |
| 16862 | put rk 0 1 |
| 16863 | put rv 0 fd |
| 16864 | put rt 0 tt |
| 16865 | ret |
| 16866 | end |
| 16867 | if or eq ft 1 eq tt 1 |
| 16868 | fail 9 |
| 16869 | end |
| 16870 | r = matreg get rk 0 get rv 0 ft |
| 16871 | wf = twid ft |
| 16872 | wt = twid tt |
| 16873 | s = ulong 99 |
| 16874 | if not and ge ft 6 le ft 9 |
| 16875 | if and ge tt 6 le tt 9 |
| 16876 | if ge wf wt |
| 16877 | s = sub wt 1 |
| 16878 | end |
| 16879 | else |
| 16880 | if gt wf wt |
| 16881 | s = wt |
| 16882 | end |
| 16883 | end |
| 16884 | else |
| 16885 | if not and ge tt 6 le tt 9 |
| 16886 | s = wt |
| 16887 | if gt s 63 |
| 16888 | s = ulong 63 |
| 16889 | end |
| 16890 | else |
| 16891 | if gt wf wt |
| 16892 | xext r tt 5 |
| 16893 | end |
| 16894 | end |
| 16895 | end |
| 16896 | if ne s 99 |
| 16897 | xload 0 r |
| 16898 | xb 72 193 232 |
| 16899 | emitb uchar s |
| 16900 | xrr 133 0 0 |
| 16901 | xtrap 1 5 |
| 16902 | end |
| 16903 | put rk 0 1 |
| 16904 | put rv 0 r |
| 16905 | put rt 0 tt |
| 16906 | end |
| 16907 | |
| 16908 | note Reserve checked stack BEFORE stores, CALL return addresses, or PUSH. |
| 16909 | fn xcheck bytes ulong to void |
| 16910 | xmem 141 0 4 sub ulong 0 bytes |
| 16911 | xrr 57 0 15 |
| 16912 | xtrap 3 6 |
| 16913 | end |
| 16914 | |
| 16915 | fn xsp down ulong bytes ulong to void |
| 16916 | if eq bytes 0 |
| 16917 | ret |
| 16918 | end |
| 16919 | if ne down 0 |
| 16920 | xcheck bytes |
| 16921 | xb 72 129 236 |
| 16922 | else |
| 16923 | xb 72 129 196 |
| 16924 | end |
| 16925 | xword bytes |
| 16926 | end |
| 16927 | |
| 16928 | fn xmovsp r ulong to void |
| 16929 | xrr 137 0 4 |
| 16930 | xstore 0 r |
| 16931 | end |
| 16932 | |
| 16933 | fn xpro np ulong to void |
| 16934 | xrr 137 11 5 |
| 16935 | emitb 85 |
| 16936 | xrr 137 5 4 |
| 16937 | xb 72 129 236 |
| 16938 | xword 256 |
| 16939 | j = ulong 0 |
| 16940 | while lt j np |
| 16941 | xmem 139 0 11 sub ulong 0 mul add j 1 8 |
| 16942 | xstore 0 j |
| 16943 | j = add j 1 |
| 16944 | end |
| 16945 | end |
| 16946 | |
| 16947 | |
| 16948 | fn xarg t ulong k ulong v ulong to void |
| 16949 | if eq k 6 |
| 16950 | mataddr t v |
| 16951 | ret |
| 16952 | end |
| 16953 | if or eq k 3 eq k 7 |
| 16954 | matconst t v |
| 16955 | ret |
| 16956 | end |
| 16957 | xmem 139 0 4 mul v 8 |
| 16958 | xstore 0 t |
| 16959 | end |
| 16960 | |
| 16961 | fn xrestore d ulong slot ulong res ulong to ulong |
| 16962 | put nslot 0 slot |
| 16963 | rd = ulong 255 |
| 16964 | if ne res 0 |
| 16965 | rd = destreg d |
| 16966 | xstore 0 rd |
| 16967 | end |
| 16968 | j = ulong 0 |
| 16969 | while lt j 18 |
| 16970 | if ne j rd |
| 16971 | xmem 139 0 4 mul j 8 |
| 16972 | xstore 0 j |
| 16973 | end |
| 16974 | j = add j 1 |
| 16975 | end |
| 16976 | xsp 0 256 |
| 16977 | ret rd |
| 16978 | end |
| 16979 | |
| 16980 | note Typed addresses carry origin through fixup records. Numeric constants never relocate. |
| 16981 | fn mataddr r ulong v ulong to void |
| 16982 | if eq get xtarget 0 0 |
| 16983 | matconst r v |
| 16984 | ret |
| 16985 | end |
| 16986 | xaddr 0 v |
| 16987 | xstore 0 r |
| 16988 | end |
| 16989 | |
| 16990 | fn xaddr r ulong v ulong to void |
| 16991 | n = get xnaddr 0 |
| 16992 | if ge n 65536 |
| 16993 | fail 14 |
| 16994 | end |
| 16995 | emitb uchar add 72 shl shr r 3 2 |
| 16996 | emitb 141 |
| 16997 | emitb uchar add 5 shl and r 7 3 |
| 16998 | put xasite n get oc 0 |
| 16999 | put xavalue n v |
| 17000 | put xnaddr 0 add n 1 |
| 17001 | xword 0 |
| 17002 | end |
| 17003 | |
| 17004 | fn xelem e ulong k ulong v ulong t ulong to void |
| 17005 | if or or eq t 1 eq t 10 eq t 11 |
| 17006 | fail 7 |
| 17007 | end |
| 17008 | i = sub e 1 |
| 17009 | ln = get nm_len i |
| 17010 | x = v |
| 17011 | if ne unsz i 0 |
| 17012 | x = matreg k v t |
| 17013 | xcmp x ulong get nm_lr i 0 |
| 17014 | xtrap 2 3 |
| 17015 | else |
| 17016 | if eq k 3 |
| 17017 | if le ln v |
| 17018 | fail 21 |
| 17019 | end |
| 17020 | if and ne get om2 0 0 le v 4095 |
| 17021 | x = ulong 255 |
| 17022 | put ea_k 0 v |
| 17023 | else |
| 17024 | x = alloc |
| 17025 | matconst x v |
| 17026 | end |
| 17027 | else |
| 17028 | xcmp v ln 1 |
| 17029 | xtrap 2 3 |
| 17030 | end |
| 17031 | end |
| 17032 | put ea_i 0 x |
| 17033 | if ge get nm_kind i 4 |
| 17034 | b = alloc |
| 17035 | mataddr b get nm_addr i |
| 17036 | put ea_b 0 b |
| 17037 | else |
| 17038 | put ea_b 0 ulong get nm_reg i |
| 17039 | end |
| 17040 | end |
| 17041 | |
| 17042 | note Indexed load/store uses RDX=base+index*element-size; pointers never enter source scalars. |
| 17043 | fn xmemval store ulong base ulong idx ulong ty ulong val ulong to void |
| 17044 | xload 2 base |
| 17045 | if eq idx 255 |
| 17046 | ximm 1 get ea_k 0 |
| 17047 | else |
| 17048 | xload 1 idx |
| 17049 | end |
| 17050 | xb 72 193 225 |
| 17051 | emitb uchar tlog ty |
| 17052 | xrr 1 2 1 |
| 17053 | xmemraw store ty val |
| 17054 | end |
| 17055 | |
| 17056 | note RDX is a checked aggregate address; layout byte offsets do not scale by the field width. |
| 17057 | fn xlayout store ulong base ulong idx ulong ty ulong val ulong to void |
| 17058 | xload 2 base |
| 17059 | xload 1 idx |
| 17060 | xrr 1 2 1 |
| 17061 | xmemraw store ty val |
| 17062 | end |
| 17063 | |
| 17064 | fn xmemraw store ulong ty ulong val ulong to void |
| 17065 | if ne store 0 |
| 17066 | xload 0 val |
| 17067 | if eq twid ty 16 |
| 17068 | emitb 102 |
| 17069 | end |
| 17070 | if eq twid ty 64 |
| 17071 | emitb 72 |
| 17072 | end |
| 17073 | if le twid ty 8 |
| 17074 | emitb 136 |
| 17075 | else |
| 17076 | emitb 137 |
| 17077 | end |
| 17078 | emitb 2 |
| 17079 | else |
| 17080 | if eq twid ty 64 |
| 17081 | xb 72 139 2 |
| 17082 | else |
| 17083 | if eq twid ty 32 |
| 17084 | if and ge ty 6 le ty 9 |
| 17085 | xb 72 99 2 |
| 17086 | else |
| 17087 | emitb 139 |
| 17088 | emitb 2 |
| 17089 | end |
| 17090 | else |
| 17091 | emitb 72 |
| 17092 | emitb 15 |
| 17093 | op = ulong 182 |
| 17094 | if eq twid ty 16 |
| 17095 | op = ulong 183 |
| 17096 | end |
| 17097 | if and ge ty 6 le ty 9 |
| 17098 | op = add op 8 |
| 17099 | end |
| 17100 | emitb uchar op |
| 17101 | emitb 2 |
| 17102 | end |
| 17103 | end |
| 17104 | xstore 0 val |
| 17105 | end |
| 17106 | end |
| 17107 | |
| 17108 | fn xio c ulong fk ulong fv ulong e ulong ro ulong rn ulong to void |
| 17109 | if ne get xtarget 0 1 |
| 17110 | fail 25 |
| 17111 | end |
| 17112 | save |
| 17113 | i = sub e 1 |
| 17114 | if ge get nm_kind i 4 |
| 17115 | xaddr 6 get nm_addr i |
| 17116 | else |
| 17117 | xload 6 ulong get nm_reg i |
| 17118 | end |
| 17119 | xmem 139 0 4 mul ro 8 |
| 17120 | xrr 1 6 0 |
| 17121 | if eq fk 3 |
| 17122 | ximm 7 fv |
| 17123 | else |
| 17124 | xmem 139 7 4 mul fv 8 |
| 17125 | end |
| 17126 | xmem 139 2 4 mul rn 8 |
| 17127 | ximm 0 sub c 53 |
| 17128 | emitb 15 |
| 17129 | emitb 5 |
| 17130 | end |
| 17131 | |
| 17132 | note xcount: the x86-64 loop of cnt_word, after vs_chk. RSI = A + off (LEA of a global or text, else the |
| 17133 | note array's slot; ADD), RCX = n, AL = v (zero-extended uchar). XMM0 = v in all 16 byte lanes (MOVD, |
| 17134 | note PUNPCKLBW, PSHUFLW 0, PSHUFD 0), XMM3 = 0, EDX = 0 (the count). While RCX >= 16 (CMP; JB): a block of |
| 17135 | note R8 = min(RCX >> 4, 255) chunks (MOV, SHR, CMP, JBE, MOV R8D 255; PXOR XMM1), each chunk MOVDQU XMM2, |
| 17136 | note [RSI]; PCMPEQB XMM2, XMM0 (0xff where equal); PSUBB XMM1, XMM2 (+1 per equal lane; 255 chunks keep |
| 17137 | note each lane <= 255); ADD RSI, 16; SUB RCX, 16; DEC R8; JNE; then PSADBW XMM1, XMM3 (each 8-lane half |
| 17138 | note summed into its quadword), MOVQ R9 / ADD RDX twice around PSRLDQ XMM1, 8, JMP back. The last RCX < 16 |
| 17139 | note bytes one at a time: TEST; JE; CMP [RSI], AL; JNE; INC RDX; INC RSI; DEC RCX; JNE. SSE2 only (every |
| 17140 | note x86-64 CPU), unaligned loads, never a byte outside the checked slice. The 128 bytes after the four |
| 17141 | note setup moves are fixed (Intel SDM vol. 2 encodings, checked byte for byte against llvm-mc 18; the short |
| 17142 | note jumps' distances are constant); RDX holds the result for cnt_word. RAX, RCX, RDX, RSI, R8, R9 and |
| 17143 | note XMM0-XMM3 are emitter scratch here: language values live in RBP slots. |
| 17144 | fn xcount e ulong ro ulong rn ulong v ulong to void |
| 17145 | i = sub e 1 |
| 17146 | if ge get nm_kind i 4 |
| 17147 | xaddr 6 get nm_addr i |
| 17148 | else |
| 17149 | xload 6 ulong get nm_reg i |
| 17150 | end |
| 17151 | xload 0 ro |
| 17152 | xrr 1 6 0 |
| 17153 | xload 1 rn |
| 17154 | xload 0 v |
| 17155 | xb 102 15 110 |
| 17156 | emitb 192 |
| 17157 | xb 102 15 96 |
| 17158 | emitb 192 |
| 17159 | xb 242 15 112 |
| 17160 | emitb 192 |
| 17161 | emitb 0 |
| 17162 | xb 102 15 112 |
| 17163 | emitb 192 |
| 17164 | emitb 0 |
| 17165 | xb 102 15 239 |
| 17166 | emitb 219 |
| 17167 | emitb 49 |
| 17168 | emitb 210 |
| 17169 | xb 72 131 249 |
| 17170 | emitb 16 |
| 17171 | emitb 114 |
| 17172 | emitb 78 |
| 17173 | xb 73 137 200 |
| 17174 | xb 73 193 232 |
| 17175 | emitb 4 |
| 17176 | xb 73 129 248 |
| 17177 | xb 255 0 0 |
| 17178 | emitb 0 |
| 17179 | emitb 118 |
| 17180 | emitb 6 |
| 17181 | xb 65 184 255 |
| 17182 | xb 0 0 0 |
| 17183 | xb 102 15 239 |
| 17184 | emitb 201 |
| 17185 | xb 243 15 111 |
| 17186 | emitb 22 |
| 17187 | xb 102 15 116 |
| 17188 | emitb 208 |
| 17189 | xb 102 15 248 |
| 17190 | emitb 202 |
| 17191 | xb 72 131 198 |
| 17192 | emitb 16 |
| 17193 | xb 72 131 233 |
| 17194 | emitb 16 |
| 17195 | xb 73 255 200 |
| 17196 | emitb 117 |
| 17197 | emitb 231 |
| 17198 | xb 102 15 246 |
| 17199 | emitb 203 |
| 17200 | xb 102 73 15 |
| 17201 | emitb 126 |
| 17202 | emitb 201 |
| 17203 | xb 76 1 202 |
| 17204 | xb 102 15 115 |
| 17205 | emitb 217 |
| 17206 | emitb 8 |
| 17207 | xb 102 73 15 |
| 17208 | emitb 126 |
| 17209 | emitb 201 |
| 17210 | xb 76 1 202 |
| 17211 | emitb 235 |
| 17212 | emitb 172 |
| 17213 | xb 72 133 201 |
| 17214 | emitb 116 |
| 17215 | emitb 15 |
| 17216 | emitb 56 |
| 17217 | emitb 6 |
| 17218 | emitb 117 |
| 17219 | emitb 3 |
| 17220 | xb 72 255 194 |
| 17221 | xb 72 255 198 |
| 17222 | xb 72 255 201 |
| 17223 | emitb 117 |
| 17224 | emitb 241 |
| 17225 | end |
| 17226 | |
| 17227 | fn xarray w ulong to void |
| 17228 | if ne get nb 0 0 |
| 17229 | fail 9 |
| 17230 | end |
| 17231 | t = typeword |
| 17232 | elemtype t |
| 17233 | n = lenval 16 |
| 17234 | arrlen n |
| 17235 | by = shl shr add shl n tlog t 15 4 4 |
| 17236 | if gt add get stkbytes 0 by 4194304 |
| 17237 | fail 23 |
| 17238 | end |
| 17239 | put stkbytes 0 add get stkbytes 0 by |
| 17240 | r = alloc |
| 17241 | put held 0 get nslot 0 |
| 17242 | rdval 0 t 255 0 |
| 17243 | if ne get rt 0 t |
| 17244 | fail 7 |
| 17245 | end |
| 17246 | v = matreg get rk 0 get rv 0 t |
| 17247 | xsp 1 by |
| 17248 | xmovsp r |
| 17249 | i = alloc |
| 17250 | matconst i 0 |
| 17251 | lp = get oc 0 |
| 17252 | xmemval 1 r i t v |
| 17253 | xarith 33 5 i 1 1 i |
| 17254 | xcmp i n 1 |
| 17255 | blo lp |
| 17256 | addname w r t n 1 0 |
| 17257 | end |
| 17258 | |
| 17259 | note xfornum / xforval: the x86 sf_num / sf_val. bn and n come from sf_num / sf_val, which parse the bound |
| 17260 | note themselves (sf_val: 1000000 when no bound is written); bn = 0 leaves a number count unguarded, as on Arm. |
| 17261 | fn xfornum w ulong t ulong k ulong sn ulong sh ulong bn ulong to void |
| 17262 | eol |
| 17263 | i = alloc |
| 17264 | put held 0 get nslot 0 |
| 17265 | addname w i t 0 0 0 |
| 17266 | matconst i 0 |
| 17267 | c = ulong 0 |
| 17268 | if ne bn 0 |
| 17269 | c = alloc |
| 17270 | put held 0 get nslot 0 |
| 17271 | matconst c 0 |
| 17272 | end |
| 17273 | hd = get oc 0 |
| 17274 | cp_head get cur 0 get line 0 |
| 17275 | xcmp i k 1 |
| 17276 | br = sf_br t |
| 17277 | if ne bn 0 |
| 17278 | lpcnt c bn |
| 17279 | end |
| 17280 | pushb br 4 hd i t |
| 17281 | pushnh sn sh |
| 17282 | cp_skip |
| 17283 | end |
| 17284 | |
| 17285 | fn xforval w ulong t ulong kr ulong sn ulong sh ulong n ulong to void |
| 17286 | eol |
| 17287 | i = alloc |
| 17288 | put held 0 get nslot 0 |
| 17289 | addname w i t 0 0 0 |
| 17290 | matconst i 0 |
| 17291 | c = alloc |
| 17292 | put held 0 get nslot 0 |
| 17293 | matconst c 0 |
| 17294 | hd = get oc 0 |
| 17295 | cp_head get cur 0 get line 0 |
| 17296 | xcmp i kr 0 |
| 17297 | br = sf_br t |
| 17298 | lpcnt c n |
| 17299 | pushb br 4 hd i t |
| 17300 | pushnh sn sh |
| 17301 | cp_skip |
| 17302 | end |
| 17303 | |
| 17304 | fn xleave to void |
| 17305 | if eq get xtarget 0 2 |
| 17306 | note UEFI: every exit jumps to the shared firmware return emitted by xefx 1; RAX is the status. |
| 17307 | n = get xnexit 0 |
| 17308 | if ge n 65536 |
| 17309 | fail 14 |
| 17310 | end |
| 17311 | put xexsite n xbranch 14 |
| 17312 | put xnexit 0 add n 1 |
| 17313 | ret |
| 17314 | end |
| 17315 | xrr 137 7 0 |
| 17316 | ximm 0 60 |
| 17317 | emitb 15 |
| 17318 | emitb 5 |
| 17319 | end |
| 17320 | |
| 17321 | fn xfinish to void |
| 17322 | eol |
| 17323 | if eq get dead 0 0 |
| 17324 | if ne get curret 0 12 |
| 17325 | fail 18 |
| 17326 | end |
| 17327 | cp_post 0 0 12 |
| 17328 | epi |
| 17329 | end |
| 17330 | j = ulong 0 |
| 17331 | n = get nt 0 |
| 17332 | while lt j n |
| 17333 | xpatch get tsite j get oc 0 |
| 17334 | if eq get progmode 0 0 |
| 17335 | note Bare units reserve physical R12/R14: recovery stack and immutable runtime table. |
| 17336 | note Host helpers clobber these registers and must remain forbidden in bare units. |
| 17337 | emitb 190 |
| 17338 | xword get tcode j |
| 17339 | xb 65 255 102 |
| 17340 | emitb 16 |
| 17341 | else |
| 17342 | if eq get xtarget 0 2 |
| 17343 | ximm 0 or 9223372036854775808 add 100 get tcode j |
| 17344 | else |
| 17345 | ximm 0 add 100 get tcode j |
| 17346 | end |
| 17347 | xleave |
| 17348 | end |
| 17349 | j = add j 1 |
| 17350 | end |
| 17351 | put curret 0 0 |
| 17352 | put nn 0 get nglob 0 |
| 17353 | put curfn 0 0 |
| 17354 | put nbrk 0 0 |
| 17355 | put ncont 0 0 |
| 17356 | end |
| 17357 | |
| 17358 | fn xlead to void |
| 17359 | note Only the exact bytes "target " at offset zero select x86. Default parsing is untouched. |
| 17360 | if lt get inlen 0 8 |
| 17361 | ret |
| 17362 | end |
| 17363 | if or ne get inp 0 116 ne get inp 1 97 |
| 17364 | ret |
| 17365 | end |
| 17366 | if or ne get inp 2 114 ne get inp 3 103 |
| 17367 | ret |
| 17368 | end |
| 17369 | if or ne get inp 4 101 ne get inp 5 116 |
| 17370 | ret |
| 17371 | end |
| 17372 | if ne get inp 6 32 |
| 17373 | ret |
| 17374 | end |
| 17375 | put cur 0 0 |
| 17376 | put line 0 1 |
| 17377 | tok |
| 17378 | tok |
| 17379 | if and eq get tw 0 8679965255892613240 eq get tl 0 8 |
| 17380 | put xtarget 0 1 |
| 17381 | else |
| 17382 | if and eq get tw 0 115888505632888 eq get tl 0 6 |
| 17383 | put xtarget 0 2 |
| 17384 | else |
| 17385 | fail 25 |
| 17386 | end |
| 17387 | end |
| 17388 | eol |
| 17389 | p = ulong 0 |
| 17390 | while lt p get cur 0 |
| 17391 | if ne get inp p 10 |
| 17392 | put inp p 32 |
| 17393 | end |
| 17394 | p = add p 1 |
| 17395 | end |
| 17396 | put cur 0 0 |
| 17397 | put line 0 1 |
| 17398 | end |
| 17399 | |
| 17400 | |
| 17401 | fn xeof to void |
| 17402 | f = findfn 1852399981 4 0 |
| 17403 | if eq f 0 |
| 17404 | fail 16 |
| 17405 | end |
| 17406 | if ne get fn_np sub f 1 0 |
| 17407 | fail 9 |
| 17408 | end |
| 17409 | entry = get oc 0 |
| 17410 | efi = eq get xtarget 0 2 |
| 17411 | if efi |
| 17412 | xefx 0 0 |
| 17413 | else |
| 17414 | xrr 137 13 4 |
| 17415 | ximm 15 268435456 |
| 17416 | ximm 4 276824064 |
| 17417 | ximm 5 0 |
| 17418 | end |
| 17419 | emitb 232 |
| 17420 | p = get oc 0 |
| 17421 | xword sub get fn_addr sub f 1 add p 4 |
| 17422 | if eq get fn_ret sub f 1 12 |
| 17423 | ximm 0 0 |
| 17424 | end |
| 17425 | xleave |
| 17426 | if efi |
| 17427 | xefx 1 0 |
| 17428 | xefx 2 entry |
| 17429 | else |
| 17430 | elfhdr |
| 17431 | wrword 16 4063234 |
| 17432 | wrword 24 add 4194304 entry |
| 17433 | wrword 96 get oc 0 |
| 17434 | wrword 104 get oc 0 |
| 17435 | wrword 160 add get poolb 0 8388608 |
| 17436 | end |
| 17437 | i = ulong 0 |
| 17438 | while lt i get xnaddr 0 |
| 17439 | p = get xasite i |
| 17440 | v = get xavalue i |
| 17441 | if efi |
| 17442 | note PE: code RVA = file offset + 3584; static data lives in the bss section at xbss. |
| 17443 | if ge v 268435456 |
| 17444 | v = add get xbss 0 sub v 268435456 |
| 17445 | else |
| 17446 | v = add sub v 4194304 3584 |
| 17447 | end |
| 17448 | p = add p 3584 |
| 17449 | else |
| 17450 | v = sub v 4194304 |
| 17451 | end |
| 17452 | wrword get xasite i sub v add p 4 |
| 17453 | i = add i 1 |
| 17454 | end |
| 17455 | writeout 0 |
| 17456 | end |
| 17457 | |
| 17458 | note ======== x86efi: UEFI 2.10 PE32+ application (docs/X86-EFI.md) ======== |
| 17459 | note efi OP ARG A OFF N -> ulong EFI_STATUS or result. OP is a literal 0..14; A is writable uchar |
| 17460 | note storage, bounds checked before any firmware call; ARG is never a pointer. Errors are 2^63|code. |
| 17461 | note Private state occupies the first 16 KiB of the PE .bss, below the owned 8 MiB stack. Firmware is |
| 17462 | note called per UEFI 2.3.4.2: RCX/RDX/R8/R9, 32-byte home area, an 80-byte 16-aligned reservation. |
| 17463 | note Language values stay in RBP slots, so integers and floats survive every firmware call. |
| 17464 | note Port of the Allen x86efi fork (operations 0..11) onto main's backend; 12, 13 and 14 are new. |
| 17465 | |
| 17466 | note xp k: 0 LEA r,private+off; 1 load r from private+off; 2 store r to private+off (via R10); |
| 17467 | note 3 call BootServices+off (R11); 4 call method off of the protocol held in private slot r (RCX = This). |
| 17468 | fn xp k ulong r ulong off ulong to void |
| 17469 | if eq k 0 |
| 17470 | xaddr r add 268435456 off |
| 17471 | ret |
| 17472 | end |
| 17473 | if eq k 1 |
| 17474 | xaddr r add 268435456 off |
| 17475 | xmem 139 r r 0 |
| 17476 | ret |
| 17477 | end |
| 17478 | if eq k 2 |
| 17479 | xaddr 10 add 268435456 off |
| 17480 | xmem 137 r 10 0 |
| 17481 | ret |
| 17482 | end |
| 17483 | if eq k 3 |
| 17484 | xaddr 11 268435456 |
| 17485 | xmem 139 11 11 0 |
| 17486 | xmem 139 11 11 96 |
| 17487 | xmem 139 11 11 off |
| 17488 | xb 65 255 211 |
| 17489 | ret |
| 17490 | end |
| 17491 | xaddr 1 add 268435456 r |
| 17492 | xmem 139 1 1 0 |
| 17493 | xmem 139 11 1 off |
| 17494 | xb 65 255 211 |
| 17495 | end |
| 17496 | |
| 17497 | note xer k: 0 branch on cc to an error tail that returns 2^63|code; 1 jump to the operation's end; |
| 17498 | note 2 RDTSC into RAX (Intel SDM: LFENCE before and after serializes local instruction execution). |
| 17499 | fn xer k ulong cc ulong code ulong to void |
| 17500 | if eq k 2 |
| 17501 | xb 15 174 232 |
| 17502 | emitb 15 |
| 17503 | emitb 49 |
| 17504 | xb 15 174 232 |
| 17505 | xb 72 193 226 |
| 17506 | emitb 32 |
| 17507 | xrr 9 0 2 |
| 17508 | ret |
| 17509 | end |
| 17510 | if eq k 0 |
| 17511 | n = get xenerr 0 |
| 17512 | if ge n 256 |
| 17513 | fail 14 |
| 17514 | end |
| 17515 | put xerrpos n xbranch cc |
| 17516 | put xerrcode n code |
| 17517 | put xenerr 0 add n 1 |
| 17518 | ret |
| 17519 | end |
| 17520 | m = get xenend 0 |
| 17521 | if ge m 256 |
| 17522 | fail 14 |
| 17523 | end |
| 17524 | put xendpos m xbranch 14 |
| 17525 | put xenend 0 add m 1 |
| 17526 | end |
| 17527 | |
| 17528 | note xg k: inline constant data skipped by a jump; returns its address for xaddr. k 0..7 a UEFI GUID |
| 17529 | note packed Data1|Data2<<32|Data3<<48 then Data4 little-endian (0 GOP, 1 SNP, 2 RNG, 3 simple pointer, |
| 17530 | note 4 absolute pointer, 5 Simple File System, 6 LoadedImage, 7 FileInfo, 9 SMBIOS3 table, 10 SMBIOS |
| 17531 | note table); 8 UCS-2 \EFI\BOOT\BOOTX64.EFI. |
| 17532 | fn xg k ulong to ulong |
| 17533 | br = xbranch 14 |
| 17534 | p = get oc 0 |
| 17535 | if eq k 8 |
| 17536 | xb 92 0 69 |
| 17537 | xb 0 70 0 |
| 17538 | xb 73 0 92 |
| 17539 | xb 0 66 0 |
| 17540 | xb 79 0 79 |
| 17541 | xb 0 84 0 |
| 17542 | xb 92 0 66 |
| 17543 | xb 0 79 0 |
| 17544 | xb 79 0 84 |
| 17545 | xb 0 88 0 |
| 17546 | xb 54 0 52 |
| 17547 | xb 0 46 0 |
| 17548 | xb 69 0 70 |
| 17549 | xb 0 73 0 |
| 17550 | emitb 0 |
| 17551 | emitb 0 |
| 17552 | else |
| 17553 | a = ulong 5348063987722529246 |
| 17554 | b = ulong 7661046075708078998 |
| 17555 | if eq k 1 |
| 17556 | a = ulong 1284559596355596985 |
| 17557 | b = ulong 5602828850577812890 |
| 17558 | end |
| 17559 | if eq k 2 |
| 17560 | a = ulong 4845287014151666853 |
| 17561 | b = ulong 4908688144209030790 |
| 17562 | end |
| 17563 | if eq k 3 |
| 17564 | a = ulong 1284945866654190727 |
| 17565 | b = ulong 5602828850577821594 |
| 17566 | end |
| 17567 | if eq k 4 |
| 17568 | a = ulong 5398063699126244139 |
| 17569 | b = ulong 4839848993530975643 |
| 17570 | end |
| 17571 | if eq k 5 |
| 17572 | a = ulong 1284199179690597154 |
| 17573 | b = ulong 4283602510276475278 |
| 17574 | end |
| 17575 | if eq k 6 |
| 17576 | a = ulong 1284253093421855137 |
| 17577 | b = ulong 4283602510276476814 |
| 17578 | end |
| 17579 | if eq k 7 |
| 17580 | a = ulong 1284208961261104786 |
| 17581 | b = ulong 4283602510276475278 |
| 17582 | end |
| 17583 | if eq k 9 |
| 17584 | a = ulong 5344813523769562436 |
| 17585 | b = ulong 10728454813909331609 |
| 17586 | end |
| 17587 | if eq k 10 |
| 17588 | a = ulong 1284420384822471985 |
| 17589 | b = ulong 5602828850577807002 |
| 17590 | end |
| 17591 | xword a |
| 17592 | xword shr a 32 |
| 17593 | xword b |
| 17594 | xword shr b 32 |
| 17595 | end |
| 17596 | xpatch br get oc 0 |
| 17597 | ret add p 4194304 |
| 17598 | end |
| 17599 | |
| 17600 | note xe k: 2 close the operation (error tails, then the shared end); 3 need N >= a (5); 4 need the |
| 17601 | note protocol in private slot a (3); 5 leave on a firmware error; 7 OR a into the info flags at A+4; |
| 17602 | note 8 LocateProtocol GUID a into slot b; 9 calibrate TSC ticks/ms over a 100 ms Stall (176, base 168); |
| 17603 | note 10 settle the transmit buffer at exit (status 88); 12 elapsed milliseconds into A. |
| 17604 | fn xe k ulong a ulong b ulong to void |
| 17605 | if eq k 2 |
| 17606 | xer 1 0 0 |
| 17607 | j = ulong 0 |
| 17608 | while lt j get xenerr 0 |
| 17609 | xpatch get xerrpos j get oc 0 |
| 17610 | ximm 0 or 9223372036854775808 get xerrcode j |
| 17611 | xer 1 0 0 |
| 17612 | j = add j 1 |
| 17613 | end |
| 17614 | i = ulong 0 |
| 17615 | while lt i get xenend 0 |
| 17616 | xpatch get xendpos i get oc 0 |
| 17617 | i = add i 1 |
| 17618 | end |
| 17619 | ret |
| 17620 | end |
| 17621 | if eq k 3 |
| 17622 | ximm 0 a |
| 17623 | xrr 57 13 0 |
| 17624 | xer 0 3 5 |
| 17625 | ret |
| 17626 | end |
| 17627 | if eq k 4 |
| 17628 | xp 1 1 a |
| 17629 | xrr 133 1 1 |
| 17630 | xer 0 0 3 |
| 17631 | ret |
| 17632 | end |
| 17633 | if eq k 5 |
| 17634 | xrr 133 0 0 |
| 17635 | ok = xbranch 0 |
| 17636 | xleave |
| 17637 | xpatch ok get oc 0 |
| 17638 | ret |
| 17639 | end |
| 17640 | if eq k 7 |
| 17641 | xhraw 0 12 4 4 |
| 17642 | ximm 2 a |
| 17643 | xrr 9 0 2 |
| 17644 | xhput 0 12 4 4 |
| 17645 | ret |
| 17646 | end |
| 17647 | if eq k 8 |
| 17648 | g = xg a |
| 17649 | xaddr 1 g |
| 17650 | ximm 2 0 |
| 17651 | xp 0 8 b |
| 17652 | xp 3 0 320 |
| 17653 | note LocateProtocol is optional. Failed output is discarded, never dereferenced. |
| 17654 | xrr 133 0 0 |
| 17655 | ok8 = xbranch 0 |
| 17656 | ximm 0 0 |
| 17657 | xp 2 0 b |
| 17658 | xpatch ok8 get oc 0 |
| 17659 | ret |
| 17660 | end |
| 17661 | if eq k 9 |
| 17662 | xer 2 0 0 |
| 17663 | xp 2 0 160 |
| 17664 | ximm 1 100000 |
| 17665 | xp 3 0 248 |
| 17666 | xrr 133 0 0 |
| 17667 | ok9 = xbranch 0 |
| 17668 | xleave |
| 17669 | xpatch ok9 get oc 0 |
| 17670 | xer 2 0 0 |
| 17671 | xp 1 1 160 |
| 17672 | xrr 41 0 1 |
| 17673 | mono = xbranch 3 |
| 17674 | ximm 1 100 |
| 17675 | ximm 2 0 |
| 17676 | xb 72 247 241 |
| 17677 | xp 2 0 176 |
| 17678 | xer 2 0 0 |
| 17679 | xp 2 0 168 |
| 17680 | xpatch mono get oc 0 |
| 17681 | ret |
| 17682 | end |
| 17683 | if eq k 10 |
| 17684 | xp 1 1 96 |
| 17685 | xrr 133 1 1 |
| 17686 | none = xbranch 0 |
| 17687 | xp 1 0 72 |
| 17688 | xrr 133 0 0 |
| 17689 | idle = xbranch 0 |
| 17690 | ximm 0 0 |
| 17691 | xp 2 0 80 |
| 17692 | ximm 2 0 |
| 17693 | xp 0 8 80 |
| 17694 | xp 4 24 88 |
| 17695 | xp 1 0 80 |
| 17696 | xp 1 2 96 |
| 17697 | xrr 57 0 2 |
| 17698 | busy = xbranch 1 |
| 17699 | xpatch idle get oc 0 |
| 17700 | xp 1 1 96 |
| 17701 | xp 3 0 72 |
| 17702 | xrr 133 0 0 |
| 17703 | freed = xbranch 0 |
| 17704 | xp 2 0 88 |
| 17705 | xpatch freed get oc 0 |
| 17706 | fin = xbranch 14 |
| 17707 | xpatch busy get oc 0 |
| 17708 | note Do not free or reuse an unreturned DMA buffer. Expose NOT_READY on exit. |
| 17709 | ximm 0 9223372036854775814 |
| 17710 | xp 2 0 88 |
| 17711 | xpatch fin get oc 0 |
| 17712 | xpatch none get oc 0 |
| 17713 | ret |
| 17714 | end |
| 17715 | xp 1 1 176 |
| 17716 | xrr 133 1 1 |
| 17717 | xer 0 0 3 |
| 17718 | xer 2 0 0 |
| 17719 | xp 1 2 168 |
| 17720 | xrr 41 0 2 |
| 17721 | xer 0 3 3 |
| 17722 | ximm 2 0 |
| 17723 | xb 72 247 241 |
| 17724 | xmem 137 0 12 0 |
| 17725 | ximm 0 0 |
| 17726 | end |
| 17727 | |
| 17728 | note xefx k: 0 image entry, 1 the shared firmware return (every exit site lands here), 2 PE32+ headers. |
| 17729 | fn xefx k ulong a ulong to void |
| 17730 | if eq k 0 |
| 17731 | note Preserve the integer nonvolatiles, MXCSR and XMM6-15 (UEFI 2.3.4.2), then install the owned stack. |
| 17732 | emitb 83 |
| 17733 | emitb 85 |
| 17734 | emitb 86 |
| 17735 | emitb 87 |
| 17736 | xb 65 84 65 |
| 17737 | emitb 85 |
| 17738 | xb 65 86 65 |
| 17739 | emitb 87 |
| 17740 | xp 2 4 2048 |
| 17741 | xp 2 1 8 |
| 17742 | xp 2 2 0 |
| 17743 | xp 0 10 2056 |
| 17744 | xb 65 15 174 |
| 17745 | emitb 26 |
| 17746 | xp 0 10 2080 |
| 17747 | j = ulong 6 |
| 17748 | while lt j 16 |
| 17749 | emitb 243 |
| 17750 | emitb uchar add 65 mul shr j 3 4 |
| 17751 | xb 15 127 add 130 shl and j 7 3 |
| 17752 | xword mul sub j 6 16 |
| 17753 | j = add j 1 |
| 17754 | end |
| 17755 | note MXCSR 0x1F80: all exceptions masked, round to nearest, as on x86 Linux. |
| 17756 | ximm 0 8064 |
| 17757 | xp 2 0 2064 |
| 17758 | xp 0 10 2064 |
| 17759 | xb 65 15 174 |
| 17760 | emitb 18 |
| 17761 | xp 0 15 16384 |
| 17762 | xp 0 4 8388608 |
| 17763 | ximm 5 0 |
| 17764 | note Entry has its own 80-byte EFI home/argument reservation, not an Omega frame. |
| 17765 | xb 72 129 236 |
| 17766 | xword 80 |
| 17767 | ximm 1 0 |
| 17768 | ximm 2 0 |
| 17769 | ximm 8 0 |
| 17770 | ximm 9 0 |
| 17771 | xp 3 0 256 |
| 17772 | xe 5 0 0 |
| 17773 | note TX storage outlives the image if firmware fails to release an in-flight packet. |
| 17774 | ximm 1 2 |
| 17775 | ximm 2 2048 |
| 17776 | xp 0 8 96 |
| 17777 | xp 3 0 64 |
| 17778 | xe 5 0 0 |
| 17779 | xe 8 0 16 |
| 17780 | xe 8 2 32 |
| 17781 | xe 8 3 40 |
| 17782 | xe 8 4 48 |
| 17783 | note Intel SDM 20.17.1 invariant TSC, CPUID.80000007H:EDX[8]; otherwise calibrate lazily (op 10). |
| 17784 | ximm 0 1 |
| 17785 | emitb 15 |
| 17786 | emitb 162 |
| 17787 | ximm 0 16 |
| 17788 | xrr 33 2 0 |
| 17789 | xrr 133 2 2 |
| 17790 | no1 = xbranch 0 |
| 17791 | ximm 0 2147483648 |
| 17792 | emitb 15 |
| 17793 | emitb 162 |
| 17794 | ximm 2 2147483655 |
| 17795 | xrr 57 0 2 |
| 17796 | no2 = xbranch 3 |
| 17797 | ximm 0 2147483655 |
| 17798 | emitb 15 |
| 17799 | emitb 162 |
| 17800 | ximm 0 256 |
| 17801 | xrr 33 2 0 |
| 17802 | xrr 133 2 2 |
| 17803 | no3 = xbranch 0 |
| 17804 | xe 9 0 0 |
| 17805 | xpatch no1 get oc 0 |
| 17806 | xpatch no2 get oc 0 |
| 17807 | xpatch no3 get oc 0 |
| 17808 | xb 72 129 196 |
| 17809 | xword 80 |
| 17810 | ret |
| 17811 | end |
| 17812 | if eq k 1 |
| 17813 | i = ulong 0 |
| 17814 | while lt i get xnexit 0 |
| 17815 | xpatch get xexsite i get oc 0 |
| 17816 | i = add i 1 |
| 17817 | end |
| 17818 | note Restore a known-good private stack even when an Omega stack check failed. |
| 17819 | xp 0 4 8388608 |
| 17820 | xb 72 129 236 |
| 17821 | xword 80 |
| 17822 | xp 2 0 88 |
| 17823 | note An efi 12 file still open at exit (return, exit or trap) is flushed when writable, then the file |
| 17824 | note and its volume root are closed and the slot cleared, as a process exit closes descriptors. |
| 17825 | xp 1 1 2304 |
| 17826 | xrr 133 1 1 |
| 17827 | p1 = xbranch 0 |
| 17828 | xp 1 0 2320 |
| 17829 | xrr 133 0 0 |
| 17830 | p2 = xbranch 0 |
| 17831 | xp 4 2304 80 |
| 17832 | xpatch p2 get oc 0 |
| 17833 | xp 4 2304 16 |
| 17834 | xpatch p1 get oc 0 |
| 17835 | xp 1 1 2312 |
| 17836 | xrr 133 1 1 |
| 17837 | p3 = xbranch 0 |
| 17838 | xp 4 2312 16 |
| 17839 | xpatch p3 get oc 0 |
| 17840 | ximm 0 0 |
| 17841 | xp 2 0 2304 |
| 17842 | xp 2 0 2312 |
| 17843 | xp 2 0 2320 |
| 17844 | xe 10 0 0 |
| 17845 | xp 0 10 2080 |
| 17846 | r = ulong 6 |
| 17847 | while lt r 16 |
| 17848 | emitb 243 |
| 17849 | emitb uchar add 65 mul shr r 3 4 |
| 17850 | xb 15 111 add 130 shl and r 7 3 |
| 17851 | xword mul sub r 6 16 |
| 17852 | r = add r 1 |
| 17853 | end |
| 17854 | xp 0 10 2056 |
| 17855 | xb 65 15 174 |
| 17856 | emitb 18 |
| 17857 | xp 1 0 88 |
| 17858 | xp 1 11 2048 |
| 17859 | xrr 137 4 11 |
| 17860 | xb 65 95 65 |
| 17861 | emitb 94 |
| 17862 | xb 65 93 65 |
| 17863 | emitb 92 |
| 17864 | emitb 95 |
| 17865 | emitb 94 |
| 17866 | emitb 93 |
| 17867 | emitb 91 |
| 17868 | emitb 195 |
| 17869 | ret |
| 17870 | end |
| 17871 | note PE32+ UEFI application. Section/file alignment 4096/512; every address is RIP-relative, so the |
| 17872 | note image is position independent. A valid empty relocation block keeps loader relocation support. |
| 17873 | while ne and get oc 0 511 0 |
| 17874 | emitb 0 |
| 17875 | end |
| 17876 | raw = sub get oc 0 512 |
| 17877 | bs = shl shr add add raw 4096 4095 12 12 |
| 17878 | put xbss 0 bs |
| 17879 | wrword 0 23117 |
| 17880 | wrword 60 64 |
| 17881 | wrword 64 17744 |
| 17882 | wrword 68 165476 |
| 17883 | wrword 84 2228464 |
| 17884 | wrword 88 523 |
| 17885 | wrword 92 raw |
| 17886 | wrword 100 add get poolb 0 8388608 |
| 17887 | wrword 104 add a 3584 |
| 17888 | wrword 108 4096 |
| 17889 | wrword 112 4194304 |
| 17890 | wrword 120 4096 |
| 17891 | wrword 124 512 |
| 17892 | wrword 128 6 |
| 17893 | wrword 136 6 |
| 17894 | wrword 144 shl shr add add bs add get poolb 0 8388608 4095 12 12 |
| 17895 | wrword 148 512 |
| 17896 | wrword 156 4194314 |
| 17897 | wrword 160 1048576 |
| 17898 | wrword 168 4096 |
| 17899 | wrword 176 1048576 |
| 17900 | wrword 184 4096 |
| 17901 | wrword 196 16 |
| 17902 | wrword 512 0 |
| 17903 | wrword 516 8 |
| 17904 | note Base relocation directory points to the first eight bytes of .text, reserved by the driver. |
| 17905 | wrword 240 4096 |
| 17906 | wrword 244 8 |
| 17907 | wrword 328 2019914798 |
| 17908 | wrword 332 116 |
| 17909 | wrword 336 raw |
| 17910 | wrword 340 4096 |
| 17911 | wrword 344 raw |
| 17912 | wrword 348 512 |
| 17913 | wrword 364 1610612768 |
| 17914 | wrword 368 1936941614 |
| 17915 | wrword 376 add get poolb 0 8388608 |
| 17916 | wrword 380 bs |
| 17917 | wrword 404 3221225600 |
| 17918 | end |
| 17919 | |
| 17920 | fn xefival dst ulong to void |
| 17921 | if ne get xtarget 0 2 |
| 17922 | fail 25 |
| 17923 | end |
| 17924 | x = mul get depth 0 32 |
| 17925 | put fr add x 7 get nslot 0 |
| 17926 | op = lenval 4 |
| 17927 | if gt op 14 |
| 17928 | fail 25 |
| 17929 | end |
| 17930 | harg x 2 5 |
| 17931 | e = harray x 1 |
| 17932 | note RBX anchors the snapshot only until ARG is loaded; firmware-preserved R14 carries it across the call |
| 17933 | note (UEFI 2.3.4.2), and the caller's R14 waits in the snapshot tail beside R13. |
| 17934 | xhbegin |
| 17935 | xmem 137 14 3 152 |
| 17936 | xrr 137 14 3 |
| 17937 | xhb 12 e get fr add x 21 |
| 17938 | xhs 13 get fr add x 22 |
| 17939 | xha x 2 3 |
| 17940 | note Firmware runs on the owned stack: reserve 64 KiB (trap 6), then align RSP for UEFI 2.3.4.2. |
| 17941 | xcheck 65536 |
| 17942 | xb 72 131 228 |
| 17943 | emitb 240 |
| 17944 | xb 72 129 236 |
| 17945 | xword 80 |
| 17946 | put xenerr 0 0 |
| 17947 | put xenend 0 0 |
| 17948 | xeop op |
| 17949 | xe 2 0 0 |
| 17950 | xrr 137 4 14 |
| 17951 | xmem 139 13 4 144 |
| 17952 | xmem 139 14 4 152 |
| 17953 | r = restore dst get fr add x 7 get svn 0 get sva 0 1 |
| 17954 | vdone 1 r 5 |
| 17955 | end |
| 17956 | |
| 17957 | note Operation registers: RBX = ARG, R12 = A+OFF, R13 = N; the result or error is RAX. |
| 17958 | fn xeop op ulong to void |
| 17959 | if eq op 1 |
| 17960 | xe 3 4 0 |
| 17961 | xp 1 1 0 |
| 17962 | xmem 139 1 1 48 |
| 17963 | xrr 133 1 1 |
| 17964 | xer 0 0 3 |
| 17965 | xrr 137 2 12 |
| 17966 | xmem 139 11 1 8 |
| 17967 | xb 65 255 211 |
| 17968 | ret |
| 17969 | end |
| 17970 | if eq op 2 |
| 17971 | xrr 137 1 3 |
| 17972 | xp 3 0 248 |
| 17973 | ret |
| 17974 | end |
| 17975 | if eq op 4 |
| 17976 | xe 3 16 0 |
| 17977 | xp 1 11 0 |
| 17978 | xmem 139 11 11 88 |
| 17979 | xmem 139 11 11 24 |
| 17980 | xrr 137 1 12 |
| 17981 | ximm 2 0 |
| 17982 | xb 65 255 211 |
| 17983 | ret |
| 17984 | end |
| 17985 | if eq op 8 |
| 17986 | xenet |
| 17987 | ret |
| 17988 | end |
| 17989 | if eq op 10 |
| 17990 | xe 3 8 0 |
| 17991 | xp 1 1 176 |
| 17992 | xrr 133 1 1 |
| 17993 | ok = xbranch 1 |
| 17994 | xe 9 0 0 |
| 17995 | xpatch ok get oc 0 |
| 17996 | xe 12 0 0 |
| 17997 | ret |
| 17998 | end |
| 17999 | if eq op 11 |
| 18000 | xefile |
| 18001 | ret |
| 18002 | end |
| 18003 | if eq op 12 |
| 18004 | xf12 |
| 18005 | ret |
| 18006 | end |
| 18007 | if eq op 14 |
| 18008 | xf14 |
| 18009 | ret |
| 18010 | end |
| 18011 | xdev op |
| 18012 | end |
| 18013 | |
| 18014 | note efi 14 machine identity; ARG bits 0..15 sub, 16..63 its parameter. Sub 0: CPUID leaf ARG>>16 |
| 18015 | note (below 2^32, else 32) with ECX 0, EAX EBX ECX EDX as four u32 at A+OFF (N >= 16, else 5), |
| 18016 | note result 16. ARG 1: the UCS-2 code units of SystemTable FirmwareVendor (+24) up to its NUL, at |
| 18017 | note most N bytes in whole units, result bytes copied (0 when the pointer is NULL). ARG 2: result |
| 18018 | note FirmwareRevision (+32). Sub 3: SMBIOS structure table bytes from position ARG>>16 into A |
| 18019 | note (at most N), result bytes copied, 0 at or past the end. The table comes from the configuration |
| 18020 | note table: the SMBIOS3 entry point (_SM3_, size u32 @12, address u64 @16) first, else SMBIOS 2.x |
| 18021 | note (_SM_, length u16 @22, address u32 @24); 44 when neither is there, an anchor is wrong or the |
| 18022 | note address is 0. Any other ARG is 32. Nothing is written past A+OFF+N. |
| 18023 | fn xf14 to void |
| 18024 | ximm 0 1 |
| 18025 | xrr 57 3 0 |
| 18026 | p = xbranch 1 |
| 18027 | xp 1 1 0 |
| 18028 | xmem 139 6 1 24 |
| 18029 | ximm 0 0 |
| 18030 | xrr 137 7 12 |
| 18031 | xrr 137 9 13 |
| 18032 | xrr 133 6 6 |
| 18033 | z = xbranch 0 |
| 18034 | loop = get oc 0 |
| 18035 | ximm 2 2 |
| 18036 | xrr 57 9 2 |
| 18037 | d1 = xbranch 3 |
| 18038 | xhraw 2 6 0 2 |
| 18039 | xrr 133 2 2 |
| 18040 | d2 = xbranch 0 |
| 18041 | xhput 2 7 0 2 |
| 18042 | xb 72 131 198 |
| 18043 | emitb 2 |
| 18044 | xb 72 131 199 |
| 18045 | emitb 2 |
| 18046 | xb 72 131 192 |
| 18047 | emitb 2 |
| 18048 | xb 73 131 233 |
| 18049 | emitb 2 |
| 18050 | q = xbranch 14 |
| 18051 | xpatch q loop |
| 18052 | xpatch z get oc 0 |
| 18053 | xpatch d1 get oc 0 |
| 18054 | xpatch d2 get oc 0 |
| 18055 | xer 1 0 0 |
| 18056 | xpatch p get oc 0 |
| 18057 | ximm 0 2 |
| 18058 | xrr 57 3 0 |
| 18059 | p = xbranch 1 |
| 18060 | xp 1 1 0 |
| 18061 | xhraw 0 1 32 4 |
| 18062 | xer 1 0 0 |
| 18063 | xpatch p get oc 0 |
| 18064 | xrr 137 6 3 |
| 18065 | ximm 0 65535 |
| 18066 | xrr 33 6 0 |
| 18067 | p = xbranch 1 |
| 18068 | xe 3 16 0 |
| 18069 | xrr 137 0 3 |
| 18070 | xb 72 193 232 |
| 18071 | emitb 16 |
| 18072 | xrr 137 2 0 |
| 18073 | xb 72 193 234 |
| 18074 | emitb 32 |
| 18075 | xrr 133 2 2 |
| 18076 | xer 0 1 32 |
| 18077 | ximm 1 0 |
| 18078 | emitb 15 |
| 18079 | emitb 162 |
| 18080 | xhput 0 12 0 4 |
| 18081 | xhput 3 12 4 4 |
| 18082 | xhput 1 12 8 4 |
| 18083 | xhput 2 12 12 4 |
| 18084 | ximm 0 16 |
| 18085 | xer 1 0 0 |
| 18086 | xpatch p get oc 0 |
| 18087 | ximm 0 3 |
| 18088 | xrr 57 6 0 |
| 18089 | xer 0 1 32 |
| 18090 | xp 1 1 0 |
| 18091 | xmem 139 8 1 104 |
| 18092 | xmem 139 9 1 112 |
| 18093 | f3 = ulong 0 |
| 18094 | f = ulong 0 |
| 18095 | g = ulong 9 |
| 18096 | while le g 10 |
| 18097 | xaddr 10 xg g |
| 18098 | xrr 137 11 9 |
| 18099 | xrr 137 1 8 |
| 18100 | loop = get oc 0 |
| 18101 | xrr 133 1 1 |
| 18102 | miss = xbranch 0 |
| 18103 | xmem 139 0 11 0 |
| 18104 | xmem 59 0 10 0 |
| 18105 | n1 = xbranch 1 |
| 18106 | xmem 139 0 11 8 |
| 18107 | xmem 59 0 10 8 |
| 18108 | n2 = xbranch 1 |
| 18109 | xmem 139 6 11 16 |
| 18110 | f = xbranch 14 |
| 18111 | xpatch n1 get oc 0 |
| 18112 | xpatch n2 get oc 0 |
| 18113 | xb 73 131 195 |
| 18114 | emitb 24 |
| 18115 | xb 72 131 233 |
| 18116 | emitb 1 |
| 18117 | q = xbranch 14 |
| 18118 | xpatch q loop |
| 18119 | xpatch miss get oc 0 |
| 18120 | if eq g 9 |
| 18121 | f3 = f |
| 18122 | end |
| 18123 | g = add g 1 |
| 18124 | end |
| 18125 | xer 0 14 44 |
| 18126 | xpatch f get oc 0 |
| 18127 | xrr 133 6 6 |
| 18128 | xer 0 0 44 |
| 18129 | xhraw 0 6 0 4 |
| 18130 | ximm 2 1598903135 |
| 18131 | xrr 57 0 2 |
| 18132 | xer 0 1 44 |
| 18133 | xhraw 8 6 22 2 |
| 18134 | xhraw 6 6 24 4 |
| 18135 | cp = xbranch 14 |
| 18136 | xpatch f3 get oc 0 |
| 18137 | xrr 133 6 6 |
| 18138 | xer 0 0 44 |
| 18139 | xhraw 0 6 0 4 |
| 18140 | ximm 2 860705631 |
| 18141 | xrr 57 0 2 |
| 18142 | xer 0 1 44 |
| 18143 | xhraw 8 6 12 4 |
| 18144 | xmem 139 6 6 16 |
| 18145 | xpatch cp get oc 0 |
| 18146 | xrr 133 6 6 |
| 18147 | xer 0 0 44 |
| 18148 | xrr 137 2 3 |
| 18149 | xb 72 193 234 |
| 18150 | emitb 16 |
| 18151 | ximm 0 0 |
| 18152 | xrr 57 2 8 |
| 18153 | done = xbranch 2 |
| 18154 | xrr 137 1 8 |
| 18155 | xrr 41 1 2 |
| 18156 | xrr 57 1 13 |
| 18157 | ok = xbranch 9 |
| 18158 | xrr 137 1 13 |
| 18159 | xpatch ok get oc 0 |
| 18160 | xrr 1 6 2 |
| 18161 | xrr 137 7 12 |
| 18162 | xrr 137 0 1 |
| 18163 | emitb 252 |
| 18164 | emitb 243 |
| 18165 | emitb 164 |
| 18166 | xpatch done get oc 0 |
| 18167 | end |
| 18168 | |
| 18169 | note Device operations: 0 info, 3 GOP Blt, 5 entropy, 6 receive, 7 transmit, 9 pointer, 13 console. |
| 18170 | note OP0 info, 64 bytes: u32 version=1, flags (1 GOP, 2 net, 4 RNG, 8 pointer), u32 width/height@8, |
| 18171 | note pixelFormat@16, stride@20, MAC[6]@24, maxPacket@32, hwAddrSize@36, media@40, state@44, txBusy@48. |
| 18172 | note OP3 ARG: width bits0..31, height bits32..47, destination row bits48..63 (UEFI 12.9.2 Blt). |
| 18173 | fn xdev op ulong to void |
| 18174 | if eq op 0 |
| 18175 | xe 3 64 0 |
| 18176 | ximm 0 0 |
| 18177 | j = ulong 0 |
| 18178 | while lt j 64 |
| 18179 | xmem 137 0 12 j |
| 18180 | j = add j 8 |
| 18181 | end |
| 18182 | ximm 0 1 |
| 18183 | xmem 137 0 12 0 |
| 18184 | xp 1 1 16 |
| 18185 | xrr 133 1 1 |
| 18186 | p = xbranch 0 |
| 18187 | xmem 139 1 1 24 |
| 18188 | xrr 133 1 1 |
| 18189 | z1 = xbranch 0 |
| 18190 | xmem 139 1 1 8 |
| 18191 | xrr 133 1 1 |
| 18192 | z2 = xbranch 0 |
| 18193 | xmem 139 0 1 4 |
| 18194 | xmem 137 0 12 8 |
| 18195 | xhraw 0 1 12 4 |
| 18196 | xhput 0 12 16 4 |
| 18197 | xhraw 0 1 32 4 |
| 18198 | xhput 0 12 20 4 |
| 18199 | ximm 0 1 |
| 18200 | xhput 0 12 4 4 |
| 18201 | xpatch p get oc 0 |
| 18202 | xp 1 1 24 |
| 18203 | xrr 133 1 1 |
| 18204 | p = xbranch 0 |
| 18205 | xmem 139 1 1 120 |
| 18206 | xrr 133 1 1 |
| 18207 | z3 = xbranch 0 |
| 18208 | xhraw 0 1 552 4 |
| 18209 | xhput 0 12 24 4 |
| 18210 | xhraw 0 1 556 2 |
| 18211 | xhput 0 12 28 4 |
| 18212 | xhraw 0 1 12 4 |
| 18213 | xhput 0 12 32 4 |
| 18214 | xhraw 0 1 4 4 |
| 18215 | xhput 0 12 36 4 |
| 18216 | xhraw 0 1 652 1 |
| 18217 | xhput 0 12 40 4 |
| 18218 | xhraw 0 1 0 4 |
| 18219 | xhput 0 12 44 4 |
| 18220 | xp 1 0 72 |
| 18221 | xhput 0 12 48 4 |
| 18222 | xe 7 2 0 |
| 18223 | xpatch p get oc 0 |
| 18224 | xp 1 1 32 |
| 18225 | xrr 133 1 1 |
| 18226 | p = xbranch 0 |
| 18227 | xe 7 4 0 |
| 18228 | xpatch p get oc 0 |
| 18229 | xp 1 1 40 |
| 18230 | xp 1 2 48 |
| 18231 | xrr 9 1 2 |
| 18232 | xrr 133 1 1 |
| 18233 | p = xbranch 0 |
| 18234 | xe 7 8 0 |
| 18235 | xpatch p get oc 0 |
| 18236 | xpatch z1 get oc 0 |
| 18237 | xpatch z2 get oc 0 |
| 18238 | xpatch z3 get oc 0 |
| 18239 | ximm 0 0 |
| 18240 | ret |
| 18241 | end |
| 18242 | if eq op 3 |
| 18243 | xe 4 16 0 |
| 18244 | xrr 137 8 3 |
| 18245 | xb 73 193 232 |
| 18246 | emitb 32 |
| 18247 | ximm 0 65535 |
| 18248 | xrr 33 8 0 |
| 18249 | xrr 137 10 3 |
| 18250 | xb 73 193 234 |
| 18251 | emitb 48 |
| 18252 | xrr 137 9 3 |
| 18253 | ximm 0 4294967295 |
| 18254 | xrr 33 9 0 |
| 18255 | xrr 133 8 8 |
| 18256 | xer 0 0 2 |
| 18257 | xrr 133 9 9 |
| 18258 | xer 0 0 2 |
| 18259 | xmem 139 2 1 24 |
| 18260 | xrr 133 2 2 |
| 18261 | xer 0 0 2 |
| 18262 | xmem 139 2 2 8 |
| 18263 | xrr 133 2 2 |
| 18264 | xer 0 0 2 |
| 18265 | xhraw 0 2 4 4 |
| 18266 | xrr 57 9 0 |
| 18267 | xer 0 8 2 |
| 18268 | xhraw 0 2 8 4 |
| 18269 | xrr 41 0 10 |
| 18270 | xer 0 3 2 |
| 18271 | xrr 57 8 0 |
| 18272 | xer 0 8 2 |
| 18273 | xrr 137 0 8 |
| 18274 | xb 73 15 175 |
| 18275 | emitb 193 |
| 18276 | xb 72 193 224 |
| 18277 | emitb 2 |
| 18278 | xrr 57 0 13 |
| 18279 | xer 0 1 2 |
| 18280 | xmem 137 9 4 56 |
| 18281 | xmem 137 8 4 64 |
| 18282 | ximm 0 0 |
| 18283 | xmem 137 0 4 32 |
| 18284 | xmem 137 0 4 40 |
| 18285 | xmem 137 10 4 48 |
| 18286 | xmem 137 0 4 72 |
| 18287 | xrr 137 2 12 |
| 18288 | ximm 8 2 |
| 18289 | ximm 9 0 |
| 18290 | xp 4 16 16 |
| 18291 | ret |
| 18292 | end |
| 18293 | if eq op 5 |
| 18294 | note RNG protocol when present; else Intel SDM RDRAND (CPUID.1:ECX[30], CF = valid), ten attempts |
| 18295 | note per byte, then EFI_NOT_READY, never fallback data. |
| 18296 | xp 1 1 32 |
| 18297 | xrr 133 1 1 |
| 18298 | p = xbranch 0 |
| 18299 | ximm 2 0 |
| 18300 | xrr 137 8 13 |
| 18301 | xrr 137 9 12 |
| 18302 | xp 4 32 8 |
| 18303 | xer 1 0 0 |
| 18304 | xpatch p get oc 0 |
| 18305 | ximm 0 0 |
| 18306 | emitb 15 |
| 18307 | emitb 162 |
| 18308 | ximm 2 1 |
| 18309 | xrr 57 0 2 |
| 18310 | xer 0 3 3 |
| 18311 | ximm 0 1 |
| 18312 | emitb 15 |
| 18313 | emitb 162 |
| 18314 | ximm 2 1073741824 |
| 18315 | xrr 33 1 2 |
| 18316 | xrr 133 1 1 |
| 18317 | xer 0 0 3 |
| 18318 | xrr 137 7 12 |
| 18319 | xrr 137 6 13 |
| 18320 | lp = get oc 0 |
| 18321 | xrr 133 6 6 |
| 18322 | q = xbranch 0 |
| 18323 | ximm 1 10 |
| 18324 | rw = get oc 0 |
| 18325 | xb 72 15 199 |
| 18326 | emitb 240 |
| 18327 | s = xbranch 3 |
| 18328 | xb 72 255 201 |
| 18329 | p = xbranch 1 |
| 18330 | xpatch p rw |
| 18331 | xer 0 14 6 |
| 18332 | xpatch s get oc 0 |
| 18333 | emitb 136 |
| 18334 | emitb 7 |
| 18335 | xb 72 255 199 |
| 18336 | xb 72 255 206 |
| 18337 | back lp |
| 18338 | xpatch q get oc 0 |
| 18339 | ximm 0 0 |
| 18340 | ret |
| 18341 | end |
| 18342 | if eq op 6 |
| 18343 | xe 3 9 0 |
| 18344 | xe 4 24 0 |
| 18345 | xrr 137 0 13 |
| 18346 | xb 72 131 232 |
| 18347 | emitb 8 |
| 18348 | xmem 137 0 12 0 |
| 18349 | ximm 2 0 |
| 18350 | xrr 137 8 12 |
| 18351 | xmem 141 9 12 8 |
| 18352 | ximm 0 0 |
| 18353 | xmem 137 0 4 32 |
| 18354 | xmem 137 0 4 40 |
| 18355 | xmem 137 0 4 48 |
| 18356 | xp 4 24 104 |
| 18357 | ret |
| 18358 | end |
| 18359 | if eq op 7 |
| 18360 | note Transmit always owns its private packet until GetStatus reclaims that exact address (UEFI 24.1.12). |
| 18361 | xe 4 24 0 |
| 18362 | xe 3 14 0 |
| 18363 | ximm 0 2048 |
| 18364 | xrr 57 13 0 |
| 18365 | xer 0 8 4 |
| 18366 | xp 1 0 72 |
| 18367 | xrr 133 0 0 |
| 18368 | p = xbranch 0 |
| 18369 | ximm 0 0 |
| 18370 | xp 2 0 80 |
| 18371 | ximm 2 0 |
| 18372 | xp 0 8 80 |
| 18373 | xp 4 24 88 |
| 18374 | xrr 133 0 0 |
| 18375 | xer 0 1 6 |
| 18376 | xp 1 0 80 |
| 18377 | xp 1 2 96 |
| 18378 | xrr 57 0 2 |
| 18379 | xer 0 1 6 |
| 18380 | ximm 0 0 |
| 18381 | xp 2 0 72 |
| 18382 | xpatch p get oc 0 |
| 18383 | xrr 137 6 12 |
| 18384 | xp 1 7 96 |
| 18385 | xrr 137 1 13 |
| 18386 | emitb 252 |
| 18387 | emitb 243 |
| 18388 | emitb 164 |
| 18389 | ximm 2 0 |
| 18390 | xrr 137 8 13 |
| 18391 | xp 1 9 96 |
| 18392 | ximm 0 0 |
| 18393 | xmem 137 0 4 32 |
| 18394 | xmem 137 0 4 40 |
| 18395 | xmem 137 0 4 48 |
| 18396 | xp 4 24 96 |
| 18397 | xrr 133 0 0 |
| 18398 | p = xbranch 1 |
| 18399 | ximm 2 1 |
| 18400 | xp 2 2 72 |
| 18401 | xpatch p get oc 0 |
| 18402 | ret |
| 18403 | end |
| 18404 | if eq op 9 |
| 18405 | xe 3 32 0 |
| 18406 | xp 1 1 40 |
| 18407 | xrr 133 1 1 |
| 18408 | q = xbranch 0 |
| 18409 | xp 0 2 256 |
| 18410 | xp 4 40 8 |
| 18411 | xrr 133 0 0 |
| 18412 | p = xbranch 1 |
| 18413 | xp 0 2 256 |
| 18414 | ximm 0 1 |
| 18415 | xmem 137 0 12 0 |
| 18416 | xhraw 0 2 12 1 |
| 18417 | xhraw 1 2 13 1 |
| 18418 | xb 72 193 225 |
| 18419 | emitb 1 |
| 18420 | xrr 9 0 1 |
| 18421 | xhput 0 12 4 4 |
| 18422 | i = ulong 0 |
| 18423 | while lt i 3 |
| 18424 | note MOVSXD rax,dword [rdx+disp32], Intel MOVSX/MOVSXD. |
| 18425 | xb 72 99 130 |
| 18426 | xword mul i 4 |
| 18427 | xmem 137 0 12 add 8 mul i 8 |
| 18428 | i = add i 1 |
| 18429 | end |
| 18430 | ximm 0 0 |
| 18431 | xpatch p get oc 0 |
| 18432 | xer 1 0 0 |
| 18433 | xpatch q get oc 0 |
| 18434 | xe 4 48 0 |
| 18435 | xp 0 2 256 |
| 18436 | xp 4 48 8 |
| 18437 | xrr 133 0 0 |
| 18438 | p = xbranch 1 |
| 18439 | xp 0 2 256 |
| 18440 | ximm 0 2 |
| 18441 | xmem 137 0 12 0 |
| 18442 | xhraw 0 2 24 4 |
| 18443 | xhput 0 12 4 4 |
| 18444 | i = ulong 0 |
| 18445 | while lt i 3 |
| 18446 | xmem 139 0 2 mul i 8 |
| 18447 | xmem 137 0 12 add 8 mul i 8 |
| 18448 | i = add i 1 |
| 18449 | end |
| 18450 | ximm 0 0 |
| 18451 | xpatch p get oc 0 |
| 18452 | ret |
| 18453 | end |
| 18454 | if ne op 13 |
| 18455 | fail 25 |
| 18456 | end |
| 18457 | note efi 13: write A[OFF..OFF+N) to ConOut (UEFI 12.4 OutputString). ARG must be 0; only bytes 9, 10, |
| 18458 | note 13 and 32..126, all checked before any output; LF becomes CR LF; UCS-2 chunks of at most 255 |
| 18459 | note characters in private 4096. Warnings (bit 63 clear) are not errors. Result N. |
| 18460 | xrr 133 3 3 |
| 18461 | xer 0 1 32 |
| 18462 | xrr 137 8 12 |
| 18463 | xrr 137 9 13 |
| 18464 | lp = get oc 0 |
| 18465 | xrr 133 9 9 |
| 18466 | p = xbranch 0 |
| 18467 | xhraw 0 8 0 1 |
| 18468 | ximm 2 9 |
| 18469 | xrr 57 0 2 |
| 18470 | q = xbranch 0 |
| 18471 | ximm 2 10 |
| 18472 | xrr 57 0 2 |
| 18473 | rw = xbranch 0 |
| 18474 | ximm 2 13 |
| 18475 | xrr 57 0 2 |
| 18476 | s = xbranch 0 |
| 18477 | ximm 2 32 |
| 18478 | xrr 57 0 2 |
| 18479 | xer 0 3 42 |
| 18480 | ximm 2 126 |
| 18481 | xrr 57 0 2 |
| 18482 | xer 0 8 42 |
| 18483 | xpatch q get oc 0 |
| 18484 | xpatch rw get oc 0 |
| 18485 | xpatch s get oc 0 |
| 18486 | xb 73 131 192 |
| 18487 | emitb 1 |
| 18488 | xb 73 131 233 |
| 18489 | emitb 1 |
| 18490 | back lp |
| 18491 | xpatch p get oc 0 |
| 18492 | note ConOut (SystemTable+64) may be NULL on headless firmware: refuse with 43 before any call. |
| 18493 | xp 1 1 0 |
| 18494 | xmem 139 1 1 64 |
| 18495 | xrr 133 1 1 |
| 18496 | xer 0 0 43 |
| 18497 | xrr 137 6 12 |
| 18498 | xrr 137 3 13 |
| 18499 | ximm 7 0 |
| 18500 | lp = get oc 0 |
| 18501 | xrr 133 3 3 |
| 18502 | p = xbranch 0 |
| 18503 | ximm 0 254 |
| 18504 | xrr 57 7 0 |
| 18505 | q = xbranch 3 |
| 18506 | xpatch p get oc 0 |
| 18507 | xrr 133 7 7 |
| 18508 | rw = xbranch 0 |
| 18509 | xp 0 10 4096 |
| 18510 | xrr 137 11 7 |
| 18511 | xrr 1 11 11 |
| 18512 | xrr 1 10 11 |
| 18513 | ximm 0 0 |
| 18514 | xhput 0 10 0 2 |
| 18515 | xp 1 1 0 |
| 18516 | xmem 139 1 1 64 |
| 18517 | xp 0 2 4096 |
| 18518 | xmem 139 11 1 8 |
| 18519 | xb 65 255 211 |
| 18520 | xrr 133 0 0 |
| 18521 | xer 0 11 43 |
| 18522 | ximm 7 0 |
| 18523 | xpatch rw get oc 0 |
| 18524 | xrr 133 3 3 |
| 18525 | s = xbranch 0 |
| 18526 | xpatch q get oc 0 |
| 18527 | xp 0 10 4096 |
| 18528 | xrr 137 11 7 |
| 18529 | xrr 1 11 11 |
| 18530 | xrr 1 10 11 |
| 18531 | xhraw 0 6 0 1 |
| 18532 | ximm 2 10 |
| 18533 | xrr 57 0 2 |
| 18534 | p = xbranch 1 |
| 18535 | ximm 0 13 |
| 18536 | xhput 0 10 0 2 |
| 18537 | ximm 0 10 |
| 18538 | xhput 0 10 2 2 |
| 18539 | xb 72 131 199 |
| 18540 | emitb 1 |
| 18541 | q = xbranch 14 |
| 18542 | xpatch p get oc 0 |
| 18543 | xhput 0 10 0 2 |
| 18544 | xpatch q get oc 0 |
| 18545 | xb 72 131 199 |
| 18546 | emitb 1 |
| 18547 | xb 72 131 198 |
| 18548 | emitb 1 |
| 18549 | xb 72 131 235 |
| 18550 | emitb 1 |
| 18551 | back lp |
| 18552 | xpatch s get oc 0 |
| 18553 | xrr 137 0 13 |
| 18554 | end |
| 18555 | |
| 18556 | note UEFI 24.1 SNP mode: MAC array capacity 16, 32-byte MAC cells, current@552, IfType@648, |
| 18557 | note MediaPresentSupported@651, MediaPresent@652. k 0 probe candidate 128 (own error scope); |
| 18558 | note k 1 reject it: shut down/stop only what this application initialized/started. |
| 18559 | fn xenpr k ulong to void |
| 18560 | if eq k 1 |
| 18561 | xp 1 0 144 |
| 18562 | xrr 133 0 0 |
| 18563 | p = xbranch 0 |
| 18564 | xp 4 128 40 |
| 18565 | xpatch p get oc 0 |
| 18566 | xp 1 0 136 |
| 18567 | xrr 133 0 0 |
| 18568 | p = xbranch 0 |
| 18569 | xp 4 128 16 |
| 18570 | xpatch p get oc 0 |
| 18571 | ret |
| 18572 | end |
| 18573 | put xenerr 0 0 |
| 18574 | put xenend 0 0 |
| 18575 | ximm 0 0 |
| 18576 | xp 2 0 136 |
| 18577 | xp 2 0 144 |
| 18578 | xp 1 1 128 |
| 18579 | xmem 139 2 1 120 |
| 18580 | xrr 133 2 2 |
| 18581 | xer 0 0 3 |
| 18582 | xhraw 0 2 4 4 |
| 18583 | ximm 8 6 |
| 18584 | xrr 57 0 8 |
| 18585 | xer 0 1 3 |
| 18586 | xhraw 0 2 648 1 |
| 18587 | ximm 8 1 |
| 18588 | xrr 57 0 8 |
| 18589 | xer 0 1 3 |
| 18590 | xhraw 0 2 0 4 |
| 18591 | xrr 133 0 0 |
| 18592 | q = xbranch 1 |
| 18593 | xp 4 128 8 |
| 18594 | xrr 133 0 0 |
| 18595 | xer 0 1 7 |
| 18596 | ximm 0 1 |
| 18597 | xp 2 0 136 |
| 18598 | xpatch q get oc 0 |
| 18599 | xp 1 1 128 |
| 18600 | xmem 139 2 1 120 |
| 18601 | xhraw 0 2 0 4 |
| 18602 | ximm 8 1 |
| 18603 | xrr 57 0 8 |
| 18604 | q = xbranch 1 |
| 18605 | ximm 2 0 |
| 18606 | ximm 8 0 |
| 18607 | xp 4 128 24 |
| 18608 | xrr 133 0 0 |
| 18609 | xer 0 1 7 |
| 18610 | ximm 0 1 |
| 18611 | xp 2 0 144 |
| 18612 | xpatch q get oc 0 |
| 18613 | ximm 2 0 |
| 18614 | ximm 8 0 |
| 18615 | xp 4 128 88 |
| 18616 | xrr 133 0 0 |
| 18617 | xer 0 1 7 |
| 18618 | xp 1 1 128 |
| 18619 | xmem 139 2 1 120 |
| 18620 | xhraw 0 2 0 4 |
| 18621 | ximm 8 2 |
| 18622 | xrr 57 0 8 |
| 18623 | xer 0 1 6 |
| 18624 | note MediaPresent is binding only when the driver says media detection is supported. |
| 18625 | xhraw 0 2 651 1 |
| 18626 | xrr 133 0 0 |
| 18627 | q = xbranch 0 |
| 18628 | xhraw 0 2 652 1 |
| 18629 | xrr 133 0 0 |
| 18630 | xer 0 0 12 |
| 18631 | xpatch q get oc 0 |
| 18632 | xhraw 0 2 24 4 |
| 18633 | ximm 8 5 |
| 18634 | xrr 33 0 8 |
| 18635 | xrr 57 0 8 |
| 18636 | xer 0 1 3 |
| 18637 | ximm 2 5 |
| 18638 | ximm 8 0 |
| 18639 | ximm 9 0 |
| 18640 | ximm 0 0 |
| 18641 | xmem 137 0 4 32 |
| 18642 | xmem 137 0 4 40 |
| 18643 | xp 4 128 48 |
| 18644 | xe 2 0 0 |
| 18645 | end |
| 18646 | |
| 18647 | note UEFI 2.4 7.3 OpenProtocol EXCLUSIVE (32) disconnects MNP and the IP stack above SNP; while they |
| 18648 | note stay bound, MNP's poll timer drains frames no child wants (aienux#454). Firmware that refuses |
| 18649 | note keeps the shared HandleProtocol path. All candidates are tried for a live link. |
| 18650 | fn xenscan g ulong to void |
| 18651 | ximm 3 0 |
| 18652 | lp = get oc 0 |
| 18653 | xrr 57 3 7 |
| 18654 | ex = xbranch 2 |
| 18655 | xrr 137 0 3 |
| 18656 | xb 72 193 224 |
| 18657 | emitb 3 |
| 18658 | xrr 1 0 6 |
| 18659 | xmem 139 1 0 0 |
| 18660 | xaddr 2 g |
| 18661 | xp 0 8 128 |
| 18662 | xp 1 9 8 |
| 18663 | ximm 0 0 |
| 18664 | xmem 137 0 4 32 |
| 18665 | ximm 0 32 |
| 18666 | xmem 137 0 4 40 |
| 18667 | xp 3 0 280 |
| 18668 | xrr 133 0 0 |
| 18669 | p = xbranch 0 |
| 18670 | xrr 137 0 3 |
| 18671 | xb 72 193 224 |
| 18672 | emitb 3 |
| 18673 | xrr 1 0 6 |
| 18674 | xmem 139 1 0 0 |
| 18675 | xaddr 2 g |
| 18676 | xp 0 8 128 |
| 18677 | xp 3 0 152 |
| 18678 | xpatch p get oc 0 |
| 18679 | xrr 133 0 0 |
| 18680 | sk = xbranch 1 |
| 18681 | xenpr 0 |
| 18682 | xrr 133 0 0 |
| 18683 | p = xbranch 1 |
| 18684 | xp 1 0 128 |
| 18685 | xp 2 0 24 |
| 18686 | sel = xbranch 14 |
| 18687 | xpatch p get oc 0 |
| 18688 | xenpr 1 |
| 18689 | xpatch sk get oc 0 |
| 18690 | xb 72 255 195 |
| 18691 | back lp |
| 18692 | xpatch ex get oc 0 |
| 18693 | ximm 0 9223372036854775822 |
| 18694 | p = xbranch 14 |
| 18695 | xpatch sel get oc 0 |
| 18696 | ximm 0 0 |
| 18697 | xpatch p get oc 0 |
| 18698 | end |
| 18699 | |
| 18700 | note OP8: select a live Simple Network Protocol interface once (result 0), or an EFI status. |
| 18701 | fn xenet to void |
| 18702 | xp 1 1 24 |
| 18703 | xrr 133 1 1 |
| 18704 | al = xbranch 1 |
| 18705 | g = xg 1 |
| 18706 | ximm 1 2 |
| 18707 | xaddr 2 g |
| 18708 | ximm 8 0 |
| 18709 | xp 0 9 104 |
| 18710 | xp 0 0 112 |
| 18711 | xmem 137 0 4 32 |
| 18712 | xp 3 0 312 |
| 18713 | xrr 133 0 0 |
| 18714 | lerr = xbranch 1 |
| 18715 | xp 1 6 112 |
| 18716 | xp 1 7 104 |
| 18717 | ximm 0 1024 |
| 18718 | xrr 57 7 0 |
| 18719 | lg = xbranch 8 |
| 18720 | xenscan g |
| 18721 | sv = xbranch 14 |
| 18722 | xpatch lg get oc 0 |
| 18723 | ximm 0 9223372036854775813 |
| 18724 | xpatch sv get oc 0 |
| 18725 | xp 2 0 152 |
| 18726 | xrr 137 1 6 |
| 18727 | xp 3 0 72 |
| 18728 | xrr 133 0 0 |
| 18729 | fe = xbranch 1 |
| 18730 | xp 1 0 152 |
| 18731 | dn = xbranch 14 |
| 18732 | xpatch al get oc 0 |
| 18733 | ximm 0 0 |
| 18734 | xpatch dn get oc 0 |
| 18735 | xpatch lerr get oc 0 |
| 18736 | xpatch fe get oc 0 |
| 18737 | put xenerr 0 0 |
| 18738 | put xenend 0 0 |
| 18739 | end |
| 18740 | |
| 18741 | note Volumes (UEFI 13.4 Simple File System, 9.1 LoadedImage). k 0: copy the handles (at most 64) to |
| 18742 | note private 1024 and free the firmware buffer (clobbers RSI/RDI/RCX); 1: result count | boot index<<8 |
| 18743 | note (255 none) and finish; 2: open the root of volume RDI into slot root (19 index, 21, 22); |
| 18744 | note 3: open the root of the volume this image was loaded from into slot root (18, 21, 22). |
| 18745 | fn xvol k ulong root ulong to void |
| 18746 | if eq k 0 |
| 18747 | g = xg 5 |
| 18748 | ximm 1 2 |
| 18749 | xaddr 2 g |
| 18750 | ximm 8 0 |
| 18751 | xp 0 9 512 |
| 18752 | xp 0 0 520 |
| 18753 | xmem 137 0 4 32 |
| 18754 | xp 3 0 312 |
| 18755 | xrr 133 0 0 |
| 18756 | xer 0 1 16 |
| 18757 | xp 1 1 512 |
| 18758 | ximm 0 64 |
| 18759 | xrr 57 1 0 |
| 18760 | p = xbranch 3 |
| 18761 | ximm 1 64 |
| 18762 | xpatch p get oc 0 |
| 18763 | xp 2 1 512 |
| 18764 | xp 1 6 520 |
| 18765 | xp 0 7 1024 |
| 18766 | emitb 252 |
| 18767 | emitb 243 |
| 18768 | emitb 72 |
| 18769 | emitb 165 |
| 18770 | xp 1 1 520 |
| 18771 | xp 3 0 72 |
| 18772 | xrr 133 0 0 |
| 18773 | xer 0 1 17 |
| 18774 | ret |
| 18775 | end |
| 18776 | if eq k 1 |
| 18777 | gl = xg 6 |
| 18778 | xp 1 1 8 |
| 18779 | xaddr 2 gl |
| 18780 | xp 0 8 528 |
| 18781 | xp 3 0 152 |
| 18782 | xrr 133 0 0 |
| 18783 | xer 0 1 18 |
| 18784 | xp 1 0 528 |
| 18785 | xmem 139 0 0 24 |
| 18786 | xp 1 6 512 |
| 18787 | xp 0 7 1024 |
| 18788 | ximm 2 0 |
| 18789 | lp = get oc 0 |
| 18790 | xrr 57 2 6 |
| 18791 | nm = xbranch 2 |
| 18792 | xmem 139 1 7 0 |
| 18793 | xrr 57 1 0 |
| 18794 | fd = xbranch 0 |
| 18795 | xb 72 131 199 |
| 18796 | emitb 8 |
| 18797 | xb 72 255 194 |
| 18798 | back lp |
| 18799 | xpatch nm get oc 0 |
| 18800 | ximm 2 255 |
| 18801 | xpatch fd get oc 0 |
| 18802 | xrr 137 0 6 |
| 18803 | xb 72 193 226 |
| 18804 | emitb 8 |
| 18805 | xrr 9 0 2 |
| 18806 | xer 1 0 0 |
| 18807 | ret |
| 18808 | end |
| 18809 | gs = xg 5 |
| 18810 | if eq k 3 |
| 18811 | gi = xg 6 |
| 18812 | xp 1 1 8 |
| 18813 | xaddr 2 gi |
| 18814 | xp 0 8 528 |
| 18815 | xp 3 0 152 |
| 18816 | xrr 133 0 0 |
| 18817 | xer 0 1 18 |
| 18818 | xp 1 1 528 |
| 18819 | xmem 139 1 1 24 |
| 18820 | else |
| 18821 | xp 1 0 512 |
| 18822 | xrr 57 7 0 |
| 18823 | xer 0 2 19 |
| 18824 | xp 0 1 1024 |
| 18825 | xrr 137 0 7 |
| 18826 | xb 72 193 224 |
| 18827 | emitb 3 |
| 18828 | xrr 1 1 0 |
| 18829 | xmem 139 1 1 0 |
| 18830 | end |
| 18831 | xaddr 2 gs |
| 18832 | xp 0 8 536 |
| 18833 | xp 3 0 152 |
| 18834 | xrr 133 0 0 |
| 18835 | xer 0 1 21 |
| 18836 | xp 0 2 root |
| 18837 | xp 4 536 8 |
| 18838 | xrr 133 0 0 |
| 18839 | xer 0 1 22 |
| 18840 | end |
| 18841 | |
| 18842 | note File I/O (UEFI 13.5). k 0: Open(root, path, mode) into slot file; the path is the fixed |
| 18843 | note \EFI\BOOT\BOOTX64.EFI for root 544 (efi 11), else the UCS-2 copy at private 3584 (efi 12). |
| 18844 | note k 1: efi 11 Read/Write (method mode) of N bytes at R12 via size slot 560. Failure: RDI = code, |
| 18845 | note jump to cleanup. |
| 18846 | fn xfio k ulong root ulong file ulong mode ulong code ulong cleanup ulong to void |
| 18847 | if eq k 0 |
| 18848 | if eq root 544 |
| 18849 | p = xg 8 |
| 18850 | xaddr 8 p |
| 18851 | else |
| 18852 | xp 0 8 3584 |
| 18853 | end |
| 18854 | xp 0 2 file |
| 18855 | ximm 9 mode |
| 18856 | ximm 0 0 |
| 18857 | xmem 137 0 4 32 |
| 18858 | xp 4 root 8 |
| 18859 | else |
| 18860 | xp 2 13 560 |
| 18861 | xp 0 2 560 |
| 18862 | xrr 137 8 12 |
| 18863 | xp 4 552 mode |
| 18864 | end |
| 18865 | xrr 133 0 0 |
| 18866 | ximm 7 code |
| 18867 | bad = xbranch 1 |
| 18868 | xpatch bad cleanup |
| 18869 | end |
| 18870 | |
| 18871 | note OP11 (Allen fork contract): ARG sub bits0..7, volume bits8..15. Sub 0 counts the volumes and |
| 18872 | note finds the boot one (count | index<<8); sub 1 reads \EFI\BOOT\BOOTX64.EFI of volume k into A |
| 18873 | note (result bytes); sub 2 writes A's N bytes as that file (deleted first; result bytes). File and |
| 18874 | note root handles are closed on every path. |
| 18875 | fn xefile to void |
| 18876 | xrr 137 0 3 |
| 18877 | ximm 2 255 |
| 18878 | xrr 33 0 2 |
| 18879 | ximm 2 2 |
| 18880 | xrr 57 0 2 |
| 18881 | xer 0 8 15 |
| 18882 | ximm 0 0 |
| 18883 | xp 2 0 544 |
| 18884 | xp 2 0 552 |
| 18885 | skip = xbranch 14 |
| 18886 | cleanup = get oc 0 |
| 18887 | xp 1 1 552 |
| 18888 | xrr 133 1 1 |
| 18889 | p = xbranch 0 |
| 18890 | xp 4 552 16 |
| 18891 | xpatch p get oc 0 |
| 18892 | xp 1 1 544 |
| 18893 | xrr 133 1 1 |
| 18894 | p = xbranch 0 |
| 18895 | xp 4 544 16 |
| 18896 | xpatch p get oc 0 |
| 18897 | xrr 133 7 7 |
| 18898 | p = xbranch 0 |
| 18899 | ximm 0 9223372036854775808 |
| 18900 | xrr 9 0 7 |
| 18901 | xer 1 0 0 |
| 18902 | xpatch p get oc 0 |
| 18903 | xp 1 0 568 |
| 18904 | xer 1 0 0 |
| 18905 | xpatch skip get oc 0 |
| 18906 | xvol 0 0 |
| 18907 | xrr 137 6 3 |
| 18908 | ximm 2 255 |
| 18909 | xrr 33 6 2 |
| 18910 | xrr 137 7 3 |
| 18911 | xb 72 193 239 |
| 18912 | emitb 8 |
| 18913 | xrr 33 7 2 |
| 18914 | xrr 133 6 6 |
| 18915 | p = xbranch 1 |
| 18916 | xvol 1 0 |
| 18917 | xpatch p get oc 0 |
| 18918 | xp 1 0 512 |
| 18919 | xrr 57 7 0 |
| 18920 | xer 0 2 19 |
| 18921 | xe 3 1 0 |
| 18922 | xvol 2 544 |
| 18923 | ximm 0 1 |
| 18924 | xrr 57 6 0 |
| 18925 | wr = xbranch 1 |
| 18926 | xfio 0 544 552 1 23 cleanup |
| 18927 | xfio 1 0 0 32 25 cleanup |
| 18928 | xp 1 0 560 |
| 18929 | xp 2 0 568 |
| 18930 | ximm 0 1 |
| 18931 | xp 2 0 560 |
| 18932 | xp 0 2 560 |
| 18933 | xp 0 8 576 |
| 18934 | xp 4 552 32 |
| 18935 | xrr 133 0 0 |
| 18936 | ximm 7 25 |
| 18937 | p = xbranch 1 |
| 18938 | xpatch p cleanup |
| 18939 | xp 1 0 560 |
| 18940 | xrr 133 0 0 |
| 18941 | ximm 7 24 |
| 18942 | p = xbranch 1 |
| 18943 | xpatch p cleanup |
| 18944 | ximm 7 0 |
| 18945 | p = xbranch 14 |
| 18946 | xpatch p cleanup |
| 18947 | xpatch wr get oc 0 |
| 18948 | xfio 0 544 552 3 26 cleanup |
| 18949 | xp 4 552 24 |
| 18950 | ximm 2 0 |
| 18951 | xp 2 2 552 |
| 18952 | xrr 133 0 0 |
| 18953 | ximm 7 27 |
| 18954 | p = xbranch 1 |
| 18955 | xpatch p cleanup |
| 18956 | xfio 0 544 552 9223372036854775811 28 cleanup |
| 18957 | xfio 1 0 0 40 29 cleanup |
| 18958 | xp 1 0 560 |
| 18959 | xrr 57 0 13 |
| 18960 | ximm 7 30 |
| 18961 | p = xbranch 1 |
| 18962 | xpatch p cleanup |
| 18963 | xp 4 552 80 |
| 18964 | xrr 133 0 0 |
| 18965 | ximm 7 31 |
| 18966 | p = xbranch 1 |
| 18967 | xpatch p cleanup |
| 18968 | xp 1 0 560 |
| 18969 | xp 2 0 568 |
| 18970 | ximm 7 0 |
| 18971 | p = xbranch 14 |
| 18972 | xpatch p cleanup |
| 18973 | end |
| 18974 | |
| 18975 | note OP12 general file (new): ARG sub bits0..7, volume bits8..15 (255 = the volume this image was |
| 18976 | note loaded from), position bits16..63. Open subs take the path A[OFF..OFF+N): 1..255 bytes, first |
| 18977 | note '\', each 32..126. Sub 0 open read-only, 5 open an existing file read/write (no truncate), both |
| 18978 | note result FileSize; 1 create empty, replacing any file (result 0). Sub 2 reads up to N bytes at |
| 18979 | note the position into A (result bytes read, 0 at end), 3 writes N bytes there (result N; needs sub |
| 18980 | note 1 or 5), 4 flushes and closes (result 0). One file at a time: its handle stays in private 2304 |
| 18981 | note and its volume root in 2312 between operations. Errors: 32 sub, 33 path, 34 busy, 35 nothing |
| 18982 | note open, 36 open/create/delete, 37 read, 38 write (or not writable), 39 short write, 40 flush, |
| 18983 | note 41 GetInfo; volume errors 16..22 as efi 11. Refusals 32..35 and 38 not-writable leave the slot |
| 18984 | note as it was (the caller still owns an open file); so do the firmware errors 37, 38 and 39 of subs |
| 18985 | note 2 and 3. Volume errors leave the slot empty. 36 and 41 close the file and root, slot empty; |
| 18986 | note sub 4 with a file open closes both and empties the slot on every path, returning 40 when Flush |
| 18987 | note failed. A file still open at exit is flushed and closed by the shared exit (xefx 1). |
| 18988 | fn xf12 to void |
| 18989 | skip = xbranch 14 |
| 18990 | cleanup = get oc 0 |
| 18991 | xp 1 1 2304 |
| 18992 | xrr 133 1 1 |
| 18993 | p = xbranch 0 |
| 18994 | xp 4 2304 16 |
| 18995 | xpatch p get oc 0 |
| 18996 | xp 1 1 2312 |
| 18997 | xrr 133 1 1 |
| 18998 | p = xbranch 0 |
| 18999 | xp 4 2312 16 |
| 19000 | xpatch p get oc 0 |
| 19001 | ximm 0 0 |
| 19002 | xp 2 0 2304 |
| 19003 | xp 2 0 2312 |
| 19004 | xp 2 0 2320 |
| 19005 | xrr 133 7 7 |
| 19006 | p = xbranch 0 |
| 19007 | ximm 0 9223372036854775808 |
| 19008 | xrr 9 0 7 |
| 19009 | xer 1 0 0 |
| 19010 | xpatch p get oc 0 |
| 19011 | xer 1 0 0 |
| 19012 | xpatch skip get oc 0 |
| 19013 | xrr 137 6 3 |
| 19014 | ximm 0 255 |
| 19015 | xrr 33 6 0 |
| 19016 | ximm 0 5 |
| 19017 | xrr 57 6 0 |
| 19018 | xer 0 8 32 |
| 19019 | ximm 0 2 |
| 19020 | xrr 57 6 0 |
| 19021 | opn = xbranch 3 |
| 19022 | ximm 0 5 |
| 19023 | xrr 57 6 0 |
| 19024 | op5 = xbranch 0 |
| 19025 | xp 1 1 2304 |
| 19026 | xrr 133 1 1 |
| 19027 | xer 0 0 35 |
| 19028 | ximm 0 4 |
| 19029 | xrr 57 6 0 |
| 19030 | p = xbranch 1 |
| 19031 | ximm 7 0 |
| 19032 | xp 1 0 2320 |
| 19033 | xrr 133 0 0 |
| 19034 | q = xbranch 0 |
| 19035 | xp 4 2304 80 |
| 19036 | xrr 133 0 0 |
| 19037 | rw = xbranch 0 |
| 19038 | ximm 7 40 |
| 19039 | xpatch rw get oc 0 |
| 19040 | xpatch q get oc 0 |
| 19041 | ximm 0 0 |
| 19042 | rw = xbranch 14 |
| 19043 | xpatch rw cleanup |
| 19044 | xpatch p get oc 0 |
| 19045 | xrr 137 2 3 |
| 19046 | xb 72 193 234 |
| 19047 | emitb 16 |
| 19048 | ximm 0 3 |
| 19049 | xrr 57 6 0 |
| 19050 | p = xbranch 0 |
| 19051 | xp 4 2304 56 |
| 19052 | xrr 133 0 0 |
| 19053 | xer 0 1 37 |
| 19054 | xp 2 13 2336 |
| 19055 | xp 0 2 2336 |
| 19056 | xrr 137 8 12 |
| 19057 | xp 4 2304 32 |
| 19058 | xrr 133 0 0 |
| 19059 | xer 0 1 37 |
| 19060 | xp 1 0 2336 |
| 19061 | xer 1 0 0 |
| 19062 | xpatch p get oc 0 |
| 19063 | xp 1 0 2320 |
| 19064 | xrr 133 0 0 |
| 19065 | xer 0 0 38 |
| 19066 | xp 4 2304 56 |
| 19067 | xrr 133 0 0 |
| 19068 | xer 0 1 38 |
| 19069 | xp 2 13 2336 |
| 19070 | xp 0 2 2336 |
| 19071 | xrr 137 8 12 |
| 19072 | xp 4 2304 40 |
| 19073 | xrr 133 0 0 |
| 19074 | xer 0 1 38 |
| 19075 | xp 1 0 2336 |
| 19076 | xrr 57 0 13 |
| 19077 | xer 0 1 39 |
| 19078 | xrr 137 0 13 |
| 19079 | xer 1 0 0 |
| 19080 | xpatch opn get oc 0 |
| 19081 | xpatch op5 get oc 0 |
| 19082 | xp 1 1 2304 |
| 19083 | xrr 133 1 1 |
| 19084 | xer 0 1 34 |
| 19085 | xrr 133 13 13 |
| 19086 | xer 0 0 33 |
| 19087 | ximm 0 255 |
| 19088 | xrr 57 13 0 |
| 19089 | xer 0 8 33 |
| 19090 | xhraw 0 12 0 1 |
| 19091 | ximm 2 92 |
| 19092 | xrr 57 0 2 |
| 19093 | xer 0 1 33 |
| 19094 | xrr 137 8 12 |
| 19095 | xrr 137 9 13 |
| 19096 | xp 0 10 3584 |
| 19097 | lp = get oc 0 |
| 19098 | xrr 133 9 9 |
| 19099 | p = xbranch 0 |
| 19100 | xhraw 0 8 0 1 |
| 19101 | ximm 2 32 |
| 19102 | xrr 57 0 2 |
| 19103 | xer 0 3 33 |
| 19104 | ximm 2 126 |
| 19105 | xrr 57 0 2 |
| 19106 | xer 0 8 33 |
| 19107 | xhput 0 10 0 2 |
| 19108 | xb 73 131 192 |
| 19109 | emitb 1 |
| 19110 | xb 73 131 194 |
| 19111 | emitb 2 |
| 19112 | xb 73 131 233 |
| 19113 | emitb 1 |
| 19114 | back lp |
| 19115 | xpatch p get oc 0 |
| 19116 | ximm 0 0 |
| 19117 | xhput 0 10 0 2 |
| 19118 | xrr 137 0 3 |
| 19119 | ximm 2 65280 |
| 19120 | xrr 33 0 2 |
| 19121 | xrr 57 0 2 |
| 19122 | p = xbranch 0 |
| 19123 | xvol 0 0 |
| 19124 | xrr 137 7 3 |
| 19125 | xb 72 193 239 |
| 19126 | emitb 8 |
| 19127 | ximm 2 255 |
| 19128 | xrr 33 7 2 |
| 19129 | xvol 2 2312 |
| 19130 | q = xbranch 14 |
| 19131 | xpatch p get oc 0 |
| 19132 | xvol 3 2312 |
| 19133 | xpatch q get oc 0 |
| 19134 | xrr 137 6 3 |
| 19135 | ximm 0 255 |
| 19136 | xrr 33 6 0 |
| 19137 | ximm 0 1 |
| 19138 | xrr 57 6 0 |
| 19139 | p = xbranch 1 |
| 19140 | note Sub 1: delete an existing file first (UEFI 13.5 Delete closes the handle), then create. |
| 19141 | xp 0 8 3584 |
| 19142 | xp 0 2 2304 |
| 19143 | ximm 9 3 |
| 19144 | ximm 0 0 |
| 19145 | xmem 137 0 4 32 |
| 19146 | xp 4 2312 8 |
| 19147 | xrr 133 0 0 |
| 19148 | q = xbranch 1 |
| 19149 | xp 4 2304 24 |
| 19150 | ximm 2 0 |
| 19151 | xp 2 2 2304 |
| 19152 | xrr 133 0 0 |
| 19153 | ximm 7 36 |
| 19154 | rw = xbranch 1 |
| 19155 | xpatch rw cleanup |
| 19156 | xpatch q get oc 0 |
| 19157 | ximm 2 0 |
| 19158 | xp 2 2 2304 |
| 19159 | xfio 0 2312 2304 9223372036854775811 36 cleanup |
| 19160 | ximm 0 1 |
| 19161 | xp 2 0 2320 |
| 19162 | ximm 0 0 |
| 19163 | xer 1 0 0 |
| 19164 | xpatch p get oc 0 |
| 19165 | ximm 0 5 |
| 19166 | xrr 57 6 0 |
| 19167 | p = xbranch 0 |
| 19168 | xfio 0 2312 2304 1 36 cleanup |
| 19169 | ximm 0 0 |
| 19170 | xp 2 0 2320 |
| 19171 | q = xbranch 14 |
| 19172 | xpatch p get oc 0 |
| 19173 | xfio 0 2312 2304 3 36 cleanup |
| 19174 | ximm 0 1 |
| 19175 | xp 2 0 2320 |
| 19176 | xpatch q get oc 0 |
| 19177 | ximm 0 1024 |
| 19178 | xp 2 0 2336 |
| 19179 | gi = xg 7 |
| 19180 | xaddr 2 gi |
| 19181 | xp 0 8 2336 |
| 19182 | xp 0 9 2560 |
| 19183 | xp 4 2304 64 |
| 19184 | xrr 133 0 0 |
| 19185 | ximm 7 41 |
| 19186 | p = xbranch 1 |
| 19187 | xpatch p cleanup |
| 19188 | xp 1 0 2568 |
| 19189 | xp 2 0 2328 |
| 19190 | end |
| 19191 | |
| 19192 |