1 use core::hint::spin_loop; 2 3 use crate::{exception::InterruptArch, sched::SchedArch, smp::core::smp_get_processor_id}; 4 5 use super::{driver::apic::apic_timer::apic_timer_init, CurrentIrqArch}; 6 7 static mut BSP_INIT_OK: bool = false; 8 9 pub struct X86_64SchedArch; 10 11 impl SchedArch for X86_64SchedArch { 12 fn enable_sched_local() { 13 // fixme: 这里将来可能需要更改,毕竟这个直接开关中断有点暴力。 14 unsafe { CurrentIrqArch::interrupt_enable() }; 15 } 16 17 fn disable_sched_local() { 18 unsafe { 19 CurrentIrqArch::interrupt_disable(); 20 } 21 } 22 23 fn initial_setup_sched_local() { 24 let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() }; 25 26 let cpu_id = smp_get_processor_id(); 27 28 if cpu_id.data() != 0 { 29 while !unsafe { BSP_INIT_OK } { 30 spin_loop(); 31 } 32 } 33 34 apic_timer_init(); 35 if smp_get_processor_id().data() == 0 { 36 unsafe { 37 BSP_INIT_OK = true; 38 } 39 } 40 41 drop(irq_guard); 42 } 43 } 44