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 / red.om

834 lines · 12669 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 CODE protocol: C seq, parts, bytes, crc, got. D parsed header.
104global C ulong 8
105global D ulong 8
106global Code uchar 32769
107global Have uchar 256
108global Piece uchar 128
109global Lang uchar 16
110global Newlang uchar 16
111fn codebeg seq ulong to void
112for i ulong 8
113put C i 0
114end
115put C 0 seq
116for i ulong 256
117put Have i 0
118end
119put Code 0 0
120end
121fn decfield slot ulong sep uchar to void
122number
123put D slot get P 1
124expect sep
125end
126fn hexread to void
127v = ulong 0
128for i ulong 8
129p = get P 0
130if ge p get Inlen 0
131put P 2 1
132ret
133end
134c = get In p
135d = ulong 16
136if isdigit c
137d = sub ulong c 48
138else
139if and ge c 97 le c 102
140d = sub ulong c 87
141end
142end
143if ge d 16
144put P 2 1
145ret
146end
147v = add mul v 16 d
148put P 0 add p 1
149end
150put D 4 v
151expect 32
152end
153fn codehead to bool
154put P 0 0
155put P 2 0
156expect 67
157expect 79
158expect 68
159expect 69
160expect 32
161decfield 0 32
162decfield 1 47
163decfield 2 32
164decfield 3 32
165hexread
166if ne get P 2 0
167ret false
168end
169if or ne get D 0 get C 0 eq get D 3 0
170ret false
171end
172if gt get D 3 32768
173ret false
174end
175if ne get D 2 div add get D 3 127 128
176ret false
177end
178if or lt get D 1 1 gt get D 1 get D 2
179ret false
180end
181if ne get C 1 0
182if or ne get C 1 get D 2 ne get C 2 get D 3
183ret false
184end
185if ne get C 3 get D 4
186ret false
187end
188end
189ret true
190end
191fn langread to bool
192for i ulong 16
193put Newlang i 0
194end
195n = ulong 0
196p = get P 0
197while lt p get Inlen 0
198c = get In p
199if eq c 32
200if eq n 0
201ret false
202end
203put P 0 add p 1
204put D 5 n
205ret true
206end
207ok = or and ge c 97 le c 122 isdigit c
208ok = or ok or eq c 43 eq c 35
209ok = or ok or eq c 46 or eq c 95 eq c 45
210if or not ok ge n 15
211ret false
212end
213put Newlang n c
214p = add p 1
215n = add n 1
216end
217ret false
218end
219fn pieceread to ulong
220p = get P 0
221n = ulong 0
222while lt p get Inlen 0
223c = get In p
224p = add p 1
225if eq c 92
226if ge p get Inlen 0
227ret 129
228end
229c = get In p
230p = add p 1
231if eq c 110
232c = 10
233else
234if ne c 92
235ret 129
236end
237end
238else
239if or lt c 32 gt c 126
240ret 129
241end
242end
243if ge n 128
244ret 129
245end
246put Piece n c
247n = add n 1
248end
249ret n
250end
251fn codetake to bool
252if gt get Inlen 0 320
253ret false
254end
255if not codehead
256ret false
257end
258if not langread
259ret false
260end
261n = pieceread
262want = ulong 128
263if eq get D 1 get D 2
264want = sub get D 3 mul sub get D 2 1 128
265end
266if ne n want
267ret false
268end
269slot = sub get D 1 1
270off = mul slot 128
271if ne get C 1 0
272for i ulong 16
273if ne get Lang i get Newlang i
274ret false
275end
276end
277end
278if ne get Have slot 0
279for i ulong n
280if ne get Code add off i get Piece i
281ret false
282end
283end
284ret true
285end
286put C 1 get D 2
287put C 2 get D 3
288put C 3 get D 4
289for i ulong 16
290put Lang i get Newlang i
291end
292for i ulong n
293put Code add off i get Piece i
294end
295put Have slot 1
296put C 4 add get C 4 1
297ret true
298end
299fn codecrc to uint
300c = uint 4294967295
301for i ulong get C 2
302c = xor c uint get Code i
303for k ulong 8
304if ne and c 1 0
305c = xor shr c 1 3988292384
306else
307c = shr c 1
308end
309end
310end
311ret not c
312end
313fn codestat to ulong
314if eq get C 1 0
315ret 0
316end
317if lt get C 4 get C 1
318ret 1
319end
320if ne ulong codecrc get C 3
321ret 3
322end
323lines = ulong 0
324for i ulong get C 2
325c = get Code i
326if eq c 0
327ret 3
328end
329if eq c 10
330lines = add lines 1
331end
332end
333if ne get Code sub get C 2 1 10
334lines = add lines 1
335end
336if gt lines 800
337ret 3
338end
339put Code get C 2 0
340ret 2
341end
342fn missing to ulong
343if eq get C 1 0
344ret 1
345end
346for i ulong get C 1
347if eq get Have i 0
348ret add i 1
349end
350end
351ret 0
352end
353note Display admission is distinct from a model's closing sentence.
354fn codeshow seq ulong to bool
355if eq get R 1 0
356ret false
357end
358if or ne seq get R 0 ne seq get C 0
359ret false
360end
361if ne codestat 2
362ret false
363end
364put R 6 1
365ret true
366end
367note Pure courier datagrams. Q session, current seq, last LINE, head, count.
368global Q ulong 8
369global N ulong 8
370global Queue uchar 2560
371global Qlens ulong 8
372global Jbuf uchar 4096
373global Jhave uchar 5
374global J ulong 3
375text Keys "ALLEN-COURIER v=1 run= kind= seq= part= bytes="
376text Kinds "JOBLINEGOTACKHELLOHI"
377fn keyread off ulong count ulong to void
378for i ulong count
379expect get Keys add off i
380end
381end
382fn keyemit off ulong count ulong to void
383for i ulong count
384emitb get Keys add off i
385end
386end
387fn kindoff k ulong to ulong
388if eq k 1
389ret 0
390end
391if eq k 2
392ret 3
393end
394if eq k 3
395ret 7
396end
397if eq k 4
398ret 10
399end
400if eq k 5
401ret 13
402end
403ret 18
404end
405fn kindlen k ulong to ulong
406if eq k 2
407ret 4
408end
409if eq k 5
410ret 5
411end
412if eq k 6
413ret 2
414end
415ret 3
416end
417fn qbegin run ulong seq ulong to void
418for i ulong 8
419put Q i 0
420end
421put Q 0 run
422put Q 1 seq
423for i ulong 5
424put Jhave i 0
425end
426for i ulong 3
427put J i 0
428end
429end
430note Serializer takes body In/Inlen; Outb/Outlen are published only on success.
431fn packet k ulong seq ulong part ulong total ulong bytes ulong to bool
432if or lt k 1 gt k 6
433ret false
434end
435if gt get Inlen 0 1000
436ret false
437end
438outreset
439keyemit 0 22
440for i ulong 16
441d = and shr get Q 0 mul sub 15 i 4 15
442emitb get Digits d
443end
444keyemit 22 6
445off = kindoff k
446for i ulong kindlen k
447emitb get Kinds add off i
448end
449keyemit 28 5
450emitn seq
451keyemit 33 6
452emitn part
453emitb 47
454emitn total
455keyemit 39 7
456emitn bytes
457emitb 10
458for i ulong get Inlen 0
459emitb get In i
460end
461ret eq get Err 0 0
462end
463fn pkparse to bool
464if or gt get Inlen 0 1200 lt get Inlen 0 65
465ret false
466end
467put P 0 0
468put P 2 0
469keyread 0 22
470run = ulong 0
471for i ulong 16
472p = get P 0
473c = get In p
474d = ulong 16
475if isdigit c
476d = sub ulong c 48
477else
478if and ge c 97 le c 102
479d = sub ulong c 87
480end
481end
482if ge d 16
483ret false
484end
485run = or shl run 4 d
486put P 0 add p 1
487end
488if ne run get Q 0
489ret false
490end
491keyread 22 6
492kind = ulong 0
493for k ulong 6
494at = get P 0
495off = kindoff add k 1
496size = kindlen add k 1
497ok = true
498for i ulong size
499if not ineq add at i get Kinds add off i
500ok = false
501end
502end
503if and ok ineq add at size 32
504kind = add k 1
505end
506end
507if eq kind 0
508ret false
509end
510put N 0 kind
511put P 0 add get P 0 kindlen kind
512keyread 28 5
513number
514put N 1 get P 1
515keyread 33 6
516number
517put N 2 get P 1
518expect 47
519number
520put N 3 get P 1
521keyread 39 7
522number
523put N 4 get P 1
524expect 10
525put N 5 get P 0
526put N 6 sub get Inlen 0 get P 0
527ret eq get P 2 0
528end
529fn jobtake to ulong
530note n via N4
531note part via N2
532note total via N3
533if or eq get N 4 0 gt get N 4 4096
534ret 0
535end
536if ne get N 3 div add get N 4 999 1000
537ret 0
538end
539if or eq get N 2 0 gt get N 2 get N 3
540ret 0
541end
542want = ulong 1000
543if eq get N 2 get N 3
544want = sub get N 4 mul sub get N 3 1 1000
545end
546if ne want get N 6
547ret 0
548end
549if ne get J 0 0
550if or ne get J 0 get N 4 ne get J 1 get N 3
551ret 0
552end
553end
554slot = sub get N 2 1
555off = mul slot 1000
556if ne get Jhave slot 0
557for i ulong want
558if ne get Jbuf add off i get In add get N 5 i
559ret 0
560end
561end
562ret 2
563end
564for i ulong want
565put Jbuf add off i get In add get N 5 i
566end
567put Jhave slot 1
568put J 0 get N 4
569put J 1 get N 3
570put J 2 add get J 2 1
571ret 1
572end
573note Return0 refused,1 accepted,2 duplicate requiring GOT/ACK again.
574fn qreceive to ulong
575if not pkparse
576ret 0
577end
578if ne get N 1 get Q 1
579ret 0
580end
581kind = get N 0
582if eq kind 1
583ret jobtake
584end
585if ne kind 2
586if ne get N 6 0
587ret 0
588end
589ret 1
590end
591note part via N2
592if eq get N 2 0
593ret 0
594end
595if le get N 2 get Q 2
596ret 2
597end
598if or ne get N 2 add get Q 2 1 eq get Q 4 8
599ret 0
600end
601n = get N 6
602if or eq n 0 gt n 319
603ret 0
604end
605slot = rem add get Q 3 get Q 4 8
606for i ulong n
607put Queue add mul slot 320 i get In add get N 5 i
608end
609put Qlens slot n
610put Q 4 add get Q 4 1
611put Q 2 get N 2
612ret 1
613end
614fn qtake to bool
615if eq get Q 4 0
616ret false
617end
618slot = get Q 3
619n = get Qlens slot
620for i ulong n
621put In i get Queue add mul slot 320 i
622end
623put Inlen 0 n
624put Q 3 rem add slot 1 8
625put Q 4 sub get Q 4 1
626ret true
627end
628note L725 compilable behavioral stub, retained only in RED evidence.
629global T ulong 16
630global JobOut uchar 4096
631fn qstart run ulong now ulong to bool
632ret false
633end
634fn qready now ulong to bool
635ret false
636end
637fn qsubmit now ulong to bool
638ret false
639end
640fn qnext now ulong link bool to bool
641ret false
642end
643fn qsent now ulong ok bool to bool
644ret false
645end
646fn qincoming now ulong to ulong
647ret 0
648end
649fn qcancel to void
650end
651global Fails ulong 1
652global Checks ulong 1
653fn check ok bool id ulong to void
654put Checks 0 add get Checks 0 1
655outreset
656emitn id
657if ok
658emitb 32
659emitb 48
660else
661put Fails 0 add get Fails 0 1
662emitb 32
663emitb 49
664end
665emitb 10
666w = write 1 Outb 0 get Outlen 0
667end
668note Native courier lifecycle regression. Clock values are injected milliseconds.
669text Lineone "SAY 1 1/1 Model text."
670fn test ok bool to void
671check ok add get Checks 0 1
672end
673fn tcopy to void
674put Inlen 0 get Outlen 0
675for i ulong get Outlen 0
676put In i get Outb i
677end
678end
679fn control kind ulong seq ulong to void
680put Inlen 0 0
681b = packet kind seq 0 0 0
682tcopy
683end
684fn linepkt part ulong to void
685put Inlen 0 len Lineone
686for i ulong len Lineone
687put In i get Lineone i
688end
689b = packet 2 get Q 1 part 0 0
690tcopy
691end
692fn jobinput to void
693put Inlen 0 1001
694for i ulong 1001
695put In i 120
696end
697put In 999 10
698put In 1000 121
699end
700fn main to int
701test qstart 42 100
702test not qready 100
703test not qnext 100 false
704test eq get T 3 0
705test qnext 100 true
706test eq get T 10 5
707test not qnext 100 true
708test qsent 100 false
709test eq get T 3 0
710test qnext 101 true
711test qsent 101 true
712test eq get T 3 1
713test not qnext 2100 true
714test qnext 2101 true
715test qsent 2101 true
716control 6 0
717test eq qincoming 2102 1
718test qready 2102
719test not qnext 12100 true
720test qnext 12101 true
721test eq get T 10 5
722test qsent 12101 true
723test qready 32101
724test not qready 32102
725test qnext 32102 true
726test qsent 32102 true
727test not qnext 32101 true
728test eq get T 0 32102
729jobinput
730test qsubmit 32103
731test eq get Q 1 1
732test eq get JobOut 999 32
733test eq get JobOut 1000 121
734test not qsubmit 32103
735test qnext 32103 true
736test eq get T 10 1
737test eq get T 11 1
738tcopy
739test pkparse
740test eq get N 6 1000
741test eq get In add get N 5 999 32
742test qsent 32103 false
743test eq get T 9 1
744test qnext 32104 true
745test eq get T 11 1
746test qsent 32104 true
747test qnext 32104 true
748test eq get T 11 2
749tcopy
750test pkparse
751test eq get N 6 1
752test eq get In get N 5 121
753test qsent 32104 true
754test eq get T 9 0
755control 6 0
756test eq qincoming 32105 1
757test qready 32105
758test not qnext 34103 true
759test qnext 34104 true
760test eq get T 10 1
761test eq get T 11 1
762test qsent 34104 true
763test qnext 34104 true
764test eq get T 11 2
765test qsent 34104 true
766control 4 2
767test eq qincoming 34105 0
768test eq get T 6 0
769control 4 1
770test eq qincoming 34105 1
771test eq get T 6 1
772test not qnext 36104 true
773linepkt 1
774test eq qincoming 36105 1
775test eq get Q 4 1
776test eq get T 13 1
777test qnext 36105 true
778test eq get T 10 3
779test qsent 36105 false
780test eq get T 13 1
781linepkt 1
782test eq qincoming 36106 2
783test eq get Q 4 1
784test qnext 36106 true
785test eq get T 10 3
786test qsent 36106 true
787test eq get T 13 0
788test qtake
789test eq get Inlen 0 len Lineone
790test not qtake
791linepkt 2
792test eq qincoming 36107 1
793linepkt 3
794test eq qincoming 36107 0
795test eq get Q 2 2
796test eq get Q 4 1
797test qnext 36108 true
798test qsent 36108 true
799linepkt 3
800test eq qincoming 36109 1
801test eq get Q 2 3
802qcancel
803test eq get T 5 0
804linepkt 4
805test eq qincoming 36110 0
806jobinput
807test qsubmit 36111
808test eq get Q 1 2
809test eq get Q 4 0
810control 6 0
811test eq qincoming 36112 1
812control 6 0
813put In 22 49
814test eq qincoming 36113 0
815test eq get T 2 36112
816control 4 2
817test eq qincoming 36110 0
818test eq get T 6 0
819qcancel
820put Q 1 4294967295
821jobinput
822test not qsubmit 36114
823test eq get Q 1 4294967295
824test not qstart 0 36114
825test eq get Q 0 42
826test qstart 43 0
827put Inlen 0 4097
828test not qsubmit 0
829test eq get Q 1 0
830put Inlen 0 0
831test not qsubmit 0
832test not qsent 0 true
833ret int get Fails 0
834end