aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / native / omegallm / eio.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note omegallm eio.om (aien-train#52): the UEFI platform unit for `target x86efi`. It replaces lio.om |
| 3 | note and defines the same functions (oargc, oargr, oflush, ocwopen, ocwput, ocwend, ofsz, ogradw, |
| 4 | note ocsinit, ocsg, ocsp, odread, owflush, owopen, owclose, ooffrd, oprd, obmsave, main) with efi words only: efi 1 key, efi 2 stall, efi 10 millisecond clock, |
| 5 | note efi 12 file (one open file; ARG bits 0..7 sub, 8..15 volume, 16..63 position; result bit 63 set |
| 6 | note on error), efi 13 console text, efi 14 machine identity (CPUID, SystemTable FirmwareVendor and |
| 7 | note FirmwareRevision, SMBIOS structure table). Every file is on the volume the image was loaded |
| 8 | note from (k = 255). After the banner main prints the identity line `ID cpu=... fw=... fwrev=... |
| 9 | note smbios=.../.../...` (CONTRACT section 9); it never prints the SMBIOS serial number or UUID. |
| 10 | note The command lines come from \OLLM\JOB.TXT (CONTRACT section 9): one command per line without the |
| 11 | note program name, tokens split on space or tab, a token in double quotes may hold spaces, empty lines |
| 12 | note and lines starting with # are skipped. Each job's line is echoed as `> line`, its output follows |
| 13 | note (with a line feed added when it does not end in one), then `J ms` (wall milliseconds, 0 when the |
| 14 | note firmware has no clock). Output goes to the console |
| 15 | note (bytes outside 9, 10, 13, 32..126 shown as ?) and, byte-exact, to \OLLM\OUT.TXT, which main |
| 16 | note recreates at start; each flush appends. After the last job main prints `OLLM DONE jobs ms` and |
| 17 | note waits up to 300 s for a key. A refusal (exit N) ends the application at once with status N, as |
| 18 | note on Linux; OUT.TXT then ends with the failing job's output so far. |
| 19 | note One job is not a cli command: `ask CK SEED N TEMPMILLI [MERGES]` (oask) is a typed conversation with |
| 20 | note the model at the machine's own keyboard and screen. It prints `You: `, reads a line of keys (efi 1; |
| 21 | note 32..126 only, Backspace removes one, at most 900), and runs `sample CK SEED+turn N TEMPMILLI LINE |
| 22 | note [MERGES]` for it, again and again. An empty line, Esc, or ten minutes without a key ends the job. The |
| 23 | note typed line and the answer go to OUT.TXT like every other output. It needs a keyboard, so no |
| 24 | note recorded job file uses it. |
| 25 | note Differences from lio.om: a checkpoint is written in place (no PATH.tmp + rename: the UEFI file |
| 26 | note protocol has no rename), and a path longer than 255 bytes is an I/O refusal (exit 70). |
| 27 | const OEV ulong 65280 |
| 28 | const OERR ulong 9223372036854775808 |
| 29 | const OJCAP ulong 65536 |
| 30 | global ojob uchar 65536 |
| 31 | global ojn ulong 1 |
| 32 | global otb ulong 64 |
| 33 | global otl ulong 64 |
| 34 | global otc ulong 1 |
| 35 | global opn uchar 16 |
| 36 | global ocon uchar 4096 |
| 37 | global oop ulong 1 |
| 38 | global owq0 uchar 256 |
| 39 | global owq1 uchar 256 |
| 40 | global owql ulong 2 |
| 41 | global owps ulong 2 |
| 42 | global oclk uchar 8 |
| 43 | global okey uchar 8 |
| 44 | global olc ulong 1 |
| 45 | global oidc uchar 16 |
| 46 | global oidb uchar 48 |
| 47 | global oidv uchar 512 |
| 48 | global oids uchar 65536 |
| 49 | |
| 50 | fn oeerr r ulong to bool |
| 51 | ret ge r OERR |
| 52 | end |
| 53 | |
| 54 | note efi 12 ARG for sub-op s at byte position p on the boot volume |
| 55 | fn oefa s ulong p ulong to ulong |
| 56 | ret or or s OEV shl p 16 |
| 57 | end |
| 58 | |
| 59 | note close the open file; a failed close is an I/O refusal |
| 60 | fn oeclose to void |
| 61 | c = efi 12 oefa 4 0 opn 0 0 |
| 62 | if oeerr c |
| 63 | exit 70 |
| 64 | end |
| 65 | end |
| 66 | |
| 67 | note opn = \OLLM\JOB.TXT (w = 0) or \OLLM\OUT.TXT (w = 1), 13 bytes |
| 68 | fn opath w ulong to void |
| 69 | put opn 0 92 |
| 70 | put opn 1 79 |
| 71 | put opn 2 76 |
| 72 | put opn 3 76 |
| 73 | put opn 4 77 |
| 74 | put opn 5 92 |
| 75 | if eq w 0 |
| 76 | put opn 6 74 |
| 77 | put opn 7 79 |
| 78 | put opn 8 66 |
| 79 | else |
| 80 | put opn 6 79 |
| 81 | put opn 7 85 |
| 82 | put opn 8 84 |
| 83 | end |
| 84 | put opn 9 46 |
| 85 | put opn 10 84 |
| 86 | put opn 11 88 |
| 87 | put opn 12 84 |
| 88 | end |
| 89 | |
| 90 | note the bytes of a little-endian u64 packing, low byte first, zero bytes skipped |
| 91 | fn oputw v ulong to void |
| 92 | for k ulong 8 |
| 93 | c = and shr v mul k 8 255 |
| 94 | if ne c 0 |
| 95 | oputc c |
| 96 | end |
| 97 | end |
| 98 | end |
| 99 | |
| 100 | note onsnow: the firmware clock in nanoseconds (kvcmp's step timing in cli.om), ms resolution |
| 101 | fn onsnow to ulong |
| 102 | ret mul oms 1000000 |
| 103 | end |
| 104 | |
| 105 | note firmware milliseconds (efi 10), 0 when unavailable |
| 106 | fn oms to ulong |
| 107 | st = efi 10 0 oclk 0 8 |
| 108 | if ne st 0 |
| 109 | ret 0 |
| 110 | end |
| 111 | v = ulong 0 |
| 112 | for i ulong 8 |
| 113 | v = or v shl ulong get oclk i mul i 8 |
| 114 | end |
| 115 | ret v |
| 116 | end |
| 117 | |
| 118 | note wait up to 300 s (3000 polls 100 ms apart) for a key |
| 119 | fn owait to void |
| 120 | for i ulong 3000 |
| 121 | st = efi 1 0 okey 0 4 |
| 122 | if eq st 0 |
| 123 | break |
| 124 | end |
| 125 | s2 = efi 2 100000 okey 0 0 |
| 126 | end |
| 127 | end |
| 128 | |
| 129 | fn oargc to ulong |
| 130 | ret get otc 0 |
| 131 | end |
| 132 | |
| 133 | note the current job is `ask` with four or five arguments (MERGES is optional, as for sample) |
| 134 | fn oisask to bool |
| 135 | if and ne get otc 0 6 ne get otc 0 7 |
| 136 | ret false |
| 137 | end |
| 138 | if ne get otl 1 3 |
| 139 | ret false |
| 140 | end |
| 141 | b = get otb 1 |
| 142 | ret and and eq ulong get ojob b 97 eq ulong get ojob add b 1 115 eq ulong get ojob add b 2 107 |
| 143 | end |
| 144 | |
| 145 | note ocon[0 .. n) to the console only (not OUT.TXT) |
| 146 | fn ocons n ulong to void |
| 147 | t = efi 13 0 ocon 0 n |
| 148 | end |
| 149 | |
| 150 | note the console line `You: ` + the n typed bytes kept at ojob[64544 ..), after a carriage return and |
| 151 | note followed by e spaces and, when e > 0, the same line again (so a removed character disappears) |
| 152 | fn oaskline n ulong e ulong to void |
| 153 | put ocon 0 13 |
| 154 | put ocon 1 89 |
| 155 | put ocon 2 111 |
| 156 | put ocon 3 117 |
| 157 | put ocon 4 58 |
| 158 | put ocon 5 32 |
| 159 | for k ulong n |
| 160 | put ocon add 6 k get ojob add 64544 k |
| 161 | end |
| 162 | for k ulong e |
| 163 | put ocon add add 6 n k 32 |
| 164 | end |
| 165 | ocons add add 6 n e |
| 166 | if gt e 0 |
| 167 | ocons add 6 n |
| 168 | end |
| 169 | end |
| 170 | |
| 171 | note read one typed line into ojob[64544 ..): its length, or OERR when Esc was pressed or no key came |
| 172 | note for ten minutes (30000 polls 20 ms apart, the count restarting at every key) |
| 173 | fn oaskread to ulong |
| 174 | n = ulong 0 |
| 175 | oaskline 0 0 |
| 176 | idle = ulong 0 |
| 177 | for i ulong 4000000000 |
| 178 | st = efi 1 0 okey 0 4 |
| 179 | if ne st 0 |
| 180 | idle = add idle 1 |
| 181 | if ge idle 30000 |
| 182 | ret OERR |
| 183 | end |
| 184 | s2 = efi 2 20000 okey 0 0 |
| 185 | else |
| 186 | idle = 0 |
| 187 | c = or ulong get okey 2 shl ulong get okey 3 8 |
| 188 | sc = or ulong get okey 0 shl ulong get okey 1 8 |
| 189 | if eq c 13 |
| 190 | ret n |
| 191 | end |
| 192 | if and eq c 0 eq sc 23 |
| 193 | ret OERR |
| 194 | end |
| 195 | if and eq c 8 gt n 0 |
| 196 | n = sub n 1 |
| 197 | oaskline n 1 |
| 198 | end |
| 199 | if and and ge c 32 le c 126 lt n 900 |
| 200 | put ojob add 64544 n uchar c |
| 201 | n = add n 1 |
| 202 | oaskline n 0 |
| 203 | end |
| 204 | end |
| 205 | end |
| 206 | ret OERR |
| 207 | end |
| 208 | |
| 209 | note v in decimal at ojob[64520 ..); the number of digits |
| 210 | fn oaskseed v ulong to ulong |
| 211 | dl = ulong 1 |
| 212 | x = v |
| 213 | for k ulong 19 |
| 214 | x = div x 10 |
| 215 | if gt x 0 |
| 216 | dl = add dl 1 |
| 217 | end |
| 218 | end |
| 219 | x = v |
| 220 | for k ulong dl |
| 221 | p = sub add 64519 dl k |
| 222 | put ojob p uchar add 48 rem x 10 |
| 223 | x = div x 10 |
| 224 | end |
| 225 | ret dl |
| 226 | end |
| 227 | |
| 228 | note the typed line of n bytes to OUT.TXT and the console as `You: line`, over the echoed one |
| 229 | fn oaskecho n ulong to void |
| 230 | put ocon 0 13 |
| 231 | ocons 1 |
| 232 | oputc 89 |
| 233 | oputc 111 |
| 234 | oputc 117 |
| 235 | oputc 58 |
| 236 | oputc 32 |
| 237 | for k ulong n |
| 238 | oputc ulong get ojob add 64544 k |
| 239 | end |
| 240 | oputc 10 |
| 241 | oflush |
| 242 | end |
| 243 | |
| 244 | note the seed argument of the ask job as a number (exit 2 unless it is 1 to 19 decimal digits, the |
| 245 | note bound sample's own argument has, so the number never wraps) |
| 246 | fn oaskbase to ulong |
| 247 | sb = get otb 3 |
| 248 | if or eq get otl 3 0 gt get otl 3 19 |
| 249 | exit 2 |
| 250 | end |
| 251 | seed = ulong 0 |
| 252 | for k ulong get otl 3 |
| 253 | d = ulong get ojob add sb k |
| 254 | if or lt d 48 gt d 57 |
| 255 | exit 2 |
| 256 | end |
| 257 | seed = add mul seed 10 sub d 48 |
| 258 | end |
| 259 | ret seed |
| 260 | end |
| 261 | |
| 262 | note ask CK SEED N TEMPMILLI [MERGES]: see the head of this file. The rewritten job is built in the last |
| 263 | note 1024 bytes of ojob, which the job file may not reach (exit 2): `sample` at 64512, the turn's seed |
| 264 | note in decimal at 64520, the typed line at 64544. |
| 265 | fn oask to void |
| 266 | if gt get ojn 0 64000 |
| 267 | exit 2 |
| 268 | end |
| 269 | put ojob 64512 115 |
| 270 | put ojob 64513 97 |
| 271 | put ojob 64514 109 |
| 272 | put ojob 64515 112 |
| 273 | put ojob 64516 108 |
| 274 | put ojob 64517 101 |
| 275 | seed = oaskbase |
| 276 | hm = eq get otc 0 7 |
| 277 | mb = get otb 6 |
| 278 | ml = get otl 6 |
| 279 | for turn ulong 1000000 |
| 280 | n = oaskread |
| 281 | if or oeerr n eq n 0 |
| 282 | break |
| 283 | end |
| 284 | oaskecho n |
| 285 | dl = oaskseed add seed turn |
| 286 | put otb 1 64512 |
| 287 | put otl 1 6 |
| 288 | put otb 3 64520 |
| 289 | put otl 3 dl |
| 290 | put otb 6 64544 |
| 291 | put otl 6 n |
| 292 | if hm |
| 293 | put otb 7 mb |
| 294 | put otl 7 ml |
| 295 | put otc 0 8 |
| 296 | else |
| 297 | put otc 0 7 |
| 298 | end |
| 299 | rc = ocmd |
| 300 | oflush |
| 301 | if ne get olc 0 10 |
| 302 | oputc 10 |
| 303 | oflush |
| 304 | end |
| 305 | end |
| 306 | put ocon 0 10 |
| 307 | ocons 1 |
| 308 | end |
| 309 | |
| 310 | note token i of the current job into oarg (at most 4096 bytes copied); argv[0] is "ollm"; returns |
| 311 | note the token length, or -1 when there is no token i |
| 312 | fn oargr i ulong to long |
| 313 | if ge i get otc 0 |
| 314 | ret sub long 0 long 1 |
| 315 | end |
| 316 | if eq i 0 |
| 317 | put oarg 0 111 |
| 318 | put oarg 1 108 |
| 319 | put oarg 2 108 |
| 320 | put oarg 3 109 |
| 321 | ret long 4 |
| 322 | end |
| 323 | s = get otb i |
| 324 | n = get otl i |
| 325 | m = n |
| 326 | if gt m 4096 |
| 327 | m = ulong 4096 |
| 328 | end |
| 329 | for k ulong m |
| 330 | put oarg k get ojob add s k |
| 331 | end |
| 332 | ret long n |
| 333 | end |
| 334 | |
| 335 | note append oout to OUT.TXT, then show it on the console |
| 336 | fn oflush to void |
| 337 | n = get oon 0 |
| 338 | if gt n 0 |
| 339 | opath 1 |
| 340 | r = efi 12 oefa 5 0 opn 0 13 |
| 341 | if oeerr r |
| 342 | exit 70 |
| 343 | end |
| 344 | if ne r get oop 0 |
| 345 | exit 70 |
| 346 | end |
| 347 | w = efi 12 oefa 3 get oop 0 oout 0 n |
| 348 | if ne w n |
| 349 | exit 70 |
| 350 | end |
| 351 | oeclose |
| 352 | put oop 0 add get oop 0 n |
| 353 | for k ulong n |
| 354 | c = ulong get oout k |
| 355 | ok = or or eq c 9 eq c 10 or eq c 13 and ge c 32 le c 126 |
| 356 | if ok |
| 357 | put ocon k uchar c |
| 358 | else |
| 359 | put ocon k 63 |
| 360 | end |
| 361 | end |
| 362 | t = efi 13 0 ocon 0 n |
| 363 | put olc 0 ulong get oout sub n 1 |
| 364 | put oon 0 0 |
| 365 | end |
| 366 | end |
| 367 | |
| 368 | note v1 checkpoint stream (ckpt.om): create (or empty) the file named by argument ai and keep it |
| 369 | note open (efi 12 holds one open file; nothing else is opened until ocwend) |
| 370 | fn ocwopen ai ulong to void |
| 371 | pl = oargp ai |
| 372 | r = efi 12 oefa 1 0 oarg 0 pl |
| 373 | if oeerr r |
| 374 | exit 70 |
| 375 | end |
| 376 | end |
| 377 | |
| 378 | note write ock[0 .. n) at byte position pos of the open checkpoint file |
| 379 | fn ocwput pos ulong n ulong to void |
| 380 | w = efi 12 oefa 3 pos ock 0 n |
| 381 | if ne w n |
| 382 | exit 70 |
| 383 | end |
| 384 | end |
| 385 | |
| 386 | note close the checkpoint file (written in place: UEFI has no rename) |
| 387 | fn ocwend ai ulong to void |
| 388 | oeclose |
| 389 | end |
| 390 | |
| 391 | note size in bytes of the file named by argument ai |
| 392 | fn ofsz ai ulong to ulong |
| 393 | pl = oargp ai |
| 394 | sz = efi 12 oefa 0 0 oarg 0 pl |
| 395 | if oeerr sz |
| 396 | exit 70 |
| 397 | end |
| 398 | oeclose |
| 399 | ret sz |
| 400 | end |
| 401 | |
| 402 | note gradient of the step loss: one process only, so K > 1 is refused (CONTRACT-V1 section 5.1) |
| 403 | fn ogradw to f64 |
| 404 | if gt get og 45 1 |
| 405 | exit 29 |
| 406 | end |
| 407 | ret ograd |
| 408 | end |
| 409 | |
| 410 | note cold store (CONTRACT-V3 section 2): GRD and the Adam moments, 3 P values, in three globals of |
| 411 | note OCSB = 15833472 values (the x86efi limit is the v2 bank-A capacity; one global holds at most |
| 412 | note 16777216 values) |
| 413 | const OCSB ulong 15833472 |
| 414 | global ocs0 f64 15833472 |
| 415 | global ocs1 f64 15833472 |
| 416 | global ocs2 f64 15833472 |
| 417 | |
| 418 | note capacity of the cold store in f64 values |
| 419 | fn ocsinit to ulong |
| 420 | ret mul 3 OCSB |
| 421 | end |
| 422 | |
| 423 | fn ocsg i ulong to f64 |
| 424 | if lt i OCSB |
| 425 | ret get ocs0 i |
| 426 | end |
| 427 | j = sub i OCSB |
| 428 | if lt j OCSB |
| 429 | ret get ocs1 j |
| 430 | end |
| 431 | ret get ocs2 sub j OCSB |
| 432 | end |
| 433 | |
| 434 | fn ocsp i ulong v f64 to void |
| 435 | if lt i OCSB |
| 436 | put ocs0 i v |
| 437 | ret |
| 438 | end |
| 439 | j = sub i OCSB |
| 440 | if lt j OCSB |
| 441 | put ocs1 j v |
| 442 | else |
| 443 | put ocs2 sub j OCSB v |
| 444 | end |
| 445 | end |
| 446 | |
| 447 | note read the file named by argument i into od0/od1; exit 21 when longer than ODCAP |
| 448 | fn odread i ulong to ulong |
| 449 | n = oargp i |
| 450 | sz = efi 12 oefa 0 0 oarg 0 n |
| 451 | if oeerr sz |
| 452 | exit 70 |
| 453 | end |
| 454 | if gt sz ODCAP |
| 455 | exit 21 |
| 456 | end |
| 457 | p = ulong 0 |
| 458 | while lt p sz bound 999999 |
| 459 | r = ulong 0 |
| 460 | if lt p ODHALF |
| 461 | e = sz |
| 462 | if gt e ODHALF |
| 463 | e = ODHALF |
| 464 | end |
| 465 | r = efi 12 oefa 2 p od0 p sub e p |
| 466 | else |
| 467 | r = efi 12 oefa 2 p od1 sub p ODHALF sub sz p |
| 468 | end |
| 469 | if or oeerr r eq r 0 |
| 470 | exit 70 |
| 471 | end |
| 472 | p = add p r |
| 473 | end |
| 474 | if ne p sz |
| 475 | exit 70 |
| 476 | end |
| 477 | oeclose |
| 478 | put odn 0 p |
| 479 | ret p |
| 480 | end |
| 481 | |
| 482 | note prep output: append writer k's buffer to its file (efi 12 sub 5 opens without truncation and |
| 483 | note returns the current size, which must equal the bytes this writer has written) |
| 484 | fn owflush k ulong to void |
| 485 | n = get owbn k |
| 486 | if gt n 0 |
| 487 | l = get owql k |
| 488 | r = ulong 0 |
| 489 | if eq k 0 |
| 490 | r = efi 12 oefa 5 0 owq0 0 l |
| 491 | else |
| 492 | r = efi 12 oefa 5 0 owq1 0 l |
| 493 | end |
| 494 | if oeerr r |
| 495 | exit 70 |
| 496 | end |
| 497 | if ne r get owps k |
| 498 | exit 70 |
| 499 | end |
| 500 | w = ulong 0 |
| 501 | if eq k 0 |
| 502 | w = efi 12 oefa 3 r owb0 0 n |
| 503 | else |
| 504 | w = efi 12 oefa 3 r owb1 0 n |
| 505 | end |
| 506 | if ne w n |
| 507 | exit 70 |
| 508 | end |
| 509 | oeclose |
| 510 | put owps k add r n |
| 511 | end |
| 512 | put owbn k 0 |
| 513 | end |
| 514 | |
| 515 | note create (or empty) the file named by argument i for writer k |
| 516 | fn owopen k ulong i ulong to void |
| 517 | n = oargp i |
| 518 | if gt n 255 |
| 519 | exit 70 |
| 520 | end |
| 521 | for j ulong n |
| 522 | if eq k 0 |
| 523 | put owq0 j get oarg j |
| 524 | else |
| 525 | put owq1 j get oarg j |
| 526 | end |
| 527 | end |
| 528 | put owql k n |
| 529 | r = efi 12 oefa 1 0 oarg 0 n |
| 530 | if oeerr r |
| 531 | exit 70 |
| 532 | end |
| 533 | oeclose |
| 534 | put owps k 0 |
| 535 | put owbn k 0 |
| 536 | end |
| 537 | |
| 538 | fn owclose k ulong to void |
| 539 | owflush k |
| 540 | end |
| 541 | |
| 542 | note read argument ai (B little-endian u64 offsets) into ochk; exit 21 unless it holds exactly 8 B bytes |
| 543 | fn ooffrd ai ulong to void |
| 544 | n = oargp ai |
| 545 | sz = efi 12 oefa 0 0 oarg 0 n |
| 546 | if oeerr sz |
| 547 | exit 70 |
| 548 | end |
| 549 | if ge sz 65536 |
| 550 | exit 21 |
| 551 | end |
| 552 | p = ulong 0 |
| 553 | while lt p sz bound 70000 |
| 554 | r = efi 12 oefa 2 p ochk p sub sz p |
| 555 | if or oeerr r eq r 0 |
| 556 | exit 70 |
| 557 | end |
| 558 | p = add p r |
| 559 | end |
| 560 | if ne p sz |
| 561 | exit 70 |
| 562 | end |
| 563 | oeclose |
| 564 | if ne p mul 8 get og 6 |
| 565 | exit 21 |
| 566 | end |
| 567 | end |
| 568 | |
| 569 | note ojob[p] is a token separator (space or tab) |
| 570 | fn ojsep p ulong to bool |
| 571 | ch = ulong get ojob p |
| 572 | ret or eq ch 32 eq ch 9 |
| 573 | end |
| 574 | |
| 575 | note split ojob[s .. e) into tokens 1.. (otb start, otl length); otc = 1 + tokens; exit 2 over 63 |
| 576 | fn ojtok s ulong e ulong to void |
| 577 | c = ulong 1 |
| 578 | p = s |
| 579 | while lt p e bound 65537 |
| 580 | ch = ulong get ojob p |
| 581 | if or eq ch 32 eq ch 9 |
| 582 | p = add p 1 |
| 583 | else |
| 584 | q = p |
| 585 | r = p |
| 586 | if eq ch 34 |
| 587 | q = add p 1 |
| 588 | r = q |
| 589 | while and lt r e ne ulong get ojob r 34 bound 65537 |
| 590 | r = add r 1 |
| 591 | end |
| 592 | p = add r 1 |
| 593 | else |
| 594 | while and lt r e not ojsep r bound 65537 |
| 595 | r = add r 1 |
| 596 | end |
| 597 | p = r |
| 598 | end |
| 599 | if ge c 64 |
| 600 | exit 2 |
| 601 | end |
| 602 | put otb c q |
| 603 | put otl c sub r q |
| 604 | c = add c 1 |
| 605 | end |
| 606 | end |
| 607 | put otc 0 c |
| 608 | end |
| 609 | |
| 610 | note read \OLLM\JOB.TXT into ojob; on a missing or over-long file print `OLLM efi JOB.TXT?`, wait, exit 2 |
| 611 | fn ojread to void |
| 612 | opath 0 |
| 613 | sz = efi 12 oefa 0 0 opn 0 13 |
| 614 | bad = oeerr sz |
| 615 | if not bad |
| 616 | if ge sz OJCAP |
| 617 | bad = true |
| 618 | oeclose |
| 619 | end |
| 620 | end |
| 621 | if bad |
| 622 | oputw 7594869011017124943 |
| 623 | oputc 32 |
| 624 | oputw 4563369441009749834 |
| 625 | oputc 10 |
| 626 | n = get oon 0 |
| 627 | for k ulong n |
| 628 | put ocon k get oout k |
| 629 | end |
| 630 | t = efi 13 0 ocon 0 n |
| 631 | owait |
| 632 | exit 2 |
| 633 | end |
| 634 | p = ulong 0 |
| 635 | while lt p sz bound 70000 |
| 636 | r = efi 12 oefa 2 p ojob p sub sz p |
| 637 | if or oeerr r eq r 0 |
| 638 | exit 70 |
| 639 | end |
| 640 | p = add p r |
| 641 | end |
| 642 | if ne p sz |
| 643 | exit 70 |
| 644 | end |
| 645 | oeclose |
| 646 | put ojn 0 p |
| 647 | end |
| 648 | |
| 649 | note identity byte: c itself when 32..126, else ? |
| 650 | fn oidp c ulong to void |
| 651 | if and ge c 32 le c 126 |
| 652 | oputc c |
| 653 | else |
| 654 | oputc 63 |
| 655 | end |
| 656 | end |
| 657 | |
| 658 | note CPUID leaf l into oidc (efi 14 sub 0); true when efi 14 answered |
| 659 | fn oidq l ulong to bool |
| 660 | r = efi 14 shl l 16 oidc 0 16 |
| 661 | ret eq r 16 |
| 662 | end |
| 663 | |
| 664 | note the little-endian u32 at oidc[k] |
| 665 | fn oidu k ulong to ulong |
| 666 | v = ulong 0 |
| 667 | for i ulong 4 |
| 668 | v = or v shl ulong get oidc add k i mul i 8 |
| 669 | end |
| 670 | ret v |
| 671 | end |
| 672 | |
| 673 | note true when brand byte i is padding (32 or 0); and/or evaluate both sides, so the trim loops in |
| 674 | note oidcpu test the index in the while and the byte inside the body: oidb[48] is never read |
| 675 | fn oidbl i ulong to bool |
| 676 | v = ulong get oidb i |
| 677 | ret or eq v 32 eq v 0 |
| 678 | end |
| 679 | |
| 680 | note the CPUID brand string (leaves 0x80000002..4) without leading or trailing spaces and NULs, or - |
| 681 | fn oidcpu to void |
| 682 | ok = oidq 2147483648 |
| 683 | if ok |
| 684 | ok = ge oidu 0 2147483652 |
| 685 | end |
| 686 | if not ok |
| 687 | oputc 45 |
| 688 | ret |
| 689 | end |
| 690 | for j ulong 3 |
| 691 | ok = oidq add 2147483650 j |
| 692 | if not ok |
| 693 | oputc 45 |
| 694 | ret |
| 695 | end |
| 696 | for k ulong 16 |
| 697 | put oidb add mul j 16 k get oidc k |
| 698 | end |
| 699 | end |
| 700 | s = ulong 0 |
| 701 | while lt s 48 bound 48 |
| 702 | if not oidbl s |
| 703 | break |
| 704 | end |
| 705 | s = add s 1 |
| 706 | end |
| 707 | e = ulong 48 |
| 708 | while gt e s bound 48 |
| 709 | if not oidbl sub e 1 |
| 710 | break |
| 711 | end |
| 712 | e = sub e 1 |
| 713 | end |
| 714 | if eq e s |
| 715 | oputc 45 |
| 716 | end |
| 717 | for i ulong sub e s |
| 718 | oidp ulong get oidb add s i |
| 719 | end |
| 720 | end |
| 721 | |
| 722 | note SystemTable FirmwareVendor, one byte per UCS-2 code unit (? outside 32..126), or - |
| 723 | fn oidfw to void |
| 724 | r = efi 14 1 oidv 0 512 |
| 725 | if or oeerr r eq r 0 |
| 726 | oputc 45 |
| 727 | ret |
| 728 | end |
| 729 | for k ulong div r 2 |
| 730 | oidp or ulong get oidv mul k 2 shl ulong get oidv add mul k 2 1 8 |
| 731 | end |
| 732 | end |
| 733 | |
| 734 | note SystemTable FirmwareRevision as 8 lowercase hex digits, or - |
| 735 | fn oidrev to void |
| 736 | r = efi 14 2 oidc 0 0 |
| 737 | if oeerr r |
| 738 | oputc 45 |
| 739 | ret |
| 740 | end |
| 741 | for i ulong 8 |
| 742 | d = and shr r mul sub 7 i 4 15 |
| 743 | if lt d 10 |
| 744 | oputc add 48 d |
| 745 | else |
| 746 | oputc add 87 d |
| 747 | end |
| 748 | end |
| 749 | end |
| 750 | |
| 751 | note true when oids[q] and oids[q+1] are both 0 (the end of a structure's strings); callers keep q+1 < t |
| 752 | fn oidz q ulong to bool |
| 753 | ret and eq ulong get oids q 0 eq ulong get oids add q 1 0 |
| 754 | end |
| 755 | |
| 756 | note SMBIOS string number n of the structure at p (table length t), or - when n is 0, when the |
| 757 | note structure's string set ends first (a string never starts with 0: that 0 ends the set), or when |
| 758 | note the string's NUL lies at or past t. Every read is below t, so the walk never leaves the structure. |
| 759 | fn oidstr p ulong n ulong t ulong to void |
| 760 | if eq n 0 |
| 761 | oputc 45 |
| 762 | ret |
| 763 | end |
| 764 | q = add p ulong get oids add p 1 |
| 765 | c = ulong 1 |
| 766 | while lt q t bound 65536 |
| 767 | if eq ulong get oids q 0 |
| 768 | oputc 45 |
| 769 | ret |
| 770 | end |
| 771 | if eq c n |
| 772 | e = q |
| 773 | while lt e t bound 65536 |
| 774 | if eq ulong get oids e 0 |
| 775 | break |
| 776 | end |
| 777 | e = add e 1 |
| 778 | end |
| 779 | if ge e t |
| 780 | oputc 45 |
| 781 | ret |
| 782 | end |
| 783 | while lt q e bound 65536 |
| 784 | oidp ulong get oids q |
| 785 | q = add q 1 |
| 786 | end |
| 787 | ret |
| 788 | end |
| 789 | while lt q t bound 65536 |
| 790 | if eq ulong get oids q 0 |
| 791 | break |
| 792 | end |
| 793 | q = add q 1 |
| 794 | end |
| 795 | q = add q 1 |
| 796 | c = add c 1 |
| 797 | end |
| 798 | oputc 45 |
| 799 | end |
| 800 | |
| 801 | note field i (0 Manufacturer, 1 Product Name, 2 Version) of the type 1 structure at p, length ln; |
| 802 | note - when the field lies outside the formatted area or at or past t |
| 803 | fn oidf p ulong ln ulong i ulong t ulong to void |
| 804 | k = add add p 4 i |
| 805 | if and lt add 4 i ln lt k t |
| 806 | oidstr p ulong get oids k t |
| 807 | else |
| 808 | oputc 45 |
| 809 | end |
| 810 | end |
| 811 | |
| 812 | note SMBIOS type 1 Manufacturer/Product Name/Version, each - when missing; the serial number (offset |
| 813 | note 7) and the UUID (8..23) are never printed |
| 814 | fn oidsm to void |
| 815 | t = efi 14 3 oids 0 65536 |
| 816 | p = ulong 0 |
| 817 | if oeerr t |
| 818 | t = ulong 0 |
| 819 | end |
| 820 | while lt add p 4 t bound 65537 |
| 821 | ty = ulong get oids p |
| 822 | ln = ulong get oids add p 1 |
| 823 | if eq ty 1 |
| 824 | oidf p ln 0 t |
| 825 | oputc 47 |
| 826 | oidf p ln 1 t |
| 827 | oputc 47 |
| 828 | oidf p ln 2 t |
| 829 | ret |
| 830 | end |
| 831 | if or eq ty 127 lt ln 4 |
| 832 | break |
| 833 | end |
| 834 | q = add p ln |
| 835 | while lt add q 1 t bound 65536 |
| 836 | if oidz q |
| 837 | break |
| 838 | end |
| 839 | q = add q 1 |
| 840 | end |
| 841 | p = add q 2 |
| 842 | end |
| 843 | oputc 45 |
| 844 | oputc 47 |
| 845 | oputc 45 |
| 846 | oputc 47 |
| 847 | oputc 45 |
| 848 | end |
| 849 | |
| 850 | note the identity line: ID cpu=... fw=... fwrev=... smbios=.../.../... (ID, not M: mathck prints M e/M l) |
| 851 | fn oident to void |
| 852 | oputc 73 |
| 853 | oputc 68 |
| 854 | oputc 32 |
| 855 | oputc 99 |
| 856 | oputc 112 |
| 857 | oputc 117 |
| 858 | oputc 61 |
| 859 | oidcpu |
| 860 | oputc 32 |
| 861 | oputc 102 |
| 862 | oputc 119 |
| 863 | oputc 61 |
| 864 | oidfw |
| 865 | oputc 32 |
| 866 | oputc 102 |
| 867 | oputc 119 |
| 868 | oputc 114 |
| 869 | oputc 101 |
| 870 | oputc 118 |
| 871 | oputc 61 |
| 872 | oidrev |
| 873 | oputc 32 |
| 874 | oputc 115 |
| 875 | oputc 109 |
| 876 | oputc 98 |
| 877 | oputc 105 |
| 878 | oputc 111 |
| 879 | oputc 115 |
| 880 | oputc 61 |
| 881 | oidsm |
| 882 | oputc 10 |
| 883 | end |
| 884 | |
| 885 | fn main to int |
| 886 | ojread |
| 887 | opath 1 |
| 888 | r = efi 12 oefa 1 0 opn 0 13 |
| 889 | if oeerr r |
| 890 | exit 70 |
| 891 | end |
| 892 | oeclose |
| 893 | put oop 0 0 |
| 894 | oputw 7594869011017124943 |
| 895 | oputc 32 |
| 896 | oputu get ojn 0 |
| 897 | oputc 10 |
| 898 | oident |
| 899 | oflush |
| 900 | t0 = oms |
| 901 | nj = ulong 0 |
| 902 | n = get ojn 0 |
| 903 | s = ulong 0 |
| 904 | while lt s n bound 65537 |
| 905 | e = s |
| 906 | while and lt e n ne ulong get ojob e 10 bound 65537 |
| 907 | e = add e 1 |
| 908 | end |
| 909 | lend = e |
| 910 | if gt lend s |
| 911 | if eq ulong get ojob sub lend 1 13 |
| 912 | lend = sub lend 1 |
| 913 | end |
| 914 | end |
| 915 | if gt lend s |
| 916 | if ne ulong get ojob s 35 |
| 917 | oputc 62 |
| 918 | oputc 32 |
| 919 | for k ulong sub lend s |
| 920 | oputc ulong get ojob add s k |
| 921 | end |
| 922 | oputc 10 |
| 923 | oflush |
| 924 | ojtok s lend |
| 925 | if ge oargc 2 |
| 926 | t1 = oms |
| 927 | if oisask |
| 928 | oask |
| 929 | else |
| 930 | rc = ocmd |
| 931 | end |
| 932 | oflush |
| 933 | if ne get olc 0 10 |
| 934 | oputc 10 |
| 935 | end |
| 936 | oputc 74 |
| 937 | oputc 32 |
| 938 | oputu sub oms t1 |
| 939 | oputc 10 |
| 940 | oflush |
| 941 | nj = add nj 1 |
| 942 | end |
| 943 | end |
| 944 | end |
| 945 | s = add e 1 |
| 946 | end |
| 947 | oputw 5642803763645008975 |
| 948 | oputc 69 |
| 949 | oputc 32 |
| 950 | oputu nj |
| 951 | oputc 32 |
| 952 | oputu sub oms t0 |
| 953 | oputc 10 |
| 954 | oflush |
| 955 | owait |
| 956 | ret 0 |
| 957 | end |
| 958 | |
| 959 | note v1 positioned read (CONTRACT-V1 section 3), as lio.om: up to n bytes of the file named by |
| 960 | note argument ai, from byte pos, into opw[off .. off + n); opened and closed on every call (efi 12 |
| 961 | note holds one open file). Returns n, fewer only when the file ends first, 0 at or after its end. |
| 962 | fn oprd ai ulong pos ulong off ulong n ulong to ulong |
| 963 | pl = oargp ai |
| 964 | sz = efi 12 oefa 0 0 oarg 0 pl |
| 965 | if oeerr sz |
| 966 | exit 70 |
| 967 | end |
| 968 | m = ulong 0 |
| 969 | if lt pos sz |
| 970 | m = sub sz pos |
| 971 | if gt m n |
| 972 | m = n |
| 973 | end |
| 974 | end |
| 975 | p = ulong 0 |
| 976 | for o ulong 3 |
| 977 | while lt p m bound 999999 |
| 978 | r = efi 12 oefa 2 add pos p opw add off p sub m p |
| 979 | if or oeerr r eq r 0 |
| 980 | exit 70 |
| 981 | end |
| 982 | p = add p r |
| 983 | end |
| 984 | end |
| 985 | oeclose |
| 986 | ret m |
| 987 | end |
| 988 | |
| 989 | note v1 (CONTRACT-V1 section 7): write obm[0 .. n) (bpe.om) to the path in argument ai, in place |
| 990 | fn obmsave ai ulong n ulong to void |
| 991 | pl = oargp ai |
| 992 | r = efi 12 oefa 1 0 oarg 0 pl |
| 993 | if oeerr r |
| 994 | exit 70 |
| 995 | end |
| 996 | w = efi 12 oefa 3 0 obm 0 n |
| 997 | if ne w n |
| 998 | exit 70 |
| 999 | end |
| 1000 | oeclose |
| 1001 | end |