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