pie_boot/
lib.rs

1#![cfg_attr(target_os = "none", no_std)]
2#![cfg(target_os = "none")]
3
4#[cfg(target_arch = "aarch64")]
5#[path = "arch/aarch64/mod.rs"]
6mod arch;
7
8mod fdt;
9mod loader;
10mod staticcell;
11
12use heapless::Vec;
13pub use kdef_pgtable::{KIMAGE_VADDR, KLINER_OFFSET};
14use pie_boot_if::EarlyBootArgs;
15pub use pie_boot_if::{BootInfo, MemoryRegion, MemoryRegionKind, MemoryRegions};
16pub use pie_boot_macros::entry;
17#[allow(unused)]
18use pie_boot_macros::start_code;
19use staticcell::StaticCell;
20
21#[allow(unused)]
22static mut BOOT_ARGS: EarlyBootArgs = EarlyBootArgs::new();
23
24#[unsafe(link_section = ".data")]
25static BOOT_INFO: StaticCell<BootInfo> = StaticCell::new(BootInfo::new());
26#[unsafe(link_section = ".data")]
27static MEMORY_REGIONS: StaticCell<Vec<MemoryRegion, 128>> = StaticCell::new(Vec::new());
28
29unsafe extern "Rust" {
30    fn __pie_boot_main(args: &BootInfo);
31}
32
33fn virt_entry(args: &BootInfo) {
34    unsafe {
35        MEMORY_REGIONS.as_mut().clear();
36        let _ = MEMORY_REGIONS
37            .as_mut()
38            .extend_from_slice(&args.memory_regions);
39
40        *BOOT_INFO.as_mut() = args.clone();
41
42        if let Some(ptr) = BOOT_INFO.fdt {
43            fdt::setup(ptr);
44        }
45
46        let regions = core::slice::from_raw_parts_mut(
47            MEMORY_REGIONS.as_mut().as_mut_ptr(),
48            MEMORY_REGIONS.len(),
49        );
50
51        BOOT_INFO.as_mut().memory_regions = regions.into();
52
53        __pie_boot_main(&BOOT_INFO);
54    }
55}
56
57pub fn boot_info() -> &'static BootInfo {
58    &BOOT_INFO
59}