Skip to main content

ostd/boot/
mod.rs

1// SPDX-License-Identifier: MPL-2.0
2//! The architecture-independent boot module, which provides
3//!  1. a universal information getter interface from the bootloader to the
4//!     rest of OSTD;
5//!  2. the routine booting into the actual kernel;
6//!  3. the routine booting the other processors in the SMP context.
7use vstd::prelude::*;
8
9pub mod memory_region;
10//pub mod smp;
11
12/* use alloc::{
13    string::{String, ToString},
14    vec::Vec,
15}; */
16
17use memory_region::{MemoryRegion, MemoryRegionArray};
18use spin::Once;
19
20/*
21/// The boot information provided by the bootloader.
22pub struct BootInfo {
23    /// The name of the bootloader.
24    pub bootloader_name: String,
25    /// The kernel command line arguments.
26    pub kernel_cmdline: String,
27    /// The initial ramfs raw bytes.
28    pub initramfs: Option<&'static [u8]>,
29    /// The framebuffer arguments.
30    pub framebuffer_arg: Option<BootloaderFramebufferArg>,
31    /// The memory regions provided by the bootloader.
32    pub memory_regions: Vec<MemoryRegion>,
33}
34
35/// Gets the boot information.
36//
37// This function is usable after initialization with `init_after_heap`.
38pub fn boot_info() -> &'static BootInfo {
39    INFO.get().unwrap()
40}
41
42static INFO: Once<BootInfo> = Once::new();
43*/
44/// ACPI information from the bootloader.
45///
46/// The boot crate can choose either providing the raw RSDP physical address or
47/// providing the RSDT/XSDT physical address after parsing RSDP.
48/// This is because bootloaders differ in such behaviors.
49#[derive(Copy, Clone, Debug)]
50pub enum BootloaderAcpiArg {
51    /// The bootloader does not provide one, a manual search is needed.
52    NotProvided,
53    /// Physical address of the RSDP.
54    Rsdp(usize),
55    /// Address of RSDT provided in RSDP v1.
56    Rsdt(usize),
57    /// Address of XSDT provided in RSDP v2+.
58    Xsdt(usize),
59}
60
61/// The framebuffer arguments.
62#[verus_verify]
63#[derive(Copy, Clone, Debug)]
64pub struct BootloaderFramebufferArg {
65    /// The address of the buffer.
66    pub address: usize,
67    /// The width of the buffer.
68    pub width: usize,
69    /// The height of the buffer.
70    pub height: usize,
71    /// Bits per pixel of the buffer.
72    pub bpp: usize,
73}
74
75/*************************** Boot-time information ***************************/
76
77/// The boot-time boot information.
78///
79/// When supporting multiple boot protocols with a single build, the entrypoint
80/// and boot information getters are dynamically decided. The entry point
81/// function should initializer all arguments at [`EARLY_INFO`].
82///
83/// All the references in this structure should be valid in the boot context.
84/// After the kernel is booted, users should use [`BootInfo`] instead.
85pub(crate) struct EarlyBootInfo {
86    pub(crate) bootloader_name: &'static str,
87    pub(crate) kernel_cmdline: &'static str,
88    pub(crate) initramfs: Option<&'static [u8]>,
89    pub(crate) acpi_arg: BootloaderAcpiArg,
90    pub(crate) framebuffer_arg: Option<BootloaderFramebufferArg>,
91    pub(crate) memory_regions: MemoryRegionArray,
92}
93
94/// The boot-time information.
95pub(crate) static EARLY_INFO: Once<EarlyBootInfo> = Once::new();
96
97/*
98/// Initializes the boot information.
99///
100/// This function copies the boot-time accessible information to the heap to
101/// allow [`boot_info`] to work properly.
102pub(crate) fn init_after_heap() {
103    let boot_time_info = EARLY_INFO.get().unwrap();
104
105    INFO.call_once(|| BootInfo {
106        bootloader_name: boot_time_info.bootloader_name.to_string(),
107        kernel_cmdline: boot_time_info.kernel_cmdline.to_string(),
108        initramfs: boot_time_info.initramfs,
109        framebuffer_arg: boot_time_info.framebuffer_arg,
110        memory_regions: boot_time_info.memory_regions.to_vec(),
111    });
112}
113
114/// Calls the OSTD-user defined entrypoint of the actual kernel.
115///
116/// Any kernel that uses the `ostd` crate should define a function marked with
117/// `ostd::main` as the entrypoint.
118///
119/// This function should be only called from the bootloader-specific module.
120pub(crate) fn call_ostd_main() -> ! {
121    // The entry point of kernel code, which should be defined by the package that
122    // uses OSTD.
123    extern "Rust" {
124        fn __ostd_main() -> !;
125    }
126
127    // SAFETY: The function is called only once on the BSP.
128    unsafe { crate::init() };
129
130    // SAFETY: This external function is defined by the package that uses OSTD,
131    // which should be generated by the `ostd::main` macro. So it is safe.
132    unsafe {
133        __ostd_main();
134    }
135}
136*/