xref: /DragonOS/kernel/src/arch/x86_64/cpu.rs (revision b5b571e02693d91eb6918d3b7561e088c3e7ee81)
1 use core::hint::spin_loop;
2 
3 use x86::cpuid::{cpuid, CpuIdResult};
4 
5 use crate::smp::cpu::ProcessorId;
6 
7 /// 获取当前cpu的apic id
8 #[inline]
current_cpu_id() -> ProcessorId9 pub fn current_cpu_id() -> ProcessorId {
10     let cpuid_res: CpuIdResult = cpuid!(0x1);
11     let cpu_id = (cpuid_res.ebx >> 24) & 0xff;
12     return ProcessorId::new(cpu_id);
13 }
14 
15 /// 重置cpu
cpu_reset() -> !16 pub unsafe fn cpu_reset() -> ! {
17     // 重启计算机
18     unsafe { x86::io::outb(0x64, 0xfe) };
19     loop {
20         spin_loop();
21     }
22 }
23