xref: /DragonOS/kernel/src/arch/x86_64/cpu.rs (revision 415e46ea470ba1dd33e4368c3684c700a75f3be8)
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]
9 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
16 pub unsafe fn cpu_reset() -> ! {
17     // 重启计算机
18     unsafe { x86::io::outb(0x64, 0xfe) };
19     loop {
20         spin_loop();
21     }
22 }
23