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-mv/blob/main/gpu/driver/gsp/logdec.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / driver / gsp / logdec.om` 1059 lines ยท 20904 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note gsp/logdec.om: Pure-Omega (OM-1) LibosLog and CrashCat decoder for GB20B GSP bring-up. 3 note Host-only decoder over caller-supplied memory images; never opens a device, maps MMIO, or performs DMA. 4 note Verified GB20B arena layout reference: gpu/driver/gsp/arena.om (arlogs, arlogpt, arnames). 5 note LibosMemoryRegionInitArgument: 32 bytes/entry (+0 id8 BE-ASCII, +8 pa, +16 size, +24 kind=1, +25 loc=1). 6 note Verified 8 GB20B region IDs (arena.om:42,271-289): 7 note LOGINIT=0x004c4f47494e4954 (64 KiB), LOGINTR=0x004c4f47494e5452 (64 KiB), 8 note LOGRM=0x0000004c4f47524d (64 KiB), LOGMNOC=0x004c4f474d4e4f43 (64 KiB), 9 note LOGDBG=0x00004c4f47444247 (64 KiB), LOGROOT=0x004c4f47524f4f54 (4 KiB), 10 note LOGKRNL=0x004c4f474b524e4c (64 KiB), RMARGS=0x0000524d41524753 (4 KiB). 11 note Verified paged log-buffer header (arena.om:260-270 arlogpt): 12 note Page 0 (4096 bytes): +0 u64 LE put (monotonic byte offset), +8..+8+8*n page_table[0..n-1] (pa + j*4096). 13 note Pages 1..n-1 (size - 4096 bytes): circular u64-slot ring data (61440 bytes = 7680 qwords for 64 KiB). 14 note LOGROOT (4096 bytes) has 0 data bytes and is handled without division by zero. 15 note CrashCat V1 wire format (NVIDIA open-gpu-kernel-modules 580.173.02 nv-crashcat.h): 16 note NvCrashCatPacketHeader_V1 (u64 LE): [63:48] sig=0xCA70 (51824), [47:44] ver=1, 17 note [43:40] type (0=REPORT,1=STACK_TRACE,2=REG32,3=REG64,4=IO32,5=IO64,6=RV64_CSR,7=RV64_GPR,8=RV64_TRACE), 18 note [39:32] payload_qwords (0..255), [31:0] header_data. 19 note Prefix lg (LibosLog/RMARGS/formatter) and cc (CrashCat). Library unit: no main. 20 21 note ---- Region ID constants (verified via Python from ASCII big-endian packing in arena.om:274-278) ---- 22 const LGIDINIT ulong `21479265821149524` 23 const LGIDINTR ulong `21479265821152338` 24 const LGIDRM ulong `327747588685` 25 const LGIDMNOC ulong `21479265888259907` 26 const LGIDDBG ulong `83903381783111` 27 const LGIDROOT ulong `21479265972211540` 28 const LGIDKRNL ulong `21479265854967372` 29 const LGIDARGS ulong `90491761870675` 30 31 note ---- Buffer and limit constants ---- 32 const LGPAGE ulong 4096 33 const LGBMAX ulong 65536 34 const LGTMAX ulong 32 35 const LGMAXA ulong 20 36 const LGOCAP ulong 4096 37 const LGU32 ulong `4294967295` 38 const LGFMTM ulong `281474976710655` 39 const LGWPRMAG ulong `15869187694674993331` 40 const LGWPRSZ ulong 256 41 const LGRMASZ ulong 128 42 const LGCCQPA ulong 224 43 const LGCCQSZ ulong 232 44 45 note ---- CrashCat V1 constants (0xCA70 = 51824) ---- 46 const CCSIG ulong 51824 47 const CCVER1 ulong 1 48 const CCTRPT ulong 0 49 const CCTSTK ulong 1 50 const CCTR32 ulong 2 51 const CCTR64 ulong 3 52 const CCTI32 ulong 4 53 const CCTI64 ulong 5 54 const CCTCSR ulong 6 55 const CCTGPR ulong 7 56 const CCTTRC ulong 8 57 const CCMAXT ulong 8 58 const CCMAXP ulong 256 59 const CCRMIN ulong 5 60 const CCGPRN ulong 31 61 62 note ---- WPR meta (256 B) and RMARGS (128 B) inspection state ---- 63 global lgwpr uchar 256 64 global lgccqpa ulong 1 65 global lgccqsz ulong 1 66 global lgrma uchar 128 67 note lgrmout: 0 sharedPA, 1 ptCount, 2 cmdOff, 3 statOff, 4 gpuInst, 5 passthru, 6 heapPA, 7 heapBytes 68 global lgrmout ulong 8 69 70 note ---- LibosMemoryRegionInitArgument table state ---- 71 global lgtbuf uchar 4096 72 global lgtcnt ulong 1 73 global lgtid ulong 32 74 global lgtpa ulong 32 75 global lgtsz ulong 32 76 global lgtkl ulong 32 77 78 note ---- LibosLog ring buffer and decoded record state ---- 79 global lgbuf uchar 65536 80 global lgsize ulong 1 81 global lghdr ulong 1 82 global lgdata ulong 1 83 global lgput ulong 1 84 global lgget ulong 1 85 global lgdrop ulong 1 86 global lgwrap ulong 1 87 global lgrcnt ulong 1 88 global lgfmt ulong 1 89 global lgts ulong 1 90 global lgargc ulong 1 91 global lglvl ulong 1 92 global lgflg ulong 1 93 global lgargs ulong 20 94 95 note ---- CrashCat linear buffer and decoded packet state ---- 96 global ccbuf uchar 65536 97 global cclen ulong 1 98 global ccpos ulong 1 99 global ccver ulong 1 100 global cctype ulong 1 101 global ccplen ulong 1 102 global cchdat ulong 1 103 global ccpay ulong 256 104 global ccrsrc ulong 1 105 global ccrcse ulong 1 106 global ccrext ulong 1 107 global ccrts ulong 1 108 global ccrver ulong 1 109 110 note ---- Buffered diagnostic formatter state (stdout/caller fd) ---- 111 global lgob uchar 4096 112 global lgon ulong 1 113 global lgofd int 1 114 global lgoerr ulong 1 115 text LGHEX "`0123456789abcdef`" 116 text LGREG0 "LOGINIT" 117 text LGREG1 "LOGINTR" 118 text LGREG2 "LOGRM" 119 text LGREG3 "LOGMNOC" 120 text LGREG4 "LOGDBG" 121 text LGREG5 "LOGROOT" 122 text LGREG6 "LOGKRNL" 123 text LGREG7 "RMARGS" 124 text LGREGU "UNKNOWN" 125 text LGKREG "REGION " 126 text LGKPA " pa=0x" 127 text LGKSZ " size=0x" 128 text LGKKD " kind=" 129 text LGKLC " loc=" 130 text LGKLOG "LOG ts=0x" 131 text LGKLVL " lvl=" 132 text LGKFMT " fmt=0x" 133 text LGKARC " argc=" 134 text LGKARG " args=[" 135 text LGKCC "CRASHCAT " 136 text LGKVER " ver=" 137 text LGKHD " hdata=0x" 138 text LGKSRC " src=0x" 139 text LGKCSE " cause=0x" 140 text LGKEXT " extra=0x" 141 text LGKTS " ts=0x" 142 text LGKRVR " rver=0x" 143 text LGKCNT " count=" 144 text LGKOFF " off=0x" 145 text LGKVAL " val=0x" 146 text LGK0X "0x" 147 text LGCT0 "REPORT" 148 text LGCT1 "STACK_TRACE" 149 text LGCT2 "REGISTER32" 150 text LGCT3 "REGISTER64" 151 text LGCT4 "IO32_STATE" 152 text LGCT5 "IO64_STATE" 153 text LGCT6 "RISCV64_CSR" 154 text LGCT7 "RISCV64_GPR" 155 text LGCT8 "RISCV64_TRACE" 156 157 note ==== Low-level little-endian readers (bounds-checked by callers) ==== 158 159 fn lgu64t o ulong to ulong 160 v = ulong 0 161 for i ulong 8 162 b = ulong get lgtbuf add o i 163 v = or v shl b mul i 8 164 end 165 ret v 166 end 167 168 fn lgu64w o ulong to ulong 169 v = ulong 0 170 for i ulong 8 171 b = ulong get lgwpr add o i 172 v = or v shl b mul i 8 173 end 174 ret v 175 end 176 177 fn lgu64r o ulong to ulong 178 v = ulong 0 179 for i ulong 8 180 b = ulong get lgrma add o i 181 v = or v shl b mul i 8 182 end 183 ret v 184 end 185 186 fn lgu32r o ulong to ulong 187 v = ulong 0 188 for i ulong 4 189 b = ulong get lgrma add o i 190 v = or v shl b mul i 8 191 end 192 ret v 193 end 194 195 note ==== GspFwWprMeta CrashCat queue locator (gb20b-gsp-boot.md:17, arena.om:312-325) ==== 196 note Verifies lgwpr[0..256): +0 magic==0xdc3aae21371a60b3, +8 rev==1, 197 note extracts +224 sysmemAddrOfCrashReportQueue and +232 sizeOfCrashReportQueue. 198 note Returns: 199 note 1 CrashCat queue present (lgccqpa, lgccqsz populated; page-aligned and non-zero) 200 note 0 WPR meta valid, CrashCat queue absent (both +224 and +232 are 0) 201 note -1 bad magic or revision 202 note -2 malformed CrashCat queue descriptor (unaligned PA/size, size > LGBMAX, or one zero) 203 204 fn lgwprparse to long 205 put lgccqpa 0 0 206 put lgccqsz 0 0 207 if ne lgu64w 0 LGWPRMAG 208 ret -1 209 end 210 if ne lgu64w 8 1 211 ret -1 212 end 213 pa = lgu64w LGCCQPA 214 sz = lgu64w LGCCQSZ 215 if and eq pa 0 eq sz 0 216 ret 0 217 end 218 if or eq pa 0 eq sz 0 219 ret -2 220 end 221 if or ne and pa 4095 0 ne and sz 4095 0 222 ret -2 223 end 224 if gt sz LGBMAX 225 ret -2 226 end 227 put lgccqpa 0 pa 228 put lgccqsz 0 sz 229 ret 1 230 end 231 232 note ==== RMARGS (GSP_ARGUMENTS_CACHED) parser (arena.om:294-303) ==== 233 note Extracts sharedMemPhysAddr (+0), ptCount (+8 u32), cmdQueueOffset (+16), 234 note statQueueOffset (+24), gpuInstance (+44 u32), bIsPassthru (+48 u8), 235 note heapPA (+72), heapBytes (+80) from lgrma[0..128) into lgrmout[0..7]. 236 note Returns 0 on valid GB20B/arena.om shape, -1 on alignment/offset violation. 237 238 fn lgrmargs to long 239 for i ulong 8 240 put lgrmout i 0 241 end 242 spa = lgu64r 0 243 ptc = lgu32r 8 244 cmdo = lgu64r 16 245 stato = lgu64r 24 246 if or eq spa 0 ne and spa 4095 0 247 ret -1 248 end 249 if eq ptc 0 250 ret -1 251 end 252 if or ne cmdo LGPAGE lt stato cmdo 253 ret -1 254 end 255 hpa = lgu64r 72 256 hsz = lgu64r 80 257 if or ne and hpa 4095 0 ne and hsz 4095 0 258 ret -1 259 end 260 put lgrmout 0 spa 261 put lgrmout 1 ptc 262 put lgrmout 2 cmdo 263 put lgrmout 3 stato 264 put lgrmout 4 lgu32r 44 265 put lgrmout 5 ulong get lgrma 48 266 put lgrmout 6 hpa 267 put lgrmout 7 hsz 268 ret 0 269 end 270 271 fn lgu64b o ulong to ulong 272 v = ulong 0 273 for i ulong 8 274 b = ulong get lgbuf add o i 275 v = or v shl b mul i 8 276 end 277 ret v 278 end 279 280 fn ccu64b o ulong to ulong 281 v = ulong 0 282 for i ulong 8 283 b = ulong get ccbuf add o i 284 v = or v shl b mul i 8 285 end 286 ret v 287 end 288 289 note ==== Region ID classification ==== 290 291 fn lgkind id ulong to long 292 if eq id LGIDINIT 293 ret 0 294 end 295 if eq id LGIDINTR 296 ret 1 297 end 298 if eq id LGIDRM 299 ret 2 300 end 301 if eq id LGIDMNOC 302 ret 3 303 end 304 if eq id LGIDDBG 305 ret 4 306 end 307 if eq id LGIDROOT 308 ret 5 309 end 310 if eq id LGIDKRNL 311 ret 6 312 end 313 if eq id LGIDARGS 314 ret 7 315 end 316 ret -1 317 end 318 319 note ==== LibosMemoryRegionInitArgument table parser ==== 320 note Reads up to LGTMAX (32) 32-byte entries from lgtbuf[0..n). 321 note Stops at the first zero id8 terminator or when n bytes are consumed. 322 note Returns entry count (>=0) on success, or negative error: 323 note -1 bad table length (not multiple of 32 or > 4096) 324 note -2 non-zero reserved bytes (+26..+31) 325 note -3 invalid kind/loc (must be kind=1, loc=1) or unaligned/zero pa/size 326 note -4 exceeds LGTMAX entries without terminator 327 328 fn lgtabparse n ulong to long 329 put lgtcnt 0 0 330 if or eq n 0 gt n LGPAGE 331 ret -1 332 end 333 if ne rem n 32 0 334 ret -1 335 end 336 maxe = div n 32 337 cnt = ulong 0 338 for i ulong maxe 339 off = mul i 32 340 id = lgu64t off 341 if eq id 0 342 break 343 end 344 if ge cnt LGTMAX 345 ret -4 346 end 347 for r ulong 6 348 if ne get lgtbuf add off add 26 r 0 349 ret -2 350 end 351 end 352 pa = lgu64t add off 8 353 sz = lgu64t add off 16 354 if ne ulong get lgtbuf add off 24 1 355 ret -3 356 end 357 if ne ulong get lgtbuf add off 25 1 358 ret -3 359 end 360 if eq sz 0 361 ret -3 362 end 363 if or ne and pa 4095 0 ne and sz 4095 0 364 ret -3 365 end 366 put lgtid cnt id 367 put lgtpa cnt pa 368 put lgtsz cnt sz 369 put lgtkl cnt 257 370 cnt = add cnt 1 371 end 372 put lgtcnt 0 cnt 373 ret long cnt 374 end 375 376 note ==== Paged LibosLog page-table validator (matches arena.om:arlogpt) ==== 377 note Verifies lgbuf[0..total_size) page 0 page table entries at +8..+8+8*npages 378 note equal base_pa + j*4096 for j in 0..npages-1. 379 note Returns 0 on success, -1 invalid size/alignment, -2 page-table entry mismatch. 380 381 fn lgptchk basepa ulong totsize ulong to long 382 if or lt totsize LGPAGE gt totsize LGBMAX 383 ret -1 384 end 385 if or ne and totsize 4095 0 ne and basepa 4095 0 386 ret -1 387 end 388 np = div totsize LGPAGE 389 if gt np 511 390 ret -1 391 end 392 for j ulong np 393 off = add 8 mul j 8 394 want = add basepa mul j LGPAGE 395 got = lgu64b off 396 if ne got want 397 ret -2 398 end 399 end 400 ret 0 401 end 402 403 note ==== LibosLog ring buffer control and wrap-around reader ==== 404 note lgrinit configures a ring buffer in lgbuf[0..totsize) with data starting at hdrsize. 405 note Standard arena.om paged buffers use hdrsize=4096 (data=61440 for 64 KiB, data=0 for LOGROOT 4 KiB). 406 note Linear header-only buffers may use hdrsize=8. 407 note Returns 0 on success, -1 invalid geometry. 408 409 fn lgrinit totsize ulong hdrsize ulong to long 410 put lgsize 0 0 411 put lghdr 0 0 412 put lgdata 0 0 413 put lgput 0 0 414 put lgget 0 0 415 put lgdrop 0 0 416 put lgwrap 0 0 417 put lgrcnt 0 0 418 if or lt totsize 8 gt totsize LGBMAX 419 ret -1 420 end 421 if or lt hdrsize 8 gt hdrsize totsize 422 ret -1 423 end 424 if ne and hdrsize 7 0 425 ret -1 426 end 427 dat = sub totsize hdrsize 428 if ne and dat 7 0 429 ret -1 430 end 431 put lgsize 0 totsize 432 put lghdr 0 hdrsize 433 put lgdata 0 dat 434 ret 0 435 end 436 437 note lgrsetget allows a caller to restore a saved host cursor (must be 8-byte aligned). 438 fn lgrsetget g ulong to long 439 if ne and g 7 0 440 ret -3 441 end 442 put lgget 0 g 443 ret 0 444 end 445 446 note lgrsync reads the firmware put pointer at lgbuf[0..8), validates it against lgget, 447 note and handles ring wrap-around overflow by advancing lgget to (put - lgdata) and 448 note accumulating dropped byte count in lgdrop and wrap count in lgwrap. 449 note Returns available unread bytes (>=0) on success, or negative error: 450 note -1 ring not initialized (lgsize < 8) 451 note -2 put < get (cursor regression or reset) 452 note -3 put not 8-byte aligned 453 note -4 non-zero put in a zero-data buffer (e.g. 4 KiB LOGROOT) 454 455 fn lgrsync to long 456 sz = get lgsize 0 457 if lt sz 8 458 ret -1 459 end 460 p = lgu64b 0 461 if ne and p 7 0 462 ret -3 463 end 464 g = get lgget 0 465 if lt p g 466 ret -2 467 end 468 put lgput 0 p 469 dat = get lgdata 0 470 if eq dat 0 471 if gt p 0 472 ret -4 473 end 474 ret 0 475 end 476 avail = sub p g 477 if gt avail dat 478 dropped = sub avail dat 479 put lgdrop 0 add get lgdrop 0 dropped 480 put lgwrap 0 add get lgwrap 0 1 481 g = sub p dat 482 put lgget 0 g 483 avail = dat 484 end 485 ret long avail 486 end 487 488 note lgrqword reads one 64-bit LE word at logical byte offset pos (8-byte aligned), 489 note wrapping modulo lgdata inside lgbuf[lghdr .. lghdr + lgdata). 490 note Caller must guarantee lgdata >= 8 and pos is 8-byte aligned. 491 492 fn lgrqword pos ulong to ulong 493 dat = get lgdata 0 494 if lt dat 8 495 ret 0 496 end 497 off = add get lghdr 0 rem pos dat 498 if gt add off 8 get lgsize 0 499 ret 0 500 end 501 ret lgu64b off 502 end 503 504 note lgpeek inspects the next u64 word (format ID / meta_va) without advancing lgget. 505 note Returns 1 if a word is available (stored in lgfmt), 0 if empty, or negative error from lgrsync. 506 507 fn lgpeek to long 508 av = lgrsync 509 if le av 0 510 ret av 511 end 512 if lt av 8 513 ret -6 514 end 515 put lgfmt 0 lgrqword get lgget 0 516 ret 1 517 end 518 519 note lgnext decodes one self-describing framed LibosLog record from the ring buffer. 520 note Slot 0 (meta word): 521 note [47:0] format_id (48-bit metadata VA / format ID) 522 note [55:48] argc (0..20) 523 note [59:56] level (0..15) 524 note [63:60] flags (bit 0 = has_timestamp) 525 note Slot 1 (if flags & 1 != 0): 64-bit PTIMER timestamp (ns). 526 note Next argc slots: u64 arguments stored in lgargs[0..argc-1]. 527 note Returns: 528 note 1 record decoded (lgfmt, lgts, lgargc, lglvl, lgflg, lgargs updated; lgget advanced) 529 note 0 empty (no unread bytes) 530 note -1..-4 sync errors from lgrsync 531 note -5 argc > LGMAXA (20) 532 note -6 truncated record (not enough unread bytes; lgget unchanged) 533 534 fn lgnext to long 535 av = lgrsync 536 if le av 0 537 ret av 538 end 539 if lt av 8 540 ret -6 541 end 542 pos = get lgget 0 543 meta = lgrqword pos 544 argc = and shr meta 48 255 545 if gt argc LGMAXA 546 ret -5 547 end 548 hasts = and shr meta 60 1 549 needb = mul add 1 add hasts argc 8 550 if lt ulong av needb 551 ret -6 552 end 553 put lgfmt 0 and meta LGFMTM 554 put lgargc 0 argc 555 put lglvl 0 and shr meta 56 15 556 put lgflg 0 and shr meta 60 15 557 pos = add pos 8 558 if eq hasts 1 559 put lgts 0 lgrqword pos 560 pos = add pos 8 561 else 562 put lgts 0 0 563 end 564 for i ulong argc 565 put lgargs i lgrqword pos 566 pos = add pos 8 567 end 568 put lgget 0 pos 569 put lgrcnt 0 add get lgrcnt 0 1 570 ret 1 571 end 572 573 note lgnextraw decodes one ELF-metadata-linked LibosLog record where the caller supplies 574 note argc (0..20) and hasts (0 or 1) obtained from the firmware .logging section for lgfmt. 575 note Slot 0 is stored verbatim as the full 64-bit meta_va in lgfmt. 576 note Returns 1 decoded, 0 empty, -1..-4 sync errors, -5 bad argc, -6 truncated. 577 578 fn lgnextraw argc ulong hasts ulong to long 579 if gt argc LGMAXA 580 ret -5 581 end 582 if gt hasts 1 583 ret -5 584 end 585 av = lgrsync 586 if le av 0 587 ret av 588 end 589 needw = add 1 add hasts argc 590 needb = mul needw 8 591 if lt ulong av needb 592 ret -6 593 end 594 pos = get lgget 0 595 put lgfmt 0 lgrqword pos 596 put lgargc 0 argc 597 put lglvl 0 0 598 put lgflg 0 hasts 599 pos = add pos 8 600 if eq hasts 1 601 put lgts 0 lgrqword pos 602 pos = add pos 8 603 else 604 put lgts 0 0 605 end 606 for i ulong argc 607 put lgargs i lgrqword pos 608 pos = add pos 8 609 end 610 put lgget 0 pos 611 put lgrcnt 0 add get lgrcnt 0 1 612 ret 1 613 end 614 615 note ==== CrashCat V1 packet and report decoder ==== 616 note ccinit initializes linear CrashCat decoding over ccbuf[0..n). 617 618 fn ccinit n ulong to long 619 put cclen 0 0 620 put ccpos 0 0 621 if gt n LGBMAX 622 ret -1 623 end 624 put cclen 0 n 625 ret 0 626 end 627 628 note ccchk validates a CrashCat V1 header word and stores parsed header fields. 629 note Returns total packet byte length (>0) on success, or negative error: 630 note -10 bad signature (not 0xCA70) 631 note -11 unsupported format version (not 1) 632 note -12 unknown packet type (> 8) 633 note -14 invalid payload qword count for typed packet 634 635 fn ccchk hdr ulong to long 636 sig = and shr hdr 48 65535 637 if ne sig CCSIG 638 ret -10 639 end 640 ver = and shr hdr 44 15 641 if ne ver CCVER1 642 ret -11 643 end 644 pt = and shr hdr 40 15 645 if gt pt CCMAXT 646 ret -12 647 end 648 plen = and shr hdr 32 255 649 if eq pt CCTRPT 650 if lt plen CCRMIN 651 ret -14 652 end 653 end 654 if eq pt CCTGPR 655 if ne plen CCGPRN 656 ret -14 657 end 658 end 659 if eq pt CCTCSR 660 if eq plen 0 661 ret -14 662 end 663 end 664 if or eq pt CCTR64 eq pt CCTI64 665 if ne and plen 1 0 666 ret -14 667 end 668 end 669 put ccver 0 ver 670 put cctype 0 pt 671 put ccplen 0 plen 672 put cchdat 0 and hdr LGU32 673 ret long mul add 1 plen 8 674 end 675 676 note ccfinal populates structured report fields when cctype == CCTRPT. 677 fn ccfinal to void 678 if eq get cctype 0 CCTRPT 679 put ccrsrc 0 get ccpay 0 680 put ccrcse 0 get ccpay 1 681 put ccrext 0 get ccpay 2 682 put ccrts 0 get ccpay 3 683 put ccrver 0 get ccpay 4 684 else 685 put ccrsrc 0 0 686 put ccrcse 0 0 687 put ccrext 0 0 688 put ccrts 0 0 689 put ccrver 0 0 690 end 691 end 692 693 note ccnext decodes one CrashCat V1 packet from linear ccbuf[ccpos..cclen). 694 note Returns: 695 note 1 packet decoded (ccver, cctype, ccplen, cchdat, ccpay, and ccr* if REPORT updated; ccpos advanced) 696 note 0 end of buffer (ccpos == cclen) 697 note -10..-12, -14 header/shape errors from ccchk 698 note -13 truncated header or payload (ccpos unchanged) 699 700 fn ccnext to long 701 p = get ccpos 0 702 n = get cclen 0 703 if ge p n 704 ret 0 705 end 706 av = sub n p 707 if lt av 8 708 ret -13 709 end 710 hdr = ccu64b p 711 need = ccchk hdr 712 if lt need 0 713 ret need 714 end 715 if lt av ulong need 716 ret -13 717 end 718 plen = get ccplen 0 719 q = add p 8 720 for i ulong plen 721 put ccpay i ccu64b q 722 q = add q 8 723 end 724 ccfinal 725 put ccpos 0 add p ulong need 726 ret 1 727 end 728 729 note ccnextring decodes one CrashCat V1 packet directly from the wrapped LibosLog ring buffer. 730 note Advances lgget only after full validation and extraction. 731 note Returns 1 decoded, 0 empty, -1..-4 ring sync error, -10..-14 CrashCat error. 732 733 fn ccnextring to long 734 av = lgrsync 735 if le av 0 736 ret av 737 end 738 if lt av 8 739 ret -13 740 end 741 p = get lgget 0 742 hdr = lgrqword p 743 need = ccchk hdr 744 if lt need 0 745 ret need 746 end 747 if lt ulong av ulong need 748 ret -13 749 end 750 plen = get ccplen 0 751 q = add p 8 752 for i ulong plen 753 put ccpay i lgrqword q 754 q = add q 8 755 end 756 ccfinal 757 put lgget 0 add p ulong need 758 ret 1 759 end 760 761 note Helper accessors for REGISTER32 / IO32_STATE packed pairs (low32=offset, high32=value). 762 fn ccpair_off i ulong to ulong 763 if ge i get ccplen 0 764 ret 0 765 end 766 ret and get ccpay i LGU32 767 end 768 769 fn ccpair_val i ulong to ulong 770 if ge i get ccplen 0 771 ret 0 772 end 773 ret and shr get ccpay i 32 LGU32 774 end 775 776 note ==== Buffered diagnostic text formatter (stdout / caller fd) ==== 777 778 fn lgoinit fd int to void 779 put lgon 0 0 780 put lgofd 0 fd 781 put lgoerr 0 0 782 end 783 784 fn lgoflush to long 785 n = get lgon 0 786 p = ulong 0 787 while lt p n bound 4096 788 r = write get lgofd 0 lgob p sub n p 789 if le r 0 790 put lgoerr 0 1 791 put lgon 0 0 792 ret -5 793 end 794 p = add p ulong r 795 end 796 put lgon 0 0 797 ret 0 798 end 799 800 fn lgoc c uchar to void 801 if ge get lgon 0 LGOCAP 802 z = lgoflush 803 end 804 n = get lgon 0 805 put lgob n c 806 put lgon 0 add n 1 807 end 808 809 fn lgodec v ulong to void 810 d = new uchar 24 0 811 n = ulong 0 812 x = v 813 while lt n 24 bound 24 814 put d n add uchar rem x 10 48 815 n = add n 1 816 x = div x 10 817 if eq x 0 818 break 819 end 820 end 821 while gt n 0 bound 24 822 n = sub n 1 823 lgoc get d n 824 end 825 end 826 827 fn lgohex v ulong to void 828 d = new uchar 16 0 829 n = ulong 0 830 x = v 831 while lt n 16 bound 16 832 put d n get LGHEX and x 15 833 n = add n 1 834 x = shr x 4 835 if eq x 0 836 break 837 end 838 end 839 while gt n 0 bound 16 840 n = sub n 1 841 lgoc get d n 842 end 843 end 844 845 fn lgoregname k long to void 846 if eq k 0 847 for i ulong len LGREG0 848 lgoc get LGREG0 i 849 end 850 ret 851 end 852 if eq k 1 853 for i ulong len LGREG1 854 lgoc get LGREG1 i 855 end 856 ret 857 end 858 if eq k 2 859 for i ulong len LGREG2 860 lgoc get LGREG2 i 861 end 862 ret 863 end 864 if eq k 3 865 for i ulong len LGREG3 866 lgoc get LGREG3 i 867 end 868 ret 869 end 870 if eq k 4 871 for i ulong len LGREG4 872 lgoc get LGREG4 i 873 end 874 ret 875 end 876 if eq k 5 877 for i ulong len LGREG5 878 lgoc get LGREG5 i 879 end 880 ret 881 end 882 if eq k 6 883 for i ulong len LGREG6 884 lgoc get LGREG6 i 885 end 886 ret 887 end 888 if eq k 7 889 for i ulong len LGREG7 890 lgoc get LGREG7 i 891 end 892 ret 893 end 894 for i ulong len LGREGU 895 lgoc get LGREGU i 896 end 897 end 898 899 fn lgcctname t ulong to void 900 if eq t 0 901 for i ulong len LGCT0 902 lgoc get LGCT0 i 903 end 904 ret 905 end 906 if eq t 1 907 for i ulong len LGCT1 908 lgoc get LGCT1 i 909 end 910 ret 911 end 912 if eq t 2 913 for i ulong len LGCT2 914 lgoc get LGCT2 i 915 end 916 ret 917 end 918 if eq t 3 919 for i ulong len LGCT3 920 lgoc get LGCT3 i 921 end 922 ret 923 end 924 if eq t 4 925 for i ulong len LGCT4 926 lgoc get LGCT4 i 927 end 928 ret 929 end 930 if eq t 5 931 for i ulong len LGCT5 932 lgoc get LGCT5 i 933 end 934 ret 935 end 936 if eq t 6 937 for i ulong len LGCT6 938 lgoc get LGCT6 i 939 end 940 ret 941 end 942 if eq t 7 943 for i ulong len LGCT7 944 lgoc get LGCT7 i 945 end 946 ret 947 end 948 for i ulong len LGCT8 949 lgoc get LGCT8 i 950 end 951 end 952 953 fn lgfmtreg idx ulong to void 954 if ge idx get lgtcnt 0 955 ret 956 end 957 for i ulong len LGKREG 958 lgoc get LGKREG i 959 end 960 lgoregname lgkind get lgtid idx 961 for i ulong len LGKPA 962 lgoc get LGKPA i 963 end 964 lgohex get lgtpa idx 965 for i ulong len LGKSZ 966 lgoc get LGKSZ i 967 end 968 lgohex get lgtsz idx 969 kl = get lgtkl idx 970 for i ulong len LGKKD 971 lgoc get LGKKD i 972 end 973 lgodec and kl 255 974 for i ulong len LGKLC 975 lgoc get LGKLC i 976 end 977 lgodec and shr kl 8 255 978 lgoc 10 979 end 980 981 fn lgfmtlog to void 982 for i ulong len LGKLOG 983 lgoc get LGKLOG i 984 end 985 lgohex get lgts 0 986 for i ulong len LGKLVL 987 lgoc get LGKLVL i 988 end 989 lgodec get lglvl 0 990 for i ulong len LGKFMT 991 lgoc get LGKFMT i 992 end 993 lgohex get lgfmt 0 994 for i ulong len LGKARC 995 lgoc get LGKARC i 996 end 997 lgodec get lgargc 0 998 for i ulong len LGKARG 999 lgoc get LGKARG i 1000 end 1001 ac = get lgargc 0 1002 for i ulong ac 1003 if gt i 0 1004 lgoc 44 1005 end 1006 for j ulong len LGK0X 1007 lgoc get LGK0X j 1008 end 1009 lgohex get lgargs i 1010 end 1011 lgoc 93 1012 lgoc 10 1013 end 1014 1015 fn lgfmtcc to void 1016 for i ulong len LGKCC 1017 lgoc get LGKCC i 1018 end 1019 t = get cctype 0 1020 lgcctname t 1021 for i ulong len LGKVER 1022 lgoc get LGKVER i 1023 end 1024 lgodec get ccver 0 1025 for i ulong len LGKHD 1026 lgoc get LGKHD i 1027 end 1028 lgohex get cchdat 0 1029 if eq t CCTRPT 1030 for i ulong len LGKSRC 1031 lgoc get LGKSRC i 1032 end 1033 lgohex get ccrsrc 0 1034 for i ulong len LGKCSE 1035 lgoc get LGKCSE i 1036 end 1037 lgohex get ccrcse 0 1038 for i ulong len LGKEXT 1039 lgoc get LGKEXT i 1040 end 1041 lgohex get ccrext 0 1042 for i ulong len LGKTS 1043 lgoc get LGKTS i 1044 end 1045 lgohex get ccrts 0 1046 for i ulong len LGKRVR 1047 lgoc get LGKRVR i 1048 end 1049 lgohex get ccrver 0 1050 lgoc 10 1051 ret 1052 end 1053 for i ulong len LGKCNT 1054 lgoc get LGKCNT i 1055 end 1056 pn = get ccplen 0 1057 lgodec pn 1058 lgoc 10 1059 end