Set the page table for APs before kicking

This commit is contained in:
Zhang Junyang
2024-12-13 21:23:52 +08:00
committed by Tate, Hongliang Tian
parent 285dde5546
commit 68bdda4c4c
3 changed files with 41 additions and 11 deletions

View File

@ -57,7 +57,8 @@ pub(crate) fn get_num_processors() -> Option<u32> {
/// Brings up all application processors.
pub(crate) fn bringup_all_aps() {
copy_ap_boot_code();
init_boot_stack_array();
fill_boot_stack_array_ptr();
fill_boot_pt_ptr();
send_boot_ipis();
}
@ -85,7 +86,7 @@ fn copy_ap_boot_code() {
}
/// Initializes the boot stack array in the AP boot code with the given pages.
fn init_boot_stack_array() {
fn fill_boot_stack_array_ptr() {
let pages = &crate::boot::smp::AP_BOOT_INFO
.get()
.unwrap()
@ -97,7 +98,7 @@ fn init_boot_stack_array() {
}
let ap_boot_stack_arr_ptr: *mut u64 = __ap_boot_stack_array_pointer as usize as *mut u64;
log::debug!(
"__ap_boot_stack_array_pointer: {:#x?}",
"Setting __ap_boot_stack_array_pointer={:#x?} for AP boot stacks",
ap_boot_stack_arr_ptr
);
@ -107,6 +108,24 @@ fn init_boot_stack_array() {
}
}
fn fill_boot_pt_ptr() {
// This is defined in the boot assembly code.
extern "C" {
fn __boot_page_table_pointer();
}
let boot_pt_ptr: *mut u32 = __boot_page_table_pointer as usize as *mut u32;
let boot_pt = crate::mm::page_table::boot_pt::with_borrow(|pt| pt.root_address()).unwrap();
log::debug!(
"Setting __boot_page_table_pointer={:#x?} for AP boot page tables",
boot_pt
);
// SAFETY: this pointer points to a static variable defined in the `ap_boot.S`.
unsafe {
boot_pt_ptr.write_volatile(boot_pt as u32);
}
}
// The symbols are defined in the linker script.
extern "C" {
fn __ap_boot_start();