Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/kernel/artifact/osc_launch.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / kernel / artifact / osc_launch.om` 314 lines ยท 6103 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/kernel/artifact/osc_launch.om: Pure-Omega OSC Unit EL0 Launch Contract 3 note (argument shape & aliasing, range ownership, stack/workspace/tick budgets, SVC/fault classification). 4 note Converted from upstream aienux native/kernel/artifact/osc_launch.h and osc_launch.c. 5 6 struct OscWindows in_va ulong in_len ulong ws_va ulong ws_len ulong end 7 8 struct OscEvent kind uint esr ulong elr ulong x0 ulong x1 ulong end 9 10 struct OscResult cls uchar trap_code uchar unknown_reason uchar refused_code uchar val ulong ticks ulong end 11 12 const OSC_MAXR ulong 6 13 const OSC_RT_SERVICES ulong 13 14 const OSC_SVC_TRAP ulong 2 15 const OSC_SVC_RETURN ulong 13 16 const OSC_RT_STUBS ulong 14 17 const OSC_RT_STUB_BYTES ulong 8 18 const OSC_TRAP_MAX ulong 14 19 const OSC_WS_MAX_PAGES ulong 32 20 const OSC_U64_MAX ulong 0xffffffffffffffff 21 const OSC_U64_MAX_DIV8 ulong 0x1fffffffffffffff 22 23 note Section 9.3 closed result classes 24 const OSC_RES_RETURNED uchar 1 25 const OSC_RES_TRAPPED uchar 2 26 const OSC_RES_REFUSED uchar 3 27 const OSC_RES_UNKNOWN uchar 4 28 29 note Diagnostic unknown_reason codes 30 const OSC_UNK_FAULT uchar 1 31 const OSC_UNK_TICK_OVERRUN uchar 2 32 const OSC_UNK_LAUNCH_LOST uchar 3 33 const OSC_UNK_TRAP_CODE_UNKNOWN uchar 4 34 const OSC_UNK_OTHER uchar 255 35 36 note Observed kernel event kinds 37 const OSC_EV_SVC uint 1 38 const OSC_EV_SYNC uint 2 39 const OSC_EV_BUDGET uint 3 40 const OSC_EV_LOST uint 4 41 42 fn osc_is_slice k uchar to bool 43 ret or eq k 11 eq k 12 44 end 45 46 fn osc_fits k uchar v ulong to bool 47 if eq k 1 48 ret le v 1 49 end 50 if eq k 2 51 ret le v 0xff 52 end 53 if eq k 3 54 ret le v 0xffff 55 end 56 if eq k 4 57 ret le v 0xffffffff 58 end 59 if eq k 6 60 ret or le v 0x7f ge v 0xffffffffffffff80 61 end 62 if eq k 7 63 ret or le v 0x7fff ge v 0xffffffffffff8000 64 end 65 if eq k 8 66 ret or le v 0x7fffffff ge v 0xffffffff80000000 67 end 68 ret true 69 end 70 71 fn osc_pair_overlaps ptr ulong sz ulong kq uchar qptr ulong qn ulong to bool 72 if or eq sz 0 eq qn 0 73 ret false 74 end 75 if and eq kq 12 gt qn OSC_U64_MAX_DIV8 76 ret false 77 end 78 qsz = qn 79 if eq kq 12 80 qsz = mul qn 8 81 end 82 if gt qsz sub OSC_U64_MAX qptr 83 ret false 84 end 85 ret and lt ptr add qptr qsz lt qptr add ptr sz 86 end 87 88 fn osc_slice_overlaps kinds view uchar 6 nregs ulong args view ulong 6 p ulong to bool 89 kp = get kinds p 90 ptr = get args p 91 sz = get args add p 1 92 if eq kp 12 93 sz = mul sz 8 94 end 95 q = ulong 0 96 while lt add q 1 nregs bound 6 97 if ne q p 98 kq = get kinds q 99 if osc_is_slice kq 100 if or eq kp 12 eq kq 12 101 if osc_pair_overlaps ptr sz kq get args q get args add q 1 102 ret true 103 end 104 end 105 end 106 end 107 q = add q 1 108 end 109 ret false 110 end 111 112 fn osc_launch_args_ok kinds view uchar 6 nregs ulong args view ulong 6 nargs ulong to bool 113 if or gt nregs OSC_MAXR ne nargs nregs 114 ret false 115 end 116 p = ulong 0 117 while lt p nregs bound 6 118 kp = get kinds p 119 if not osc_is_slice kp 120 if not osc_fits kp get args p 121 ret false 122 end 123 end 124 p = add p 1 125 end 126 p = ulong 0 127 while lt add p 1 nregs bound 6 128 kp = get kinds p 129 if osc_is_slice kp 130 ptr = get args p 131 n = get args add p 1 132 if eq kp 12 133 if gt n OSC_U64_MAX_DIV8 134 ret false 135 end 136 if and ne n 0 ne and ptr 7 0 137 ret false 138 end 139 end 140 sz = n 141 if eq kp 12 142 sz = mul n 8 143 end 144 if and ne n 0 eq ptr 0 145 ret false 146 end 147 if gt sz sub OSC_U64_MAX ptr 148 ret false 149 end 150 if osc_slice_overlaps kinds nregs args p 151 ret false 152 end 153 end 154 p = add p 1 155 end 156 ret true 157 end 158 159 fn osc_inside ptr ulong sz ulong base ulong wlen ulong to bool 160 if lt ptr base 161 ret false 162 end 163 off = sub ptr base 164 if gt off wlen 165 ret false 166 end 167 ret le sz sub wlen off 168 end 169 170 fn osc_launch_ranges_owned kinds view uchar 6 nregs ulong args view ulong 6 win view OscWindows to bool 171 p = ulong 0 172 while lt add p 1 nregs bound 6 173 kp = get kinds p 174 if osc_is_slice kp 175 ptr = get args p 176 n = get args add p 1 177 if ne n 0 178 if eq kp 12 179 if gt n OSC_U64_MAX_DIV8 180 ret false 181 end 182 if not osc_inside ptr mul n 8 get win ws_va get win ws_len 183 ret false 184 end 185 else 186 if not osc_inside ptr n get win in_va get win in_len 187 ret false 188 end 189 end 190 end 191 end 192 p = add p 1 193 end 194 ret true 195 end 196 197 fn osc_launch_disjoint a ulong alen ulong b ulong blen ulong to bool 198 if or eq alen 0 eq blen 0 199 ret true 200 end 201 aend = add a alen 202 bend = add b blen 203 if or lt aend a lt bend b 204 ret false 205 end 206 ret or le aend b le bend a 207 end 208 209 fn osc_launch_stack_ok declared ulong hard_max ulong to bool 210 ret le declared hard_max 211 end 212 213 fn osc_launch_ws_pages_ok pages ulong to bool 214 ret le pages OSC_WS_MAX_PAGES 215 end 216 217 fn osc_launch_budget unit_ticks ulong caller_cap ulong to ulong 218 if and ne caller_cap 0 lt caller_cap unit_ticks 219 ret caller_cap 220 end 221 ret unit_ticks 222 end 223 224 fn osc_launch_budget_expired seen ulong budget ulong to bool 225 ret ge seen budget 226 end 227 228 fn osc_fault_class ec ulong to bool 229 if or eq ec 0x00 or eq ec 0x07 or eq ec 0x0e eq ec 0x18 230 ret true 231 end 232 if or eq ec 0x20 or eq ec 0x22 or eq ec 0x24 or eq ec 0x26 eq ec 0x3c 233 ret true 234 end 235 ret false 236 end 237 238 fn osc_set_unknown r edit OscResult why uchar to void 239 put r cls OSC_RES_UNKNOWN 240 put r unknown_reason why 241 end 242 243 fn osc_launch_classify e view OscEvent rt_code_va ulong r edit OscResult to void 244 put r cls 0 245 put r trap_code 0 246 put r unknown_reason 0 247 put r refused_code 0 248 put r val 0 249 k = get e kind 250 if eq k OSC_EV_SVC 251 esr = get e esr 252 elr = get e elr 253 ec = and shr esr 26 0x3f 254 imm = and esr 0xffff 255 if or ne ec 0x15 lt elr 4 256 osc_set_unknown r OSC_UNK_FAULT 257 ret 258 end 259 site = sub elr 4 260 if lt site rt_code_va 261 osc_set_unknown r OSC_UNK_FAULT 262 ret 263 end 264 off = sub site rt_code_va 265 lim = mul OSC_RT_STUBS OSC_RT_STUB_BYTES 266 if ge off lim 267 osc_set_unknown r OSC_UNK_FAULT 268 ret 269 end 270 if ne rem off OSC_RT_STUB_BYTES 0 271 osc_set_unknown r OSC_UNK_FAULT 272 ret 273 end 274 if ne imm div off OSC_RT_STUB_BYTES 275 osc_set_unknown r OSC_UNK_FAULT 276 ret 277 end 278 if eq imm OSC_SVC_RETURN 279 put r cls OSC_RES_RETURNED 280 put r val get e x0 281 ret 282 end 283 if eq imm OSC_SVC_TRAP 284 x1 = get e x1 285 if and ge x1 1 le x1 OSC_TRAP_MAX 286 put r cls OSC_RES_TRAPPED 287 put r trap_code uchar x1 288 else 289 osc_set_unknown r OSC_UNK_TRAP_CODE_UNKNOWN 290 end 291 ret 292 end 293 osc_set_unknown r OSC_UNK_OTHER 294 ret 295 end 296 if eq k OSC_EV_SYNC 297 ec = and shr get e esr 26 0x3f 298 if osc_fault_class ec 299 osc_set_unknown r OSC_UNK_FAULT 300 else 301 osc_set_unknown r OSC_UNK_OTHER 302 end 303 ret 304 end 305 if eq k OSC_EV_BUDGET 306 osc_set_unknown r OSC_UNK_TICK_OVERRUN 307 ret 308 end 309 if eq k OSC_EV_LOST 310 osc_set_unknown r OSC_UNK_LAUNCH_LOST 311 ret 312 end 313 osc_set_unknown r OSC_UNK_OTHER 314 end