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/omega-gpu-driver/blob/main/gsp/bindata.om # omega-gpu-driver aien-dev/omega-gpu-driver 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 `omega-gpu-driver / gsp / bindata.om` 1526 lines ยท 28406 bytes Raw Blame History 1 note gsp/bindata.om: the NVIDIA generated bindata reader in seeded Omega (OM-1). Ports the extract path 2 note of aienux PR #441 native/kernel/tools/ck_gsp_bindata_extract.c: refuse, next_line, after, 3 note parse_u32, copy_field, parse_hex_array, parse_pvt, parse_archive, parse_file, find_label, 4 note decode_desc, region_ok, check_semantics, report (stdout lines; no --out writing) and the read 5 note step of cmd_extract. Every refusal text is the C's, "line N: " prefix included. 6 note Library unit: no main. Prefix bd. Needs gsp/sha2.om, gsp/inflate.om and gsp/fw.om first 7 note (SHA-256/384, DEFLATE + CRC-32 + ISIZE, and the fwo* stdout writer). 8 note The text is read through a 1 MiB pread window (the C reads the whole file, at most 64 MiB, first; 9 note this port hashes the whole file first, so a read failure is still reported before any parse). 10 note Deviations (documented): arrays live in two 16 MiB pools, bdraw for compressed arrays as stored and 11 note bdpl for plain bytes (uncompressed arrays are parsed straight into bdpl). Running out of a pool is 12 note the C's own "out of memory for LABEL" refusal; the C would malloc up to MAX_ARRAY per array and 13 note DATA SIZE per inflated array. A directory path is refused as "File too large", the text the C 14 note prints on this host (glibc ftell on a directory). 15 const BDMAXB ulong 16 16 const BDPOOL ulong `16777216` 17 const BDMAXA ulong `8388608` 18 const BDNONE ulong 999 19 const BDUNS ulong `4294967295` 20 const BDWIN ulong `1048576` 21 global bdok ulong 1 22 global bdsgb ulong 160 23 global bdsgl ulong 160 24 global bdpath uchar 4096 25 global bdpathn ulong 1 26 global bdfd int 1 27 global bdst uchar 128 28 global bdfsz ulong 1 29 global bdfpos ulong 1 30 global bdtp ulong 1 31 global bdte ulong 1 32 global bdtx uchar `1048576` 33 global bdln uchar 520 34 global bdll ulong 1 35 global bdlno ulong 1 36 global bdrs uchar 256 37 global bdrsn ulong 1 38 global bdn ulong 1 39 global bdarc ulong 1 40 global bdcmp ulong 16 41 global bdds ulong 16 42 global bdcs ulong 16 43 global bdhh ulong 16 44 global bdhd ulong 16 45 global bdhp ulong 16 46 global bdnb ulong 16 47 global bdbo ulong 16 48 global bdpo ulong 16 49 global bdpn ulong 16 50 global bdfn uchar 1536 51 global bdfnl ulong 16 52 global bdlb uchar 1024 53 global bdlbl ulong 16 54 global bdfm uchar 2560 55 global bdfml ulong 16 56 global bdid uchar 3072 57 global bdidl ulong 16 58 global bdraw uchar `16777216` 59 global bdrtop ulong 1 60 global bdpl uchar `16777216` 61 global bdptop ulong 1 62 global bdimg uchar 64 63 global bdimgn ulong 1 64 global bdfsh uchar 64 65 note segment k of BDTXT is the text between the k-th and (k+1)-th '|': 1..76 refusal pieces in C 66 note wording, 77..114 the C's line prefixes and tokens, 115.. report pieces 67 text BDTXT "|line |: |line longer than 511 characters|array size out of range for |expected '{' after the array declaration of |out of memory for |file ends inside the array of |non-hex token in the array of |byte token without a trailing comma in |more bytes than the declared size in |fewer bytes than the declared size in |expected '{' in the storage record of |storage record: bad uncompressed size for |storage record: uncompressed size differs from DATA SIZE for |storage record: bad compressed size for |storage record: compressed size differs from the header for |storage record: missing pointer line for |storage record: data pointer is not the array of |storage record: missing compressed flag for |storage record: bad compressed flag for |storage record: compressed flag disagrees with COMPRESSION for |second archive table|archive table name is not the file's function|expected '{' after the archive declaration|archive: bad entryNum|archive: entryNum differs from the number of arrays|archive: expected entries block|archive: expected the entries comment|archive: missing entry |archive: malformed entry for |archive: entry order or label differs from the arrays at |archive: entry without a storage index for |archive: storage index is not this array for |archive: expected end of entries|archive: expected end of table|array | has no data or no storage record|more than 16 arrays|FUNCTION line without a BINDATA_LABEL|FUNCTION line not terminated|bad function name|bad label|array belongs to a different function: |duplicate label |function is not a kgspGetBinArchive function: |identifier too long for |data before the first FUNCTION header|bad file name for |FILE TYPE is not BINARY for |COMPRESSION is neither YES nor NO for |COMPLEX_STRUCT is not NO for |bad DATA SIZE for |bad COMPRESSED SIZE for |second array for |array header incomplete for |COMPRESSED SIZE missing with COMPRESSION YES for |COMPRESSED SIZE given with COMPRESSION NO for |array identifier is not the expected one for |storage record before the array of |second storage record for |no arrays found|no archive table|descriptor is not 84 bytes: |descriptor version is not 5: |descriptor monitor not enabled: |descriptor without a matching image: |descriptor manifest region outside the image or unaligned: |descriptor monitor-data region outside the image or unaligned: |descriptor monitor-code region outside the image or unaligned: |hash array is not 48 bytes|hash array without UCODE_IMAGE|UCODE_HASH is not SHA-384 of UCODE_IMAGE| is not 384 bytes|unknown label | (|)|// FUNCTION: |(\"BINDATA_LABEL_|\")|kgspGetBinArchive|kgspBinArchive|_BINDATA_LABEL_|_data|// FILE NAME: |// FILE TYPE: |BINARY|// COMPRESSION: |YES|NO|// COMPLEX_STRUCT: |// DATA SIZE (bytes): |// COMPRESSED SIZE (bytes): |N/A|static BINDATA_CONST NvU8 |[] = |#if defined(BINDATA_INCLUDE_STORAGE_PVT_DEFN)|static const BINDATA_ARCHIVE __|static BINDATA_CONST|static const BINDATA_ARCHIVE|{|};|NV_TRUE,|NV_FALSE,| =|// entries[]|{ BINDATA_LABEL_|&g_bindata_pvt[__idx_|}|UCODE_DESC|UCODE_IMAGE|UCODE_HASH|UCODE_SIG|UCODE_PKEY|//|function | arrays=|desc | version=| manifest=0x|+0x| monitor_data=0x| monitor_code=0x| monitor_enabled=| fb_reserved=0x| signed_as_code=| app_version=| image=|/|hash384 UCODE_HASH equals sha384(UCODE_IMAGE)| file=| stored=| compressed=|yes|no| size=| sha256=|RESULT OK arrays=|REFUSED: |REFUSED: cannot read | |" 68 note build the segment table and reset the pools (call once per program) 69 fn bdsetup to void 70 if eq get bdok 0 1 71 ret 72 end 73 put bdok 0 1 74 fwsetup 75 infsetup 76 seg = ulong 0 77 for i ulong len BDTXT 78 c = get BDTXT i 79 if eq c 124 80 seg = add seg 1 81 put bdsgb seg add i 1 82 put bdsgl seg 0 83 else 84 put bdsgl seg add get bdsgl seg 1 85 end 86 end 87 put bdrtop 0 0 88 put bdptop 0 0 89 end 90 note ---- printing through the fw.om writer ---- 91 fn bdos k ulong to void 92 b = get bdsgb k 93 for i ulong get bdsgl k 94 fwoc get BDTXT add b i 95 end 96 end 97 fn bdolab i ulong to void 98 b = mul i 64 99 for j ulong get bdlbl i 100 fwoc get bdlb add b j 101 end 102 end 103 fn bdofn i ulong to void 104 b = mul i 96 105 for j ulong get bdfnl i 106 fwoc get bdfn add b j 107 end 108 end 109 fn bdofm i ulong to void 110 b = mul i 160 111 for j ulong get bdfml i 112 fwoc get bdfm add b j 113 end 114 end 115 fn bdopath to void 116 for i ulong get bdpathn 0 117 fwoc get bdpath i 118 end 119 end 120 note ---- the refusal reason (C f->reason, 256 bytes: at most 255 characters kept) ---- 121 fn bdrc c uchar to void 122 n = get bdrsn 0 123 if lt n 255 124 put bdrs n c 125 put bdrsn 0 add n 1 126 end 127 end 128 fn bdrseg k ulong to void 129 b = get bdsgb k 130 for i ulong get bdsgl k 131 bdrc get BDTXT add b i 132 end 133 end 134 fn bdrlab i ulong to void 135 b = mul i 64 136 for j ulong get bdlbl i 137 bdrc get bdlb add b j 138 end 139 end 140 fn bdrfn i ulong to void 141 b = mul i 96 142 for j ulong get bdfnl i 143 bdrc get bdfn add b j 144 end 145 end 146 note "line N: " (C refuse: N is the cursor's line count, 0 when the cursor is NULL) 147 fn bdrhd ln ulong to void 148 put bdrsn 0 0 149 bdrseg 1 150 d = new uchar 24 0 151 n = ulong 0 152 x = ln 153 while lt n 24 bound 24 154 put d n add uchar rem x 10 48 155 n = add n 1 156 x = div x 10 157 if eq x 0 158 break 159 end 160 end 161 while gt n 0 bound 24 162 n = sub n 1 163 bdrc get d n 164 end 165 bdrseg 2 166 end 167 note refuse at the current line with reason k, then the label of block b unless b is BDNONE 168 fn bdrl k ulong b ulong to ulong 169 bdrhd get bdlno 0 170 bdrseg k 171 if ne b BDNONE 172 bdrlab b 173 end 174 ret 2 175 end 176 note refuse at the current line with reason k and the function name of block b 177 fn bdrf k ulong b ulong to ulong 178 bdrhd get bdlno 0 179 bdrseg k 180 bdrfn b 181 ret 2 182 end 183 note refuse with line 0 (semantic checks) with reason k, then the label of b unless BDNONE 184 fn bdr0 k ulong b ulong to ulong 185 bdrhd 0 186 bdrseg k 187 if ne b BDNONE 188 bdrlab b 189 end 190 ret 2 191 end 192 note "array LABEL has no data or no storage record" at the current line 193 fn bdrnd b ulong to ulong 194 bdrhd get bdlno 0 195 bdrseg 36 196 bdrlab b 197 bdrseg 37 198 ret 2 199 end 200 note ---- the text window and C next_line ---- 201 note keep at least 512 unread bytes in bdtx unless the file is used up: 0, or 3 on a read error 202 fn bdfill to ulong 203 tp = get bdtp 0 204 av = sub get bdte 0 tp 205 if ge av 512 206 ret 0 207 end 208 fp = get bdfpos 0 209 if ge fp get bdfsz 0 210 ret 0 211 end 212 for i ulong av 213 put bdtx i get bdtx add tp i 214 end 215 put bdtp 0 0 216 put bdte 0 av 217 w = sub BDWIN av 218 lf = sub get bdfsz 0 fp 219 if lt lf w 220 w = lf 221 end 222 q = ulong 0 223 while lt q w bound 999999 224 r = pread get bdfd 0 bdtx add av q sub w q long add fp q 225 if lt r 1 226 ret 3 227 end 228 q = add q ulong r 229 end 230 put bdte 0 add av w 231 put bdfpos 0 add fp w 232 ret 0 233 end 234 note C next_line into bdln[0..bdll): 1 = a line, 0 = end of text, 2 = longer than 511 characters 235 note (reason set, line count advanced), 3 = read error. A trailing CR is dropped and the line ends 236 note at its first NUL (the C's string view of its buffer). 237 fn bdnext to ulong 238 e = bdfill 239 if ne e 0 240 ret 3 241 end 242 tp = get bdtp 0 243 te = get bdte 0 244 if ge tp te 245 ret 0 246 end 247 lim = add tp 512 248 if gt lim te 249 lim = te 250 end 251 j = tp 252 nl = ulong 0 253 while lt j lim bound 600 254 if eq get bdtx j 10 255 nl = 1 256 break 257 end 258 j = add j 1 259 end 260 put bdlno 0 add get bdlno 0 1 261 n = sub j tp 262 if ge n 512 263 bdrhd get bdlno 0 264 bdrseg 3 265 ret 2 266 end 267 for i ulong n 268 put bdln i get bdtx add tp i 269 end 270 if gt n 0 271 if eq get bdln sub n 1 13 272 n = sub n 1 273 end 274 end 275 k = ulong 0 276 while lt k n bound 600 277 if eq get bdln k 0 278 break 279 end 280 k = add k 1 281 end 282 put bdln k 0 283 put bdll 0 k 284 if eq nl 1 285 put bdtp 0 add j 1 286 else 287 put bdtp 0 te 288 end 289 ret 1 290 end 291 note ---- string helpers over the line ---- 292 fn bdlc i ulong to uchar 293 if ge i get bdll 0 294 ret 0 295 end 296 ret get bdln i 297 end 298 note does the line at p start with segment k (C after / strncmp)? 299 fn bdpre p ulong k ulong to ulong 300 b = get bdsgb k 301 l = get bdsgl k 302 if gt add p l get bdll 0 303 ret 0 304 end 305 for i ulong l 306 if ne get bdln add p i get BDTXT add b i 307 ret 0 308 end 309 end 310 ret 1 311 end 312 note is the line from p to its end exactly segment k (C strcmp)? 313 fn bdeqs p ulong k ulong to ulong 314 L = get bdll 0 315 if gt p L 316 ret 0 317 end 318 if ne sub L p get bdsgl k 319 ret 0 320 end 321 ret bdpre p k 322 end 323 note C strspn(line + p, " ") 324 fn bdsp p ulong to ulong 325 q = p 326 L = get bdll 0 327 while lt q L bound 600 328 if ne get bdln q 32 329 break 330 end 331 q = add q 1 332 end 333 ret q 334 end 335 note first position at or after p where segment k occurs (C strstr), BDNONE if none 336 fn bdfind p ulong k ulong to ulong 337 q = p 338 L = get bdll 0 339 while le q L bound 600 340 if eq bdpre q k 1 341 ret q 342 end 343 q = add q 1 344 end 345 ret BDNONE 346 end 347 note first '(' at or after p (C strchr), BDNONE if none 348 fn bdfpar p ulong to ulong 349 q = p 350 L = get bdll 0 351 while lt q L bound 600 352 if eq get bdln q 40 353 ret q 354 end 355 q = add q 1 356 end 357 ret BDNONE 358 end 359 note C parse_u32 at p: decimal at most `4294967295`, then spaces, commas or tabs, then the end or "//" 360 fn bdu32 p ulong to long 361 c = bdlc p 362 if lt c 48 363 ret -1 364 end 365 if gt c 57 366 ret -1 367 end 368 acc = ulong 0 369 q = p 370 while lt q get bdll 0 bound 600 371 c = get bdln q 372 if lt c 48 373 break 374 end 375 if gt c 57 376 break 377 end 378 acc = add mul acc 10 sub ulong c 48 379 if gt acc BDUNS 380 ret -1 381 end 382 q = add q 1 383 end 384 while lt q get bdll 0 bound 600 385 c = get bdln q 386 if and and ne c 32 ne c 44 ne c 9 387 break 388 end 389 q = add q 1 390 end 391 if lt q get bdll 0 392 if eq bdpre q 114 0 393 ret -1 394 end 395 end 396 ret long acc 397 end 398 note does the line at p hold the first n characters of block i's identifier? 399 fn bdlnid p ulong i ulong n ulong to ulong 400 if gt add p n get bdll 0 401 ret 0 402 end 403 b = mul i 192 404 for j ulong n 405 if ne get bdln add p j get bdid add b j 406 ret 0 407 end 408 end 409 ret 1 410 end 411 note does the line at p start with block i's label? 412 fn bdlnlb p ulong i ulong to ulong 413 n = get bdlbl i 414 if gt add p n get bdll 0 415 ret 0 416 end 417 b = mul i 64 418 for j ulong n 419 if ne get bdln add p j get bdlb add b j 420 ret 0 421 end 422 end 423 ret 1 424 end 425 note does the line at p start with block i's function name? 426 fn bdlnfn p ulong i ulong to ulong 427 n = get bdfnl i 428 if gt add p n get bdll 0 429 ret 0 430 end 431 b = mul i 96 432 for j ulong n 433 if ne get bdln add p j get bdfn add b j 434 ret 0 435 end 436 end 437 ret 1 438 end 439 note labels of blocks i and j equal? 440 fn bdlbeq i ulong j ulong to ulong 441 n = get bdlbl i 442 if ne n get bdlbl j 443 ret 0 444 end 445 a = mul i 64 446 b = mul j 64 447 for k ulong n 448 if ne get bdlb add a k get bdlb add b k 449 ret 0 450 end 451 end 452 ret 1 453 end 454 note function names of blocks i and j equal? 455 fn bdfneq i ulong j ulong to ulong 456 n = get bdfnl i 457 if ne n get bdfnl j 458 ret 0 459 end 460 a = mul i 96 461 b = mul j 96 462 for k ulong n 463 if ne get bdfn add a k get bdfn add b k 464 ret 0 465 end 466 end 467 ret 1 468 end 469 note label of block i starts with segment k (sw 0) or equals it (sw 1)? 470 fn bdlbsg i ulong k ulong sw ulong to ulong 471 n = get bdlbl i 472 l = get bdsgl k 473 if lt n l 474 ret 0 475 end 476 if eq sw 1 477 if ne n l 478 ret 0 479 end 480 end 481 a = mul i 64 482 b = get bdsgb k 483 for j ulong l 484 if ne get bdlb add a j get BDTXT add b j 485 ret 0 486 end 487 end 488 ret 1 489 end 490 note function name of block i starts with segment k? 491 fn bdfnsg i ulong k ulong to ulong 492 n = get bdfnl i 493 l = get bdsgl k 494 if lt n l 495 ret 0 496 end 497 a = mul i 96 498 b = get bdsgb k 499 for j ulong l 500 if ne get bdfn add a j get BDTXT add b j 501 ret 0 502 end 503 end 504 ret 1 505 end 506 note C find_label for the name in bdimg[0..bdimgn): block index or BDNONE 507 fn bdfimg to ulong 508 for i ulong get bdn 0 509 n = get bdlbl i 510 if eq n get bdimgn 0 511 a = mul i 64 512 m = ulong 1 513 for j ulong n 514 if ne get bdlb add a j get bdimg j 515 m = 0 516 end 517 end 518 if eq m 1 519 ret i 520 end 521 end 522 end 523 ret BDNONE 524 end 525 note C find_label for segment k: block index or BDNONE 526 fn bdfseg k ulong to ulong 527 for i ulong get bdn 0 528 if eq bdlbsg i k 1 1 529 ret i 530 end 531 end 532 ret BDNONE 533 end 534 note ---- C copy_field into the block's fields (len checked by the caller) ---- 535 fn bdsetfn i ulong p ulong n ulong to void 536 b = mul i 96 537 for j ulong n 538 put bdfn add b j get bdln add p j 539 end 540 put bdfnl i n 541 end 542 fn bdsetlb i ulong p ulong n ulong to void 543 b = mul i 64 544 for j ulong n 545 put bdlb add b j get bdln add p j 546 end 547 put bdlbl i n 548 end 549 fn bdsetfm i ulong p ulong n ulong to void 550 b = mul i 160 551 for j ulong n 552 put bdfm add b j get bdln add p j 553 end 554 put bdfml i n 555 end 556 note append segment k to block i's identifier at q; returns the new end 557 fn bdidsg i ulong q ulong k ulong to ulong 558 b = mul i 192 559 s = get bdsgb k 560 for j ulong get bdsgl k 561 put bdid add b add q j get BDTXT add s j 562 end 563 ret add q get bdsgl k 564 end 565 note identifier kgspBinArchive_BINDATA_LABEL_