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
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note core.om: hardware capability manifest reader, checker and admission (seeded Omega, AArch64). |
| 3 | note Unit 1 of hwman: cat backend/hw/core.om backend/hw/cpu.om backend/hw/tpm.om backend/hw/main.om | omc |
| 4 | note Units share globals; each unit's private names carry its prefix (cpu*, tpm*); core owns the rest. |
| 5 | note |
| 6 | note Manifest format (backend/hw/manifest.tsv): line 1 is exactly "hwman<TAB>1" (schema 1); line 2 is |
| 7 | note exactly the column header THDR below; every later line that is neither empty nor starts with '#' |
| 8 | note is one target row of exactly NCOL tab-separated nonempty fields ("-" when a field has no value). |
| 9 | note The checker refuses (exit 3) a wrong schema line, a wrong header, a wrong field count, an empty |
| 10 | note field, an id outside [a-z0-9-] or repeated, a family/route/status/admit value outside its |
| 11 | note enumeration, a non-decimal timeout_ms, any of the 21 required families missing, and these rules: |
| 12 | note admit YES needs status CHIP_TESTED, evidence other than NOT_RUN, a hwman-* runner, ops, blocker - |
| 13 | note BLOCKED_* needs a blocker and admit NO; route UNRESOLVED exactly when status BLOCKED_NAME |
| 14 | note PROPOSED needs admit NO; every other status except BLOCKED_* needs evidence other than NOT_RUN |
| 15 | note Refusals print one line "REFUSE <class> <reason> ..." on stdout. |
| 16 | om2 |
| 17 | |
| 18 | text THDR "id\tfamily\tvendor\tpart\trevision\troute\tplatform\tidentity\tnode\tisa_cmds\tdiscovery\tops\taddr_spaces\tdma_coherence\tqueue_irq\treset_power\tfirmware\tcompiler_artifact\trefs\trunner\ttimeout_ms\tstatus\tadmit\tevidence\tblocker" |
| 19 | text TSCH "hwman\t1" |
| 20 | text TFAM "CPU GPU APU PPU SPU NPU TPU LPU MCU ISP TPM SECURE_ENCLAVE ASIC FPGA DPU WSE NEUROMORPHIC PHOTONIC QPU TSU BPU" |
| 21 | text TROUTE "NATIVE_ISA DIRECT_DEVICE VENDOR_RUNTIME REMOTE_SERVICE FIRMWARE_OWNED UNRESOLVED" |
| 22 | text TSTAT "CHIP_TESTED PRIOR_RECEIPT EMULATED HOST_TESTED PROPOSED BLOCKED_ACCESS BLOCKED_NAME" |
| 23 | text TYESNO "YES NO" |
| 24 | text TDASH "-" |
| 25 | text TNOTRUN "NOT_RUN" |
| 26 | text THWPFX "hwman-" |
| 27 | note The closed runner table: the runners this program implements, the one family and route each |
| 28 | note drives, and the operations each dispatches (cpuop in cpu.om; runtpm in main.om). check refuses |
| 29 | note a row naming any other hwman- runner, another family or route, or another operation. |
| 30 | text TRUN "hwman-cpu hwman-tpm" |
| 31 | text TOPCPU "sumsq64 fnv1a64" |
| 32 | text TOPTPM "props getrandom" |
| 33 | const FCPU long 0 |
| 34 | const FTPM long 10 |
| 35 | const RNATIVE long 0 |
| 36 | const RDIRECT long 1 |
| 37 | text TREF "REFUSE " |
| 38 | text TNL "\n" |
| 39 | text TSP " " |
| 40 | text TEQ "=" |
| 41 | text TLINE " line=" |
| 42 | text TIO "hwman: I/O error reading " |
| 43 | text TBIG "hwman: manifest larger than 262144 bytes\n" |
| 44 | |
| 45 | note column indices (0-based) |
| 46 | const CID ulong 0 |
| 47 | const CFAM ulong 1 |
| 48 | const CVEND ulong 2 |
| 49 | const CPART ulong 3 |
| 50 | const CREV ulong 4 |
| 51 | const CROUTE ulong 5 |
| 52 | const CIDENT ulong 7 |
| 53 | const CNODE ulong 8 |
| 54 | const COPS ulong 11 |
| 55 | const CRUNNER ulong 19 |
| 56 | const CTMO ulong 20 |
| 57 | const CSTAT ulong 21 |
| 58 | const CADMIT ulong 22 |
| 59 | const CEVID ulong 23 |
| 60 | const CBLOCK ulong 24 |
| 61 | const NCOL ulong 25 |
| 62 | const NFAM ulong 21 |
| 63 | const MAXROW ulong 128 |
| 64 | const MANCAP ulong 262144 |
| 65 | |
| 66 | note exit classes shared by every command |
| 67 | const XOK int 0 |
| 68 | const XUSAGE int 2 |
| 69 | const XMAN int 3 |
| 70 | const XUNKNOWN int 4 |
| 71 | const XUNSUP int 5 |
| 72 | const XAUTH int 6 |
| 73 | const XSTALE int 7 |
| 74 | const XWRDEV int 8 |
| 75 | const XBUSY int 9 |
| 76 | const XOFFLINE int 10 |
| 77 | const XTIMEOUT int 11 |
| 78 | const XMISM int 12 |
| 79 | const XDEVERR int 13 |
| 80 | const XINVAL int 14 |
| 81 | const XIO int 74 |
| 82 | |
| 83 | global gman uchar 262144 |
| 84 | global gav uchar 8192 |
| 85 | global gao ulong 16 |
| 86 | global gal ulong 16 |
| 87 | global gpath uchar 4096 |
| 88 | global gfile uchar 65536 |
| 89 | global gob uchar 8192 |
| 90 | global gfo ulong 32 |
| 91 | global gfl ulong 32 |
| 92 | global grow ulong 128 |
| 93 | global grln ulong 128 |
| 94 | note gst: 0 manifest length, 1 output fill, 2 fields in current row, 3 rows, 4 argc, 5 path length, |
| 95 | note 6 current row line number, 7 gfile length, 8 admitted rows |
| 96 | global gst ulong 16 |
| 97 | |
| 98 | fn oflush to void |
| 99 | n = write 1 gob 0 get gst 1 |
| 100 | put gst 1 0 |
| 101 | end |
| 102 | |
| 103 | fn oc b uchar to void |
| 104 | f = get gst 1 |
| 105 | if ge f 8000 |
| 106 | oflush |
| 107 | f = get gst 1 |
| 108 | end |
| 109 | put gob f b |
| 110 | put gst 1 add f 1 |
| 111 | end |
| 112 | |
| 113 | fn ot t view uchar * to void |
| 114 | for i ulong len t |
| 115 | oc get t i |
| 116 | end |
| 117 | end |
| 118 | |
| 119 | fn odec v ulong to void |
| 120 | d = new uchar 20 0 |
| 121 | k = ulong 0 |
| 122 | x = v |
| 123 | while true bound 21 |
| 124 | put d k uchar add rem x 10 48 |
| 125 | k = add k 1 |
| 126 | x = div x 10 |
| 127 | if eq x 0 |
| 128 | break |
| 129 | end |
| 130 | end |
| 131 | for i ulong k |
| 132 | oc get d sub sub k i 1 |
| 133 | end |
| 134 | end |
| 135 | |
| 136 | fn osdec v long to void |
| 137 | if lt v 0 |
| 138 | oc 45 |
| 139 | odec ulong sub 0 v |
| 140 | else |
| 141 | odec ulong v |
| 142 | end |
| 143 | end |
| 144 | |
| 145 | fn ohx v ulong w ulong to void |
| 146 | oc 48 |
| 147 | oc 120 |
| 148 | for i ulong w |
| 149 | s = mul sub sub w i 1 4 |
| 150 | q = and shr v s 15 |
| 151 | if lt q 10 |
| 152 | oc uchar add q 48 |
| 153 | else |
| 154 | oc uchar add q 87 |
| 155 | end |
| 156 | end |
| 157 | end |
| 158 | |
| 159 | fn ofield k ulong to void |
| 160 | o = get gfo k |
| 161 | for i ulong get gfl k |
| 162 | oc get gman add o i |
| 163 | end |
| 164 | end |
| 165 | |
| 166 | fn oarg a ulong to void |
| 167 | o = get gao a |
| 168 | for i ulong get gal a |
| 169 | oc get gav add o i |
| 170 | end |
| 171 | end |
| 172 | |
| 173 | fn fail code int msg view uchar * to void |
| 174 | oflush |
| 175 | n = write 2 msg 0 len msg |
| 176 | exit code |
| 177 | end |
| 178 | |
| 179 | note copy every argument into gav; argument a is gav[gao a .. + gal a] |
| 180 | fn loadargs to void |
| 181 | c = argcnt |
| 182 | if gt c 16 |
| 183 | fail XUSAGE TNL |
| 184 | end |
| 185 | put gst 4 ulong c |
| 186 | o = ulong 0 |
| 187 | for a ulong ulong c |
| 188 | n = argread a gav o sub len gav o |
| 189 | if lt n 0 |
| 190 | fail XUSAGE TNL |
| 191 | end |
| 192 | put gao a o |
| 193 | put gal a ulong n |
| 194 | o = add o ulong n |
| 195 | end |
| 196 | end |
| 197 | |
| 198 | fn argc to ulong |
| 199 | ret get gst 4 |
| 200 | end |
| 201 | |
| 202 | fn argeq a ulong t view uchar * to bool |
| 203 | if ne get gal a len t |
| 204 | ret false |
| 205 | end |
| 206 | o = get gao a |
| 207 | for i ulong len t |
| 208 | if ne get gav add o i get t i |
| 209 | ret false |
| 210 | end |
| 211 | end |
| 212 | ret true |
| 213 | end |
| 214 | |
| 215 | note decimal argument; -1 when empty, non-decimal or above 2^40 |
| 216 | fn argdec a ulong to long |
| 217 | n = get gal a |
| 218 | if eq n 0 |
| 219 | ret -1 |
| 220 | end |
| 221 | if gt n 13 |
| 222 | ret -1 |
| 223 | end |
| 224 | o = get gao a |
| 225 | v = ulong 0 |
| 226 | for i ulong n |
| 227 | c = get gav add o i |
| 228 | if or lt c 48 gt c 57 |
| 229 | ret -1 |
| 230 | end |
| 231 | v = add mul v 10 ulong sub c 48 |
| 232 | end |
| 233 | ret long v |
| 234 | end |
| 235 | |
| 236 | note path buffer |
| 237 | fn pclear to void |
| 238 | put gst 5 0 |
| 239 | end |
| 240 | |
| 241 | fn pc b uchar to void |
| 242 | p = get gst 5 |
| 243 | if ge p sub len gpath 1 |
| 244 | fail XUSAGE TNL |
| 245 | end |
| 246 | put gpath p b |
| 247 | put gst 5 add p 1 |
| 248 | end |
| 249 | |
| 250 | fn pt t view uchar * to void |
| 251 | for i ulong len t |
| 252 | pc get t i |
| 253 | end |
| 254 | end |
| 255 | |
| 256 | fn pfield k ulong to void |
| 257 | o = get gfo k |
| 258 | for i ulong get gfl k |
| 259 | pc get gman add o i |
| 260 | end |
| 261 | end |
| 262 | |
| 263 | fn parg a ulong to void |
| 264 | o = get gao a |
| 265 | for i ulong get gal a |
| 266 | pc get gav add o i |
| 267 | end |
| 268 | end |
| 269 | |
| 270 | fn pdec v ulong to void |
| 271 | d = new uchar 20 0 |
| 272 | k = ulong 0 |
| 273 | x = v |
| 274 | while true bound 21 |
| 275 | put d k uchar add rem x 10 48 |
| 276 | k = add k 1 |
| 277 | x = div x 10 |
| 278 | if eq x 0 |
| 279 | break |
| 280 | end |
| 281 | end |
| 282 | for i ulong k |
| 283 | pc get d sub sub k i 1 |
| 284 | end |
| 285 | end |
| 286 | |
| 287 | note read the file named in gpath into gfile; return its length or -errno |
| 288 | fn readpath to long |
| 289 | fd = fopen gpath 0 get gst 5 0 0 |
| 290 | if lt fd 0 |
| 291 | ret fd |
| 292 | end |
| 293 | t = ulong 0 |
| 294 | while true bound 4096 |
| 295 | n = read int fd gfile t sub len gfile t |
| 296 | if lt n 0 |
| 297 | c = fclose int fd |
| 298 | ret n |
| 299 | end |
| 300 | if eq n 0 |
| 301 | break |
| 302 | end |
| 303 | t = add t ulong n |
| 304 | if eq t len gfile |
| 305 | break |
| 306 | end |
| 307 | end |
| 308 | c = fclose int fd |
| 309 | put gst 7 t |
| 310 | ret long t |
| 311 | end |
| 312 | |
| 313 | fn readman a ulong to void |
| 314 | pclear |
| 315 | parg a |
| 316 | fd = fopen gpath 0 get gst 5 0 0 |
| 317 | if lt fd 0 |
| 318 | ot TIO |
| 319 | oarg a |
| 320 | oc 10 |
| 321 | fail XIO TNL |
| 322 | end |
| 323 | t = ulong 0 |
| 324 | while true bound 4096 |
| 325 | n = read int fd gman t sub MANCAP t |
| 326 | if lt n 0 |
| 327 | fail XIO TIO |
| 328 | end |
| 329 | if eq n 0 |
| 330 | break |
| 331 | end |
| 332 | t = add t ulong n |
| 333 | if eq t MANCAP |
| 334 | fail XMAN TBIG |
| 335 | end |
| 336 | end |
| 337 | c = fclose int fd |
| 338 | put gst 0 t |
| 339 | end |
| 340 | |
| 341 | note split the line starting at off into gfo/gfl; return the offset after its newline |
| 342 | fn rowat off ulong to ulong |
| 343 | m = get gst 0 |
| 344 | k = ulong 0 |
| 345 | s = off |
| 346 | i = off |
| 347 | put gfo 0 off |
| 348 | while true bound 262145 |
| 349 | if ge i m |
| 350 | break |
| 351 | end |
| 352 | c = get gman i |
| 353 | if eq c 10 |
| 354 | break |
| 355 | end |
| 356 | if eq c 9 |
| 357 | if lt k sub len gfo 1 |
| 358 | put gfl k sub i s |
| 359 | k = add k 1 |
| 360 | put gfo k add i 1 |
| 361 | end |
| 362 | s = add i 1 |
| 363 | end |
| 364 | i = add i 1 |
| 365 | end |
| 366 | put gfl k sub i s |
| 367 | put gst 2 add k 1 |
| 368 | if lt i m |
| 369 | ret add i 1 |
| 370 | end |
| 371 | ret i |
| 372 | end |
| 373 | |
| 374 | fn feq k ulong t view uchar * to bool |
| 375 | if ne get gfl k len t |
| 376 | ret false |
| 377 | end |
| 378 | o = get gfo k |
| 379 | for i ulong len t |
| 380 | if ne get gman add o i get t i |
| 381 | ret false |
| 382 | end |
| 383 | end |
| 384 | ret true |
| 385 | end |
| 386 | |
| 387 | fn fpfx k ulong t view uchar * to bool |
| 388 | if lt get gfl k len t |
| 389 | ret false |
| 390 | end |
| 391 | o = get gfo k |
| 392 | for i ulong len t |
| 393 | if ne get gman add o i get t i |
| 394 | ret false |
| 395 | end |
| 396 | end |
| 397 | ret true |
| 398 | end |
| 399 | |
| 400 | fn fargeq k ulong a ulong to bool |
| 401 | if ne get gfl k get gal a |
| 402 | ret false |
| 403 | end |
| 404 | o = get gfo k |
| 405 | p = get gao a |
| 406 | for i ulong get gfl k |
| 407 | if ne get gman add o i get gav add p i |
| 408 | ret false |
| 409 | end |
| 410 | end |
| 411 | ret true |
| 412 | end |
| 413 | |
| 414 | note gman[o..o+n) equals t[s..s+n) |
| 415 | fn mteq o ulong n ulong t view uchar * s ulong to bool |
| 416 | if gt add s n len t |
| 417 | ret false |
| 418 | end |
| 419 | for j ulong n |
| 420 | if ne get gman add o j get t add s j |
| 421 | ret false |
| 422 | end |
| 423 | end |
| 424 | ret true |
| 425 | end |
| 426 | |
| 427 | note gman[o..o+n) equals gav[p..p+n) |
| 428 | fn maeq o ulong n ulong p ulong to bool |
| 429 | for j ulong n |
| 430 | if ne get gman add o j get gav add p j |
| 431 | ret false |
| 432 | end |
| 433 | end |
| 434 | ret true |
| 435 | end |
| 436 | |
| 437 | note index of field k in the space-separated enumeration t, or -1 |
| 438 | fn fenum k ulong t view uchar * to long |
| 439 | o = get gfo k |
| 440 | n = get gfl k |
| 441 | idx = long 0 |
| 442 | s = ulong 0 |
| 443 | for i ulong add len t 1 |
| 444 | b = true |
| 445 | if lt i len t |
| 446 | b = eq get t i 32 |
| 447 | end |
| 448 | if b |
| 449 | if eq sub i s n |
| 450 | if mteq o n t s |
| 451 | ret idx |
| 452 | end |
| 453 | end |
| 454 | idx = add idx 1 |
| 455 | s = add i 1 |
| 456 | end |
| 457 | end |
| 458 | ret -1 |
| 459 | end |
| 460 | |
| 461 | note decimal field value, or -1 |
| 462 | fn fdec k ulong to long |
| 463 | n = get gfl k |
| 464 | if or eq n 0 gt n 13 |
| 465 | ret -1 |
| 466 | end |
| 467 | o = get gfo k |
| 468 | v = ulong 0 |
| 469 | for i ulong n |
| 470 | c = get gman add o i |
| 471 | if or lt c 48 gt c 57 |
| 472 | ret -1 |
| 473 | end |
| 474 | v = add mul v 10 ulong sub c 48 |
| 475 | end |
| 476 | ret long v |
| 477 | end |
| 478 | |
| 479 | note does the comma list in field k contain argument a |
| 480 | fn flisthas k ulong a ulong to bool |
| 481 | o = get gfo k |
| 482 | n = get gfl k |
| 483 | w = get gal a |
| 484 | if eq w 0 |
| 485 | ret false |
| 486 | end |
| 487 | s = ulong 0 |
| 488 | for i ulong add n 1 |
| 489 | b = true |
| 490 | if lt i n |
| 491 | b = eq get gman add o i 44 |
| 492 | end |
| 493 | if b |
| 494 | if eq sub i s w |
| 495 | if maeq add o s w get gao a |
| 496 | ret true |
| 497 | end |
| 498 | end |
| 499 | s = add i 1 |
| 500 | end |
| 501 | end |
| 502 | ret false |
| 503 | end |
| 504 | |
| 505 | note is gman[o..o+w) one word of the space-separated list t |
| 506 | fn wordin o ulong w ulong t view uchar * to bool |
| 507 | if eq w 0 |
| 508 | ret false |
| 509 | end |
| 510 | s = ulong 0 |
| 511 | for i ulong add len t 1 |
| 512 | b = true |
| 513 | if lt i len t |
| 514 | b = eq get t i 32 |
| 515 | end |
| 516 | if b |
| 517 | if eq sub i s w |
| 518 | if mteq o w t s |
| 519 | ret true |
| 520 | end |
| 521 | end |
| 522 | s = add i 1 |
| 523 | end |
| 524 | end |
| 525 | ret false |
| 526 | end |
| 527 | |
| 528 | note is every comma-separated item of field k a word of the space-separated list t |
| 529 | fn listin k ulong t view uchar * to bool |
| 530 | o = get gfo k |
| 531 | n = get gfl k |
| 532 | s = ulong 0 |
| 533 | for i ulong add n 1 |
| 534 | b = true |
| 535 | if lt i n |
| 536 | b = eq get gman add o i 44 |
| 537 | end |
| 538 | if b |
| 539 | if not wordin add o s sub i s t |
| 540 | ret false |
| 541 | end |
| 542 | s = add i 1 |
| 543 | end |
| 544 | end |
| 545 | ret true |
| 546 | end |
| 547 | |
| 548 | note gav[p..p+w) equals t[s..s+w) |
| 549 | fn ateq p ulong w ulong t view uchar * s ulong to bool |
| 550 | for j ulong w |
| 551 | if ne get gav add p j get t add s j |
| 552 | ret false |
| 553 | end |
| 554 | end |
| 555 | ret true |
| 556 | end |
| 557 | |
| 558 | note is argument a one word of the space-separated list t |
| 559 | fn argin a ulong t view uchar * to bool |
| 560 | w = get gal a |
| 561 | s = ulong 0 |
| 562 | for i ulong add len t 1 |
| 563 | b = true |
| 564 | if lt i len t |
| 565 | b = eq get t i 32 |
| 566 | end |
| 567 | if b |
| 568 | if and eq sub i s w gt w 0 |
| 569 | if ateq get gao a w t s |
| 570 | ret true |
| 571 | end |
| 572 | end |
| 573 | s = add i 1 |
| 574 | end |
| 575 | end |
| 576 | ret false |
| 577 | end |
| 578 | |
| 579 | fn mrefuse why view uchar * line ulong to int |
| 580 | ot TREF |
| 581 | ot why |
| 582 | ot TLINE |
| 583 | odec line |
| 584 | oc 10 |
| 585 | oflush |
| 586 | ret XMAN |
| 587 | end |
| 588 | |
| 589 | text RSCHEMA "manifest schema_version" |
| 590 | text RHDR "manifest header" |
| 591 | text RCOLS "manifest field_count" |
| 592 | text REMPTY "manifest empty_field" |
| 593 | text RIDCH "manifest id_charset" |
| 594 | text RDUP "manifest duplicate_id" |
| 595 | text RFAM "manifest family" |
| 596 | text RROUTE "manifest route" |
| 597 | text RSTAT "manifest status" |
| 598 | text RADMIT "manifest admit" |
| 599 | text RTMO "manifest timeout_ms" |
| 600 | text RADMEV "manifest admit_without_chip_evidence" |
| 601 | text RBLK "manifest blocked_without_blocker" |
| 602 | text RUNRES "manifest unresolved_route_status" |
| 603 | text RPROP "manifest proposed_admitted" |
| 604 | text REVID "manifest status_without_evidence" |
| 605 | text RROWS "manifest too_many_rows" |
| 606 | text RMISS "manifest missing_family " |
| 607 | text RRUN "manifest unknown_runner" |
| 608 | text RRFAM "manifest runner_family_route" |
| 609 | text RROP "manifest runner_op" |
| 610 | |
| 611 | note is the line starting at st exactly t (followed by a newline or the end of the manifest) |
| 612 | fn lineis st ulong t view uchar * to bool |
| 613 | m = get gst 0 |
| 614 | if gt add st len t m |
| 615 | ret false |
| 616 | end |
| 617 | for i ulong len t |
| 618 | if ne get gman add st i get t i |
| 619 | ret false |
| 620 | end |
| 621 | end |
| 622 | e = add st len t |
| 623 | if eq e m |
| 624 | ret true |
| 625 | end |
| 626 | ret eq get gman e 10 |
| 627 | end |
| 628 | |
| 629 | note print token idx of the space-separated enumeration t |
| 630 | fn otok t view uchar * idx ulong to void |
| 631 | k = ulong 0 |
| 632 | for i ulong len t |
| 633 | c = get t i |
| 634 | if eq c 32 |
| 635 | k = add k 1 |
| 636 | else |
| 637 | if eq k idx |
| 638 | oc c |
| 639 | end |
| 640 | end |
| 641 | end |
| 642 | end |
| 643 | |
| 644 | global gchk ulong 4 |
| 645 | |
| 646 | note the id of the split row is [a-z0-9-] |
| 647 | fn idok to bool |
| 648 | o = get gfo CID |
| 649 | for i ulong get gfl CID |
| 650 | c = get gman add o i |
| 651 | ok = or and ge c 97 le c 122 or and ge c 48 le c 57 eq c 45 |
| 652 | if not ok |
| 653 | ret false |
| 654 | end |
| 655 | end |
| 656 | ret true |
| 657 | end |
| 658 | |
| 659 | note runner rn of TRUN drives exactly one family and route |
| 660 | fn runok rn long fam long route long to bool |
| 661 | if eq rn 0 |
| 662 | ret and eq fam FCPU eq route RNATIVE |
| 663 | end |
| 664 | ret and eq fam FTPM eq route RDIRECT |
| 665 | end |
| 666 | |
| 667 | note every operation of the row is one runner rn dispatches |
| 668 | fn runops rn long to bool |
| 669 | if eq rn 0 |
| 670 | ret listin COPS TOPCPU |
| 671 | end |
| 672 | ret listin COPS TOPTPM |
| 673 | end |
| 674 | |
| 675 | note rules for the split row at manifest line `line`; sets gchk 0 family index, gchk 1 admitted |
| 676 | fn chkrow line ulong to int |
| 677 | if ne get gst 2 NCOL |
| 678 | ret mrefuse RCOLS line |
| 679 | end |
| 680 | for k ulong NCOL |
| 681 | if eq get gfl k 0 |
| 682 | ret mrefuse REMPTY line |
| 683 | end |
| 684 | end |
| 685 | if not idok |
| 686 | ret mrefuse RIDCH line |
| 687 | end |
| 688 | fam = fenum CFAM TFAM |
| 689 | if lt fam 0 |
| 690 | ret mrefuse RFAM line |
| 691 | end |
| 692 | route = fenum CROUTE TROUTE |
| 693 | if lt route 0 |
| 694 | ret mrefuse RROUTE line |
| 695 | end |
| 696 | sts = fenum CSTAT TSTAT |
| 697 | if lt sts 0 |
| 698 | ret mrefuse RSTAT line |
| 699 | end |
| 700 | yes = fenum CADMIT TYESNO |
| 701 | if lt yes 0 |
| 702 | ret mrefuse RADMIT line |
| 703 | end |
| 704 | if lt fdec CTMO 0 |
| 705 | ret mrefuse RTMO line |
| 706 | end |
| 707 | noev = or feq CEVID TNOTRUN feq CEVID TDASH |
| 708 | nobl = feq CBLOCK TDASH |
| 709 | put gchk 1 0 |
| 710 | if eq yes 0 |
| 711 | ok = and and eq sts 0 not noev and and fpfx CRUNNER THWPFX nobl not feq COPS TDASH |
| 712 | if not ok |
| 713 | ret mrefuse RADMEV line |
| 714 | end |
| 715 | put gchk 1 1 |
| 716 | end |
| 717 | if ge sts 5 |
| 718 | if or nobl eq yes 0 |
| 719 | ret mrefuse RBLK line |
| 720 | end |
| 721 | end |
| 722 | if ne eq route 5 eq sts 6 |
| 723 | ret mrefuse RUNRES line |
| 724 | end |
| 725 | if and eq sts 4 eq yes 0 |
| 726 | ret mrefuse RPROP line |
| 727 | end |
| 728 | if and lt sts 4 noev |
| 729 | ret mrefuse REVID line |
| 730 | end |
| 731 | if fpfx CRUNNER THWPFX |
| 732 | rn = fenum CRUNNER TRUN |
| 733 | if lt rn 0 |
| 734 | ret mrefuse RRUN line |
| 735 | end |
| 736 | if not runok rn fam route |
| 737 | ret mrefuse RRFAM line |
| 738 | end |
| 739 | if not runops rn |
| 740 | ret mrefuse RROP line |
| 741 | end |
| 742 | end |
| 743 | put gchk 0 ulong fam |
| 744 | ret XOK |
| 745 | end |
| 746 | |
| 747 | note gman[a..a+n) equals gman[b..b+n) |
| 748 | fn mmeq a ulong b ulong n ulong to bool |
| 749 | for j ulong n |
| 750 | if ne get gman add a j get gman add b j |
| 751 | ret false |
| 752 | end |
| 753 | end |
| 754 | ret true |
| 755 | end |
| 756 | |
| 757 | note does any of the first rows rows carry the id at gman[io..io+il) |
| 758 | fn iddup rows ulong io ulong il ulong to bool |
| 759 | for r ulong rows |
| 760 | q = rowat get grow r |
| 761 | if eq get gfl CID il |
| 762 | if mmeq get gfo CID io il |
| 763 | ret true |
| 764 | end |
| 765 | end |
| 766 | end |
| 767 | ret false |
| 768 | end |
| 769 | |
| 770 | note check the loaded manifest; record row offsets in grow/grln; return an exit class |
| 771 | fn check to int |
| 772 | m = get gst 0 |
| 773 | if not lineis 0 TSCH |
| 774 | ret mrefuse RSCHEMA 1 |
| 775 | end |
| 776 | h = rowat 0 |
| 777 | if not lineis h THDR |
| 778 | ret mrefuse RHDR 2 |
| 779 | end |
| 780 | off = rowat h |
| 781 | line = ulong 2 |
| 782 | rows = ulong 0 |
| 783 | fams = ulong 0 |
| 784 | adm = ulong 0 |
| 785 | while true bound 65536 |
| 786 | if ge off m |
| 787 | break |
| 788 | end |
| 789 | line = add line 1 |
| 790 | st = off |
| 791 | off = rowat st |
| 792 | if and eq get gfl 0 0 eq get gst 2 1 |
| 793 | continue |
| 794 | end |
| 795 | if eq get gman st 35 |
| 796 | continue |
| 797 | end |
| 798 | c = chkrow line |
| 799 | if ne c XOK |
| 800 | ret c |
| 801 | end |
| 802 | if ge rows MAXROW |
| 803 | ret mrefuse RROWS line |
| 804 | end |
| 805 | if iddup rows get gfo CID get gfl CID |
| 806 | ret mrefuse RDUP line |
| 807 | end |
| 808 | put grow rows st |
| 809 | put grln rows line |
| 810 | rows = add rows 1 |
| 811 | fams = or fams shl ulong 1 get gchk 0 |
| 812 | adm = add adm get gchk 1 |
| 813 | end |
| 814 | put gst 3 rows |
| 815 | put gst 8 adm |
| 816 | note report the first missing family by name |
| 817 | for f ulong NFAM |
| 818 | if eq and shr fams f 1 0 |
| 819 | ot TREF |
| 820 | ot RMISS |
| 821 | otok TFAM f |
| 822 | oc 10 |
| 823 | oflush |
| 824 | ret XMAN |
| 825 | end |
| 826 | end |
| 827 | ret XOK |
| 828 | end |
| 829 | |
| 830 | note row index of the target named by argument a, or -1; leaves that row split |
| 831 | fn findrow a ulong to long |
| 832 | for r ulong get gst 3 |
| 833 | q = rowat get grow r |
| 834 | if fargeq CID a |
| 835 | ret long r |
| 836 | end |
| 837 | end |
| 838 | ret -1 |
| 839 | end |
| 840 | |
| 841 | fn hexdig c uchar to long |
| 842 | if and ge c 48 le c 57 |
| 843 | ret long sub c 48 |
| 844 | end |
| 845 | if and ge c 97 le c 102 |
| 846 | ret long sub c 87 |
| 847 | end |
| 848 | if and ge c 65 le c 70 |
| 849 | ret long sub c 55 |
| 850 | end |
| 851 | ret -1 |
| 852 | end |
| 853 | |
| 854 | note "0x" hex number at gfile[off..off+n), optional trailing newline; -1 when malformed or above 2^60 |
| 855 | fn hexat off ulong n ulong to long |
| 856 | if lt n 3 |
| 857 | ret -1 |
| 858 | end |
| 859 | if or ne get gfile off 48 ne get gfile add off 1 120 |
| 860 | ret -1 |
| 861 | end |
| 862 | v = ulong 0 |
| 863 | d = ulong 0 |
| 864 | for i ulong sub n 2 |
| 865 | c = get gfile add add off 2 i |
| 866 | if eq c 10 |
| 867 | if eq add i 3 n |
| 868 | break |
| 869 | end |
| 870 | ret -1 |
| 871 | end |
| 872 | x = hexdig c |
| 873 | if lt x 0 |
| 874 | ret -1 |
| 875 | end |
| 876 | if ge v 0x0800000000000000 |
| 877 | ret -1 |
| 878 | end |
| 879 | v = or shl v 4 ulong x |
| 880 | d = add d 1 |
| 881 | end |
| 882 | if eq d 0 |
| 883 | ret -1 |
| 884 | end |
| 885 | ret long v |
| 886 | end |
| 887 | |
| 888 | note identity field "key=0xHEX": the value, or -1 |
| 889 | fn fidhex to long |
| 890 | o = get gfo CIDENT |
| 891 | n = get gfl CIDENT |
| 892 | e = n |
| 893 | for i ulong n |
| 894 | if eq get gman add o i 61 |
| 895 | if eq e n |
| 896 | e = i |
| 897 | end |
| 898 | end |
| 899 | end |
| 900 | if ge add e 3 n |
| 901 | ret -1 |
| 902 | end |
| 903 | if or ne get gman add add o e 1 48 ne get gman add add o e 2 120 |
| 904 | ret -1 |
| 905 | end |
| 906 | v = ulong 0 |
| 907 | for i ulong sub sub n e 3 |
| 908 | x = hexdig get gman add add add o e 3 i |
| 909 | if or lt x 0 ge v 0x0800000000000000 |
| 910 | ret -1 |
| 911 | end |
| 912 | v = or shl v 4 ulong x |
| 913 | end |
| 914 | ret long v |
| 915 | end |
| 916 | |
| 917 | fn hexc q ulong to uchar |
| 918 | if lt q 10 |
| 919 | ret uchar add q 48 |
| 920 | end |
| 921 | ret uchar add q 87 |
| 922 | end |