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-3/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-3 / launch-a64.om` 1015 lines · 20214 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 note O_DIRECTORY differs across ARM64 and x86. getdnts verifies the read-only fd. 478 dfd = int checked fopen nodes 0 len nodes 0 0 479 found = false 480 while not found bound `9223372036854775807` 481 r = checked getdnts dfd dirbuf 0 len dirbuf 482 if eq r 0 483 exit 66 484 end 485 p = ulong 0 486 while lt p ulong r bound 4096 487 span p 20 ulong r 488 sz = add ulong get dirbuf add p 16 shl ulong get dirbuf add p 17 8 489 if lt sz 20 490 exit 66 491 end 492 span p sz ulong r 493 c = get dirbuf add p 19 494 if and ge c 48 le c 57 495 n = len nodes 496 for i ulong n bound 4096 497 put nodepath i get nodes i 498 end 499 j = add p 19 500 while true bound 4096 501 if ge j add p sz 502 exit 66 503 end 504 if eq get dirbuf j 0 505 break 506 end 507 if ge n len nodepath 508 exit 66 509 end 510 put nodepath n get dirbuf j 511 n = add n 1 512 j = add j 1 513 end 514 put noden 0 n 515 if nodecheck 516 found = true 517 break 518 end 519 end 520 p = add p sz 521 end 522 end 523 r = checked fclose dfd 524 n = addpath render 0 525 minor = get dev 1 526 if gt minor `4294967295` 527 exit 66 528 end 529 b = new uchar 10 0 530 p = ulong 10 531 while gt minor 9 bound 10 532 p = sub p 1 533 put b p uchar add rem minor 10 48 534 minor = div minor 10 535 end 536 p = sub p 1 537 put b p uchar add minor 48 538 n = addpath part b p sub 10 p n 539 put dev 1 ulong checked fopen pathbuf 0 n 2 0 540 end 541 fn connectkfd to void 542 fd = fopen kfdpath 0 len kfdpath 2 0 543 if eq fd -2 544 emit absent 545 exit 77 546 end 547 put dev 0 ulong checked fd 548 zerohdr 549 r = checked kfdctl int fd `2148027137` hdr 0 8 550 if or ne hget 0 4 1 lt hget 4 4 14 551 exit 67 552 end 553 topology 554 zerohdr 555 hput 0 4 get dev 1 556 hput 4 4 get dev 2 557 r = checked kfdctl int get dev 0 `1074285333` hdr 0 8 558 for i ulong 4 559 put ids i uchar and shr get dev 2 mul i 8 255 560 end 561 end 562 fn ctxsizes to void 563 if or eq get dev 4 0 eq get dev 7 0 564 exit 66 565 end 566 if eq get dev 6 0 567 exit 66 568 end 569 cu = div div get dev 3 get dev 4 get dev 7 570 if eq cu 0 571 exit 66 572 end 573 waves = mul cu 40 574 maxwaves = mul div div get dev 5 get dev 6 get dev 6 512 575 if lt maxwaves waves 576 waves = maxwaves 577 end 578 if eq waves 0 579 exit 66 580 end 581 ctl = roundup add 40 add mul waves 8 8 4096 582 wg = roundup mul cu add add ulong 0x80000 0x4000 add ulong 0x10000 0x1000 4096 583 put dev 8 add ctl wg 584 put dev 9 ctl 585 put dev 10 roundup mul waves 32 64 586 if gt get dev 8 `4294967295` 587 exit 66 588 end 589 end 590 fn mapgpu kh ulong to void 591 zerohdr 592 hput 0 8 kh 593 hput 16 4 1 594 r = checked kfdctl int get dev 0 `3222817560` hdr 0 24 ids 0 4 595 if ne hget 20 4 1 596 exit 68 597 end 598 end 599 note Allocation record on the caller's table: CPU handle, KFD handle, byte size (24 bytes). 600 fn gpumem n ulong flags ulong table long rec ulong to long 601 sz = roundup n 4096 602 h = checked kfdres sz 603 zerohdr 604 hput 8 8 sz 605 hput 32 4 get dev 2 606 hput 36 4 flags 607 r = checked kfdctl int get dev 0 `3223866134` hdr 0 40 h 608 kh = hget 16 8 609 moff = hget 24 8 610 r = checked mapset table rec 8 ulong h 611 r = checked mapset table add rec 8 8 kh 612 r = checked mapset table add rec 16 8 sz 613 mapgpu kh 614 r = checked mapbind h int get dev 1 moff 3 615 ret h 616 end 617 fn gpufree table long rec ulong to void 618 kh = mapget table add rec 8 8 619 zerohdr 620 hput 0 8 kh 621 hput 16 4 1 622 r = checked kfdctl int get dev 0 `3222817561` hdr 0 24 ids 0 4 623 if ne hget 20 4 1 624 exit 68 625 end 626 r = checked mapdrop long mapget table rec 8 627 zerohdr 628 hput 0 8 kh 629 r = checked kfdctl int get dev 0 `1074285335` hdr 0 8 630 end 631 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 632 note launch: table,ninputs,repeats,timeoutns,outbytes,groupsX,groupsY,queueid,bell,belloff. 633 global launch ulong 10 634 text timed "OMEGA dispatch_ns=" 635 text repeatlabel " packets=" 636 fn lh i ulong to long 637 ret long mapget long get launch 0 mul i 24 8 638 end 639 fn allocate i ulong n ulong flags ulong to long 640 ret gpumem n flags long get launch 0 mul i 24 641 end 642 fn queueinit to void 643 ctxsizes 644 r = allocate 3 1024 0xa6000002 645 r = allocate 4 4096 0xa6000002 646 r = allocate 5 4096 0xa6000002 647 n = roundup mul add get dev 8 get dev 10 get dev 7 4096 648 r = allocate 6 n 0xe4000002 649 r = allocate 7 4096 0xa6000002 650 zeromap lh 3 0 1024 651 zeromap lh 4 0 8 652 zeromap lh 5 0 8 653 zeromap lh 6 0 n 654 zeromap lh 7 0 64 655 note USER signal ABI: kind 1 at 0, value at 8, no interrupt event. 656 r = checked mapset lh 7 0 8 1 657 r = checked mapset lh 7 8 8 get launch 2 658 for i ulong get dev 7 bound `9223372036854775807` 659 p = mul i get dev 8 660 r = checked mapset lh 6 add p 16 4 mul sub get dev 7 i get dev 8 661 r = checked mapset lh 6 add p 20 4 mul get dev 10 get dev 7 662 end 663 for i ulong 16 664 r = checked mapset lh 3 mul i 64 4 1 665 end 666 zerohdr 667 hput 32 4 1024 668 hput 36 4 get dev 2 669 hput 40 4 2 670 hput 44 4 100 671 hput 48 4 7 672 hput 80 4 get dev 8 673 hput 84 4 get dev 9 674 note gfx942 AQL queues require no EOP allocation (ROCT queues.c). 675 r = checked kfdctl int get dev 0 `3227011842` hdr 0 88 lh 3 lh 4 lh 5 long 0 lh 6 676 put launch 7 hget 52 4 677 belloff = hget 24 8 678 put launch 9 rem belloff 8192 679 put launch 8 ulong checked kfdmap int get dev 0 sub belloff rem belloff 8192 8192 680 end 681 fn packet id ulong to void 682 slot = mul rem id 16 64 683 zerohdr 684 note First dword kept INVALID until every other field is published. 685 hput 0 2 1 686 hput 2 2 2 687 hput 4 2 64 688 hput 6 2 1 689 hput 8 2 1 690 hput 12 4 mul get launch 5 64 691 hput 16 4 get launch 6 692 hput 20 4 1 693 hput 24 4 get el 10 694 hput 28 4 get el 9 695 hput 32 8 add mapaddr lh 0 get el 6 696 hput 40 8 mapaddr lh 1 697 hput 56 8 mapaddr lh 7 698 r = checked mapset lh 3 slot 4 1 699 r = checked mapwrite lh 3 add slot 4 hdr 4 60 700 cpufence 701 note type KERNEL_DISPATCH=2, barrier=1, acquire/release SYSTEM=2, dimensions=2. 702 r = checked mapset lh 3 slot 4 0x00021502 703 cpufence 704 r = checked mapset lh 4 0 8 add id 1 705 cpufence 706 r = checked mapset long get launch 8 get launch 9 8 id 707 end 708 fn deadline start long to void 709 now = monons 710 if lt now start 711 exit 75 712 end 713 if gt ulong sub now start get launch 3 714 exit 75 715 end 716 end 717 fn dispatch to void 718 start = monons 719 if lt start 0 720 exit 74 721 end 722 for i ulong get launch 2 bound `9223372036854775807` 723 while ge sub i mapget lh 5 0 8 16 bound `9223372036854775807` 724 deadline start 725 cpurelax 726 end 727 packet i 728 end 729 while ne mapget lh 7 8 8 0 bound `9223372036854775807` 730 deadline start 731 cpurelax 732 end 733 cpufence 734 elapsed = sub monons start 735 emit timed 736 printnum ulong elapsed 737 emit repeatlabel 738 printnum get launch 2 739 emit newline 740 end 741 fn teardown to void 742 zerohdr 743 hput 0 4 get launch 7 744 r = checked kfdctl int get dev 0 `3221768963` hdr 0 8 745 r = checked mapdrop long get launch 8 746 for i ulong add get launch 1 8 bound `9223372036854775807` 747 gpufree long get launch 0 mul i 24 748 end 749 r = checked mapdrop long get launch 0 750 r = checked fclose int get dev 1 751 r = checked fclose int get dev 0 752 r = checked fclose int get el 0 753 end 754 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 755 text runmode "run" 756 text inspectmode "inspect" 757 text vaddmode "vadd" 758 text parsed "OMEGA elf=accepted image_bytes=" 759 text argslabel " kernarg_bytes=" 760 text passed "OMEGA vadd=PASS count=256\n" 761 global config ulong 3 762 fn mode name view uchar * to bool 763 n = patharg 1 764 if ne n len name 765 ret false 766 end 767 for i ulong n bound 4096 768 if ne get pathbuf i get name i 769 ret false 770 end 771 end 772 ret true 773 end 774 fn configread to void 775 fd = argfile 6 0 776 put config 0 ulong fd 777 size = filesize fd 778 span 0 48 size 779 note Eight ASCII bytes OMKFD001. 780 if ne fword fd 0 8 0x31303044464b4d4f 781 exit 64 782 end 783 if ne fword fd 8 8 get el 8 784 exit 64 785 end 786 put launch 4 fword fd 16 8 787 put launch 2 fword fd 24 8 788 put launch 3 fword fd 32 8 789 put config 1 fword fd 40 8 790 if gt get config 1 div get el 8 8 791 exit 64 792 end 793 put config 2 add 48 mul get config 1 16 794 span get config 2 get el 8 size 795 if ne add get config 2 get el 8 size 796 exit 64 797 end 798 if or eq get launch 4 0 eq get launch 2 0 799 exit 64 800 end 801 if or gt get launch 2 `9223372036854775807` eq get launch 3 0 802 exit 64 803 end 804 for i ulong get config 1 bound `9223372036854775807` 805 p = add 48 mul i 16 806 off = fword fd p 8 807 span off 8 get el 8 808 if ne rem off 8 0 809 exit 64 810 end 811 if gt fword fd add p 8 8 get launch 1 812 exit 64 813 end 814 if ne fword fd add get config 2 off 8 0 815 exit 64 816 end 817 for j ulong i bound `9223372036854775807` 818 if eq off fword fd add 48 mul j 16 8 819 exit 64 820 end 821 end 822 end 823 end 824 fn prepare to void 825 n = mul add get launch 1 8 24 826 put launch 0 ulong checked mapnew -1 0 n 3 34 827 r = allocate 0 get el 7 0xe0000001 828 loadelf r 829 r = allocate 1 get el 8 0xa4000002 830 r = allocate 2 get launch 4 0xa0000001 831 end 832 fn loadinputs to void 833 for i ulong get launch 1 bound `9223372036854775807` 834 fd = argfile add i 7 0 835 size = filesize fd 836 if eq size 0 837 exit 64 838 end 839 h = allocate add i 8 size 0xa0000001 840 filecopy fd 0 h 0 size 841 r = checked fclose fd 842 end 843 filecopy int get config 0 get config 2 lh 1 0 get el 8 844 for i ulong get config 1 bound `9223372036854775807` 845 p = add 48 mul i 16 846 off = fword int get config 0 p 8 847 idx = fword int get config 0 add p 8 8 848 h = lh 2 849 if lt idx get launch 1 850 h = lh add idx 8 851 end 852 r = checked mapset lh 1 off 8 mapaddr h 853 end 854 r = checked fclose int get config 0 855 end 856 fn vaddinputs to void 857 if ne get el 8 28 858 exit 65 859 end 860 h = allocate 8 1024 0xa0000001 861 h = allocate 9 1024 0xa0000001 862 note IEEE754 binary32 1 + 1 = 2; exact independent host oracle in the gate. 863 for i ulong 256 864 r = checked mapset lh 8 mul i 4 4 0x3f800000 865 r = checked mapset lh 9 mul i 4 4 0x3f800000 866 r = checked mapset lh 2 mul i 4 4 0x7fc00000 867 end 868 r = checked mapset lh 1 0 8 mapaddr lh 8 869 r = checked mapset lh 1 8 8 mapaddr lh 9 870 r = checked mapset lh 1 16 8 mapaddr lh 2 871 r = checked mapset lh 1 24 4 256 872 end 873 fn vaddcheck to void 874 for i ulong 256 875 if ne mapget lh 2 mul i 4 4 0x40000000 876 exit 76 877 end 878 end 879 emit passed 880 end 881 fn main to int 882 if lt argcnt 4 883 ret 64 884 end 885 isinspect = mode inspectmode 886 isvadd = mode vaddmode 887 isrun = mode runmode 888 if not or isinspect or isvadd isrun 889 ret 64 890 end 891 parseelf 2 3 892 if isinspect 893 emit parsed 894 printnum get el 7 895 emit argslabel 896 printnum get el 8 897 emit newline 898 r = checked fclose int get el 0 899 ret 0 900 end 901 if isvadd 902 if ne argcnt 4 903 ret 64 904 end 905 put launch 1 2 906 put launch 2 1 907 put launch 3 `10000000000` 908 put launch 4 1024 909 put launch 5 4 910 put launch 6 1 911 else 912 if lt argcnt 8 913 ret 64 914 end 915 put launch 1 sub ulong argcnt 8 916 put launch 5 argnum 4 917 put launch 6 argnum 5 918 if or eq get launch 5 0 gt get launch 5 div ulong `4294967295` 64 919 ret 64 920 end 921 if or eq get launch 6 0 gt get launch 6 `4294967295` 922 ret 64 923 end 924 configread 925 end 926 connectkfd 927 prepare 928 if isvadd 929 vaddinputs 930 else 931 loadinputs 932 end 933 queueinit 934 dispatch 935 if isvadd 936 vaddcheck 937 else 938 fd = argfile sub ulong argcnt 1 577 939 savefile fd lh 2 get launch 4 940 r = checked fclose fd 941 end 942 teardown 943 ret 0 944 end 945 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 946 note Shared CLI unsigned parser; append after aql.om, kernarg.om, records.om or ring.om. 947 note A uint64 text needs at most 20 decimal digits or 0x plus 16 hexadecimal digits. 948 note Buffer 21 permits the extra byte that makes an overlong value refuse, not truncate. 949 note WolframLanguageEvaluator: {2^64-1,Quotient[2^64-1,10],Mod[2^64-1,10]} -> 950 note {`18446744073709551615`,`1844674407370955161`,5} (integer range, dimensionless). 951 fn argnum i ulong to ulong 952 ab = new uchar 21 0 953 n = argread i ab 0 21 954 if lt n 1 955 exit 2 956 end 957 k = ulong n 958 s = ulong 0 959 hex = false 960 if gt k 2 961 if and eq get ab 0 48 eq get ab 1 120 962 hex = true 963 s = ulong 2 964 end 965 end 966 m = sub k s 967 if hex 968 if gt m 16 969 exit 2 970 end 971 end 972 v = ulong 0 973 for j ulong m 974 d = ulong get ab add j s 975 dv = ulong 16 976 if and ge d 48 le d 57 977 dv = sub d 48 978 end 979 if hex 980 if and ge d 97 le d 102 981 dv = sub d 87 982 end 983 if eq dv 16 984 exit 2 985 end 986 v = or shl v 4 dv 987 else 988 if gt dv 9 989 exit 2 990 end 991 if gt v `1844674407370955161` 992 exit 2 993 end 994 if and eq v `1844674407370955161` gt dv 5 995 exit 2 996 end 997 v = add mul v 10 dv 998 end 999 end 1000 ret v 1001 end 1002 note Full write or exit 74. Applies to files and pipes, including partial writes and EINTR. 1003 fn emit b view uchar * to void 1004 p = ulong 0 1005 while lt p len b bound 999999 1006 r = write 1 b p sub len b p 1007 if eq r neg long 4 1008 continue 1009 end 1010 if le r 0 1011 exit 74 1012 end 1013 p = add p ulong r 1014 end 1015 end