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 / gpu / driver / uvm / range.om

226 lines · 3688 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note One va_space per service instance, 64 ranges. Sorted implicit binary tree.
3note Rows: base,size,physical base,preferred(0 CPU/1 GPU),accessed-by mask,read-dup,RO,reserved.
4note Binary lookup traverses midpoint children; mutation moves bounded rows, never page backing.
5global sr ulong 512
6global sn ulong 1
7global slive ulong 1
8fn sget i ulong f ulong to ulong
9ret get sr add mul i 8 f
10end
11fn sset i ulong f ulong v ulong to void
12put sr add mul i 8 f v
13end
14fn scopy dst ulong src ulong to void
15for f ulong 8
16sset dst f sget src f
17end
18end
19fn sfind va ulong to ulong
20lo = ulong 0
21hi = get sn 0
22while lt lo hi bound 7
23mid = div add lo hi 2
24if lt va sget mid 0
25hi = mid
26else
27if lt sub va sget mid 0 sget mid 1
28ret mid
29end
30lo = add mid 1
31end
32end
33ret 64
34end
35fn screate to ulong
36if ne get slive 0 0
37ret UVEBUSY
38end
39r = uvinit
40if ne r UVOK
41ret r
42end
43put sn 0 0
44put slive 0 1
45ret UVOK
46end
47fn sdestroy to ulong
48if eq get slive 0 0
49ret UVENOENT
50end
51if ne get sn 0 0
52ret UVEBUSY
53end
54if not squiescent
55ret UVEBUSY
56end
57put slive 0 0
58ret UVOK
59end
60fn scheck va ulong size ulong pa ulong pol ulong to ulong
61if eq get slive 0 0
62ret UVEPERM
63end
64if ne rem va UV4K 0
65ret UVEALIGN
66end
67if ne rem size UV4K 0
68ret UVEALIGN
69end
70if ne rem pa UV4K 0
71ret UVEALIGN
72end
73if or eq size 0 ge va add UVBASE UVWIN
74ret UVERANGE
75end
76if lt va UVBASE
77ret UVERANGE
78end
79if gt size sub add UVBASE UVWIN va
80ret UVERANGE
81end
82if or ge pa UVPA52 gt size sub UVPA52 pa
83ret UVERANGE
84end
85if and ne pa 0 uvpoolhit pa size
86ret UVERANGE
87end
88if gt pol 63
89ret UVEINVAL
90end
91ret UVOK
92end
93fn sadd va ulong size ulong pa ulong pol ulong to ulong
94r = scheck va size pa pol
95if ne r UVOK
96ret r
97end
98for i ulong get sn 0
99if lt va add sget i 0 sget i 1
100if lt sget i 0 add va size
101ret UVEBUSY
102end
103end
104end
105if eq get sn 0 64
106ret UVENOM
107end
108pos = ulong 0
109for i ulong get sn 0
110if lt sget i 0 va
111pos = add pos 1
112end
113end
114j = get sn 0
115while gt j pos bound 64
116scopy j sub j 1
117j = sub j 1
118end
119sset pos 0 va
120sset pos 1 size
121sset pos 2 pa
122sset pos 3 and pol 1
123sset pos 4 and shr pol 1 3
124sset pos 5 and shr pol 3 1
125sset pos 6 and shr pol 4 1
126sset pos 7 and shr pol 5 1
127put sn 0 add get sn 0 1
128ret UVOK
129end
130fn ssplit va ulong to ulong
131if ne rem va UV4K 0
132ret UVEALIGN
133end
134i = sfind va
135if eq i 64
136ret UVENOENT
137end
138if eq va sget i 0
139ret UVEINVAL
140end
141if eq get sn 0 64
142ret UVENOM
143end
144j = get sn 0
145while gt j i bound 64
146scopy j sub j 1
147j = sub j 1
148end
149off = sub va sget i 0
150sset add i 1 0 va
151sset add i 1 1 sub sget i 1 off
152if ne sget i 2 0
153sset add i 1 2 add sget i 2 off
154end
155sset i 1 off
156put sn 0 add get sn 0 1
157ret UVOK
158end
159fn serase i ulong to void
160j = i
161while lt add j 1 get sn 0 bound 64
162scopy j add j 1
163j = add j 1
164end
165put sn 0 sub get sn 0 1
166for f ulong 8
167sset get sn 0 f 0
168end
169end
170fn smerge va ulong to ulong
171i = sfind va
172if eq i 64
173ret UVENOENT
174end
175j = add i 1
176if ge j get sn 0
177ret UVENOENT
178end
179if ne add sget i 0 sget i 1 sget j 0
180ret UVEINVAL
181end
182if ne sget i 2 0
183if ne add sget i 2 sget i 1 sget j 2
184ret UVEINVAL
185end
186else
187if ne sget j 2 0
188ret UVEINVAL
189end
190end
191for f ulong 5
192if ne sget i add f 3 sget j add f 3
193ret UVEPERM
194end
195end
196sset i 1 add sget i 1 sget j 1
197serase j
198ret UVOK
199end
200fn sremove va ulong size ulong to ulong
201if or ne rem va UV4K 0 ne rem size UV4K 0
202ret UVEALIGN
203end
204i = sfind va
205if eq i 64
206ret UVENOENT
207end
208if or ne va sget i 0 ne size sget i 1
209ret UVEINVAL
210end
211if ne get iqcprod 0 get iqccons 0
212ret UVEBUSY
213end
214note Unmap each installed 4K PTE, never reclaim hardware backing or PT pages.
215off = ulong 0
216while lt off size bound 65536
217r = uvread add va off UV4K
218if eq r UVMAPPED
219r = uvunmap add va off UV4K UV4K
220end
221off = add off UV4K
222end
223serase i
224sforget va size
225ret UVOK
226end