Skip to content

Commit e722958

Browse files
committed
fix(x86_64): don't use boot info in SMP start
1 parent c22a59e commit e722958

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/arch/x86_64/kernel/apic.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ pub fn init_x2apic() {
728728
}
729729
}
730730

731-
/// Initialize the required _start variables for the next CPU to be booted.
731+
/// Initialize the required `smp::start` variables for the next CPU to be booted.
732732
#[cfg(feature = "smp")]
733733
pub fn init_next_processor_variables() {
734734
use alloc::alloc::alloc;
@@ -751,7 +751,6 @@ pub fn init_next_processor_variables() {
751751
/// This is partly confirmed by <https://wiki.osdev.org/Symmetric_Multiprocessing>
752752
#[cfg(all(target_os = "none", feature = "smp"))]
753753
pub fn boot_application_processors() {
754-
use hermit_entry::boot_info::RawBootInfo;
755754
use x86_64::structures::paging::Translate;
756755

757756
let smp_boot_code = include_bytes!(concat!(core::env!("OUT_DIR"), "/boot.bin"));
@@ -797,11 +796,11 @@ pub fn boot_application_processors() {
797796
// Set entry point
798797
debug!(
799798
"Set entry point for application processor to {:p}",
800-
arch::start::hermit_entry::_start as *const ()
799+
arch::start::smp::start as *const ()
801800
);
802801
(SMP_BOOT_CODE_ADDRESS + SMP_BOOT_CODE_OFFSET_ENTRY)
803-
.as_mut_ptr::<unsafe extern "C" fn(Option<&'static RawBootInfo>, cpu_id: u32) -> !>()
804-
.write_unaligned(arch::start::hermit_entry::_start);
802+
.as_mut_ptr::<unsafe extern "C" fn() -> !>()
803+
.write_unaligned(arch::start::smp::start);
805804
}
806805

807806
// Now wake up each application processor.

src/arch/x86_64/start/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
pub mod hermit_entry;
2+
#[cfg(feature = "smp")]
3+
pub mod smp;

src/arch/x86_64/start/smp.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use x86_64::registers::control::{Cr0, Cr0Flags};
2+
3+
use crate::arch::kernel::scheduler::TaskStacks;
4+
use crate::config::KERNEL_STACK_SIZE;
5+
use crate::kernel::CURRENT_STACK_ADDRESS;
6+
7+
#[unsafe(naked)]
8+
pub unsafe extern "C" fn start() -> ! {
9+
core::arch::naked_asm!(
10+
// Overwrite RSP with `CURRENT_STACK_ADDRESS`
11+
"mov rax, qword ptr [rip + {current_stack_address}@GOTPCREL]",
12+
"mov rsp, qword ptr [rax]",
13+
14+
// Add top stack offset
15+
"add rsp, {stack_top_offset}",
16+
17+
// Jump into Rust code
18+
"jmp {start_rust}",
19+
20+
current_stack_address = sym CURRENT_STACK_ADDRESS,
21+
stack_top_offset = const KERNEL_STACK_SIZE - TaskStacks::MARKER_SIZE,
22+
start_rust = sym start_rust,
23+
)
24+
}
25+
26+
unsafe extern "C" fn start_rust() -> ! {
27+
// Enable caching
28+
unsafe {
29+
Cr0::update(|flags| flags.remove(Cr0Flags::CACHE_DISABLE | Cr0Flags::NOT_WRITE_THROUGH));
30+
}
31+
32+
crate::application_processor_main();
33+
}

0 commit comments

Comments
 (0)