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
omega-mv / aienux / crates / aienos-boot / boot_crate_test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/crates/aienos-boot/boot_crate_test.om: Behavioral self-test for aienos-boot. |
| 3 | note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-boot/boot_crate.om aienux/crates/aienos-boot/boot_crate_test.om |
| 4 | |
| 5 | text t_dp_path_def "\\EFI\\DEFAULT\\default.efi" |
| 6 | text t_dp_path_cand "\\EFI\\AIENOS\\CANDIDATE.EFI" |
| 7 | text t_dp_path_stager "\\EFI\\BOOT\\BOOTAA64.EFI" |
| 8 | text t_mode_fault "mode=fault\n" |
| 9 | text t_mode_timeout "timeout" |
| 10 | text t_mode_absent "absent" |
| 11 | text t_mode_malformed "malformed" |
| 12 | text t_mode_real "real_aienos" |
| 13 | text t_mode_normal "normal" |
| 14 | text t_art_a "alpha.aien" |
| 15 | text t_art_b "beta.AIEN" |
| 16 | text t_art_c "charlie.aien" |
| 17 | text t_stmt_1 "qemu: the operator asked AIEN to remember this" |
| 18 | text t_sent_hex "b6a72a740e5c8e5c" |
| 19 | |
| 20 | fn test_lib_and_wcslen to int |
| 21 | if ne BC_CREATES_AGENT_IDENTITY 0 |
| 22 | ret 1 |
| 23 | end |
| 24 | if ne len bc_firmware_banner 30 |
| 25 | ret 2 |
| 26 | end |
| 27 | if not bc_feature_config_valid true false false |
| 28 | ret 3 |
| 29 | end |
| 30 | if bc_feature_config_valid true true false |
| 31 | ret 4 |
| 32 | end |
| 33 | if bc_feature_config_valid true false true |
| 34 | ret 5 |
| 35 | end |
| 36 | if not bc_feature_config_valid false true true |
| 37 | ret 6 |
| 38 | end |
| 39 | |
| 40 | note wcslen.rs test 1: empty_string_is_zero |
| 41 | w0 = new ushort 1 0 |
| 42 | if ne bc_wide_len w0 0 |
| 43 | ret 7 |
| 44 | end |
| 45 | |
| 46 | note wcslen.rs test 2: counts_units_before_first_zero |
| 47 | w1 = new ushort 4 0 |
| 48 | put w1 0 97 |
| 49 | put w1 1 98 |
| 50 | put w1 2 99 |
| 51 | put w1 3 0 |
| 52 | if ne bc_wide_len w1 3 |
| 53 | ret 8 |
| 54 | end |
| 55 | |
| 56 | note wcslen.rs test 3: stops_at_first_zero_not_slice_end |
| 57 | w2 = new ushort 6 0 |
| 58 | put w2 0 1 |
| 59 | put w2 1 2 |
| 60 | put w2 2 0 |
| 61 | put w2 3 3 |
| 62 | put w2 4 4 |
| 63 | put w2 5 0 |
| 64 | if ne bc_wide_len w2 2 |
| 65 | ret 9 |
| 66 | end |
| 67 | |
| 68 | note wcslen.rs test 4: high_unit_values_are_not_terminators |
| 69 | w3 = new ushort 5 0 |
| 70 | put w3 0 0xffff |
| 71 | put w3 1 0x8000 |
| 72 | put w3 2 0x0100 |
| 73 | put w3 3 0xd800 |
| 74 | put w3 4 0 |
| 75 | if ne bc_wide_len w3 4 |
| 76 | ret 10 |
| 77 | end |
| 78 | |
| 79 | note wcslen bounded safety: no zero returns slice len |
| 80 | w4 = new ushort 3 0x0041 |
| 81 | if ne bc_wide_len w4 3 |
| 82 | ret 11 |
| 83 | end |
| 84 | ret 0 |
| 85 | end |
| 86 | |
| 87 | fn test_rollback_dp_and_load_opt to int |
| 88 | note Build a synthetic partition DP prefix (8 bytes: Type 0x04 SubType 0x01 Len 8) |
| 89 | prefix = new uchar 8 0 |
| 90 | put prefix 0 0x04 |
| 91 | put prefix 1 0x01 |
| 92 | bc_put_u16_le prefix 2 8 |
| 93 | put prefix 4 0x01 |
| 94 | |
| 95 | dp_def = new uchar 128 0 |
| 96 | len_def = bc_build_file_dp prefix t_dp_path_def dp_def |
| 97 | if eq len_def 0 |
| 98 | ret 20 |
| 99 | end |
| 100 | if ne bc_dp_prefix_len part dp_def 0 len_def 8 |
| 101 | ret 21 |
| 102 | end |
| 103 | if ne bc_dp_detect_role part dp_def 0 len_def BC_ROLE_DEFAULT_OS |
| 104 | ret 22 |
| 105 | end |
| 106 | |
| 107 | dp_cand = new uchar 128 0 |
| 108 | len_cand = bc_build_file_dp prefix t_dp_path_cand dp_cand |
| 109 | if eq len_cand 0 |
| 110 | ret 23 |
| 111 | end |
| 112 | if ne bc_dp_detect_role part dp_cand 0 len_cand BC_ROLE_CANDIDATE |
| 113 | ret 24 |
| 114 | end |
| 115 | |
| 116 | dp_stg = new uchar 128 0 |
| 117 | len_stg = bc_build_file_dp prefix t_dp_path_stager dp_stg |
| 118 | if ne bc_dp_detect_role part dp_stg 0 len_stg BC_ROLE_STAGER |
| 119 | ret 25 |
| 120 | end |
| 121 | |
| 122 | note Build EFI_LOAD_OPTION and verify header fields |
| 123 | opt = new uchar 256 0 |
| 124 | opt_len = bc_build_load_option bc_rb_desc_default part dp_def 0 len_def opt |
| 125 | if eq opt_len 0 |
| 126 | ret 26 |
| 127 | end |
| 128 | if ne bc_get_u32_le opt 0 BC_LOAD_OPTION_ACTIVE |
| 129 | ret 27 |
| 130 | end |
| 131 | if ne ulong bc_get_u16_le opt 4 len_def |
| 132 | ret 28 |
| 133 | end |
| 134 | note Description is "Default Linux OS" (16 chars + null = 34 bytes at offset 6..40) |
| 135 | if ne get opt 6 68 |
| 136 | ret 29 |
| 137 | end |
| 138 | if ne get opt 7 0 |
| 139 | ret 30 |
| 140 | end |
| 141 | if ne bc_get_u16_le opt 38 0 |
| 142 | ret 31 |
| 143 | end |
| 144 | note Mode parsing |
| 145 | if ne bc_rollback_parse_mode t_mode_fault BC_MODE_FAULT |
| 146 | ret 32 |
| 147 | end |
| 148 | if ne bc_rollback_parse_mode t_mode_timeout BC_MODE_TIMEOUT |
| 149 | ret 33 |
| 150 | end |
| 151 | if ne bc_rollback_parse_mode t_mode_absent BC_MODE_ABSENT |
| 152 | ret 34 |
| 153 | end |
| 154 | if ne bc_rollback_parse_mode t_mode_malformed BC_MODE_MALFORMED |
| 155 | ret 35 |
| 156 | end |
| 157 | if ne bc_rollback_parse_mode t_mode_real BC_MODE_REAL_AIENOS |
| 158 | ret 36 |
| 159 | end |
| 160 | if ne bc_rollback_parse_mode t_mode_normal BC_MODE_NORMAL |
| 161 | ret 37 |
| 162 | end |
| 163 | ret 0 |
| 164 | end |
| 165 | |
| 166 | fn test_rollback_state_machine to int |
| 167 | st = new ulong 9 0 |
| 168 | bc_rollback_init st |
| 169 | note Empty prefix rejected |
| 170 | if ne bc_rollback_stager st BC_MODE_NORMAL 0 BC_RB_ACTION_UNSUPPORTED |
| 171 | ret 40 |
| 172 | end |
| 173 | note Stage normal rollback |
| 174 | if ne bc_rollback_stager st BC_MODE_NORMAL 8 BC_RB_ACTION_COLD_RESET_OK |
| 175 | ret 41 |
| 176 | end |
| 177 | note First firmware boot consumes BootNext -> Candidate (0x0000) |
| 178 | if ne bc_rollback_firmware_boot st BC_BOOT_CANDIDATE |
| 179 | ret 42 |
| 180 | end |
| 181 | if ne get st BC_RB_BOOT_NEXT_PRESENT 0 |
| 182 | ret 43 |
| 183 | end |
| 184 | note Candidate normal termination -> cold reset |
| 185 | if ne bc_rollback_candidate st BC_MODE_NORMAL BC_RB_ACTION_COLD_RESET_OK |
| 186 | ret 44 |
| 187 | end |
| 188 | if ne bc_rollback_candidate st BC_MODE_FAULT BC_RB_ACTION_COLD_RESET_ABORT |
| 189 | ret 45 |
| 190 | end |
| 191 | if ne bc_rollback_candidate st BC_MODE_TIMEOUT BC_RB_ACTION_HANG |
| 192 | ret 46 |
| 193 | end |
| 194 | note Second firmware boot falls back to BootOrder[0] -> Default (0x0001) |
| 195 | if ne bc_rollback_firmware_boot st BC_BOOT_DEFAULT |
| 196 | ret 47 |
| 197 | end |
| 198 | note First return to Default OS: cycle 0 -> 1, triggers repeat boot |
| 199 | if ne bc_rollback_default st BC_RB_ACTION_COLD_RESET_REPEAT |
| 200 | ret 48 |
| 201 | end |
| 202 | if ne get st BC_RB_INVARIANT_MASK 3 |
| 203 | ret 49 |
| 204 | end |
| 205 | if ne get st BC_RB_CYCLE 1 |
| 206 | ret 50 |
| 207 | end |
| 208 | note Third firmware boot: repeat boot into Default OS -> SHUTDOWN_PASS |
| 209 | if ne bc_rollback_firmware_boot st BC_BOOT_DEFAULT |
| 210 | ret 51 |
| 211 | end |
| 212 | if ne bc_rollback_default st BC_RB_ACTION_SHUTDOWN_PASS |
| 213 | ret 52 |
| 214 | end |
| 215 | ret 0 |
| 216 | end |
| 217 | |
| 218 | fn test_store_qual_and_bounded_nvme to int |
| 219 | if not bc_is_recovery_mode BC_MODE_RECOVERY_INSPECT |
| 220 | ret 60 |
| 221 | end |
| 222 | if not bc_is_recovery_mode BC_MODE_RECOVERY_REPAIR |
| 223 | ret 61 |
| 224 | end |
| 225 | if not bc_is_recovery_mode BC_MODE_RECOVERY_PROVISION |
| 226 | ret 62 |
| 227 | end |
| 228 | if bc_is_recovery_mode BC_MODE_CONT_PROVISION |
| 229 | ret 63 |
| 230 | end |
| 231 | if not bc_is_continuity_mode BC_MODE_CONT_PROVISION |
| 232 | ret 64 |
| 233 | end |
| 234 | if not bc_is_continuity_mode BC_MODE_CONT_CRASH |
| 235 | ret 65 |
| 236 | end |
| 237 | if bc_is_continuity_mode BC_MODE_VERIFY |
| 238 | ret 66 |
| 239 | end |
| 240 | if not bc_is_512_qual_mode BC_MODE_RUN_512B |
| 241 | ret 67 |
| 242 | end |
| 243 | if not bc_is_512_qual_mode BC_MODE_VERIFY_512B |
| 244 | ret 68 |
| 245 | end |
| 246 | if ne bc_store_config_lba 512 BC_CONFIG_LBA_512 |
| 247 | ret 69 |
| 248 | end |
| 249 | if ne bc_store_config_lba 4096 BC_CONFIG_LBA |
| 250 | ret 70 |
| 251 | end |
| 252 | |
| 253 | note BoundedNvme translation and bounds checks |
| 254 | dev = new ulong 3 0 |
| 255 | out_lba = new ulong 1 0 |
| 256 | bc_bounded_nvme_init dev 4096 BC_STORE_BASE_LBA BC_STORE_REGION_BLOCKS |
| 257 | if ne bc_bounded_nvme_translate dev 0 4096 out_lba BC_BLK_OK |
| 258 | ret 71 |
| 259 | end |
| 260 | if ne get out_lba 0 64 |
| 261 | ret 72 |
| 262 | end |
| 263 | if ne bc_bounded_nvme_translate dev 255 4096 out_lba BC_BLK_OK |
| 264 | ret 73 |
| 265 | end |
| 266 | if ne get out_lba 0 319 |
| 267 | ret 74 |
| 268 | end |
| 269 | if ne bc_bounded_nvme_translate dev 256 4096 out_lba BC_BLK_ERR_OUT_OF_RANGE |
| 270 | ret 75 |
| 271 | end |
| 272 | if ne bc_bounded_nvme_translate dev 0 100 out_lba BC_BLK_ERR_INVALID_INPUT |
| 273 | ret 76 |
| 274 | end |
| 275 | if ne bc_bounded_nvme_translate dev 0xffffffffffffffff 4096 out_lba BC_BLK_ERR_OUT_OF_RANGE |
| 276 | ret 77 |
| 277 | end |
| 278 | |
| 279 | note Geometry validation |
| 280 | if ne bc_store_qual_check_geometry 4096 BC_MODE_VERIFY 1024 true BC_QUAL_OK |
| 281 | ret 78 |
| 282 | end |
| 283 | if ne bc_store_qual_check_geometry 4096 BC_MODE_VERIFY 1024 false BC_QUAL_ERR_NOT_ATOMIC |
| 284 | ret 79 |
| 285 | end |
| 286 | if ne bc_store_qual_check_geometry 512 BC_MODE_RUN_512B 4096 false BC_QUAL_OK |
| 287 | ret 80 |
| 288 | end |
| 289 | if ne bc_store_qual_check_geometry 4096 BC_MODE_RUN_512B 4096 true BC_QUAL_ERR_512_NEEDS_512 |
| 290 | ret 81 |
| 291 | end |
| 292 | if ne bc_store_qual_check_geometry 512 BC_MODE_VERIFY 4096 true BC_QUAL_ERR_4096_REQUIRED |
| 293 | ret 82 |
| 294 | end |
| 295 | if ne bc_store_qual_check_geometry 4096 BC_MODE_VERIFY 100 true BC_QUAL_ERR_REGION_OOB |
| 296 | ret 83 |
| 297 | end |
| 298 | if not bc_store_reopen_gen_valid 4 2 |
| 299 | ret 84 |
| 300 | end |
| 301 | if bc_store_reopen_gen_valid 5 2 |
| 302 | ret 85 |
| 303 | end |
| 304 | if not bc_store_slot_reuse_proven 4 3 |
| 305 | ret 86 |
| 306 | end |
| 307 | if bc_store_slot_reuse_proven 3 3 |
| 308 | ret 87 |
| 309 | end |
| 310 | ret 0 |
| 311 | end |
| 312 | |
| 313 | fn test_nvme_dma_and_sentinel to int |
| 314 | note PCI requester ID and BME helpers |
| 315 | if ne bc_pci_requester_id 1 2 3 0x0113 |
| 316 | ret 90 |
| 317 | end |
| 318 | if bc_pci_bme_enabled 0x0002 |
| 319 | ret 91 |
| 320 | end |
| 321 | if not bc_pci_bme_enabled 0x0006 |
| 322 | ret 92 |
| 323 | end |
| 324 | if ne bc_pci_without_bme 0x0007 0x0003 |
| 325 | ret 93 |
| 326 | end |
| 327 | if ne bc_pci_with_bme 0x0003 0x0007 |
| 328 | ret 94 |
| 329 | end |
| 330 | |
| 331 | note DMA grant gate (M3 rule: no SMMU confinement means no DMA) |
| 332 | if ne bc_dma_grant true true false BC_DMA_GRANT_CONFINED |
| 333 | ret 95 |
| 334 | end |
| 335 | if ne bc_dma_grant false true true BC_DMA_DENIED_SMMU_NOT_READY |
| 336 | ret 96 |
| 337 | end |
| 338 | if ne bc_dma_grant false false false BC_DMA_DENIED_NO_SMMU |
| 339 | ret 97 |
| 340 | end |
| 341 | if ne bc_dma_grant false false true BC_DMA_GRANT_UNSAFE_BYPASS |
| 342 | ret 98 |
| 343 | end |
| 344 | |
| 345 | note NVMe BAR decoder |
| 346 | if ne bc_nvme_decode_bar 0x01080200 0x10000004 0x00000002 0x0000000210000000 |
| 347 | ret 99 |
| 348 | end |
| 349 | if ne bc_nvme_decode_bar 0x01080200 0xfe000000 0x00000000 0xfe000000 |
| 350 | ret 100 |
| 351 | end |
| 352 | if ne bc_nvme_decode_bar 0x0c033000 0xfe000000 0x00000000 0 |
| 353 | ret 101 |
| 354 | end |
| 355 | if ne bc_nvme_decode_bar 0x01080200 0x0000c001 0x00000000 0 |
| 356 | ret 102 |
| 357 | end |
| 358 | |
| 359 | note NativeDma bump arena |
| 360 | arena = new ulong 3 0 |
| 361 | phys = new ulong 1 0 |
| 362 | off = new ulong 1 0 |
| 363 | bc_dma_arena_init arena 0x40000000 BC_NVME_ARENA_BYTES |
| 364 | if ne bc_dma_arena_alloc arena 100 4096 phys 0 |
| 365 | ret 103 |
| 366 | end |
| 367 | if ne get phys 0 0x40000000 |
| 368 | ret 104 |
| 369 | end |
| 370 | if ne bc_dma_arena_alloc arena 4096 4096 phys 0 |
| 371 | ret 105 |
| 372 | end |
| 373 | if ne get phys 0 0x40001000 |
| 374 | ret 106 |
| 375 | end |
| 376 | if ne bc_dma_arena_alloc arena 64 3 phys -1 |
| 377 | ret 107 |
| 378 | end |
| 379 | if ne bc_dma_arena_offset arena 0x40001000 4096 off 0 |
| 380 | ret 108 |
| 381 | end |
| 382 | if ne get off 0 4096 |
| 383 | ret 109 |
| 384 | end |
| 385 | if ne bc_dma_arena_offset arena 0x3fffffff 4 off -1 |
| 386 | ret 110 |
| 387 | end |
| 388 | if ne bc_dma_arena_offset arena 0x4007ff00 512 off -1 |
| 389 | ret 111 |
| 390 | end |
| 391 | |
| 392 | note Sentinel pattern fill, verify, and SHA-256 hex digest |
| 393 | sec = new uchar 512 0 |
| 394 | hex = new uchar 64 0 |
| 395 | if not bc_nvme_fill_sector_pattern sec bc_nvme_sentinel_magic |
| 396 | ret 112 |
| 397 | end |
| 398 | if not bc_nvme_verify_sector_pattern sec bc_nvme_sentinel_magic |
| 399 | ret 113 |
| 400 | end |
| 401 | if ne bc_nvme_sector_sha256_hex sec hex 64 |
| 402 | ret 114 |
| 403 | end |
| 404 | note Mutate one byte and confirm verify fails and digest changes |
| 405 | put sec 511 xor get sec 511 1 |
| 406 | if bc_nvme_verify_sector_pattern sec bc_nvme_sentinel_magic |
| 407 | ret 115 |
| 408 | end |
| 409 | hex2 = new uchar 64 0 |
| 410 | if ne bc_nvme_sector_sha256_hex sec hex2 64 |
| 411 | ret 116 |
| 412 | end |
| 413 | if bc_bytes_eq hex hex2 |
| 414 | ret 117 |
| 415 | end |
| 416 | |
| 417 | note Continuity cortex statement hash |
| 418 | ctx = new ulong 40 0 |
| 419 | dig = new uchar 32 0 |
| 420 | sha256_init ctx |
| 421 | bc_continuity_hash_statement ctx t_stmt_1 |
| 422 | sha256_final ctx dig |
| 423 | nonzero = false |
| 424 | for i ulong 32 |
| 425 | if ne get dig i 0 |
| 426 | nonzero = true |
| 427 | end |
| 428 | end |
| 429 | if not nonzero |
| 430 | ret 118 |
| 431 | end |
| 432 | ret 0 |
| 433 | end |
| 434 | |
| 435 | fn test_usb_keyboard to int |
| 436 | if ne bc_xhci_mmio_base 0x0c033000 0x10000004 0x00000001 0x0000000110000000 |
| 437 | ret 120 |
| 438 | end |
| 439 | if ne bc_xhci_mmio_base 0x0c032000 0x10000004 0x00000001 0 |
| 440 | ret 121 |
| 441 | end |
| 442 | |
| 443 | prev = new uchar 6 0 |
| 444 | rep = new uchar 8 0 |
| 445 | kinds = new uchar 6 0 |
| 446 | chars = new uchar 6 0 |
| 447 | line = new uchar 128 0 |
| 448 | llen = new ulong 1 0 |
| 449 | |
| 450 | note Press 'h' (0x0b), 'i' (0x0c) |
| 451 | put rep 0 0 |
| 452 | put rep 2 0x0b |
| 453 | put rep 3 0x0c |
| 454 | n1 = bc_hid_decode_report prev rep kinds chars |
| 455 | if ne n1 2 |
| 456 | ret 122 |
| 457 | end |
| 458 | if ne get kinds 0 BC_KEY_CHAR |
| 459 | ret 123 |
| 460 | end |
| 461 | if ne get chars 0 104 |
| 462 | ret 124 |
| 463 | end |
| 464 | if ne get chars 1 105 |
| 465 | ret 125 |
| 466 | end |
| 467 | for i ulong n1 bound 6 |
| 468 | r = bc_kb_line_apply line llen get kinds i get chars i |
| 469 | if ne r 0 |
| 470 | ret 126 |
| 471 | end |
| 472 | end |
| 473 | |
| 474 | note Hold 'i' (0x0c) and press Shift+'1' ('!') |
| 475 | put rep 0 0x02 |
| 476 | put rep 2 0x0c |
| 477 | put rep 3 0x1e |
| 478 | n2 = bc_hid_decode_report prev rep kinds chars |
| 479 | if ne n2 1 |
| 480 | ret 127 |
| 481 | end |
| 482 | if ne get chars 0 33 |
| 483 | ret 128 |
| 484 | end |
| 485 | r2 = bc_kb_line_apply line llen get kinds 0 get chars 0 |
| 486 | if ne r2 0 |
| 487 | ret 129 |
| 488 | end |
| 489 | if ne get llen 0 3 |
| 490 | ret 130 |
| 491 | end |
| 492 | |
| 493 | note ErrorRollOver report (0x01) must be ignored |
| 494 | put rep 2 0x01 |
| 495 | put rep 3 0 |
| 496 | n3 = bc_hid_decode_report prev rep kinds chars |
| 497 | if ne n3 0 |
| 498 | ret 131 |
| 499 | end |
| 500 | |
| 501 | note Backspace removes '!', leaving "hi" |
| 502 | put rep 0 0 |
| 503 | put rep 2 0x2a |
| 504 | n4 = bc_hid_decode_report prev rep kinds chars |
| 505 | if ne n4 1 |
| 506 | ret 132 |
| 507 | end |
| 508 | if ne get kinds 0 BC_KEY_BACKSPACE |
| 509 | ret 133 |
| 510 | end |
| 511 | r4 = bc_kb_line_apply line llen get kinds 0 get chars 0 |
| 512 | if ne r4 0 |
| 513 | ret 134 |
| 514 | end |
| 515 | if ne get llen 0 2 |
| 516 | ret 135 |
| 517 | end |
| 518 | |
| 519 | note Enter signals line complete |
| 520 | put rep 2 0x28 |
| 521 | n5 = bc_hid_decode_report prev rep kinds chars |
| 522 | if ne n5 1 |
| 523 | ret 136 |
| 524 | end |
| 525 | if ne get kinds 0 BC_KEY_ENTER |
| 526 | ret 137 |
| 527 | end |
| 528 | if ne bc_kb_line_apply line llen get kinds 0 get chars 0 1 |
| 529 | ret 138 |
| 530 | end |
| 531 | if ne get line 0 104 |
| 532 | ret 139 |
| 533 | end |
| 534 | if ne get line 1 105 |
| 535 | ret 140 |
| 536 | end |
| 537 | |
| 538 | note Stop reason classification |
| 539 | if ne bc_kb_stop_reason true false BC_KB_DONE_EXIT |
| 540 | ret 141 |
| 541 | end |
| 542 | if ne bc_kb_stop_reason false true BC_KB_DONE_HALTED |
| 543 | ret 142 |
| 544 | end |
| 545 | if ne bc_kb_stop_reason false false BC_KB_DONE_TIMEOUT |
| 546 | ret 143 |
| 547 | end |
| 548 | ret 0 |
| 549 | end |
| 550 | |
| 551 | fn test_handoff_logic to int |
| 552 | note Post-exit heap allocator |
| 553 | heap = new ulong 3 0 |
| 554 | addr = new ulong 1 0 |
| 555 | bc_heap_init heap 0x80000000 mul BC_POST_EXIT_HEAP_PAGES 4096 |
| 556 | if ne bc_heap_alloc heap 64 256 addr 0 |
| 557 | ret 150 |
| 558 | end |
| 559 | if ne get addr 0 0x80000000 |
| 560 | ret 151 |
| 561 | end |
| 562 | if ne bc_heap_alloc heap 128 256 addr 0 |
| 563 | ret 152 |
| 564 | end |
| 565 | if ne get addr 0 0x80000100 |
| 566 | ret 153 |
| 567 | end |
| 568 | if ne bc_heap_alloc heap 16 3 addr -1 |
| 569 | ret 154 |
| 570 | end |
| 571 | |
| 572 | note SMMU alignment and stream ID validation |
| 573 | if not bc_smmu_validate 0x80040000 12 |
| 574 | ret 155 |
| 575 | end |
| 576 | if bc_smmu_validate 0x80001000 12 |
| 577 | ret 156 |
| 578 | end |
| 579 | if bc_smmu_validate 0x80040000 4096 |
| 580 | ret 157 |
| 581 | end |
| 582 | |
| 583 | note MAT header length |
| 584 | mat = new uchar 16 0 |
| 585 | bc_put_u32_le mat 4 10 |
| 586 | bc_put_u32_le mat 8 48 |
| 587 | if ne bc_mat_header_length mat 496 |
| 588 | ret 158 |
| 589 | end |
| 590 | bc_put_u32_le mat 4 100000 |
| 591 | bc_put_u32_le mat 8 48 |
| 592 | if ne bc_mat_header_length mat 0 |
| 593 | ret 159 |
| 594 | end |
| 595 | |
| 596 | note Page-aligned MMIO range |
| 597 | rng = new ulong 2 0 |
| 598 | if not bc_page_align_range 0x10000100 0x1000 rng |
| 599 | ret 160 |
| 600 | end |
| 601 | if ne get rng 0 0x10000000 |
| 602 | ret 161 |
| 603 | end |
| 604 | if ne get rng 1 0x2000 |
| 605 | ret 162 |
| 606 | end |
| 607 | |
| 608 | note EL1 MMU switch verification |
| 609 | if not bc_mmu_switched 1 true 0x0001000040000000 0x0000000030000000 0x40000000 |
| 610 | ret 163 |
| 611 | end |
| 612 | if bc_mmu_switched 2 true 0x40000000 0x30000000 0x40000000 |
| 613 | ret 164 |
| 614 | end |
| 615 | if bc_mmu_switched 1 true 0x40000000 0x40000000 0x40000000 |
| 616 | ret 165 |
| 617 | end |
| 618 | |
| 619 | note Timer ticks to us |
| 620 | if ne bc_timer_ticks_to_us 62500000 62500000 1000000 |
| 621 | ret 166 |
| 622 | end |
| 623 | if ne bc_timer_ticks_to_us 625000 62500000 10000 |
| 624 | ret 167 |
| 625 | end |
| 626 | if ne bc_timer_ticks_to_us 100 0 0 |
| 627 | ret 168 |
| 628 | end |
| 629 | |
| 630 | note ADR 0008 NVRAM write budget |
| 631 | b = new ulong 3 0 |
| 632 | bc_var_budget_init b BC_MAX_VAR_WRITES BC_MAX_VAR_BYTES |
| 633 | if ne bc_var_budget_try_write b 4096 BC_VAR_ERR_TOO_LARGE |
| 634 | ret 169 |
| 635 | end |
| 636 | if ne bc_var_budget_try_write b 100 1 |
| 637 | ret 170 |
| 638 | end |
| 639 | if ne bc_var_budget_try_write b 200 2 |
| 640 | ret 171 |
| 641 | end |
| 642 | if ne bc_var_budget_try_write b 300 3 |
| 643 | ret 172 |
| 644 | end |
| 645 | if ne bc_var_budget_try_write b 100 BC_VAR_ERR_BUDGET_SPENT |
| 646 | ret 173 |
| 647 | end |
| 648 | |
| 649 | note Artifact name validation (UTF-16 -> ASCII, .aien case-insensitive) |
| 650 | aw = new ushort 11 0 |
| 651 | put aw 0 65 |
| 652 | put aw 1 46 |
| 653 | put aw 2 65 |
| 654 | put aw 3 73 |
| 655 | put aw 4 69 |
| 656 | put aw 5 78 |
| 657 | put aw 6 0 |
| 658 | aname = new uchar 32 0 |
| 659 | if ne bc_artifact_name_valid aw aname 6 |
| 660 | ret 174 |
| 661 | end |
| 662 | put aw 2 88 |
| 663 | if ne bc_artifact_name_valid aw aname 0 |
| 664 | ret 175 |
| 665 | end |
| 666 | if bc_artifact_oversize BC_MAX_ARTIFACT_FILE_BYTES |
| 667 | ret 176 |
| 668 | end |
| 669 | if not bc_artifact_oversize add BC_MAX_ARTIFACT_FILE_BYTES 1 |
| 670 | ret 177 |
| 671 | end |
| 672 | |
| 673 | note Sorted artifact candidate insertion (insert charlie, alpha, beta -> alpha, beta, charlie) |
| 674 | entries = new uchar 2304 0 |
| 675 | meta = new ulong 2 0 |
| 676 | c1 = bc_artifact_insert_sorted entries meta t_art_c 300 |
| 677 | c2 = bc_artifact_insert_sorted entries meta t_art_a 100 |
| 678 | c3 = bc_artifact_insert_sorted entries meta t_art_b 200 |
| 679 | if ne c1 1 |
| 680 | ret 178 |
| 681 | end |
| 682 | if ne c2 2 |
| 683 | ret 179 |
| 684 | end |
| 685 | if ne c3 3 |
| 686 | ret 180 |
| 687 | end |
| 688 | if ne get entries 0 97 |
| 689 | ret 181 |
| 690 | end |
| 691 | if ne get entries 48 98 |
| 692 | ret 182 |
| 693 | end |
| 694 | if ne get entries 96 99 |
| 695 | ret 183 |
| 696 | end |
| 697 | if ne bc_get_u64_le entries 40 100 |
| 698 | ret 184 |
| 699 | end |
| 700 | |
| 701 | note RSDP 2.0 validation |
| 702 | rsdp = new uchar 36 0 |
| 703 | for i ulong 8 |
| 704 | put rsdp i get bc_rsdp_sig i |
| 705 | end |
| 706 | bc_put_u64_le rsdp 24 0x00000000bf001000 |
| 707 | if ne bc_rsdp_xsdt_addr rsdp 0x00000000bf001000 |
| 708 | ret 185 |
| 709 | end |
| 710 | put rsdp 0 88 |
| 711 | if ne bc_rsdp_xsdt_addr rsdp 0 |
| 712 | ret 186 |
| 713 | end |
| 714 | |
| 715 | note Stage, EL0, and preemption predicates |
| 716 | if not bc_stage_valid BC_STAGE_COUNTDOWN |
| 717 | ret 187 |
| 718 | end |
| 719 | if bc_stage_valid BC_STAGE_COUNT |
| 720 | ret 188 |
| 721 | end |
| 722 | if not bc_el0_report_ok true true true 0 |
| 723 | ret 189 |
| 724 | end |
| 725 | if bc_el0_report_ok true true true 1 |
| 726 | ret 190 |
| 727 | end |
| 728 | if not bc_preempt_ok 1 1 4 |
| 729 | ret 191 |
| 730 | end |
| 731 | if bc_preempt_ok 1 1 3 |
| 732 | ret 192 |
| 733 | end |
| 734 | ret 0 |
| 735 | end |
| 736 | |
| 737 | fn main to int |
| 738 | r1 = test_lib_and_wcslen |
| 739 | if ne r1 0 |
| 740 | ret r1 |
| 741 | end |
| 742 | r2 = test_rollback_dp_and_load_opt |
| 743 | if ne r2 0 |
| 744 | ret r2 |
| 745 | end |
| 746 | r3 = test_rollback_state_machine |
| 747 | if ne r3 0 |
| 748 | ret r3 |
| 749 | end |
| 750 | r4 = test_store_qual_and_bounded_nvme |
| 751 | if ne r4 0 |
| 752 | ret r4 |
| 753 | end |
| 754 | r5 = test_nvme_dma_and_sentinel |
| 755 | if ne r5 0 |
| 756 | ret r5 |
| 757 | end |
| 758 | r6 = test_usb_keyboard |
| 759 | if ne r6 0 |
| 760 | ret r6 |
| 761 | end |
| 762 | r7 = test_handoff_logic |
| 763 | if ne r7 0 |
| 764 | ret r7 |
| 765 | end |
| 766 | ret 0 |
| 767 | end |