Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/evidence/AMD-KFD-LAUNCH/investigation/gate-2/launch-a64.om # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / evidence / AMD-KFD-LAUNCH / investigation / gate-2 / launch-a64.om` 1014 lines · 20136 bytes Raw Blame History 1 om2 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 note Concatenate common, elf, device, dispatch, main, then existing cli.om under om2. 4 note Fixed arrays below are Linux pathname or ABI records, not input-size limits. 5 global pathbuf uchar 4096 6 global chunk uchar 4096 7 global hdr uchar 88 8 global ids uchar 4 9 global one uchar 1 10 text newline "\n" 11 text failed "OMEGA error=" 12 text kfdpath "/dev/kfd" 13 fn checked r long to long 14 if lt r 0 15 emit failed 16 if eq r -`9223372036854775808` 17 exit 74 18 end 19 printnum ulong neg r 20 emit newline 21 exit 74 22 end 23 ret r 24 end 25 fn printnum v ulong to void 26 b = new uchar 20 0 27 p = ulong 20 28 while gt v 9 bound 20 29 p = sub p 1 30 put b p uchar add rem v 10 48 31 v = div v 10 32 end 33 p = sub p 1 34 put b p uchar add v 48 35 emit part b p sub 20 p 36 end 37 fn roundup n ulong a ulong to ulong 38 if gt n sub `9223372036854775807` sub a 1 39 exit 65 40 end 41 ret mul div add n sub a 1 a a 42 end 43 fn patharg i ulong to ulong 44 n = argread i pathbuf 0 len pathbuf 45 if lt n 1 46 exit 64 47 end 48 ret ulong n 49 end 50 fn argfile i ulong flags int to int 51 n = patharg i 52 ret int checked fopen pathbuf 0 n flags 384 53 end 54 fn filesize fd int to ulong 55 n = checked fseek fd 0 2 56 r = checked fseek fd 0 0 57 ret ulong n 58 end 59 fn zerohdr to void 60 for i ulong 88 61 put hdr i 0 62 end 63 end 64 fn hput off ulong width ulong v ulong to void 65 for i ulong width 66 put hdr add off i uchar and shr v mul i 8 255 67 end 68 end 69 fn hget off ulong width ulong to ulong 70 v = ulong 0 71 for i ulong width 72 v = or v shl ulong get hdr add off i mul i 8 73 end 74 ret v 75 end 76 fn fword fd int off ulong width ulong to ulong 77 b = new uchar 8 0 78 r = pread fd b 0 width long off 79 if ne r long width 80 exit 65 81 end 82 v = ulong 0 83 for i ulong width 84 v = or v shl ulong get b i mul i 8 85 end 86 ret v 87 end 88 fn byteat fd int off ulong to uchar 89 r = pread fd one 0 1 long off 90 if ne r 1 91 exit 65 92 end 93 ret get one 0 94 end 95 fn filecopy fd int src ulong dst long off ulong n ulong to void 96 p = ulong 0 97 while lt p n bound `9223372036854775807` 98 k = sub n p 99 if gt k len chunk 100 k = len chunk 101 end 102 r = checked pread fd chunk 0 k long add src p 103 if eq r 0 104 exit 65 105 end 106 r = checked mapwrite dst add off p chunk 0 ulong r 107 p = add p ulong r 108 end 109 end 110 fn zeromap dst long off ulong n ulong to void 111 for i ulong len chunk bound 4096 112 put chunk i 0 113 end 114 p = ulong 0 115 while lt p n bound `9223372036854775807` 116 k = sub n p 117 if gt k len chunk 118 k = len chunk 119 end 120 r = checked mapwrite dst add off p chunk 0 k 121 p = add p k 122 end 123 end 124 fn savefile fd int src long n ulong to void 125 p = ulong 0 126 while lt p n bound `9223372036854775807` 127 k = sub n p 128 if gt k len chunk 129 k = len chunk 130 end 131 r = checked mapread src p chunk 0 k 132 q = ulong 0 133 while lt q k bound `9223372036854775807` 134 r = checked write fd chunk q sub k q 135 if eq r 0 136 exit 74 137 end 138 q = add q ulong r 139 end 140 p = add p k 141 end 142 end 143 fn span off ulong n ulong total ulong to void 144 if gt off total 145 exit 65 146 end 147 if gt n sub total off 148 exit 65 149 end 150 end 151 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 152 note ELF64 HSA v5 gfx942 images emitted by backend/amd/gfx942/hsaco.om. 153 note el: fd,size,phoff,phnum,shoff,shnum,kdVA,imageBytes,kernarg,group,private,kdFile. 154 global el ulong 12 155 fn ew off ulong width ulong to ulong 156 ret fword int get el 0 off width 157 end 158 fn ph i ulong to ulong 159 ret add get el 2 mul i 56 160 end 161 fn sh i ulong to ulong 162 ret add get el 4 mul i 64 163 end 164 fn vaoff va ulong n ulong to ulong 165 for i ulong get el 3 bound 65535 166 p = ph i 167 if eq ew p 4 1 168 base = ew add p 16 8 169 if ge va base 170 d = sub va base 171 sz = ew add p 32 8 172 if le d sz 173 if le n sub sz d 174 ret add ew add p 8 8 d 175 end 176 end 177 end 178 end 179 end 180 exit 65 181 end 182 fn symmatch off ulong size ulong namelen ulong to bool 183 if lt size add namelen 4 184 ret false 185 end 186 for i ulong namelen bound 4096 187 if ne byteat int get el 0 add off i get pathbuf i 188 ret false 189 end 190 end 191 if ne byteat int get el 0 add off namelen 46 192 ret false 193 end 194 if ne byteat int get el 0 add add off namelen 1 107 195 ret false 196 end 197 if ne byteat int get el 0 add add off namelen 2 100 198 ret false 199 end 200 ret eq byteat int get el 0 add add off namelen 3 0 201 end 202 fn acceptsym s ulong to void 203 if or ne ew add s 4 1 17 ne ew add s 16 8 64 204 exit 65 205 end 206 v = ew add s 8 8 207 if ne get el 6 0 208 if ne get el 6 v 209 exit 65 210 end 211 end 212 if ne rem v 64 0 213 exit 65 214 end 215 put el 6 v 216 end 217 fn findsym sec ulong namelen ulong to void 218 linkidx = ew add sec 40 4 219 if ge linkidx get el 5 220 exit 65 221 end 222 strsec = sh linkidx 223 if ne ew add strsec 4 4 3 224 exit 65 225 end 226 strbase = ew add strsec 24 8 227 strsize = ew add strsec 32 8 228 span strbase strsize get el 1 229 base = ew add sec 24 8 230 size = ew add sec 32 8 231 span base size get el 1 232 if or ne ew add sec 56 8 24 ne rem size 24 0 233 exit 65 234 end 235 for i ulong div size 24 bound `9223372036854775807` 236 s = add base mul i 24 237 noff = ew s 4 238 if ge noff strsize 239 exit 65 240 end 241 if symmatch add strbase noff sub strsize noff namelen 242 acceptsym s 243 end 244 end 245 end 246 fn segment i ulong to void 247 p = ph i 248 if eq ew p 4 1 249 base = ew add p 16 8 250 sz = ew add p 32 8 251 memsz = ew add p 40 8 252 span ew add p 8 8 sz get el 1 253 if gt sz memsz 254 exit 65 255 end 256 span base memsz `9223372036854775807` 257 last = add base memsz 258 if gt last get el 7 259 put el 7 last 260 end 261 for j ulong i bound 65535 262 q = ph j 263 if eq ew q 4 1 264 qb = ew add q 16 8 265 qe = add qb ew add q 40 8 266 if and lt base qe lt qb last 267 exit 65 268 end 269 end 270 end 271 end 272 end 273 fn parseelf objarg ulong namearg ulong to void 274 fd = argfile objarg 0 275 put el 0 ulong fd 276 put el 1 filesize fd 277 span 0 64 get el 1 278 if or ne ew 0 4 `1179403647` ne ew 4 4 `1073807618` 279 exit 65 280 end 281 if or ne ew 8 1 3 ne ew 16 4 `14680067` 282 exit 65 283 end 284 if or ne ew 20 4 1 ne ew 52 2 64 285 exit 65 286 end 287 if or ne ew 54 2 56 ne ew 58 2 64 288 exit 65 289 end 290 note gfx942 machine selection; XNACK/SRAMECC any or enabled are accepted. 291 if ne and ew 48 4 255 76 292 exit 65 293 end 294 put el 2 ew 32 8 295 put el 3 ew 56 2 296 put el 4 ew 40 8 297 put el 5 ew 60 2 298 span get el 2 mul get el 3 56 get el 1 299 span get el 4 mul get el 5 64 get el 1 300 for i ulong get el 3 bound 65535 301 segment i 302 end 303 if eq get el 7 0 304 exit 65 305 end 306 namelen = patharg namearg 307 for i ulong get el 5 bound 65535 308 s = sh i 309 t = ew add s 4 4 310 if or eq t 4 eq t 9 311 if ne ew add s 32 8 0 312 exit 65 313 end 314 end 315 if or eq t 2 eq t 11 316 findsym s namelen 317 end 318 end 319 if eq get el 6 0 320 exit 65 321 end 322 d = vaoff get el 6 64 323 put el 11 d 324 put el 8 ew add d 8 4 325 put el 9 ew d 4 326 put el 10 ew add d 4 4 327 note This writer declares no private segment or hidden ABI arguments. 328 if or ne get el 10 0 gt get el 9 65536 329 exit 65 330 end 331 if ne and ew add d 56 2 1024 0 332 exit 65 333 end 334 entry = bitcast long ew add d 16 8 335 if lt entry 0 336 exit 65 337 end 338 v = add get el 6 ulong entry 339 q = vaoff v 4 340 end 341 fn loadelf dst long to void 342 for i ulong get el 3 bound 65535 343 p = ph i 344 if eq ew p 4 1 345 filecopy int get el 0 ew add p 8 8 dst ew add p 16 8 ew add p 32 8 346 zeromap dst add ew add p 16 8 ew add p 32 8 sub ew add p 40 8 ew add p 32 8 347 end 348 end 349 end 350 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 351 note dev: kfd,render,gpu,simds,simdpercu,arrays,arraysperengine,xcc,ctxperxcc,ctl,debug. 352 global dev ulong 11 353 global dirbuf uchar 4096 354 global nodepath uchar 4096 355 global noden ulong 1 356 text nodes "/sys/class/kfd/kfd/topology/nodes/" 357 text props "/properties" 358 text gpufile "/gpu_id" 359 text render "/dev/dri/renderD" 360 text gfxkey "gfx_target_version" 361 text drmkey "drm_render_minor" 362 text simdkey "simd_count" 363 text cukey "simd_per_cu" 364 text arrkey "array_count" 365 text engkey "simd_arrays_per_engine" 366 text xcckey "num_xcc" 367 text absent "OMEGA device=absent errno=2\n" 368 fn addpath b view uchar * p ulong to ulong 369 span p len b len pathbuf 370 for i ulong len b bound 4096 371 put pathbuf add p i get b i 372 end 373 ret add p len b 374 end 375 fn nodefile suffix view uchar * to int 376 n = get noden 0 377 for i ulong n bound 4096 378 put pathbuf i get nodepath i 379 end 380 n = addpath suffix n 381 ret int checked fopen pathbuf 0 n 0 0 382 end 383 fn propvalue fd int key view uchar * to ulong 384 r = checked fseek fd 0 0 385 idx = ulong 0 386 match = true 387 value = ulong 0 388 number = false 389 while true bound `9223372036854775807` 390 r = read fd one 0 1 391 if eq r 0 392 exit 66 393 end 394 r = checked r 395 c = get one 0 396 if eq c 10 397 if and match number 398 ret value 399 end 400 idx = ulong 0 401 match = true 402 number = false 403 value = ulong 0 404 continue 405 end 406 if number 407 if match 408 if or lt c 48 gt c 57 409 exit 66 410 end 411 if gt value div sub ulong `18446744073709551615` ulong sub c 48 10 412 exit 66 413 end 414 value = add mul value 10 ulong sub c 48 415 end 416 else 417 if eq c 32 418 if ne idx len key 419 match = false 420 end 421 number = true 422 else 423 if lt idx len key 424 if ne c get key idx 425 match = false 426 end 427 else 428 match = false 429 end 430 idx = add idx 1 431 end 432 end 433 end 434 ret 0 435 end 436 fn nodecheck to bool 437 fd = nodefile props 438 gfx = propvalue fd gfxkey 439 if ne gfx 90402 440 r = checked fclose fd 441 ret false 442 end 443 put dev 1 propvalue fd drmkey 444 put dev 3 propvalue fd simdkey 445 put dev 4 propvalue fd cukey 446 put dev 5 propvalue fd arrkey 447 put dev 6 propvalue fd engkey 448 put dev 7 propvalue fd xcckey 449 r = checked fclose fd 450 fd = nodefile gpufile 451 v = ulong 0 452 while true bound `9223372036854775807` 453 r = checked read fd one 0 1 454 if eq r 0 455 break 456 end 457 c = get one 0 458 if eq c 10 459 break 460 end 461 if or lt c 48 gt c 57 462 exit 66 463 end 464 if gt v `429496729` 465 exit 66 466 end 467 v = add mul v 10 ulong sub c 48 468 end 469 if or eq v 0 gt v `4294967295` 470 exit 66 471 end 472 put dev 2 v 473 r = checked fclose fd 474 ret true 475 end 476 fn topology to void 477 dfd = int checked fopen nodes 0 len nodes 65536 0 478 found = false 479 while not found bound `9223372036854775807` 480 r = checked getdnts dfd dirbuf 0 len dirbuf 481 if eq r 0 482 exit 66 483 end 484 p = ulong 0 485 while lt p ulong r bound 4096 486 span p 20 ulong r 487 sz = add ulong get dirbuf add p 16 shl ulong get dirbuf add p 17 8 488 if lt sz 20 489 exit 66 490 end 491 span p sz ulong r 492 c = get dirbuf add p 19 493 if and ge c 48 le c 57 494 n = len nodes 495 for i ulong n bound 4096 496 put nodepath i get nodes i 497 end 498 j = add p 19 499 while true bound 4096 500 if ge j add p sz 501 exit 66 502 end 503 if eq get dirbuf j 0 504 break 505 end 506 if ge n len nodepath 507 exit 66 508 end 509 put nodepath n get dirbuf j 510 n = add n 1 511 j = add j 1 512 end 513 put noden 0 n 514 if nodecheck 515 found = true 516 break 517 end 518 end 519 p = add p sz 520 end 521 end 522 r = checked fclose dfd 523 n = addpath render 0 524 minor = get dev 1 525 if gt minor `4294967295` 526 exit 66 527 end 528 b = new uchar 10 0 529 p = ulong 10 530 while gt minor 9 bound 10 531 p = sub p 1 532 put b p uchar add rem minor 10 48 533 minor = div minor 10 534 end 535 p = sub p 1 536 put b p uchar add minor 48 537 n = addpath part b p sub 10 p n 538 put dev 1 ulong checked fopen pathbuf 0 n 2 0 539 end 540 fn connectkfd to void 541 fd = fopen kfdpath 0 len kfdpath 2 0 542 if eq fd -2 543 emit absent 544 exit 77 545 end 546 put dev 0 ulong checked fd 547 zerohdr 548 r = checked kfdctl int fd `2148027137` hdr 0 8 549 if or ne hget 0 4 1 lt hget 4 4 14 550 exit 67 551 end 552 topology 553 zerohdr 554 hput 0 4 get dev 1 555 hput 4 4 get dev 2 556 r = checked kfdctl int get dev 0 `1074285333` hdr 0 8 557 for i ulong 4 558 put ids i uchar and shr get dev 2 mul i 8 255 559 end 560 end 561 fn ctxsizes to void 562 if or eq get dev 4 0 eq get dev 7 0 563 exit 66 564 end 565 if eq get dev 6 0 566 exit 66 567 end 568 cu = div div get dev 3 get dev 4 get dev 7 569 if eq cu 0 570 exit 66 571 end 572 waves = mul cu 40 573 maxwaves = mul div div get dev 5 get dev 6 get dev 6 512 574 if lt maxwaves waves 575 waves = maxwaves 576 end 577 if eq waves 0 578 exit 66 579 end 580 ctl = roundup add 40 add mul waves 8 8 4096 581 wg = roundup mul cu add add ulong 0x80000 0x4000 add ulong 0x10000 0x1000 4096 582 put dev 8 add ctl wg 583 put dev 9 ctl 584 put dev 10 roundup mul waves 32 64 585 if gt get dev 8 `4294967295` 586 exit 66 587 end 588 end 589 fn mapgpu kh ulong to void 590 zerohdr 591 hput 0 8 kh 592 hput 16 4 1 593 r = checked kfdctl int get dev 0 `3222817560` hdr 0 24 ids 0 4 594 if ne hget 20 4 1 595 exit 68 596 end 597 end 598 note Allocation record on the caller's table: CPU handle, KFD handle, byte size (24 bytes). 599 fn gpumem n ulong flags ulong table long rec ulong to long 600 sz = roundup n 4096 601 h = checked kfdres sz 602 zerohdr 603 hput 8 8 sz 604 hput 32 4 get dev 2 605 hput 36 4 flags 606 r = checked kfdctl int get dev 0 `3223866134` hdr 0 40 h 607 kh = hget 16 8 608 moff = hget 24 8 609 r = checked mapset table rec 8 ulong h 610 r = checked mapset table add rec 8 8 kh 611 r = checked mapset table add rec 16 8 sz 612 mapgpu kh 613 r = checked mapbind h int get dev 1 moff 3 614 ret h 615 end 616 fn gpufree table long rec ulong to void 617 kh = mapget table add rec 8 8 618 zerohdr 619 hput 0 8 kh 620 hput 16 4 1 621 r = checked kfdctl int get dev 0 `3222817561` hdr 0 24 ids 0 4 622 if ne hget 20 4 1 623 exit 68 624 end 625 r = checked mapdrop long mapget table rec 8 626 zerohdr 627 hput 0 8 kh 628 r = checked kfdctl int get dev 0 `1074285335` hdr 0 8 629 end 630 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 631 note launch: table,ninputs,repeats,timeoutns,outbytes,groupsX,groupsY,queueid,bell,belloff. 632 global launch ulong 10 633 text timed "OMEGA dispatch_ns=" 634 text repeatlabel " packets=" 635 fn lh i ulong to long 636 ret long mapget long get launch 0 mul i 24 8 637 end 638 fn allocate i ulong n ulong flags ulong to long 639 ret gpumem n flags long get launch 0 mul i 24 640 end 641 fn queueinit to void 642 ctxsizes 643 r = allocate 3 1024 0xa6000002 644 r = allocate 4 4096 0xa6000002 645 r = allocate 5 4096 0xa6000002 646 n = roundup mul add get dev 8 get dev 10 get dev 7 4096 647 r = allocate 6 n 0xe4000002 648 r = allocate 7 4096 0xa6000002 649 zeromap lh 3 0 1024 650 zeromap lh 4 0 8 651 zeromap lh 5 0 8 652 zeromap lh 6 0 n 653 zeromap lh 7 0 64 654 note USER signal ABI: kind 1 at 0, value at 8, no interrupt event. 655 r = checked mapset lh 7 0 8 1 656 r = checked mapset lh 7 8 8 get launch 2 657 for i ulong get dev 7 bound `9223372036854775807` 658 p = mul i get dev 8 659 r = checked mapset lh 6 add p 16 4 mul sub get dev 7 i get dev 8 660 r = checked mapset lh 6 add p 20 4 mul get dev 10 get dev 7 661 end 662 for i ulong 16 663 r = checked mapset lh 3 mul i 64 4 1 664 end 665 zerohdr 666 hput 32 4 1024 667 hput 36 4 get dev 2 668 hput 40 4 2 669 hput 44 4 100 670 hput 48 4 7 671 hput 80 4 get dev 8 672 hput 84 4 get dev 9 673 note gfx942 AQL queues require no EOP allocation (ROCT queues.c). 674 r = checked kfdctl int get dev 0 `3227011842` hdr 0 88 lh 3 lh 4 lh 5 long 0 lh 6 675 put launch 7 hget 52 4 676 belloff = hget 24 8 677 put launch 9 rem belloff 8192 678 put launch 8 ulong checked kfdmap int get dev 0 sub belloff rem belloff 8192 8192 679 end 680 fn packet id ulong to void 681 slot = mul rem id 16 64 682 zerohdr 683 note First dword kept INVALID until every other field is published. 684 hput 0 2 1 685 hput 2 2 2 686 hput 4 2 64 687 hput 6 2 1 688 hput 8 2 1 689 hput 12 4 mul get launch 5 64 690 hput 16 4 get launch 6 691 hput 20 4 1 692 hput 24 4 get el 10 693 hput 28 4 get el 9 694 hput 32 8 add mapaddr lh 0 get el 6 695 hput 40 8 mapaddr lh 1 696 hput 56 8 mapaddr lh 7 697 r = checked mapset lh 3 slot 4 1 698 r = checked mapwrite lh 3 add slot 4 hdr 4 60 699 cpufence 700 note type KERNEL_DISPATCH=2, barrier=1, acquire/release SYSTEM=2, dimensions=2. 701 r = checked mapset lh 3 slot 4 0x00021502 702 cpufence 703 r = checked mapset lh 4 0 8 add id 1 704 cpufence 705 r = checked mapset long get launch 8 get launch 9 8 id 706 end 707 fn deadline start long to void 708 now = monons 709 if lt now start 710 exit 75 711 end 712 if gt ulong sub now start get launch 3 713 exit 75 714 end 715 end 716 fn dispatch to void 717 start = monons 718 if lt start 0 719 exit 74 720 end 721 for i ulong get launch 2 bound `9223372036854775807` 722 while ge sub i mapget lh 5 0 8 16 bound `9223372036854775807` 723 deadline start 724 cpurelax 725 end 726 packet i 727 end 728 while ne mapget lh 7 8 8 0 bound `9223372036854775807` 729 deadline start 730 cpurelax 731 end 732 cpufence 733 elapsed = sub monons start 734 emit timed 735 printnum ulong elapsed 736 emit repeatlabel 737 printnum get launch 2 738 emit newline 739 end 740 fn teardown to void 741 zerohdr 742 hput 0 4 get launch 7 743 r = checked kfdctl int get dev 0 `3221768963` hdr 0 8 744 r = checked mapdrop long get launch 8 745 for i ulong add get launch 1 8 bound `9223372036854775807` 746 gpufree long get launch 0 mul i 24 747 end 748 r = checked mapdrop long get launch 0 749 r = checked fclose int get dev 1 750 r = checked fclose int get dev 0 751 r = checked fclose int get el 0 752 end 753 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 754 text runmode "run" 755 text inspectmode "inspect" 756 text vaddmode "vadd" 757 text parsed "OMEGA elf=accepted image_bytes=" 758 text argslabel " kernarg_bytes=" 759 text passed "OMEGA vadd=PASS count=256\n" 760 global config ulong 3 761 fn mode name view uchar * to bool 762 n = patharg 1 763 if ne n len name 764 ret false 765 end 766 for i ulong n bound 4096 767 if ne get pathbuf i get name i 768 ret false 769 end 770 end 771 ret true 772 end 773 fn configread to void 774 fd = argfile 6 0 775 put config 0 ulong fd 776 size = filesize fd 777 span 0 48 size 778 note Eight ASCII bytes OMKFD001. 779 if ne fword fd 0 8 0x31303044464b4d4f 780 exit 64 781 end 782 if ne fword fd 8 8 get el 8 783 exit 64 784 end 785 put launch 4 fword fd 16 8 786 put launch 2 fword fd 24 8 787 put launch 3 fword fd 32 8 788 put config 1 fword fd 40 8 789 if gt get config 1 div get el 8 8 790 exit 64 791 end 792 put config 2 add 48 mul get config 1 16 793 span get config 2 get el 8 size 794 if ne add get config 2 get el 8 size 795 exit 64 796 end 797 if or eq get launch 4 0 eq get launch 2 0 798 exit 64 799 end 800 if or gt get launch 2 `9223372036854775807` eq get launch 3 0 801 exit 64 802 end 803 for i ulong get config 1 bound `9223372036854775807` 804 p = add 48 mul i 16 805 off = fword fd p 8 806 span off 8 get el 8 807 if ne rem off 8 0 808 exit 64 809 end 810 if gt fword fd add p 8 8 get launch 1 811 exit 64 812 end 813 if ne fword fd add get config 2 off 8 0 814 exit 64 815 end 816 for j ulong i bound `9223372036854775807` 817 if eq off fword fd add 48 mul j 16 8 818 exit 64 819 end 820 end 821 end 822 end 823 fn prepare to void 824 n = mul add get launch 1 8 24 825 put launch 0 ulong checked mapnew -1 0 n 3 34 826 r = allocate 0 get el 7 0xe0000001 827 loadelf r 828 r = allocate 1 get el 8 0xa4000002 829 r = allocate 2 get launch 4 0xa0000001 830 end 831 fn loadinputs to void 832 for i ulong get launch 1 bound `9223372036854775807` 833 fd = argfile add i 7 0 834 size = filesize fd 835 if eq size 0 836 exit 64 837 end 838 h = allocate add i 8 size 0xa0000001 839 filecopy fd 0 h 0 size 840 r = checked fclose fd 841 end 842 filecopy int get config 0 get config 2 lh 1 0 get el 8 843 for i ulong get config 1 bound `9223372036854775807` 844 p = add 48 mul i 16 845 off = fword int get config 0 p 8 846 idx = fword int get config 0 add p 8 8 847 h = lh 2 848 if lt idx get launch 1 849 h = lh add idx 8 850 end 851 r = checked mapset lh 1 off 8 mapaddr h 852 end 853 r = checked fclose int get config 0 854 end 855 fn vaddinputs to void 856 if ne get el 8 28 857 exit 65 858 end 859 h = allocate 8 1024 0xa0000001 860 h = allocate 9 1024 0xa0000001 861 note IEEE754 binary32 1 + 1 = 2; exact independent host oracle in the gate. 862 for i ulong 256 863 r = checked mapset lh 8 mul i 4 4 0x3f800000 864 r = checked mapset lh 9 mul i 4 4 0x3f800000 865 r = checked mapset lh 2 mul i 4 4 0x7fc00000 866 end 867 r = checked mapset lh 1 0 8 mapaddr lh 8 868 r = checked mapset lh 1 8 8 mapaddr lh 9 869 r = checked mapset lh 1 16 8 mapaddr lh 2 870 r = checked mapset lh 1 24 4 256 871 end 872 fn vaddcheck to void 873 for i ulong 256 874 if ne mapget lh 2 mul i 4 4 0x40000000 875 exit 76 876 end 877 end 878 emit passed 879 end 880 fn main to int 881 if lt argcnt 4 882 ret 64 883 end 884 isinspect = mode inspectmode 885 isvadd = mode vaddmode 886 isrun = mode runmode 887 if not or isinspect or isvadd isrun 888 ret 64 889 end 890 parseelf 2 3 891 if isinspect 892 emit parsed 893 printnum get el 7 894 emit argslabel 895 printnum get el 8 896 emit newline 897 r = checked fclose int get el 0 898 ret 0 899 end 900 if isvadd 901 if ne argcnt 4 902 ret 64 903 end 904 put launch 1 2 905 put launch 2 1 906 put launch 3 `10000000000` 907 put launch 4 1024 908 put launch 5 4 909 put launch 6 1 910 else 911 if lt argcnt 8 912 ret 64 913 end 914 put launch 1 sub ulong argcnt 8 915 put launch 5 argnum 4 916 put launch 6 argnum 5 917 if or eq get launch 5 0 gt get launch 5 div ulong `4294967295` 64 918 ret 64 919 end 920 if or eq get launch 6 0 gt get launch 6 `4294967295` 921 ret 64 922 end 923 configread 924 end 925 connectkfd 926 prepare 927 if isvadd 928 vaddinputs 929 else 930 loadinputs 931 end 932 queueinit 933 dispatch 934 if isvadd 935 vaddcheck 936 else 937 fd = argfile sub ulong argcnt 1 577 938 savefile fd lh 2 get launch 4 939 r = checked fclose fd 940 end 941 teardown 942 ret 0 943 end 944 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 945 note Shared CLI unsigned parser; append after aql.om, kernarg.om, records.om or ring.om. 946 note A uint64 text needs at most 20 decimal digits or 0x plus 16 hexadecimal digits. 947 note Buffer 21 permits the extra byte that makes an overlong value refuse, not truncate. 948 note WolframLanguageEvaluator: {2^64-1,Quotient[2^64-1,10],Mod[2^64-1,10]} -> 949 note {`18446744073709551615`,`1844674407370955161`,5} (integer range, dimensionless). 950 fn argnum i ulong to ulong 951 ab = new uchar 21 0 952 n = argread i ab 0 21 953 if lt n 1 954 exit 2 955 end 956 k = ulong n 957 s = ulong 0 958 hex = false 959 if gt k 2 960 if and eq get ab 0 48 eq get ab 1 120 961 hex = true 962 s = ulong 2 963 end 964 end 965 m = sub k s 966 if hex 967 if gt m 16 968 exit 2 969 end 970 end 971 v = ulong 0 972 for j ulong m 973 d = ulong get ab add j s 974 dv = ulong 16 975 if and ge d 48 le d 57 976 dv = sub d 48 977 end 978 if hex 979 if and ge d 97 le d 102 980 dv = sub d 87 981 end 982 if eq dv 16 983 exit 2 984 end 985 v = or shl v 4 dv 986 else 987 if gt dv 9 988 exit 2 989 end 990 if gt v `1844674407370955161` 991 exit 2 992 end 993 if and eq v `1844674407370955161` gt dv 5 994 exit 2 995 end 996 v = add mul v 10 dv 997 end 998 end 999 ret v 1000 end 1001 note Full write or exit 74. Applies to files and pipes, including partial writes and EINTR. 1002 fn emit b view uchar * to void 1003 p = ulong 0 1004 while lt p len b bound 999999 1005 r = write 1 b p sub len b p 1006 if eq r neg long 4 1007 continue 1008 end 1009 if le r 0 1010 exit 74 1011 end 1012 p = add p ulong r 1013 end 1014 end