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 / qual / x86linux_qual.om

336 lines · 6477 bytes Raw Blame History
1target x86linux
2om2
3note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4note gpu/qual/x86linux_qual.om: standalone pure-Omega x86-64 Linux physical-hardware qualification binary.
5note Build (from repo root):
6note { printf 'target x86linux\nom2\n'; cat seed/ng/sha256.om gpu/qual/x86linux_qual.om | grep -v '^target x86linux$' | grep -v '^om2$'; } | seed/out/omc > x86linux_qual
7note Or compose via gpu/qual/gate.sh.
8note
9note Behavior:
10note 1. Inspects /proc/version, /proc/cpuinfo, /proc/self/maps to distinguish physical x86-64 Linux
11note hardware from user-mode emulation (e.g., qemu-x86_64 on an AArch64 kernel).
12note 2. Exercises native x86-64 integer arithmetic, signed/unsigned overflow & shift semantics,
13note IEEE-754 f32/f64 arithmetic + sqrt + bitcast, NIST FIPS 180-4 SHA-256 vectors,
14note mmap (mapnew/mapset/mapget/mapdrop), cpufence/cpurelax, monotonic clock, and
15note fork+waitpid negative-control trap delivery (traps 1, 2, 3, 5 -> exits 101, 102, 103, 105).
16note 3. Emits a structured qualification report with SHA-256 digest of the report body.
17note
18note Exit codes:
19note 0 PHYSICAL_X86_64 PASS (or EMULATED_SELFTEST PASS when --allow-emulated-selftest is explicitly passed)
20note 1 FAIL (functional check or trap control failed)
21note 2 usage error
22note 3 BLOCKED_HARDWARE (running under emulation / non-x86_64 kernel; refuses to claim physical PASS)
23
24text xq_flag "--allow-emulated-selftest"
25text xq_pver "/proc/version"
26text xq_pcpu "/proc/cpuinfo"
27text xq_pmap "/proc/self/maps"
28text xq_kx86 "x86_64"
29text xq_ka64 "aarch64"
30text xq_karm "arm64"
31text xq_kqemu "qemu"
32text xq_kintel "GenuineIntel"
33text xq_kamd "AuthenticAMD"
34text xq_kven "vendor_id"
35text xq_abc "abc"
36text xq_abc_sha "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
37text xq_e0_sha "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
38text xq_hdr "OMEGA-X86LINUX-QUAL v1\n"
39text xq_phys "EXEC_CLASS=PHYSICAL_X86_64\n"
40text xq_emu "EXEC_CLASS=EMULATED\n"
41text xq_vpass "VERDICT=PASS checks=12 traps=4/4 hardware=PHYSICAL_X86_64\n"
42text xq_vemu_ok "VERDICT=EMULATED_SELFTEST_PASS checks=12 traps=4/4 hardware=NOT_RUN\n"
43text xq_vblk "VERDICT=BLOCKED_HARDWARE reason=emulated_not_physical_x86_64 checks=12 traps=4/4\n"
44text xq_vfail "VERDICT=FAIL\n"
45text xq_rcpt "RECEIPT_SHA256="
46text xq_use "usage: x86linux_qual [--allow-emulated-selftest]\n"
47
48global xq_buf uchar 32768
49global xq_arg uchar 64
50global xq_st uchar 4
51global xq_hx uchar 64
52
53fn xq_readfile p view uchar * to ulong
54fd = fopen p 0 len p 0 0
55if lt fd 0
56ret 0
57end
58tot = ulong 0
59while lt tot 32768 bound 128
60got = read int fd xq_buf tot sub 32768 tot
61if le got 0
62break
63end
64tot = add tot ulong got
65end
66r = fclose int fd
67ret tot
68end
69
70fn xq_has n ulong pat view uchar * to bool
71pl = len pat
72if or eq pl 0 gt pl n
73ret false
74end
75lim = add sub n pl 1
76for i ulong lim bound 32768
77ok = true
78for j ulong pl bound 64
79if ne get xq_buf add i j get pat j
80ok = false
81break
82end
83end
84if ok
85ret true
86end
87end
88ret false
89end
90
91fn xq_is_physical to bool
92vn = xq_readfile xq_pver
93if eq vn 0
94ret false
95end
96if or xq_has vn xq_ka64 xq_has vn xq_karm
97ret false
98end
99mn = xq_readfile xq_pmap
100if gt mn 0
101if xq_has mn xq_kqemu
102ret false
103end
104end
105cn = xq_readfile xq_pcpu
106if eq cn 0
107ret false
108end
109if not xq_has cn xq_kven
110ret false
111end
112if or xq_has cn xq_kintel xq_has cn xq_kamd
113ret true
114end
115ret xq_has vn xq_kx86
116end
117
118fn xq_check_arith to bool
119a = ulong 18446744073709551615
120if ne add a 1 0
121ret false
122end
123if ne mul ulong 65537 ulong 65537 ulong 4295098369
124ret false
125end
126s = long -123456789
127if ne div s long -3 long 41152263
128ret false
129end
130if ne rem s long 10 long -9
131ret false
132end
133if ne shr ulong 18446744073709551615 60 15
134ret false
135end
136if ne shr long -16 2 long -4
137ret false
138end
139ret true
140end
141
142fn xq_check_float to bool
143x = f64 9.0
144y = fsqrt x
145if ne y f64 3.0
146ret false
147end
148z = add mul f64 1.5 f64 4.0 f64 -2.25
149if ne z f64 3.75
150ret false
151end
152f1 = f32 16.0
153f2 = fsqrt f1
154if ne f2 f32 4.0
155ret false
156end
157b = bitcast uint f2
158if ne b uint 1082130432
159ret false
160end
161ret true
162end
163
164fn xq_sha_text t view uchar * to void
165for i ulong len t bound 256
166put sh_dat i get t i
167end
168sh_all len t
169for j ulong 32
170b = get sh_dig j
171put xq_hx mul j 2 sh_hexd uint shr b 4
172put xq_hx add mul j 2 1 sh_hexd uint and b 15
173end
174end
175
176fn xq_check_sha to bool
177xq_sha_text xq_abc
178for i ulong 64
179if ne get xq_hx i get xq_abc_sha i
180ret false
181end
182end
183sh_all 0
184for j ulong 32
185b = get sh_dig j
186put xq_hx mul j 2 sh_hexd uint shr b 4
187put xq_hx add mul j 2 1 sh_hexd uint and b 15
188end
189for i ulong 64
190if ne get xq_hx i get xq_e0_sha i
191ret false
192end
193end
194ret true
195end
196
197fn xq_check_sys to bool
198t1 = monons
199cpufence
200cpurelax
201r = sleepns 1000
202t2 = monons
203if lt t2 t1
204ret false
205end
206ret true
207end
208
209fn xq_run_trap kind ulong to ulong
210arr = new uchar 4 0
211pid = fork
212if lt pid 0
213ret 255
214end
215if eq pid 0
216if eq kind 1
217v = long 9223372036854775807
218w = add v 1
219exit int w
220end
221if eq kind 2
222d = ulong 0
223w = div ulong 1 d
224exit int w
225end
226if eq kind 3
227idx = ulong 7
228c = get arr idx
229exit int c
230end
231xv = ulong 300
232sv = uchar xv
233exit int sv
234end
235wp = waitpid int pid xq_st 0 4 0
236if lt wp 0
237ret 254
238end
239w = or ulong get xq_st 0 shl ulong get xq_st 1 8
240ret and shr w 8 255
241end
242
243fn xq_check_traps to bool
244if ne xq_run_trap 1 101
245ret false
246end
247if ne xq_run_trap 2 102
248ret false
249end
250if ne xq_run_trap 3 103
251ret false
252end
253if ne xq_run_trap 5 105
254ret false
255end
256ret true
257end
258
259fn main to int
260nl = new uchar 1 10
261allow_emu = false
262ac = argcnt
263if eq ac 2
264n1 = argread 1 xq_arg 0 64
265if ne n1 long len xq_flag
266r = write 2 xq_use 0 len xq_use
267ret 2
268end
269for i ulong len xq_flag
270if ne get xq_arg i get xq_flag i
271r = write 2 xq_use 0 len xq_use
272ret 2
273end
274end
275allow_emu = true
276else
277if ne ac 1
278r = write 2 xq_use 0 len xq_use
279ret 2
280end
281end
282
283phys = xq_is_physical
284r = write 1 xq_hdr 0 len xq_hdr
285if phys
286r = write 1 xq_phys 0 len xq_phys
287else
288r = write 1 xq_emu 0 len xq_emu
289end
290
291ok = true
292if not xq_check_arith
293ok = false
294end
295if not xq_check_float
296ok = false
297end
298if not xq_check_sha
299ok = false
300end
301if not xq_check_sys
302ok = false
303end
304if not xq_check_traps
305ok = false
306end
307if not ok
308r = write 1 xq_vfail 0 len xq_vfail
309ret 1
310end
311
312if phys
313r = write 1 xq_vpass 0 len xq_vpass
314xq_sha_text xq_vpass
315else
316if allow_emu
317r = write 1 xq_vemu_ok 0 len xq_vemu_ok
318xq_sha_text xq_vemu_ok
319else
320r = write 1 xq_vblk 0 len xq_vblk
321xq_sha_text xq_vblk
322end
323end
324
325r = write 1 xq_rcpt 0 len xq_rcpt
326r = write 1 xq_hx 0 64
327r = write 1 nl 0 1
328
329if phys
330ret 0
331end
332if allow_emu
333ret 0
334end
335ret 3
336end