interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / gpu / driver / tests / sysinfo_cli.om

409 lines · 6363 bytes Raw Blame History
1note tests/sysinfo_cli.om: the command line of aien-dev/aienux PR #441 native/kernel/tools/ck_gsp_sysinfo_encode.c
2note over gsp/sysinfo.om, same stdout bytes and exit codes, so tests/sysinfo_diff.sh can cmp the two.
3note fields the 72 fields: "%-36s off=%3u size=%u"
4note encode IN OUT parse IN, echo "set %-36s off=%3u size=%u value=%#llx" per accepted line, then
5note "REFUSED: why" (exit 2) or write the 936 bytes to OUT and "RESULT OK OUT 936 bytes"
6note byidx OUT .om only: set all 72 fields through siseti with distinct non-zero bytes, print the
7note same values as "name 0x.." text (for the C tool to encode) and write the bytes
8note api .om only: the API refusals (siseti/sisetn/sitext), one line each
9note Anything else: usage on stderr, exit 1 (as the C tool). Host only; never touches a device.
10note Build: cat gsp/sysinfo.om tests/sysinfo_cli.om | omc
11text zitx "REFUSED: |cannot read |cannot write |RESULT OK | 936 bytes|set | off=| size=| value=|fields|encode|byidx|api|api | rc=| why=|nit|idx|fit|ok|rep|name|unk|big|bytes|Chipset|chipset|"
12text ziut "usage: ck_gsp_sysinfo_encode encode IN.txt OUT.bin | fields | selftest\n"
13global ziob uchar 65536
14global zipos ulong 1
15global zia uchar 64
16global zip1 uchar 4096
17global zip2 uchar 4096
18global zix uchar 1
19fn ziflush to void
20n = get zipos 0
21if gt n 0
22r = write 1 ziob 0 n
23if ne r long n
24exit 1
25end
26end
27put zipos 0 0
28end
29fn zich c uchar to void
30p = get zipos 0
31put ziob p c
32put zipos 0 add p 1
33if ge add p 1 65000
34ziflush
35end
36end
37note fragment k of zitx (fragments end at | 124)
38fn zifr k ulong to void
39w = ulong 0
40for i ulong len zitx
41c = get zitx i
42if eq c 124
43w = add w 1
44else
45if eq w k
46zich c
47end
48end
49end
50end
51fn zinl to void
52zich 10
53end
54fn zidec v ulong to void
55d = ulong 1
56while le d div v 10 bound 20
57d = mul d 10
58end
59while ne d 0 bound 20
60zich uchar add rem div v d 10 48
61d = div d 10
62end
63end
64fn zisdec v long to void
65if lt v 0
66zich 45
67zidec ulong sub 0 v
68ret
69end
70zidec ulong v
71end
72note %3u
73fn zipad3 v ulong to void
74if lt v 100
75zich 32
76end
77if lt v 10
78zich 32
79end
80zidec v
81end
82note %#llx (0 prints as 0)
83fn zihex v ulong to void
84if eq v 0
85zich 48
86ret
87end
88zich 48
89zich 120
90nd = ulong 0
91t = v
92while ne t 0 bound 17
93nd = add nd 1
94t = shr t 4
95end
96for i ulong nd
97d = and shr v mul sub sub nd i 1 4 15
98if lt d 10
99zich uchar add d 48
100else
101zich uchar add d 87
102end
103end
104end
105note %-36s of sinam
106fn zinam to void
107n = get sinl 0
108for i ulong n
109zich get sinam i
110end
111if lt n 36
112for j ulong sub 36 n
113zich 32
114end
115end
116end
117fn zipath which ulong n ulong to void
118for i ulong n
119if eq which 1
120zich get zip1 i
121else
122zich get zip2 i
123end
124end
125end
126note "name off=%3u size=%u" for field k (name already in sinam)
127fn zifield k ulong to void
128zinam
129zifr 6
130zipad3 get sioff k
131zifr 7
132zidec get sisz k
133end
134note argv[1] equals fragment k of zitx
135fn zimode n long k ulong to bool
136w = ulong 0
137j = ulong 0
138for i ulong len zitx
139c = get zitx i
140if eq c 124
141w = add w 1
142else
143if eq w k
144if ge j ulong n
145ret false
146end
147if ne get zia j c
148ret false
149end
150j = add j 1
151end
152end
153end
154ret eq j ulong n
155end
156fn ziusage to int
157ziflush
158r = write 2 ziut 0 len ziut
159ret 1
160end
161fn zifields to int
162sireset
163for k ulong SINF
164sinmk k
165zifield k
166zinl
167end
168ziflush
169ret 0
170end
171fn ziecho to void
172for i ulong get sinord 0
173k = get siord i
174sinmk k
175zifr 5
176zifield k
177zifr 8
178zihex get sival k
179zinl
180end
181end
182note siwb already holds the refusal text (siwhy is called before the echo, which reuses sinam)
183fn zirefuse to int
184zifr 0
185for i ulong get siwl 0
186zich get siwb i
187end
188zinl
189ziflush
190ret 2
191end
192fn zicant k ulong which ulong n ulong to int
193zifr 0
194zifr k
195zipath which n
196zinl
197ziflush
198ret 2
199end
200note write siout to the path in zip2[0..n); false when any step fails
201fn ziput n ulong to bool
202fd = fopen zip2 0 n 524865 438
203if lt fd 0
204ret false
205end
206w = write int fd siout 0 SISIZE
207c = fclose int fd
208ret and eq w long SISIZE eq c 0
209end
210fn zislurp n ulong to long
211fd = fopen zip1 0 n 524288 0
212if lt fd 0
213ret -1
214end
215t = ulong 0
216bad = false
217while lt t SITXMAX bound 70000
218r = read int fd sitxt t sub SITXMAX t
219if lt r 0
220bad = true
221break
222end
223if eq r 0
224break
225end
226t = add t ulong r
227end
228if and eq t SITXMAX not bad
229r = read int fd zix 0 1
230if lt r 0
231bad = true
232end
233if gt r 0
234t = add t 1
235end
236end
237c = fclose int fd
238if bad
239ret -1
240end
241ret long t
242end
243fn ziencode n1 ulong n2 ulong to int
244t = zislurp n1
245if lt t 0
246r = zicant 1 1 n1
247ret r
248end
249sireset
250e = sitext ulong t
251siwhy e
252ziecho
253if ne e SIEOK
254r = zirefuse
255ret r
256end
257siencode
258if not ziput n2
259r = zicant 2 2 n2
260ret r
261end
262zifr 3
263zipath 2 n2
264zifr 4
265zinl
266ziflush
267ret 0
268end
269fn zipat k ulong to ulong
270v = ulong 0
271for b ulong get sisz k
272x = add rem add mul k 8 b 251 1
273v = or v shl x mul b 8
274end
275ret v
276end
277fn zibyidx n2 ulong to int
278sireset
279for k ulong SINF
280v = zipat k
281e = siseti k v
282if ne e SIEOK
283siwhy e
284r = zirefuse
285ret r
286end
287for i ulong get sinl 0
288zich get sinam i
289end
290zich 32
291zihex v
292zinl
293end
294siencode
295if not ziput n2
296r = zicant 2 2 n2
297ret r
298end
299ziflush
300ret 0
301end
302note one api line: "api TAG rc=N why=TEXT"
303fn ziapi tag ulong e long to void
304zifr 13
305zifr tag
306zifr 14
307zisdec e
308zifr 15
309siwhy e
310for i ulong get siwl 0
311zich get siwb i
312end
313zinl
314end
315note put fragment k of zitx into sinam/sinl (for sisetn)
316fn zisetnm k ulong to void
317w = ulong 0
318o = ulong 0
319for i ulong len zitx
320c = get zitx i
321if eq c 124
322w = add w 1
323else
324if eq w k
325put sinam o c
326o = add o 1
327end
328end
329end
330put sinl 0 o
331end
332fn ziapis to int
333e = siseti 0 1
334ziapi 16 e
335sireset
336e = siseti 72 5
337ziapi 17 e
338e = siseti 16 256
339ziapi 18 e
340e = siseti 16 255
341ziapi 19 e
342e = siseti 16 1
343ziapi 20 e
344zisetnm 25
345e = sisetn 4205
346ziapi 21 e
347zisetnm 26
348e = sisetn 4205
349ziapi 22 e
350e = sitext 65537
351ziapi 23 e
352e = sitext 65536
353ziapi 19 e
354siencode
355zifr 13
356zifr 24
357zich 32
358zidec get sinord 0
359zich 32
360zihex ulong get siout 104
361for i ulong 4
362zich 32
363zihex ulong get siout add 120 i
364end
365zinl
366ziflush
367ret 0
368end
369fn main to int
370na = argcnt
371if lt na 2
372r = ziusage
373ret r
374end
375a = argread 1 zia 0 64
376if lt a 0
377r = ziusage
378ret r
379end
380if and eq na 2 zimode a 9
381r = zifields
382ret r
383end
384if and eq na 2 zimode a 12
385r = ziapis
386ret r
387end
388if and eq na 3 zimode a 11
389n2 = argread 2 zip2 0 4096
390if lt n2 0
391r = ziusage
392ret r
393end
394r = zibyidx ulong n2
395ret r
396end
397if and eq na 4 zimode a 10
398n1 = argread 2 zip1 0 4096
399n2 = argread 3 zip2 0 4096
400if or lt n1 0 lt n2 0
401r = ziusage
402ret r
403end
404r = ziencode ulong n1 ulong n2
405ret r
406end
407r = ziusage
408ret r
409end