interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / evidence / allen-omega-L694 / L725 / red3.om

991 lines · 15275 bytes Raw Blame History
1note L694 fixed-buffer utilities. No platform effects in product functions.
2global In uchar 8192
3global Inlen ulong 1
4global Outb uchar 8192
5global Outlen ulong 1
6global Err ulong 1
7text Digits "0123456789abcdef"
8fn emitb c uchar to void
9n = get Outlen 0
10if ge n len Outb
11put Err 0 1
12else
13put Outb n c
14put Outlen 0 add n 1
15end
16end
17fn emitn v ulong to void
18d = new uchar 20 0
19n = ulong 0
20x = v
21put d n uchar add rem x 10 48
22n = add n 1
23x = div x 10
24while gt x 0
25put d n uchar add rem x 10 48
26n = add n 1
27x = div x 10
28end
29while gt n 0
30n = sub n 1
31emitb get d n
32end
33end
34fn outreset to void
35put Outlen 0 0
36put Err 0 0
37end
38fn ineq at ulong c uchar to bool
39if ge at get Inlen 0
40ret false
41end
42ret eq get In at c
43end
44fn isdigit c uchar to bool
45ret and ge c 48 le c 57
46end
47note Parser cursor P0, number P1, error P2. Never wraps a u32.
48global P ulong 3
49fn number to void
50v = ulong 0
51n = ulong 0
52p = get P 0
53while lt p get Inlen 0
54c = get In p
55if not isdigit c
56put P 0 p
57put P 1 v
58if eq n 0
59put P 2 1
60end
61ret
62end
63if or ge n 10 gt v 429496729
64put P 2 1
65ret
66end
67v = add mul v 10 sub ulong c 48
68if gt v 4294967295
69put P 2 1
70ret
71end
72n = add n 1
73p = add p 1
74end
75put P 0 p
76put P 1 v
77if eq n 0
78put P 2 1
79end
80end
81fn expect c uchar to void
82p = get P 0
83if not ineq p c
84put P 2 1
85else
86put P 0 add p 1
87end
88end
89fn crc off ulong count ulong to uint
90c = uint 4294967295
91for i ulong count
92c = xor c uint get In add off i
93for k ulong 8
94if ne and c 1 0
95c = xor shr c 1 3988292384
96else
97c = shr c 1
98end
99end
100end
101ret not c
102end
103note R: seq, active, kind (1 chat 2 code 3 more), asked, heard, slow,
104note code-visible, prompt length, answer length, history count, session.
105global R ulong 16
106global Prompt uchar 160
107global Answer uchar 160
108global Hist uchar 5120
109global Hlen ulong 32
110text Ack "I need to code that. Let me send it off to the Spark."
111text Ackmore "Let me take that change to the Spark."
112fn textok to bool
113n = get Inlen 0
114if or eq n 0 gt n 159
115ret false
116end
117for i ulong n
118c = get In i
119if or lt c 32 gt c 126
120ret false
121end
122end
123ret true
124end
125fn histadd which ulong to void
126n = get R 9
127if eq n 32
128for i ulong 4960
129put Hist i get Hist add i 160
130end
131for i ulong 31
132put Hlen i get Hlen add i 1
133end
134n = 31
135end
136size = get R add which 7
137for i ulong size
138if eq which 0
139put Hist add mul n 160 i get Prompt i
140else
141put Hist add mul n 160 i get Answer i
142end
143end
144put Hlen n size
145put R 9 add n 1
146end
147fn start kind ulong now ulong to bool
148if or ne get R 1 0 ge get R 0 4294967295
149ret false
150end
151if or lt kind 1 gt kind 3
152ret false
153end
154if and eq kind 3 eq get R 6 0
155ret false
156end
157if not textok
158ret false
159end
160for i ulong get Inlen 0
161put Prompt i get In i
162end
163put R 7 get Inlen 0
164put R 0 add get R 0 1
165put R 1 1
166put R 2 kind
167put R 3 now
168put R 4 now
169put R 5 0
170put R 8 0
171put R 11 0
172put R 13 0
173if eq kind 2
174for i ulong len Ack
175put Answer i get Ack i
176end
177put R 8 len Ack
178end
179if eq kind 3
180for i ulong len Ackmore
181put Answer i get Ackmore i
182end
183put R 8 len Ackmore
184end
185histadd 0
186ret true
187end
188fn answer seq ulong now ulong to bool
189if or eq get R 1 0 ne seq get R 0
190ret false
191end
192if or lt now get R 4 not textok
193ret false
194end
195for i ulong get Inlen 0
196put Answer i get In i
197end
198put R 8 get Inlen 0
199put R 4 now
200put R 1 0
201histadd 1
202ret true
203end
204fn cancel to void
205put R 1 0
206end
207fn heard seq ulong now ulong to bool
208if or eq get R 1 0 ne seq get R 0
209ret false
210end
211if lt now get R 4
212ret false
213end
214put R 4 now
215ret true
216end
217fn tick now ulong to ulong
218if or eq get R 1 0 lt now get R 4
219ret 0
220end
221if ge sub now get R 4 30000
222cancel
223ret 2
224end
225if and eq get R 5 0 ge sub now get R 3 20000
226put R 5 1
227ret 1
228end
229ret 0
230end
231fn reset to void
232for i ulong 9
233put R add i 1 0
234end
235end
236note Restore one externally decoded transcript line. No live job or ID reuse.
237fn restore to bool
238if or ne get R 1 0 not textok
239ret false
240end
241for i ulong get Inlen 0
242put Answer i get In i
243end
244put R 8 get Inlen 0
245histadd 1
246ret true
247end
248note CODE protocol: C seq, parts, bytes, crc, got. D parsed header.
249global C ulong 8
250global D ulong 8
251global Code uchar 32769
252global Have uchar 256
253global Piece uchar 128
254global Lang uchar 16
255global Newlang uchar 16
256fn codebeg seq ulong to void
257for i ulong 8
258put C i 0
259end
260put C 0 seq
261for i ulong 256
262put Have i 0
263end
264put Code 0 0
265end
266fn decfield slot ulong sep uchar to void
267number
268put D slot get P 1
269expect sep
270end
271fn hexread to void
272v = ulong 0
273for i ulong 8
274p = get P 0
275if ge p get Inlen 0
276put P 2 1
277ret
278end
279c = get In p
280d = ulong 16
281if isdigit c
282d = sub ulong c 48
283else
284if and ge c 97 le c 102
285d = sub ulong c 87
286end
287end
288if ge d 16
289put P 2 1
290ret
291end
292v = add mul v 16 d
293put P 0 add p 1
294end
295put D 4 v
296expect 32
297end
298fn codehead to bool
299put P 0 0
300put P 2 0
301expect 67
302expect 79
303expect 68
304expect 69
305expect 32
306decfield 0 32
307decfield 1 47
308decfield 2 32
309decfield 3 32
310hexread
311if ne get P 2 0
312ret false
313end
314if or ne get D 0 get C 0 eq get D 3 0
315ret false
316end
317if gt get D 3 32768
318ret false
319end
320if ne get D 2 div add get D 3 127 128
321ret false
322end
323if or lt get D 1 1 gt get D 1 get D 2
324ret false
325end
326if ne get C 1 0
327if or ne get C 1 get D 2 ne get C 2 get D 3
328ret false
329end
330if ne get C 3 get D 4
331ret false
332end
333end
334ret true
335end
336fn langread to bool
337for i ulong 16
338put Newlang i 0
339end
340n = ulong 0
341p = get P 0
342while lt p get Inlen 0
343c = get In p
344if eq c 32
345if eq n 0
346ret false
347end
348put P 0 add p 1
349put D 5 n
350ret true
351end
352ok = or and ge c 97 le c 122 isdigit c
353ok = or ok or eq c 43 eq c 35
354ok = or ok or eq c 46 or eq c 95 eq c 45
355if or not ok ge n 15
356ret false
357end
358put Newlang n c
359p = add p 1
360n = add n 1
361end
362ret false
363end
364fn pieceread to ulong
365p = get P 0
366n = ulong 0
367while lt p get Inlen 0
368c = get In p
369p = add p 1
370if eq c 92
371if ge p get Inlen 0
372ret 129
373end
374c = get In p
375p = add p 1
376if eq c 110
377c = 10
378else
379if ne c 92
380ret 129
381end
382end
383else
384if or lt c 32 gt c 126
385ret 129
386end
387end
388if ge n 128
389ret 129
390end
391put Piece n c
392n = add n 1
393end
394ret n
395end
396fn codetake to bool
397if gt get Inlen 0 320
398ret false
399end
400if not codehead
401ret false
402end
403if not langread
404ret false
405end
406n = pieceread
407want = ulong 128
408if eq get D 1 get D 2
409want = sub get D 3 mul sub get D 2 1 128
410end
411if ne n want
412ret false
413end
414slot = sub get D 1 1
415off = mul slot 128
416if ne get C 1 0
417for i ulong 16
418if ne get Lang i get Newlang i
419ret false
420end
421end
422end
423if ne get Have slot 0
424for i ulong n
425if ne get Code add off i get Piece i
426ret false
427end
428end
429ret true
430end
431put C 1 get D 2
432put C 2 get D 3
433put C 3 get D 4
434for i ulong 16
435put Lang i get Newlang i
436end
437for i ulong n
438put Code add off i get Piece i
439end
440put Have slot 1
441put C 4 add get C 4 1
442ret true
443end
444fn codecrc to uint
445c = uint 4294967295
446for i ulong get C 2
447c = xor c uint get Code i
448for k ulong 8
449if ne and c 1 0
450c = xor shr c 1 3988292384
451else
452c = shr c 1
453end
454end
455end
456ret not c
457end
458fn codestat to ulong
459if eq get C 1 0
460ret 0
461end
462if lt get C 4 get C 1
463ret 1
464end
465if ne ulong codecrc get C 3
466ret 3
467end
468lines = ulong 0
469for i ulong get C 2
470c = get Code i
471if eq c 0
472ret 3
473end
474if eq c 10
475lines = add lines 1
476end
477end
478if ne get Code sub get C 2 1 10
479lines = add lines 1
480end
481if gt lines 800
482ret 3
483end
484put Code get C 2 0
485ret 2
486end
487fn missing to ulong
488if eq get C 1 0
489ret 1
490end
491for i ulong get C 1
492if eq get Have i 0
493ret add i 1
494end
495end
496ret 0
497end
498note Display admission is distinct from a model's closing sentence.
499fn codeshow seq ulong to bool
500if eq get R 1 0
501ret false
502end
503if or ne seq get R 0 ne seq get C 0
504ret false
505end
506if ne codestat 2
507ret false
508end
509put R 6 1
510ret true
511end
512note Pure courier datagrams. Q session, current seq, last LINE, head, count.
513global Q ulong 8
514global N ulong 8
515global Queue uchar 2560
516global Qlens ulong 8
517global Jbuf uchar 4096
518global Jhave uchar 5
519global J ulong 3
520text Keys "ALLEN-COURIER v=1 run= kind= seq= part= bytes="
521text Kinds "JOBLINEGOTACKHELLOHI"
522fn keyread off ulong count ulong to void
523for i ulong count
524expect get Keys add off i
525end
526end
527fn keyemit off ulong count ulong to void
528for i ulong count
529emitb get Keys add off i
530end
531end
532fn kindoff k ulong to ulong
533if eq k 1
534ret 0
535end
536if eq k 2
537ret 3
538end
539if eq k 3
540ret 7
541end
542if eq k 4
543ret 10
544end
545if eq k 5
546ret 13
547end
548ret 18
549end
550fn kindlen k ulong to ulong
551if eq k 2
552ret 4
553end
554if eq k 5
555ret 5
556end
557if eq k 6
558ret 2
559end
560ret 3
561end
562fn qbegin run ulong seq ulong to void
563for i ulong 8
564put Q i 0
565end
566put Q 0 run
567put Q 1 seq
568for i ulong 5
569put Jhave i 0
570end
571for i ulong 3
572put J i 0
573end
574end
575note Serializer takes body In/Inlen; Outb/Outlen are published only on success.
576fn packet k ulong seq ulong part ulong total ulong bytes ulong to bool
577if or lt k 1 gt k 6
578ret false
579end
580if gt get Inlen 0 1000
581ret false
582end
583outreset
584keyemit 0 22
585for i ulong 16
586d = and shr get Q 0 mul sub 15 i 4 15
587emitb get Digits d
588end
589keyemit 22 6
590off = kindoff k
591for i ulong kindlen k
592emitb get Kinds add off i
593end
594keyemit 28 5
595emitn seq
596keyemit 33 6
597emitn part
598emitb 47
599emitn total
600keyemit 39 7
601emitn bytes
602emitb 10
603for i ulong get Inlen 0
604emitb get In i
605end
606ret eq get Err 0 0
607end
608fn pkparse to bool
609if or gt get Inlen 0 1200 lt get Inlen 0 65
610ret false
611end
612put P 0 0
613put P 2 0
614keyread 0 22
615run = ulong 0
616for i ulong 16
617p = get P 0
618c = get In p
619d = ulong 16
620if isdigit c
621d = sub ulong c 48
622else
623if and ge c 97 le c 102
624d = sub ulong c 87
625end
626end
627if ge d 16
628ret false
629end
630run = or shl run 4 d
631put P 0 add p 1
632end
633if ne run get Q 0
634ret false
635end
636keyread 22 6
637kind = ulong 0
638for k ulong 6
639at = get P 0
640off = kindoff add k 1
641size = kindlen add k 1
642ok = true
643for i ulong size
644if not ineq add at i get Kinds add off i
645ok = false
646end
647end
648if and ok ineq add at size 32
649kind = add k 1
650end
651end
652if eq kind 0
653ret false
654end
655put N 0 kind
656put P 0 add get P 0 kindlen kind
657keyread 28 5
658number
659put N 1 get P 1
660keyread 33 6
661number
662put N 2 get P 1
663expect 47
664number
665put N 3 get P 1
666keyread 39 7
667number
668put N 4 get P 1
669expect 10
670put N 5 get P 0
671put N 6 sub get Inlen 0 get P 0
672ret eq get P 2 0
673end
674fn jobtake to ulong
675note n via N4
676note part via N2
677note total via N3
678if or eq get N 4 0 gt get N 4 4096
679ret 0
680end
681if ne get N 3 div add get N 4 999 1000
682ret 0
683end
684if or eq get N 2 0 gt get N 2 get N 3
685ret 0
686end
687want = ulong 1000
688if eq get N 2 get N 3
689want = sub get N 4 mul sub get N 3 1 1000
690end
691if ne want get N 6
692ret 0
693end
694if ne get J 0 0
695if or ne get J 0 get N 4 ne get J 1 get N 3
696ret 0
697end
698end
699slot = sub get N 2 1
700off = mul slot 1000
701if ne get Jhave slot 0
702for i ulong want
703if ne get Jbuf add off i get In add get N 5 i
704ret 0
705end
706end
707ret 2
708end
709for i ulong want
710put Jbuf add off i get In add get N 5 i
711end
712put Jhave slot 1
713put J 0 get N 4
714put J 1 get N 3
715put J 2 add get J 2 1
716ret 1
717end
718note Return0 refused,1 accepted,2 duplicate requiring GOT/ACK again.
719fn qreceive to ulong
720if not pkparse
721ret 0
722end
723if ne get N 1 get Q 1
724ret 0
725end
726kind = get N 0
727if eq kind 1
728ret jobtake
729end
730if ne kind 2
731if ne get N 6 0
732ret 0
733end
734ret 1
735end
736note part via N2
737if eq get N 2 0
738ret 0
739end
740if le get N 2 get Q 2
741ret 2
742end
743if or ne get N 2 add get Q 2 1 eq get Q 4 8
744ret 0
745end
746n = get N 6
747if or eq n 0 gt n 319
748ret 0
749end
750slot = rem add get Q 3 get Q 4 8
751for i ulong n
752put Queue add mul slot 320 i get In add get N 5 i
753end
754put Qlens slot n
755put Q 4 add get Q 4 1
756put Q 2 get N 2
757ret 1
758end
759fn qtake to bool
760if eq get Q 4 0
761ret false
762end
763slot = get Q 3
764n = get Qlens slot
765for i ulong n
766put In i get Queue add mul slot 320 i
767end
768put Inlen 0 n
769put Q 3 rem add slot 1 8
770put Q 4 sub get Q 4 1
771ret true
772end
773note L725 compilable behavioral stub, retained only in RED evidence.
774global T ulong 16
775global JobOut uchar 4096
776fn qstart run ulong now ulong to bool
777ret false
778end
779fn qready now ulong to bool
780ret false
781end
782fn qsubmit now ulong to bool
783ret false
784end
785fn qnext now ulong link bool to bool
786ret false
787end
788fn qsent now ulong ok bool to bool
789ret false
790end
791fn qincoming now ulong to ulong
792ret 0
793end
794fn qcancel to void
795end
796global Fails ulong 1
797global Checks ulong 1
798fn check ok bool id ulong to void
799put Checks 0 add get Checks 0 1
800outreset
801emitn id
802if ok
803emitb 32
804emitb 48
805else
806put Fails 0 add get Fails 0 1
807emitb 32
808emitb 49
809end
810emitb 10
811w = write 1 Outb 0 get Outlen 0
812end
813note Native courier lifecycle regression. Clock values are injected milliseconds.
814text Lineone "SAY 1 1/1 Model text."
815note check writes through Outb; preserve the actual pending datagram around logging.
816global SavedOut uchar 8192
817fn test ok bool to void
818n = get Outlen 0
819e = get Err 0
820for i ulong n
821put SavedOut i get Outb i
822end
823check ok add get Checks 0 1
824for i ulong n
825put Outb i get SavedOut i
826end
827put Outlen 0 n
828put Err 0 e
829end
830fn tcopy to void
831put Inlen 0 get Outlen 0
832for i ulong get Outlen 0
833put In i get Outb i
834end
835end
836fn control kind ulong seq ulong to void
837put Inlen 0 0
838b = packet kind seq 0 0 0
839tcopy
840end
841fn linepkt part ulong to void
842put Inlen 0 len Lineone
843for i ulong len Lineone
844put In i get Lineone i
845end
846b = packet 2 get Q 1 part 0 0
847tcopy
848end
849fn jobinput to void
850put Inlen 0 1001
851for i ulong 1001
852put In i 120
853end
854put In 999 10
855put In 1000 121
856end
857fn main to int
858test qstart 42 100
859test not qready 100
860test not qnext 100 false
861test eq get T 3 0
862test qnext 100 true
863test eq get T 10 5
864test not qnext 100 true
865test qsent 100 false
866test eq get T 3 0
867test qnext 101 true
868test qsent 101 true
869test eq get T 3 1
870test not qnext 2100 true
871test qnext 2101 true
872test qsent 2101 true
873control 6 0
874test eq qincoming 2102 1
875test qready 2102
876test not qnext 12100 true
877test qnext 12101 true
878test eq get T 10 5
879test qsent 12101 true
880test qready 32101
881test not qready 32102
882test qnext 32102 true
883test qsent 32102 true
884test not qnext 32101 true
885test eq get T 0 32102
886jobinput
887test qsubmit 32103
888test eq get Q 1 1
889test eq get JobOut 999 32
890test eq get JobOut 1000 121
891test not qsubmit 32103
892test qnext 32103 true
893test eq get T 10 1
894test eq get T 11 1
895tcopy
896test pkparse
897test eq get N 6 1000
898test eq get In add get N 5 999 32
899test qsent 32103 false
900test eq get T 9 1
901test qnext 32104 true
902test eq get T 11 1
903test qsent 32104 true
904test qnext 32104 true
905test eq get T 11 2
906tcopy
907test pkparse
908test eq get N 6 1
909test eq get In get N 5 121
910test qsent 32104 true
911test eq get T 9 0
912control 6 0
913test eq qincoming 32105 1
914test qready 32105
915test not qnext 34103 true
916test qnext 34104 true
917test eq get T 10 1
918test eq get T 11 1
919test qsent 34104 true
920test qnext 34104 true
921test eq get T 11 2
922test qsent 34104 true
923control 4 2
924test eq qincoming 34105 0
925test eq get T 6 0
926control 4 1
927test eq qincoming 34105 1
928test eq get T 6 1
929test not qnext 36104 true
930linepkt 1
931test eq qincoming 36105 1
932test eq get Q 4 1
933test eq get T 13 1
934test qnext 36105 true
935test eq get T 10 3
936test qsent 36105 false
937test eq get T 13 1
938linepkt 1
939test eq qincoming 36106 2
940test eq get Q 4 1
941test qnext 36106 true
942test eq get T 10 3
943test qsent 36106 true
944test eq get T 13 0
945test qtake
946test eq get Inlen 0 len Lineone
947test not qtake
948linepkt 2
949test eq qincoming 36107 1
950linepkt 3
951test eq qincoming 36107 0
952test eq get Q 2 2
953test eq get Q 4 1
954test qnext 36108 true
955test qsent 36108 true
956linepkt 3
957test eq qincoming 36109 1
958test eq get Q 2 3
959qcancel
960test eq get T 5 0
961linepkt 4
962test eq qincoming 36110 0
963jobinput
964test qsubmit 36111
965test eq get Q 1 2
966test eq get Q 4 0
967control 6 0
968test eq qincoming 36112 1
969control 6 0
970put In 22 49
971test eq qincoming 36113 0
972test eq get T 2 36112
973control 4 2
974test eq qincoming 36110 0
975test eq get T 6 0
976qcancel
977put Q 1 4294967295
978jobinput
979test not qsubmit 36114
980test eq get Q 1 4294967295
981test not qstart 0 36114
982test eq get Q 0 42
983test qstart 43 0
984put Inlen 0 4097
985test not qsubmit 0
986test eq get Q 1 0
987put Inlen 0 0
988test not qsubmit 0
989test not qsent 0 true
990ret int get Fails 0
991end