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