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 / efi_boot.om

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