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 / protocol / interplane / omega / hardware / map.om
| 1 | note L558 handwritten seeded Omega hardware capability validator and mapper |
| 2 | note Inputs are model stdin and host-owned discovery fd3, never permission |
| 3 | text Err "hardware refusal " |
| 4 | text NL "\n" |
| 5 | text Hex "0123456789abcdef" |
| 6 | text Start "{\"kind\":\"capability_request\",\"request_id\":\"hw-" |
| 7 | text Run "\",\"runtime\":\"aienux\",\"capability\":\"hw_" |
| 8 | text Cpu "cpu_discover" |
| 9 | text Timer "timer_arm" |
| 10 | text Irq "interrupt_bind" |
| 11 | text Dma "dma_map" |
| 12 | text Power "power_request" |
| 13 | text Args "\",\"arguments\":{\"identifier\":" |
| 14 | text Feat ",\"required_features\":" |
| 15 | text Val ",\"value\":" |
| 16 | text Gen ",\"discovery_generation\":\"" |
| 17 | text Tool "\"},\"tool\":{\"namespace\":\"hardware\",\"name\":\"" |
| 18 | text Ccpu "cpu.discover" |
| 19 | text Ctimer "timer.arm" |
| 20 | text Cirq "interrupt.bind" |
| 21 | text Cdma "dma.map" |
| 22 | text Cpower "power.request" |
| 23 | text Map "\"},\"mapping\":{\"table_version\":\"hardware-1\",\"rule_id\":\"alias:hardware." |
| 24 | text Digest "\",\"passthrough\":false,\"catalog_digest\":\"sha256:" |
| 25 | text End "\"}}\n" |
| 26 | |
| 27 | fn frame fd int a edit uchar 96 to bool |
| 28 | pos = ulong 0 |
| 29 | while lt pos 96 |
| 30 | n = read fd a pos sub ulong 96 pos |
| 31 | if ne n -4 |
| 32 | if le n 0 |
| 33 | ret false |
| 34 | end |
| 35 | pos = add pos ulong n |
| 36 | end |
| 37 | end |
| 38 | extra = new uchar 1 0 |
| 39 | n = read fd extra 0 1 |
| 40 | while eq n -4 |
| 41 | n = read fd extra 0 1 |
| 42 | end |
| 43 | ret eq n 0 |
| 44 | end |
| 45 | |
| 46 | fn word a view uchar 96 off ulong count ulong to ulong |
| 47 | v = ulong 0 |
| 48 | for i ulong count |
| 49 | v = or v shl ulong get a add off i mul i 8 |
| 50 | end |
| 51 | ret v |
| 52 | end |
| 53 | |
| 54 | fn shape r view uchar 96 d view uchar 96 to int |
| 55 | if ne word r 0 4 826890056 |
| 56 | ret 20 |
| 57 | end |
| 58 | if ne word d 0 4 826562376 |
| 59 | ret 20 |
| 60 | end |
| 61 | for i ulong 2 |
| 62 | if ne get r add i 10 0 |
| 63 | ret 20 |
| 64 | end |
| 65 | end |
| 66 | for i ulong 24 |
| 67 | if ne get r add i 72 0 |
| 68 | ret 20 |
| 69 | end |
| 70 | end |
| 71 | for i ulong 6 |
| 72 | if ne get d add i 18 0 |
| 73 | ret 20 |
| 74 | end |
| 75 | end |
| 76 | for i ulong 32 |
| 77 | if ne get d add i 64 0 |
| 78 | ret 20 |
| 79 | end |
| 80 | end |
| 81 | if or ne get r 4 1 ne get d 4 1 |
| 82 | ret 21 |
| 83 | end |
| 84 | if or or ne get d 5 1 ne get d 6 1 ne get d 7 0 |
| 85 | ret 22 |
| 86 | end |
| 87 | ret 0 |
| 88 | end |
| 89 | |
| 90 | fn platform r view uchar 96 d view uchar 96 to int |
| 91 | for i ulong 3 |
| 92 | if or ne get r add i 6 1 ne get d add i 8 1 |
| 93 | ret 23 |
| 94 | end |
| 95 | end |
| 96 | if gt get d 11 1 |
| 97 | ret 23 |
| 98 | end |
| 99 | if ne and get r 9 get d 11 get r 9 |
| 100 | ret 23 |
| 101 | end |
| 102 | ret 0 |
| 103 | end |
| 104 | |
| 105 | fn binding r view uchar 96 d view uchar 96 to int |
| 106 | if eq word d 24 8 0 |
| 107 | ret 24 |
| 108 | end |
| 109 | if ne word r 24 8 word d 24 8 |
| 110 | ret 24 |
| 111 | end |
| 112 | any = uchar 0 |
| 113 | for i ulong 32 |
| 114 | if ne get r add i 32 get d add i 32 |
| 115 | ret 24 |
| 116 | end |
| 117 | any = or any get d add i 32 |
| 118 | end |
| 119 | if eq any 0 |
| 120 | ret 24 |
| 121 | end |
| 122 | ret 0 |
| 123 | end |
| 124 | |
| 125 | fn iface d view uchar 96 to int |
| 126 | if or ne get d 12 1 ne get d 13 3 |
| 127 | ret 25 |
| 128 | end |
| 129 | if and ne get d 14 0 ne get d 14 3 |
| 130 | ret 25 |
| 131 | end |
| 132 | if and ne get d 15 1 ne get d 15 2 |
| 133 | ret 25 |
| 134 | end |
| 135 | if and eq get d 14 0 eq get d 15 2 |
| 136 | ret 25 |
| 137 | end |
| 138 | if ne get d 16 1 |
| 139 | ret 25 |
| 140 | end |
| 141 | if and ne get d 17 1 ne get d 17 2 |
| 142 | ret 25 |
| 143 | end |
| 144 | ret 0 |
| 145 | end |
| 146 | |
| 147 | fn values r view uchar 96 d view uchar 96 to int |
| 148 | op = get r 5 |
| 149 | id = word r 12 4 |
| 150 | val = word r 16 8 |
| 151 | if or lt op 1 gt op 5 |
| 152 | ret 26 |
| 153 | end |
| 154 | if eq word r 64 8 0 |
| 155 | ret 27 |
| 156 | end |
| 157 | if eq op 1 |
| 158 | if or ne id 0 ne val 0 |
| 159 | ret 27 |
| 160 | end |
| 161 | end |
| 162 | if eq op 2 |
| 163 | if or or ne id 0 eq val 0 gt val 2147483647 |
| 164 | ret 27 |
| 165 | end |
| 166 | end |
| 167 | if eq op 3 |
| 168 | if or or lt id 32 gt id 1019 ne val 0 |
| 169 | ret 27 |
| 170 | end |
| 171 | end |
| 172 | if eq op 4 |
| 173 | if or or gt id 65535 eq val 0 gt val 1048576 |
| 174 | ret 27 |
| 175 | end |
| 176 | if ne rem val 4096 0 |
| 177 | ret 27 |
| 178 | end |
| 179 | if ne get d 14 3 |
| 180 | ret 28 |
| 181 | end |
| 182 | end |
| 183 | if eq op 5 |
| 184 | if or or lt id 1 gt id 2 ne val 0 |
| 185 | ret 27 |
| 186 | end |
| 187 | end |
| 188 | ret 0 |
| 189 | end |
| 190 | |
| 191 | fn number fd int n ulong to void |
| 192 | buf = new uchar 20 0 |
| 193 | pos = ulong 20 |
| 194 | while gt n 9 bound 20 |
| 195 | pos = sub pos 1 |
| 196 | put buf pos uchar add rem n 10 48 |
| 197 | n = div n 10 |
| 198 | end |
| 199 | pos = sub pos 1 |
| 200 | put buf pos uchar add n 48 |
| 201 | size = sub ulong 20 pos |
| 202 | while gt size 0 |
| 203 | w = write fd buf pos size |
| 204 | if ne w -4 |
| 205 | if le w 0 |
| 206 | exit 29 |
| 207 | end |
| 208 | pos = add pos ulong w |
| 209 | size = sub size ulong w |
| 210 | end |
| 211 | end |
| 212 | end |
| 213 | |
| 214 | fn check w long n ulong to void |
| 215 | if ne w long n |
| 216 | exit 29 |
| 217 | end |
| 218 | end |
| 219 | |
| 220 | fn name op uchar canon bool to void |
| 221 | if canon |
| 222 | if eq op 1 |
| 223 | check write 1 Ccpu 0 len Ccpu len Ccpu |
| 224 | end |
| 225 | if eq op 2 |
| 226 | check write 1 Ctimer 0 len Ctimer len Ctimer |
| 227 | end |
| 228 | if eq op 3 |
| 229 | check write 1 Cirq 0 len Cirq len Cirq |
| 230 | end |
| 231 | if eq op 4 |
| 232 | check write 1 Cdma 0 len Cdma len Cdma |
| 233 | end |
| 234 | if eq op 5 |
| 235 | check write 1 Cpower 0 len Cpower len Cpower |
| 236 | end |
| 237 | else |
| 238 | if eq op 1 |
| 239 | check write 1 Cpu 0 len Cpu len Cpu |
| 240 | end |
| 241 | if eq op 2 |
| 242 | check write 1 Timer 0 len Timer len Timer |
| 243 | end |
| 244 | if eq op 3 |
| 245 | check write 1 Irq 0 len Irq len Irq |
| 246 | end |
| 247 | if eq op 4 |
| 248 | check write 1 Dma 0 len Dma len Dma |
| 249 | end |
| 250 | if eq op 5 |
| 251 | check write 1 Power 0 len Power len Power |
| 252 | end |
| 253 | end |
| 254 | end |
| 255 | |
| 256 | fn emit r view uchar 96 to void |
| 257 | check write 1 Start 0 len Start len Start |
| 258 | number 1 word r 64 8 |
| 259 | check write 1 Run 0 len Run len Run |
| 260 | name get r 5 false |
| 261 | check write 1 Args 0 len Args len Args |
| 262 | number 1 word r 12 4 |
| 263 | check write 1 Feat 0 len Feat len Feat |
| 264 | number 1 ulong get r 9 |
| 265 | check write 1 Val 0 len Val len Val |
| 266 | number 1 word r 16 8 |
| 267 | check write 1 Gen 0 len Gen len Gen |
| 268 | number 1 word r 24 8 |
| 269 | check write 1 Tool 0 len Tool len Tool |
| 270 | name get r 5 true |
| 271 | check write 1 Map 0 len Map len Map |
| 272 | name get r 5 true |
| 273 | check write 1 Digest 0 len Digest len Digest |
| 274 | buf = new uchar 64 0 |
| 275 | for i ulong 32 |
| 276 | b = get r add i 32 |
| 277 | put buf mul i 2 get Hex ulong shr b 4 |
| 278 | put buf add mul i 2 1 get Hex ulong and b 15 |
| 279 | end |
| 280 | check write 1 buf 0 len buf len buf |
| 281 | check write 1 End 0 len End len End |
| 282 | end |
| 283 | |
| 284 | fn fail code int to int |
| 285 | check write 2 Err 0 len Err len Err |
| 286 | number 2 ulong code |
| 287 | check write 2 NL 0 len NL len NL |
| 288 | ret code |
| 289 | end |
| 290 | |
| 291 | fn main to int |
| 292 | r = new uchar 96 0 |
| 293 | d = new uchar 96 0 |
| 294 | if not frame 0 r |
| 295 | ret fail 20 |
| 296 | end |
| 297 | if not frame 3 d |
| 298 | ret fail 20 |
| 299 | end |
| 300 | code = shape r d |
| 301 | if ne code 0 |
| 302 | ret fail code |
| 303 | end |
| 304 | code = platform r d |
| 305 | if ne code 0 |
| 306 | ret fail code |
| 307 | end |
| 308 | code = binding r d |
| 309 | if ne code 0 |
| 310 | ret fail code |
| 311 | end |
| 312 | code = iface d |
| 313 | if ne code 0 |
| 314 | ret fail code |
| 315 | end |
| 316 | code = values r d |
| 317 | if ne code 0 |
| 318 | ret fail code |
| 319 | end |
| 320 | emit r |
| 321 | ret 0 |
| 322 | end |