omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / qualification / security673 / relational / evidence / gate1 / 26.src
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/qualification/om2/leak/leakscan.om: static leakage scan of one omc FUNCTION-MODE artifact |
| 3 | note (raw little-endian AArch64 words, entry word 0), contract spec/omegese-om2.md section 8, evidence (a) |
| 4 | note (#748, ledger L836). Handwritten seeded Omega, OM-1, program mode, built by the pinned omc 734f0a39. |
| 5 | note README.txt in this directory states the decode subset, the taint rules, the call rule and what is |
| 6 | note MANUAL. The scan is a may-analysis: "data" means "may depend on data", never "proved to leak". |
| 7 | note |
| 8 | note Usage: leakscan [xN | pub:SLOT:OFF:LEN ...] < artifact. xN marks DATA (N 0..5). |
| 9 | note pub declares public memory relative to entry xSLOT, fully contained in the half-open byte range. |
| 10 | note Output, in this order: one LEAKSCAN line; per word, in word order, UNKNOWN, UNHANDLED, BRANCH and MEM |
| 11 | note lines; one SUMMARY line; MANUAL-ITEMS when needed; one VERDICT line. |
| 12 | note Exit status: 0 PASS, 1 FAIL (data address), 2 NOT_RUN (MANUAL), 90 usage, 91 invalid artifact. |
| 13 | note |
| 14 | note Taint state per word (the state on entry to the word): rm bit b is 1 when the value may be DATA; |
| 15 | note bits 0..30 x0..x30, bit 31 the NZCV flags, bits 32..63 v0..v31. sm bit j is 1 when the 8 bytes |
| 16 | note at [SP + 8j] (current SP) may hold DATA. dep is the bytes the SP is below the function's entry SP, |
| 17 | note plus 1 (0: never reached). fid is the function's entry word. |
| 18 | global inb uchar 8388612 |
| 19 | global wd uint 2097152 |
| 20 | global rm ulong 2097152 |
| 21 | global sm ulong 2097152 |
| 22 | global dep ulong 2097152 |
| 23 | global fid ulong 2097152 |
| 24 | global ex ulong 2097152 |
| 25 | global exs uchar 2097152 |
| 26 | global blt ulong 2097152 |
| 27 | global trp uchar 2097152 |
| 28 | global uh uchar 2097152 |
| 29 | global inq uchar 2097152 |
| 30 | global wl ulong 2097152 |
| 31 | global dc ulong 24 |
| 32 | global cu ulong 4 |
| 33 | global gv ulong 32 |
| 34 | global ob uchar 1048576 |
| 35 | global obn ulong 1 |
| 36 | global dig uchar 32 |
| 37 | global tbo ulong 128 |
| 38 | global tbl ulong 128 |
| 39 | global ab uchar 16 |
| 40 | global pab uchar 128 |
| 41 | note Exact provenance and E12 known-zero bits, allocated for reached words. |
| 42 | note Tokens: tag:8 | signed-offset:56; tag 1 constant, tags 2..7 entry x0..x5 + offset, 0 unknown. |
| 43 | note ps/pe point into pp (128 cells: 31 regs, AND-proof mask, 64 spill slots, 32 known-zero masks). |
| 44 | note At most 131072 records; exhaustion is UNHANDLED provenance-cap and forces NOT_RUN. |
| 45 | global pp ulong 16777216 |
| 46 | global ps ulong 2097152 |
| 47 | global pe ulong 2097152 |
| 48 | global pc ulong 128 |
| 49 | global pdecl ulong 96 |
| 50 | note E13 whole-artifact revocation: rv[word] lists the public-range bits revoked by that store. |
| 51 | global rv ulong 2097152 |
| 52 | text revmsg "PUBLIC-MEM-REVOKED @" |
| 53 | text pmsg "PUBLIC-DECL \nPUBLIC-MEM @\n public-mem \n+\n:\nprovenance-cap\nusage: leakscan [x0..x5 | pub:SLOT:OFF:LEN ...] < function-mode artifact\n" |
| 54 | text e12 "data MANUAL\nVERDICT TRACE-EQUIV-STATIC NOT_RUN\n" |
| 55 | note decoded fields, indices into dc |
| 56 | const dkind ulong 0 |
| 57 | const dtgt ulong 1 |
| 58 | const ddst ulong 2 |
| 59 | const ds1 ulong 3 |
| 60 | const ds2 ulong 4 |
| 61 | const ds3 ulong 5 |
| 62 | const dfl ulong 6 |
| 63 | const dmk ulong 7 |
| 64 | const dmb ulong 8 |
| 65 | const dmi ulong 9 |
| 66 | const dmo ulong 10 |
| 67 | const dms ulong 11 |
| 68 | const dmt ulong 12 |
| 69 | const dmt2 ulong 13 |
| 70 | const dwb ulong 14 |
| 71 | const dmn ulong 15 |
| 72 | const dcc ulong 16 |
| 73 | const dspo ulong 17 |
| 74 | const dspa ulong 18 |
| 75 | const dmf ulong 19 |
| 76 | note gv: 0 words, 1 worklist size, 2 entry word, 3 DATA parameter bits, 4 len branches, 5 trap checks, |
| 77 | note 6 data branches, 7 unreached branches, 8 const, 9 public-index, 10 data-index, 11 unreached memory, |
| 78 | note 12 unknown, 13 unhandled, 14 branches, 15 memory accesses, 16 word 0 is the entry branch |
| 79 | text tb "b\nbl\ncbz\ncbnz\ntbz\ntbnz\nret\nbr\nblr\nsvc\nldrb\nldrsb\nldrh\nldrsh\nldr\nldrsw\nstrb\nstrh\nstr\nldp\nstp\nldpsw\n?\nnop\ndsb\nb.eq\nb.ne\nb.cs\nb.cc\nb.mi\nb.pl\nb.vs\nb.vc\nb.hi\nb.ls\nb.ge\nb.lt\nb.gt\nb.le\nb.al\nb.nv\nLEAKSCAN 1 words=\n entry=@\n data=\nnone\nUNKNOWN @\nUNHANDLED @\nBRANCH @\nMEM @\n ->@\nlen\ndata never-taken-trap-check\ndata DATA-BRANCH\nunreached\nconst\npublic-index\ndata-index\n trap=\n base=\n index=\nsp\n-\n trap-tail\nSUMMARY branches=\n len=\n trap-check=\n data-branch=\n branch-unreached=\n mem=\n const=\n public-index=\n data-index=\n mem-unreached=\n unknown=\n unhandled=\nVERDICT TRACE-EQUIV-STATIC PASS\nVERDICT TRACE-EQUIV-STATIC FAIL\nVERDICT TRACE-EQUIV-STATIC MANUAL\n 0x\nusage: leakscan [x0..x5 ...] < function-mode artifact\nleakscan: input is not a function-mode artifact: empty, not whole words, ELF, or over 8 MiB\nimm\nreg\nunscaled\npost\npre\npair\nliteral\nunpriv\n?\nsp-write\nsp-writeback\nstack-escape\ndepth-mismatch\nshared-code\nret-depth\nret-x30-data\nbr-indirect\nblr-indirect\nsvc-syscall\nflow-out\nsp-underflow\nx7-write\nbelow-sp\n \nMANUAL-ITEMS \n listed above as UNKNOWN and UNHANDLED lines\n always\nx\n,\n" |
| 80 | |
| 81 | note ---- output ---------------------------------------------------------------------------------- |
| 82 | fn inittb to void |
| 83 | k = ulong 0 |
| 84 | s = ulong 0 |
| 85 | for i ulong len tb |
| 86 | if eq get tb i 10 |
| 87 | put tbo k s |
| 88 | put tbl k sub i s |
| 89 | k = add k 1 |
| 90 | s = add i 1 |
| 91 | end |
| 92 | end |
| 93 | end |
| 94 | fn obf to void |
| 95 | n = get obn 0 |
| 96 | o = ulong 0 |
| 97 | while lt o n |
| 98 | r = write 1 ob o sub n o |
| 99 | if le r 0 |
| 100 | exit 93 |
| 101 | end |
| 102 | o = add o ulong r |
| 103 | end |
| 104 | put obn 0 0 |
| 105 | end |
| 106 | fn ob1 b uchar to void |
| 107 | n = get obn 0 |
| 108 | if ge n 1048000 |
| 109 | obf |
| 110 | n = ulong 0 |
| 111 | end |
| 112 | put ob n b |
| 113 | put obn 0 add n 1 |
| 114 | end |
| 115 | fn say id ulong to void |
| 116 | o = get tbo id |
| 117 | for i ulong get tbl id |
| 118 | ob1 get tb add o i |
| 119 | end |
| 120 | end |
| 121 | fn onl to void |
| 122 | ob1 10 |
| 123 | end |
| 124 | fn od v ulong to void |
| 125 | x = v |
| 126 | n = ulong 0 |
| 127 | while ge x 10 |
| 128 | put dig n uchar add 48 rem x 10 |
| 129 | x = div x 10 |
| 130 | n = add n 1 |
| 131 | end |
| 132 | put dig n uchar add 48 x |
| 133 | n = add n 1 |
| 134 | for i ulong n |
| 135 | ob1 get dig sub sub n i 1 |
| 136 | end |
| 137 | end |
| 138 | fn hexd v ulong to uchar |
| 139 | if lt v 10 |
| 140 | ret uchar add v 48 |
| 141 | end |
| 142 | ret uchar add v 87 |
| 143 | end |
| 144 | fn oh v ulong to void |
| 145 | for i ulong 8 |
| 146 | ob1 hexd and shr v mul sub 7 i 4 15 |
| 147 | end |
| 148 | end |
| 149 | note a register field: 255 "-", 31 "sp" (a base), else xN |
| 150 | fn oreg r ulong to void |
| 151 | if eq r 255 |
| 152 | say 61 |
| 153 | ret |
| 154 | end |
| 155 | if eq r 31 |
| 156 | say 60 |
| 157 | ret |
| 158 | end |
| 159 | say 108 |
| 160 | od r |
| 161 | end |
| 162 | fn inc k ulong to void |
| 163 | put gv k add get gv k 1 |
| 164 | end |
| 165 | |
| 166 | note ---- bit helpers ----------------------------------------------------------------------------- |
| 167 | fn fld x ulong lo ulong n ulong to ulong |
| 168 | ret and shr x lo sub shl ulong 1 n 1 |
| 169 | end |
| 170 | note a general register field where 31 is the zero register (public, no state bit) |
| 171 | fn gz r ulong to ulong |
| 172 | if eq r 31 |
| 173 | ret 255 |
| 174 | end |
| 175 | ret r |
| 176 | end |
| 177 | note sign extension of an n-bit field to 64 bits (two's complement in a ulong) |
| 178 | fn sx v ulong n ulong to ulong |
| 179 | if eq and shr v sub n 1 1 0 |
| 180 | ret v |
| 181 | end |
| 182 | ret or v not sub shl ulong 1 n 1 |
| 183 | end |
| 184 | fn tnt r ulong b ulong to ulong |
| 185 | if ge b 64 |
| 186 | ret 0 |
| 187 | end |
| 188 | ret and shr r b 1 |
| 189 | end |
| 190 | fn sbit r ulong b ulong v ulong to ulong |
| 191 | if ge b 64 |
| 192 | ret r |
| 193 | end |
| 194 | m = shl ulong 1 b |
| 195 | if eq v 0 |
| 196 | ret and r not m |
| 197 | end |
| 198 | ret or r m |
| 199 | end |
| 200 | |
| 201 | note ---- decoder: the classes omc emits (README.txt lists them with their omc.om sources) --------- |
| 202 | fn dclr to void |
| 203 | for i ulong 24 |
| 204 | put dc i 255 |
| 205 | end |
| 206 | put dc dkind 0 |
| 207 | put dc dfl 0 |
| 208 | put dc dmk 0 |
| 209 | put dc dwb 0 |
| 210 | put dc dmn 22 |
| 211 | put dc dspo 0 |
| 212 | put dc dspa 0 |
| 213 | put dc dmf 0 |
| 214 | put dc dtgt 0 |
| 215 | put dc dmo 0 |
| 216 | put dc dms 0 |
| 217 | end |
| 218 | note kinds: 0 straight-line, 1 B, 2 BL, 3 B.cond, 4 CBZ/CBNZ, 5 TBZ/TBNZ, 6 RET, 7 BR, 8 BLR, 9 SVC, |
| 219 | note 10 unknown, 11 no effect (NOP, DSB) |
| 220 | fn dbr x ulong w ulong to bool |
| 221 | m = and x 4227858432 |
| 222 | if eq m 335544320 |
| 223 | put dc dkind 1 |
| 224 | put dc dtgt add w sx and x 67108863 26 |
| 225 | put dc dmn 0 |
| 226 | ret true |
| 227 | end |
| 228 | if eq m 2483027968 |
| 229 | put dc dkind 2 |
| 230 | put dc dtgt add w sx and x 67108863 26 |
| 231 | put dc dmn 1 |
| 232 | ret true |
| 233 | end |
| 234 | if eq and x 4278190096 1409286144 |
| 235 | put dc dkind 3 |
| 236 | put dc dtgt add w sx fld x 5 19 19 |
| 237 | put dc dcc and x 15 |
| 238 | put dc dmn add 25 and x 15 |
| 239 | ret true |
| 240 | end |
| 241 | m = and x 2113929216 |
| 242 | if eq m 872415232 |
| 243 | put dc dkind 4 |
| 244 | put dc dtgt add w sx fld x 5 19 19 |
| 245 | put dc ds1 gz and x 31 |
| 246 | put dc dmn add 2 fld x 24 1 |
| 247 | ret true |
| 248 | end |
| 249 | if eq m 905969664 |
| 250 | put dc dkind 5 |
| 251 | put dc dtgt add w sx fld x 5 14 14 |
| 252 | put dc ds1 gz and x 31 |
| 253 | put dc dcc or shl fld x 31 1 5 fld x 19 5 |
| 254 | put dc dmn add 4 fld x 24 1 |
| 255 | ret true |
| 256 | end |
| 257 | m = and x 4294966303 |
| 258 | if eq m 3592355840 |
| 259 | put dc dkind 7 |
| 260 | put dc ds1 fld x 5 5 |
| 261 | put dc dmn 7 |
| 262 | ret true |
| 263 | end |
| 264 | if eq m 3594452992 |
| 265 | put dc dkind 8 |
| 266 | put dc ds1 fld x 5 5 |
| 267 | put dc dmn 8 |
| 268 | ret true |
| 269 | end |
| 270 | if eq m 3596550144 |
| 271 | put dc dkind 6 |
| 272 | put dc ds1 fld x 5 5 |
| 273 | put dc dmn 6 |
| 274 | ret true |
| 275 | end |
| 276 | if eq and x 4292870175 3556769793 |
| 277 | put dc dkind 9 |
| 278 | put dc dmn 9 |
| 279 | ret true |
| 280 | end |
| 281 | if eq x 3573751839 |
| 282 | put dc dkind 11 |
| 283 | put dc dmn 23 |
| 284 | ret true |
| 285 | end |
| 286 | if eq and x 4294963455 3573756063 |
| 287 | put dc dkind 11 |
| 288 | put dc dmn 24 |
| 289 | ret true |
| 290 | end |
| 291 | ret false |
| 292 | end |
| 293 | |
| 294 | note ADD/SUB (immediate): Rn 31 is SP; Rd 31 is SP unless flags are set (then the zero register) |
| 295 | fn daddi x ulong to void |
| 296 | rd = and x 31 |
| 297 | rn = fld x 5 5 |
| 298 | if eq fld x 29 1 1 |
| 299 | put dc ddst gz rd |
| 300 | put dc ds1 gz rn |
| 301 | put dc dfl 2 |
| 302 | ret |
| 303 | end |
| 304 | if eq rd 31 |
| 305 | if eq rn 31 |
| 306 | put dc dspo add 1 fld x 30 1 |
| 307 | put dc dspa shl fld x 10 12 mul fld x 22 1 12 |
| 308 | ret |
| 309 | end |
| 310 | put dc dspo 3 |
| 311 | ret |
| 312 | end |
| 313 | put dc ddst rd |
| 314 | put dc ds1 gz rn |
| 315 | end |
| 316 | fn dlogi x ulong to void |
| 317 | rd = and x 31 |
| 318 | if eq fld x 29 2 3 |
| 319 | put dc dfl 2 |
| 320 | put dc ddst gz rd |
| 321 | else |
| 322 | if eq rd 31 |
| 323 | put dc dspo 3 |
| 324 | ret |
| 325 | end |
| 326 | put dc ddst rd |
| 327 | end |
| 328 | put dc ds1 gz fld x 5 5 |
| 329 | end |
| 330 | fn dmovw x ulong to bool |
| 331 | opc = fld x 29 2 |
| 332 | if eq opc 1 |
| 333 | ret false |
| 334 | end |
| 335 | put dc ddst gz and x 31 |
| 336 | if eq opc 3 |
| 337 | put dc dfl 4 |
| 338 | end |
| 339 | ret true |
| 340 | end |
| 341 | fn dbfm x ulong to bool |
| 342 | opc = fld x 29 2 |
| 343 | if eq opc 3 |
| 344 | ret false |
| 345 | end |
| 346 | put dc ddst gz and x 31 |
| 347 | put dc ds1 gz fld x 5 5 |
| 348 | if eq opc 1 |
| 349 | put dc dfl 4 |
| 350 | end |
| 351 | ret true |
| 352 | end |
| 353 | note three-register forms: Rd, Rn, Rm (31 the zero register); fl as given |
| 354 | fn d3r x ulong fl ulong to void |
| 355 | put dc ddst gz and x 31 |
| 356 | put dc ds1 gz fld x 5 5 |
| 357 | put dc ds2 gz fld x 16 5 |
| 358 | put dc dfl fl |
| 359 | end |
| 360 | note ADD/SUB (extended register): Rn 31 is SP (public); Rd 31 is SP unless flags are set |
| 361 | fn daddx x ulong to void |
| 362 | rd = and x 31 |
| 363 | s = fld x 29 1 |
| 364 | if eq s 1 |
| 365 | put dc ddst gz rd |
| 366 | put dc dfl 2 |
| 367 | else |
| 368 | if eq rd 31 |
| 369 | put dc dspo 3 |
| 370 | ret |
| 371 | end |
| 372 | put dc ddst rd |
| 373 | end |
| 374 | put dc ds1 gz fld x 5 5 |
| 375 | put dc ds2 gz fld x 16 5 |
| 376 | end |
| 377 | fn dalu x ulong to bool |
| 378 | m = and x 528482304 |
| 379 | if eq m 285212672 |
| 380 | daddi x |
| 381 | ret true |
| 382 | end |
| 383 | if eq m 301989888 |
| 384 | dlogi x |
| 385 | ret true |
| 386 | end |
| 387 | if eq m 310378496 |
| 388 | ret dmovw x |
| 389 | end |
| 390 | if eq m 318767104 |
| 391 | ret dbfm x |
| 392 | end |
| 393 | if eq m 327155712 |
| 394 | if or ne fld x 29 2 0 ne fld x 21 1 0 |
| 395 | ret false |
| 396 | end |
| 397 | d3r x 0 |
| 398 | ret true |
| 399 | end |
| 400 | if eq and x 520093696 268435456 |
| 401 | put dc ddst gz and x 31 |
| 402 | ret true |
| 403 | end |
| 404 | if eq and x 520093696 167772160 |
| 405 | if eq fld x 29 2 3 |
| 406 | d3r x 2 |
| 407 | else |
| 408 | d3r x 0 |
| 409 | end |
| 410 | ret true |
| 411 | end |
| 412 | m = and x 522190848 |
| 413 | if eq m 184549376 |
| 414 | d3r x shl fld x 29 1 1 |
| 415 | ret true |
| 416 | end |
| 417 | if eq m 186646528 |
| 418 | daddx x |
| 419 | ret true |
| 420 | end |
| 421 | m = and x 534773760 |
| 422 | if eq m 436207616 |
| 423 | if ne fld x 10 6 0 |
| 424 | ret false |
| 425 | end |
| 426 | d3r x or 1 shl fld x 29 1 1 |
| 427 | ret true |
| 428 | end |
| 429 | if eq m 440401920 |
| 430 | if eq fld x 29 1 0 |
| 431 | ret false |
| 432 | end |
| 433 | put dc ds1 gz fld x 5 5 |
| 434 | if eq fld x 11 1 0 |
| 435 | put dc ds2 gz fld x 16 5 |
| 436 | end |
| 437 | put dc dfl 3 |
| 438 | ret true |
| 439 | end |
| 440 | if eq m 444596224 |
| 441 | if or ne fld x 29 1 0 ne fld x 11 1 0 |
| 442 | ret false |
| 443 | end |
| 444 | d3r x 1 |
| 445 | ret true |
| 446 | end |
| 447 | m = and x 1608515584 |
| 448 | if eq m 448790528 |
| 449 | d3r x 0 |
| 450 | ret true |
| 451 | end |
| 452 | if eq m 1522532352 |
| 453 | put dc ddst gz and x 31 |
| 454 | put dc ds1 gz fld x 5 5 |
| 455 | ret true |
| 456 | end |
| 457 | if eq and x 520093696 452984832 |
| 458 | d3r x 0 |
| 459 | put dc ds3 gz fld x 10 5 |
| 460 | ret true |
| 461 | end |
| 462 | ret false |
| 463 | end |
| 464 | note allocation checks (Arm ARM C4.1): an encoding of a decoded class that is unallocated, reserved |
| 465 | note or outside the subset is UNKNOWN. bmok: the logical-immediate bitmask (DecodeBitMasks) is valid. |
| 466 | fn bmok x ulong to bool |
| 467 | n = fld x 22 1 |
| 468 | s = fld x 10 6 |
| 469 | if and eq fld x 31 1 0 eq n 1 |
| 470 | ret false |
| 471 | end |
| 472 | v = or shl n 6 and not s 63 |
| 473 | if eq v 0 |
| 474 | ret false |
| 475 | end |
| 476 | l = ulong 6 |
| 477 | while eq and shr v l 1 0 bound 8 |
| 478 | l = sub l 1 |
| 479 | end |
| 480 | if eq l 0 |
| 481 | ret false |
| 482 | end |
| 483 | lv = sub shl ulong 1 l 1 |
| 484 | ret ne and s lv lv |
| 485 | end |
| 486 | fn dp3ok x ulong sf ulong to bool |
| 487 | if ne fld x 29 2 0 |
| 488 | ret false |
| 489 | end |
| 490 | o = fld x 21 3 |
| 491 | if eq o 0 |
| 492 | ret true |
| 493 | end |
| 494 | if eq sf 0 |
| 495 | ret false |
| 496 | end |
| 497 | if or eq o 1 eq o 5 |
| 498 | ret true |
| 499 | end |
| 500 | if or eq o 2 eq o 6 |
| 501 | ret eq fld x 15 1 0 |
| 502 | end |
| 503 | ret false |
| 504 | end |
| 505 | fn aluok x ulong to bool |
| 506 | sf = fld x 31 1 |
| 507 | m = and x 528482304 |
| 508 | if eq m 301989888 |
| 509 | ret bmok x |
| 510 | end |
| 511 | if eq m 310378496 |
| 512 | ret or eq sf 1 eq fld x 22 1 0 |
| 513 | end |
| 514 | if or eq m 318767104 eq m 327155712 |
| 515 | if ne fld x 22 1 sf |
| 516 | ret false |
| 517 | end |
| 518 | if and eq sf 0 eq m 318767104 |
| 519 | ret and eq fld x 21 1 0 eq fld x 15 1 0 |
| 520 | end |
| 521 | ret or eq sf 1 eq fld x 15 1 0 |
| 522 | end |
| 523 | if eq and x 520093696 167772160 |
| 524 | ret or eq sf 1 eq fld x 15 1 0 |
| 525 | end |
| 526 | m = and x 522190848 |
| 527 | if eq m 184549376 |
| 528 | if eq fld x 22 2 3 |
| 529 | ret false |
| 530 | end |
| 531 | ret or eq sf 1 eq fld x 15 1 0 |
| 532 | end |
| 533 | if eq m 186646528 |
| 534 | if ne fld x 22 2 0 |
| 535 | ret false |
| 536 | end |
| 537 | ret le fld x 10 3 4 |
| 538 | end |
| 539 | if eq and x 534773760 440401920 |
| 540 | ret and eq fld x 10 1 0 eq fld x 4 1 0 |
| 541 | end |
| 542 | m = and x 1608515584 |
| 543 | if eq m 448790528 |
| 544 | if ne fld x 29 1 0 |
| 545 | ret false |
| 546 | end |
| 547 | o = fld x 10 6 |
| 548 | ret or or eq o 2 eq o 3 and ge o 8 le o 11 |
| 549 | end |
| 550 | if eq m 1522532352 |
| 551 | o = fld x 10 6 |
| 552 | if or gt o 5 ne fld x 16 5 0 |
| 553 | ret false |
| 554 | end |
| 555 | ret or eq sf 1 ne o 3 |
| 556 | end |
| 557 | if eq and x 520093696 452984832 |
| 558 | ret dp3ok x sf |
| 559 | end |
| 560 | ret true |
| 561 | end |
| 562 | fn fpok x ulong to bool |
| 563 | ty = fld x 22 2 |
| 564 | if gt ty 1 |
| 565 | ret false |
| 566 | end |
| 567 | if eq and x 1595997184 505413632 |
| 568 | op = fld x 16 3 |
| 569 | if le op 1 |
| 570 | ret true |
| 571 | end |
| 572 | if ne fld x 19 2 0 |
| 573 | ret false |
| 574 | end |
| 575 | if le op 5 |
| 576 | ret true |
| 577 | end |
| 578 | ret eq fld x 31 1 ty |
| 579 | end |
| 580 | if eq and x 1595964416 505430016 |
| 581 | op = fld x 15 6 |
| 582 | if le op 3 |
| 583 | ret true |
| 584 | end |
| 585 | if or eq op 4 eq op 5 |
| 586 | ret ne sub op 4 ty |
| 587 | end |
| 588 | ret false |
| 589 | end |
| 590 | if eq and x 1595948032 505421824 |
| 591 | ret and eq fld x 14 2 0 eq and x 7 0 |
| 592 | end |
| 593 | ret le fld x 12 4 8 |
| 594 | end |
| 595 | note constrained-unpredictable load/store forms omc never emits: writeback with Rt or Rt2 = Rn, and a |
| 596 | note load pair with Rt = Rt2 |
| 597 | fn lsok to bool |
| 598 | b = get dc dmb |
| 599 | if and ne get dc dwb 0 ne b 31 |
| 600 | if or eq get dc dmt b eq get dc dmt2 b |
| 601 | ret false |
| 602 | end |
| 603 | end |
| 604 | if and eq get dc dmk 1 ne get dc dmt2 255 |
| 605 | ret ne get dc dmt get dc dmt2 |
| 606 | end |
| 607 | ret true |
| 608 | end |
| 609 | note scalar floating point: FMOV/convert (general <-> FP), 1-source, compare, 2-source |
| 610 | fn dfp x ulong to bool |
| 611 | if ne fld x 29 2 0 |
| 612 | ret false |
| 613 | end |
| 614 | rd = and x 31 |
| 615 | rn = fld x 5 5 |
| 616 | if eq and x 1595997184 505413632 |
| 617 | op = fld x 16 3 |
| 618 | if or or eq op 2 eq op 3 eq op 7 |
| 619 | put dc ddst add 32 rd |
| 620 | put dc ds1 gz rn |
| 621 | else |
| 622 | put dc ddst gz rd |
| 623 | put dc ds1 add 32 rn |
| 624 | end |
| 625 | ret true |
| 626 | end |
| 627 | if ne fld x 31 1 0 |
| 628 | ret false |
| 629 | end |
| 630 | if eq and x 1595964416 505430016 |
| 631 | put dc ddst add 32 rd |
| 632 | put dc ds1 add 32 rn |
| 633 | ret true |
| 634 | end |
| 635 | if eq and x 1595948032 505421824 |
| 636 | put dc ds1 add 32 rn |
| 637 | if eq fld x 3 1 0 |
| 638 | put dc ds2 add 32 fld x 16 5 |
| 639 | end |
| 640 | put dc dfl 2 |
| 641 | ret true |
| 642 | end |
| 643 | if eq and x 1595935744 505415680 |
| 644 | put dc ddst add 32 rd |
| 645 | put dc ds1 add 32 rn |
| 646 | put dc ds2 add 32 fld x 16 5 |
| 647 | ret true |
| 648 | end |
| 649 | ret false |
| 650 | end |
| 651 | |
| 652 | note load/store kind, size and mnemonic from size, V and opc; false for PRFM and unallocated forms |
| 653 | fn lsk sz ulong v ulong opc ulong rt ulong to bool |
| 654 | if eq v 1 |
| 655 | b = shl ulong 1 sz |
| 656 | if ne and opc 2 0 |
| 657 | if ne sz 0 |
| 658 | ret false |
| 659 | end |
| 660 | b = ulong 16 |
| 661 | end |
| 662 | put dc dms b |
| 663 | put dc dmt add 32 rt |
| 664 | if eq and opc 1 1 |
| 665 | put dc dmk 1 |
| 666 | put dc dmn 14 |
| 667 | else |
| 668 | put dc dmk 2 |
| 669 | put dc dmn 18 |
| 670 | end |
| 671 | ret true |
| 672 | end |
| 673 | put dc dms shl ulong 1 sz |
| 674 | put dc dmt gz rt |
| 675 | k = sz |
| 676 | if gt k 2 |
| 677 | k = ulong 2 |
| 678 | end |
| 679 | if eq opc 0 |
| 680 | put dc dmk 2 |
| 681 | put dc dmn add 16 k |
| 682 | ret true |
| 683 | end |
| 684 | put dc dmk 1 |
| 685 | if eq opc 1 |
| 686 | put dc dmn add 10 mul k 2 |
| 687 | ret true |
| 688 | end |
| 689 | if eq opc 2 |
| 690 | if eq sz 3 |
| 691 | ret false |
| 692 | end |
| 693 | put dc dmn add 11 mul k 2 |
| 694 | ret true |
| 695 | end |
| 696 | if ge sz 2 |
| 697 | ret false |
| 698 | end |
| 699 | put dc dmn add 11 mul k 2 |
| 700 | ret true |
| 701 | end |
| 702 | fn dpair x ulong to bool |
| 703 | v = fld x 26 1 |
| 704 | opc = fld x 30 2 |
| 705 | l = fld x 22 1 |
| 706 | es = ulong 0 |
| 707 | if eq v 0 |
| 708 | if eq opc 0 |
| 709 | es = ulong 4 |
| 710 | end |
| 711 | if eq opc 2 |
| 712 | es = ulong 8 |
| 713 | end |
| 714 | if and and eq opc 1 eq l 1 ne fld x 23 2 0 |
| 715 | es = ulong 4 |
| 716 | end |
| 717 | put dc dmt gz and x 31 |
| 718 | put dc dmt2 gz fld x 10 5 |
| 719 | else |
| 720 | if lt opc 3 |
| 721 | es = shl ulong 4 opc |
| 722 | end |
| 723 | put dc dmt add 32 and x 31 |
| 724 | put dc dmt2 add 32 fld x 10 5 |
| 725 | end |
| 726 | if eq es 0 |
| 727 | ret false |
| 728 | end |
| 729 | put dc dms es |
| 730 | put dc dmf 6 |
| 731 | if eq l 1 |
| 732 | put dc dmk 1 |
| 733 | put dc dmn 19 |
| 734 | if and eq v 0 eq opc 1 |
| 735 | put dc dmn 21 |
| 736 | end |
| 737 | else |
| 738 | put dc dmk 2 |
| 739 | put dc dmn 20 |
| 740 | end |
| 741 | put dc dmb fld x 5 5 |
| 742 | ty = fld x 23 2 |
| 743 | off = mul sx fld x 15 7 7 es |
| 744 | if ne ty 1 |
| 745 | put dc dmo off |
| 746 | end |
| 747 | if or eq ty 1 eq ty 3 |
| 748 | put dc dwb 1 |
| 749 | put dc dspa off |
| 750 | end |
| 751 | ret true |
| 752 | end |
| 753 | note the immediate (unscaled / pre / post / unprivileged) forms by bits 11..10: 3 unscaled, 4 post, |
| 754 | note 8 unprivileged, 5 pre |
| 755 | fn uform ty ulong to ulong |
| 756 | if eq ty 0 |
| 757 | ret 3 |
| 758 | end |
| 759 | if eq ty 1 |
| 760 | ret 4 |
| 761 | end |
| 762 | if eq ty 2 |
| 763 | ret 8 |
| 764 | end |
| 765 | ret 5 |
| 766 | end |
| 767 | fn dls x ulong to bool |
| 768 | sz = fld x 30 2 |
| 769 | v = fld x 26 1 |
| 770 | opc = fld x 22 2 |
| 771 | rt = and x 31 |
| 772 | if eq and x 989855744 956301312 |
| 773 | if not lsk sz v opc rt |
| 774 | ret false |
| 775 | end |
| 776 | sc = sz |
| 777 | if and eq v 1 ne and opc 2 0 |
| 778 | sc = ulong 4 |
| 779 | end |
| 780 | put dc dmf 1 |
| 781 | put dc dmb fld x 5 5 |
| 782 | put dc dmo shl fld x 10 12 sc |
| 783 | ret true |
| 784 | end |
| 785 | if eq and x 991955968 941623296 |
| 786 | if eq fld x 14 1 0 |
| 787 | ret false |
| 788 | end |
| 789 | if not lsk sz v opc rt |
| 790 | ret false |
| 791 | end |
| 792 | put dc dmf 2 |
| 793 | put dc dmb fld x 5 5 |
| 794 | put dc dmi gz fld x 16 5 |
| 795 | ret true |
| 796 | end |
| 797 | if eq and x 991952896 939524096 |
| 798 | if not lsk sz v opc rt |
| 799 | ret false |
| 800 | end |
| 801 | ty = fld x 10 2 |
| 802 | im = sx fld x 12 9 9 |
| 803 | put dc dmb fld x 5 5 |
| 804 | if and eq v 1 eq ty 2 |
| 805 | ret false |
| 806 | end |
| 807 | put dc dmf uform ty |
| 808 | if ne ty 1 |
| 809 | put dc dmo im |
| 810 | end |
| 811 | if or eq ty 1 eq ty 3 |
| 812 | put dc dwb 1 |
| 813 | put dc dspa im |
| 814 | end |
| 815 | ret true |
| 816 | end |
| 817 | if eq and x 973078528 671088640 |
| 818 | ret dpair x |
| 819 | end |
| 820 | if eq and x 989855744 402653184 |
| 821 | o2 = fld x 30 2 |
| 822 | if eq o2 3 |
| 823 | ret false |
| 824 | end |
| 825 | put dc dmk 3 |
| 826 | put dc dmf 7 |
| 827 | put dc dmn 14 |
| 828 | if eq v 1 |
| 829 | put dc dmt add 32 rt |
| 830 | else |
| 831 | put dc dmt gz rt |
| 832 | if eq o2 2 |
| 833 | put dc dmn 15 |
| 834 | end |
| 835 | end |
| 836 | ret true |
| 837 | end |
| 838 | ret false |
| 839 | end |
| 840 | fn dec x ulong w ulong to void |
| 841 | dclr |
| 842 | if dbr x w |
| 843 | ret |
| 844 | end |
| 845 | if dls x |
| 846 | if lsok |
| 847 | ret |
| 848 | end |
| 849 | end |
| 850 | dclr |
| 851 | if dalu x |
| 852 | if aluok x |
| 853 | ret |
| 854 | end |
| 855 | end |
| 856 | dclr |
| 857 | if dfp x |
| 858 | if fpok x |
| 859 | ret |
| 860 | end |
| 861 | end |
| 862 | dclr |
| 863 | put dc dkind 10 |
| 864 | put dc dmn 22 |
| 865 | end |
| 866 | |
| 867 | note ---- dataflow ---------------------------------------------------------------------------------- |
| 868 | fn unh w ulong k ulong to void |
| 869 | if eq get uh w 0 |
| 870 | put uh w uchar k |
| 871 | end |
| 872 | end |
| 873 | fn push u ulong to void |
| 874 | if eq get inq u 0 |
| 875 | put inq u 1 |
| 876 | n = get gv 1 |
| 877 | put wl n u |
| 878 | put gv 1 add n 1 |
| 879 | end |
| 880 | end |
| 881 | note join the current state cu into word u |
| 882 | fn join u ulong to void |
| 883 | dd = add get cu 2 1 |
| 884 | if eq get dep u 0 |
| 885 | put rm u get cu 0 |
| 886 | put sm u get cu 1 |
| 887 | put dep u dd |
| 888 | put fid u get cu 3 |
| 889 | push u |
| 890 | pjoin u true |
| 891 | ret |
| 892 | end |
| 893 | if ne get dep u dd |
| 894 | unh u 4 |
| 895 | ret |
| 896 | end |
| 897 | if ne get fid u get cu 3 |
| 898 | unh u 5 |
| 899 | ret |
| 900 | end |
| 901 | a = or get rm u get cu 0 |
| 902 | b = or get sm u get cu 1 |
| 903 | if or ne a get rm u ne b get sm u |
| 904 | put rm u a |
| 905 | put sm u b |
| 906 | push u |
| 907 | end |
| 908 | pjoin u false |
| 909 | end |
| 910 | note an edge from w to u: outside the artifact is unhandled; into the trap stubs it ends the path |
| 911 | fn flow w ulong u ulong to void |
| 912 | if ge u get gv 0 |
| 913 | unh w 11 |
| 914 | ret |
| 915 | end |
| 916 | if ne get trp u 0 |
| 917 | ret |
| 918 | end |
| 919 | join u |
| 920 | end |
| 921 | fn talu to void |
| 922 | r = get cu 0 |
| 923 | t = or or tnt r get dc ds1 tnt r get dc ds2 tnt r get dc ds3 |
| 924 | fl = get dc dfl |
| 925 | if ne and fl 1 0 |
| 926 | t = or t tnt r 31 |
| 927 | end |
| 928 | if ne and fl 4 0 |
| 929 | t = or t tnt r get dc ddst |
| 930 | end |
| 931 | if ne and fl 2 0 |
| 932 | r = sbit r 31 t |
| 933 | end |
| 934 | put cu 0 sbit r get dc ddst t |
| 935 | end |
| 936 | note SP arithmetic: k = bytes / 8 slots shift; the slots that come into view are unknown (DATA) |
| 937 | fn tsp w ulong to void |
| 938 | k = get dc dspo |
| 939 | if eq k 3 |
| 940 | unh w 1 |
| 941 | ret |
| 942 | end |
| 943 | a = get dc dspa |
| 944 | d = get cu 2 |
| 945 | s = get cu 1 |
| 946 | q = div a 8 |
| 947 | all = not ulong 0 |
| 948 | if ne rem a 8 0 |
| 949 | q = ulong 64 |
| 950 | end |
| 951 | if eq k 1 |
| 952 | if gt a d |
| 953 | unh w 12 |
| 954 | put cu 2 0 |
| 955 | put cu 1 all |
| 956 | ret |
| 957 | end |
| 958 | put cu 2 sub d a |
| 959 | if ge q 64 |
| 960 | put cu 1 all |
| 961 | ret |
| 962 | end |
| 963 | if ne q 0 |
| 964 | put cu 1 or shr s q not shr all q |
| 965 | end |
| 966 | ret |
| 967 | end |
| 968 | put cu 2 add d a |
| 969 | if ge q 64 |
| 970 | put cu 1 all |
| 971 | ret |
| 972 | end |
| 973 | if ne q 0 |
| 974 | put cu 1 or shl s q sub shl ulong 1 q 1 |
| 975 | end |
| 976 | end |
| 977 | note SP-relative slot range check: below SP or above the function's entry SP is unhandled |
| 978 | fn slotok w ulong off ulong es ulong to bool |
| 979 | if ne shr off 63 0 |
| 980 | unh w 14 |
| 981 | ret false |
| 982 | end |
| 983 | if gt add off es get cu 2 |
| 984 | unh w 3 |
| 985 | ret false |
| 986 | end |
| 987 | ret true |
| 988 | end |
| 989 | fn slotld w ulong off ulong es ulong to ulong |
| 990 | if not slotok w off es |
| 991 | ret 1 |
| 992 | end |
| 993 | s = get cu 1 |
| 994 | t = ulong 0 |
| 995 | j = div off 8 |
| 996 | e = div add off sub es 1 8 |
| 997 | while le j e bound 8 |
| 998 | if ge j 64 |
| 999 | t = ulong 1 |
| 1000 | else |
| 1001 | t = or t and shr s j 1 |
| 1002 | end |
| 1003 | j = add j 1 |
| 1004 | end |
| 1005 | ret t |
| 1006 | end |
| 1007 | fn slotst w ulong off ulong es ulong v ulong to void |
| 1008 | if not slotok w off es |
| 1009 | ret |
| 1010 | end |
| 1011 | s = get cu 1 |
| 1012 | j = div off 8 |
| 1013 | if and and eq rem off 8 0 eq es 8 lt j 64 |
| 1014 | put cu 1 sbit s j v |
| 1015 | ret |
| 1016 | end |
| 1017 | e = div add off sub es 1 8 |
| 1018 | while le j e bound 8 |
| 1019 | if lt j 64 |
| 1020 | s = sbit s j or v and shr s j 1 |
| 1021 | end |
| 1022 | j = add j 1 |
| 1023 | end |
| 1024 | put cu 1 s |
| 1025 | end |
| 1026 | fn tslot w ulong to void |
| 1027 | off = get dc dmo |
| 1028 | es = get dc dms |
| 1029 | r = get cu 0 |
| 1030 | if eq get dc dmk 1 |
| 1031 | t = slotld w off es |
| 1032 | r = sbit r get dc dmt t |
| 1033 | if ne get dc dmt2 255 |
| 1034 | r = sbit r get dc dmt2 slotld w add off es es |
| 1035 | end |
| 1036 | put cu 0 r |
| 1037 | ret |
| 1038 | end |
| 1039 | slotst w off es tnt r get dc dmt |
| 1040 | if ne get dc dmt2 255 |
| 1041 | slotst w add off es es tnt r get dc dmt2 |
| 1042 | end |
| 1043 | end |
| 1044 | fn tmem w ulong to void |
| 1045 | mk = get dc dmk |
| 1046 | r = get cu 0 |
| 1047 | if eq mk 3 |
| 1048 | put cu 0 sbit r get dc dmt 0 |
| 1049 | ret |
| 1050 | end |
| 1051 | b = get dc dmb |
| 1052 | if eq b 31 |
| 1053 | if ne get dc dwb 0 |
| 1054 | unh w 2 |
| 1055 | else |
| 1056 | if eq get dc dmi 255 |
| 1057 | tslot w |
| 1058 | ret |
| 1059 | end |
| 1060 | end |
| 1061 | end |
| 1062 | if eq mk 1 |
| 1063 | t = ppublic ulong get wd w |
| 1064 | v = ulong 1 |
| 1065 | if ne t 0 |
| 1066 | v = ulong 0 |
| 1067 | end |
| 1068 | r = sbit r get dc dmt v |
| 1069 | r = sbit r get dc dmt2 v |
| 1070 | put cu 0 r |
| 1071 | end |
| 1072 | end |
| 1073 | fn pseq w ulong to void |
| 1074 | if ne get dc dspo 0 |
| 1075 | tsp w |
| 1076 | pshift |
| 1077 | flow w add w 1 |
| 1078 | ret |
| 1079 | end |
| 1080 | if eq get dc ddst 7 |
| 1081 | unh w 13 |
| 1082 | end |
| 1083 | mk = get dc dmk |
| 1084 | if ne mk 0 |
| 1085 | if eq mk 1 |
| 1086 | if or eq get dc dmt 7 eq get dc dmt2 7 |
| 1087 | unh w 13 |
| 1088 | end |
| 1089 | end |
| 1090 | tmem w |
| 1091 | else |
| 1092 | talu |
| 1093 | end |
| 1094 | zstep w |
| 1095 | pstep w |
| 1096 | flow w add w 1 |
| 1097 | end |
| 1098 | note BL: the callee's entry state joins the caller's registers (x30 public), a fresh stack; after the |
| 1099 | note call the registers are the callee's exit summary, the caller's own slots and depth are kept |
| 1100 | fn pbl w ulong to void |
| 1101 | t = get dc dtgt |
| 1102 | if ge t get gv 0 |
| 1103 | unh w 11 |
| 1104 | ret |
| 1105 | end |
| 1106 | r = get cu 0 |
| 1107 | s = get cu 1 |
| 1108 | d = get cu 2 |
| 1109 | f = get cu 3 |
| 1110 | put cu 0 and r not shl ulong 1 30 |
| 1111 | put cu 1 not ulong 0 |
| 1112 | put cu 2 0 |
| 1113 | put cu 3 t |
| 1114 | pcall |
| 1115 | if eq get trp t 0 |
| 1116 | join t |
| 1117 | end |
| 1118 | put cu 1 s |
| 1119 | put cu 2 d |
| 1120 | put cu 3 f |
| 1121 | if ne get exs t 0 |
| 1122 | put cu 0 get ex t |
| 1123 | preturn w t |
| 1124 | flow w add w 1 |
| 1125 | end |
| 1126 | end |
| 1127 | fn requeue f ulong to void |
| 1128 | n = get gv 0 |
| 1129 | for a ulong 5 |
| 1130 | for b ulong 500000 |
| 1131 | j = add mul a 500000 b |
| 1132 | if ge j n |
| 1133 | ret |
| 1134 | end |
| 1135 | if and eq get blt j add f 1 ne get dep j 0 |
| 1136 | push j |
| 1137 | end |
| 1138 | end |
| 1139 | end |
| 1140 | end |
| 1141 | fn pret w ulong to void |
| 1142 | if ne get dc ds1 30 |
| 1143 | unh w 8 |
| 1144 | end |
| 1145 | if ne get cu 2 0 |
| 1146 | unh w 6 |
| 1147 | end |
| 1148 | if ne tnt get cu 0 30 0 |
| 1149 | unh w 7 |
| 1150 | end |
| 1151 | f = get cu 3 |
| 1152 | e = get ex f |
| 1153 | n = or e get cu 0 |
| 1154 | if pexit f |
| 1155 | requeue f |
| 1156 | end |
| 1157 | if or eq get exs f 0 ne n e |
| 1158 | put ex f n |
| 1159 | put exs f 1 |
| 1160 | requeue f |
| 1161 | end |
| 1162 | end |
| 1163 | fn proc w ulong to void |
| 1164 | dec ulong get wd w w |
| 1165 | put cu 0 get rm w |
| 1166 | put cu 1 get sm w |
| 1167 | put cu 2 sub get dep w 1 |
| 1168 | put cu 3 get fid w |
| 1169 | pload w |
| 1170 | k = get dc dkind |
| 1171 | if eq k 0 |
| 1172 | pseq w |
| 1173 | ret |
| 1174 | end |
| 1175 | if eq k 11 |
| 1176 | flow w add w 1 |
| 1177 | ret |
| 1178 | end |
| 1179 | if eq k 1 |
| 1180 | flow w get dc dtgt |
| 1181 | ret |
| 1182 | end |
| 1183 | if eq k 3 |
| 1184 | flow w get dc dtgt |
| 1185 | if lt get dc dcc 14 |
| 1186 | flow w add w 1 |
| 1187 | end |
| 1188 | ret |
| 1189 | end |
| 1190 | if or eq k 4 eq k 5 |
| 1191 | flow w get dc dtgt |
| 1192 | flow w add w 1 |
| 1193 | ret |
| 1194 | end |
| 1195 | if eq k 2 |
| 1196 | pbl w |
| 1197 | ret |
| 1198 | end |
| 1199 | if eq k 6 |
| 1200 | pret w |
| 1201 | ret |
| 1202 | end |
| 1203 | if eq k 7 |
| 1204 | unh w 8 |
| 1205 | ret |
| 1206 | end |
| 1207 | if eq k 8 |
| 1208 | unh w 9 |
| 1209 | ret |
| 1210 | end |
| 1211 | if eq k 9 |
| 1212 | unh w 10 |
| 1213 | put cu 0 sbit get cu 0 0 1 |
| 1214 | put pc 0 0 |
| 1215 | flow w add w 1 |
| 1216 | end |
| 1217 | end |
| 1218 | fn fix to void |
| 1219 | for a ulong 999999 |
| 1220 | if eq get gv 1 0 |
| 1221 | ret |
| 1222 | end |
| 1223 | for b ulong 999999 |
| 1224 | n = get gv 1 |
| 1225 | if eq n 0 |
| 1226 | break |
| 1227 | end |
| 1228 | u = get wl sub n 1 |
| 1229 | put gv 1 sub n 1 |
| 1230 | put inq u 0 |
| 1231 | proc u |
| 1232 | end |
| 1233 | end |
| 1234 | exit 92 |
| 1235 | end |
| 1236 | |
| 1237 | note ---- preparation ------------------------------------------------------------------------------- |
| 1238 | note trap stubs (omc.om finish): MOVZ X1, #code (1..14); B tail; tail = MOV X0, X7; LDR X16, [X7, #16]; |
| 1239 | note BR X16. trp: code at the MOVZ, 16 at its B, 15 on the three tail words |
| 1240 | fn stubat w ulong to void |
| 1241 | n = get gv 0 |
| 1242 | x = ulong get wd w |
| 1243 | if ne and x 4292870175 3531603969 |
| 1244 | ret |
| 1245 | end |
| 1246 | code = fld x 5 16 |
| 1247 | if or lt code 1 gt code 14 |
| 1248 | ret |
| 1249 | end |
| 1250 | if ge add w 1 n |
| 1251 | ret |
| 1252 | end |
| 1253 | y = ulong get wd add w 1 |
| 1254 | if ne and y 4227858432 335544320 |
| 1255 | ret |
| 1256 | end |
| 1257 | u = add add w 1 sx and y 67108863 26 |
| 1258 | if or ge u n ge add u 2 n |
| 1259 | ret |
| 1260 | end |
| 1261 | if ne ulong get wd u 2852586464 |
| 1262 | ret |
| 1263 | end |
| 1264 | if ne ulong get wd add u 1 4181723376 |
| 1265 | ret |
| 1266 | end |
| 1267 | if ne ulong get wd add u 2 3592356352 |
| 1268 | ret |
| 1269 | end |
| 1270 | put trp w uchar code |
| 1271 | put trp add w 1 16 |
| 1272 | put trp u 15 |
| 1273 | put trp add u 1 15 |
| 1274 | put trp add u 2 15 |
| 1275 | end |
| 1276 | fn blat w ulong to void |
| 1277 | x = ulong get wd w |
| 1278 | if eq and x 4227858432 2483027968 |
| 1279 | t = add w sx and x 67108863 26 |
| 1280 | if lt t get gv 0 |
| 1281 | put blt w add t 1 |
| 1282 | end |
| 1283 | end |
| 1284 | end |
| 1285 | fn prep to void |
| 1286 | n = get gv 0 |
| 1287 | for a ulong 5 |
| 1288 | for b ulong 500000 |
| 1289 | j = add mul a 500000 b |
| 1290 | if ge j n |
| 1291 | ret |
| 1292 | end |
| 1293 | stubat j |
| 1294 | blat j |
| 1295 | end |
| 1296 | end |
| 1297 | end |
| 1298 | fn seed to void |
| 1299 | e = ulong 0 |
| 1300 | x = ulong get wd 0 |
| 1301 | if eq and x 4227858432 335544320 |
| 1302 | t = sx and x 67108863 26 |
| 1303 | if and lt t get gv 0 ne t 0 |
| 1304 | e = t |
| 1305 | put gv 16 1 |
| 1306 | end |
| 1307 | end |
| 1308 | put gv 2 e |
| 1309 | m = not ulong 63 |
| 1310 | m = and m not shl ulong 1 7 |
| 1311 | m = and m not shl ulong 1 30 |
| 1312 | put cu 0 or m get gv 3 |
| 1313 | put cu 1 not ulong 0 |
| 1314 | put cu 2 0 |
| 1315 | put cu 3 e |
| 1316 | for i ulong 6 |
| 1317 | put pc i ptok add i 2 0 |
| 1318 | end |
| 1319 | if eq get trp e 0 |
| 1320 | join e |
| 1321 | end |
| 1322 | end |
| 1323 | |
| 1324 | note ---- report ------------------------------------------------------------------------------------ |
| 1325 | fn reached w ulong to bool |
| 1326 | if ne get dep w 0 |
| 1327 | ret true |
| 1328 | end |
| 1329 | ret and eq w 0 eq get gv 16 1 |
| 1330 | end |
| 1331 | fn rbr w ulong to void |
| 1332 | inc 14 |
| 1333 | say 47 |
| 1334 | od w |
| 1335 | say 104 |
| 1336 | say get dc dmn |
| 1337 | say 49 |
| 1338 | t = get dc dtgt |
| 1339 | od t |
| 1340 | say 104 |
| 1341 | tc = ulong 0 |
| 1342 | if lt t get gv 0 |
| 1343 | tc = ulong get trp t |
| 1344 | end |
| 1345 | if not reached w |
| 1346 | say 53 |
| 1347 | inc 7 |
| 1348 | onl |
| 1349 | ret |
| 1350 | end |
| 1351 | k = get dc dkind |
| 1352 | d = ulong 0 |
| 1353 | r = get rm w |
| 1354 | if eq k 3 |
| 1355 | if lt get dc dcc 14 |
| 1356 | d = tnt r 31 |
| 1357 | end |
| 1358 | else |
| 1359 | d = tnt r get dc ds1 |
| 1360 | end |
| 1361 | if eq d 0 |
| 1362 | say 50 |
| 1363 | inc 4 |
| 1364 | else |
| 1365 | pload w |
| 1366 | if and ne tc 0 ztrap w |
| 1367 | say 51 |
| 1368 | inc 5 |
| 1369 | else |
| 1370 | ezsay 0 |
| 1371 | inc 6 |
| 1372 | end |
| 1373 | end |
| 1374 | if and eq k 3 ge get dc dcc 14 |
| 1375 | say 107 |
| 1376 | end |
| 1377 | if ne tc 0 |
| 1378 | say 57 |
| 1379 | if le tc 14 |
| 1380 | od tc |
| 1381 | else |
| 1382 | say 61 |
| 1383 | end |
| 1384 | end |
| 1385 | onl |
| 1386 | end |
| 1387 | fn listed to bool |
| 1388 | mk = get dc dmk |
| 1389 | if or eq mk 0 eq mk 3 |
| 1390 | ret false |
| 1391 | end |
| 1392 | b = get dc dmb |
| 1393 | if and ne b 31 ne b 29 |
| 1394 | ret true |
| 1395 | end |
| 1396 | ret ne get dc dmi 255 |
| 1397 | end |
| 1398 | fn rmem w ulong to void |
| 1399 | inc 15 |
| 1400 | say 48 |
| 1401 | od w |
| 1402 | say 104 |
| 1403 | say get dc dmn |
| 1404 | say 104 |
| 1405 | say add 80 get dc dmf |
| 1406 | say 58 |
| 1407 | b = get dc dmb |
| 1408 | oreg b |
| 1409 | say 59 |
| 1410 | i = get dc dmi |
| 1411 | oreg i |
| 1412 | say 104 |
| 1413 | if ne get trp w 0 |
| 1414 | say 54 |
| 1415 | say 62 |
| 1416 | inc 8 |
| 1417 | onl |
| 1418 | ret |
| 1419 | end |
| 1420 | if not reached w |
| 1421 | say 53 |
| 1422 | inc 11 |
| 1423 | onl |
| 1424 | ret |
| 1425 | end |
| 1426 | r = get rm w |
| 1427 | t = tnt r i |
| 1428 | if ne b 31 |
| 1429 | t = or t tnt r b |
| 1430 | end |
| 1431 | if ne t 0 |
| 1432 | say 56 |
| 1433 | inc 10 |
| 1434 | else |
| 1435 | if ne i 255 |
| 1436 | say 55 |
| 1437 | inc 9 |
| 1438 | else |
| 1439 | say 54 |
| 1440 | inc 8 |
| 1441 | end |
| 1442 | end |
| 1443 | onl |
| 1444 | end |
| 1445 | fn rep w ulong to void |
| 1446 | x = ulong get wd w |
| 1447 | dec x w |
| 1448 | k = get dc dkind |
| 1449 | if eq k 10 |
| 1450 | say 45 |
| 1451 | od w |
| 1452 | say 78 |
| 1453 | oh x |
| 1454 | onl |
| 1455 | inc 12 |
| 1456 | end |
| 1457 | u = ulong get uh w |
| 1458 | if ne u 0 |
| 1459 | say 46 |
| 1460 | od w |
| 1461 | say 104 |
| 1462 | if eq u 15 |
| 1463 | psay 5 |
| 1464 | else |
| 1465 | say add 89 u |
| 1466 | end |
| 1467 | onl |
| 1468 | inc 13 |
| 1469 | end |
| 1470 | if or or eq k 3 eq k 4 eq k 5 |
| 1471 | rbr w |
| 1472 | end |
| 1473 | if listed |
| 1474 | rmem w |
| 1475 | end |
| 1476 | if ne get dep w 0 |
| 1477 | pload w |
| 1478 | t = ppublic x |
| 1479 | if ne t 0 |
| 1480 | psay 1 |
| 1481 | od w |
| 1482 | psay 2 |
| 1483 | od sub shr t 56 2 |
| 1484 | psay 3 |
| 1485 | od and t 72057594037927935 |
| 1486 | onl |
| 1487 | end |
| 1488 | end |
| 1489 | end |
| 1490 | fn header to void |
| 1491 | say 41 |
| 1492 | od get gv 0 |
| 1493 | say 42 |
| 1494 | od get gv 2 |
| 1495 | say 43 |
| 1496 | m = get gv 3 |
| 1497 | if eq m 0 |
| 1498 | say 44 |
| 1499 | else |
| 1500 | first = true |
| 1501 | for i ulong 6 |
| 1502 | if ne and shr m i 1 0 |
| 1503 | if not first |
| 1504 | say 109 |
| 1505 | end |
| 1506 | say 108 |
| 1507 | od i |
| 1508 | first = false |
| 1509 | end |
| 1510 | end |
| 1511 | end |
| 1512 | onl |
| 1513 | for i ulong get gv 19 |
| 1514 | psay 0 |
| 1515 | od get pdecl mul i 3 |
| 1516 | psay 3 |
| 1517 | od get pdecl add mul i 3 1 |
| 1518 | psay 4 |
| 1519 | od get pdecl add mul i 3 2 |
| 1520 | onl |
| 1521 | end |
| 1522 | end |
| 1523 | fn sumkv id ulong k ulong to void |
| 1524 | say id |
| 1525 | od get gv k |
| 1526 | end |
| 1527 | fn summary to int |
| 1528 | sumkv 63 14 |
| 1529 | sumkv 64 4 |
| 1530 | sumkv 65 5 |
| 1531 | sumkv 66 6 |
| 1532 | sumkv 67 7 |
| 1533 | sumkv 68 15 |
| 1534 | sumkv 69 8 |
| 1535 | sumkv 70 9 |
| 1536 | sumkv 71 10 |
| 1537 | sumkv 72 11 |
| 1538 | sumkv 73 12 |
| 1539 | sumkv 74 13 |
| 1540 | onl |
| 1541 | man = add get gv 12 get gv 13 |
| 1542 | if ne man 0 |
| 1543 | say 105 |
| 1544 | od man |
| 1545 | say 106 |
| 1546 | onl |
| 1547 | ezsay 1 |
| 1548 | onl |
| 1549 | ret 2 |
| 1550 | end |
| 1551 | if ne get gv 6 0 |
| 1552 | ezsay 1 |
| 1553 | onl |
| 1554 | ret 2 |
| 1555 | end |
| 1556 | if ne get gv 10 0 |
| 1557 | say 76 |
| 1558 | onl |
| 1559 | ret 1 |
| 1560 | end |
| 1561 | say 75 |
| 1562 | onl |
| 1563 | ret 0 |
| 1564 | end |
| 1565 | fn report to int |
| 1566 | header |
| 1567 | n = get gv 0 |
| 1568 | for a ulong 5 |
| 1569 | for b ulong 500000 |
| 1570 | j = add mul a 500000 b |
| 1571 | if ge j n |
| 1572 | break |
| 1573 | end |
| 1574 | rep j |
| 1575 | rvshow j |
| 1576 | end |
| 1577 | end |
| 1578 | v = summary |
| 1579 | obf |
| 1580 | ret v |
| 1581 | end |
| 1582 | |
| 1583 | note ---- input ------------------------------------------------------------------------------------- |
| 1584 | note xN marks a DATA entry register; pub:SLOT:OFF:LEN declares a public immutable memory range. |
| 1585 | fn args to bool |
| 1586 | c = argcnt |
| 1587 | i = ulong 1 |
| 1588 | while lt long i c bound 64 |
| 1589 | r = argread i pab 0 len pab |
| 1590 | if lt r 0 |
| 1591 | ret false |
| 1592 | end |
| 1593 | if and eq r 2 eq get pab 0 120 |
| 1594 | d = get pab 1 |
| 1595 | if or lt d 48 gt d 53 |
| 1596 | ret false |
| 1597 | end |
| 1598 | put gv 3 or get gv 3 shl ulong 1 ulong sub d 48 |
| 1599 | else |
| 1600 | if not parg ulong r |
| 1601 | ret false |
| 1602 | end |
| 1603 | end |
| 1604 | i = add i 1 |
| 1605 | end |
| 1606 | ret true |
| 1607 | end |
| 1608 | fn rdin to ulong |
| 1609 | n = ulong 0 |
| 1610 | go = true |
| 1611 | while go bound 999999 |
| 1612 | r = read 0 inb n sub len inb n |
| 1613 | if lt r 0 |
| 1614 | ret 0 |
| 1615 | end |
| 1616 | if eq r 0 |
| 1617 | go = false |
| 1618 | else |
| 1619 | n = add n ulong r |
| 1620 | if eq n len inb |
| 1621 | go = false |
| 1622 | end |
| 1623 | end |
| 1624 | end |
| 1625 | ret n |
| 1626 | end |
| 1627 | fn bad to void |
| 1628 | say 80 |
| 1629 | onl |
| 1630 | obf |
| 1631 | exit 91 |
| 1632 | end |
| 1633 | fn main to int |
| 1634 | inittb |
| 1635 | if not args |
| 1636 | psay 6 |
| 1637 | onl |
| 1638 | obf |
| 1639 | ret 90 |
| 1640 | end |
| 1641 | n = rdin |
| 1642 | if or or eq n 0 ne rem n 4 0 gt n 8388608 |
| 1643 | bad |
| 1644 | end |
| 1645 | nw = div n 4 |
| 1646 | put gv 0 nw |
| 1647 | for a ulong 5 |
| 1648 | for b ulong 500000 |
| 1649 | j = add mul a 500000 b |
| 1650 | if ge j nw |
| 1651 | break |
| 1652 | end |
| 1653 | o = mul j 4 |
| 1654 | v = or ulong get inb o shl ulong get inb add o 1 8 |
| 1655 | v = or v shl ulong get inb add o 2 16 |
| 1656 | v = or v shl ulong get inb add o 3 24 |
| 1657 | put wd j uint v |
| 1658 | end |
| 1659 | end |
| 1660 | if eq ulong get wd 0 1179403647 |
| 1661 | bad |
| 1662 | end |
| 1663 | prep |
| 1664 | seed |
| 1665 | rvfix |
| 1666 | ret report |
| 1667 | end |
| 1668 | |
| 1669 | note ---- exact entry-parameter provenance (constant domain, no interval or call specialization) ----- |
| 1670 | fn psay id ulong to void |
| 1671 | k = ulong 0 |
| 1672 | s = ulong 0 |
| 1673 | for i ulong len pmsg |
| 1674 | if eq get pmsg i 10 |
| 1675 | if eq k id |
| 1676 | for j ulong sub i s |
| 1677 | ob1 get pmsg add s j |
| 1678 | end |
| 1679 | ret |
| 1680 | end |
| 1681 | k = add k 1 |
| 1682 | s = add i 1 |
| 1683 | end |
| 1684 | end |
| 1685 | end |
| 1686 | fn parg n ulong to bool |
| 1687 | if or lt n 9 ge get gv 19 32 |
| 1688 | ret false |
| 1689 | end |
| 1690 | if ne get pab 0 112 |
| 1691 | ret false |
| 1692 | end |
| 1693 | if ne get pab 1 117 |
| 1694 | ret false |
| 1695 | end |
| 1696 | if ne get pab 2 98 |
| 1697 | ret false |
| 1698 | end |
| 1699 | if ne get pab 3 58 |
| 1700 | ret false |
| 1701 | end |
| 1702 | f = ulong 0 |
| 1703 | v = ulong 0 |
| 1704 | digits = ulong 0 |
| 1705 | b = mul get gv 19 3 |
| 1706 | for i ulong sub n 3 |
| 1707 | j = add i 4 |
| 1708 | c = uchar 58 |
| 1709 | if lt j n |
| 1710 | c = get pab j |
| 1711 | end |
| 1712 | if eq c 58 |
| 1713 | if or eq digits 0 ge f 3 |
| 1714 | ret false |
| 1715 | end |
| 1716 | put pdecl add b f v |
| 1717 | f = add f 1 |
| 1718 | v = ulong 0 |
| 1719 | digits = ulong 0 |
| 1720 | else |
| 1721 | if or lt c 48 gt c 57 |
| 1722 | ret false |
| 1723 | end |
| 1724 | if gt v 3602879701896396 |
| 1725 | ret false |
| 1726 | end |
| 1727 | v = add mul v 10 ulong sub c 48 |
| 1728 | if gt v 36028797018963967 |
| 1729 | ret false |
| 1730 | end |
| 1731 | digits = add digits 1 |
| 1732 | end |
| 1733 | end |
| 1734 | if ne f 3 |
| 1735 | ret false |
| 1736 | end |
| 1737 | if gt get pdecl b 5 |
| 1738 | ret false |
| 1739 | end |
| 1740 | if gt add get pdecl add b 1 get pdecl add b 2 36028797018963967 |
| 1741 | ret false |
| 1742 | end |
| 1743 | inc 19 |
| 1744 | ret true |
| 1745 | end |
| 1746 | fn ptok k ulong v ulong to ulong |
| 1747 | if ne sx and v 72057594037927935 56 v |
| 1748 | ret 0 |
| 1749 | end |
| 1750 | ret or shl k 56 and v 72057594037927935 |
| 1751 | end |
| 1752 | fn pget i ulong to ulong |
| 1753 | if ge i 31 |
| 1754 | ret 0 |
| 1755 | end |
| 1756 | ret get pc i |
| 1757 | end |
| 1758 | fn pval v ulong to ulong |
| 1759 | ret sx and v 72057594037927935 56 |
| 1760 | end |
| 1761 | fn pconst i ulong to ulong |
| 1762 | if eq i 255 |
| 1763 | ret ptok 1 0 |
| 1764 | end |
| 1765 | ret pget i |
| 1766 | end |
| 1767 | fn padd a ulong b ulong subtr bool to ulong |
| 1768 | ak = shr a 56 |
| 1769 | bk = shr b 56 |
| 1770 | if or eq ak 0 eq bk 0 |
| 1771 | ret 0 |
| 1772 | end |
| 1773 | if subtr |
| 1774 | if ne bk 1 |
| 1775 | ret 0 |
| 1776 | end |
| 1777 | ret ptok ak sub pval a pval b |
| 1778 | end |
| 1779 | if eq bk 1 |
| 1780 | ret ptok ak add pval a pval b |
| 1781 | end |
| 1782 | if eq ak 1 |
| 1783 | ret ptok bk add pval a pval b |
| 1784 | end |
| 1785 | ret 0 |
| 1786 | end |
| 1787 | fn palloc w ulong to ulong |
| 1788 | n = get gv 18 |
| 1789 | if gt add n 128 len pp |
| 1790 | unh w 15 |
| 1791 | ret 0 |
| 1792 | end |
| 1793 | put gv 18 add n 128 |
| 1794 | for i ulong 128 |
| 1795 | put pp add n i get pc i |
| 1796 | end |
| 1797 | ret add n 1 |
| 1798 | end |
| 1799 | fn pmerge ptr ulong count ulong to bool |
| 1800 | if eq ptr 0 |
| 1801 | ret false |
| 1802 | end |
| 1803 | b = sub ptr 1 |
| 1804 | changed = false |
| 1805 | for i ulong count |
| 1806 | v = get pp add b i |
| 1807 | n = ulong 0 |
| 1808 | if or ge i 96 eq i 31 |
| 1809 | n = and v get pc i |
| 1810 | else |
| 1811 | if eq v get pc i |
| 1812 | n = v |
| 1813 | end |
| 1814 | end |
| 1815 | if ne v n |
| 1816 | put pp add b i n |
| 1817 | changed = true |
| 1818 | end |
| 1819 | end |
| 1820 | ret changed |
| 1821 | end |
| 1822 | fn pjoin w ulong fresh bool to void |
| 1823 | if fresh |
| 1824 | put ps w palloc w |
| 1825 | ret |
| 1826 | end |
| 1827 | if pmerge get ps w 128 |
| 1828 | push w |
| 1829 | end |
| 1830 | end |
| 1831 | fn pload w ulong to void |
| 1832 | b = get ps w |
| 1833 | for i ulong 128 |
| 1834 | v = ulong 0 |
| 1835 | if ne b 0 |
| 1836 | v = get pp add sub b 1 i |
| 1837 | end |
| 1838 | put pc i v |
| 1839 | end |
| 1840 | end |
| 1841 | fn pexit f ulong to bool |
| 1842 | if eq get pe f 0 |
| 1843 | put pe f palloc f |
| 1844 | ret ne get pe f 0 |
| 1845 | end |
| 1846 | ret pmerge get pe f 128 |
| 1847 | end |
| 1848 | fn pcall to void |
| 1849 | put pc 30 0 |
| 1850 | for i ulong 64 |
| 1851 | put pc add i 32 0 |
| 1852 | end |
| 1853 | end |
| 1854 | fn preturn w ulong t ulong to void |
| 1855 | s = get ps w |
| 1856 | e = get pe t |
| 1857 | if ne e 0 |
| 1858 | put pc 31 get pp add sub e 1 31 |
| 1859 | else |
| 1860 | put pc 31 0 |
| 1861 | end |
| 1862 | for i ulong 31 |
| 1863 | v = ulong 0 |
| 1864 | if ne e 0 |
| 1865 | v = get pp add sub e 1 i |
| 1866 | end |
| 1867 | put pc i v |
| 1868 | end |
| 1869 | for i ulong 64 |
| 1870 | v = ulong 0 |
| 1871 | if ne s 0 |
| 1872 | v = get pp add add sub s 1 i 32 |
| 1873 | end |
| 1874 | put pc add i 32 v |
| 1875 | end |
| 1876 | for i ulong 32 |
| 1877 | v = ulong 0 |
| 1878 | if ne e 0 |
| 1879 | v = get pp add add sub e 1 i 96 |
| 1880 | end |
| 1881 | put pc add i 96 v |
| 1882 | end |
| 1883 | end |
| 1884 | fn pshift to void |
| 1885 | a = get dc dspa |
| 1886 | k = get dc dspo |
| 1887 | if or eq k 3 ne rem a 8 0 |
| 1888 | a = ulong 512 |
| 1889 | end |
| 1890 | q = div a 8 |
| 1891 | if eq k 1 |
| 1892 | for i ulong 64 |
| 1893 | v = ulong 0 |
| 1894 | if lt add i q 64 |
| 1895 | v = get pc add add i q 32 |
| 1896 | end |
| 1897 | put pc add i 32 v |
| 1898 | end |
| 1899 | else |
| 1900 | for i ulong 64 |
| 1901 | j = sub 63 i |
| 1902 | v = ulong 0 |
| 1903 | if ge j q |
| 1904 | v = get pc add sub j q 32 |
| 1905 | end |
| 1906 | put pc add j 32 v |
| 1907 | end |
| 1908 | end |
| 1909 | end |
| 1910 | note Register-offset addressing: UXTW/UXTX/SXTW/SXTX; S means scale by element size. |
| 1911 | fn pindex x ulong to ulong |
| 1912 | i = get dc dmi |
| 1913 | if eq i 255 |
| 1914 | ret ptok 1 0 |
| 1915 | end |
| 1916 | v = pget i |
| 1917 | if ne shr v 56 1 |
| 1918 | ret 0 |
| 1919 | end |
| 1920 | v = pval v |
| 1921 | opt = fld x 13 3 |
| 1922 | if eq opt 2 |
| 1923 | v = and v 4294967295 |
| 1924 | end |
| 1925 | if eq opt 6 |
| 1926 | v = sx and v 4294967295 32 |
| 1927 | end |
| 1928 | if ne fld x 12 1 0 |
| 1929 | v = mul v get dc dms |
| 1930 | end |
| 1931 | ret ptok 1 v |
| 1932 | end |
| 1933 | fn paddr x ulong to ulong |
| 1934 | b = pget get dc dmb |
| 1935 | v = padd b pindex x false |
| 1936 | ret padd v ptok 1 get dc dmo false |
| 1937 | end |
| 1938 | fn pinrange b ulong k ulong off ulong size ulong to bool |
| 1939 | if ne get pdecl b sub k 2 |
| 1940 | ret false |
| 1941 | end |
| 1942 | lo = get pdecl add b 1 |
| 1943 | hi = add lo get pdecl add b 2 |
| 1944 | ret and ge off lo le add off size hi |
| 1945 | end |
| 1946 | fn ppublic x ulong to ulong |
| 1947 | if or eq get gv 19 0 ne get dc dmk 1 |
| 1948 | ret 0 |
| 1949 | end |
| 1950 | v = paddr x |
| 1951 | k = shr v 56 |
| 1952 | if or lt k 2 gt k 7 |
| 1953 | ret 0 |
| 1954 | end |
| 1955 | off = pval v |
| 1956 | if ne shr off 63 0 |
| 1957 | ret 0 |
| 1958 | end |
| 1959 | size = get dc dms |
| 1960 | if ne get dc dmt2 255 |
| 1961 | size = mul size 2 |
| 1962 | end |
| 1963 | for i ulong get gv 19 |
| 1964 | if and eq tnt get gv 20 i 0 pinrange mul i 3 k off size |
| 1965 | ret v |
| 1966 | end |
| 1967 | end |
| 1968 | ret 0 |
| 1969 | end |
| 1970 | note Exact immediate constants plus param-base +/- constant. Other results lose provenance. |
| 1971 | fn pim x ulong to ulong |
| 1972 | k = fld x 29 2 |
| 1973 | shift = mul fld x 21 2 16 |
| 1974 | v = shl fld x 5 16 shift |
| 1975 | if eq k 0 |
| 1976 | v = not v |
| 1977 | end |
| 1978 | if eq k 3 |
| 1979 | a = pget and x 31 |
| 1980 | if ne shr a 56 1 |
| 1981 | ret 0 |
| 1982 | end |
| 1983 | v = or and pval a not shl ulong 65535 shift v |
| 1984 | end |
| 1985 | if eq fld x 31 1 0 |
| 1986 | v = and v 4294967295 |
| 1987 | end |
| 1988 | ret ptok 1 v |
| 1989 | end |
| 1990 | fn pregcalc x ulong to ulong |
| 1991 | a = pconst get dc ds1 |
| 1992 | b = pconst get dc ds2 |
| 1993 | if ne shr b 56 1 |
| 1994 | ret 0 |
| 1995 | end |
| 1996 | v = pval b |
| 1997 | if eq and x 522190848 186646528 |
| 1998 | opt = fld x 13 3 |
| 1999 | if lt opt 3 |
| 2000 | v = and v sub shl ulong 1 shl ulong 8 opt 1 |
| 2001 | end |
| 2002 | if ge opt 4 |
| 2003 | bits = shl ulong 8 sub opt 4 |
| 2004 | if lt bits 64 |
| 2005 | v = sx and v sub shl ulong 1 bits 1 bits |
| 2006 | end |
| 2007 | end |
| 2008 | v = shl v fld x 10 3 |
| 2009 | else |
| 2010 | sh = fld x 10 6 |
| 2011 | ty = fld x 22 2 |
| 2012 | if eq ty 0 |
| 2013 | v = shl v sh |
| 2014 | end |
| 2015 | if eq ty 1 |
| 2016 | v = shr v sh |
| 2017 | end |
| 2018 | if eq ty 2 |
| 2019 | if ne sh 0 |
| 2020 | v = or shr v sh shl sub 0 shr v 63 sub 64 sh |
| 2021 | end |
| 2022 | end |
| 2023 | end |
| 2024 | ret padd a ptok 1 v eq fld x 30 1 1 |
| 2025 | end |
| 2026 | fn palu x ulong to ulong |
| 2027 | m = and x 528482304 |
| 2028 | if eq m 310378496 |
| 2029 | ret pim x |
| 2030 | end |
| 2031 | if eq m 285212672 |
| 2032 | a = pconst get dc ds1 |
| 2033 | b = shl fld x 10 12 mul fld x 22 1 12 |
| 2034 | ret padd a ptok 1 b eq fld x 30 1 1 |
| 2035 | end |
| 2036 | if eq and x 520093696 184549376 |
| 2037 | ret pregcalc x |
| 2038 | end |
| 2039 | note MOV is ORR Xd,XZR,Xm with no shift; full-width copies preserve base identity. |
| 2040 | if eq and x 4292935648 2852127712 |
| 2041 | ret pconst fld x 16 5 |
| 2042 | end |
| 2043 | ret 0 |
| 2044 | end |
| 2045 | fn pslotone off ulong size ulong rt ulong to void |
| 2046 | idx = div off 8 |
| 2047 | if eq get dc dmk 1 |
| 2048 | v = ulong 0 |
| 2049 | if and and eq rem off 8 0 eq size 8 lt idx 64 |
| 2050 | v = get pc add idx 32 |
| 2051 | end |
| 2052 | if lt rt 31 |
| 2053 | put pc rt v |
| 2054 | end |
| 2055 | ret |
| 2056 | end |
| 2057 | if and and eq rem off 8 0 eq size 8 lt idx 64 |
| 2058 | put pc add idx 32 pconst rt |
| 2059 | ret |
| 2060 | end |
| 2061 | last = div add off sub size 1 8 |
| 2062 | while le idx last bound 8 |
| 2063 | if lt idx 64 |
| 2064 | put pc add idx 32 0 |
| 2065 | end |
| 2066 | idx = add idx 1 |
| 2067 | end |
| 2068 | end |
| 2069 | fn pslot to void |
| 2070 | pslotone get dc dmo get dc dms get dc dmt |
| 2071 | if ne get dc dmt2 255 |
| 2072 | pslotone add get dc dmo get dc dms get dc dms get dc dmt2 |
| 2073 | end |
| 2074 | end |
| 2075 | fn pspmem to bool |
| 2076 | if ne get dc dmb 31 |
| 2077 | ret false |
| 2078 | end |
| 2079 | if ne get dc dwb 0 |
| 2080 | ret false |
| 2081 | end |
| 2082 | ret eq get dc dmi 255 |
| 2083 | end |
| 2084 | fn pstep w ulong to void |
| 2085 | x = ulong get wd w |
| 2086 | mk = get dc dmk |
| 2087 | if ne mk 0 |
| 2088 | if pspmem |
| 2089 | pslot |
| 2090 | ret |
| 2091 | end |
| 2092 | if or eq mk 1 eq mk 3 |
| 2093 | if lt get dc dmt 31 |
| 2094 | put pc get dc dmt 0 |
| 2095 | end |
| 2096 | if lt get dc dmt2 31 |
| 2097 | put pc get dc dmt2 0 |
| 2098 | end |
| 2099 | end |
| 2100 | if and ne get dc dwb 0 lt get dc dmb 31 |
| 2101 | put pc get dc dmb 0 |
| 2102 | end |
| 2103 | ret |
| 2104 | end |
| 2105 | d = get dc ddst |
| 2106 | if lt d 31 |
| 2107 | v = palu x |
| 2108 | if and eq fld x 31 1 0 ne shr v 56 1 |
| 2109 | v = ulong 0 |
| 2110 | end |
| 2111 | if and eq fld x 31 1 0 ne v 0 |
| 2112 | v = ptok 1 and pval v 4294967295 |
| 2113 | end |
| 2114 | put pc d v |
| 2115 | end |
| 2116 | end |
| 2117 | |
| 2118 | note E12: only a proven-zero CBNZ conversion check discharges a DATA trap edge. |
| 2119 | note pc[96+r] is known-zero bits of Xr. Meet at joins is intersection, unlike provenance tokens. |
| 2120 | fn ezsay id ulong to void |
| 2121 | s = ulong 0 |
| 2122 | k = ulong 0 |
| 2123 | for i ulong len e12 |
| 2124 | if eq get e12 i 10 |
| 2125 | if eq k id |
| 2126 | for j ulong sub i s |
| 2127 | ob1 get e12 add s j |
| 2128 | end |
| 2129 | ret |
| 2130 | end |
| 2131 | k = add k 1 |
| 2132 | s = add i 1 |
| 2133 | end |
| 2134 | end |
| 2135 | end |
| 2136 | fn zget r ulong to ulong |
| 2137 | if ge r 31 |
| 2138 | ret not ulong 0 |
| 2139 | end |
| 2140 | ret get pc add r 96 |
| 2141 | end |
| 2142 | fn zimm x ulong to ulong |
| 2143 | k = fld x 29 2 |
| 2144 | sh = mul fld x 21 2 16 |
| 2145 | v = shl fld x 5 16 sh |
| 2146 | if eq k 0 |
| 2147 | ret v |
| 2148 | end |
| 2149 | if eq k 3 |
| 2150 | old = zget and x 31 |
| 2151 | ret or and old not shl ulong 65535 sh and not v shl ulong 65535 sh |
| 2152 | end |
| 2153 | ret not v |
| 2154 | end |
| 2155 | fn zalu x ulong to ulong |
| 2156 | if and eq and x 528482304 301989888 or eq fld x 29 2 0 eq fld x 29 2 3 |
| 2157 | ret or zget get dc ds1 not zmask x |
| 2158 | end |
| 2159 | if eq and x 528482304 310378496 |
| 2160 | ret zimm x |
| 2161 | end |
| 2162 | if eq and x 520093696 167772160 |
| 2163 | a = zget get dc ds1 |
| 2164 | b = zget get dc ds2 |
| 2165 | if ne fld x 21 1 0 |
| 2166 | ret 0 |
| 2167 | end |
| 2168 | if ne fld x 10 6 0 |
| 2169 | ret 0 |
| 2170 | end |
| 2171 | op = fld x 29 2 |
| 2172 | if or eq op 0 eq op 3 |
| 2173 | ret or a b |
| 2174 | end |
| 2175 | if eq op 1 |
| 2176 | ret and a b |
| 2177 | end |
| 2178 | ret 0 |
| 2179 | end |
| 2180 | if and eq and x 528482304 318767104 eq fld x 29 2 2 |
| 2181 | r = fld x 16 6 |
| 2182 | s = fld x 10 6 |
| 2183 | z = zget get dc ds1 |
| 2184 | bits = ulong 64 |
| 2185 | if eq fld x 31 1 0 |
| 2186 | bits = ulong 32 |
| 2187 | end |
| 2188 | if eq r 0 |
| 2189 | if lt s 63 |
| 2190 | ret or z not sub shl ulong 1 add s 1 1 |
| 2191 | end |
| 2192 | ret z |
| 2193 | end |
| 2194 | if eq s sub bits 1 |
| 2195 | ret or shr z r not shr not ulong 0 r |
| 2196 | end |
| 2197 | end |
| 2198 | ret 0 |
| 2199 | end |
| 2200 | fn zstep w ulong to void |
| 2201 | x = ulong get wd w |
| 2202 | if ne get dc dmk 0 |
| 2203 | if or eq get dc dmk 1 eq get dc dmk 3 |
| 2204 | for i ulong 2 |
| 2205 | r = get dc dmt |
| 2206 | if eq i 1 |
| 2207 | r = get dc dmt2 |
| 2208 | end |
| 2209 | if lt r 31 |
| 2210 | z = ulong 0 |
| 2211 | put pc add r 96 z |
| 2212 | put pc 31 sbit get pc 31 r 0 |
| 2213 | end |
| 2214 | end |
| 2215 | end |
| 2216 | ret |
| 2217 | end |
| 2218 | d = get dc ddst |
| 2219 | if lt d 31 |
| 2220 | proof = zproof x |
| 2221 | put pc 31 sbit get pc 31 d proof |
| 2222 | z = zalu x |
| 2223 | if eq fld x 31 1 0 |
| 2224 | z = or z 18446744069414584320 |
| 2225 | end |
| 2226 | put pc add d 96 z |
| 2227 | end |
| 2228 | end |
| 2229 | fn ztrap w ulong to bool |
| 2230 | x = ulong get wd w |
| 2231 | if ne and x 4278190080 3036676096 |
| 2232 | ret false |
| 2233 | end |
| 2234 | if eq tnt get pc 31 and x 31 0 |
| 2235 | ret false |
| 2236 | end |
| 2237 | ret eq zget and x 31 not ulong 0 |
| 2238 | end |
| 2239 | note Arm DecodeBitMasks (logical immediate), unallocated masks already rejected by bmok. |
| 2240 | fn zmask x ulong to ulong |
| 2241 | v = or shl fld x 22 1 6 and not fld x 10 6 63 |
| 2242 | l = ulong 6 |
| 2243 | while eq and shr v l 1 0 bound 8 |
| 2244 | l = sub l 1 |
| 2245 | end |
| 2246 | width = shl ulong 1 l |
| 2247 | levels = sub width 1 |
| 2248 | s = and fld x 10 6 levels |
| 2249 | r = and fld x 16 6 levels |
| 2250 | base = sub shl ulong 1 add s 1 1 |
| 2251 | if ne r 0 |
| 2252 | base = or shr base r shl base sub width r |
| 2253 | end |
| 2254 | if lt width 64 |
| 2255 | base = and base sub shl ulong 1 width 1 |
| 2256 | end |
| 2257 | result = ulong 0 |
| 2258 | for i ulong div 64 width |
| 2259 | result = or result shl base mul i width |
| 2260 | end |
| 2261 | ret result |
| 2262 | end |
| 2263 | fn zproof x ulong to ulong |
| 2264 | m = and x 528482304 |
| 2265 | if and eq m 301989888 or eq fld x 29 2 0 eq fld x 29 2 3 |
| 2266 | ret 1 |
| 2267 | end |
| 2268 | if eq and x 520093696 167772160 |
| 2269 | op = fld x 29 2 |
| 2270 | if and eq fld x 21 1 0 or eq op 0 eq op 3 |
| 2271 | a = pconst get dc ds1 |
| 2272 | b = pconst get dc ds2 |
| 2273 | if or eq shr a 56 1 eq shr b 56 1 |
| 2274 | ret 1 |
| 2275 | end |
| 2276 | end |
| 2277 | if eq and x 4292935648 2852127712 |
| 2278 | ret tnt get pc 31 fld x 16 5 |
| 2279 | end |
| 2280 | end |
| 2281 | if eq m 318767104 |
| 2282 | ret tnt get pc 31 get dc ds1 |
| 2283 | end |
| 2284 | ret 0 |
| 2285 | end |
| 2286 | note Rotation decode citations, independent of all OM-2 compiler sources: |
| 2287 | note ARM DDI0487M.d C6.2.160 (p2201): EXTR sf|00|100111|N|0|Rm|imms|Rn|Rd, N=sf; ROR immediate Rn=Rm. |
| 2288 | note C6.2.349 (p2580): RORV sf|00|11010110|Rm|001011|Rn|Rd (DP2 opcode 11). |
| 2289 | note C6.2.295 (p2475): NEG is SUB shifted-register with Rn=31 (XZR), not SP. |
| 2290 | note dalu already covers these instruction classes; E12 zero/provenance transfer drops rotate knowledge. |
| 2291 | |
| 2292 | note E13 fallback: revoke ranges globally if any DATA/unclassified store may overlap. |
| 2293 | note Re-run the analysis after revocation so declassified-load dependencies cannot retain false PUBLIC. |
| 2294 | fn rvoutside decl ulong addr ulong size ulong to bool |
| 2295 | b = mul decl 3 |
| 2296 | if eq get pdecl add b 2 0 |
| 2297 | ret true |
| 2298 | end |
| 2299 | if ne shr addr 56 add get pdecl b 2 |
| 2300 | ret false |
| 2301 | end |
| 2302 | off = pval addr |
| 2303 | endoff = add off size |
| 2304 | lo = get pdecl add b 1 |
| 2305 | hi = add lo get pdecl add b 2 |
| 2306 | if ne shr off 63 0 |
| 2307 | if ne shr endoff 63 0 |
| 2308 | ret true |
| 2309 | end |
| 2310 | ret le endoff lo |
| 2311 | end |
| 2312 | ret or ge off hi le endoff lo |
| 2313 | end |
| 2314 | fn rvbad w ulong to bool |
| 2315 | if ne get uh w 0 |
| 2316 | ret true |
| 2317 | end |
| 2318 | if eq get dc dkind 10 |
| 2319 | ret true |
| 2320 | end |
| 2321 | if ne get dc dmk 2 |
| 2322 | ret false |
| 2323 | end |
| 2324 | if eq get dep w 0 |
| 2325 | ret true |
| 2326 | end |
| 2327 | r = get rm w |
| 2328 | v = or tnt r get dc dmt tnt r get dc dmt2 |
| 2329 | if ne get dc dmb 31 |
| 2330 | v = or v tnt r get dc dmb |
| 2331 | end |
| 2332 | v = or v tnt r get dc dmi |
| 2333 | ret ne v 0 |
| 2334 | end |
| 2335 | fn rvstore w ulong to void |
| 2336 | dec ulong get wd w w |
| 2337 | if not rvbad w |
| 2338 | ret |
| 2339 | end |
| 2340 | addr = ulong 0 |
| 2341 | size = ulong 0 |
| 2342 | if and eq get dc dmk 2 ne get dep w 0 |
| 2343 | note Proven current-frame SP spills cannot alias entry-parameter ranges (existing A1 invariant). |
| 2344 | if and eq get uh w 0 pspmem |
| 2345 | ret |
| 2346 | end |
| 2347 | pload w |
| 2348 | addr = paddr ulong get wd w |
| 2349 | size = get dc dms |
| 2350 | if ne get dc dmt2 255 |
| 2351 | size = mul size 2 |
| 2352 | end |
| 2353 | end |
| 2354 | for i ulong get gv 19 |
| 2355 | if not rvoutside i addr size |
| 2356 | bit = shl ulong 1 i |
| 2357 | put rv w or get rv w bit |
| 2358 | put gv 20 or get gv 20 bit |
| 2359 | end |
| 2360 | end |
| 2361 | end |
| 2362 | fn rvcollect to void |
| 2363 | n = get gv 0 |
| 2364 | for a ulong 5 |
| 2365 | for b ulong 500000 |
| 2366 | j = add mul a 500000 b |
| 2367 | if ge j n |
| 2368 | ret |
| 2369 | end |
| 2370 | rvstore j |
| 2371 | end |
| 2372 | end |
| 2373 | end |
| 2374 | fn rvclearword w ulong to void |
| 2375 | put dep w 0 |
| 2376 | put ex w 0 |
| 2377 | put exs w 0 |
| 2378 | put inq w 0 |
| 2379 | put ps w 0 |
| 2380 | put pe w 0 |
| 2381 | end |
| 2382 | fn rvreset to void |
| 2383 | put gv 1 0 |
| 2384 | put gv 18 0 |
| 2385 | put gv 16 0 |
| 2386 | for i ulong 128 |
| 2387 | put pc i 0 |
| 2388 | end |
| 2389 | n = get gv 0 |
| 2390 | for a ulong 5 |
| 2391 | for b ulong 500000 |
| 2392 | j = add mul a 500000 b |
| 2393 | if ge j n |
| 2394 | ret |
| 2395 | end |
| 2396 | rvclearword j |
| 2397 | end |
| 2398 | end |
| 2399 | end |
| 2400 | fn rvfix to void |
| 2401 | for pass ulong 33 |
| 2402 | fix |
| 2403 | if eq get gv 19 0 |
| 2404 | ret |
| 2405 | end |
| 2406 | before = get gv 20 |
| 2407 | rvcollect |
| 2408 | if eq before get gv 20 |
| 2409 | ret |
| 2410 | end |
| 2411 | rvreset |
| 2412 | seed |
| 2413 | end |
| 2414 | exit 92 |
| 2415 | end |
| 2416 | fn rvshow w ulong to void |
| 2417 | for i ulong get gv 19 |
| 2418 | if ne tnt get rv w i 0 |
| 2419 | for j ulong len revmsg |
| 2420 | ob1 get revmsg j |
| 2421 | end |
| 2422 | od w |
| 2423 | psay 2 |
| 2424 | od get pdecl mul i 3 |
| 2425 | psay 3 |
| 2426 | od get pdecl add mul i 3 1 |
| 2427 | psay 4 |
| 2428 | od get pdecl add mul i 3 2 |
| 2429 | onl |
| 2430 | end |
| 2431 | end |
| 2432 | end |