1use crate::lib::sync::niche_cell::NicheCell;
7use alloc::boxed::Box;
8
9#[cfg(target_arch = "x86_64")]
10use crate::arch::x86_64::cpu::state::*;
11
12#[repr(align(64))]
16pub struct Cpu {
17 global_cpu_state: GlobalCpuState,
18 bsp_cpu_state: CpuState,
19 ap_cpu_states: NicheCell<Box<[CpuState]>>
20}
21
22impl Cpu {
23 pub const fn new() -> Self {
25 Self {
26 global_cpu_state: GlobalCpuState::new(),
27 bsp_cpu_state: CpuState::new(),
28 ap_cpu_states: NicheCell::new(),
29 }
30 }
31
32 pub unsafe fn init_ap_cpu_states(&self, value: Box<[CpuState]>) {
33 unsafe { self.ap_cpu_states.init(value) };
34 }
35
36 pub fn global_cpu_state(&self) -> &GlobalCpuState {
38 &self.global_cpu_state
39 }
40
41 pub fn bsp_cpu_state(&self) -> &CpuState {
43 &self.bsp_cpu_state
44 }
45
46 pub unsafe fn ap_cpu_states(&self) -> &Option<Box<[CpuState]>> {
52 unsafe { self.ap_cpu_states.get() }
53 }
54}