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 / driver / tests / sysinfo_cli.om
| 1 | note tests/sysinfo_cli.om: the command line of aien-dev/aienux PR #441 native/kernel/tools/ck_gsp_sysinfo_encode.c |
| 2 | note over gsp/sysinfo.om, same stdout bytes and exit codes, so tests/sysinfo_diff.sh can cmp the two. |
| 3 | note fields the 72 fields: "%-36s off=%3u size=%u" |
| 4 | note encode IN OUT parse IN, echo "set %-36s off=%3u size=%u value=%#llx" per accepted line, then |
| 5 | note "REFUSED: why" (exit 2) or write the 936 bytes to OUT and "RESULT OK OUT 936 bytes" |
| 6 | note byidx OUT .om only: set all 72 fields through siseti with distinct non-zero bytes, print the |
| 7 | note same values as "name 0x.." text (for the C tool to encode) and write the bytes |
| 8 | note api .om only: the API refusals (siseti/sisetn/sitext), one line each |
| 9 | note Anything else: usage on stderr, exit 1 (as the C tool). Host only; never touches a device. |
| 10 | note Build: cat gsp/sysinfo.om tests/sysinfo_cli.om | omc |
| 11 | text zitx "REFUSED: |cannot read |cannot write |RESULT OK | 936 bytes|set | off=| size=| value=|fields|encode|byidx|api|api | rc=| why=|nit|idx|fit|ok|rep|name|unk|big|bytes|Chipset|chipset|" |
| 12 | text ziut "usage: ck_gsp_sysinfo_encode encode IN.txt OUT.bin | fields | selftest\n" |
| 13 | global ziob uchar 65536 |
| 14 | global zipos ulong 1 |
| 15 | global zia uchar 64 |
| 16 | global zip1 uchar 4096 |
| 17 | global zip2 uchar 4096 |
| 18 | global zix uchar 1 |
| 19 | fn ziflush to void |
| 20 | n = get zipos 0 |
| 21 | if gt n 0 |
| 22 | r = write 1 ziob 0 n |
| 23 | if ne r long n |
| 24 | exit 1 |
| 25 | end |
| 26 | end |
| 27 | put zipos 0 0 |
| 28 | end |
| 29 | fn zich c uchar to void |
| 30 | p = get zipos 0 |
| 31 | put ziob p c |
| 32 | put zipos 0 add p 1 |
| 33 | if ge add p 1 65000 |
| 34 | ziflush |
| 35 | end |
| 36 | end |
| 37 | note fragment k of zitx (fragments end at | 124) |
| 38 | fn zifr k ulong to void |
| 39 | w = ulong 0 |
| 40 | for i ulong len zitx |
| 41 | c = get zitx i |
| 42 | if eq c 124 |
| 43 | w = add w 1 |
| 44 | else |
| 45 | if eq w k |
| 46 | zich c |
| 47 | end |
| 48 | end |
| 49 | end |
| 50 | end |
| 51 | fn zinl to void |
| 52 | zich 10 |
| 53 | end |
| 54 | fn zidec v ulong to void |
| 55 | d = ulong 1 |
| 56 | while le d div v 10 bound 20 |
| 57 | d = mul d 10 |
| 58 | end |
| 59 | while ne d 0 bound 20 |
| 60 | zich uchar add rem div v d 10 48 |
| 61 | d = div d 10 |
| 62 | end |
| 63 | end |
| 64 | fn zisdec v long to void |
| 65 | if lt v 0 |
| 66 | zich 45 |
| 67 | zidec ulong sub 0 v |
| 68 | ret |
| 69 | end |
| 70 | zidec ulong v |
| 71 | end |
| 72 | note %3u |
| 73 | fn zipad3 v ulong to void |
| 74 | if lt v 100 |
| 75 | zich 32 |
| 76 | end |
| 77 | if lt v 10 |
| 78 | zich 32 |
| 79 | end |
| 80 | zidec v |
| 81 | end |
| 82 | note %#llx (0 prints as 0) |
| 83 | fn zihex v ulong to void |
| 84 | if eq v 0 |
| 85 | zich 48 |
| 86 | ret |
| 87 | end |
| 88 | zich 48 |
| 89 | zich 120 |
| 90 | nd = ulong 0 |
| 91 | t = v |
| 92 | while ne t 0 bound 17 |
| 93 | nd = add nd 1 |
| 94 | t = shr t 4 |
| 95 | end |
| 96 | for i ulong nd |
| 97 | d = and shr v mul sub sub nd i 1 4 15 |
| 98 | if lt d 10 |
| 99 | zich uchar add d 48 |
| 100 | else |
| 101 | zich uchar add d 87 |
| 102 | end |
| 103 | end |
| 104 | end |
| 105 | note %-36s of sinam |
| 106 | fn zinam to void |
| 107 | n = get sinl 0 |
| 108 | for i ulong n |
| 109 | zich get sinam i |
| 110 | end |
| 111 | if lt n 36 |
| 112 | for j ulong sub 36 n |
| 113 | zich 32 |
| 114 | end |
| 115 | end |
| 116 | end |
| 117 | fn zipath which ulong n ulong to void |
| 118 | for i ulong n |
| 119 | if eq which 1 |
| 120 | zich get zip1 i |
| 121 | else |
| 122 | zich get zip2 i |
| 123 | end |
| 124 | end |
| 125 | end |
| 126 | note "name off=%3u size=%u" for field k (name already in sinam) |
| 127 | fn zifield k ulong to void |
| 128 | zinam |
| 129 | zifr 6 |
| 130 | zipad3 get sioff k |
| 131 | zifr 7 |
| 132 | zidec get sisz k |
| 133 | end |
| 134 | note argv[1] equals fragment k of zitx |
| 135 | fn zimode n long k ulong to bool |
| 136 | w = ulong 0 |
| 137 | j = ulong 0 |
| 138 | for i ulong len zitx |
| 139 | c = get zitx i |
| 140 | if eq c 124 |
| 141 | w = add w 1 |
| 142 | else |
| 143 | if eq w k |
| 144 | if ge j ulong n |
| 145 | ret false |
| 146 | end |
| 147 | if ne get zia j c |
| 148 | ret false |
| 149 | end |
| 150 | j = add j 1 |
| 151 | end |
| 152 | end |
| 153 | end |
| 154 | ret eq j ulong n |
| 155 | end |
| 156 | fn ziusage to int |
| 157 | ziflush |
| 158 | r = write 2 ziut 0 len ziut |
| 159 | ret 1 |
| 160 | end |
| 161 | fn zifields to int |
| 162 | sireset |
| 163 | for k ulong SINF |
| 164 | sinmk k |
| 165 | zifield k |
| 166 | zinl |
| 167 | end |
| 168 | ziflush |
| 169 | ret 0 |
| 170 | end |
| 171 | fn ziecho to void |
| 172 | for i ulong get sinord 0 |
| 173 | k = get siord i |
| 174 | sinmk k |
| 175 | zifr 5 |
| 176 | zifield k |
| 177 | zifr 8 |
| 178 | zihex get sival k |
| 179 | zinl |
| 180 | end |
| 181 | end |
| 182 | note siwb already holds the refusal text (siwhy is called before the echo, which reuses sinam) |
| 183 | fn zirefuse to int |
| 184 | zifr 0 |
| 185 | for i ulong get siwl 0 |
| 186 | zich get siwb i |
| 187 | end |
| 188 | zinl |
| 189 | ziflush |
| 190 | ret 2 |
| 191 | end |
| 192 | fn zicant k ulong which ulong n ulong to int |
| 193 | zifr 0 |
| 194 | zifr k |
| 195 | zipath which n |
| 196 | zinl |
| 197 | ziflush |
| 198 | ret 2 |
| 199 | end |
| 200 | note write siout to the path in zip2[0..n); false when any step fails |
| 201 | fn ziput n ulong to bool |
| 202 | fd = fopen zip2 0 n 524865 438 |
| 203 | if lt fd 0 |
| 204 | ret false |
| 205 | end |
| 206 | w = write int fd siout 0 SISIZE |
| 207 | c = fclose int fd |
| 208 | ret and eq w long SISIZE eq c 0 |
| 209 | end |
| 210 | fn zislurp n ulong to long |
| 211 | fd = fopen zip1 0 n 524288 0 |
| 212 | if lt fd 0 |
| 213 | ret -1 |
| 214 | end |
| 215 | t = ulong 0 |
| 216 | bad = false |
| 217 | while lt t SITXMAX bound 70000 |
| 218 | r = read int fd sitxt t sub SITXMAX t |
| 219 | if lt r 0 |
| 220 | bad = true |
| 221 | break |
| 222 | end |
| 223 | if eq r 0 |
| 224 | break |
| 225 | end |
| 226 | t = add t ulong r |
| 227 | end |
| 228 | if and eq t SITXMAX not bad |
| 229 | r = read int fd zix 0 1 |
| 230 | if lt r 0 |
| 231 | bad = true |
| 232 | end |
| 233 | if gt r 0 |
| 234 | t = add t 1 |
| 235 | end |
| 236 | end |
| 237 | c = fclose int fd |
| 238 | if bad |
| 239 | ret -1 |
| 240 | end |
| 241 | ret long t |
| 242 | end |
| 243 | fn ziencode n1 ulong n2 ulong to int |
| 244 | t = zislurp n1 |
| 245 | if lt t 0 |
| 246 | r = zicant 1 1 n1 |
| 247 | ret r |
| 248 | end |
| 249 | sireset |
| 250 | e = sitext ulong t |
| 251 | siwhy e |
| 252 | ziecho |
| 253 | if ne e SIEOK |
| 254 | r = zirefuse |
| 255 | ret r |
| 256 | end |
| 257 | siencode |
| 258 | if not ziput n2 |
| 259 | r = zicant 2 2 n2 |
| 260 | ret r |
| 261 | end |
| 262 | zifr 3 |
| 263 | zipath 2 n2 |
| 264 | zifr 4 |
| 265 | zinl |
| 266 | ziflush |
| 267 | ret 0 |
| 268 | end |
| 269 | fn zipat k ulong to ulong |
| 270 | v = ulong 0 |
| 271 | for b ulong get sisz k |
| 272 | x = add rem add mul k 8 b 251 1 |
| 273 | v = or v shl x mul b 8 |
| 274 | end |
| 275 | ret v |
| 276 | end |
| 277 | fn zibyidx n2 ulong to int |
| 278 | sireset |
| 279 | for k ulong SINF |
| 280 | v = zipat k |
| 281 | e = siseti k v |
| 282 | if ne e SIEOK |
| 283 | siwhy e |
| 284 | r = zirefuse |
| 285 | ret r |
| 286 | end |
| 287 | for i ulong get sinl 0 |
| 288 | zich get sinam i |
| 289 | end |
| 290 | zich 32 |
| 291 | zihex v |
| 292 | zinl |
| 293 | end |
| 294 | siencode |
| 295 | if not ziput n2 |
| 296 | r = zicant 2 2 n2 |
| 297 | ret r |
| 298 | end |
| 299 | ziflush |
| 300 | ret 0 |
| 301 | end |
| 302 | note one api line: "api TAG rc=N why=TEXT" |
| 303 | fn ziapi tag ulong e long to void |
| 304 | zifr 13 |
| 305 | zifr tag |
| 306 | zifr 14 |
| 307 | zisdec e |
| 308 | zifr 15 |
| 309 | siwhy e |
| 310 | for i ulong get siwl 0 |
| 311 | zich get siwb i |
| 312 | end |
| 313 | zinl |
| 314 | end |
| 315 | note put fragment k of zitx into sinam/sinl (for sisetn) |
| 316 | fn zisetnm k ulong to void |
| 317 | w = ulong 0 |
| 318 | o = ulong 0 |
| 319 | for i ulong len zitx |
| 320 | c = get zitx i |
| 321 | if eq c 124 |
| 322 | w = add w 1 |
| 323 | else |
| 324 | if eq w k |
| 325 | put sinam o c |
| 326 | o = add o 1 |
| 327 | end |
| 328 | end |
| 329 | end |
| 330 | put sinl 0 o |
| 331 | end |
| 332 | fn ziapis to int |
| 333 | e = siseti 0 1 |
| 334 | ziapi 16 e |
| 335 | sireset |
| 336 | e = siseti 72 5 |
| 337 | ziapi 17 e |
| 338 | e = siseti 16 256 |
| 339 | ziapi 18 e |
| 340 | e = siseti 16 255 |
| 341 | ziapi 19 e |
| 342 | e = siseti 16 1 |
| 343 | ziapi 20 e |
| 344 | zisetnm 25 |
| 345 | e = sisetn 4205 |
| 346 | ziapi 21 e |
| 347 | zisetnm 26 |
| 348 | e = sisetn 4205 |
| 349 | ziapi 22 e |
| 350 | e = sitext 65537 |
| 351 | ziapi 23 e |
| 352 | e = sitext 65536 |
| 353 | ziapi 19 e |
| 354 | siencode |
| 355 | zifr 13 |
| 356 | zifr 24 |
| 357 | zich 32 |
| 358 | zidec get sinord 0 |
| 359 | zich 32 |
| 360 | zihex ulong get siout 104 |
| 361 | for i ulong 4 |
| 362 | zich 32 |
| 363 | zihex ulong get siout add 120 i |
| 364 | end |
| 365 | zinl |
| 366 | ziflush |
| 367 | ret 0 |
| 368 | end |
| 369 | fn main to int |
| 370 | na = argcnt |
| 371 | if lt na 2 |
| 372 | r = ziusage |
| 373 | ret r |
| 374 | end |
| 375 | a = argread 1 zia 0 64 |
| 376 | if lt a 0 |
| 377 | r = ziusage |
| 378 | ret r |
| 379 | end |
| 380 | if and eq na 2 zimode a 9 |
| 381 | r = zifields |
| 382 | ret r |
| 383 | end |
| 384 | if and eq na 2 zimode a 12 |
| 385 | r = ziapis |
| 386 | ret r |
| 387 | end |
| 388 | if and eq na 3 zimode a 11 |
| 389 | n2 = argread 2 zip2 0 4096 |
| 390 | if lt n2 0 |
| 391 | r = ziusage |
| 392 | ret r |
| 393 | end |
| 394 | r = zibyidx ulong n2 |
| 395 | ret r |
| 396 | end |
| 397 | if and eq na 4 zimode a 10 |
| 398 | n1 = argread 2 zip1 0 4096 |
| 399 | n2 = argread 3 zip2 0 4096 |
| 400 | if or lt n1 0 lt n2 0 |
| 401 | r = ziusage |
| 402 | ret r |
| 403 | end |
| 404 | r = ziencode ulong n1 ulong n2 |
| 405 | ret r |
| 406 | end |
| 407 | r = ziusage |
| 408 | ret r |
| 409 | end |