interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / aienux / kernel / artifact / osc_launch.om

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