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 / gpu / nvidia / native / nvrm / struct.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note ABI580.173.02 measured by tests/nvrm_struct_layout.c against vendor headers. |
| 3 | note Only the fields filled or consumed by nvrm.c are projected; all other request bytes zero. |
| 4 | note Kinds: 1 ID 2 DEVICE 3 SUBDEVICE 4 VIRTUAL 5 GPU_INFO_V2 6 GR_GET |
| 5 | note 7 CLASSLIST 8 VASPACE 9 GID 10 MEMORY 11 CHANNEL 12 CHGROUP |
| 6 | note 13 CTXSHARE 14 TOKEN 15 SCHEDULE 16 CARD_TABLE 17 GR_INFO. |
| 7 | note mode 0 encode, 1 decode scalar, 2 size, 3 offset, 4 width, 5 count. |
| 8 | note For mode1 a[0]=field a[1]=record index (CARD_TABLE or GPU_INFO_V2). |
| 9 | note GID data is byte fields 3..258, after index/flags/length; not host-endian u64 chunks. |
| 10 | note CARD_TABLE mode0 zeroes all records then fills record zero from a; other records are driver output. |
| 11 | fn ns_size k ulong to ulong |
| 12 | if eq k 18 |
| 13 | ret 16 |
| 14 | end |
| 15 | if eq k 19 |
| 16 | ret 8 |
| 17 | end |
| 18 | if eq k 20 |
| 19 | ret 24 |
| 20 | end |
| 21 | if eq k 21 |
| 22 | ret 40 |
| 23 | end |
| 24 | if eq k 22 |
| 25 | ret 20 |
| 26 | end |
| 27 | if eq k 23 |
| 28 | ret 32 |
| 29 | end |
| 30 | if eq k 24 |
| 31 | ret 56 |
| 32 | end |
| 33 | if eq k 25 |
| 34 | ret 28 |
| 35 | end |
| 36 | if eq k 26 |
| 37 | ret 9264 |
| 38 | end |
| 39 | if eq k 1 |
| 40 | ret 32 |
| 41 | end |
| 42 | if eq k 2 |
| 43 | ret 56 |
| 44 | end |
| 45 | if eq k 3 |
| 46 | ret 4 |
| 47 | end |
| 48 | if eq k 4 |
| 49 | ret 24 |
| 50 | end |
| 51 | if eq k 5 |
| 52 | ret 564 |
| 53 | end |
| 54 | if eq k 6 |
| 55 | ret 32 |
| 56 | end |
| 57 | if eq k 7 |
| 58 | ret 16 |
| 59 | end |
| 60 | if eq k 8 |
| 61 | ret 56 |
| 62 | end |
| 63 | if eq k 9 |
| 64 | ret 268 |
| 65 | end |
| 66 | if eq k 10 |
| 67 | ret 128 |
| 68 | end |
| 69 | if eq k 11 |
| 70 | ret 368 |
| 71 | end |
| 72 | if eq k 12 |
| 73 | ret 20 |
| 74 | end |
| 75 | if eq k 13 |
| 76 | ret 12 |
| 77 | end |
| 78 | if eq k 14 |
| 79 | ret 4 |
| 80 | end |
| 81 | if eq k 15 |
| 82 | ret 3 |
| 83 | end |
| 84 | if eq k 16 |
| 85 | ret 4608 |
| 86 | end |
| 87 | if eq k 17 |
| 88 | ret 8 |
| 89 | end |
| 90 | ret 0 |
| 91 | end |
| 92 | fn ns_count k ulong to ulong |
| 93 | if or eq k 18 eq k 19 |
| 94 | ret 2 |
| 95 | end |
| 96 | if eq k 20 |
| 97 | ret 3 |
| 98 | end |
| 99 | if or eq k 21 eq k 23 |
| 100 | ret 6 |
| 101 | end |
| 102 | if eq k 22 |
| 103 | ret 3 |
| 104 | end |
| 105 | if eq k 24 |
| 106 | ret 8 |
| 107 | end |
| 108 | if eq k 25 |
| 109 | ret 5 |
| 110 | end |
| 111 | if eq k 26 |
| 112 | ret 11 |
| 113 | end |
| 114 | if eq k 1 |
| 115 | ret 4 |
| 116 | end |
| 117 | if eq k 2 |
| 118 | ret 3 |
| 119 | end |
| 120 | if eq k 3 |
| 121 | ret 1 |
| 122 | end |
| 123 | if eq k 4 |
| 124 | ret 3 |
| 125 | end |
| 126 | if eq k 5 |
| 127 | ret 3 |
| 128 | end |
| 129 | if eq k 6 |
| 130 | ret 2 |
| 131 | end |
| 132 | if eq k 7 |
| 133 | ret 2 |
| 134 | end |
| 135 | if eq k 8 |
| 136 | ret 4 |
| 137 | end |
| 138 | if eq k 9 |
| 139 | ret 259 |
| 140 | end |
| 141 | if eq k 10 |
| 142 | ret 9 |
| 143 | end |
| 144 | if eq k 11 |
| 145 | ret 9 |
| 146 | end |
| 147 | if eq k 12 |
| 148 | ret 2 |
| 149 | end |
| 150 | if eq k 13 |
| 151 | ret 3 |
| 152 | end |
| 153 | if eq k 14 |
| 154 | ret 1 |
| 155 | end |
| 156 | if eq k 15 |
| 157 | ret 3 |
| 158 | end |
| 159 | if eq k 16 |
| 160 | ret 9 |
| 161 | end |
| 162 | if eq k 17 |
| 163 | ret 2 |
| 164 | end |
| 165 | ret 0 |
| 166 | end |
| 167 | fn ns_off k ulong f ulong to ulong |
| 168 | if eq k 18 |
| 169 | ret mul f 8 |
| 170 | end |
| 171 | if eq k 19 |
| 172 | ret mul f 4 |
| 173 | end |
| 174 | if eq k 20 |
| 175 | ret mul f 8 |
| 176 | end |
| 177 | if eq k 21 |
| 178 | if lt f 2 |
| 179 | ret mul f 8 |
| 180 | end |
| 181 | ret add 24 mul sub f 2 4 |
| 182 | end |
| 183 | if or eq k 22 eq k 23 |
| 184 | if lt f 2 |
| 185 | ret mul f 8 |
| 186 | end |
| 187 | ret add 16 mul sub f 2 4 |
| 188 | end |
| 189 | if eq k 24 |
| 190 | if lt f 2 |
| 191 | ret mul f 8 |
| 192 | end |
| 193 | if lt f 5 |
| 194 | ret add 16 mul sub f 2 4 |
| 195 | end |
| 196 | ret add 32 mul sub f 5 8 |
| 197 | end |
| 198 | if eq k 25 |
| 199 | if lt f 2 |
| 200 | ret mul f 8 |
| 201 | end |
| 202 | ret add 16 mul sub f 2 4 |
| 203 | end |
| 204 | if eq k 26 |
| 205 | if lt f 6 |
| 206 | ret mul f 8 |
| 207 | end |
| 208 | if eq f 6 |
| 209 | ret 9240 |
| 210 | end |
| 211 | ret add 9248 mul sub f 7 4 |
| 212 | end |
| 213 | if eq k 1 |
| 214 | if eq f 0 |
| 215 | ret 0 |
| 216 | end |
| 217 | if eq f 1 |
| 218 | ret 8 |
| 219 | end |
| 220 | if eq f 2 |
| 221 | ret 12 |
| 222 | end |
| 223 | ret 4 |
| 224 | end |
| 225 | if eq k 2 |
| 226 | if eq f 2 |
| 227 | ret 48 |
| 228 | end |
| 229 | ret mul f 4 |
| 230 | end |
| 231 | if eq k 4 |
| 232 | ret mul f 8 |
| 233 | end |
| 234 | if eq k 5 |
| 235 | ret mul f 4 |
| 236 | end |
| 237 | if eq k 6 |
| 238 | ret mul f 8 |
| 239 | end |
| 240 | if eq k 7 |
| 241 | ret mul f 8 |
| 242 | end |
| 243 | if eq k 8 |
| 244 | if eq f 0 |
| 245 | ret 0 |
| 246 | end |
| 247 | if eq f 1 |
| 248 | ret 4 |
| 249 | end |
| 250 | if eq f 2 |
| 251 | ret 8 |
| 252 | end |
| 253 | ret 40 |
| 254 | end |
| 255 | if eq k 9 |
| 256 | if lt f 3 |
| 257 | ret mul f 4 |
| 258 | end |
| 259 | ret add 12 sub f 3 |
| 260 | end |
| 261 | if eq k 10 |
| 262 | if lt f 3 |
| 263 | ret mul f 4 |
| 264 | end |
| 265 | if lt f 6 |
| 266 | ret add 24 mul sub f 3 4 |
| 267 | end |
| 268 | if eq f 6 |
| 269 | ret 64 |
| 270 | end |
| 271 | if eq f 7 |
| 272 | ret 72 |
| 273 | end |
| 274 | ret 88 |
| 275 | end |
| 276 | if eq k 11 |
| 277 | if lt f 2 |
| 278 | ret mul f 4 |
| 279 | end |
| 280 | if eq f 2 |
| 281 | ret 8 |
| 282 | end |
| 283 | if eq f 3 |
| 284 | ret 16 |
| 285 | end |
| 286 | if eq f 4 |
| 287 | ret 24 |
| 288 | end |
| 289 | if eq f 5 |
| 290 | ret 28 |
| 291 | end |
| 292 | if eq f 6 |
| 293 | ret 32 |
| 294 | end |
| 295 | if eq f 7 |
| 296 | ret 64 |
| 297 | end |
| 298 | ret 128 |
| 299 | end |
| 300 | if eq k 12 |
| 301 | if eq f 1 |
| 302 | ret 12 |
| 303 | end |
| 304 | ret 0 |
| 305 | end |
| 306 | if eq k 13 |
| 307 | ret mul f 4 |
| 308 | end |
| 309 | if eq k 15 |
| 310 | ret f |
| 311 | end |
| 312 | if eq k 16 |
| 313 | if eq f 0 |
| 314 | ret 0 |
| 315 | end |
| 316 | if eq f 1 |
| 317 | ret 4 |
| 318 | end |
| 319 | if eq f 2 |
| 320 | ret 8 |
| 321 | end |
| 322 | if eq f 3 |
| 323 | ret 9 |
| 324 | end |
| 325 | if eq f 4 |
| 326 | ret 10 |
| 327 | end |
| 328 | if eq f 5 |
| 329 | ret 16 |
| 330 | end |
| 331 | if eq f 6 |
| 332 | ret 56 |
| 333 | end |
| 334 | if eq f 7 |
| 335 | ret 12 |
| 336 | end |
| 337 | ret 14 |
| 338 | end |
| 339 | if eq k 17 |
| 340 | ret mul f 4 |
| 341 | end |
| 342 | ret 0 |
| 343 | end |
| 344 | fn ns_width k ulong f ulong to ulong |
| 345 | if eq k 4 |
| 346 | if lt f 2 |
| 347 | ret 8 |
| 348 | end |
| 349 | end |
| 350 | if eq k 18 |
| 351 | if eq f 0 |
| 352 | ret 8 |
| 353 | end |
| 354 | end |
| 355 | if eq k 20 |
| 356 | if lt f 2 |
| 357 | ret 8 |
| 358 | end |
| 359 | end |
| 360 | if and ge k 21 le k 25 |
| 361 | if lt f 2 |
| 362 | ret 8 |
| 363 | end |
| 364 | if and eq k 24 and ge f 5 lt f 7 |
| 365 | ret 8 |
| 366 | end |
| 367 | end |
| 368 | if eq k 26 |
| 369 | if or lt f 5 eq f 6 |
| 370 | ret 8 |
| 371 | end |
| 372 | end |
| 373 | if or eq k 6 eq k 7 |
| 374 | if eq f 1 |
| 375 | ret 8 |
| 376 | end |
| 377 | end |
| 378 | if eq k 8 |
| 379 | if ge f 2 |
| 380 | ret 8 |
| 381 | end |
| 382 | end |
| 383 | if eq k 9 |
| 384 | if ge f 3 |
| 385 | ret 1 |
| 386 | end |
| 387 | end |
| 388 | if eq k 10 |
| 389 | if ge f 6 |
| 390 | ret 8 |
| 391 | end |
| 392 | end |
| 393 | if eq k 11 |
| 394 | if or eq f 2 eq f 7 |
| 395 | ret 8 |
| 396 | end |
| 397 | end |
| 398 | if eq k 15 |
| 399 | ret 1 |
| 400 | end |
| 401 | if eq k 16 |
| 402 | if or eq f 0 and ge f 2 le f 4 |
| 403 | ret 1 |
| 404 | end |
| 405 | if ge f 7 |
| 406 | ret 2 |
| 407 | end |
| 408 | end |
| 409 | ret 4 |
| 410 | end |
| 411 | fn ns_store b edit uchar * off ulong v ulong n ulong to void |
| 412 | for i ulong n |
| 413 | put b add off i uchar and shr v mul i 8 255 |
| 414 | end |
| 415 | end |
| 416 | fn ns_load b edit uchar * off ulong n ulong to ulong |
| 417 | v = ulong 0 |
| 418 | for i ulong n |
| 419 | v = or v shl ulong get b add off i mul i 8 |
| 420 | end |
| 421 | ret v |
| 422 | end |
| 423 | fn ns_uvmk cmd ulong to ulong |
| 424 | if eq cmd 805306369 |
| 425 | ret 18 |
| 426 | end |
| 427 | if eq cmd 75 |
| 428 | ret 19 |
| 429 | end |
| 430 | if or eq cmd 34 eq cmd 73 |
| 431 | ret 20 |
| 432 | end |
| 433 | if eq cmd 37 |
| 434 | ret 21 |
| 435 | end |
| 436 | if or eq cmd 38 eq cmd 26 |
| 437 | ret 22 |
| 438 | end |
| 439 | if eq cmd 25 |
| 440 | ret 23 |
| 441 | end |
| 442 | if eq cmd 27 |
| 443 | ret 24 |
| 444 | end |
| 445 | if eq cmd 28 |
| 446 | ret 25 |
| 447 | end |
| 448 | if eq cmd 33 |
| 449 | ret 26 |
| 450 | end |
| 451 | ret 0 |
| 452 | end |
| 453 | fn ns_arg a view ulong * i ulong to ulong |
| 454 | if ge i len a |
| 455 | ret 0 |
| 456 | end |
| 457 | ret get a i |
| 458 | end |
| 459 | fn ns_uenc k ulong a view ulong * b edit uchar * to ulong |
| 460 | v = new ulong 16 0 |
| 461 | uuid = new uchar 16 0 |
| 462 | cmd = ulong 0 |
| 463 | if le k 20 |
| 464 | put v 0 ns_arg a 0 |
| 465 | put v 1 ns_arg a 1 |
| 466 | if eq k 18 |
| 467 | cmd = 805306369 |
| 468 | end |
| 469 | if eq k 19 |
| 470 | cmd = 75 |
| 471 | end |
| 472 | if eq k 20 |
| 473 | cmd = 34 |
| 474 | end |
| 475 | else |
| 476 | if eq k 26 |
| 477 | nv_ustor uuid 0 ns_arg a 3 8 |
| 478 | nv_ustor uuid 8 ns_arg a 4 8 |
| 479 | put v 0 ns_arg a 0 |
| 480 | put v 1 ns_arg a 1 |
| 481 | put v 2 ns_arg a 2 |
| 482 | put v 3 ns_arg a 6 |
| 483 | put v 4 ns_arg a 7 |
| 484 | put v 5 ns_arg a 8 |
| 485 | put v 6 ns_arg a 9 |
| 486 | put v 7 ns_arg a 5 |
| 487 | else |
| 488 | nv_ustor uuid 0 ns_arg a 0 8 |
| 489 | nv_ustor uuid 8 ns_arg a 1 8 |
| 490 | for i ulong 5 |
| 491 | put v i ns_arg a add i 2 |
| 492 | end |
| 493 | if eq k 21 |
| 494 | cmd = 37 |
| 495 | end |
| 496 | if eq k 22 |
| 497 | cmd = 38 |
| 498 | end |
| 499 | if eq k 23 |
| 500 | cmd = 25 |
| 501 | end |
| 502 | if eq k 24 |
| 503 | cmd = 27 |
| 504 | end |
| 505 | if eq k 25 |
| 506 | cmd = 28 |
| 507 | end |
| 508 | end |
| 509 | end |
| 510 | n = ulong 0 |
| 511 | if eq k 26 |
| 512 | n = nv_umap v uuid b |
| 513 | else |
| 514 | n = nv_ubody cmd v uuid b |
| 515 | end |
| 516 | f = sub ns_count k 1 |
| 517 | nv_ustor b ns_off k f ns_arg a f 4 |
| 518 | ret n |
| 519 | end |
| 520 | fn nvrm_struct mode ulong k ulong a view ulong * b edit uchar * to ulong |
| 521 | if eq mode 8 |
| 522 | ret ns_size ns_uvmk k |
| 523 | end |
| 524 | if eq mode 7 |
| 525 | if or ne len b 184 lt len a 1 |
| 526 | ret 0 |
| 527 | end |
| 528 | if eq get a 0 0 |
| 529 | ret ns_load b 20 4 |
| 530 | end |
| 531 | if eq get a 0 1 |
| 532 | ret ns_load b 24 8 |
| 533 | end |
| 534 | if eq get a 0 2 |
| 535 | ret ns_load b 32 8 |
| 536 | end |
| 537 | ret 0 |
| 538 | end |
| 539 | if eq mode 6 |
| 540 | k = ns_uvmk k |
| 541 | if or eq k 0 ne len b ns_size k |
| 542 | ret 0 |
| 543 | end |
| 544 | ret ns_load b ns_off k sub ns_count k 1 4 |
| 545 | end |
| 546 | sz = ns_size k |
| 547 | if eq sz 0 |
| 548 | ret 0 |
| 549 | end |
| 550 | if eq mode 2 |
| 551 | ret sz |
| 552 | end |
| 553 | if eq mode 5 |
| 554 | ret ns_count k |
| 555 | end |
| 556 | if lt len a 1 |
| 557 | ret 0 |
| 558 | end |
| 559 | if or eq mode 3 eq mode 4 |
| 560 | f = get a 0 |
| 561 | if ge f ns_count k |
| 562 | ret 0 |
| 563 | end |
| 564 | if eq mode 3 |
| 565 | ret ns_off k f |
| 566 | end |
| 567 | ret ns_width k f |
| 568 | end |
| 569 | if ne len b sz |
| 570 | ret 0 |
| 571 | end |
| 572 | if eq mode 0 |
| 573 | if gt len a ns_count k |
| 574 | ret 0 |
| 575 | end |
| 576 | if ge k 18 |
| 577 | ret ns_uenc k a b |
| 578 | end |
| 579 | for i ulong sz |
| 580 | put b i 0 |
| 581 | end |
| 582 | for i ulong len a |
| 583 | ns_store b ns_off k i get a i ns_width k i |
| 584 | end |
| 585 | ret sz |
| 586 | end |
| 587 | if eq mode 1 |
| 588 | if lt len a 2 |
| 589 | ret 0 |
| 590 | end |
| 591 | f = get a 0 |
| 592 | idx = get a 1 |
| 593 | if ge f ns_count k |
| 594 | ret 0 |
| 595 | end |
| 596 | off = ns_off k f |
| 597 | if eq k 16 |
| 598 | if ge idx 64 |
| 599 | ret 0 |
| 600 | end |
| 601 | off = add off mul idx 72 |
| 602 | else |
| 603 | if eq k 5 |
| 604 | if gt f 0 |
| 605 | if ge idx 70 |
| 606 | ret 0 |
| 607 | end |
| 608 | off = add off mul idx 8 |
| 609 | end |
| 610 | end |
| 611 | end |
| 612 | ret ns_load b off ns_width k f |
| 613 | end |
| 614 | ret 0 |
| 615 | end |