interplane.Get Omega
Read in your language

omega-helix

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

omega-helix / native / eio.om

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