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 / gsp / rpc.om
| 1 | note gsp/rpc.om: bounded non-CC GSP-RM queue codec, host replay ONLY. No DMA/MMIO or hardware readiness. |
| 2 | note NVIDIA 580.173.02 message_queue_cpu.c:434-585,615-735; msgq.c SWAP_RX; rpc.c:11194-11228. |
| 3 | note Reference aienux c5bb3a4b native/kernel/dev/gb10_gsp_boot.c:152-361. |
| 4 | note rqcmd/rqstat are caller-owned replay images, NOT device mappings. No implicit hardware backend. |
| 5 | note rqsend uses rqpay; logical n may exclude appended RM_ALLOC params, physical p includes them. |
| 6 | note rqrecv captures full declared slots, validates actual alignment padding (not manufactured zeros). |
| 7 | note Status: 0 empty/success; 1 received; -1 shape/length; -2 full; -3 checksum; -4 sequence; |
| 8 | note -5 unsupported version/signature; -6 quarantined. Refusals never advance pointers or counters. |
| 9 | const RQQSZ ulong 262144 |
| 10 | const RQSLOT ulong 4096 |
| 11 | const RQCOUNT ulong 63 |
| 12 | const RQMAX ulong 65536 |
| 13 | const RQVER ulong 50331648 |
| 14 | const RQSIG ulong 1129337430 |
| 15 | const RQU32 ulong 4294967295 |
| 16 | global rqcmd uchar 262144 |
| 17 | global rqstat uchar 262144 |
| 18 | global rqpay uchar 65536 |
| 19 | global rqout uchar 65536 |
| 20 | global rqtmp uchar 65536 |
| 21 | note counters: tx element, rx element, synchronous RPC; increment only after publication/acceptance. |
| 22 | global rqtx uint 1 |
| 23 | global rqrx uint 1 |
| 24 | global rqseq uint 1 |
| 25 | global rqsent uint 1 |
| 26 | global rqlen ulong 1 |
| 27 | global rqslots ulong 1 |
| 28 | global rqfun ulong 1 |
| 29 | global rqres ulong 1 |
| 30 | global rqpriv ulong 1 |
| 31 | global rqreply ulong 1 |
| 32 | global rqdead uchar 1 |
| 33 | global rqlink uchar 1 |
| 34 | note Preparation is private; single-use token commits sequences only after the chosen publisher succeeds. |
| 35 | global rqptok ulong 1 |
| 36 | global rqppend uchar 1 |
| 37 | global rqpwr ulong 1 |
| 38 | global rqpcnt ulong 1 |
| 39 | global rqpseq uint 1 |
| 40 | global rqptx uint 1 |
| 41 | global rqpsync uchar 1 |
| 42 | note Array selectors avoid passing globals (not supported by pinned compiler): 0 cmd,1 stat,2 tmp,3 out,4 pay. |
| 43 | fn rqbyte a ulong o ulong to uchar |
| 44 | if eq a 0 |
| 45 | ret get rqcmd o |
| 46 | end |
| 47 | if eq a 1 |
| 48 | ret get rqstat o |
| 49 | end |
| 50 | if eq a 2 |
| 51 | ret get rqtmp o |
| 52 | end |
| 53 | if eq a 3 |
| 54 | ret get rqout o |
| 55 | end |
| 56 | ret get rqpay o |
| 57 | end |
| 58 | fn rqput a ulong o ulong v uchar to void |
| 59 | if eq a 0 |
| 60 | put rqcmd o v |
| 61 | ret |
| 62 | end |
| 63 | if eq a 1 |
| 64 | put rqstat o v |
| 65 | ret |
| 66 | end |
| 67 | if eq a 2 |
| 68 | put rqtmp o v |
| 69 | ret |
| 70 | end |
| 71 | if eq a 3 |
| 72 | put rqout o v |
| 73 | ret |
| 74 | end |
| 75 | put rqpay o v |
| 76 | end |
| 77 | fn rqget32 a ulong o ulong to ulong |
| 78 | v = ulong 0 |
| 79 | for i ulong 4 |
| 80 | v = or v shl ulong rqbyte a add o i mul i 8 |
| 81 | end |
| 82 | ret v |
| 83 | end |
| 84 | fn rqput32 a ulong o ulong v ulong to void |
| 85 | for i ulong 4 |
| 86 | rqput a add o i uchar and shr v mul i 8 255 |
| 87 | end |
| 88 | end |
| 89 | fn rqsum a ulong n ulong to ulong |
| 90 | v = ulong 0 |
| 91 | for i ulong n |
| 92 | v = xor v shl ulong rqbyte a i mul rem i 4 8 |
| 93 | end |
| 94 | ret v |
| 95 | end |
| 96 | fn rqshape a ulong to bool |
| 97 | if or ne rqget32 a 0 0 ne rqget32 a 4 RQQSZ |
| 98 | ret false |
| 99 | end |
| 100 | if or ne rqget32 a 8 RQSLOT ne rqget32 a 12 RQCOUNT |
| 101 | ret false |
| 102 | end |
| 103 | if or ne rqget32 a 20 1 ne rqget32 a 24 32 |
| 104 | ret false |
| 105 | end |
| 106 | ret eq rqget32 a 28 RQSLOT |
| 107 | end |
| 108 | fn rqinit to void |
| 109 | for i ulong RQQSZ |
| 110 | put rqcmd i 0 |
| 111 | put rqstat i 0 |
| 112 | end |
| 113 | rqput32 0 4 RQQSZ |
| 114 | rqput32 0 8 RQSLOT |
| 115 | rqput32 0 12 RQCOUNT |
| 116 | rqput32 0 20 1 |
| 117 | rqput32 0 24 32 |
| 118 | rqput32 0 28 RQSLOT |
| 119 | put rqtx 0 0 |
| 120 | put rqrx 0 0 |
| 121 | put rqseq 0 0 |
| 122 | put rqsent 0 0 |
| 123 | put rqlen 0 0 |
| 124 | put rqslots 0 0 |
| 125 | put rqdead 0 0 |
| 126 | put rqlink 0 0 |
| 127 | put rqppend 0 0 |
| 128 | end |
| 129 | note Replay peer queue creation is explicit input, never inferred from a boot command. |
| 130 | fn rqpeer to void |
| 131 | for i ulong 32 |
| 132 | put rqstat i get rqcmd i |
| 133 | end |
| 134 | rqput32 1 16 0 |
| 135 | put rqlink 0 1 |
| 136 | end |
| 137 | fn rqclear n ulong to void |
| 138 | if gt n RQMAX |
| 139 | trap 3 |
| 140 | end |
| 141 | for i ulong n |
| 142 | put rqpay i 0 |
| 143 | end |
| 144 | end |
| 145 | fn rqframe f ulong n ulong p ulong seq uint e ulong to void |
| 146 | for i ulong mul e RQSLOT |
| 147 | put rqtmp i 0 |
| 148 | end |
| 149 | rqput32 2 36 ulong get rqtx 0 |
| 150 | rqput32 2 40 e |
| 151 | rqput32 2 48 RQVER |
| 152 | rqput32 2 52 RQSIG |
| 153 | rqput32 2 56 add 32 n |
| 154 | rqput32 2 60 f |
| 155 | rqput32 2 64 RQU32 |
| 156 | rqput32 2 68 RQU32 |
| 157 | rqput32 2 72 ulong seq |
| 158 | for i ulong p |
| 159 | put rqtmp add 80 i get rqpay i |
| 160 | end |
| 161 | note All padding was zeroed above; supported RM_ALLOC fixed32 ends exactly on alignment. |
| 162 | rqput32 2 32 rqsum 2 mul div add add 80 n 7 8 8 |
| 163 | end |
| 164 | fn rqcopy wr ulong e ulong to void |
| 165 | for i ulong mul e RQSLOT |
| 166 | o = rem add wr div i RQSLOT RQCOUNT |
| 167 | o = add RQSLOT mul o RQSLOT |
| 168 | o = add o rem i RQSLOT |
| 169 | put rqcmd o get rqtmp i |
| 170 | end |
| 171 | end |
| 172 | fn rqprep f ulong n ulong p ulong sync bool to long |
| 173 | if ne get rqdead 0 0 |
| 174 | ret -6 |
| 175 | end |
| 176 | if ne get rqppend 0 0 |
| 177 | ret -6 |
| 178 | end |
| 179 | if eq add get rqptok 0 1 0 |
| 180 | ret -6 |
| 181 | end |
| 182 | if or gt f RQU32 or gt n 65456 lt p n |
| 183 | ret -1 |
| 184 | end |
| 185 | note The sole supported unchecked physical tail is vendor RM_ALLOC's aligned fixed32 body. |
| 186 | if and gt p n not and eq f 103 eq n 32 |
| 187 | ret -1 |
| 188 | end |
| 189 | e = div add add 80 n 4095 RQSLOT |
| 190 | if or gt p sub mul e RQSLOT 80 gt p 65456 |
| 191 | ret -1 |
| 192 | end |
| 193 | if not rqshape 0 |
| 194 | ret -1 |
| 195 | end |
| 196 | wr = rqget32 0 16 |
| 197 | rd = rqget32 1 32 |
| 198 | if or ge wr RQCOUNT ge rd RQCOUNT |
| 199 | ret -1 |
| 200 | end |
| 201 | if lt rem sub add rd RQCOUNT add wr 1 RQCOUNT e |
| 202 | ret -2 |
| 203 | end |
| 204 | seq = uint 0 |
| 205 | if sync |
| 206 | seq = get rqseq 0 |
| 207 | end |
| 208 | rqframe f n p seq e |
| 209 | put rqptok 0 add get rqptok 0 1 |
| 210 | put rqppend 0 1 |
| 211 | put rqpwr 0 wr |
| 212 | put rqpcnt 0 e |
| 213 | put rqpseq 0 seq |
| 214 | put rqptx 0 get rqtx 0 |
| 215 | put rqpsync 0 0 |
| 216 | if sync |
| 217 | put rqpsync 0 1 |
| 218 | end |
| 219 | ret 0 |
| 220 | end |
| 221 | fn rqcommit token ulong to long |
| 222 | if or ne get rqppend 0 1 ne token get rqptok 0 |
| 223 | ret -6 |
| 224 | end |
| 225 | if or ne get rqtx 0 get rqptx 0 ne rqget32 0 16 get rqpwr 0 |
| 226 | ret -6 |
| 227 | end |
| 228 | if and ne get rqpsync 0 0 ne get rqseq 0 get rqpseq 0 |
| 229 | ret -6 |
| 230 | end |
| 231 | wr = get rqpwr 0 |
| 232 | e = get rqpcnt 0 |
| 233 | seq = get rqpseq 0 |
| 234 | rqput32 0 16 rem add wr e RQCOUNT |
| 235 | put rqsent 0 seq |
| 236 | put rqtx 0 add get rqtx 0 uint 1 |
| 237 | if ne get rqpsync 0 0 |
| 238 | put rqseq 0 add seq uint 1 |
| 239 | end |
| 240 | put rqppend 0 0 |
| 241 | ret 0 |
| 242 | end |
| 243 | fn rqsend f ulong n ulong p ulong sync bool to long |
| 244 | r = rqprep f n p sync |
| 245 | if ne r 0 |
| 246 | ret r |
| 247 | end |
| 248 | rqcopy get rqpwr 0 get rqpcnt 0 |
| 249 | ret rqcommit get rqptok 0 |
| 250 | end |
| 251 | fn rqcapt rd ulong e ulong to void |
| 252 | for i ulong mul e RQSLOT |
| 253 | p = rem add rd div i RQSLOT RQCOUNT |
| 254 | p = add RQSLOT mul p RQSLOT |
| 255 | p = add p rem i RQSLOT |
| 256 | put rqtmp i get rqstat p |
| 257 | end |
| 258 | end |
| 259 | fn rqvalid m ulong to long |
| 260 | aligned = mul div add m 7 8 8 |
| 261 | if ne rqsum 2 aligned 0 |
| 262 | ret -3 |
| 263 | end |
| 264 | if ne rqget32 2 36 ulong get rqrx 0 |
| 265 | ret -4 |
| 266 | end |
| 267 | if or ne rqget32 2 48 RQVER ne rqget32 2 52 RQSIG |
| 268 | ret -5 |
| 269 | end |
| 270 | note Strict single-client non-CC profile: no authentication metadata or routing union. |
| 271 | for i ulong 32 |
| 272 | if ne get rqtmp i 0 |
| 273 | ret -5 |
| 274 | end |
| 275 | end |
| 276 | if or ne rqget32 2 44 0 ne rqget32 2 76 0 |
| 277 | ret -5 |
| 278 | end |
| 279 | ret 0 |
| 280 | end |
| 281 | fn rqaccept n ulong e ulong rd ulong to void |
| 282 | for i ulong mul e RQSLOT |
| 283 | put rqout i get rqtmp i |
| 284 | end |
| 285 | put rqlen 0 sub n 32 |
| 286 | put rqslots 0 mul e RQSLOT |
| 287 | put rqfun 0 rqget32 3 60 |
| 288 | put rqres 0 rqget32 3 64 |
| 289 | put rqpriv 0 rqget32 3 68 |
| 290 | put rqreply 0 rqget32 3 72 |
| 291 | rqput32 0 32 rem add rd e RQCOUNT |
| 292 | put rqrx 0 add get rqrx 0 uint 1 |
| 293 | end |
| 294 | fn rqrecv to long |
| 295 | if ne get rqdead 0 0 |
| 296 | ret -6 |
| 297 | end |
| 298 | if not rqshape 0 |
| 299 | ret -1 |
| 300 | end |
| 301 | if not rqshape 1 |
| 302 | if eq get rqlink 0 0 |
| 303 | ret 0 |
| 304 | end |
| 305 | ret -1 |
| 306 | end |
| 307 | put rqlink 0 1 |
| 308 | wr = rqget32 1 16 |
| 309 | rd = rqget32 0 32 |
| 310 | if or ge wr RQCOUNT ge rd RQCOUNT |
| 311 | ret -1 |
| 312 | end |
| 313 | avail = rem sub add wr RQCOUNT rd RQCOUNT |
| 314 | if eq avail 0 |
| 315 | ret 0 |
| 316 | end |
| 317 | o = add RQSLOT mul rd RQSLOT |
| 318 | e = rqget32 1 add o 40 |
| 319 | n = rqget32 1 add o 56 |
| 320 | if or or eq e 0 gt e 16 gt e avail |
| 321 | ret -1 |
| 322 | end |
| 323 | if or lt n 32 gt n 65488 |
| 324 | ret -1 |
| 325 | end |
| 326 | if ne e div add add 48 n 4095 RQSLOT |
| 327 | ret -1 |
| 328 | end |
| 329 | rqcapt rd e |
| 330 | r = rqvalid add 48 n |
| 331 | if ne r 0 |
| 332 | ret r |
| 333 | end |
| 334 | rqaccept n e rd |
| 335 | ret 1 |
| 336 | end |