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 / si / architecture / tools / doctrine / gate.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gate: the ARCH-DOCTRINE gate runner (#316), seeded native Omega. |
| 3 | note usage: gate OMC ROOT (run from tools/doctrine; writes under build/) |
| 4 | note Builds ../zero-legacy/sha256.om and doctrine.om with OMC, hashes OMC with the native sha256 |
| 5 | note and compares it to ../zero-legacy/omega.pin, prints AIEN-OBS lines, then runs |
| 6 | note build/doctrine ROOT with this process's stdout. Exit: the checker's exit (0 PASS, 1 FAIL, |
| 7 | note 2 ROOT unusable); 3 when OMC is missing or does not match the pin (NOT_RUN); 1 when a |
| 8 | note build fails. gate.sh independently authenticates OMC before executing it to compile this gate. |
| 9 | |
| 10 | text tbl "../zero-legacy/sha256.om\nbuild/sha256\ndoctrine.om\nbuild/doctrine\nbuild/omc.sha\nbuild/doctrine.sha\n../zero-legacy/omega.pin\nbuild\n" |
| 11 | text tobs "AIEN-OBS " |
| 12 | text tsha "doctrine_sha256 \"" |
| 13 | text tq "\"\n" |
| 14 | text texit "doctrine_exit " |
| 15 | text tnl "\n" |
| 16 | text tuse "usage: gate OMC ROOT\n" |
| 17 | text tnot "gate: OMC missing or not the pinned compiler (NOT_RUN)\n" |
| 18 | text tcf "gate: compile failed\n" |
| 19 | text tkey "omc_sha256: " |
| 20 | |
| 21 | global omcp uchar 4096 |
| 22 | global omcl ulong 1 |
| 23 | global rootp uchar 4096 |
| 24 | global rootl ulong 1 |
| 25 | global pk uchar 4096 |
| 26 | global pkn ulong 1 |
| 27 | global pkc ulong 1 |
| 28 | global arg uchar 4096 |
| 29 | global argl ulong 1 |
| 30 | global fin uchar 256 |
| 31 | global finl ulong 1 |
| 32 | global fout uchar 256 |
| 33 | global foutl ulong 1 |
| 34 | global status uchar 4 |
| 35 | global pin uchar 4096 |
| 36 | global pinl ulong 1 |
| 37 | global sha uchar 128 |
| 38 | global nb uchar 24 |
| 39 | |
| 40 | note ---- text table ---- |
| 41 | |
| 42 | fn pick i ulong to void |
| 43 | s = ulong 0 |
| 44 | k = ulong 0 |
| 45 | while lt k i bound 4096 |
| 46 | if eq get tbl s 10 |
| 47 | k = add k 1 |
| 48 | end |
| 49 | s = add s 1 |
| 50 | end |
| 51 | n = ulong 0 |
| 52 | while ne get tbl add s n 10 bound 256 |
| 53 | put arg n get tbl add s n |
| 54 | n = add n 1 |
| 55 | end |
| 56 | put argl 0 n |
| 57 | end |
| 58 | |
| 59 | note ---- packets for execprog ---- |
| 60 | |
| 61 | fn pk0 to void |
| 62 | put pkn 0 2 |
| 63 | put pkc 0 0 |
| 64 | end |
| 65 | |
| 66 | fn pka to void |
| 67 | n = get pkn 0 |
| 68 | m = get argl 0 |
| 69 | put pk n uchar rem m 256 |
| 70 | put pk add n 1 uchar div m 256 |
| 71 | for i ulong m |
| 72 | put pk add n add 2 i get arg i |
| 73 | end |
| 74 | put pkn 0 add n add 2 m |
| 75 | c = add get pkc 0 1 |
| 76 | put pkc 0 c |
| 77 | put pk 0 uchar rem c 256 |
| 78 | put pk 1 uchar div c 256 |
| 79 | end |
| 80 | |
| 81 | fn pkt i ulong to void |
| 82 | pick i |
| 83 | pka |
| 84 | end |
| 85 | |
| 86 | fn pkomc to void |
| 87 | for i ulong get omcl 0 |
| 88 | put arg i get omcp i |
| 89 | end |
| 90 | put argl 0 get omcl 0 |
| 91 | pka |
| 92 | end |
| 93 | |
| 94 | fn pkroot to void |
| 95 | for i ulong get rootl 0 |
| 96 | put arg i get rootp i |
| 97 | end |
| 98 | put argl 0 get rootl 0 |
| 99 | pka |
| 100 | end |
| 101 | |
| 102 | fn setin i ulong to void |
| 103 | pick i |
| 104 | for j ulong get argl 0 |
| 105 | put fin j get arg j |
| 106 | end |
| 107 | put finl 0 get argl 0 |
| 108 | end |
| 109 | |
| 110 | fn setout i ulong to void |
| 111 | pick i |
| 112 | for j ulong get argl 0 |
| 113 | put fout j get arg j |
| 114 | end |
| 115 | put foutl 0 get argl 0 |
| 116 | end |
| 117 | |
| 118 | fn noio to void |
| 119 | put finl 0 0 |
| 120 | put foutl 0 0 |
| 121 | end |
| 122 | |
| 123 | note ---- run the packet; stdin/stdout redirected when set; returns exit code or -1 ---- |
| 124 | |
| 125 | fn child to void |
| 126 | if gt get finl 0 0 |
| 127 | fd = fopen fin 0 get finl 0 0 0 |
| 128 | if lt fd 0 |
| 129 | exit 126 |
| 130 | end |
| 131 | r = dupfd int fd 0 0 |
| 132 | end |
| 133 | if gt get foutl 0 0 |
| 134 | fd = fopen fout 0 get foutl 0 577 420 |
| 135 | if lt fd 0 |
| 136 | exit 126 |
| 137 | end |
| 138 | r = dupfd int fd 1 0 |
| 139 | end |
| 140 | r = execprog pk 0 get pkn 0 |
| 141 | exit 127 |
| 142 | end |
| 143 | |
| 144 | fn run to long |
| 145 | pid = fork |
| 146 | if lt pid 0 |
| 147 | ret -1 |
| 148 | end |
| 149 | if eq pid 0 |
| 150 | child |
| 151 | end |
| 152 | r = waitpid int pid status 0 4 0 |
| 153 | if ne r pid |
| 154 | ret -1 |
| 155 | end |
| 156 | if ne get status 0 0 |
| 157 | ret -1 |
| 158 | end |
| 159 | ret long get status 1 |
| 160 | end |
| 161 | |
| 162 | note ---- steps ---- |
| 163 | |
| 164 | fn compile src ulong dst ulong to bool |
| 165 | pk0 |
| 166 | pkomc |
| 167 | setin src |
| 168 | setout dst |
| 169 | r = run |
| 170 | if ne r 0 |
| 171 | ret false |
| 172 | end |
| 173 | pick dst |
| 174 | r = chmod arg 0 get argl 0 493 |
| 175 | ret eq r 0 |
| 176 | end |
| 177 | |
| 178 | note hash the file named by table entry f into table entry out; read 64 hex into sha |
| 179 | fn hashto f ulong out ulong to bool |
| 180 | pk0 |
| 181 | pkt 1 |
| 182 | pkt f |
| 183 | put finl 0 0 |
| 184 | setout out |
| 185 | r = run |
| 186 | if ne r 0 |
| 187 | ret false |
| 188 | end |
| 189 | ret readsha out |
| 190 | end |
| 191 | |
| 192 | fn hashomc to bool |
| 193 | pk0 |
| 194 | pkt 1 |
| 195 | pkomc |
| 196 | put finl 0 0 |
| 197 | setout 4 |
| 198 | r = run |
| 199 | if ne r 0 |
| 200 | ret false |
| 201 | end |
| 202 | ret readsha 4 |
| 203 | end |
| 204 | |
| 205 | fn readsha out ulong to bool |
| 206 | pick out |
| 207 | fd = fopen arg 0 get argl 0 0 0 |
| 208 | if lt fd 0 |
| 209 | ret false |
| 210 | end |
| 211 | r = read int fd sha 0 128 |
| 212 | c = fclose int fd |
| 213 | ret ge r 64 |
| 214 | end |
| 215 | |
| 216 | fn loadpin to bool |
| 217 | pick 6 |
| 218 | fd = fopen arg 0 get argl 0 0 0 |
| 219 | if lt fd 0 |
| 220 | ret false |
| 221 | end |
| 222 | r = read int fd pin 0 4096 |
| 223 | c = fclose int fd |
| 224 | if le r 0 |
| 225 | ret false |
| 226 | end |
| 227 | put pinl 0 ulong r |
| 228 | ret true |
| 229 | end |
| 230 | |
| 231 | note does sha[0..64) equal the 64 bytes after "omc_sha256: " in the pin |
| 232 | fn pinok to bool |
| 233 | n = get pinl 0 |
| 234 | m = len tkey |
| 235 | if lt n add m 64 |
| 236 | ret false |
| 237 | end |
| 238 | e = sub n add m 64 |
| 239 | i = ulong 0 |
| 240 | while le i e bound 4096 |
| 241 | j = ulong 0 |
| 242 | while lt j m bound 16 |
| 243 | if ne get pin add i j get tkey j |
| 244 | break |
| 245 | end |
| 246 | j = add j 1 |
| 247 | end |
| 248 | if eq j m |
| 249 | ret same add i m |
| 250 | end |
| 251 | i = add i 1 |
| 252 | end |
| 253 | ret false |
| 254 | end |
| 255 | |
| 256 | fn same p ulong to bool |
| 257 | for j ulong 64 |
| 258 | if ne get pin add p j get sha j |
| 259 | ret false |
| 260 | end |
| 261 | end |
| 262 | ret true |
| 263 | end |
| 264 | |
| 265 | note build/doctrine ROOT, stdout inherited |
| 266 | fn rundoc to long |
| 267 | pk0 |
| 268 | pkt 3 |
| 269 | pkroot |
| 270 | noio |
| 271 | ret run |
| 272 | end |
| 273 | |
| 274 | note ---- output ---- |
| 275 | |
| 276 | fn wnum v long to void |
| 277 | if lt v 0 |
| 278 | put nb 22 45 |
| 279 | put nb 23 49 |
| 280 | r = write 1 nb 22 2 |
| 281 | ret |
| 282 | end |
| 283 | x = ulong v |
| 284 | n = ulong 0 |
| 285 | if eq x 0 |
| 286 | put nb 23 48 |
| 287 | n = 1 |
| 288 | end |
| 289 | while gt x 0 bound 20 |
| 290 | put nb sub 23 n uchar add 48 rem x 10 |
| 291 | x = div x 10 |
| 292 | n = add n 1 |
| 293 | end |
| 294 | r = write 1 nb sub 24 n n |
| 295 | end |
| 296 | |
| 297 | fn obs1 to void |
| 298 | r = write 1 tobs 0 len tobs |
| 299 | r = write 1 tsha 0 len tsha |
| 300 | r = write 1 sha 0 64 |
| 301 | r = write 1 tq 0 len tq |
| 302 | end |
| 303 | |
| 304 | fn obs2 v long to void |
| 305 | r = write 1 tobs 0 len tobs |
| 306 | r = write 1 texit 0 len texit |
| 307 | wnum v |
| 308 | r = write 1 tnl 0 1 |
| 309 | end |
| 310 | |
| 311 | fn main to int |
| 312 | if lt argcnt 3 |
| 313 | r = write 2 tuse 0 len tuse |
| 314 | ret 64 |
| 315 | end |
| 316 | n = argread 1 omcp 0 4095 |
| 317 | if lt n 1 |
| 318 | r = write 2 tuse 0 len tuse |
| 319 | ret 64 |
| 320 | end |
| 321 | put omcl 0 ulong n |
| 322 | n = argread 2 rootp 0 4095 |
| 323 | if lt n 1 |
| 324 | r = write 2 tuse 0 len tuse |
| 325 | ret 64 |
| 326 | end |
| 327 | put rootl 0 ulong n |
| 328 | pick 7 |
| 329 | r = makedir arg 0 get argl 0 493 |
| 330 | if not compile 0 1 |
| 331 | r = write 2 tnot 0 len tnot |
| 332 | ret 3 |
| 333 | end |
| 334 | if not loadpin |
| 335 | r = write 2 tnot 0 len tnot |
| 336 | ret 3 |
| 337 | end |
| 338 | if not hashomc |
| 339 | r = write 2 tnot 0 len tnot |
| 340 | ret 3 |
| 341 | end |
| 342 | if not pinok |
| 343 | r = write 2 tnot 0 len tnot |
| 344 | ret 3 |
| 345 | end |
| 346 | if not compile 2 3 |
| 347 | r = write 2 tcf 0 len tcf |
| 348 | ret 1 |
| 349 | end |
| 350 | if not hashto 3 5 |
| 351 | r = write 2 tcf 0 len tcf |
| 352 | ret 1 |
| 353 | end |
| 354 | obs1 |
| 355 | e = rundoc |
| 356 | obs2 e |
| 357 | if lt e 0 |
| 358 | ret 1 |
| 359 | end |
| 360 | ret int e |
| 361 | end |