ax_cpu/x86_64/init.rs
1//! Helper functions to initialize the CPU states on systems bootstrapping.
2
3/// Initializes the per-CPU data structures.
4///
5/// It calls the initialization function of the [`ax-percpu`] crate. It (or other
6/// alternative initialization) should be called before [`init_trap`].
7///
8/// [`ax-percpu`]: https://docs.rs/ax-percpu/latest/ax_percpu/index.html
9pub fn init_percpu(cpu_id: usize) {
10 ax_percpu::init();
11 ax_percpu::init_percpu_reg(cpu_id);
12}
13
14/// Initializes trap handling on the current CPU.
15///
16/// In detail, it initializes the GDT, IDT on x86_64 platforms. If the `uspace`
17/// feature is enabled, it also initializes relevant model-specific registers to
18/// configure the handler for `syscall` instruction.
19///
20/// # Notes
21/// Before calling this function, the initialization function of the [`ax-percpu`]
22/// crate should have been invoked to ensure that the per-CPU data structures
23/// are set up correctly (i.e., by calling [`init_percpu`]).
24///
25/// [`ax-percpu`]: https://docs.rs/ax-percpu/latest/ax_percpu/index.html
26pub fn init_trap() {
27 #[cfg(feature = "exception-table")]
28 crate::exception_table::init_exception_table();
29 super::gdt::init();
30 super::idt::init();
31 #[cfg(feature = "uspace")]
32 super::uspace::init_syscall();
33}