mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Reorder heap initialization
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
5ea366bced
commit
7676f8ec95
@ -38,14 +38,11 @@ fn parse_bootloader_name(mb1_info: &MultibootLegacyInfo) -> &str {
|
|||||||
fn parse_kernel_commandline(mb1_info: &MultibootLegacyInfo) -> &str {
|
fn parse_kernel_commandline(mb1_info: &MultibootLegacyInfo) -> &str {
|
||||||
let mut cmdline = "";
|
let mut cmdline = "";
|
||||||
if mb1_info.cmdline != 0 {
|
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.
|
// SAFETY: the command line is C-style zero-terminated string.
|
||||||
unsafe {
|
let cstr = unsafe { core::ffi::CStr::from_ptr(ptr) };
|
||||||
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();
|
cmdline = cstr.to_str().unwrap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
cmdline
|
cmdline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ pub struct BootInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the boot information.
|
/// Gets the boot information.
|
||||||
|
///
|
||||||
|
/// This function is usable after initialization with [`init_after_heap`].
|
||||||
pub fn boot_info() -> &'static BootInfo {
|
pub fn boot_info() -> &'static BootInfo {
|
||||||
INFO.get().unwrap()
|
INFO.get().unwrap()
|
||||||
}
|
}
|
||||||
@ -90,10 +92,11 @@ pub(crate) struct EarlyBootInfo {
|
|||||||
/// The boot-time information.
|
/// The boot-time information.
|
||||||
pub(crate) static EARLY_INFO: Once<EarlyBootInfo> = Once::new();
|
pub(crate) static EARLY_INFO: Once<EarlyBootInfo> = Once::new();
|
||||||
|
|
||||||
/// Initializes the runtime information.
|
/// Initializes the boot information.
|
||||||
///
|
///
|
||||||
/// This function allows the run-time getters to work properly.
|
/// This function copies the boot-time accessible information to the heap to
|
||||||
pub(crate) fn init() {
|
/// allow [`boot_info`] to work properly.
|
||||||
|
pub(crate) fn init_after_heap() {
|
||||||
let boot_time_info = EARLY_INFO.get().unwrap();
|
let boot_time_info = EARLY_INFO.get().unwrap();
|
||||||
|
|
||||||
INFO.call_once(|| BootInfo {
|
INFO.call_once(|| BootInfo {
|
||||||
|
@ -75,14 +75,15 @@ unsafe fn init() {
|
|||||||
#[cfg(feature = "cvm_guest")]
|
#[cfg(feature = "cvm_guest")]
|
||||||
arch::init_cvm_guest();
|
arch::init_cvm_guest();
|
||||||
|
|
||||||
|
logger::init();
|
||||||
|
|
||||||
// SAFETY: This function is called only once and only on the BSP.
|
// SAFETY: This function is called only once and only on the BSP.
|
||||||
unsafe { cpu::local::early_init_bsp_local_base() };
|
unsafe { cpu::local::early_init_bsp_local_base() };
|
||||||
|
|
||||||
// SAFETY: This function is called only once and only on the BSP.
|
// SAFETY: This function is called only once and only on the BSP.
|
||||||
unsafe { mm::heap_allocator::init() };
|
unsafe { mm::heap_allocator::init() };
|
||||||
|
|
||||||
boot::init();
|
boot::init_after_heap();
|
||||||
logger::init();
|
|
||||||
|
|
||||||
mm::frame::allocator::init();
|
mm::frame::allocator::init();
|
||||||
mm::kspace::init_kernel_page_table(mm::init_page_meta());
|
mm::kspace::init_kernel_page_table(mm::init_page_meta());
|
||||||
|
@ -12,7 +12,7 @@ use core::str::FromStr;
|
|||||||
use log::{LevelFilter, Metadata, Record};
|
use log::{LevelFilter, Metadata, Record};
|
||||||
use spin::Once;
|
use spin::Once;
|
||||||
|
|
||||||
use crate::boot::BOOT_TIME_INFO;
|
use crate::boot::EARLY_INFO;
|
||||||
|
|
||||||
static LOGGER: Logger = Logger::new();
|
static LOGGER: Logger = Logger::new();
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ pub(crate) fn init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_log_level() -> Option<LevelFilter> {
|
fn get_log_level() -> Option<LevelFilter> {
|
||||||
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,
|
// Although OSTD is agnostic of the parsing of the kernel command line,
|
||||||
// the logger assumes that it follows the Linux kernel command line format.
|
// the logger assumes that it follows the Linux kernel command line format.
|
||||||
|
Reference in New Issue
Block a user