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 / core / rsi / om / reuse-eval / judge.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note judge.om: the REUSE-1 judge (spark-rsi-mv #73, lane EvalJudge), written from the frozen |
| 3 | note contract (omega-mv d6edaad1 docs/reuse/REUSE-1.md), the evaluator formats and the drive.om |
| 4 | note CLI only; no candidate source is read. Units before it: sha256 ref. Prefix jd / JD / JW / JM. |
| 5 | note Entry: jdmain (argv[1] = run, tap, calib, build, recheck, controls); see docs/reuse-eval/README.md. |
| 6 | note |
| 7 | note String registers: JDS holds 32 byte strings of up to 4095 bytes (register r at r * 4096), |
| 8 | note lengths in JDSL. Register map: 0..2 scratch, 3 split dir, 4 output dir, 5 base ELF, |
| 9 | note 6 ALLOW (run), 7 cpu, 8 arm name, 9 LIBDIR (process), 10 MANSHA (process), 11 ALLOW (process), |
| 10 | note 12 TAPFILE, 13 SPLIT, 14 TRAIN lib, 15 TRAIN mansha, 16 TRAINP lib, 17 TRAINP mansha, |
| 11 | note 18 drive, 19 omega-mv checkout, 20 omc, 21 calibration file, 22 control dir, 23 nog3 unit path, |
| 12 | note 24 c4 unit path, 25 DEV split dir, 26..29 control scratch, 30 acquisition dir, 31 jdabs only. |
| 13 | note Word memory JDM: JMIX index, JMSE sessions, JMEX group .exp, JMRQ group .req, JMOF request |
| 14 | note offsets, JMRT per-request results (route, r0, r1, status), JMSC scratch. |
| 15 | text JDW "/usr/bin/taskset-c-echofullcachemethoddeltaselecttap/proc//stat/status/proc/loadavg/proc/self/statVmHWM:VmRSS:arm--rep--g.logproc.logacq.logacq-.manshaindexsessions.req.expCURRENTgen-.man.elf.om.calmanifest_sha256=build AUTHORIZED REVOKED mutant:c1mutant:c1bmutant:c1cunit:check=unit:delta=crashafter:controls.loglib-c0123456789abcdef.tmpctrlarm= wrong= violations=tap_sha256= tap_bytes=drive_exit= elapsed_ns=REBUILD MATCH BLOCKED rebuild pinned usage: judge run|tap|calib|build|recheck|controls (docs/reuse-eval/README.md) queries=cal_sha256=judge error unit:mutant:" |
| 16 | const JWTASK ulong 0 |
| 17 | const JWDC ulong 16 |
| 18 | const JWDASH ulong 18 |
| 19 | const JWECHO ulong 19 |
| 20 | const JWFULL ulong 23 |
| 21 | const JWCACHE ulong 27 |
| 22 | const JWMETH ulong 32 |
| 23 | const JWDELTA ulong 38 |
| 24 | const JWSEL ulong 43 |
| 25 | const JWTAP ulong 49 |
| 26 | const JWPROC ulong 52 |
| 27 | const JWSTAT ulong 58 |
| 28 | const JWSTATUS ulong 63 |
| 29 | const JWLOADAV ulong 70 |
| 30 | const JWSELF ulong 83 |
| 31 | const JWHWM ulong 98 |
| 32 | const JWRSS ulong 104 |
| 33 | const JWARM ulong 110 |
| 34 | const JWREP ulong 114 |
| 35 | const JWG ulong 119 |
| 36 | const JWLOG ulong 121 |
| 37 | const JWPLOG ulong 125 |
| 38 | const JWACQ ulong 133 |
| 39 | const JWACQ2 ulong 140 |
| 40 | const JWMANS ulong 144 |
| 41 | const JWINDEX ulong 151 |
| 42 | const JWSESS ulong 156 |
| 43 | const JWREQ ulong 164 |
| 44 | const JWEXP ulong 168 |
| 45 | const JWCUR ulong 172 |
| 46 | const JWGEN ulong 179 |
| 47 | const JWMAN ulong 183 |
| 48 | const JWELF ulong 187 |
| 49 | const JWOM ulong 191 |
| 50 | const JWCAL ulong 194 |
| 51 | const JWMSHA ulong 198 |
| 52 | const JWBUILD ulong 214 |
| 53 | const JWAUTH ulong 219 |
| 54 | const JWREVK ulong 231 |
| 55 | const JWMC1 ulong 240 |
| 56 | const JWMC1B ulong 249 |
| 57 | const JWMC1C ulong 259 |
| 58 | const JWUCHK ulong 269 |
| 59 | const JWUDEL ulong 280 |
| 60 | const JWCRASH ulong 291 |
| 61 | const JWCLOG ulong 302 |
| 62 | const JWLIB ulong 314 |
| 63 | const JWCTL ulong 318 |
| 64 | const JWHEX ulong 319 |
| 65 | const JWTMP ulong 335 |
| 66 | const JWCTRL ulong 339 |
| 67 | const JWAEQ ulong 343 |
| 68 | const JWWRONG ulong 347 |
| 69 | const JWVIOL ulong 354 |
| 70 | const JWTSHA ulong 366 |
| 71 | const JWTBYT ulong 377 |
| 72 | const JWDEX ulong 388 |
| 73 | const JWELNS ulong 399 |
| 74 | const JWMATCH ulong 411 |
| 75 | const JWBLK ulong 425 |
| 76 | const JWPIN ulong 441 |
| 77 | const JWUSAGE ulong 449 |
| 78 | const JWQRY ulong 526 |
| 79 | const JWCSHA ulong 535 |
| 80 | const JWERR ulong 546 |
| 81 | const JWUNIT ulong 558 |
| 82 | const JWMUT ulong 563 |
| 83 | const JMIX ulong 0 |
| 84 | const JMSE ulong 4096 |
| 85 | const JMEX ulong 1048576 |
| 86 | const JMRQ ulong 2097152 |
| 87 | const JMOF ulong 8388608 |
| 88 | const JMPRC ulong 9437150 |
| 89 | const JMEND ulong 9437180 |
| 90 | const JMRT ulong 9437184 |
| 91 | const JMSC ulong 10485760 |
| 92 | const JDNONE ulong 18446744073709551615 |
| 93 | global JDS uchar 131072 |
| 94 | global JDSL ulong 32 |
| 95 | global JDM ulong 16777216 |
| 96 | global JDF uchar 16777216 |
| 97 | global JDLB uchar 8388608 |
| 98 | global JDIO uchar 65536 |
| 99 | global JDWB uchar 65536 |
| 100 | global JDPK uchar 4096 |
| 101 | global JDPKN ulong 2 |
| 102 | global JDPF uchar 16 |
| 103 | global JDWS uchar 4 |
| 104 | global JDST uchar 128 |
| 105 | global JDRS ulong 40 |
| 106 | global JDSM ulong 1 |
| 107 | global JDC ulong 64 |
| 108 | global JDA ulong 64 |
| 109 | global JDH ulong 4 |
| 110 | global JDT ulong 8 |
| 111 | global JDXA uchar 16384 |
| 112 | global JDXL ulong 130 |
| 113 | global JDQ ulong 8 |
| 114 | |
| 115 | note ---- string registers ---- |
| 116 | |
| 117 | fn jdsclr r ulong to void |
| 118 | put JDSL r 0 |
| 119 | end |
| 120 | |
| 121 | fn jdsc r ulong c uchar to void |
| 122 | n = get JDSL r |
| 123 | if ge n 4095 |
| 124 | trap 3 |
| 125 | end |
| 126 | put JDS add mul r 4096 n c |
| 127 | put JDSL r add n 1 |
| 128 | end |
| 129 | |
| 130 | fn jdsw r ulong off ulong n ulong to void |
| 131 | for i ulong n |
| 132 | jdsc r get JDW add off i |
| 133 | end |
| 134 | end |
| 135 | |
| 136 | fn jdsr r ulong s ulong to void |
| 137 | n = get JDSL s |
| 138 | b = mul s 4096 |
| 139 | for i ulong n |
| 140 | jdsc r get JDS add b i |
| 141 | end |
| 142 | end |
| 143 | |
| 144 | fn jdscp r ulong s ulong to void |
| 145 | if eq r s |
| 146 | ret |
| 147 | end |
| 148 | jdsclr r |
| 149 | jdsr r s |
| 150 | end |
| 151 | |
| 152 | fn jdsnum r ulong v ulong w ulong to void |
| 153 | d = new uchar 24 0 |
| 154 | k = ulong 0 |
| 155 | x = v |
| 156 | while true bound 24 |
| 157 | put d k uchar add rem x 10 48 |
| 158 | k = add k 1 |
| 159 | x = div x 10 |
| 160 | if and eq x 0 ge k w |
| 161 | break |
| 162 | end |
| 163 | end |
| 164 | while gt k 0 bound 24 |
| 165 | k = sub k 1 |
| 166 | jdsc r get d k |
| 167 | end |
| 168 | end |
| 169 | |
| 170 | fn jdshex r ulong v ulong to void |
| 171 | for i ulong 16 |
| 172 | sh = mul sub 15 i 4 |
| 173 | jdsc r get JDW add JWHEX and shr v sh 15 |
| 174 | end |
| 175 | end |
| 176 | |
| 177 | fn jdsarg r ulong i ulong to bool |
| 178 | n = argread i JDS mul r 4096 4095 |
| 179 | if lt n 0 |
| 180 | put JDSL r 0 |
| 181 | ret false |
| 182 | end |
| 183 | put JDSL r ulong n |
| 184 | ret true |
| 185 | end |
| 186 | |
| 187 | fn jdseq r ulong s ulong to bool |
| 188 | n = get JDSL r |
| 189 | if ne n get JDSL s |
| 190 | ret false |
| 191 | end |
| 192 | a = mul r 4096 |
| 193 | b = mul s 4096 |
| 194 | for i ulong n |
| 195 | if ne get JDS add a i get JDS add b i |
| 196 | ret false |
| 197 | end |
| 198 | end |
| 199 | ret true |
| 200 | end |
| 201 | |
| 202 | fn jdsdash r ulong to bool |
| 203 | if ne get JDSL r 1 |
| 204 | ret false |
| 205 | end |
| 206 | ret eq get JDS mul r 4096 45 |
| 207 | end |
| 208 | |
| 209 | fn jdsdsh r ulong to void |
| 210 | jdsclr r |
| 211 | jdsc r 45 |
| 212 | end |
| 213 | |
| 214 | fn jdsval r ulong to ulong |
| 215 | n = get JDSL r |
| 216 | if or eq n 0 gt n 20 |
| 217 | ret JDNONE |
| 218 | end |
| 219 | b = mul r 4096 |
| 220 | v = ulong 0 |
| 221 | for i ulong n |
| 222 | c = ulong get JDS add b i |
| 223 | if or lt c 48 gt c 57 |
| 224 | ret JDNONE |
| 225 | end |
| 226 | v = add mul v 10 sub c 48 |
| 227 | end |
| 228 | ret v |
| 229 | end |
| 230 | |
| 231 | fn jdspack r ulong to ulong |
| 232 | n = get JDSL r |
| 233 | if gt n 8 |
| 234 | ret 0 |
| 235 | end |
| 236 | b = mul r 4096 |
| 237 | v = ulong 0 |
| 238 | for i ulong n |
| 239 | v = or v shl ulong get JDS add b i mul i 8 |
| 240 | end |
| 241 | ret v |
| 242 | end |
| 243 | |
| 244 | note byte i of register r, 256 past the end |
| 245 | fn jdsb r ulong i ulong to ulong |
| 246 | if ge i get JDSL r |
| 247 | ret 256 |
| 248 | end |
| 249 | ret ulong get JDS add mul r 4096 i |
| 250 | end |
| 251 | |
| 252 | note true if register r starts with the JDW bytes off..off+n |
| 253 | fn jdspre r ulong off ulong n ulong to bool |
| 254 | if lt get JDSL r n |
| 255 | ret false |
| 256 | end |
| 257 | b = mul r 4096 |
| 258 | for i ulong n |
| 259 | if ne get JDS add b i get JDW add off i |
| 260 | ret false |
| 261 | end |
| 262 | end |
| 263 | ret true |
| 264 | end |
| 265 | |
| 266 | fn jdhexd c ulong to ulong |
| 267 | if and ge c 48 le c 57 |
| 268 | ret sub c 48 |
| 269 | end |
| 270 | if and ge c 97 le c 102 |
| 271 | ret sub c 87 |
| 272 | end |
| 273 | if and ge c 65 le c 70 |
| 274 | ret sub c 55 |
| 275 | end |
| 276 | ret 16 |
| 277 | end |
| 278 | |
| 279 | note the byte k of a hex string in register r (2 hex digits), 256 if bad |
| 280 | fn jdshexb r ulong k ulong to ulong |
| 281 | hi = jdhexd jdsb r mul k 2 |
| 282 | lo = jdhexd jdsb r add mul k 2 1 |
| 283 | if or gt hi 15 gt lo 15 |
| 284 | ret 256 |
| 285 | end |
| 286 | ret add mul hi 16 lo |
| 287 | end |
| 288 | |
| 289 | fn jdsout r ulong to void |
| 290 | jdsc r 10 |
| 291 | n = write 1 JDS mul r 4096 get JDSL r |
| 292 | put JDSL r sub get JDSL r 1 |
| 293 | end |
| 294 | |
| 295 | note append the string form of an 8-word path: dir r, "/", then JDW off..off+n |
| 296 | fn jdspath r ulong d ulong off ulong n ulong to void |
| 297 | jdscp r d |
| 298 | jdsc r 47 |
| 299 | jdsw r off n |
| 300 | end |
| 301 | |
| 302 | note ---- little-endian words in byte pools ---- |
| 303 | |
| 304 | fn jdgfw off ulong to ulong |
| 305 | v = ulong 0 |
| 306 | i = ulong 8 |
| 307 | while gt i 0 bound 8 |
| 308 | i = sub i 1 |
| 309 | v = or shl v 8 ulong get JDF add off i |
| 310 | end |
| 311 | ret v |
| 312 | end |
| 313 | |
| 314 | fn jdpfw off ulong v ulong to void |
| 315 | x = v |
| 316 | for i ulong 8 |
| 317 | put JDF add off i uchar and x 255 |
| 318 | x = shr x 8 |
| 319 | end |
| 320 | end |
| 321 | |
| 322 | fn jdgiw off ulong to ulong |
| 323 | v = ulong 0 |
| 324 | i = ulong 8 |
| 325 | while gt i 0 bound 8 |
| 326 | i = sub i 1 |
| 327 | v = or shl v 8 ulong get JDIO add off i |
| 328 | end |
| 329 | ret v |
| 330 | end |
| 331 | |
| 332 | fn jdpiw off ulong v ulong to void |
| 333 | x = v |
| 334 | for i ulong 8 |
| 335 | put JDIO add off i uchar and x 255 |
| 336 | x = shr x 8 |
| 337 | end |
| 338 | end |
| 339 | |
| 340 | fn jdpww off ulong v ulong to void |
| 341 | x = v |
| 342 | for i ulong 8 |
| 343 | put JDWB add off i uchar and x 255 |
| 344 | x = shr x 8 |
| 345 | end |
| 346 | end |
| 347 | |
| 348 | fn jdplw off ulong v ulong to void |
| 349 | x = v |
| 350 | for i ulong 8 |
| 351 | put JDLB add off i uchar and x 255 |
| 352 | x = shr x 8 |
| 353 | end |
| 354 | end |
| 355 | |
| 356 | fn jdbswap x ulong to ulong |
| 357 | v = ulong 0 |
| 358 | y = x |
| 359 | for i ulong 8 |
| 360 | v = or shl v 8 and y 255 |
| 361 | y = shr y 8 |
| 362 | end |
| 363 | ret v |
| 364 | end |
| 365 | |
| 366 | note ---- files ---- |
| 367 | |
| 368 | fn jdopen r ulong flags int to long |
| 369 | ret fopen JDS mul r 4096 get JDSL r flags 420 |
| 370 | end |
| 371 | |
| 372 | fn jdexists r ulong to bool |
| 373 | x = faccess JDS mul r 4096 get JDSL r 0 |
| 374 | ret eq x 0 |
| 375 | end |
| 376 | |
| 377 | fn jdmkdir r ulong mode int to long |
| 378 | ret makedir JDS mul r 4096 get JDSL r mode |
| 379 | end |
| 380 | |
| 381 | note whole file of register r into JDF; byte count, -1 open/read error, -2 too big |
| 382 | fn jdldf r ulong to long |
| 383 | x = jdopen r 0 |
| 384 | if lt x 0 |
| 385 | ret -1 |
| 386 | end |
| 387 | fd = int x |
| 388 | tot = ulong 0 |
| 389 | while true bound 999999 |
| 390 | if ge tot 16777216 |
| 391 | c = fclose fd |
| 392 | ret -2 |
| 393 | end |
| 394 | k = read fd JDF tot sub 16777216 tot |
| 395 | if lt k 0 |
| 396 | c = fclose fd |
| 397 | ret -1 |
| 398 | end |
| 399 | if eq k 0 |
| 400 | break |
| 401 | end |
| 402 | tot = add tot ulong k |
| 403 | end |
| 404 | c = fclose fd |
| 405 | ret long tot |
| 406 | end |
| 407 | |
| 408 | note JDF[0..n) to the file of register r with open flags (577 truncate, 1089 append, 705 new) |
| 409 | fn jdwrf r ulong n ulong flags int to long |
| 410 | x = jdopen r flags |
| 411 | if lt x 0 |
| 412 | ret x |
| 413 | end |
| 414 | fd = int x |
| 415 | off = ulong 0 |
| 416 | while lt off n bound 999999 |
| 417 | k = write fd JDF off sub n off |
| 418 | if le k 0 |
| 419 | c = fclose fd |
| 420 | ret -1 |
| 421 | end |
| 422 | off = add off ulong k |
| 423 | end |
| 424 | c = fsync fd |
| 425 | c = fclose fd |
| 426 | ret 0 |
| 427 | end |
| 428 | |
| 429 | note words of file r into JDM[base..); word count, or negative |
| 430 | fn jdldw r ulong base ulong maxw ulong to long |
| 431 | n = jdldf r |
| 432 | if lt n 0 |
| 433 | ret n |
| 434 | end |
| 435 | nb = ulong n |
| 436 | if ne and nb 7 0 |
| 437 | ret -3 |
| 438 | end |
| 439 | nw = shr nb 3 |
| 440 | if gt nw maxw |
| 441 | ret -2 |
| 442 | end |
| 443 | for i ulong nw |
| 444 | put JDM add base i jdgfw shl i 3 |
| 445 | end |
| 446 | ret long nw |
| 447 | end |
| 448 | |
| 449 | fn jdw2wb b ulong k ulong to void |
| 450 | for i ulong k |
| 451 | v = get JDM add b i |
| 452 | jdpww shl i 3 v |
| 453 | end |
| 454 | end |
| 455 | |
| 456 | note JDM[base..base+nw) to file r (flags as jdwrf) |
| 457 | fn jdstw r ulong base ulong nw ulong flags int to long |
| 458 | x = jdopen r flags |
| 459 | if lt x 0 |
| 460 | ret x |
| 461 | end |
| 462 | fd = int x |
| 463 | done = ulong 0 |
| 464 | while lt done nw bound 999999 |
| 465 | k = sub nw done |
| 466 | if gt k 8192 |
| 467 | k = 8192 |
| 468 | end |
| 469 | jdw2wb add base done k |
| 470 | w = write fd JDWB 0 shl k 3 |
| 471 | if ne w long shl k 3 |
| 472 | c = fclose fd |
| 473 | ret -1 |
| 474 | end |
| 475 | done = add done k |
| 476 | end |
| 477 | c = fsync fd |
| 478 | c = fclose fd |
| 479 | ret 0 |
| 480 | end |
| 481 | |
| 482 | note small file (at most 65535 bytes) of register r into JDWB; bytes or negative |
| 483 | fn jdldsm r ulong to long |
| 484 | x = jdopen r 0 |
| 485 | if lt x 0 |
| 486 | ret x |
| 487 | end |
| 488 | fd = int x |
| 489 | k = read fd JDWB 0 65535 |
| 490 | c = fclose fd |
| 491 | ret k |
| 492 | end |
| 493 | |
| 494 | note file size of register r, -1 if missing |
| 495 | fn jdfsize r ulong to long |
| 496 | x = stat JDS mul r 4096 get JDSL r JDST 0 128 |
| 497 | if ne x 0 |
| 498 | ret -1 |
| 499 | end |
| 500 | v = ulong 0 |
| 501 | i = ulong 8 |
| 502 | while gt i 0 bound 8 |
| 503 | i = sub i 1 |
| 504 | v = or shl v 8 ulong get JDST add 48 i |
| 505 | end |
| 506 | ret long v |
| 507 | end |
| 508 | |
| 509 | note mode bits of register r (st_mode), 0 if missing |
| 510 | fn jdfmode r ulong to ulong |
| 511 | x = stat JDS mul r 4096 get JDSL r JDST 0 128 |
| 512 | if ne x 0 |
| 513 | ret 0 |
| 514 | end |
| 515 | v = or ulong get JDST 16 shl ulong get JDST 17 8 |
| 516 | v = or v shl ulong get JDST 18 16 |
| 517 | ret v |
| 518 | end |
| 519 | |
| 520 | note copy file register s to register d (new file, same permission bits) |
| 521 | fn jdcpf s ulong d ulong to int |
| 522 | m = jdfmode s |
| 523 | if ne and m 61440 32768 |
| 524 | ret 1 |
| 525 | end |
| 526 | n = jdldf s |
| 527 | if lt n 0 |
| 528 | ret 2 |
| 529 | end |
| 530 | x = jdopen d 705 |
| 531 | if lt x 0 |
| 532 | ret 3 |
| 533 | end |
| 534 | fd = int x |
| 535 | c = fchmod fd int and m 4095 |
| 536 | off = ulong 0 |
| 537 | nb = ulong n |
| 538 | while lt off nb bound 999999 |
| 539 | k = write fd JDF off sub nb off |
| 540 | if le k 0 |
| 541 | c = fclose fd |
| 542 | ret 4 |
| 543 | end |
| 544 | off = add off ulong k |
| 545 | end |
| 546 | c = fsync fd |
| 547 | c = fclose fd |
| 548 | ret 0 |
| 549 | end |
| 550 | |
| 551 | fn jdu16 off ulong to ulong |
| 552 | ret or ulong get JDWB off shl ulong get JDWB add off 1 8 |
| 553 | end |
| 554 | |
| 555 | note the name of the getdents64 record at pos appended to register r |
| 556 | fn jddname pos ulong r ulong to void |
| 557 | k = add pos 19 |
| 558 | while ne get JDWB k 0 bound 256 |
| 559 | jdsc r get JDWB k |
| 560 | k = add k 1 |
| 561 | end |
| 562 | end |
| 563 | |
| 564 | note one directory record: copy (mode 1, s -> d) or size (mode 0); names in registers 0 and 1 |
| 565 | fn jddent pos ulong s ulong d ulong mode ulong to ulong |
| 566 | jdscp 0 s |
| 567 | jdsc 0 47 |
| 568 | jddname pos 0 |
| 569 | m = jdfmode 0 |
| 570 | if ne and m 61440 32768 |
| 571 | ret 0 |
| 572 | end |
| 573 | if eq mode 0 |
| 574 | z = jdfsize 0 |
| 575 | if gt z 0 |
| 576 | ret ulong z |
| 577 | end |
| 578 | ret 0 |
| 579 | end |
| 580 | jdscp 1 d |
| 581 | jdsc 1 47 |
| 582 | jddname pos 1 |
| 583 | c = jdcpf 0 1 |
| 584 | if ne c 0 |
| 585 | ret add 10 ulong c |
| 586 | end |
| 587 | ret 0 |
| 588 | end |
| 589 | |
| 590 | note walk directory register s: mode 1 copies regular files into d (error code back), mode 0 sums sizes |
| 591 | fn jdwalk s ulong d ulong mode ulong to ulong |
| 592 | x = jdopen s 0 |
| 593 | if lt x 0 |
| 594 | ret JDNONE |
| 595 | end |
| 596 | fd = int x |
| 597 | acc = ulong 0 |
| 598 | while true bound 100000 |
| 599 | n = getdnts fd JDWB 0 65536 |
| 600 | if le n 0 |
| 601 | break |
| 602 | end |
| 603 | pos = ulong 0 |
| 604 | while lt pos ulong n bound 100000 |
| 605 | v = jddent pos s d mode |
| 606 | if eq mode 0 |
| 607 | acc = add acc v |
| 608 | else |
| 609 | if ne v 0 |
| 610 | acc = v |
| 611 | end |
| 612 | end |
| 613 | pos = add pos jdu16 add pos 16 |
| 614 | end |
| 615 | end |
| 616 | c = fclose fd |
| 617 | ret acc |
| 618 | end |
| 619 | |
| 620 | note copy every regular file of directory register s into a new directory register d (mode 0700) |
| 621 | fn jdcpdir s ulong d ulong to int |
| 622 | r = jdmkdir d 448 |
| 623 | if ne r 0 |
| 624 | ret 1 |
| 625 | end |
| 626 | e = jdwalk s d 1 |
| 627 | if ne e 0 |
| 628 | ret 2 |
| 629 | end |
| 630 | ret 0 |
| 631 | end |
| 632 | |
| 633 | note sum of st_size of the regular files of directory register s |
| 634 | fn jddirb s ulong to ulong |
| 635 | v = jdwalk s s 0 |
| 636 | if eq v JDNONE |
| 637 | ret 0 |
| 638 | end |
| 639 | ret v |
| 640 | end |
| 641 | |
| 642 | note make register r absolute against the current directory (register 31 is scratch) |
| 643 | fn jdabs r ulong to void |
| 644 | if eq jdsb r 0 47 |
| 645 | ret |
| 646 | end |
| 647 | n = cwd JDWB 0 4096 |
| 648 | if le n 1 |
| 649 | ret |
| 650 | end |
| 651 | jdsclr 31 |
| 652 | for i ulong sub ulong n 1 |
| 653 | jdsc 31 get JDWB i |
| 654 | end |
| 655 | jdsc 31 47 |
| 656 | jdsr 31 r |
| 657 | jdscp r 31 |
| 658 | end |
| 659 | |
| 660 | note ---- SHA-256 (sha256 unit, omsha) ---- |
| 661 | |
| 662 | fn jdhput w view ulong 64 to void |
| 663 | for i ulong 4 |
| 664 | put JDH i jdbswap get w i |
| 665 | end |
| 666 | end |
| 667 | |
| 668 | note SHA-256 of the file of register r into JDH (big-endian words); size or -1 |
| 669 | fn jdhfile r ulong to long |
| 670 | c = new uchar 104 0 |
| 671 | b = new uchar 4096 0 |
| 672 | w = new ulong 64 0 |
| 673 | b8 = new ulong 512 0 |
| 674 | omsha c b 0 0 w b8 |
| 675 | x = jdopen r 0 |
| 676 | if lt x 0 |
| 677 | ret -1 |
| 678 | end |
| 679 | fd = int x |
| 680 | tot = ulong 0 |
| 681 | while true bound 999999 |
| 682 | k = read fd b 0 4096 |
| 683 | if lt k 0 |
| 684 | y = fclose fd |
| 685 | ret -1 |
| 686 | end |
| 687 | if eq k 0 |
| 688 | break |
| 689 | end |
| 690 | omsha c b ulong k 1 w b8 |
| 691 | tot = add tot ulong k |
| 692 | end |
| 693 | y = fclose fd |
| 694 | omsha c b 0 2 w b8 |
| 695 | jdhput w |
| 696 | ret long tot |
| 697 | end |
| 698 | |
| 699 | fn jdhcpf b edit uchar 4096 off ulong k ulong to void |
| 700 | for j ulong k |
| 701 | put b j get JDF add off j |
| 702 | end |
| 703 | end |
| 704 | |
| 705 | note SHA-256 of JDF[off..off+n) into JDH |
| 706 | fn jdhjdf off ulong n ulong to void |
| 707 | c = new uchar 104 0 |
| 708 | b = new uchar 4096 0 |
| 709 | w = new ulong 64 0 |
| 710 | b8 = new ulong 512 0 |
| 711 | omsha c b 0 0 w b8 |
| 712 | d = ulong 0 |
| 713 | while lt d n bound 999999 |
| 714 | k = sub n d |
| 715 | if gt k 4096 |
| 716 | k = 4096 |
| 717 | end |
| 718 | jdhcpf b add off d k |
| 719 | omsha c b k 1 w b8 |
| 720 | d = add d k |
| 721 | end |
| 722 | omsha c b 0 2 w b8 |
| 723 | jdhput w |
| 724 | end |
| 725 | |
| 726 | note the 64 hex digits of JDH appended to register r |
| 727 | fn jdshash r ulong to void |
| 728 | for i ulong 4 |
| 729 | jdshex r get JDH i |
| 730 | end |
| 731 | end |
| 732 | |
| 733 | note ---- splitmix64 ---- |
| 734 | |
| 735 | fn jdsmix to ulong |
| 736 | s = add get JDSM 0 11400714819323198485 |
| 737 | put JDSM 0 s |
| 738 | z = mul xor s shr s 30 13787848793156543929 |
| 739 | z = mul xor z shr z 27 10723151780598845931 |
| 740 | ret xor z shr z 31 |
| 741 | end |
| 742 | |
| 743 | note ---- argument packets for execprog ---- |
| 744 | |
| 745 | fn jdpk0 to void |
| 746 | put JDPKN 0 2 |
| 747 | put JDPKN 1 0 |
| 748 | end |
| 749 | |
| 750 | fn jdpkb c uchar to void |
| 751 | n = get JDPKN 0 |
| 752 | if ge n 4096 |
| 753 | trap 3 |
| 754 | end |
| 755 | put JDPK n c |
| 756 | put JDPKN 0 add n 1 |
| 757 | end |
| 758 | |
| 759 | fn jdpkr r ulong to void |
| 760 | n = get JDSL r |
| 761 | jdpkb uchar and n 255 |
| 762 | jdpkb uchar shr n 8 |
| 763 | b = mul r 4096 |
| 764 | for i ulong n |
| 765 | jdpkb get JDS add b i |
| 766 | end |
| 767 | put JDPKN 1 add get JDPKN 1 1 |
| 768 | end |
| 769 | |
| 770 | note extra-argument list JDXA / JDXL (0 count, 1 + 2i offset, 2 + 2i length) |
| 771 | fn jdx0 to void |
| 772 | put JDXL 0 0 |
| 773 | end |
| 774 | |
| 775 | fn jdxadd r ulong to void |
| 776 | k = get JDXL 0 |
| 777 | if ge k 64 |
| 778 | trap 3 |
| 779 | end |
| 780 | off = ulong 0 |
| 781 | if gt k 0 |
| 782 | off = add get JDXL sub mul k 2 1 get JDXL mul k 2 |
| 783 | end |
| 784 | n = get JDSL r |
| 785 | if gt add off n 16384 |
| 786 | trap 3 |
| 787 | end |
| 788 | b = mul r 4096 |
| 789 | for i ulong n |
| 790 | put JDXA add off i get JDS add b i |
| 791 | end |
| 792 | put JDXL add mul k 2 1 off |
| 793 | put JDXL add mul k 2 2 n |
| 794 | put JDXL 0 add k 1 |
| 795 | end |
| 796 | |
| 797 | note list item i into register r |
| 798 | fn jdxget r ulong i ulong to void |
| 799 | jdsclr r |
| 800 | off = get JDXL add mul i 2 1 |
| 801 | n = get JDXL add mul i 2 2 |
| 802 | for j ulong n |
| 803 | jdsc r get JDXA add off j |
| 804 | end |
| 805 | end |
| 806 | |
| 807 | fn jdpkfin to void |
| 808 | c = get JDPKN 1 |
| 809 | put JDPK 0 uchar and c 255 |
| 810 | put JDPK 1 uchar shr c 8 |
| 811 | end |
| 812 | |
| 813 | note ---- /proc readings ---- |
| 814 | |
| 815 | note /proc/PID/stat (or /proc/self/stat for pid 0) fields into JDT: 0 utime 1 stime 2 cutime |
| 816 | note 3 cstime 4 processor; 0 ok |
| 817 | fn jdprocst pid ulong to int |
| 818 | jdsclr 0 |
| 819 | if eq pid 0 |
| 820 | jdsw 0 JWSELF 15 |
| 821 | else |
| 822 | jdsw 0 JWPROC 6 |
| 823 | jdsnum 0 pid 1 |
| 824 | jdsw 0 JWSTAT 5 |
| 825 | end |
| 826 | n = jdldsm 0 |
| 827 | if le n 0 |
| 828 | ret 1 |
| 829 | end |
| 830 | nb = ulong n |
| 831 | p = ulong 0 |
| 832 | for i ulong nb |
| 833 | if eq get JDWB i 41 |
| 834 | p = i |
| 835 | end |
| 836 | end |
| 837 | tok = ulong 0 |
| 838 | v = ulong 0 |
| 839 | i = add p 2 |
| 840 | while lt i nb bound 65536 |
| 841 | c = ulong get JDWB i |
| 842 | if or eq c 32 eq c 10 |
| 843 | jdstok tok v |
| 844 | tok = add tok 1 |
| 845 | v = 0 |
| 846 | else |
| 847 | if and ge c 48 le c 57 |
| 848 | v = add mul v 10 sub c 48 |
| 849 | end |
| 850 | end |
| 851 | i = add i 1 |
| 852 | end |
| 853 | ret 0 |
| 854 | end |
| 855 | |
| 856 | fn jdstok tok ulong v ulong to void |
| 857 | if and ge tok 11 le tok 14 |
| 858 | put JDT sub tok 11 v |
| 859 | end |
| 860 | if eq tok 36 |
| 861 | put JDT 4 v |
| 862 | end |
| 863 | end |
| 864 | |
| 865 | note index of JDW[off..off+wn) in JDWB[0..n), or n |
| 866 | fn jdfindw n ulong off ulong wn ulong to ulong |
| 867 | if lt n wn |
| 868 | ret n |
| 869 | end |
| 870 | for i ulong add sub n wn 1 |
| 871 | k = ulong 0 |
| 872 | while lt k wn bound 64 |
| 873 | if ne get JDWB add i k get JDW add off k |
| 874 | break |
| 875 | end |
| 876 | k = add k 1 |
| 877 | end |
| 878 | if eq k wn |
| 879 | ret i |
| 880 | end |
| 881 | end |
| 882 | ret n |
| 883 | end |
| 884 | |
| 885 | note first decimal number in JDWB at or after p (stops at a newline after digits) |
| 886 | fn jdnumat p ulong n ulong to ulong |
| 887 | v = ulong 0 |
| 888 | seen = false |
| 889 | i = p |
| 890 | while lt i n bound 65536 |
| 891 | c = ulong get JDWB i |
| 892 | if and ge c 48 le c 57 |
| 893 | v = add mul v 10 sub c 48 |
| 894 | seen = true |
| 895 | else |
| 896 | if seen |
| 897 | break |
| 898 | end |
| 899 | end |
| 900 | i = add i 1 |
| 901 | end |
| 902 | ret v |
| 903 | end |
| 904 | |
| 905 | note VmHWM and VmRSS kB of pid into JDT 5, 6 |
| 906 | fn jdprocmem pid ulong to void |
| 907 | put JDT 5 0 |
| 908 | put JDT 6 0 |
| 909 | jdsclr 0 |
| 910 | jdsw 0 JWPROC 6 |
| 911 | jdsnum 0 pid 1 |
| 912 | jdsw 0 JWSTATUS 7 |
| 913 | n = jdldsm 0 |
| 914 | if le n 0 |
| 915 | ret |
| 916 | end |
| 917 | nb = ulong n |
| 918 | p = jdfindw nb JWHWM 6 |
| 919 | if lt p nb |
| 920 | put JDT 5 jdnumat p nb |
| 921 | end |
| 922 | p = jdfindw nb JWRSS 6 |
| 923 | if lt p nb |
| 924 | put JDT 6 jdnumat p nb |
| 925 | end |
| 926 | end |
| 927 | |
| 928 | note first /proc/loadavg value x 100 |
| 929 | fn jdloadav to ulong |
| 930 | jdsclr 0 |
| 931 | jdsw 0 JWLOADAV 13 |
| 932 | n = jdldsm 0 |
| 933 | if le n 0 |
| 934 | ret 0 |
| 935 | end |
| 936 | v = ulong 0 |
| 937 | fr = ulong 0 |
| 938 | dig = ulong 0 |
| 939 | dot = false |
| 940 | for i ulong ulong n |
| 941 | c = ulong get JDWB i |
| 942 | if eq c 32 |
| 943 | break |
| 944 | end |
| 945 | if eq c 46 |
| 946 | dot = true |
| 947 | continue |
| 948 | end |
| 949 | if and ge c 48 le c 57 |
| 950 | if dot |
| 951 | if lt dig 2 |
| 952 | fr = add mul fr 10 sub c 48 |
| 953 | dig = add dig 1 |
| 954 | end |
| 955 | else |
| 956 | v = add mul v 10 sub c 48 |
| 957 | end |
| 958 | end |
| 959 | end |
| 960 | while lt dig 2 bound 2 |
| 961 | fr = mul fr 10 |
| 962 | dig = add dig 1 |
| 963 | end |
| 964 | ret add mul v 100 fr |
| 965 | end |
| 966 | |
| 967 | note ---- arm processes ---- |
| 968 | note JDC: 0 pid, 1 write fd, 2 read fd, 3 kept stdin read end, 4 t0, 5 start-to-ready, 6 sum rt, |
| 969 | note 7 requests sent, 8 alive, 9 violation code, 10 arm id, 11 group, 12 repetition, 13 loadavg, |
| 970 | note 14 log bytes in JDLB, 15 requests done by this process, 16 revoke-at request, 17 kill-at |
| 971 | note request, 18 exit status, 19 log enabled, 20 utime, 21 stime, 22 cutime, 23 cstime, 24 cpu, |
| 972 | note 25 hwm, 26 rss, 27 proc read done. |
| 973 | note JDA counters: 0 QUERYs, 1 wrong (correctness 0), 2..7 QUERY routes 0..5, 8 other routes, |
| 974 | note 10 QUERYs after revoke, 11 route 3/4 after, 12 route 5 after, 13 route 3/4 before, 14 wrong |
| 975 | note QUERYs, 15 violations. |
| 976 | |
| 977 | fn jdfdw off ulong to int |
| 978 | x = ulong 0 |
| 979 | for i ulong 4 |
| 980 | v = ulong get JDPF add off i |
| 981 | x = or x shl v mul i 8 |
| 982 | end |
| 983 | ret int x |
| 984 | end |
| 985 | |
| 986 | fn jdspawn to long |
| 987 | r = pipefds JDPF 0 8 524288 |
| 988 | if ne r 0 |
| 989 | ret -1 |
| 990 | end |
| 991 | r = pipefds JDPF 8 8 524288 |
| 992 | if ne r 0 |
| 993 | ret -1 |
| 994 | end |
| 995 | a0 = jdfdw 0 |
| 996 | a1 = jdfdw 4 |
| 997 | b0 = jdfdw 8 |
| 998 | b1 = jdfdw 12 |
| 999 | pid = fork |
| 1000 | if lt pid 0 |
| 1001 | ret -1 |
| 1002 | end |
| 1003 | if eq pid 0 |
| 1004 | d = dupfd a0 0 0 |
| 1005 | d = dupfd b1 1 0 |
| 1006 | e = execprog JDPK 0 get JDPKN 0 |
| 1007 | exit 127 |
| 1008 | end |
| 1009 | c = fclose b1 |
| 1010 | put JDC 0 ulong pid |
| 1011 | put JDC 1 ulong a1 |
| 1012 | put JDC 2 ulong b0 |
| 1013 | put JDC 3 ulong a0 |
| 1014 | ret pid |
| 1015 | end |
| 1016 | |
| 1017 | fn jdarmname r ulong a ulong to void |
| 1018 | jdsclr r |
| 1019 | if eq a 0 |
| 1020 | jdsw r JWECHO 4 |
| 1021 | end |
| 1022 | if eq a 1 |
| 1023 | jdsw r JWFULL 4 |
| 1024 | end |
| 1025 | if eq a 2 |
| 1026 | jdsw r JWCACHE 5 |
| 1027 | end |
| 1028 | if eq a 3 |
| 1029 | jdsw r JWMETH 6 |
| 1030 | end |
| 1031 | if and ge a 4 le a 6 |
| 1032 | jdsw r JWDELTA 5 |
| 1033 | end |
| 1034 | if eq a 7 |
| 1035 | jdsw r JWSEL 6 |
| 1036 | end |
| 1037 | if eq a 8 |
| 1038 | jdsw r JWTAP 3 |
| 1039 | end |
| 1040 | end |
| 1041 | |
| 1042 | note packet: [taskset -c CPU] BASE ARM LIBDIR MANSHA ALLOW TAPFILE SPLIT |
| 1043 | fn jdarmpk to void |
| 1044 | jdpk0 |
| 1045 | if not jdsdash 7 |
| 1046 | jdsclr 0 |
| 1047 | jdsw 0 JWTASK 16 |
| 1048 | jdpkr 0 |
| 1049 | jdsclr 0 |
| 1050 | jdsw 0 JWDC 2 |
| 1051 | jdpkr 0 |
| 1052 | jdpkr 7 |
| 1053 | end |
| 1054 | jdpkr 5 |
| 1055 | jdpkr 8 |
| 1056 | jdpkr 9 |
| 1057 | jdpkr 10 |
| 1058 | jdpkr 11 |
| 1059 | jdpkr 12 |
| 1060 | jdpkr 13 |
| 1061 | jdpkfin |
| 1062 | end |
| 1063 | |
| 1064 | fn jdpstart to int |
| 1065 | jdarmpk |
| 1066 | put JDC 13 jdloadav |
| 1067 | t0 = monons |
| 1068 | pid = jdspawn |
| 1069 | if lt pid 0 |
| 1070 | ret 1 |
| 1071 | end |
| 1072 | put JDC 4 ulong t0 |
| 1073 | put JDC 5 0 |
| 1074 | put JDC 6 0 |
| 1075 | put JDC 7 0 |
| 1076 | put JDC 8 1 |
| 1077 | put JDC 9 0 |
| 1078 | put JDC 15 0 |
| 1079 | put JDC 18 0 |
| 1080 | put JDC 27 0 |
| 1081 | put JDC 28 0 |
| 1082 | for i ulong 5 |
| 1083 | put JDT i 0 |
| 1084 | end |
| 1085 | put JDT 5 0 |
| 1086 | put JDT 6 0 |
| 1087 | ret 0 |
| 1088 | end |
| 1089 | |
| 1090 | note write a frame JDM[off..off+nw) to the arm before deadline dl; 0 ok, 3 timeout, 4 write failure |
| 1091 | fn jdsend off ulong nw ulong dl long to int |
| 1092 | fd = int get JDC 1 |
| 1093 | nb = shl nw 3 |
| 1094 | if gt nb 65536 |
| 1095 | ret 4 |
| 1096 | end |
| 1097 | for i ulong nw |
| 1098 | jdpiw shl i 3 get JDM add off i |
| 1099 | end |
| 1100 | done = ulong 0 |
| 1101 | while lt done nb bound 999999 |
| 1102 | left = sub dl monons |
| 1103 | if le left 0 |
| 1104 | ret 3 |
| 1105 | end |
| 1106 | e = waitio fd 4 left |
| 1107 | if eq e 0 |
| 1108 | ret 3 |
| 1109 | end |
| 1110 | if or lt e 0 eq and e 4 0 |
| 1111 | ret 4 |
| 1112 | end |
| 1113 | k = sub nb done |
| 1114 | if gt k 4096 |
| 1115 | k = 4096 |
| 1116 | end |
| 1117 | w = write fd JDIO done k |
| 1118 | if le w 0 |
| 1119 | ret 4 |
| 1120 | end |
| 1121 | done = add done ulong w |
| 1122 | end |
| 1123 | ret 0 |
| 1124 | end |
| 1125 | |
| 1126 | note read exactly n bytes into JDIO[off..) before deadline dl; 0 ok, 1 end of file, 3 timeout |
| 1127 | fn jdrdn fd int off ulong n ulong dl long to int |
| 1128 | got = ulong 0 |
| 1129 | while lt got n bound 999999 |
| 1130 | left = sub dl monons |
| 1131 | if le left 0 |
| 1132 | ret 3 |
| 1133 | end |
| 1134 | e = waitio fd 1 left |
| 1135 | if lt e 0 |
| 1136 | ret 1 |
| 1137 | end |
| 1138 | if eq e 0 |
| 1139 | ret 3 |
| 1140 | end |
| 1141 | k = read fd JDIO add off got sub n got |
| 1142 | if le k 0 |
| 1143 | ret 1 |
| 1144 | end |
| 1145 | got = add got ulong k |
| 1146 | end |
| 1147 | ret 0 |
| 1148 | end |
| 1149 | |
| 1150 | note response into JDRS (0 status, 1 q, 2.. words); 0 ok, 1 short, 2 bad q, 3 timeout |
| 1151 | fn jdrecv dl long to int |
| 1152 | fd = int get JDC 2 |
| 1153 | e = jdrdn fd 0 16 dl |
| 1154 | if ne e 0 |
| 1155 | ret e |
| 1156 | end |
| 1157 | put JDRS 0 jdgiw 0 |
| 1158 | q = jdgiw 8 |
| 1159 | put JDRS 1 q |
| 1160 | if gt q 32 |
| 1161 | ret 2 |
| 1162 | end |
| 1163 | e = jdrdn fd 16 shl q 3 dl |
| 1164 | if ne e 0 |
| 1165 | ret e |
| 1166 | end |
| 1167 | for i ulong q |
| 1168 | put JDRS add 2 i jdgiw add 16 shl i 3 |
| 1169 | end |
| 1170 | ret 0 |
| 1171 | end |
| 1172 | |
| 1173 | note read /proc of the live arm once (before END or a kill) |
| 1174 | fn jdpread to void |
| 1175 | if ne get JDC 27 0 |
| 1176 | ret |
| 1177 | end |
| 1178 | pid = get JDC 0 |
| 1179 | r = jdprocst pid |
| 1180 | put JDC 20 get JDT 0 |
| 1181 | put JDC 21 get JDT 1 |
| 1182 | put JDC 22 get JDT 2 |
| 1183 | put JDC 23 get JDT 3 |
| 1184 | put JDC 24 get JDT 4 |
| 1185 | jdprocmem pid |
| 1186 | put JDC 25 get JDT 5 |
| 1187 | put JDC 26 get JDT 6 |
| 1188 | put JDC 27 1 |
| 1189 | end |
| 1190 | |
| 1191 | fn jdclosefd to void |
| 1192 | c = fclose int get JDC 1 |
| 1193 | c = fclose int get JDC 2 |
| 1194 | c = fclose int get JDC 3 |
| 1195 | end |
| 1196 | |
| 1197 | note wait status in JDWS to the proc.log exit word |
| 1198 | fn jdwstat to ulong |
| 1199 | sig = and ulong get JDWS 0 127 |
| 1200 | if ne sig 0 |
| 1201 | ret add 256 sig |
| 1202 | end |
| 1203 | ret ulong get JDWS 1 |
| 1204 | end |
| 1205 | |
| 1206 | note reap the arm within 10 s, killing it after that |
| 1207 | fn jdreap to void |
| 1208 | pid = int get JDC 0 |
| 1209 | dl = add monons 10000000000 |
| 1210 | while true bound 999999 |
| 1211 | r = waitpid pid JDWS 0 4 1 |
| 1212 | if eq r long pid |
| 1213 | put JDC 18 jdwstat |
| 1214 | ret |
| 1215 | end |
| 1216 | if lt r 0 |
| 1217 | put JDC 18 1023 |
| 1218 | ret |
| 1219 | end |
| 1220 | if gt monons dl |
| 1221 | k = killpid pid 9 |
| 1222 | r = waitpid pid JDWS 0 4 0 |
| 1223 | put JDC 18 jdwstat |
| 1224 | ret |
| 1225 | end |
| 1226 | s = sleepns 1000000 |
| 1227 | end |
| 1228 | end |
| 1229 | |
| 1230 | note kill the arm (protocol violation or a C11 kill); code 0 = deliberate kill |
| 1231 | fn jdpkill code ulong to void |
| 1232 | if eq get JDC 8 0 |
| 1233 | ret |
| 1234 | end |
| 1235 | jdpread |
| 1236 | pid = int get JDC 0 |
| 1237 | k = killpid pid 9 |
| 1238 | r = waitpid pid JDWS 0 4 0 |
| 1239 | if eq code 0 |
| 1240 | put JDC 18 jdwstat |
| 1241 | else |
| 1242 | put JDC 18 add 512 code |
| 1243 | end |
| 1244 | put JDC 8 0 |
| 1245 | jdclosefd |
| 1246 | end |
| 1247 | |
| 1248 | note send END, require status 0 and q 0, reap; K17: END round trip into JDC 28, and 1024 added to |
| 1249 | note the exit word when END itself failed (bad status or q, end of file, timeout, write failure; |
| 1250 | note the low bits then hold the exit status, or 512 + 4 + code when the judge had to kill the arm) |
| 1251 | fn jdpfin to void |
| 1252 | if eq get JDC 8 0 |
| 1253 | ret |
| 1254 | end |
| 1255 | if eq get JDC 19 1 |
| 1256 | jdpstats |
| 1257 | end |
| 1258 | jdpread |
| 1259 | put JDM JMEND 10 |
| 1260 | put JDM add JMEND 1 0 |
| 1261 | t1 = monons |
| 1262 | dl = add t1 10000000000 |
| 1263 | e = jdsend JMEND 2 dl |
| 1264 | if eq e 0 |
| 1265 | e = jdrecv dl |
| 1266 | end |
| 1267 | put JDC 28 ulong sub monons t1 |
| 1268 | if ne e 0 |
| 1269 | jdpkill add 4 ulong e |
| 1270 | put JDC 18 add get JDC 18 1024 |
| 1271 | ret |
| 1272 | end |
| 1273 | bad = or ne get JDRS 0 0 ne get JDRS 1 0 |
| 1274 | jdreap |
| 1275 | if bad |
| 1276 | put JDC 18 add get JDC 18 1024 |
| 1277 | end |
| 1278 | put JDC 8 0 |
| 1279 | jdclosefd |
| 1280 | end |
| 1281 | |
| 1282 | note K14: diagnostic STATS, excluded from every latency sum, padded to 32 counter words. |
| 1283 | fn jdpstats to void |
| 1284 | for i ulong 34 |
| 1285 | put JDM add 9437000 i 0 |
| 1286 | end |
| 1287 | put JDM JMEND 9 |
| 1288 | put JDM add JMEND 1 0 |
| 1289 | dl = add monons 10000000000 |
| 1290 | e = jdsend JMEND 2 dl |
| 1291 | if eq e 0 |
| 1292 | e = jdrecv dl |
| 1293 | end |
| 1294 | if eq e 0 |
| 1295 | put JDM 9437000 get JDRS 0 |
| 1296 | put JDM 9437001 get JDRS 1 |
| 1297 | for i ulong get JDRS 1 |
| 1298 | put JDM add 9437002 i get JDRS add i 2 |
| 1299 | end |
| 1300 | else |
| 1301 | put JDM 9437000 JDNONE |
| 1302 | end |
| 1303 | jdscp 0 4 |
| 1304 | jdsc 0 47 |
| 1305 | jdsc 0 115 |
| 1306 | jdsc 0 116 |
| 1307 | jdsc 0 97 |
| 1308 | jdsc 0 116 |
| 1309 | jdsc 0 115 |
| 1310 | jdsc 0 45 |
| 1311 | jdsnum 0 get JDC 10 1 |
| 1312 | jdsc 0 45 |
| 1313 | jdsnum 0 get JDC 12 1 |
| 1314 | jdsw 0 JWG 2 |
| 1315 | jdsnum 0 get JDC 11 2 |
| 1316 | jdsc 0 46 |
| 1317 | jdsc 0 99 |
| 1318 | jdsc 0 116 |
| 1319 | jdsc 0 114 |
| 1320 | x = jdstw 0 9437000 34 705 |
| 1321 | end |
| 1322 | |
| 1323 | note status, r0, r1, route of the response as logged, into JDQ 0..3 |
| 1324 | fn jdlogval op ulong code ulong to void |
| 1325 | put JDQ 0 get JDRS 0 |
| 1326 | put JDQ 1 0 |
| 1327 | put JDQ 2 0 |
| 1328 | put JDQ 3 0 |
| 1329 | if and eq op 2 ge get JDRS 1 3 |
| 1330 | put JDQ 1 get JDRS 2 |
| 1331 | put JDQ 2 get JDRS 3 |
| 1332 | put JDQ 3 get JDRS 4 |
| 1333 | end |
| 1334 | if ne code 0 |
| 1335 | put JDQ 1 0 |
| 1336 | put JDQ 2 0 |
| 1337 | put JDQ 3 0 |
| 1338 | end |
| 1339 | if eq code 1 |
| 1340 | put JDQ 0 JDNONE |
| 1341 | end |
| 1342 | if eq code 2 |
| 1343 | put JDQ 0 sub JDNONE 1 |
| 1344 | end |
| 1345 | end |
| 1346 | |
| 1347 | note one 16-word raw record for request j into JDLB, counters into JDA |
| 1348 | fn jdlogrec j ulong code ulong rt ulong to void |
| 1349 | off = get JDM add JMOF j |
| 1350 | op = get JDM add JMRQ off |
| 1351 | ex = add JMEX shl j 3 |
| 1352 | jdlogval op code |
| 1353 | co = jdcorr op code get JDQ 0 get JDQ 1 get JDQ 2 ex |
| 1354 | jdcount j op code co get JDQ 3 |
| 1355 | if eq get JDC 19 0 |
| 1356 | ret |
| 1357 | end |
| 1358 | jdlogw j op ex rt co |
| 1359 | end |
| 1360 | |
| 1361 | fn jdlogw j ulong op ulong ex ulong rt ulong co ulong to void |
| 1362 | b = get JDC 14 |
| 1363 | if gt add b 128 8388608 |
| 1364 | trap 3 |
| 1365 | end |
| 1366 | jdplw b get JDC 11 |
| 1367 | jdplw add b 8 get JDC 12 |
| 1368 | jdplw add b 16 get JDC 10 |
| 1369 | jdplw add b 24 j |
| 1370 | jdplw add b 32 op |
| 1371 | jdplw add b 40 get JDQ 0 |
| 1372 | jdplw add b 48 get JDQ 1 |
| 1373 | jdplw add b 56 get JDQ 2 |
| 1374 | jdplw add b 64 get JDQ 3 |
| 1375 | jdplw add b 72 get JDM ex |
| 1376 | jdplw add b 80 get JDM add ex 2 |
| 1377 | jdplw add b 88 get JDM add ex 3 |
| 1378 | jdplw add b 96 rt |
| 1379 | jdplw add b 104 get JDM add ex 6 |
| 1380 | jdplw add b 112 get JDM add ex 5 |
| 1381 | jdplw add b 120 co |
| 1382 | put JDC 14 add b 128 |
| 1383 | end |
| 1384 | |
| 1385 | note correctness word: code 0 answered, 1 violation, 2 not sent |
| 1386 | fn jdcorr op ulong code ulong st ulong r0 ulong r1 ulong ex ulong to ulong |
| 1387 | if ne code 0 |
| 1388 | ret 0 |
| 1389 | end |
| 1390 | if eq get JDC 10 0 |
| 1391 | ret 2 |
| 1392 | end |
| 1393 | if ne st get JDM ex |
| 1394 | ret 0 |
| 1395 | end |
| 1396 | if ne op 2 |
| 1397 | ret 2 |
| 1398 | end |
| 1399 | if ne st 0 |
| 1400 | ret 1 |
| 1401 | end |
| 1402 | e0 = get JDM add ex 2 |
| 1403 | if ne r0 e0 |
| 1404 | ret 0 |
| 1405 | end |
| 1406 | e1 = get JDM add ex 3 |
| 1407 | if ne r1 e1 |
| 1408 | ret 0 |
| 1409 | end |
| 1410 | ret 1 |
| 1411 | end |
| 1412 | |
| 1413 | fn jdcount j ulong op ulong code ulong co ulong ro ulong to void |
| 1414 | rt = add JMRT shl j 2 |
| 1415 | put JDM rt ro |
| 1416 | put JDM add rt 1 code |
| 1417 | put JDM add rt 2 co |
| 1418 | if eq co 0 |
| 1419 | put JDA 1 add get JDA 1 1 |
| 1420 | end |
| 1421 | if eq code 1 |
| 1422 | put JDA 15 add get JDA 15 1 |
| 1423 | end |
| 1424 | if ne op 2 |
| 1425 | ret |
| 1426 | end |
| 1427 | put JDM add rt 3 1 |
| 1428 | put JDA 0 add get JDA 0 1 |
| 1429 | if eq co 0 |
| 1430 | put JDA 14 add get JDA 14 1 |
| 1431 | end |
| 1432 | if ne code 0 |
| 1433 | ret |
| 1434 | end |
| 1435 | if le ro 5 |
| 1436 | put JDA add 2 ro add get JDA add 2 ro 1 |
| 1437 | else |
| 1438 | put JDA 8 add get JDA 8 1 |
| 1439 | end |
| 1440 | m = or eq ro 3 eq ro 4 |
| 1441 | rv = get JDC 16 |
| 1442 | if and ne rv JDNONE ge j rv |
| 1443 | put JDA 10 add get JDA 10 1 |
| 1444 | if m |
| 1445 | put JDA 11 add get JDA 11 1 |
| 1446 | end |
| 1447 | if eq ro 5 |
| 1448 | put JDA 12 add get JDA 12 1 |
| 1449 | end |
| 1450 | else |
| 1451 | if m |
| 1452 | put JDA 13 add get JDA 13 1 |
| 1453 | end |
| 1454 | end |
| 1455 | end |
| 1456 | |
| 1457 | fn jdcnt0 to void |
| 1458 | for i ulong 64 |
| 1459 | put JDA i 0 |
| 1460 | end |
| 1461 | end |
| 1462 | |
| 1463 | note send request j and read its response; logs it |
| 1464 | fn jdpreq j ulong to void |
| 1465 | if eq get JDC 8 0 |
| 1466 | jdlogrec j 2 0 |
| 1467 | ret |
| 1468 | end |
| 1469 | if eq j get JDC 16 |
| 1470 | jdrevoke |
| 1471 | end |
| 1472 | off = get JDM add JMOF j |
| 1473 | nw = add get JDM add add JMRQ off 1 2 |
| 1474 | t1 = monons |
| 1475 | dl = add t1 10000000000 |
| 1476 | e = jdsend add JMRQ off nw dl |
| 1477 | if eq e 0 |
| 1478 | e = jdrecv dl |
| 1479 | end |
| 1480 | t2 = monons |
| 1481 | if eq e 0 |
| 1482 | eq1 = get JDM add add JMEX shl j 3 1 |
| 1483 | if ne get JDRS 1 eq1 |
| 1484 | e = 2 |
| 1485 | end |
| 1486 | end |
| 1487 | rt = ulong sub t2 t1 |
| 1488 | if eq get JDC 15 0 |
| 1489 | put JDC 5 ulong sub t2 long get JDC 4 |
| 1490 | end |
| 1491 | put JDC 15 add get JDC 15 1 |
| 1492 | put JDC 6 add get JDC 6 rt |
| 1493 | put JDC 7 add get JDC 7 1 |
| 1494 | if ne e 0 |
| 1495 | put JDC 9 ulong e |
| 1496 | jdlogrec j 1 rt |
| 1497 | jdpkill ulong e |
| 1498 | ret |
| 1499 | end |
| 1500 | jdlogrec j 0 rt |
| 1501 | end |
| 1502 | |
| 1503 | note C7 mid-session revocation: append the line of register 29 to the ALLOW copy of register 28 |
| 1504 | fn jdrevoke to void |
| 1505 | if eq get JDSL 28 0 |
| 1506 | ret |
| 1507 | end |
| 1508 | x = jdopen 28 1089 |
| 1509 | if lt x 0 |
| 1510 | ret |
| 1511 | end |
| 1512 | fd = int x |
| 1513 | w = write fd JDS 118784 get JDSL 29 |
| 1514 | c = fsync fd |
| 1515 | c = fclose fd |
| 1516 | end |
| 1517 | |
| 1518 | note the proc.log record (16 words at JMPRC) appended to <dir 4>/proc.log |
| 1519 | fn jdproclog to int |
| 1520 | p = JMPRC |
| 1521 | put JDM p get JDC 10 |
| 1522 | put JDM add p 1 get JDC 11 |
| 1523 | put JDM add p 2 get JDC 12 |
| 1524 | put JDM add p 3 get JDC 5 |
| 1525 | put JDM add p 4 get JDC 20 |
| 1526 | put JDM add p 5 get JDC 21 |
| 1527 | put JDM add p 6 get JDC 22 |
| 1528 | put JDM add p 7 get JDC 23 |
| 1529 | put JDM add p 8 get JDC 25 |
| 1530 | put JDM add p 9 get JDC 26 |
| 1531 | put JDM add p 10 get JDC 18 |
| 1532 | put JDM add p 11 get JDC 7 |
| 1533 | put JDM add p 12 get JDC 6 |
| 1534 | put JDM add p 13 get JDC 24 |
| 1535 | put JDM add p 14 get JDC 13 |
| 1536 | put JDM add p 15 get JDC 28 |
| 1537 | jdspath 0 4 JWPLOG 8 |
| 1538 | x = jdstw 0 p 16 1089 |
| 1539 | if lt x 0 |
| 1540 | ret 1 |
| 1541 | end |
| 1542 | ret 0 |
| 1543 | end |
| 1544 | |
| 1545 | note <dir 4>/arm-A-rep-R-gNN.log from JDLB (a new file; never overwritten) |
| 1546 | fn jdrawlog to int |
| 1547 | jdscp 0 4 |
| 1548 | jdsc 0 47 |
| 1549 | jdsw 0 JWARM 4 |
| 1550 | jdsnum 0 get JDC 10 1 |
| 1551 | jdsw 0 JWREP 5 |
| 1552 | jdsnum 0 get JDC 12 1 |
| 1553 | jdsw 0 JWG 2 |
| 1554 | jdsnum 0 get JDC 11 2 |
| 1555 | jdsw 0 JWLOG 4 |
| 1556 | x = jdopen 0 705 |
| 1557 | if lt x 0 |
| 1558 | ret 1 |
| 1559 | end |
| 1560 | fd = int x |
| 1561 | n = get JDC 14 |
| 1562 | off = ulong 0 |
| 1563 | while lt off n bound 999999 |
| 1564 | k = write fd JDLB off sub n off |
| 1565 | if le k 0 |
| 1566 | c = fclose fd |
| 1567 | ret 2 |
| 1568 | end |
| 1569 | off = add off ulong k |
| 1570 | end |
| 1571 | c = fsync fd |
| 1572 | c = fclose fd |
| 1573 | ret 0 |
| 1574 | end |
| 1575 | |
| 1576 | note one arm process over requests j0..j1 of the loaded group; arm config in registers 5, 7..13, |
| 1577 | note JDC 10..12; writes the raw log and proc.log when JDC 19 = 1. 0 ok, nonzero judge failure. |
| 1578 | fn jdpgroup j0 ulong j1 ulong to int |
| 1579 | put JDC 14 0 |
| 1580 | r = jdpstart |
| 1581 | if ne r 0 |
| 1582 | ret 1 |
| 1583 | end |
| 1584 | j = j0 |
| 1585 | while lt j j1 bound 999999 |
| 1586 | if eq j get JDC 17 |
| 1587 | jdpkill 0 |
| 1588 | end |
| 1589 | jdpreq j |
| 1590 | j = add j 1 |
| 1591 | end |
| 1592 | jdpfin |
| 1593 | if eq get JDC 19 0 |
| 1594 | ret 0 |
| 1595 | end |
| 1596 | r = jdrawlog |
| 1597 | if ne r 0 |
| 1598 | ret 2 |
| 1599 | end |
| 1600 | r = jdproclog |
| 1601 | if ne r 0 |
| 1602 | ret 3 |
| 1603 | end |
| 1604 | ret 0 |
| 1605 | end |
| 1606 | |
| 1607 | note ---- split directories ---- |
| 1608 | |
| 1609 | note index and sessions of the split in register 3; group count or negative |
| 1610 | fn jdsload to long |
| 1611 | jdspath 0 3 JWINDEX 5 |
| 1612 | n = jdldw 0 JMIX 4096 |
| 1613 | if lt n 16 |
| 1614 | ret -1 |
| 1615 | end |
| 1616 | if ne get JDM JMIX 3544386032354079058 |
| 1617 | ret -2 |
| 1618 | end |
| 1619 | if ne get JDM add JMIX 1 1 |
| 1620 | ret -2 |
| 1621 | end |
| 1622 | g = get JDM add JMIX 3 |
| 1623 | if or gt g 100 ne ulong n add 16 g |
| 1624 | ret -3 |
| 1625 | end |
| 1626 | jdspath 0 3 JWSESS 8 |
| 1627 | s = jdldw 0 JMSE 1044480 |
| 1628 | if lt s 0 |
| 1629 | ret -4 |
| 1630 | end |
| 1631 | if ne ulong s mul 16 get JDM add JMIX 4 |
| 1632 | ret -5 |
| 1633 | end |
| 1634 | ret long g |
| 1635 | end |
| 1636 | |
| 1637 | fn jdgpath r ulong d ulong g ulong ext ulong to void |
| 1638 | jdscp r d |
| 1639 | jdsc r 47 |
| 1640 | jdsc r 103 |
| 1641 | jdsnum r g 2 |
| 1642 | jdsw r ext 4 |
| 1643 | end |
| 1644 | |
| 1645 | note group g of the split in register 3 into JMRQ / JMOF / JMEX; request count or negative |
| 1646 | fn jdgload g ulong to long |
| 1647 | jdgpath 0 3 g JWREQ |
| 1648 | nw = jdldw 0 JMRQ 6291456 |
| 1649 | if lt nw 0 |
| 1650 | ret -1 |
| 1651 | end |
| 1652 | off = ulong 0 |
| 1653 | j = ulong 0 |
| 1654 | while lt off ulong nw bound 999999 |
| 1655 | if ge j 1048576 |
| 1656 | ret -2 |
| 1657 | end |
| 1658 | put JDM add JMOF j off |
| 1659 | off = add off add get JDM add add JMRQ off 1 2 |
| 1660 | j = add j 1 |
| 1661 | end |
| 1662 | if ne off ulong nw |
| 1663 | ret -3 |
| 1664 | end |
| 1665 | if ne j get JDM add add JMIX 16 g |
| 1666 | ret -4 |
| 1667 | end |
| 1668 | jdgpath 0 3 g JWEXP |
| 1669 | ne8 = jdldw 0 JMEX 1048576 |
| 1670 | if ne ulong ne8 shl j 3 |
| 1671 | ret -5 |
| 1672 | end |
| 1673 | for i ulong j |
| 1674 | if not jdopok i |
| 1675 | ret -6 |
| 1676 | end |
| 1677 | end |
| 1678 | ret long j |
| 1679 | end |
| 1680 | |
| 1681 | fn jdopok i ulong to bool |
| 1682 | o = get JDM add JMOF i |
| 1683 | op = get JDM add JMRQ o |
| 1684 | eo = get JDM add add JMEX shl i 3 4 |
| 1685 | ret eq op eo |
| 1686 | end |
| 1687 | |
| 1688 | fn jdusage to int |
| 1689 | jdsclr 0 |
| 1690 | jdsw 0 JWUSAGE 77 |
| 1691 | jdsc 0 10 |
| 1692 | n = write 2 JDS 0 get JDSL 0 |
| 1693 | ret 2 |
| 1694 | end |
| 1695 | |
| 1696 | fn jderr code ulong to int |
| 1697 | jdsclr 0 |
| 1698 | jdsw 0 JWERR 12 |
| 1699 | jdsnum 0 code 1 |
| 1700 | jdsc 0 10 |
| 1701 | n = write 2 JDS 0 get JDSL 0 |
| 1702 | ret 3 |
| 1703 | end |
| 1704 | |
| 1705 | note ---- run ---- |
| 1706 | |
| 1707 | note arm-order seed: a 64-hex FINAL seed gives bytes 16..23 little endian; else a decimal value |
| 1708 | fn jdseed r ulong to ulong |
| 1709 | if eq get JDSL r 64 |
| 1710 | v = ulong 0 |
| 1711 | for k ulong 8 |
| 1712 | b = jdshexb r add 16 k |
| 1713 | if gt b 255 |
| 1714 | ret JDNONE |
| 1715 | end |
| 1716 | v = or v shl b mul k 8 |
| 1717 | end |
| 1718 | ret v |
| 1719 | end |
| 1720 | ret jdsval r |
| 1721 | end |
| 1722 | |
| 1723 | note arm digits of register r into JDM JMSC..; count, 0 when invalid |
| 1724 | fn jdarms r ulong to ulong |
| 1725 | n = get JDSL r |
| 1726 | if or eq n 0 gt n 8 |
| 1727 | ret 0 |
| 1728 | end |
| 1729 | for i ulong n |
| 1730 | c = jdsb r i |
| 1731 | if or lt c 48 gt c 55 |
| 1732 | ret 0 |
| 1733 | end |
| 1734 | a = sub c 48 |
| 1735 | for k ulong i |
| 1736 | if eq get JDM add JMSC k a |
| 1737 | ret 0 |
| 1738 | end |
| 1739 | end |
| 1740 | put JDM add JMSC i a |
| 1741 | end |
| 1742 | ret n |
| 1743 | end |
| 1744 | |
| 1745 | note fresh copy of the base arm list at JMSC + 16, Fisher-Yates with splitmix64 (i = n-1 .. 1) |
| 1746 | fn jdperm n ulong to void |
| 1747 | b = add JMSC 16 |
| 1748 | for i ulong n |
| 1749 | put JDM add b i get JDM add JMSC i |
| 1750 | end |
| 1751 | i = sub n 1 |
| 1752 | while gt i 0 bound 8 |
| 1753 | j = rem jdsmix add i 1 |
| 1754 | t = get JDM add b i |
| 1755 | put JDM add b i get JDM add b j |
| 1756 | put JDM add b j t |
| 1757 | i = sub i 1 |
| 1758 | end |
| 1759 | end |
| 1760 | |
| 1761 | fn jdlibdir r ulong rep ulong lib ulong to void |
| 1762 | jdscp r 4 |
| 1763 | jdsc r 47 |
| 1764 | jdsw r JWLIB 4 |
| 1765 | jdsnum r rep 1 |
| 1766 | jdsc r 45 |
| 1767 | jdsnum r lib 1 |
| 1768 | end |
| 1769 | |
| 1770 | note process registers 8..13 and JDC 10, 12 for arm a in repetition rep of a run |
| 1771 | fn jdarmcfg a ulong rep ulong to void |
| 1772 | jdarmname 8 a |
| 1773 | jdsdsh 9 |
| 1774 | jdsdsh 10 |
| 1775 | jdsdsh 11 |
| 1776 | jdsdsh 12 |
| 1777 | jdsdsh 13 |
| 1778 | if or eq a 3 or eq a 4 eq a 7 |
| 1779 | jdlibdir 9 rep 1 |
| 1780 | jdscp 10 15 |
| 1781 | jdscp 11 6 |
| 1782 | end |
| 1783 | if eq a 5 |
| 1784 | jdscp 11 6 |
| 1785 | end |
| 1786 | if eq a 6 |
| 1787 | jdlibdir 9 rep 2 |
| 1788 | jdscp 10 17 |
| 1789 | jdscp 11 6 |
| 1790 | end |
| 1791 | put JDC 10 a |
| 1792 | put JDC 12 rep |
| 1793 | end |
| 1794 | |
| 1795 | fn jdaddm i ulong d ulong to void |
| 1796 | put JDM i add get JDM i d |
| 1797 | end |
| 1798 | |
| 1799 | fn jdneed n ulong lib ulong to bool |
| 1800 | for i ulong n |
| 1801 | a = get JDM add JMSC i |
| 1802 | if and eq lib 1 or eq a 3 or eq a 4 eq a 7 |
| 1803 | ret true |
| 1804 | end |
| 1805 | if and eq lib 2 eq a 6 |
| 1806 | ret true |
| 1807 | end |
| 1808 | end |
| 1809 | ret false |
| 1810 | end |
| 1811 | |
| 1812 | fn jdsummary n ulong to void |
| 1813 | for i ulong n |
| 1814 | a = get JDM add JMSC i |
| 1815 | jdsclr 0 |
| 1816 | jdsw 0 JWAEQ 4 |
| 1817 | jdsnum 0 a 1 |
| 1818 | jdsw 0 JWWRONG 7 |
| 1819 | jdsnum 0 get JDM add add JMSC 32 a 1 |
| 1820 | jdsw 0 JWVIOL 12 |
| 1821 | jdsnum 0 get JDM add add JMSC 48 a 1 |
| 1822 | jdsout 0 |
| 1823 | end |
| 1824 | end |
| 1825 | |
| 1826 | note all arms of the base list over one loaded group g, repetition rep |
| 1827 | fn jdrungrp na ulong g ulong rep ulong nreq ulong to int |
| 1828 | jdperm na |
| 1829 | for k ulong na |
| 1830 | a = get JDM add add JMSC 16 k |
| 1831 | jdarmcfg a rep |
| 1832 | put JDC 11 g |
| 1833 | w0 = get JDA 1 |
| 1834 | v0 = get JDA 15 |
| 1835 | e = jdpgroup 0 nreq |
| 1836 | if ne e 0 |
| 1837 | ret add 40 e |
| 1838 | end |
| 1839 | dw = sub get JDA 1 w0 |
| 1840 | jdaddm add add JMSC 32 a dw |
| 1841 | dv = sub get JDA 15 v0 |
| 1842 | jdaddm add add JMSC 48 a dv |
| 1843 | end |
| 1844 | ret 0 |
| 1845 | end |
| 1846 | |
| 1847 | note judge run SPLIT OUT REPS SEED ARMS BASE ALLOW LIB MAN LIBP MANP CPU |
| 1848 | fn jdrun to int |
| 1849 | if ne argcnt 14 |
| 1850 | ret jdusage |
| 1851 | end |
| 1852 | b = jdsarg 3 2 |
| 1853 | b = jdsarg 4 3 |
| 1854 | b = jdsarg 0 4 |
| 1855 | b = jdsarg 1 5 |
| 1856 | b = jdsarg 2 6 |
| 1857 | b = jdsarg 5 7 |
| 1858 | b = jdsarg 6 8 |
| 1859 | b = jdsarg 14 9 |
| 1860 | b = jdsarg 15 10 |
| 1861 | b = jdsarg 16 11 |
| 1862 | b = jdsarg 17 12 |
| 1863 | b = jdsarg 7 13 |
| 1864 | reps = jdsval 0 |
| 1865 | seed = jdseed 1 |
| 1866 | na = jdarms 2 |
| 1867 | if or or eq reps JDNONE or eq reps 0 gt reps 99 or eq seed JDNONE eq na 0 |
| 1868 | ret jdusage |
| 1869 | end |
| 1870 | n1 = jdneed na 1 |
| 1871 | n2 = jdneed na 2 |
| 1872 | if and n1 or jdsdash 14 jdsdash 15 |
| 1873 | ret jdusage |
| 1874 | end |
| 1875 | if and n2 or jdsdash 16 jdsdash 17 |
| 1876 | ret jdusage |
| 1877 | end |
| 1878 | g = jdsload |
| 1879 | if lt g 0 |
| 1880 | ret jderr 10 |
| 1881 | end |
| 1882 | r = jdmkdir 4 493 |
| 1883 | jdspath 0 4 JWPLOG 8 |
| 1884 | if jdexists 0 |
| 1885 | ret jderr 11 |
| 1886 | end |
| 1887 | for i ulong 32 |
| 1888 | put JDM add add JMSC 32 i 0 |
| 1889 | end |
| 1890 | put JDSM 0 seed |
| 1891 | e = jdrunloop reps na n1 n2 ulong g |
| 1892 | if ne e 0 |
| 1893 | ret jderr e |
| 1894 | end |
| 1895 | jdsummary na |
| 1896 | ret 0 |
| 1897 | end |
| 1898 | |
| 1899 | |
| 1900 | fn jdrunloop reps ulong na ulong n1 bool n2 bool g ulong to ulong |
| 1901 | put JDC 16 JDNONE |
| 1902 | put JDC 17 JDNONE |
| 1903 | put JDC 19 1 |
| 1904 | jdcnt0 |
| 1905 | for rep ulong reps |
| 1906 | if n1 |
| 1907 | jdlibdir 26 rep 1 |
| 1908 | c = jdcpdir 14 26 |
| 1909 | if ne c 0 |
| 1910 | ret 12 |
| 1911 | end |
| 1912 | end |
| 1913 | if n2 |
| 1914 | jdlibdir 26 rep 2 |
| 1915 | c = jdcpdir 16 26 |
| 1916 | if ne c 0 |
| 1917 | ret 13 |
| 1918 | end |
| 1919 | end |
| 1920 | for gi ulong g |
| 1921 | nreq = jdgload gi |
| 1922 | if lt nreq 0 |
| 1923 | ret 20 |
| 1924 | end |
| 1925 | e = jdrungrp na gi rep ulong nreq |
| 1926 | if ne e 0 |
| 1927 | ret ulong e |
| 1928 | end |
| 1929 | end |
| 1930 | end |
| 1931 | ret 0 |
| 1932 | end |
| 1933 | |
| 1934 | note ---- tap ---- |
| 1935 | |
| 1936 | note judge tap SPLIT BASE TAPFILE SPLITARG CPU: one B process over every group in order |
| 1937 | fn jdtap to int |
| 1938 | if ne argcnt 7 |
| 1939 | ret jdusage |
| 1940 | end |
| 1941 | b = jdsarg 3 2 |
| 1942 | b = jdsarg 5 3 |
| 1943 | b = jdsarg 12 4 |
| 1944 | b = jdsarg 13 5 |
| 1945 | b = jdsarg 7 6 |
| 1946 | g = jdsload |
| 1947 | if lt g 0 |
| 1948 | ret jderr 10 |
| 1949 | end |
| 1950 | if jdexists 12 |
| 1951 | ret jderr 14 |
| 1952 | end |
| 1953 | jdarmname 8 8 |
| 1954 | jdsdsh 9 |
| 1955 | jdsdsh 10 |
| 1956 | jdsdsh 11 |
| 1957 | put JDC 10 1 |
| 1958 | put JDC 11 0 |
| 1959 | put JDC 12 0 |
| 1960 | put JDC 16 JDNONE |
| 1961 | put JDC 17 JDNONE |
| 1962 | put JDC 19 0 |
| 1963 | jdcnt0 |
| 1964 | r = jdpstart |
| 1965 | if ne r 0 |
| 1966 | ret jderr 15 |
| 1967 | end |
| 1968 | for gi ulong ulong g |
| 1969 | nreq = jdgload gi |
| 1970 | if lt nreq 0 |
| 1971 | jdpkill 0 |
| 1972 | ret jderr 16 |
| 1973 | end |
| 1974 | for j ulong ulong nreq |
| 1975 | jdpreq j |
| 1976 | end |
| 1977 | end |
| 1978 | jdpfin |
| 1979 | z = jdhfile 12 |
| 1980 | jdsclr 0 |
| 1981 | jdsw 0 JWTSHA 11 |
| 1982 | jdshash 0 |
| 1983 | jdsw 0 JWTBYT 11 |
| 1984 | if gt z 0 |
| 1985 | jdsnum 0 ulong z 1 |
| 1986 | else |
| 1987 | jdsc 0 48 |
| 1988 | end |
| 1989 | jdsw 0 JWQRY 9 |
| 1990 | jdsnum 0 get JDA 0 1 |
| 1991 | jdsw 0 JWWRONG 7 |
| 1992 | jdsnum 0 get JDA 1 1 |
| 1993 | jdsw 0 JWVIOL 12 |
| 1994 | jdsnum 0 get JDA 15 1 |
| 1995 | jdsout 0 |
| 1996 | if or ne get JDA 1 0 ne get JDC 18 0 |
| 1997 | ret 4 |
| 1998 | end |
| 1999 | if le z 0 |
| 2000 | ret 4 |
| 2001 | end |
| 2002 | ret 0 |
| 2003 | end |
| 2004 | |
| 2005 | note ---- calib ---- |
| 2006 | note pairs (key, ns) at JMSC, sort area at JMSC + 2097152, logs at JMSC + 3145728; change class |
| 2007 | note of QUERY j at JMRT + j, per-session change counts at JMRT + 524288 + ordinal. |
| 2008 | |
| 2009 | const JDPAIR ulong 10485760 |
| 2010 | const JDSORT ulong 12582912 |
| 2011 | const JDLOGW ulong 13631488 |
| 2012 | |
| 2013 | fn jdccls c ulong to ulong |
| 2014 | if eq c 0 |
| 2015 | ret 0 |
| 2016 | end |
| 2017 | if eq c 1 |
| 2018 | ret 1 |
| 2019 | end |
| 2020 | if le c 64 |
| 2021 | ret 2 |
| 2022 | end |
| 2023 | ret 3 |
| 2024 | end |
| 2025 | |
| 2026 | fn jdcchg nreq ulong to void |
| 2027 | cb = add JMRT 524288 |
| 2028 | for j ulong nreq |
| 2029 | o = get JDM add JMOF j |
| 2030 | op = get JDM add JMRQ o |
| 2031 | ex = add JMEX shl j 3 |
| 2032 | s = get JDM add ex 5 |
| 2033 | ok = eq get JDM ex 0 |
| 2034 | si = add cb s |
| 2035 | put JDM add JMRT j 9 |
| 2036 | if and eq op 1 ok |
| 2037 | put JDM si 0 |
| 2038 | end |
| 2039 | if and ok and ge op 3 le op 6 |
| 2040 | jdaddm si 1 |
| 2041 | end |
| 2042 | if and ok eq op 8 |
| 2043 | jdaddm si 1 |
| 2044 | end |
| 2045 | if and ok eq op 7 |
| 2046 | m = get JDM add add JMRQ o 2 |
| 2047 | jdaddm si m |
| 2048 | end |
| 2049 | if eq op 2 |
| 2050 | put JDM add JMRT j jdccls get JDM si |
| 2051 | put JDM si 0 |
| 2052 | end |
| 2053 | end |
| 2054 | end |
| 2055 | |
| 2056 | fn jdpair k ulong v ulong np ulong to ulong |
| 2057 | if ge np 1048576 |
| 2058 | ret np |
| 2059 | end |
| 2060 | put JDM add JDPAIR shl np 1 k |
| 2061 | put JDM add add JDPAIR shl np 1 1 v |
| 2062 | ret add np 1 |
| 2063 | end |
| 2064 | |
| 2065 | note pairs of one arm log (already at JDLOGW) for a loaded group of nreq requests |
| 2066 | fn jdcpairs a ulong nreq ulong np ulong to ulong |
| 2067 | n = np |
| 2068 | path = ulong 2 |
| 2069 | if eq a 1 |
| 2070 | path = 0 |
| 2071 | end |
| 2072 | if eq a 3 |
| 2073 | path = 1 |
| 2074 | end |
| 2075 | for j ulong nreq |
| 2076 | n = jdcpone a path j n |
| 2077 | end |
| 2078 | ret n |
| 2079 | end |
| 2080 | |
| 2081 | fn jdsfld s ulong w ulong to ulong |
| 2082 | ret get JDM add add JMSE shl s 4 w |
| 2083 | end |
| 2084 | |
| 2085 | fn jdcpone a ulong path ulong j ulong np ulong to ulong |
| 2086 | rec = add JDLOGW shl j 4 |
| 2087 | fam = jdsfld get JDM add rec 14 2 |
| 2088 | ncl = jdsfld get JDM add rec 14 5 |
| 2089 | if or or lt fam 1 gt fam 2 gt ncl 2 |
| 2090 | ret np |
| 2091 | end |
| 2092 | k = add mul sub fam 1 3 ncl |
| 2093 | n = jdcpq path j k np |
| 2094 | if jdcbind get JDM add rec 4 rec j a |
| 2095 | kb = add k 100 |
| 2096 | if eq a 1 |
| 2097 | kb = add k 200 |
| 2098 | end |
| 2099 | n = jdpair kb get JDM add rec 12 n |
| 2100 | end |
| 2101 | ret n |
| 2102 | end |
| 2103 | |
| 2104 | note QUERY pair of record j; k = (family - 1) * 3 + nclass |
| 2105 | fn jdcpq path ulong j ulong k ulong np ulong to ulong |
| 2106 | rec = add JDLOGW shl j 4 |
| 2107 | if or ne get JDM add rec 4 2 ne get JDM add rec 15 1 |
| 2108 | ret np |
| 2109 | end |
| 2110 | f0 = div k 3 |
| 2111 | ncl = rem k 3 |
| 2112 | c = jdcell f0 path ncl get JDM add JMRT j |
| 2113 | ret jdpair c get JDM add rec 12 np |
| 2114 | end |
| 2115 | |
| 2116 | fn jdcell f0 ulong path ulong ncl ulong cc ulong to ulong |
| 2117 | x = mul add mul f0 4 path 12 |
| 2118 | ret add add x mul ncl 4 cc |
| 2119 | end |
| 2120 | |
| 2121 | fn jdcbind op ulong rec ulong j ulong a ulong to bool |
| 2122 | if or ne op 1 eq j 0 |
| 2123 | ret false |
| 2124 | end |
| 2125 | if eq a 4 |
| 2126 | ret false |
| 2127 | end |
| 2128 | ret and eq get JDM add rec 5 0 eq get JDM add rec 9 0 |
| 2129 | end |
| 2130 | |
| 2131 | note values of key k gathered into JDSORT and sorted; count |
| 2132 | fn jdgather k ulong np ulong to ulong |
| 2133 | n = ulong 0 |
| 2134 | for i ulong np |
| 2135 | if eq get JDM add JDPAIR shl i 1 k |
| 2136 | put JDM add JDSORT n get JDM add add JDPAIR shl i 1 1 |
| 2137 | n = add n 1 |
| 2138 | end |
| 2139 | end |
| 2140 | jdhsort JDSORT n |
| 2141 | ret n |
| 2142 | end |
| 2143 | |
| 2144 | fn jdsift b ulong st ulong n ulong to void |
| 2145 | root = st |
| 2146 | while true bound 64 |
| 2147 | ch = add mul root 2 1 |
| 2148 | if ge ch n |
| 2149 | break |
| 2150 | end |
| 2151 | sw = root |
| 2152 | if gt get JDM add b ch get JDM add b sw |
| 2153 | sw = ch |
| 2154 | end |
| 2155 | c2 = add ch 1 |
| 2156 | if lt c2 n |
| 2157 | if gt get JDM add b c2 get JDM add b sw |
| 2158 | sw = c2 |
| 2159 | end |
| 2160 | end |
| 2161 | if eq sw root |
| 2162 | break |
| 2163 | end |
| 2164 | t = get JDM add b root |
| 2165 | put JDM add b root get JDM add b sw |
| 2166 | put JDM add b sw t |
| 2167 | root = sw |
| 2168 | end |
| 2169 | end |
| 2170 | |
| 2171 | fn jdhsort b ulong n ulong to void |
| 2172 | if lt n 2 |
| 2173 | ret |
| 2174 | end |
| 2175 | st = add div sub n 2 2 1 |
| 2176 | while gt st 0 bound 999999 |
| 2177 | st = sub st 1 |
| 2178 | jdsift b st n |
| 2179 | end |
| 2180 | e = sub n 1 |
| 2181 | while gt e 0 bound 999999 |
| 2182 | t = get JDM b |
| 2183 | put JDM b get JDM add b e |
| 2184 | put JDM add b e t |
| 2185 | jdsift b 0 e |
| 2186 | e = sub e 1 |
| 2187 | end |
| 2188 | end |
| 2189 | |
| 2190 | note nearest-rank percentile p of the n sorted values at JDSORT: index ceil(p n / 100) - 1 |
| 2191 | fn jdpct n ulong p ulong to ulong |
| 2192 | i = div add mul p n 99 100 |
| 2193 | if eq i 0 |
| 2194 | i = 1 |
| 2195 | end |
| 2196 | ret get JDM add JDSORT sub i 1 |
| 2197 | end |
| 2198 | |
| 2199 | fn jdfloor1 a ulong b ulong to ulong |
| 2200 | if le a b |
| 2201 | ret 1 |
| 2202 | end |
| 2203 | d = sub a b |
| 2204 | if lt d 1 |
| 2205 | ret 1 |
| 2206 | end |
| 2207 | ret d |
| 2208 | end |
| 2209 | |
| 2210 | note the calibration words into JMEX[0..200) |
| 2211 | fn jdcalout np ulong eqv ulong to void |
| 2212 | for i ulong 200 |
| 2213 | put JDM add JMEX i 0 |
| 2214 | end |
| 2215 | put JDM JMEX 3544386010811150674 |
| 2216 | put JDM add JMEX 1 1 |
| 2217 | put JDM add JMEX 2 eqv |
| 2218 | for c ulong 96 |
| 2219 | if eq rem div c 12 4 3 |
| 2220 | continue |
| 2221 | end |
| 2222 | n = jdgather c np |
| 2223 | if gt n 0 |
| 2224 | put JDM add add JMEX 8 shl c 1 jdpct n 50 |
| 2225 | put JDM add add JMEX 9 shl c 1 jdpct n 90 |
| 2226 | end |
| 2227 | end |
| 2228 | for f0 ulong 2 |
| 2229 | for ncl ulong 3 |
| 2230 | jdcalbind f0 ncl np |
| 2231 | end |
| 2232 | end |
| 2233 | end |
| 2234 | |
| 2235 | fn jdcalbind f0 ulong ncl ulong np ulong to void |
| 2236 | k = add mul f0 3 ncl |
| 2237 | nf = jdgather add k 200 np |
| 2238 | if eq nf 0 |
| 2239 | ret |
| 2240 | end |
| 2241 | fp = jdpct nf 50 |
| 2242 | nm = jdgather add k 100 np |
| 2243 | if eq nm 0 |
| 2244 | ret |
| 2245 | end |
| 2246 | c = add mul add mul f0 4 3 12 mul ncl 4 |
| 2247 | put JDM add add JMEX 8 shl c 1 jdfloor1 jdpct nm 50 fp |
| 2248 | put JDM add add JMEX 9 shl c 1 jdfloor1 jdpct nm 90 fp |
| 2249 | end |
| 2250 | |
| 2251 | note judge calib CALIBDIR RUNDIR REPS OUTFILE |
| 2252 | fn jdcalib to int |
| 2253 | if ne argcnt 6 |
| 2254 | ret jdusage |
| 2255 | end |
| 2256 | b = jdsarg 3 2 |
| 2257 | b = jdsarg 4 3 |
| 2258 | b = jdsarg 0 4 |
| 2259 | b = jdsarg 21 5 |
| 2260 | reps = jdsval 0 |
| 2261 | if or eq reps JDNONE eq reps 0 |
| 2262 | ret jdusage |
| 2263 | end |
| 2264 | g = jdsload |
| 2265 | if lt g 0 |
| 2266 | ret jderr 10 |
| 2267 | end |
| 2268 | ns = get JDM add JMIX 4 |
| 2269 | if eq ns 0 |
| 2270 | ret jderr 17 |
| 2271 | end |
| 2272 | eqv = div mul get JDM add JMIX 6 1000 ns |
| 2273 | np = jdcalloop reps ulong g |
| 2274 | if eq np JDNONE |
| 2275 | ret jderr 18 |
| 2276 | end |
| 2277 | jdcalout np eqv |
| 2278 | x = jdstw 21 JMEX 200 705 |
| 2279 | if lt x 0 |
| 2280 | ret jderr 19 |
| 2281 | end |
| 2282 | z = jdhfile 21 |
| 2283 | jdsclr 0 |
| 2284 | jdsw 0 JWCSHA 11 |
| 2285 | jdshash 0 |
| 2286 | jdsout 0 |
| 2287 | ret 0 |
| 2288 | end |
| 2289 | |
| 2290 | fn jdcalloop reps ulong g ulong to ulong |
| 2291 | np = ulong 0 |
| 2292 | for rep ulong reps |
| 2293 | for gi ulong g |
| 2294 | x = jdgload gi |
| 2295 | if lt x 0 |
| 2296 | ret JDNONE |
| 2297 | end |
| 2298 | nreq = ulong x |
| 2299 | jdcchg nreq |
| 2300 | np = jdcal3 rep gi nreq np |
| 2301 | if eq np JDNONE |
| 2302 | ret JDNONE |
| 2303 | end |
| 2304 | end |
| 2305 | end |
| 2306 | ret np |
| 2307 | end |
| 2308 | |
| 2309 | fn jdcal3 rep ulong gi ulong nreq ulong np ulong to ulong |
| 2310 | n = np |
| 2311 | for t ulong 3 |
| 2312 | a = add t 2 |
| 2313 | if eq t 0 |
| 2314 | a = 1 |
| 2315 | end |
| 2316 | if eq t 2 |
| 2317 | a = 4 |
| 2318 | end |
| 2319 | x = jdcload a rep gi |
| 2320 | if ne x mul nreq 16 |
| 2321 | ret JDNONE |
| 2322 | end |
| 2323 | n = jdcpairs a nreq n |
| 2324 | end |
| 2325 | ret n |
| 2326 | end |
| 2327 | |
| 2328 | note raw log arm a, repetition rep, group g of the run dir in register 4 into JDLOGW; words |
| 2329 | fn jdcload a ulong rep ulong g ulong to ulong |
| 2330 | jdscp 0 4 |
| 2331 | jdsc 0 47 |
| 2332 | jdsw 0 JWARM 4 |
| 2333 | jdsnum 0 a 1 |
| 2334 | jdsw 0 JWREP 5 |
| 2335 | jdsnum 0 rep 1 |
| 2336 | jdsw 0 JWG 2 |
| 2337 | jdsnum 0 g 2 |
| 2338 | jdsw 0 JWLOG 4 |
| 2339 | x = jdldw 0 JDLOGW 3145728 |
| 2340 | if lt x 0 |
| 2341 | ret JDNONE |
| 2342 | end |
| 2343 | ret ulong x |
| 2344 | end |
| 2345 | |
| 2346 | note ---- build ---- |
| 2347 | |
| 2348 | note index of JDW[off..off+wn) in JDF[0..n), or n |
| 2349 | fn jdfindf n ulong off ulong wn ulong to ulong |
| 2350 | if lt n wn |
| 2351 | ret n |
| 2352 | end |
| 2353 | for i ulong add sub n wn 1 |
| 2354 | k = ulong 0 |
| 2355 | while lt k wn bound 64 |
| 2356 | if ne get JDF add i k get JDW add off k |
| 2357 | break |
| 2358 | end |
| 2359 | k = add k 1 |
| 2360 | end |
| 2361 | if eq k wn |
| 2362 | ret i |
| 2363 | end |
| 2364 | end |
| 2365 | ret n |
| 2366 | end |
| 2367 | |
| 2368 | note register r written to the file of register p (flags), with a final newline |
| 2369 | fn jdwreg r ulong p ulong flags int to long |
| 2370 | x = jdopen p flags |
| 2371 | if lt x 0 |
| 2372 | ret x |
| 2373 | end |
| 2374 | fd = int x |
| 2375 | jdsc r 10 |
| 2376 | w = write fd JDS mul r 4096 get JDSL r |
| 2377 | put JDSL r sub get JDSL r 1 |
| 2378 | c = fsync fd |
| 2379 | c = fclose fd |
| 2380 | ret 0 |
| 2381 | end |
| 2382 | |
| 2383 | note drive child: chdir into register 19, stdout onto the pipe, exec the packet |
| 2384 | fn jddchild wr int to void |
| 2385 | c = chdir JDS 77824 get JDSL 19 |
| 2386 | if ne c 0 |
| 2387 | exit 126 |
| 2388 | end |
| 2389 | d = dupfd wr 1 0 |
| 2390 | e = execprog JDPK 0 get JDPKN 0 |
| 2391 | exit 127 |
| 2392 | end |
| 2393 | |
| 2394 | note read the child's stdout into JDF until end of file; bytes |
| 2395 | fn jddread rd int dl long to ulong |
| 2396 | n = ulong 0 |
| 2397 | while true bound 999999 |
| 2398 | left = sub dl monons |
| 2399 | if le left 0 |
| 2400 | break |
| 2401 | end |
| 2402 | e = waitio rd 1 left |
| 2403 | if le e 0 |
| 2404 | break |
| 2405 | end |
| 2406 | if ge n 16777216 |
| 2407 | break |
| 2408 | end |
| 2409 | k = read rd JDF n sub 16777216 n |
| 2410 | if le k 0 |
| 2411 | break |
| 2412 | end |
| 2413 | n = add n ulong k |
| 2414 | end |
| 2415 | ret n |
| 2416 | end |
| 2417 | |
| 2418 | note run drive build: registers 18 drive, 19 checkout (cwd of drive), 20 omc, 11 ALLOW, 21 CALIB, |
| 2419 | note 9 OUTLIB, 30 acquisition dir, JDXA extra arguments. acq.log record, acq-L-R.mansha; the |
| 2420 | note manifest hex is left in register 10 (empty if none). Returns the drive exit word. |
| 2421 | fn jdbuild lib ulong rep ulong to ulong |
| 2422 | jdbpk |
| 2423 | r = jdprocst 0 |
| 2424 | put JDC 40 get JDT 2 |
| 2425 | put JDC 41 get JDT 3 |
| 2426 | ex = jdbrun |
| 2427 | r = jdprocst 0 |
| 2428 | el = get JDC 42 |
| 2429 | n = get JDC 43 |
| 2430 | cu = sub get JDT 2 get JDC 40 |
| 2431 | cs = sub get JDT 3 get JDC 41 |
| 2432 | jdacqrec lib rep el cu cs ex |
| 2433 | jdmansha lib rep n |
| 2434 | w = write 1 JDF 0 n |
| 2435 | jdsclr 0 |
| 2436 | jdsw 0 JWDEX 11 |
| 2437 | jdsnum 0 ex 1 |
| 2438 | jdsw 0 JWELNS 12 |
| 2439 | jdsnum 0 el 1 |
| 2440 | jdsout 0 |
| 2441 | ret ex |
| 2442 | end |
| 2443 | |
| 2444 | fn jdbpk to void |
| 2445 | jdpk0 |
| 2446 | jdpkr 18 |
| 2447 | jdsclr 0 |
| 2448 | jdsw 0 JWBUILD 5 |
| 2449 | jdpkr 0 |
| 2450 | jdpkr 20 |
| 2451 | jdpkr 11 |
| 2452 | jdpkr 21 |
| 2453 | jdpkr 9 |
| 2454 | for i ulong get JDXL 0 |
| 2455 | jdxget 0 i |
| 2456 | jdpkr 0 |
| 2457 | end |
| 2458 | jdpkfin |
| 2459 | end |
| 2460 | |
| 2461 | note fork and exec the drive packet; exit word; JDC 42 elapsed ns, JDC 43 output bytes in JDF |
| 2462 | fn jdbrun to ulong |
| 2463 | put JDC 42 0 |
| 2464 | put JDC 43 0 |
| 2465 | pr = pipefds JDPF 0 8 524288 |
| 2466 | if ne pr 0 |
| 2467 | ret 1001 |
| 2468 | end |
| 2469 | rd = jdfdw 0 |
| 2470 | wr = jdfdw 4 |
| 2471 | t0 = monons |
| 2472 | pid = fork |
| 2473 | if lt pid 0 |
| 2474 | ret 1002 |
| 2475 | end |
| 2476 | if eq pid 0 |
| 2477 | jddchild wr |
| 2478 | end |
| 2479 | c = fclose wr |
| 2480 | dl = add t0 3600000000000 |
| 2481 | n = jddread rd dl |
| 2482 | if gt monons dl |
| 2483 | k = killpid int pid 9 |
| 2484 | end |
| 2485 | w = waitpid int pid JDWS 0 4 0 |
| 2486 | t1 = monons |
| 2487 | c = fclose rd |
| 2488 | put JDC 42 ulong sub t1 t0 |
| 2489 | put JDC 43 n |
| 2490 | ret jdwstat |
| 2491 | end |
| 2492 | |
| 2493 | fn jdacqrec lib ulong rep ulong el ulong cu ulong cs ulong ex ulong to void |
| 2494 | p = JMPRC |
| 2495 | put JDM p lib |
| 2496 | put JDM add p 1 rep |
| 2497 | put JDM add p 2 el |
| 2498 | put JDM add p 3 cu |
| 2499 | put JDM add p 4 cs |
| 2500 | put JDM add p 5 ex |
| 2501 | put JDM add p 6 jddirb 9 |
| 2502 | put JDM add p 7 0 |
| 2503 | jdspath 0 30 JWACQ 7 |
| 2504 | x = jdstw 0 p 8 1089 |
| 2505 | end |
| 2506 | |
| 2507 | note manifest_sha256=<64 hex> of the drive output into register 10 and acq-L-R.mansha |
| 2508 | fn jdmansha lib ulong rep ulong n ulong to void |
| 2509 | jdsclr 10 |
| 2510 | p = jdfindf n JWMSHA 16 |
| 2511 | if ge add p 80 add n 1 |
| 2512 | ret |
| 2513 | end |
| 2514 | b = add p 16 |
| 2515 | for i ulong 64 |
| 2516 | jdsc 10 get JDF add b i |
| 2517 | end |
| 2518 | jdscp 0 30 |
| 2519 | jdsc 0 47 |
| 2520 | jdsw 0 JWACQ2 4 |
| 2521 | jdsnum 0 lib 1 |
| 2522 | jdsc 0 45 |
| 2523 | jdsnum 0 rep 1 |
| 2524 | jdsw 0 JWMANS 7 |
| 2525 | x = jdwreg 10 0 577 |
| 2526 | end |
| 2527 | |
| 2528 | fn jdxpre r ulong to bool |
| 2529 | if jdspre r JWUNIT 5 |
| 2530 | ret true |
| 2531 | end |
| 2532 | if jdspre r JWMUT 7 |
| 2533 | ret true |
| 2534 | end |
| 2535 | ret jdspre r JWCRASH 11 |
| 2536 | end |
| 2537 | |
| 2538 | note judge build DRIVE OMEGADIR OMC ALLOW CALIB OUTLIB ACQDIR LIBID REP [DRIVE ARGS...] |
| 2539 | fn jdbuildc to int |
| 2540 | if lt argcnt 11 |
| 2541 | ret jdusage |
| 2542 | end |
| 2543 | b = jdsarg 18 2 |
| 2544 | b = jdsarg 19 3 |
| 2545 | b = jdsarg 20 4 |
| 2546 | b = jdsarg 11 5 |
| 2547 | b = jdsarg 21 6 |
| 2548 | b = jdsarg 9 7 |
| 2549 | b = jdsarg 30 8 |
| 2550 | b = jdsarg 0 9 |
| 2551 | lib = jdsval 0 |
| 2552 | b = jdsarg 0 10 |
| 2553 | rep = jdsval 0 |
| 2554 | if or eq lib JDNONE eq rep JDNONE |
| 2555 | ret jdusage |
| 2556 | end |
| 2557 | jdabs 18 |
| 2558 | jdabs 20 |
| 2559 | if not jdsdash 11 |
| 2560 | jdabs 11 |
| 2561 | end |
| 2562 | if not jdsdash 21 |
| 2563 | jdabs 21 |
| 2564 | end |
| 2565 | jdabs 9 |
| 2566 | jdx0 |
| 2567 | i = ulong 11 |
| 2568 | while lt i ulong argcnt bound 64 |
| 2569 | b = jdsarg 0 i |
| 2570 | if not jdxpre 0 |
| 2571 | jdabs 0 |
| 2572 | end |
| 2573 | jdxadd 0 |
| 2574 | i = add i 1 |
| 2575 | end |
| 2576 | ex = jdbuild lib rep |
| 2577 | if gt ex 255 |
| 2578 | ret 255 |
| 2579 | end |
| 2580 | ret int ex |
| 2581 | end |
| 2582 | |
| 2583 | note ---- recheck (contract 7.4) ---- |
| 2584 | |
| 2585 | note judge recheck MANSHAFILE PINHEX: 0 REBUILD MATCH, 3 BLOCKED |
| 2586 | fn jdrecheck to int |
| 2587 | if ne argcnt 4 |
| 2588 | ret jdusage |
| 2589 | end |
| 2590 | b = jdsarg 1 2 |
| 2591 | b = jdsarg 2 3 |
| 2592 | n = jdldsm 1 |
| 2593 | jdsclr 0 |
| 2594 | if gt n 0 |
| 2595 | for i ulong ulong n |
| 2596 | c = get JDWB i |
| 2597 | if eq c 10 |
| 2598 | break |
| 2599 | end |
| 2600 | jdsc 0 c |
| 2601 | end |
| 2602 | end |
| 2603 | if and eq get JDSL 2 64 jdseq 0 2 |
| 2604 | jdsclr 1 |
| 2605 | jdsw 1 JWMATCH 14 |
| 2606 | jdsr 1 0 |
| 2607 | jdsout 1 |
| 2608 | ret 0 |
| 2609 | end |
| 2610 | jdsclr 1 |
| 2611 | jdsw 1 JWBLK 16 |
| 2612 | jdsr 1 0 |
| 2613 | jdsw 1 JWPIN 8 |
| 2614 | jdsr 1 2 |
| 2615 | jdsout 1 |
| 2616 | ret 3 |
| 2617 | end |
| 2618 | |
| 2619 | note ---- entry ---- |
| 2620 | |
| 2621 | fn jdmain to int |
| 2622 | if lt argcnt 2 |
| 2623 | ret jdusage |
| 2624 | end |
| 2625 | b = jdsarg 0 1 |
| 2626 | k = jdspack 0 |
| 2627 | if eq k 7239026 |
| 2628 | ret jdrun |
| 2629 | end |
| 2630 | if eq k 7364980 |
| 2631 | ret jdtap |
| 2632 | end |
| 2633 | if eq k 422675505507 |
| 2634 | ret jdcalib |
| 2635 | end |
| 2636 | if eq k 431315580258 |
| 2637 | ret jdbuildc |
| 2638 | end |
| 2639 | if eq k 30227109702231410 |
| 2640 | ret jdrecheck |
| 2641 | end |
| 2642 | if eq k 8317145149216812899 |
| 2643 | ret jdcontrols |
| 2644 | end |
| 2645 | ret jdusage |
| 2646 | end |
| 2647 | |
| 2648 | note ---- controls (contract 9; K7 outcome words, K10 mutants) ---- |
| 2649 | |
| 2650 | note JDK: 0 synthetic request count, 1 request word cursor, 2 synthetic session ordinal, |
| 2651 | note 3 cold flag, 4 outcome undetected count, 5 not-run count, 6 experience byte size, |
| 2652 | note 7 last drive exit, 8 synthetic wl, 9 synthetic shape mode, 10 stored generation. |
| 2653 | global JDK ulong 64 |
| 2654 | global JDCP ulong 64 |
| 2655 | |
| 2656 | note Control paths: <control dir>/cID-SUFFIX, no collisions/overwrites. |
| 2657 | fn jdctpath r ulong id ulong suffix ulong to void |
| 2658 | jdscp r 22 |
| 2659 | jdsc r 47 |
| 2660 | jdsc r 99 |
| 2661 | jdsnum r id 1 |
| 2662 | jdsc r 45 |
| 2663 | jdsnum r suffix 1 |
| 2664 | end |
| 2665 | |
| 2666 | note controls.log: id, subcase, detected (1), undetected (0), reported (2) or not-run (3), |
| 2667 | note served-tampered flag, four reserved zero words. Each observation also printed to stdout. |
| 2668 | fn jdctl id ulong subc ulong outcome ulong served ulong to void |
| 2669 | for i ulong 8 |
| 2670 | put JDM add JMPRC i 0 |
| 2671 | end |
| 2672 | put JDM JMPRC id |
| 2673 | put JDM add JMPRC 1 subc |
| 2674 | put JDM add JMPRC 2 outcome |
| 2675 | put JDM add JMPRC 3 served |
| 2676 | jdspath 0 22 JWCLOG 12 |
| 2677 | x = jdstw 0 JMPRC 8 1089 |
| 2678 | if or eq outcome 0 ne served 0 |
| 2679 | jdaddk 4 1 |
| 2680 | end |
| 2681 | if eq outcome 3 |
| 2682 | jdaddk 5 1 |
| 2683 | end |
| 2684 | jdsclr 0 |
| 2685 | jdsc 0 67 |
| 2686 | jdsnum 0 id 1 |
| 2687 | jdsc 0 47 |
| 2688 | jdsnum 0 subc 1 |
| 2689 | jdsc 0 61 |
| 2690 | jdsnum 0 outcome 1 |
| 2691 | jdsw 0 JWWRONG 7 |
| 2692 | jdsnum 0 get JDA 1 1 |
| 2693 | jdsw 0 JWVIOL 12 |
| 2694 | jdsnum 0 get JDA 15 1 |
| 2695 | jdsc 0 32 |
| 2696 | jdsc 0 53 |
| 2697 | jdsc 0 61 |
| 2698 | jdsnum 0 get JDA 7 1 |
| 2699 | jdsc 0 32 |
| 2700 | jdsc 0 77 |
| 2701 | jdsc 0 61 |
| 2702 | jdsnum 0 add get JDA 5 get JDA 6 1 |
| 2703 | jdsout 0 |
| 2704 | end |
| 2705 | |
| 2706 | fn jdaddk i ulong v ulong to void |
| 2707 | put JDK i add get JDK i v |
| 2708 | end |
| 2709 | |
| 2710 | fn jdctlbool id ulong subc ulong yes bool served ulong to void |
| 2711 | o = ulong 0 |
| 2712 | if yes |
| 2713 | o = 1 |
| 2714 | end |
| 2715 | jdctl id subc o served |
| 2716 | end |
| 2717 | |
| 2718 | note load the first valid AGG BEGIN of DEV as the ancestor of the control programs. |
| 2719 | fn jdctancestor to bool |
| 2720 | jdscp 3 25 |
| 2721 | g = jdsload |
| 2722 | if lt g 0 |
| 2723 | ret false |
| 2724 | end |
| 2725 | for gi ulong ulong g |
| 2726 | nr = jdgload gi |
| 2727 | if lt nr 0 |
| 2728 | ret false |
| 2729 | end |
| 2730 | if jdctfind ulong nr |
| 2731 | ret true |
| 2732 | end |
| 2733 | end |
| 2734 | ret false |
| 2735 | end |
| 2736 | |
| 2737 | fn jdctfind nr ulong to bool |
| 2738 | for j ulong nr |
| 2739 | o = add JMRQ get JDM add JMOF j |
| 2740 | if ne get JDM o 1 |
| 2741 | continue |
| 2742 | end |
| 2743 | if ne get JDM add o 3 1 |
| 2744 | continue |
| 2745 | end |
| 2746 | for k ulong 64 |
| 2747 | put JDCP k get JDM add add o 2 k |
| 2748 | end |
| 2749 | ret true |
| 2750 | end |
| 2751 | ret false |
| 2752 | end |
| 2753 | |
| 2754 | note emit RFRQ as the next synthetic request, compare with the independent reference. |
| 2755 | fn jdctemit to void |
| 2756 | j = get JDK 0 |
| 2757 | o = get JDK 1 |
| 2758 | nw = add get RFRQ 1 2 |
| 2759 | put JDM add JMOF j o |
| 2760 | for k ulong nw |
| 2761 | put JDM add JMRQ add o k get RFRQ k |
| 2762 | end |
| 2763 | st = rfreq |
| 2764 | ex = add JMEX shl j 3 |
| 2765 | for k ulong 8 |
| 2766 | put JDM add ex k 0 |
| 2767 | end |
| 2768 | put JDM ex get RFRS 0 |
| 2769 | put JDM add ex 1 get RFRS 1 |
| 2770 | put JDM add ex 2 get RFRS 2 |
| 2771 | put JDM add ex 3 get RFRS 3 |
| 2772 | put JDM add ex 4 get RFRQ 0 |
| 2773 | put JDM add ex 5 get JDK 2 |
| 2774 | if eq get RFRQ 0 2 |
| 2775 | put JDM add ex 6 get JDK 3 |
| 2776 | put JDK 3 0 |
| 2777 | end |
| 2778 | if or eq get RFRQ 0 1 eq get RFRQ 0 8 |
| 2779 | put JDK 3 1 |
| 2780 | end |
| 2781 | put JDK 0 add j 1 |
| 2782 | put JDK 1 add o nw |
| 2783 | end |
| 2784 | |
| 2785 | note derive a valid AGG program from DEV, with the same family/fold and its first constant, |
| 2786 | note keeping just ADD at the selected width. These deliberate shapes isolate the mutants. |
| 2787 | fn jdctprog wl ulong c ulong to void |
| 2788 | for k ulong 64 |
| 2789 | put RFRQ add 2 k 0 |
| 2790 | end |
| 2791 | put RFRQ 2 3544411312749556050 |
| 2792 | put RFRQ 3 1 |
| 2793 | put RFRQ 4 wl |
| 2794 | put RFRQ 5 1 |
| 2795 | put RFRQ 6 1 |
| 2796 | put RFRQ 7 1 |
| 2797 | put RFRQ 8 c |
| 2798 | end |
| 2799 | |
| 2800 | note build a synthetic workload: mode 0, train (8 QUERYs); 1, drift + boundary refusals; |
| 2801 | note 2, MUL/SHL boundary KATs. It is independently scored by rfreq, not candidate responses. |
| 2802 | fn jdctsyn wl ulong mode ulong to void |
| 2803 | rfreset |
| 2804 | put JDK 0 0 |
| 2805 | put JDK 1 0 |
| 2806 | put JDK 2 0 |
| 2807 | put JDK 3 1 |
| 2808 | put JDK 8 wl |
| 2809 | put JDK 9 mode |
| 2810 | jdctprog wl and get JDCP 6 7 |
| 2811 | put RFRQ 0 1 |
| 2812 | put RFRQ 1 69 |
| 2813 | put RFRQ 66 4 |
| 2814 | put RFRQ 67 0 |
| 2815 | put RFRQ 68 1 |
| 2816 | put RFRQ 69 sub shl ulong 1 wl 1 |
| 2817 | put RFRQ 70 2 |
| 2818 | if eq wl 16 |
| 2819 | put RFRQ 68 256 |
| 2820 | end |
| 2821 | jdctemit |
| 2822 | for i ulong 8 |
| 2823 | put RFRQ 0 2 |
| 2824 | put RFRQ 1 0 |
| 2825 | jdctemit |
| 2826 | end |
| 2827 | if eq mode 1 |
| 2828 | jdctprog wl 9 |
| 2829 | put RFRQ 0 8 |
| 2830 | put RFRQ 1 64 |
| 2831 | jdctemit |
| 2832 | put RFRQ 0 2 |
| 2833 | put RFRQ 1 0 |
| 2834 | jdctemit |
| 2835 | put RFRQ 0 3 |
| 2836 | put RFRQ 1 2 |
| 2837 | put RFRQ 2 0 |
| 2838 | put RFRQ 3 shl ulong 1 wl |
| 2839 | jdctemit |
| 2840 | put RFRQ 0 2 |
| 2841 | put RFRQ 1 0 |
| 2842 | jdctemit |
| 2843 | end |
| 2844 | if eq mode 2 |
| 2845 | jdctbound wl 3 |
| 2846 | jdctbound wl 7 |
| 2847 | end |
| 2848 | end |
| 2849 | |
| 2850 | fn jdctbound wl ulong op ulong to void |
| 2851 | jdctprog wl 1 |
| 2852 | put RFRQ 7 op |
| 2853 | put RFRQ 8 sub wl 1 |
| 2854 | if eq op 3 |
| 2855 | put RFRQ 8 sub shl ulong 1 wl 1 |
| 2856 | end |
| 2857 | put RFRQ 0 8 |
| 2858 | put RFRQ 1 64 |
| 2859 | jdctemit |
| 2860 | put RFRQ 0 2 |
| 2861 | put RFRQ 1 0 |
| 2862 | jdctemit |
| 2863 | put RFRQ 0 3 |
| 2864 | put RFRQ 1 2 |
| 2865 | put RFRQ 2 0 |
| 2866 | put RFRQ 3 shl ulong 1 wl |
| 2867 | jdctemit |
| 2868 | put RFRQ 0 2 |
| 2869 | put RFRQ 1 0 |
| 2870 | jdctemit |
| 2871 | end |
| 2872 | |
| 2873 | note authorize the current digest JDH in ALLOW register 11 (copies of ALLOW are always private). |
| 2874 | fn jdctauth to bool |
| 2875 | jdsclr 0 |
| 2876 | jdshash 0 |
| 2877 | jdsw 0 JWAUTH 12 |
| 2878 | jdsw 0 JWCTRL 4 |
| 2879 | x = jdwreg 0 11 1089 |
| 2880 | ret eq x 0 |
| 2881 | end |
| 2882 | |
| 2883 | note tap the current synthetic workload to fresh experience register ep, then authorize it. |
| 2884 | fn jdcttap ep ulong to bool |
| 2885 | jdarmname 8 8 |
| 2886 | jdsdsh 9 |
| 2887 | jdsdsh 10 |
| 2888 | jdsdsh 11 |
| 2889 | jdscp 12 ep |
| 2890 | jdsclr 13 |
| 2891 | jdsc 13 49 |
| 2892 | put JDC 10 1 |
| 2893 | put JDC 11 0 |
| 2894 | put JDC 12 0 |
| 2895 | put JDC 16 JDNONE |
| 2896 | put JDC 17 JDNONE |
| 2897 | put JDC 19 0 |
| 2898 | jdcnt0 |
| 2899 | e = jdpgroup 0 get JDK 0 |
| 2900 | if or ne e 0 ne get JDA 1 0 |
| 2901 | ret false |
| 2902 | end |
| 2903 | if ne get JDC 18 0 |
| 2904 | ret false |
| 2905 | end |
| 2906 | z = jdhfile ep |
| 2907 | if le z 0 |
| 2908 | ret false |
| 2909 | end |
| 2910 | jdscp 11 6 |
| 2911 | ret jdctauth |
| 2912 | end |
| 2913 | |
| 2914 | note build a library from experience ep, optional mutant kind (0 none, 1 c1, 2 c1b, 3 c1c), |
| 2915 | note optional unit mutant kind (0 none, 1 nog3, 2 c4). Destination register 9. |
| 2916 | fn jdctbuild ep ulong mut ulong unit ulong rep ulong to ulong |
| 2917 | jdx0 |
| 2918 | if ne mut 0 |
| 2919 | jdsclr 0 |
| 2920 | if eq mut 1 |
| 2921 | jdsw 0 JWMC1 9 |
| 2922 | end |
| 2923 | if eq mut 2 |
| 2924 | jdsw 0 JWMC1B 10 |
| 2925 | end |
| 2926 | if eq mut 3 |
| 2927 | jdsw 0 JWMC1C 10 |
| 2928 | end |
| 2929 | jdxadd 0 |
| 2930 | end |
| 2931 | if ne unit 0 |
| 2932 | jdsclr 0 |
| 2933 | if eq unit 1 |
| 2934 | jdsw 0 JWUCHK 11 |
| 2935 | jdsr 0 23 |
| 2936 | end |
| 2937 | if eq unit 2 |
| 2938 | jdsw 0 JWUDEL 11 |
| 2939 | jdsr 0 24 |
| 2940 | end |
| 2941 | jdxadd 0 |
| 2942 | end |
| 2943 | jdxadd ep |
| 2944 | jdscp 11 6 |
| 2945 | jdsdsh 21 |
| 2946 | ex = jdbuild 9 rep |
| 2947 | put JDK 7 ex |
| 2948 | ret ex |
| 2949 | end |
| 2950 | |
| 2951 | note run a synthetic workload against the current library (9/10), arm a; no raw measurement log. |
| 2952 | fn jdctserve a ulong to bool |
| 2953 | jdarmname 8 a |
| 2954 | jdscp 11 6 |
| 2955 | jdsdsh 12 |
| 2956 | jdsdsh 13 |
| 2957 | put JDC 10 a |
| 2958 | put JDC 11 0 |
| 2959 | put JDC 12 0 |
| 2960 | put JDC 16 JDNONE |
| 2961 | put JDC 17 JDNONE |
| 2962 | put JDC 19 0 |
| 2963 | jdcnt0 |
| 2964 | e = jdpgroup 0 get JDK 0 |
| 2965 | ret and eq e 0 eq get JDA 15 0 |
| 2966 | end |
| 2967 | |
| 2968 | note G3 refusal means every successful QUERY was route 5 with correct values, no protocol failure. |
| 2969 | fn jdctrefused to bool |
| 2970 | if eq get JDA 0 0 |
| 2971 | ret false |
| 2972 | end |
| 2973 | if ne get JDA 1 0 |
| 2974 | ret false |
| 2975 | end |
| 2976 | if ne get JDA 15 0 |
| 2977 | ret false |
| 2978 | end |
| 2979 | ret eq get JDA 7 get JDA 0 |
| 2980 | end |
| 2981 | |
| 2982 | note mutant library build + independently scored synthetic workload (id 1/2/3/6). |
| 2983 | fn jdctmut id ulong subc ulong mut ulong unit ulong ep ulong to void |
| 2984 | jdctpath 9 id subc |
| 2985 | ex = jdctbuild ep mut unit add mul id 100 subc |
| 2986 | if or ne ex 0 ne get JDSL 10 64 |
| 2987 | jdctl id subc 3 0 |
| 2988 | ret |
| 2989 | end |
| 2990 | wl = ulong 16 |
| 2991 | jdctsyn wl 1 |
| 2992 | ok = jdctserve 4 |
| 2993 | if not ok |
| 2994 | jdctl id subc 0 0 |
| 2995 | ret |
| 2996 | end |
| 2997 | if or eq unit 1 eq unit 2 |
| 2998 | jdctlbool id subc gt get JDA 14 0 0 |
| 2999 | else |
| 3000 | yes = jdctrefused |
| 3001 | if eq id 1 |
| 3002 | yes = or yes gt get JDA 14 0 |
| 3003 | end |
| 3004 | jdctlbool id subc yes 0 |
| 3005 | end |
| 3006 | end |
| 3007 | |
| 3008 | note C2/C3 tampered experience helpers. ep -> private copy at register 2; re-authorize its new hash. |
| 3009 | fn jdctexcopy ep ulong id ulong subc ulong to bool |
| 3010 | jdctpath 2 id add 100 subc |
| 3011 | c = jdcpf ep 2 |
| 3012 | if ne c 0 |
| 3013 | ret false |
| 3014 | end |
| 3015 | ret true |
| 3016 | end |
| 3017 | |
| 3018 | note tamper variant 0 magic byte, 1 program digest, 2 sample output, 3 permute diagnostic costs. |
| 3019 | note Valid admitted records are 1024 bytes, sample slots at words 16..47, costs at word 7. |
| 3020 | fn jdctexmut ep ulong id ulong subc ulong kind ulong to void |
| 3021 | if not jdctexcopy ep id subc |
| 3022 | jdctl id subc 3 0 |
| 3023 | ret |
| 3024 | end |
| 3025 | n = jdldf 2 |
| 3026 | if lt n 1024 |
| 3027 | jdctl id subc 3 0 |
| 3028 | ret |
| 3029 | end |
| 3030 | if eq kind 0 |
| 3031 | put JDF 0 xor get JDF 0 1 |
| 3032 | end |
| 3033 | if eq kind 1 |
| 3034 | put JDF 416 xor get JDF 416 1 |
| 3035 | end |
| 3036 | if eq kind 2 |
| 3037 | x = jdgfw 136 |
| 3038 | y = jdgfw 152 |
| 3039 | jdpfw 136 y |
| 3040 | jdpfw 152 x |
| 3041 | end |
| 3042 | if eq kind 3 |
| 3043 | jdctcost ulong n |
| 3044 | end |
| 3045 | x = jdwrf 2 ulong n 577 |
| 3046 | z = jdhfile 2 |
| 3047 | jdscp 11 6 |
| 3048 | if not jdctauth |
| 3049 | jdctl id subc 3 0 |
| 3050 | ret |
| 3051 | end |
| 3052 | jdctpath 9 id subc |
| 3053 | ex = jdctbuild 2 0 0 add mul id 100 subc |
| 3054 | if eq kind 3 |
| 3055 | if ne ex 0 |
| 3056 | jdctl id subc 0 0 |
| 3057 | ret |
| 3058 | end |
| 3059 | jdctsame id subc |
| 3060 | else |
| 3061 | jdctlbool id subc eq ex 10 0 |
| 3062 | end |
| 3063 | end |
| 3064 | |
| 3065 | fn jdctcost n ulong to void |
| 3066 | nr = div n 1024 |
| 3067 | if lt nr 2 |
| 3068 | ret |
| 3069 | end |
| 3070 | first = jdgfw 56 |
| 3071 | for i ulong sub nr 1 |
| 3072 | next = jdgfw add mul add i 1 1024 56 |
| 3073 | jdpfw add mul i 1024 56 next |
| 3074 | end |
| 3075 | jdpfw add mul sub nr 1 1024 56 first |
| 3076 | end |
| 3077 | |
| 3078 | note K13 C3 equality: code/ELF byte-identical, manifest count/entries identical; lineage differs. |
| 3079 | fn jdctsame id ulong subc ulong to void |
| 3080 | ok = jdctcmpdir 14 9 |
| 3081 | jdctlbool id subc ok 0 |
| 3082 | end |
| 3083 | |
| 3084 | fn jdctcmpfile to bool |
| 3085 | x = jdhfile 0 |
| 3086 | for i ulong 4 |
| 3087 | put JDT i get JDH i |
| 3088 | end |
| 3089 | y = jdhfile 1 |
| 3090 | if or ne x y lt x 0 |
| 3091 | ret false |
| 3092 | end |
| 3093 | for i ulong 4 |
| 3094 | if ne get JDT i get JDH i |
| 3095 | ret false |
| 3096 | end |
| 3097 | end |
| 3098 | ret true |
| 3099 | end |
| 3100 | |
| 3101 | fn jdctcmpdir a ulong b ulong to bool |
| 3102 | jdspath 0 a JWCUR 7 |
| 3103 | x = jdldf 0 |
| 3104 | if ne x 40 |
| 3105 | ret false |
| 3106 | end |
| 3107 | ga = jdgfw 0 |
| 3108 | jdspath 0 b JWCUR 7 |
| 3109 | x = jdldf 0 |
| 3110 | if ne x 40 |
| 3111 | ret false |
| 3112 | end |
| 3113 | gb = jdgfw 0 |
| 3114 | for e ulong 2 |
| 3115 | ext = JWOM |
| 3116 | if eq e 1 |
| 3117 | ext = JWELF |
| 3118 | end |
| 3119 | jdgenpath 0 a ga ext |
| 3120 | jdgenpath 1 b gb ext |
| 3121 | if not jdctcmpfile |
| 3122 | ret false |
| 3123 | end |
| 3124 | end |
| 3125 | jdgenpath 0 a ga JWMAN |
| 3126 | x = jdldw 0 add JMSC 1024 256 |
| 3127 | if ne x 256 |
| 3128 | ret false |
| 3129 | end |
| 3130 | jdgenpath 0 b gb JWMAN |
| 3131 | x = jdldf 0 |
| 3132 | if ne x 2048 |
| 3133 | ret false |
| 3134 | end |
| 3135 | if ne get JDM add JMSC 1028 jdgfw 32 |
| 3136 | ret false |
| 3137 | end |
| 3138 | for i ulong 128 |
| 3139 | pos = add i 56 |
| 3140 | if ne get JDM add add JMSC 1024 pos jdgfw mul pos 8 |
| 3141 | ret false |
| 3142 | end |
| 3143 | end |
| 3144 | ret true |
| 3145 | end |
| 3146 | |
| 3147 | fn jdgenpath r ulong d ulong g ulong ext ulong to void |
| 3148 | jdspath r d JWGEN 4 |
| 3149 | jdsnum r g 1 |
| 3150 | n = ulong 4 |
| 3151 | if eq ext JWOM |
| 3152 | n = 3 |
| 3153 | end |
| 3154 | jdsw r ext n |
| 3155 | end |
| 3156 | |
| 3157 | note mutate CURRENT's named file in library 9; 0 ELF byte, 1 manifest byte, 2 coherent ELF, |
| 3158 | note 3 compiler digest, 4 profile version, 5 truncated manifest, 6 truncated CURRENT. |
| 3159 | fn jdctart kind ulong to bool |
| 3160 | jdspath 0 9 JWCUR 7 |
| 3161 | n = jdldf 0 |
| 3162 | if ne n 40 |
| 3163 | ret false |
| 3164 | end |
| 3165 | g = jdgfw 0 |
| 3166 | put JDK 10 g |
| 3167 | if eq kind 6 |
| 3168 | x = truncate JDS 0 get JDSL 0 17 |
| 3169 | ret eq x 0 |
| 3170 | end |
| 3171 | if or eq kind 0 eq kind 2 |
| 3172 | jdgenpath 0 9 g JWELF |
| 3173 | n = jdldf 0 |
| 3174 | if le n 256 |
| 3175 | ret false |
| 3176 | end |
| 3177 | p = sub ulong n 1 |
| 3178 | put JDF p xor get JDF p 1 |
| 3179 | x = jdwrf 0 ulong n 577 |
| 3180 | if eq kind 0 |
| 3181 | ret eq x 0 |
| 3182 | end |
| 3183 | z = jdhfile 0 |
| 3184 | for i ulong 4 |
| 3185 | put JDK add 16 i get JDH i |
| 3186 | end |
| 3187 | end |
| 3188 | jdgenpath 0 9 g JWMAN |
| 3189 | n = jdldf 0 |
| 3190 | if ne n 2048 |
| 3191 | ret false |
| 3192 | end |
| 3193 | if eq kind 5 |
| 3194 | x = truncate JDS 0 get JDSL 0 777 |
| 3195 | ret eq x 0 |
| 3196 | end |
| 3197 | if eq kind 1 |
| 3198 | put JDF 101 xor get JDF 101 1 |
| 3199 | end |
| 3200 | if eq kind 2 |
| 3201 | for i ulong 4 |
| 3202 | jdpfw mul add 10 i 8 get JDK add 16 i |
| 3203 | end |
| 3204 | end |
| 3205 | if eq kind 3 |
| 3206 | put JDF 112 xor get JDF 112 1 |
| 3207 | end |
| 3208 | if eq kind 4 |
| 3209 | jdpfw 144 2 |
| 3210 | end |
| 3211 | if ne kind 1 |
| 3212 | jdctfnv |
| 3213 | end |
| 3214 | x = jdwrf 0 2048 577 |
| 3215 | z = jdhfile 0 |
| 3216 | jdspath 0 9 JWCUR 7 |
| 3217 | jdpfw 0 g |
| 3218 | for i ulong 4 |
| 3219 | jdpfw mul add i 1 8 jdbswap get JDH i |
| 3220 | end |
| 3221 | x = jdwrf 0 40 577 |
| 3222 | note K7 C9 must pass the mutated manifest as MANSHA so the compiler/profile check itself is tested. |
| 3223 | if or eq kind 3 eq kind 4 |
| 3224 | jdsclr 10 |
| 3225 | jdshash 10 |
| 3226 | end |
| 3227 | ret eq x 0 |
| 3228 | end |
| 3229 | |
| 3230 | fn jdctfnv to void |
| 3231 | h = ulong 14695981039346656037 |
| 3232 | for i ulong 2040 |
| 3233 | h = mul xor h ulong get JDF i 1099511628211 |
| 3234 | end |
| 3235 | jdpfw 2040 h |
| 3236 | end |
| 3237 | |
| 3238 | note artifact load-refusal controls use the private honest library 14/15. |
| 3239 | fn jdctartifact id ulong subc ulong kind ulong to void |
| 3240 | jdctpath 9 id subc |
| 3241 | x = jdcpdir 14 9 |
| 3242 | if ne x 0 |
| 3243 | jdctl id subc 3 0 |
| 3244 | ret |
| 3245 | end |
| 3246 | jdscp 10 15 |
| 3247 | if not jdctart kind |
| 3248 | jdctl id subc 3 0 |
| 3249 | ret |
| 3250 | end |
| 3251 | jdctsyn 16 1 |
| 3252 | ok = jdctserve 4 |
| 3253 | served = ulong 0 |
| 3254 | if gt add get JDA 5 get JDA 6 0 |
| 3255 | served = 1 |
| 3256 | end |
| 3257 | jdctlbool id subc and ok jdctrefused served |
| 3258 | end |
| 3259 | |
| 3260 | note create a private ALLOW and append a REVOKED line for the control experience register 27. |
| 3261 | fn jdctrevprep subc ulong to bool |
| 3262 | jdctpath 28 9 add 100 subc |
| 3263 | x = jdcpf 6 28 |
| 3264 | if ne x 0 |
| 3265 | ret false |
| 3266 | end |
| 3267 | z = jdhfile 27 |
| 3268 | if lt z 0 |
| 3269 | ret false |
| 3270 | end |
| 3271 | jdsclr 29 |
| 3272 | jdshash 29 |
| 3273 | jdsw 29 JWREVK 9 |
| 3274 | jdsw 29 JWCTRL 4 |
| 3275 | jdsc 29 10 |
| 3276 | ret true |
| 3277 | end |
| 3278 | |
| 3279 | fn jdctrevoke subc ulong to void |
| 3280 | if not jdctrevprep subc |
| 3281 | jdctl 9 subc 3 0 |
| 3282 | ret |
| 3283 | end |
| 3284 | jdctsyn 16 1 |
| 3285 | jdarmname 8 4 |
| 3286 | jdscp 9 14 |
| 3287 | jdscp 10 15 |
| 3288 | jdscp 11 28 |
| 3289 | jdsdsh 12 |
| 3290 | jdsdsh 13 |
| 3291 | put JDC 10 4 |
| 3292 | put JDC 11 0 |
| 3293 | put JDC 12 0 |
| 3294 | put JDC 16 JDNONE |
| 3295 | if eq subc 0 |
| 3296 | jdrevoke |
| 3297 | else |
| 3298 | put JDC 16 2 |
| 3299 | end |
| 3300 | put JDC 17 JDNONE |
| 3301 | put JDC 19 0 |
| 3302 | jdcnt0 |
| 3303 | e = jdpgroup 0 get JDK 0 |
| 3304 | served = ulong 0 |
| 3305 | ok = false |
| 3306 | if eq subc 0 |
| 3307 | if gt add get JDA 5 get JDA 6 0 |
| 3308 | served = 1 |
| 3309 | end |
| 3310 | ok = jdctrefused |
| 3311 | else |
| 3312 | if gt get JDA 11 0 |
| 3313 | served = 1 |
| 3314 | end |
| 3315 | ok = jdctrevmid |
| 3316 | end |
| 3317 | ok = and ok eq e 0 |
| 3318 | ok = and ok eq get JDA 1 0 |
| 3319 | jdctlbool 9 subc ok served |
| 3320 | put JDC 16 JDNONE |
| 3321 | jdsclr 28 |
| 3322 | jdsclr 29 |
| 3323 | end |
| 3324 | |
| 3325 | fn jdctrevmid to bool |
| 3326 | if eq get JDA 13 0 |
| 3327 | ret false |
| 3328 | end |
| 3329 | if eq get JDA 10 0 |
| 3330 | ret false |
| 3331 | end |
| 3332 | ret eq get JDA 10 get JDA 12 |
| 3333 | end |
| 3334 | |
| 3335 | note C8 steps: seed the directory with an honest complete generation, then invoke crashafter:K; |
| 3336 | note read CURRENT and check its manifest/ELF SHA-256, pin it, serve and score with the reference. |
| 3337 | fn jdctcrash step ulong to void |
| 3338 | jdctpath 9 10 step |
| 3339 | x = jdcpdir 14 9 |
| 3340 | if ne x 0 |
| 3341 | jdctl 10 step 3 0 |
| 3342 | ret |
| 3343 | end |
| 3344 | jdx0 |
| 3345 | jdsclr 0 |
| 3346 | jdsw 0 JWCRASH 11 |
| 3347 | jdsnum 0 step 1 |
| 3348 | jdxadd 0 |
| 3349 | jdxadd 27 |
| 3350 | jdscp 11 6 |
| 3351 | jdsdsh 21 |
| 3352 | ex = jdbuild 9 add 1000 step |
| 3353 | if ne ex 97 |
| 3354 | jdctl 10 step 0 0 |
| 3355 | ret |
| 3356 | end |
| 3357 | if not jdctcurrent |
| 3358 | jdctl 10 step 0 0 |
| 3359 | ret |
| 3360 | end |
| 3361 | jdctsyn 16 1 |
| 3362 | ok = jdctserve 4 |
| 3363 | ok = and ok eq get JDA 1 0 |
| 3364 | m = add get JDA 5 get JDA 6 |
| 3365 | ok = and ok gt m 0 |
| 3366 | jdctlbool 10 step ok 0 |
| 3367 | end |
| 3368 | |
| 3369 | note validate complete CURRENT files independently; use its manifest digest as MANSHA (register 10). |
| 3370 | fn jdctcurrent to bool |
| 3371 | jdspath 0 9 JWCUR 7 |
| 3372 | n = jdldf 0 |
| 3373 | if ne n 40 |
| 3374 | ret false |
| 3375 | end |
| 3376 | g = jdgfw 0 |
| 3377 | for i ulong 4 |
| 3378 | put JDK add 16 i jdbswap jdgfw mul add i 1 8 |
| 3379 | end |
| 3380 | jdgenpath 0 9 g JWMAN |
| 3381 | n = jdhfile 0 |
| 3382 | if ne n 2048 |
| 3383 | ret false |
| 3384 | end |
| 3385 | for i ulong 4 |
| 3386 | if ne get JDH i get JDK add 16 i |
| 3387 | ret false |
| 3388 | end |
| 3389 | end |
| 3390 | jdsclr 10 |
| 3391 | jdshash 10 |
| 3392 | n = jdldf 0 |
| 3393 | if ne n 2048 |
| 3394 | ret false |
| 3395 | end |
| 3396 | for i ulong 4 |
| 3397 | put JDK add 16 i jdgfw mul add 10 i 8 |
| 3398 | end |
| 3399 | jdgenpath 0 9 g JWELF |
| 3400 | n = jdhfile 0 |
| 3401 | if le n 0 |
| 3402 | ret false |
| 3403 | end |
| 3404 | for i ulong 4 |
| 3405 | if ne get JDH i get JDK add 16 i |
| 3406 | ret false |
| 3407 | end |
| 3408 | end |
| 3409 | jdgenpath 0 9 g JWOM |
| 3410 | ret gt jdfsize 0 0 |
| 3411 | end |
| 3412 | |
| 3413 | note C11: identity before/after a real SIGKILL mid-session, fresh process byte-identical responses. |
| 3414 | fn jdctrestart to void |
| 3415 | jdctsyn 16 1 |
| 3416 | jdscp 9 14 |
| 3417 | jdscp 10 15 |
| 3418 | ok = jdctserve 4 |
| 3419 | if or not ok ne get JDA 1 0 |
| 3420 | jdctl 13 0 0 0 |
| 3421 | ret |
| 3422 | end |
| 3423 | for i ulong 4 |
| 3424 | put JDK add 24 i get JDM add add JMRT 4 i |
| 3425 | end |
| 3426 | if not jdctcurrent |
| 3427 | jdctl 13 0 0 0 |
| 3428 | ret |
| 3429 | end |
| 3430 | jdctsyn 16 1 |
| 3431 | jdarmname 8 4 |
| 3432 | jdscp 11 6 |
| 3433 | jdsdsh 12 |
| 3434 | jdsdsh 13 |
| 3435 | put JDC 17 3 |
| 3436 | put JDC 16 JDNONE |
| 3437 | put JDC 19 0 |
| 3438 | jdcnt0 |
| 3439 | e = jdpgroup 0 get JDK 0 |
| 3440 | killed = eq get JDC 18 265 |
| 3441 | put JDC 17 JDNONE |
| 3442 | jdscp 9 14 |
| 3443 | if not jdctcurrent |
| 3444 | jdctl 13 0 0 0 |
| 3445 | ret |
| 3446 | end |
| 3447 | jdctsyn 16 1 |
| 3448 | ok = jdctserve 4 |
| 3449 | same = jdseq 10 15 |
| 3450 | jdctlbool 13 0 and killed and same and ok eq get JDA 1 0 0 |
| 3451 | end |
| 3452 | |
| 3453 | note C5 is scored both at widths 8 and 16, full and delta (with/without a library). |
| 3454 | fn jdctkat wl ulong a ulong subc ulong to void |
| 3455 | jdctsyn wl 2 |
| 3456 | if eq a 1 |
| 3457 | jdsdsh 9 |
| 3458 | jdsdsh 10 |
| 3459 | else |
| 3460 | jdscp 9 14 |
| 3461 | jdscp 10 15 |
| 3462 | end |
| 3463 | ok = jdctserve a |
| 3464 | jdctlbool 7 subc and ok eq get JDA 1 0 0 |
| 3465 | end |
| 3466 | |
| 3467 | note controls DEV BASE DRIVE OMEGADIR OMC ALLOW NOG3 C4 OUT CPU |
| 3468 | note Builds its own honest control experiences and libraries; no FINAL data or vault access. |
| 3469 | fn jdcontrols to int |
| 3470 | if ne argcnt 12 |
| 3471 | ret jdusage |
| 3472 | end |
| 3473 | b = jdsarg 25 2 |
| 3474 | b = jdsarg 5 3 |
| 3475 | b = jdsarg 18 4 |
| 3476 | b = jdsarg 19 5 |
| 3477 | b = jdsarg 20 6 |
| 3478 | b = jdsarg 1 7 |
| 3479 | b = jdsarg 23 8 |
| 3480 | b = jdsarg 24 9 |
| 3481 | b = jdsarg 22 10 |
| 3482 | b = jdsarg 7 11 |
| 3483 | jdabs 18 |
| 3484 | jdabs 20 |
| 3485 | jdabs 23 |
| 3486 | jdabs 24 |
| 3487 | r = jdmkdir 22 448 |
| 3488 | jdabs 22 |
| 3489 | jdscp 30 22 |
| 3490 | jdctpath 6 0 0 |
| 3491 | c = jdcpf 1 6 |
| 3492 | if ne c 0 |
| 3493 | ret jderr 70 |
| 3494 | end |
| 3495 | jdctpath 26 0 8 |
| 3496 | jdctpath 27 0 16 |
| 3497 | if not jdctancestor |
| 3498 | ret jderr 71 |
| 3499 | end |
| 3500 | put JDK 4 0 |
| 3501 | put JDK 5 0 |
| 3502 | jdctsyn 8 0 |
| 3503 | if not jdcttap 26 |
| 3504 | ret jderr 72 |
| 3505 | end |
| 3506 | jdctsyn 16 0 |
| 3507 | if not jdcttap 27 |
| 3508 | ret jderr 73 |
| 3509 | end |
| 3510 | note Honest rebuild for C3 costs and all artifact/lifecycle controls. |
| 3511 | jdctpath 9 0 1 |
| 3512 | ex = jdctbuild 27 0 0 1 |
| 3513 | if ne ex 0 |
| 3514 | ret jderr 74 |
| 3515 | end |
| 3516 | jdscp 14 9 |
| 3517 | jdscp 15 10 |
| 3518 | jdctmut 1 0 1 0 26 |
| 3519 | jdctmut 1 1 1 1 26 |
| 3520 | jdctmut 2 0 2 0 27 |
| 3521 | jdctmut 2 1 2 1 27 |
| 3522 | jdctmut 3 0 3 0 27 |
| 3523 | jdctexmut 27 4 0 0 |
| 3524 | jdctexmut 27 4 1 1 |
| 3525 | jdctexmut 27 5 0 2 |
| 3526 | jdctexmut 27 5 1 3 |
| 3527 | jdctmut 6 0 0 2 27 |
| 3528 | for w ulong 2 |
| 3529 | wl = add mul w 8 8 |
| 3530 | jdctkat wl 1 mul w 3 |
| 3531 | jdctkat wl 4 add mul w 3 1 |
| 3532 | jdctsyn wl 2 |
| 3533 | jdsdsh 9 |
| 3534 | jdsdsh 10 |
| 3535 | ok = jdctserve 4 |
| 3536 | jdctlbool 7 add mul w 3 2 and ok eq get JDA 1 0 0 |
| 3537 | end |
| 3538 | for k ulong 3 |
| 3539 | jdctartifact 8 k k |
| 3540 | end |
| 3541 | jdctrevoke 0 |
| 3542 | jdctrevoke 1 |
| 3543 | for k ulong 9 |
| 3544 | jdctcrash add k 1 |
| 3545 | end |
| 3546 | jdctartifact 11 0 3 |
| 3547 | jdctartifact 11 1 4 |
| 3548 | jdctartifact 12 0 5 |
| 3549 | jdctartifact 12 1 6 |
| 3550 | jdctrestart |
| 3551 | note C12 is an ablation report, not a guard detection; run independently via judge run with arms 56. |
| 3552 | jdctl 14 0 2 0 |
| 3553 | if gt get JDK 4 0 |
| 3554 | ret 4 |
| 3555 | end |
| 3556 | if gt get JDK 5 0 |
| 3557 | ret 3 |
| 3558 | end |
| 3559 | ret 0 |
| 3560 | end |