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/backend/targets.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 / backend / targets.om` 1128 lines · 19535 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note targets.om: the portable backend's target table and code-object loader checks (seeded Omega, 3 note AArch64 host). docs/ARCHITECTURE.md "Portable backend" defines the formats; this file is the 4 note first IMPLEMENTED piece of that split. It opens no device: it reads one file and prints. 5 note 6 note targets doctor print every target row with its honest status 7 note targets load FORMAT FILE [ARG] validate FILE as FORMAT; print LOAD ACCEPT or LOAD REFUSE 8 note 9 note Formats (ob_code_load tags): SM121_RAW, SPIRV_CL, SPIRV_VK, AMDGPU_HSACO accepted after checks; 10 note MSL_SOURCE and AARCH64 (cpu-ref) have no backend yet (PLANNED, refused); CUBIN is reserved (#864 HOLD, refused). 11 note ARG: for SPIRV_CL/SPIRV_VK an entry point name that must exist; for AMDGPU_HSACO the gfx target 12 note (required), checked against e_flags and the NT_AMDGPU_METADATA note. 13 note Checks: 14 note SPIR-V magic 0x07230203, version 1.0..1.6, bound 1..`4194303`, schema 0, every instruction inside 15 note the file; SPIRV_VK: Shader, no Kernel, Logical GLSL450, a GLCompute entry; 16 note SPIRV_CL: Kernel and Addresses, no Shader, Physical64 OpenCL, a Kernel entry. 17 note Authority: registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html sections 2.3, 3. 18 note HSACO ELF64 little-endian version 1, OSABI 64 (HSA), ABI version 2 (code object v4) or 3 (v5), 19 note ET_DYN, e_machine 224 (EM_AMDGPU), e_flags & 0xff == the target's mach, a PT_NOTE 20 note holding owner "AMDGPU" type 32 (NT_AMDGPU_METADATA) whose msgpack map has 21 note amdhsa.version [1, x], a non-empty amdhsa.kernels and amdhsa.target equal to 22 note "amdgcn-amd-amdhsa--" + ARG (no feature suffix). Authority for the numbers: 23 note llvm/BinaryFormat/ELF.h at LLVM 18.1.3 (EM_AMDGPU, ELFOSABI_AMDGPU_HSA, 24 note ELFABIVERSION_AMDGPU_HSA_V4/V5, EF_AMDGPU_MACH_AMDGCN_*, NT_AMDGPU_METADATA) and 25 note llvm.org/docs/AMDGPUUsage.html "Code Object Metadata"; msgpack.org spec for the walk. 26 note SM121_RAW non-empty, a whole number of 16-byte instructions, not ELF and not SPIR-V. 27 note Validation is offline: an AMD or SPIR-V ACCEPT here says the bytes are well formed for that 28 note target, never that a GPU ran them (hardware NOT_RUN on every non-GB10 row). 29 note Exit: 0 accept or doctor; 2 usage; 3 I/O or file over 1 MiB; 10 unknown format; 11 format has 30 note no backend (PLANNED); 12 format reserved; 20 SPIR-V header; 21 SPIR-V instruction stream; 31 note 22 SPIR-V capability or memory model wrong for the format; 23 entry point missing; 32 note 30 ELF header; 31 OSABI or ABI version; 32 ELF type or machine; 33 e_flags mach is not the target; 33 note 34 AMDGPU metadata note missing or malformed; 35 msgpack malformed; 36 metadata target, version 34 note or kernels wrong; 37 unknown gfx target; 40 SM121_RAW shape. Traps exit 100 + code. 35 om2 36 37 text tuse "usage: targets doctor | targets load FORMAT FILE [ENTRY|GFX]\n" 38 text tio "targets: cannot read FILE, or FILE is empty or over 1 MiB\n" 39 text tdoc "doctor" 40 text tload "load" 41 text fsm "SM121_RAW" 42 text fcl "SPIRV_CL" 43 text fvk "SPIRV_VK" 44 text fhs "AMDGPU_HSACO" 45 text fms "MSL_SOURCE" 46 text fa64 "AARCH64" 47 text fcu "CUBIN" 48 text tacc "LOAD ACCEPT " 49 text tref "LOAD REFUSE " 50 text tcode " code=" 51 text trsn " reason=" 52 text tnl "\n" 53 text tsp " " 54 text tdot "." 55 text tver " version=" 56 text tbnd " bound=" 57 text twds " words=" 58 text tent " entry=" 59 text tmach " mach=0x" 60 text tabi " abi=" 61 text tkern " kernels=" 62 text ttgt " target=" 63 text tnote " note=AMDGPU/NT_AMDGPU_METADATA" 64 text tsz " bytes=" 65 text tinsn " insns=" 66 text tpfx "amdgcn-amd-amdhsa--" 67 text kver "amdhsa.version" 68 text kkern "amdhsa.kernels" 69 text ktgt "amdhsa.target" 70 text rnofmt "unknown format tag" 71 text rplan "format has no backend yet (PLANNED)" 72 text rresv "format reserved (CUBIN, #864 HOLD)" 73 text rmagic "not a SPIR-V module (magic, version, bound or schema)" 74 text rstrm "SPIR-V instruction runs past the end, has word count 0, or the module does not end with OpFunctionEnd" 75 text rcapv "not Vulkan compute SPIR-V (needs Shader, no Kernel, Logical GLSL450)" 76 text rcapc "not OpenCL kernel SPIR-V (needs Kernel+Addresses, no Shader, Physical64 OpenCL)" 77 text rentry "no entry point of the right model (or with that name)" 78 text relf "not an ELF64 little-endian version-1 file" 79 text rabi "OSABI is not HSA (64) or ABI version is not code object v4/v5" 80 text rmach "not an AMDGPU shared object (e_type 3, e_machine 224)" 81 text rflag "e_flags mach does not match the requested gfx target" 82 text rnote "no well-formed AMDGPU NT_AMDGPU_METADATA note in a PT_NOTE segment" 83 text rmsg "metadata msgpack malformed" 84 text rtgt "metadata amdhsa.target, amdhsa.version or amdhsa.kernels does not match" 85 text rgfx "unknown gfx target (known: gfx900 gfx90a gfx942 gfx1030 gfx1100 gfx1151 gfx1200 gfx1201)" 86 text rraw "SM121_RAW must be non-empty 16-byte instructions and not ELF or SPIR-V" 87 text rarg "AMDGPU_HSACO needs the gfx target argument" 88 text g900 "gfx900" 89 text g90a "gfx90a" 90 text g942 "gfx942" 91 text g1030 "gfx1030" 92 text g1100 "gfx1100" 93 text g1151 "gfx1151" 94 text g1200 "gfx1200" 95 text g1201 "gfx1201" 96 text hdr "TARGET id vendor arch format status hardware loader\n" 97 text tt "TARGET " 98 text sSUP "SUPPORTED" 99 text sPLN "PLANNED" 100 text sHOST "HOST-ONLY(not-a-GPU)" 101 text hGB "chip-receipts(README)" 102 text hNR "NOT_RUN" 103 text hCPU "EXERCISED(host-CPU)" 104 text lRAW "SM121_RAW" 105 text lNONE "none" 106 text lSPV "spirv-validate" 107 text lHSA "hsaco-validate" 108 text vNV "nvidia" 109 text vAMD "amd" 110 text vINT "intel" 111 text vAPL "apple" 112 text vQC "qualcomm" 113 text vARM "arm" 114 text vIMG "imagination" 115 text vBCM "broadcom" 116 text vVTX "vortex" 117 text vCPU "cpu" 118 text fSASS "SASS(encoder-per-arch)" 119 text fMSL "MSL_SOURCE" 120 text fSPCL "SPIRV_CL|SPIRV_VK" 121 122 const MAXF ulong `1048576` 123 124 global gbuf uchar `1048576` 125 global garg uchar 64 126 global gfmt uchar 32 127 global gtgt uchar 96 128 global gob uchar 512 129 note gst: 0 file size, 1 output fill, 2 msgpack cursor, 3 msgpack end, 4 format length, 130 note 5 kernels, 6 target ok, 7 version ok, 8 expected target length, 9 entry name length 131 global gst ulong 12 132 133 fn oflush to void 134 n = write 1 gob 0 get gst 1 135 put gst 1 0 136 end 137 138 fn oc b uchar to void 139 if ge get gst 1 len gob 140 oflush 141 end 142 f = get gst 1 143 put gob f b 144 put gst 1 add f 1 145 end 146 147 fn ot t view uchar * to void 148 for i ulong len t 149 oc get t i 150 end 151 end 152 153 fn odec v ulong to void 154 d = new uchar 20 0 155 k = ulong 0 156 x = v 157 while true bound 21 158 put d k uchar add rem x 10 48 159 k = add k 1 160 x = div x 10 161 if eq x 0 162 break 163 end 164 end 165 for i ulong k 166 oc get d sub sub k i 1 167 end 168 end 169 170 fn ohx v ulong to void 171 for i ulong 2 172 s = sub 4 mul i 4 173 d = and shr v s 15 174 if lt d 10 175 oc uchar add d 48 176 else 177 oc uchar add d 87 178 end 179 end 180 end 181 182 fn ofmt to void 183 for i ulong get gst 4 184 oc get gfmt i 185 end 186 end 187 188 fn refuse code int msg view uchar * to void 189 ot tref 190 ofmt 191 ot tcode 192 odec ulong code 193 ot trsn 194 ot msg 195 ot tnl 196 oflush 197 exit code 198 end 199 200 fn fail code int msg view uchar * to void 201 oflush 202 n = write 2 msg 0 len msg 203 exit code 204 end 205 206 fn fmtis t view uchar * to bool 207 if ne get gst 4 len t 208 ret false 209 end 210 for k ulong len t 211 if ne get gfmt k get t k 212 ret false 213 end 214 end 215 ret true 216 end 217 218 fn argis t view uchar * to bool 219 if ne get gst 9 len t 220 ret false 221 end 222 for k ulong len t 223 if ne get garg k get t k 224 ret false 225 end 226 end 227 ret true 228 end 229 230 fn row id view uchar * vn view uchar * ar view uchar * to void 231 note starts a row: id, vendor, arch (a view parameter takes two of the 6 parameter slots) 232 ot tt 233 ot id 234 ot tsp 235 ot vn 236 ot tsp 237 ot ar 238 end 239 240 fn rf fm view uchar * st view uchar * hw view uchar * to void 241 note the middle of a row: format, status, hardware 242 ot tsp 243 ot fm 244 ot tsp 245 ot st 246 ot tsp 247 ot hw 248 end 249 250 fn rl ld view uchar * to void 251 note ends a row: the loader column (a function has at most 6 parameters) 252 ot tsp 253 ot ld 254 ot tnl 255 end 256 257 text i121 "nvidia-sm_121" 258 text a121 "sm_121(GB10)" 259 text i80 "nvidia-sm_80" 260 text a80 "sm_80(A100)" 261 text i86 "nvidia-sm_86" 262 text a86 "sm_86(RTX30)" 263 text i89 "nvidia-sm_89" 264 text a89 "sm_89(RTX40/L40)" 265 text i90 "nvidia-sm_90" 266 text a90 "sm_90(H100/H200)" 267 text i100 "nvidia-sm_100" 268 text a100 "sm_100(B200)" 269 text i120 "nvidia-sm_120" 270 text a120 "sm_120(RTX50)" 271 text ig9 "amd-gfx9" 272 text ag9 "gfx900/gfx90a/gfx942(MI300)" 273 text ig10 "amd-gfx10" 274 text ag10 "gfx1030(RDNA2)" 275 text ig11 "amd-gfx11" 276 text ag11 "gfx1100(RDNA3)/gfx1151(Strix-Halo)" 277 text ig12 "amd-gfx12" 278 text ag12 "gfx1200/gfx1201(RDNA4)" 279 text ixlp "intel-xe-lp" 280 text axlp "Xe-LP(Gen12-iGPU)" 281 text ixhp "intel-xe-hpg" 282 text axhp "Xe-HPG(Arc-Alchemist)" 283 text ixe2 "intel-xe2" 284 text axe2 "Xe2(Lunar-Lake/Battlemage)" 285 text iapl "apple-m" 286 text aapl "Apple-GPU(M-series)" 287 text iqc "qualcomm-adreno" 288 text aqc "Adreno" 289 text iarm "arm-mali" 290 text aarm "Mali/Immortalis" 291 text iimg "imagination-powervr" 292 text aimg "PowerVR" 293 text ibcm "broadcom-v3d" 294 text abcm "V3D(Raspberry-Pi)" 295 text ivtx "vortex" 296 text avtx "Vortex(RISC-V-GPGPU)" 297 text ipcl "cpu-pocl" 298 text apcl "PoCL-7.2-CPU" 299 text ilvp "cpu-lavapipe" 300 text alvp "Mesa-lavapipe-CPU" 301 text ssc "SPIRV_CL" 302 text svk "SPIRV_VK" 303 304 fn doctor to int 305 ot hdr 306 row i121 vNV a121 307 rf lRAW sSUP hGB 308 rl lRAW 309 row i80 vNV a80 310 rf fSASS sPLN hNR 311 rl lNONE 312 row i86 vNV a86 313 rf fSASS sPLN hNR 314 rl lNONE 315 row i89 vNV a89 316 rf fSASS sPLN hNR 317 rl lNONE 318 row i90 vNV a90 319 rf fSASS sPLN hNR 320 rl lNONE 321 row i100 vNV a100 322 rf fSASS sPLN hNR 323 rl lNONE 324 row i120 vNV a120 325 rf fSASS sPLN hNR 326 rl lNONE 327 row ig9 vAMD ag9 328 rf fhs sPLN hNR 329 rl lHSA 330 row ig10 vAMD ag10 331 rf fhs sPLN hNR 332 rl lHSA 333 row ig11 vAMD ag11 334 rf fhs sPLN hNR 335 rl lHSA 336 row ig12 vAMD ag12 337 rf fhs sPLN hNR 338 rl lHSA 339 row ixlp vINT axlp 340 rf fSPCL sPLN hNR 341 rl lSPV 342 row ixhp vINT axhp 343 rf fSPCL sPLN hNR 344 rl lSPV 345 row ixe2 vINT axe2 346 rf fSPCL sPLN hNR 347 rl lSPV 348 row iapl vAPL aapl 349 rf fMSL sPLN hNR 350 rl lNONE 351 row iqc vQC aqc 352 rf svk sPLN hNR 353 rl lSPV 354 row iarm vARM aarm 355 rf svk sPLN hNR 356 rl lSPV 357 row iimg vIMG aimg 358 rf svk sPLN hNR 359 rl lSPV 360 row ibcm vBCM abcm 361 rf svk sPLN hNR 362 rl lSPV 363 row ivtx vVTX avtx 364 rf ssc sPLN hNR 365 rl lSPV 366 row ipcl vCPU apcl 367 rf ssc sHOST hCPU 368 rl lSPV 369 row ilvp vCPU alvp 370 rf svk sHOST hCPU 371 rl lSPV 372 oflush 373 ret 0 374 end 375 376 fn b8 o ulong to ulong 377 ret ulong get gbuf o 378 end 379 380 fn le16 o ulong to ulong 381 ret or b8 o shl b8 add o 1 8 382 end 383 384 fn le32 o ulong to ulong 385 ret or le16 o shl le16 add o 2 16 386 end 387 388 fn le64 o ulong to ulong 389 ret or le32 o shl le32 add o 4 32 390 end 391 392 fn be16 o ulong to ulong 393 ret or shl b8 o 8 b8 add o 1 394 end 395 396 fn be32 o ulong to ulong 397 ret or shl be16 o 16 be16 add o 2 398 end 399 400 fn rdfile ai ulong to void 401 p = new uchar 4096 0 402 n = argread ai p 0 4095 403 if le n 0 404 fail 2 tuse 405 end 406 fd = fopen p 0 ulong n 0 0 407 if lt fd 0 408 fail 3 tio 409 end 410 sz = fseek int fd 0 2 411 if le sz 0 412 fail 3 tio 413 end 414 if gt ulong sz MAXF 415 fail 3 tio 416 end 417 r = pread int fd gbuf 0 ulong sz 0 418 if ne r sz 419 fail 3 tio 420 end 421 c = fclose int fd 422 put gst 0 ulong sz 423 end 424 425 fn spvword i ulong to ulong 426 ret le32 mul i 4 427 end 428 429 fn namehit w ulong nw ulong to bool 430 note entry name of an OpEntryPoint starting at word w (nw words); compares with garg 431 o = mul add w 3 4 432 e = mul add w nw 4 433 k = ulong 0 434 while true bound 4096 435 if ge add o k e 436 ret false 437 end 438 c = get gbuf add o k 439 if eq c 0 440 ret eq k get gst 9 441 end 442 if ge k get gst 9 443 ret false 444 end 445 if ne c get garg k 446 ret false 447 end 448 k = add k 1 449 end 450 ret false 451 end 452 453 fn spvhdr to void 454 sz = get gst 0 455 if lt sz 20 456 refuse 20 rmagic 457 end 458 if ne rem sz 4 0 459 refuse 20 rmagic 460 end 461 if ne spvword 0 0x07230203 462 refuse 20 rmagic 463 end 464 v = spvword 1 465 if ne and v 0xff0000ff 0 466 refuse 20 rmagic 467 end 468 if ne and shr v 16 255 1 469 refuse 20 rmagic 470 end 471 if gt and shr v 8 255 6 472 refuse 20 rmagic 473 end 474 bd = spvword 3 475 if eq bd 0 476 refuse 20 rmagic 477 end 478 if ge bd `4194304` 479 refuse 20 rmagic 480 end 481 if ne spvword 4 0 482 refuse 20 rmagic 483 end 484 end 485 486 fn spvop w ulong wc ulong seen ulong to ulong 487 note one instruction at word w; returns seen with the bits it proves: 488 note 1 Shader, 2 Kernel, 4 Addresses, 8 Logical GLSL450, 16 Physical64 OpenCL, 489 note 32 GLCompute entry (named, if a name was given), 64 Kernel entry (named, if given) 490 op = and spvword w 0xffff 491 s = seen 492 if eq op 17 493 if lt wc 2 494 refuse 21 rstrm 495 end 496 cp = spvword add w 1 497 if eq cp 1 498 s = or s 1 499 end 500 if eq cp 6 501 s = or s 2 502 end 503 if eq cp 4 504 s = or s 4 505 end 506 end 507 if eq op 14 508 if lt wc 3 509 refuse 21 rstrm 510 end 511 am = spvword add w 1 512 mm = spvword add w 2 513 if eq am 0 514 if eq mm 1 515 s = or s 8 516 end 517 end 518 if eq am 2 519 if eq mm 2 520 s = or s 16 521 end 522 end 523 end 524 if eq op 15 525 if lt wc 4 526 refuse 21 rstrm 527 end 528 em = spvword add w 1 529 ok = true 530 if gt get gst 9 0 531 ok = namehit w wc 532 end 533 if ok 534 if eq em 5 535 s = or s 32 536 end 537 if eq em 6 538 s = or s 64 539 end 540 end 541 end 542 ret s 543 end 544 545 fn spvwalk to ulong 546 note walks every instruction; returns the seen bits, leaves the instruction count in gst 11 547 nw = div get gst 0 4 548 w = ulong 5 549 ni = ulong 0 550 seen = ulong 0 551 lw = ulong 5 552 while lt w nw bound 999999 553 wc = shr spvword w 16 554 if eq wc 0 555 refuse 21 rstrm 556 end 557 if gt add w wc nw 558 refuse 21 rstrm 559 end 560 seen = spvop w wc seen 561 lw = w 562 w = add w wc 563 ni = add ni 1 564 end 565 if lt w nw 566 refuse 21 rstrm 567 end 568 if ne and spvword lw 65535 56 569 refuse 21 rstrm 570 end 571 put gst 11 ni 572 ret seen 573 end 574 575 fn spirv vk bool to int 576 spvhdr 577 seen = spvwalk 578 if vk 579 if ne and seen 11 9 580 refuse 22 rcapv 581 end 582 if eq and seen 32 0 583 refuse 23 rentry 584 end 585 else 586 if ne and seen 23 22 587 refuse 22 rcapc 588 end 589 if eq and seen 64 0 590 refuse 23 rentry 591 end 592 end 593 v = spvword 1 594 ot tacc 595 ofmt 596 ot tver 597 odec and shr v 16 255 598 ot tdot 599 odec and shr v 8 255 600 ot tbnd 601 odec spvword 3 602 ot twds 603 odec div get gst 0 4 604 ot tinsn 605 odec get gst 11 606 if gt get gst 9 0 607 ot tent 608 for i ulong get gst 9 609 oc get garg i 610 end 611 end 612 ot tnl 613 oflush 614 ret 0 615 end 616 617 fn gfxmach to ulong 618 note EF_AMDGPU_MACH_AMDGCN_* from llvm/BinaryFormat/ELF.h, LLVM 18.1.3 619 if argis g900 620 ret 0x2c 621 end 622 if argis g90a 623 ret 0x3f 624 end 625 if argis g942 626 ret 0x4c 627 end 628 if argis g1030 629 ret 0x36 630 end 631 if argis g1100 632 ret 0x41 633 end 634 if argis g1151 635 ret 0x4a 636 end 637 if argis g1200 638 ret 0x48 639 end 640 if argis g1201 641 ret 0x4e 642 end 643 ret 0 644 end 645 646 fn mpneed n ulong to void 647 if gt add get gst 2 n get gst 3 648 refuse 35 rmsg 649 end 650 end 651 652 fn mpbyte to ulong 653 mpneed 1 654 p = get gst 2 655 put gst 2 add p 1 656 ret b8 p 657 end 658 659 fn mplen n ulong to ulong 660 note read an n-byte big-endian length or value at the cursor (n = 1, 2 or 4) 661 mpneed n 662 p = get gst 2 663 put gst 2 add p n 664 if eq n 1 665 ret b8 p 666 end 667 if eq n 2 668 ret be16 p 669 end 670 ret be32 p 671 end 672 673 fn mpstr to ulong 674 note string header at the cursor: returns the length; the cursor moves to the first byte 675 b = mpbyte 676 if eq and b 0xe0 0xa0 677 ret and b 31 678 end 679 if eq b 0xd9 680 ret mplen 1 681 end 682 if eq b 0xda 683 ret mplen 2 684 end 685 if eq b 0xdb 686 ret mplen 4 687 end 688 refuse 35 rmsg 689 ret 0 690 end 691 692 fn mpskip to void 693 note skip one complete value; pending counts values still to skip (bounded, no recursion) 694 pend = ulong 1 695 while gt pend 0 bound 999999 696 pend = sub pend 1 697 b = mpbyte 698 sk = ulong 0 699 if le b 0x7f 700 sk = 0 701 else 702 if ge b 0xe0 703 sk = 0 704 else 705 if eq and b 0xf0 0x80 706 pend = add pend mul and b 15 2 707 else 708 if eq and b 0xf0 0x90 709 pend = add pend and b 15 710 else 711 if eq and b 0xe0 0xa0 712 sk = and b 31 713 else 714 sk = mpskipx b 715 pend = add pend get gst 10 716 end 717 end 718 end 719 end 720 end 721 mpneed sk 722 put gst 2 add get gst 2 sk 723 if gt pend `1000000` 724 refuse 35 rmsg 725 end 726 end 727 end 728 729 fn mpskipx b ulong to ulong 730 note non-fix forms: returns bytes to skip; sets gst 10 to extra pending values 731 put gst 10 0 732 if eq b 0xc0 733 ret 0 734 end 735 if eq b 0xc2 736 ret 0 737 end 738 if eq b 0xc3 739 ret 0 740 end 741 if eq b 0xcc 742 ret 1 743 end 744 if eq b 0xd0 745 ret 1 746 end 747 if eq b 0xcd 748 ret 2 749 end 750 if eq b 0xd1 751 ret 2 752 end 753 if eq b 0xca 754 ret 4 755 end 756 if eq b 0xce 757 ret 4 758 end 759 if eq b 0xd2 760 ret 4 761 end 762 if eq b 0xcb 763 ret 8 764 end 765 if eq b 0xcf 766 ret 8 767 end 768 if eq b 0xd3 769 ret 8 770 end 771 if eq b 0xc4 772 ret mplen 1 773 end 774 if eq b 0xd9 775 ret mplen 1 776 end 777 if eq b 0xc5 778 ret mplen 2 779 end 780 if eq b 0xda 781 ret mplen 2 782 end 783 if eq b 0xc6 784 ret mplen 4 785 end 786 if eq b 0xdb 787 ret mplen 4 788 end 789 if eq b 0xdc 790 put gst 10 mplen 2 791 ret 0 792 end 793 if eq b 0xdd 794 put gst 10 mplen 4 795 ret 0 796 end 797 if eq b 0xde 798 put gst 10 mul mplen 2 2 799 ret 0 800 end 801 if eq b 0xdf 802 put gst 10 mul mplen 4 2 803 ret 0 804 end 805 refuse 35 rmsg 806 ret 0 807 end 808 809 fn mpkey t view uchar * n ulong to bool 810 note the string of length n at the cursor equals t (cursor not moved) 811 if ne n len t 812 ret false 813 end 814 p = get gst 2 815 for k ulong n 816 if ne get gbuf add p k get t k 817 ret false 818 end 819 end 820 ret true 821 end 822 823 fn mparr to ulong 824 note array header at the cursor: returns the count 825 b = mpbyte 826 if eq and b 0xf0 0x90 827 ret and b 15 828 end 829 if eq b 0xdc 830 ret mplen 2 831 end 832 if eq b 0xdd 833 ret mplen 4 834 end 835 refuse 36 rtgt 836 ret 0 837 end 838 839 fn mpval kk ulong to void 840 note value of the key kk (1 version, 2 kernels, 3 target) at the cursor 841 st = get gst 2 842 if eq kk 1 843 c = mparr 844 if ge c 1 845 if eq mpbyte 1 846 put gst 7 1 847 end 848 end 849 end 850 if eq kk 2 851 put gst 5 mparr 852 end 853 if eq kk 3 854 n = mpstr 855 mpneed n 856 if eq n get gst 8 857 p = get gst 2 858 ok = true 859 for k ulong n 860 if ne get gbuf add p k get gtgt k 861 ok = false 862 end 863 end 864 if ok 865 put gst 6 1 866 end 867 end 868 end 869 put gst 2 st 870 mpskip 871 end 872 873 fn metadata o ulong n ulong to void 874 put gst 2 o 875 put gst 3 add o n 876 b = mpbyte 877 c = ulong 0 878 if eq and b 0xf0 0x80 879 c = and b 15 880 else 881 if eq b 0xde 882 c = mplen 2 883 else 884 refuse 35 rmsg 885 end 886 end 887 for i ulong c 888 kn = mpstr 889 mpneed kn 890 kk = ulong 0 891 if mpkey kver kn 892 kk = 1 893 end 894 if mpkey kkern kn 895 kk = 2 896 end 897 if mpkey ktgt kn 898 kk = 3 899 end 900 put gst 2 add get gst 2 kn 901 mpval kk 902 end 903 end 904 905 fn notes o ulong n ulong to bool 906 note walk the notes of one PT_NOTE segment; true once the AMDGPU metadata note was parsed 907 e = add o n 908 p = o 909 while lt p e bound 4096 910 if gt add p 12 e 911 refuse 34 rnote 912 end 913 nz = le32 p 914 dz = le32 add p 4 915 ty = le32 add p 8 916 nm = add p 12 917 ds = add nm and add nz 3 0xfffffffc 918 nx = add ds and add dz 3 0xfffffffc 919 if gt nx e 920 refuse 34 rnote 921 end 922 if eq nz 7 923 if eq ty 32 924 if eq le32 nm 0x47444d41 925 if eq le16 add nm 4 0x5550 926 if eq b8 add nm 6 0 927 metadata ds dz 928 ret true 929 end 930 end 931 end 932 end 933 end 934 p = nx 935 end 936 ret false 937 end 938 939 fn hsaco to int 940 sz = get gst 0 941 if eq get gst 9 0 942 fail 2 rarg 943 end 944 mach = gfxmach 945 if eq mach 0 946 refuse 37 rgfx 947 end 948 if lt sz 64 949 refuse 30 relf 950 end 951 if ne le32 0 0x464c457f 952 refuse 30 relf 953 end 954 if ne b8 4 2 955 refuse 30 relf 956 end 957 if ne b8 5 1 958 refuse 30 relf 959 end 960 if ne b8 6 1 961 refuse 30 relf 962 end 963 if ne b8 7 64 964 refuse 31 rabi 965 end 966 abi = b8 8 967 if lt abi 2 968 refuse 31 rabi 969 end 970 if gt abi 3 971 refuse 31 rabi 972 end 973 if ne le16 16 3 974 refuse 32 rmach 975 end 976 if ne le16 18 224 977 refuse 32 rmach 978 end 979 fl = le32 48 980 if ne and fl 0xff mach 981 refuse 33 rflag 982 end 983 po = le64 32 984 pe = le16 54 985 pn = le16 56 986 if ne pe 56 987 refuse 30 relf 988 end 989 if gt add po mul pn 56 sz 990 refuse 30 relf 991 end 992 done = false 993 for i ulong pn 994 h = add po mul i 56 995 if eq le32 h 4 996 off = le64 add h 8 997 fs = le64 add h 32 998 if gt add off fs sz 999 refuse 34 rnote 1000 end 1001 if not done 1002 done = notes off fs 1003 end 1004 end 1005 end 1006 if not done 1007 refuse 34 rnote 1008 end 1009 if eq get gst 7 0 1010 refuse 36 rtgt 1011 end 1012 if eq get gst 5 0 1013 refuse 36 rtgt 1014 end 1015 if eq get gst 6 0 1016 refuse 36 rtgt 1017 end 1018 ot tacc 1019 ofmt 1020 ot ttgt 1021 ot tpfx 1022 for i ulong get gst 9 1023 oc get garg i 1024 end 1025 ot tmach 1026 ohx and fl 0xff 1027 ot tabi 1028 odec abi 1029 ot tkern 1030 odec get gst 5 1031 ot tnote 1032 ot tsz 1033 odec sz 1034 ot tnl 1035 oflush 1036 ret 0 1037 end 1038 1039 fn rawsm to int 1040 sz = get gst 0 1041 if ne rem sz 16 0 1042 refuse 40 rraw 1043 end 1044 if eq le32 0 0x464c457f 1045 refuse 40 rraw 1046 end 1047 if eq le32 0 0x07230203 1048 refuse 40 rraw 1049 end 1050 ot tacc 1051 ofmt 1052 ot tsz 1053 odec sz 1054 ot tnl 1055 oflush 1056 ret 0 1057 end 1058 1059 fn main to int 1060 ac = argcnt 1061 if lt ac 2 1062 fail 2 tuse 1063 end 1064 n = argread 1 gfmt 0 len gfmt 1065 put gst 4 ulong n 1066 if fmtis tdoc 1067 if ne ac 2 1068 fail 2 tuse 1069 end 1070 ret doctor 1071 end 1072 if not fmtis tload 1073 fail 2 tuse 1074 end 1075 if lt ac 4 1076 fail 2 tuse 1077 end 1078 if gt ac 5 1079 fail 2 tuse 1080 end 1081 n = argread 2 gfmt 0 len gfmt 1082 if le n 0 1083 fail 2 tuse 1084 end 1085 put gst 4 ulong n 1086 put gst 9 0 1087 if eq ac 5 1088 m = argread 4 garg 0 len garg 1089 if le m 0 1090 fail 2 tuse 1091 end 1092 put gst 9 ulong m 1093 end 1094 for i ulong len tpfx 1095 put gtgt i get tpfx i 1096 end 1097 for i ulong get gst 9 1098 put gtgt add len tpfx i get garg i 1099 end 1100 put gst 8 add len tpfx get gst 9 1101 if fmtis fms 1102 refuse 11 rplan 1103 end 1104 if fmtis fa64 1105 refuse 11 rplan 1106 end 1107 if fmtis fcu 1108 refuse 12 rresv 1109 end 1110 if fmtis fsm 1111 rdfile 3 1112 ret rawsm 1113 end 1114 if fmtis fcl 1115 rdfile 3 1116 ret spirv false 1117 end 1118 if fmtis fvk 1119 rdfile 3 1120 ret spirv true 1121 end 1122 if fmtis fhs 1123 rdfile 3 1124 ret hsaco 1125 end 1126 refuse 10 rnofmt 1127 ret 10 1128 end