diff --git a/ostd/src/arch/x86/boot/smp.rs b/ostd/src/arch/x86/boot/smp.rs index 3b5ac609d..bd980ce56 100644 --- a/ostd/src/arch/x86/boot/smp.rs +++ b/ostd/src/arch/x86/boot/smp.rs @@ -92,37 +92,29 @@ fn fill_boot_stack_array_ptr() { .unwrap() .boot_stack_array; - // This is defined in the boot assembly code. 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 { - 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() { - // This is defined in the boot assembly code. 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(); - 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`. + let ptr = unsafe { &__boot_page_table_pointer as *const u32 as *mut u32 }; + // SAFETY: We only write to it once. unsafe { - boot_pt_ptr.write_volatile(boot_pt as u32); + ptr.write_volatile(boot_pt as u32); } }