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 / tests / x86efi / ident / id.om

272 lines · 4194 bytes Raw Blame History
1target x86efi
2note efi 14 identity: the CPUID brand string, SystemTable FirmwareVendor (UCS-2 to ASCII, ? outside
3note 32..126), SMBIOS type 1 Manufacturer/Product/Version (never Serial or UUID), then one hex line
4note per refusal or edge result. FirmwareRevision goes after the ==B block (it depends on the OVMF build).
5global ms uchar 256
6global ml ulong 1
7global cb uchar 16
8global br uchar 48
9global vb uchar 256
10global sb uchar 8192
11global pb uchar 8
12
13fn pc c ulong to void
14put ms get ml 0 uchar c
15put ml 0 add get ml 0 1
16end
17
18fn nl to void
19pc 10
20r = efi 13 0 ms 0 get ml 0
21put ml 0 0
22end
23
24fn ps c ulong to void
25if and ge c 32 le c 126
26pc c
27else
28pc 63
29end
30end
31
32fn hx v ulong n ulong to void
33i = ulong 0
34while lt i n bound 16
35d = and shr v mul sub sub n 1 i 4 15
36if lt d 10
37pc add 48 d
38else
39pc add 87 d
40end
41i = add i 1
42end
43end
44
45fn rd4 k ulong to ulong
46v = ulong 0
47for i ulong 4
48v = or v shl ulong get cb add k i mul i 8
49end
50ret v
51end
52
53note CPUID leaf l into cb; returns efi 14's result
54fn cpu l ulong to ulong
55ret efi 14 shl l 16 cb 0 16
56end
57
58note true when brand byte i is padding (32 or 0); and/or evaluate both sides, so the trim loops test
59note their index bound in the while and the byte inside the body: br[48] is never read
60fn bblank i ulong to bool
61v = ulong get br i
62ret or eq v 32 eq v 0
63end
64
65fn brand to void
66r = cpu 2147483648
67if or ne r 16 lt rd4 0 2147483652
68pc 45
69ret
70end
71for j ulong 3
72r = cpu add 2147483650 j
73for k ulong 16
74put br add mul j 16 k get cb k
75end
76end
77s = ulong 0
78while lt s 48 bound 48
79if not bblank s
80break
81end
82s = add s 1
83end
84e = ulong 48
85while gt e s bound 48
86if not bblank sub e 1
87break
88end
89e = sub e 1
90end
91if eq e s
92pc 45
93end
94i = s
95while lt i e bound 48
96ps ulong get br i
97i = add i 1
98end
99end
100
101fn vendor to void
102r = efi 14 1 vb 0 256
103if or ge r 9223372036854775808 eq r 0
104pc 45
105ret
106end
107for k ulong div r 2
108ps or ulong get vb mul k 2 shl ulong get vb add mul k 2 1 8
109end
110end
111
112note SMBIOS string number n of the structure at p (formatted length at p+1), or - when n is 0, when
113note the string set ends first (a string may not start with 0: that 0 ends the set), or when the
114note string's NUL lies at or past t. Every read is below t, so the walk never leaves the structure.
115fn sstr p ulong n ulong t ulong to void
116if eq n 0
117pc 45
118ret
119end
120q = add p ulong get sb add p 1
121c = ulong 1
122while lt q t bound 8192
123if eq ulong get sb q 0
124pc 45
125ret
126end
127if eq c n
128e = q
129while lt e t bound 8192
130if eq ulong get sb e 0
131break
132end
133e = add e 1
134end
135if ge e t
136pc 45
137ret
138end
139while lt q e bound 8192
140ps ulong get sb q
141q = add q 1
142end
143ret
144end
145while lt q t bound 8192
146if eq ulong get sb q 0
147break
148end
149q = add q 1
150end
151q = add q 1
152c = add c 1
153end
154pc 45
155end
156
157note string number in field i of the structure at p (byte p+4+i), or 0 when that byte is at or past t
158fn fld p ulong i ulong t ulong to ulong
159k = add add p 4 i
160if ge k t
161ret 0
162end
163ret ulong get sb k
164end
165
166note true when sb[q] and sb[q+1] are both 0 (the end of a structure's string set)
167fn dnul q ulong to bool
168ret and eq ulong get sb q 0 eq ulong get sb add q 1 0
169end
170
171fn smbios to void
172t = efi 14 3 sb 0 8192
173if or ge t 9223372036854775808 lt t 4
174pc 45
175ret
176end
177p = ulong 0
178while lt add p 4 t bound 8192
179ty = ulong get sb p
180ln = ulong get sb add p 1
181if eq ty 1
182if lt ln 8
183pc 45
184ret
185end
186sstr p fld p 0 t t
187pc 47
188sstr p fld p 1 t t
189pc 47
190sstr p fld p 2 t t
191ret
192end
193if or eq ty 127 lt ln 4
194pc 45
195ret
196end
197q = add p ln
198while lt add q 1 t bound 8192
199if dnul q
200break
201end
202q = add q 1
203end
204p = add q 2
205end
206pc 45
207end
208
209fn line v ulong to void
210hx v 16
211nl
212end
213
214fn main to ulong
215pc 61
216pc 61
217pc 66
218nl
219pc 98
220pc 114
221pc 61
222brand
223nl
224pc 102
225pc 119
226pc 61
227vendor
228nl
229pc 115
230pc 109
231pc 61
232smbios
233nl
234note sub 3 at position 4: 8 bytes equal to the table's bytes 4..11
235r = efi 14 or ulong 3 shl ulong 4 16 pb 0 8
236ok = eq r 8
237for k ulong 8
238if ne get pb k get sb add k 4
239ok = false
240end
241end
242if ok
243pc 112
244pc 111
245pc 115
246pc 32
247pc 111
248pc 107
249else
250pc 63
251end
252nl
253line efi 14 3 pb 0 0
254line efi 14 or ulong 3 shl ulong 1048575 16 pb 0 8
255line efi 14 0 cb 0 16
256line efi 14 0 cb 0 15
257line efi 14 shl ulong 1 48 cb 0 16
258line efi 14 4 cb 0 16
259line efi 14 65537 cb 0 16
260line efi 14 256 cb 0 16
261pc 61
262pc 61
263pc 69
264nl
265pc 61
266pc 61
267pc 82
268pc 32
269hx efi 14 2 cb 0 0 8
270nl
271ret 0
272end