diff --git a/ostd/src/arch/x86/boot/multiboot/mod.rs b/ostd/src/arch/x86/boot/multiboot/mod.rs index 1523413a3..e202c6654 100644 --- a/ostd/src/arch/x86/boot/multiboot/mod.rs +++ b/ostd/src/arch/x86/boot/multiboot/mod.rs @@ -38,13 +38,10 @@ fn parse_bootloader_name(mb1_info: &MultibootLegacyInfo) -> &str { fn parse_kernel_commandline(mb1_info: &MultibootLegacyInfo) -> &str { let mut cmdline = ""; if mb1_info.cmdline != 0 { + let ptr = paddr_to_vaddr(mb1_info.cmdline as usize) as *const i8; // SAFETY: the command line is C-style zero-terminated string. - unsafe { - let cstr = paddr_to_vaddr(mb1_info.cmdline as usize) as *const i8; - let cstr = core::ffi::CStr::from_ptr(cstr); - - cmdline = cstr.to_str().unwrap(); - } + let cstr = unsafe { core::ffi::CStr::from_ptr(ptr) }; + cmdline = cstr.to_str().unwrap(); } cmdline } diff --git a/ostd/src/boot/mod.rs b/ostd/src/boot/mod.rs index 346111643..589e31a10 100644 --- a/ostd/src/boot/mod.rs +++ b/ostd/src/boot/mod.rs @@ -32,6 +32,8 @@ pub struct BootInfo { } /// Gets the boot information. +/// +/// This function is usable after initialization with [`init_after_heap`]. pub fn boot_info() -> &'static BootInfo { INFO.get().unwrap() } @@ -90,10 +92,11 @@ pub(crate) struct EarlyBootInfo { /// The boot-time information. pub(crate) static EARLY_INFO: Once = Once::new(); -/// Initializes the runtime information. +/// Initializes the boot information. /// -/// This function allows the run-time getters to work properly. -pub(crate) fn init() { +/// This function copies the boot-time accessible information to the heap to +/// allow [`boot_info`] to work properly. +pub(crate) fn init_after_heap() { let boot_time_info = EARLY_INFO.get().unwrap(); INFO.call_once(|| BootInfo { diff --git a/ostd/src/lib.rs b/ostd/src/lib.rs index 15ac2b80b..15cadf8cc 100644 --- a/ostd/src/lib.rs +++ b/ostd/src/lib.rs @@ -75,14 +75,15 @@ unsafe fn init() { #[cfg(feature = "cvm_guest")] arch::init_cvm_guest(); + logger::init(); + // SAFETY: This function is called only once and only on the BSP. unsafe { cpu::local::early_init_bsp_local_base() }; // SAFETY: This function is called only once and only on the BSP. unsafe { mm::heap_allocator::init() }; - boot::init(); - logger::init(); + boot::init_after_heap(); mm::frame::allocator::init(); mm::kspace::init_kernel_page_table(mm::init_page_meta()); diff --git a/ostd/src/logger.rs b/ostd/src/logger.rs index a941e2dc2..af269fbce 100644 --- a/ostd/src/logger.rs +++ b/ostd/src/logger.rs @@ -12,7 +12,7 @@ use core::str::FromStr; use log::{LevelFilter, Metadata, Record}; use spin::Once; -use crate::boot::BOOT_TIME_INFO; +use crate::boot::EARLY_INFO; static LOGGER: Logger = Logger::new(); @@ -82,7 +82,7 @@ pub(crate) fn init() { } fn get_log_level() -> Option { - let kcmdline = BOOT_TIME_INFO.get().unwrap().kernel_cmdline; + let kcmdline = EARLY_INFO.get().unwrap().kernel_cmdline; // Although OSTD is agnostic of the parsing of the kernel command line, // the logger assumes that it follows the Linux kernel command line format.