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 / intel / xe / records.om

187 lines · 2690 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note records.om: pure seeded-Omega Linux drm/xe ioctl wire-record serializer (mirrors gpu/amd/kfd/records.om).
3note Usage: records TABLE RECORD_INDEX [FIELD_VALUE ...]
4note Serializes the indexed record from requests.tsv to stdout in little-endian wire format.
5note No field values -> zero-filled record. Otherwise one unsigned decimal value per scalar field slot.
6note Exit: 0 emitted; 2 bad numeric input; 3 malformed table/record; 64 usage; 74 I/O error.
7om2
8
9global gpath uchar 4096
10global garg uchar 64
11global gbuf uchar 256
12global grb uchar 1
13global grfd int 1
14
15fn rbyte to ulong
16r = read get grfd 0 grb 0 1
17if eq r 0
18ret 256
19end
20if ne r 1
21exit 74
22end
23ret ulong get grb 0
24end
25
26fn tnum to ulong
27c = rbyte
28while true bound 999999
29if eq c 256
30exit 3
31end
32if eq c 35
33while ne c 10 bound 999999
34c = rbyte
35if eq c 256
36exit 3
37end
38end
39c = rbyte
40continue
41end
42if or eq c 32 or eq c 9 or eq c 10 eq c 13
43c = rbyte
44continue
45end
46break
47end
48if or lt c 48 gt c 57
49exit 3
50end
51v = sub c 48
52while true bound 999999
53c = rbyte
54if eq c 256
55ret v
56end
57if eq c 35
58while ne c 10 bound 999999
59c = rbyte
60if eq c 256
61ret v
62end
63end
64ret v
65end
66if or eq c 32 or eq c 9 or eq c 10 eq c 13
67ret v
68end
69if or lt c 48 gt c 57
70exit 3
71end
72v = add mul v 10 sub c 48
73end
74ret v
75end
76
77fn parseu ai ulong to ulong
78n = argread ai garg 0 len garg
79if or le n 0 gt n 20
80exit 2
81end
82v = ulong 0
83for i ulong ulong n
84c = get garg i
85if or lt c 48 gt c 57
86exit 2
87end
88v = add mul v 10 ulong sub c 48
89end
90ret v
91end
92
93fn putle off ulong w ulong v ulong to void
94for k ulong w
95put gbuf add off k uchar and shr v mul k 8 255
96end
97end
98
99fn skip_recs want ulong to void
100rec = ulong 0
101while lt rec want bound 256
102req = tnum
103sz = tnum
104nf = tnum
105for i ulong nf
106o = tnum
107w = tnum
108cnt = tnum
109end
110rec = add rec 1
111end
112end
113
114fn valid_w w ulong to bool
115if eq w 1
116ret true
117end
118if eq w 2
119ret true
120end
121if eq w 4
122ret true
123end
124ret eq w 8
125end
126
127fn read_fields sz ulong nf ulong ac long to void
128has_vals = gt ac 3
129ai = ulong 3
130for i ulong nf
131o = tnum
132w = tnum
133cnt = tnum
134if not valid_w w
135exit 3
136end
137if gt add o mul w cnt sz
138exit 3
139end
140for k ulong cnt
141if has_vals
142if ge long ai ac
143exit 2
144end
145putle add o mul k w w parseu ai
146ai = add ai 1
147end
148end
149end
150if and has_vals ne long ai ac
151exit 2
152end
153end
154
155fn main to int
156ac = argcnt
157if lt ac 3
158exit 64
159end
160pn = argread 1 gpath 0 len gpath
161if le pn 0
162exit 64
163end
164fd = fopen gpath 0 ulong pn 0 0
165if lt fd 0
166exit 74
167end
168put grfd 0 int fd
169skip_recs parseu 2
170req = tnum
171sz = tnum
172nf = tnum
173if or eq sz 0 gt sz 256
174c = fclose int fd
175exit 3
176end
177for i ulong sz
178put gbuf i 0
179end
180read_fields sz nf ac
181c = fclose int fd
182wr = write 1 gbuf 0 sz
183if ne wr long sz
184exit 74
185end
186ret 0
187end