Revise the access of some external statics

This commit is contained in:
Zhang Junyang
2024-12-16 16:43:16 +08:00
committed by Tate, Hongliang Tian
parent 68bdda4c4c
commit 04511b74c4

View File

@ -92,37 +92,29 @@ fn fill_boot_stack_array_ptr() {
.unwrap() .unwrap()
.boot_stack_array; .boot_stack_array;
// This is defined in the boot assembly code.
extern "C" { extern "C" {
fn __ap_boot_stack_array_pointer(); static __ap_boot_stack_array_pointer: u64;
} }
let ap_boot_stack_arr_ptr: *mut u64 = __ap_boot_stack_array_pointer as usize as *mut u64;
log::debug!(
"Setting __ap_boot_stack_array_pointer={:#x?} for AP boot stacks",
ap_boot_stack_arr_ptr
);
// SAFETY: this pointer points to a static variable defined in the `ap_boot.S`. // SAFETY: This pointer points to a static variable defined in the `ap_boot.S`.
let ptr = unsafe { &__ap_boot_stack_array_pointer as *const u64 as *mut u64 };
// SAFETY: We only write to it once.
unsafe { unsafe {
ap_boot_stack_arr_ptr.write_volatile(paddr_to_vaddr(pages.start_paddr()) as u64); ptr.write_volatile(paddr_to_vaddr(pages.start_paddr()) as u64);
} }
} }
fn fill_boot_pt_ptr() { fn fill_boot_pt_ptr() {
// This is defined in the boot assembly code.
extern "C" { extern "C" {
fn __boot_page_table_pointer(); static __boot_page_table_pointer: u32;
} }
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(); 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`. // SAFETY: this pointer points to a static variable defined in the `ap_boot.S`.
let ptr = unsafe { &__boot_page_table_pointer as *const u32 as *mut u32 };
// SAFETY: We only write to it once.
unsafe { unsafe {
boot_pt_ptr.write_volatile(boot_pt as u32); ptr.write_volatile(boot_pt as u32);
} }
} }