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 / native / omega / allen / courier.om

261 lines · 3836 bytes Raw Blame History
1note Pure courier datagrams. Q session, current seq, last LINE, head, count.
2global Q ulong 8
3global N ulong 8
4global Queue uchar 2560
5global Qlens ulong 8
6global Jbuf uchar 4096
7global Jhave uchar 5
8global J ulong 3
9text Keys "ALLEN-COURIER v=1 run= kind= seq= part= bytes="
10text Kinds "JOBLINEGOTACKHELLOHI"
11fn keyread off ulong count ulong to void
12for i ulong count
13expect get Keys add off i
14end
15end
16fn keyemit off ulong count ulong to void
17for i ulong count
18emitb get Keys add off i
19end
20end
21fn kindoff k ulong to ulong
22if eq k 1
23ret 0
24end
25if eq k 2
26ret 3
27end
28if eq k 3
29ret 7
30end
31if eq k 4
32ret 10
33end
34if eq k 5
35ret 13
36end
37ret 18
38end
39fn kindlen k ulong to ulong
40if eq k 2
41ret 4
42end
43if eq k 5
44ret 5
45end
46if eq k 6
47ret 2
48end
49ret 3
50end
51fn qbegin run ulong seq ulong to void
52for i ulong 8
53put Q i 0
54end
55put Q 0 run
56put Q 1 seq
57for i ulong 5
58put Jhave i 0
59end
60for i ulong 3
61put J i 0
62end
63end
64note Serializer takes body In/Inlen; Outb/Outlen are published only on success.
65fn packet k ulong seq ulong part ulong total ulong bytes ulong to bool
66if or lt k 1 gt k 6
67ret false
68end
69if gt get Inlen 0 1000
70ret false
71end
72outreset
73keyemit 0 22
74for i ulong 16
75d = and shr get Q 0 mul sub 15 i 4 15
76emitb get Digits d
77end
78keyemit 22 6
79off = kindoff k
80for i ulong kindlen k
81emitb get Kinds add off i
82end
83keyemit 28 5
84emitn seq
85keyemit 33 6
86emitn part
87emitb 47
88emitn total
89keyemit 39 7
90emitn bytes
91emitb 10
92for i ulong get Inlen 0
93emitb get In i
94end
95ret eq get Err 0 0
96end
97fn pkparse to bool
98if or gt get Inlen 0 1200 lt get Inlen 0 65
99ret false
100end
101put P 0 0
102put P 2 0
103keyread 0 22
104run = ulong 0
105for i ulong 16
106p = get P 0
107c = get In p
108d = ulong 16
109if isdigit c
110d = sub ulong c 48
111else
112if and ge c 97 le c 102
113d = sub ulong c 87
114end
115end
116if ge d 16
117ret false
118end
119run = or shl run 4 d
120put P 0 add p 1
121end
122if ne run get Q 0
123ret false
124end
125keyread 22 6
126kind = ulong 0
127for k ulong 6
128at = get P 0
129off = kindoff add k 1
130size = kindlen add k 1
131ok = true
132for i ulong size
133if not ineq add at i get Kinds add off i
134ok = false
135end
136end
137if and ok ineq add at size 32
138kind = add k 1
139end
140end
141if eq kind 0
142ret false
143end
144put N 0 kind
145put P 0 add get P 0 kindlen kind
146keyread 28 5
147number
148put N 1 get P 1
149keyread 33 6
150number
151put N 2 get P 1
152expect 47
153number
154put N 3 get P 1
155keyread 39 7
156number
157put N 4 get P 1
158expect 10
159put N 5 get P 0
160put N 6 sub get Inlen 0 get P 0
161ret eq get P 2 0
162end
163fn jobtake to ulong
164note n via N4
165note part via N2
166note total via N3
167if or eq get N 4 0 gt get N 4 4096
168ret 0
169end
170if ne get N 3 div add get N 4 999 1000
171ret 0
172end
173if or eq get N 2 0 gt get N 2 get N 3
174ret 0
175end
176want = ulong 1000
177if eq get N 2 get N 3
178want = sub get N 4 mul sub get N 3 1 1000
179end
180if ne want get N 6
181ret 0
182end
183if ne get J 0 0
184if or ne get J 0 get N 4 ne get J 1 get N 3
185ret 0
186end
187end
188slot = sub get N 2 1
189off = mul slot 1000
190if ne get Jhave slot 0
191for i ulong want
192if ne get Jbuf add off i get In add get N 5 i
193ret 0
194end
195end
196ret 2
197end
198for i ulong want
199put Jbuf add off i get In add get N 5 i
200end
201put Jhave slot 1
202put J 0 get N 4
203put J 1 get N 3
204put J 2 add get J 2 1
205ret 1
206end
207note Return0 refused,1 accepted,2 duplicate requiring GOT/ACK again.
208fn qreceive to ulong
209if not pkparse
210ret 0
211end
212if ne get N 1 get Q 1
213ret 0
214end
215kind = get N 0
216if eq kind 1
217ret jobtake
218end
219if ne kind 2
220if ne get N 6 0
221ret 0
222end
223ret 1
224end
225note part via N2
226if eq get N 2 0
227ret 0
228end
229if le get N 2 get Q 2
230ret 2
231end
232if or ne get N 2 add get Q 2 1 eq get Q 4 8
233ret 0
234end
235n = get N 6
236if or eq n 0 gt n 319
237ret 0
238end
239slot = rem add get Q 3 get Q 4 8
240for i ulong n
241put Queue add mul slot 320 i get In add get N 5 i
242end
243put Qlens slot n
244put Q 4 add get Q 4 1
245put Q 2 get N 2
246ret 1
247end
248fn qtake to bool
249if eq get Q 4 0
250ret false
251end
252slot = get Q 3
253n = get Qlens slot
254for i ulong n
255put In i get Queue add mul slot 320 i
256end
257put Inlen 0 n
258put Q 3 rem add slot 1 8
259put Q 4 sub get Q 4 1
260ret true
261end