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/efi_boot.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 / efi_boot.om` 223 lines ยท 6436 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/kernel/arm64/efi_boot.om: Pure-Omega Bare-Metal Aienux UEFI Boot Entry (Piece 1 / Slice A). 3 note Concatenated after: target a64efi, om2, seed/a64efi/efirt.om, fwops.om, uart.om, frames.om, 4 note acpi.om, mmu.om, gicv3.om, smp.om. 5 note Flow: 6 note 1. Disable UEFI watchdog, find ACPI 2.0 RSDP via UEFI ConfigurationTable (efcfg) 7 note 2. GetMemoryMap (64 KiB static buffer) + ExitBootServices retry loop (max 8 attempts) 8 note 3. Mask DAIF + arm post_ebs guard (never calls dead UEFI services on trap/exit) 9 note 4. Parse ACPI RSDP -> XSDT -> MADT (20 cores, GICD, GICR, GITS), FADT (PSCI), SPCR (UART), MCFG, IORT 10 note 5. Init UART (SPCR or Spark 0x16A00000), ingest EfiConventionalMemory + reserve non-conv/image/RMRs 11 note 6. Build Stage-1 MMU (MAIR=0x440004ff, pre-carved Normal-NC pool, W^X image, IPS >= 40-bit) 12 note 7. EL2 -> EL1h eret (immediate ISB after HCR_EL2.E2H=0, CNTVOFF_EL2=0, TLBI VMALLE1IS) 13 note 8. In el1main: init GICv3 + ITS, bring up all 20 cores via PSCI CPU_ON, print BootHandoff, reset via PSCI. 14 15 const EFI_MMAP_CAP ulong 65536 16 global efi_mmap uchar 65536 17 note efi_mm_out (8 * u64 = 64 bytes): 0=map_size, 8=map_key, 16=desc_size, 24=desc_ver, 32=exit_attempts, 40=rsdp_pa, 48=boot_el 18 global efi_mm_out uchar 64 19 20 text b_hdr "\nAIENUX_A64EFI_BOOT_START\n" 21 text b_el1 "EL1_ALIVE current_el=" 22 text b_mair " mair=0x" 23 text b_sctlr " sctlr=0x" 24 text b_tcr " tcr=0x" 25 text b_ram " free_mib=" 26 text b_nc " nc_pool_pa=0x" 27 text b_ncsz " nc_pool_mib=" 28 text b_gic " GICV3_OK rev=" 29 text b_gicf " GICV3_FAIL\n" 30 text b_its " ITS_OK cmds=" 31 text b_itsf " ITS_SKIP\n" 32 text b_sys " SYSRD_WR_OK=1" 33 text b_bbm " BBM_4K_2M_OK=1" 34 text b_smp " SMP_ONLINE online=" 35 text b_exp " expected=" 36 text b_fail " failed=" 37 text b_mcfg " mcfg_segs=" 38 text b_ms " boot_ms=" 39 text b_pass "\nSLICE_A_QEMU_BOOT_PASS\n" 40 text b_fail_sum "\nSLICE_A_QEMU_BOOT_FAIL\n" 41 42 note ACPI 2.0 Table GUID: `8868e871`-e4f1-11d3-bc22-`0080c73c8881` 43 note Little-endian halves: a = 0x11d3e4f18868e871, b = 0x81883cc7800022bc 44 fn efi_find_acpi2_rsdp to ulong 45 ret efcfg 0x11d3e4f18868e871 0x81883cc7800022bc 46 end 47 48 note UEFI BootServices offsets (UEFI 2.10 Table 4-3): 49 note 56 GetMemoryMap(MemoryMapSize*, MemoryMap, MapKey*, DescriptorSize*, DescriptorVersion*) 50 note 232 ExitBootServices(ImageHandle, MapKey) 51 note 256 SetWatchdogTimer(Timeout, WatchdogCode, DataSize, WatchdogData) 52 fn efi_exit_boot_services to bool 53 bs = efbs 54 ih = fwsys 0 55 x = fwcall fwld add bs 256 8 0 0 0 0 0 0 56 outp = fwadr efi_mm_out 0 64 57 x = fwst add outp 40 8 efi_find_acpi2_rsdp 58 x = fwst add outp 48 8 arm64_current_el 59 gmm = fwld add bs 56 8 60 ebs = fwld add bs 232 8 61 mp = fwadr efi_mmap 0 EFI_MMAP_CAP 62 att = ulong 0 63 while lt att 8 bound 8 64 x = fwst outp 8 EFI_MMAP_CAP 65 s = fwcall gmm outp mp add outp 8 add outp 16 add outp 24 0 66 if ne s 0 67 ret false 68 end 69 s2 = fwcall ebs ih fwld add outp 8 8 0 0 0 0 70 att = add att 1 71 if eq s2 0 72 x = fwst add outp 32 8 att 73 ret true 74 end 75 end 76 ret false 77 end 78 79 note Reserve mandatory GB10 IORT RMR carveouts if present in RAM range. 80 fn reserve_gb10_rmrs to void 81 frames_reserve 0x00000000a1600000 0x00000000b9800000 82 frames_reserve 0x0000000280000000 0x0000000303000000 83 end 84 85 fn el1_self_checks to bool 86 note 1. Verify unified FWOP_SYSRD / FWOP_SYSWR roundtrip on ICC_PMR_EL1 (12) and CNTP_CTL_EL0 (25). 87 pmr = arm64_sysrd SYSREG_ICC_PMR_EL1 88 if ne and pmr 0xf0 0xf0 89 ret false 90 end 91 arm64_syswr SYSREG_CNTP_CTL_EL0 2 92 ctl = arm64_sysrd SYSREG_CNTP_CTL_EL0 93 if ne and ctl 3 2 94 ret false 95 end 96 uart_puts b_sys 97 note 2. Verify mmu_remap_nc_bbm on a 4 KiB-split 2 MiB non-kernel span (must remap at 4 KiB without L2 conflict!). 98 span = frames_alloc 512 MMU_2M FR_PA_40BIT_LIMIT 99 if eq span 0 100 ret false 101 end 102 note Split into 512x 4 KiB L3 leaves by mapping 4 KiB at a time after breaking the 2 MiB block: 103 if not mmu_remap_nc_bbm span MMU_2M 104 ret false 105 end 106 uart_puts b_bbm 107 uart_puts u_nl 108 ret true 109 end 110 111 note el1main: runs at EL1h with Stage-1 MMU active, W^X enforced, pre-carved Normal-NC pool ready. 112 fn el1main arg ulong to void 113 lpi_out = new ulong 1 0 114 uart_puts b_hdr 115 uart_puts b_el1 116 uart_putdec arm64_current_el 117 uart_puts b_mair 118 uart_puthex arm64_sysrd SYSREG_MAIR_EL1 119 uart_puts b_sctlr 120 uart_puthex arm64_sysrd SYSREG_SCTLR_EL1 121 uart_puts b_tcr 122 uart_puthex arm64_sysrd SYSREG_TCR_EL1 123 uart_puts u_nl 124 uart_puts b_ram 125 uart_putdec div frames_free_bytes `1048576` 126 uart_puts b_nc 127 uart_puthex dma_pool_base 128 uart_puts b_ncsz 129 uart_putdec div dma_pool_size `1048576` 130 uart_puts b_mcfg 131 uart_putdec get acpi_info 12 132 uart_puts u_nl 133 gic_ok = gicv3_init get acpi_info 2 get acpi_info 3 get acpi_info 4 get acpi_info 5 134 if gic_ok 135 uart_puts b_gic 136 uart_putdec get gic_state 4 137 uart_puts u_nl 138 else 139 uart_puts b_gicf 140 end 141 its_ok = true 142 if ne get acpi_info 5 0 143 its_ok = gic_its_init 144 if its_ok 145 db = gic_its_map_msix 0x100 8 lpi_out 146 if or ne db add get acpi_info 5 GITS_TRANSLATER ne get lpi_out 0 8192 147 its_ok = false 148 else 149 uart_puts b_its 150 uart_putdec get gic_state 11 151 uart_puts u_nl 152 end 153 end 154 else 155 uart_puts b_itsf 156 end 157 chk_ok = el1_self_checks 158 online = smp_bringup 159 uart_puts b_smp 160 uart_putdec online 161 uart_puts b_exp 162 uart_putdec get smp_stats 1 163 uart_puts b_fail 164 uart_putdec get smp_stats 2 165 uart_puts b_ms 166 uart_putdec arm64_time_ms 167 uart_puts u_nl 168 ok_all = and eq arm64_current_el 1 eq arm64_sysrd SYSREG_MAIR_EL1 MMU_MAIR_EL1 169 ok_all = and ok_all and gic_ok its_ok 170 ok_all = and ok_all and chk_ok eq get smp_stats 2 0 171 if ok_all 172 uart_puts b_pass 173 else 174 uart_puts b_fail_sum 175 end 176 arm64_psci_reset get acpi_info 7 177 i = ulong 0 178 while lt i `9223372036854775807` bound `9223372036854775807` 179 arm64_wfe 180 end 181 end 182 183 fn main to int 184 if not efi_exit_boot_services 185 ret 1 186 end 187 note Post-ExitBootServices: mask DAIF and arm post_ebs guard immediately! 188 arm64_daif_mask 189 arm64_post_ebs_set UART_SPARK_16550_PA PSCI_CONDUIT_NONE 190 outp = fwadr efi_mm_out 0 64 191 rsdp = fwld add outp 40 8 192 ok_acpi = acpi_parse_rsdp rsdp 193 conduit = get acpi_info 7 194 if ne get acpi_info 8 0 195 uart_init get acpi_info 8 get acpi_info 9 conduit 196 else 197 uart_init UART_SPARK_16550_PA UART_KIND_16550_32 conduit 198 end 199 arm64_post_ebs_set uart_base conduit 200 frames_init 201 mp = fwadr efi_mmap 0 EFI_MMAP_CAP 202 cnt = frames_ingest_efi_raw mp fwld outp 8 fwld add outp 16 8 203 if eq cnt 0 204 trap 8 205 end 206 ib = arm64_meta 0 207 bss = arm64_meta 1 208 ie = arm64_meta 2 209 frames_reserve ib ie 210 reserve_gb10_rmrs 211 if ne rsdp 0 212 frames_reserve rsdp add rsdp 4096 213 end 214 if not mmu_build_initial ib bss ie 215 trap 8 216 end 217 e1 = arm64_meta 4 218 if eq e1 0 219 trap 8 220 end 221 mmu_enter_el1 e1 rsdp 222 ret 0 223 end