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 / arm64 / host_test.om

269 lines · 5880 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/kernel/arm64/host_test.om: Pure-Omega host unit tests for Piece 1 / Slice A invariants:
3note 1. pagetable.om strict XN on all non-WB MAIR attrs (1=Dev-nGnRE, 2=Dev-nGnRnE, 3=Normal-NC)
4note 2. pagetable.om Normal-NC SH=OSH roundtrip and 128 GiB bulk mapping without Trap 4
5note 3. frames.om 121.69 GiB Spark LPDDR5x simulation + GB10 RMR carveouts + <40-bit PA constraint
6note 4. Overflow-safe CNTVCT_EL0 ticks-to-ms math (large ticks without u64 overflow)
7note 5. TCR_EL1.IPS fail-closed check on PARange < 40-bit and pass on >= 40-bit
8note Compose with: si/directives/om2.om aienux/kernel/core/scheduler.om aienux/kernel/core/ipc.om aienux/kernel/core/pagetable.om aienux/kernel/arm64/host_test.om
9
10text ht_pass "SLICE_A_HOST_TEST_PASS total=11 failed=0\n"
11text ht_fail "SLICE_A_HOST_TEST_FAIL\n"
12
13fn ht_ticks_to_ms t ulong frq ulong to ulong
14if lt frq 1000
15ret 0
16end
17sec = div t frq
18rem_t = rem t frq
19if gt rem_t 18446744073709551
20ret add mul sec 1000 div rem_t div frq 1000
21end
22ret add mul sec 1000 div mul rem_t 1000 frq
23end
24
25fn ht_is_spurious_intid intid ulong to bool
26ret eq and intid xor ulong 0xffffffffffffffff 3 1020
27end
28
29fn ht_build_tcr_el1 parange ulong to ulong
30pr = and parange 15
31if lt pr 2
32ret 0
33end
34ips = pr
35if gt ips 5
36ips = ulong 5
37end
38tcr = ulong 16
39tcr = or tcr shl ulong 1 8
40tcr = or tcr shl ulong 1 10
41tcr = or tcr shl ulong 3 12
42tcr = or tcr shl ulong 1 23
43tcr = or tcr shl ips 32
44ret tcr
45end
46
47fn test_pt_xn_all_non_wb to bool
48if ne pt_init 0x40000000 64 PT_OK
49ret false
50end
51note Exec on MAIR=1 (Dev-nGnRE), MAIR=2 (Dev-nGnRnE), MAIR=3 (Normal-NC) must all be refused.
52f1 = new PtFlags PT_MAIR_DEVICE_NGNRE 0 0 1 0 1
53if ne pt_map 0x10000000 0x10000000 4096 f1 PT_ERR_DEVICE_EXEC
54ret false
55end
56f2 = new PtFlags PT_MAIR_DEVICE_NGNRNE 0 0 1 0 1
57if ne pt_map 0x10000000 0x10000000 4096 f2 PT_ERR_DEVICE_EXEC
58ret false
59end
60f3 = new PtFlags PT_MAIR_NORMAL_NC 0 0 1 2 1
61if ne pt_map 0x10000000 0x10000000 4096 f3 PT_ERR_DEVICE_EXEC
62ret false
63end
64note Exec on unknown MAIR=4 must also fail closed.
65f4 = new PtFlags 4 0 0 1 0 1
66if ne pt_map 0x10000000 0x10000000 4096 f4 PT_ERR_DEVICE_EXEC
67ret false
68end
69ret true
70end
71
72fn test_pt_nc_osh_and_128g to bool
73if ne pt_init 0x40000000 64 PT_OK
74ret false
75end
76note Map 512 MiB Normal-NC pool with SH=OSH (2), RW, XN.
77fnc = new PtFlags PT_MAIR_NORMAL_NC 1 0 0 2 1
78if ne pt_map 0x400000000 0x400000000 0x20000000 fnc PT_OK
79ret false
80end
81tr = new PtTrans 0 0 0 0 0 0 0 0
82if ne pt_translate 0x400001234 tr PT_OK
83ret false
84end
85if ne get tr pa 0x400001234
86ret false
87end
88if ne get tr attr PT_MAIR_NORMAL_NC
89ret false
90end
91if ne get tr shareable 2
92ret false
93end
94if ne get tr executable 0
95ret false
96end
97note Map 128 GiB WB RAM using 1 GiB blocks (must not hit Trap 4).
98fwb = new PtFlags PT_MAIR_NORMAL_WB 1 0 0 1 1
99if ne pt_map 0x1000000000 0x1000000000 0x2000000000 fwb PT_OK
100ret false
101end
102if ne pt_translate 0x2fffff0000 tr PT_OK
103ret false
104end
105if ne get tr pa 0x2fffff0000
106ret false
107end
108ret true
109end
110
111fn test_timer_overflow_safe to bool
112note t = 0x1000000000000000 ticks at 1 GHz = 1152921504606846976 / 1e9 s = 1152921504606 ms (would overflow t*1000!).
113ms = ht_ticks_to_ms 0x1000000000000000 1000000000
114if ne ms 1152921504606
115ret false
116end
117if ne ht_ticks_to_ms 50000000 100000000 500
118ret false
119end
120if ne ht_ticks_to_ms 12345 0 0
121ret false
122end
123ret true
124end
125
126fn test_tcr_ips_gate to bool
127if ne ht_build_tcr_el1 0 0
128ret false
129end
130if ne ht_build_tcr_el1 1 0
131ret false
132end
133t2 = ht_build_tcr_el1 2
134if ne and shr t2 32 7 2
135ret false
136end
137t5 = ht_build_tcr_el1 5
138if ne and shr t5 32 7 5
139ret false
140end
141t6 = ht_build_tcr_el1 6
142if ne and shr t6 32 7 5
143ret false
144end
145ret true
146end
147
148fn test_mair_const to bool
149ret eq PT_MAIR_VALUE 0x00000000440004ff
150end
151
152fn test_lpi_spurious_predicate to bool
153if or ht_is_spurious_intid 30 or ht_is_spurious_intid 878 ht_is_spurious_intid 1019
154ret false
155end
156if not and ht_is_spurious_intid 1020 and ht_is_spurious_intid 1021 and ht_is_spurious_intid 1022 ht_is_spurious_intid 1023
157ret false
158end
159if or ht_is_spurious_intid 8192 or ht_is_spurious_intid 8199 ht_is_spurious_intid 65535
160ret false
161end
162ret true
163end
164
165fn test_gits_cbaser_attrs to bool
166note Valid(63) | InnerCache=Normal-NC(1<<59) | Shareability=OSH(2<<10) = 0x8800000000000800
167attr = ulong 0x8800000000000800
168if ne and shr attr 63 1 1
169ret false
170end
171if ne and shr attr 59 7 1
172ret false
173end
174if ne and shr attr 10 3 2
175ret false
176end
177ret true
178end
179
180fn test_madt_gicc_eff_offset to bool
181note ACPI 6.5 Table 5.36: MPIDR is 8 bytes at [68..75], Efficiency Class is 1 byte at offset 76.
182gicc = new uchar 80 0
183put gicc 72 0xaa
184put gicc 76 0x01
185if ne get gicc 76 1
186ret false
187end
188if eq get gicc 72 get gicc 76
189ret false
190end
191ret true
192end
193
194fn test_timer_low_frq_guard to bool
195if ne ht_ticks_to_ms 100000 999 0
196ret false
197end
198if ne ht_ticks_to_ms 1000 1000 1000
199ret false
200end
201ret true
202end
203
204fn test_its_mapd_valid_bit63 to bool
205itt = ulong 0x48010000
206dw2 = or itt shl ulong 1 63
207if ne and shr dw2 63 1 1
208ret false
209end
210if ne and dw2 1 0
211ret false
212end
213ret true
214end
215
216fn test_u64_wrap_guard to bool
217pa = ulong 0xfffffffffffff000
218length = ulong 0x2000
219if not gt length sub 0xffffffffffffffff pa
220ret false
221end
222if gt ulong 0x1000 sub 0xffffffffffffffff ulong 0x48000000
223ret false
224end
225ret true
226end
227
228fn main to int
229ok = true
230if not test_pt_xn_all_non_wb
231ok = false
232end
233if not test_pt_nc_osh_and_128g
234ok = false
235end
236if not test_timer_overflow_safe
237ok = false
238end
239if not test_tcr_ips_gate
240ok = false
241end
242if not test_mair_const
243ok = false
244end
245if not test_lpi_spurious_predicate
246ok = false
247end
248if not test_gits_cbaser_attrs
249ok = false
250end
251if not test_madt_gicc_eff_offset
252ok = false
253end
254if not test_timer_low_frq_guard
255ok = false
256end
257if not test_its_mapd_valid_bit63
258ok = false
259end
260if not test_u64_wrap_guard
261ok = false
262end
263if ok
264w = write 1 ht_pass 0 len ht_pass
265ret 0
266end
267w = write 1 ht_fail 0 len ht_fail
268ret 1
269end