Skip to main content

axplat_x86_pc/
lib.rs

1#![no_std]
2
3#[macro_use]
4extern crate log;
5#[macro_use]
6extern crate axplat;
7
8mod apic;
9mod boot;
10mod console;
11mod init;
12mod mem;
13mod power;
14mod time;
15
16#[cfg(feature = "smp")]
17mod mp;
18
19pub mod config {
20    //! Platform configuration module.
21    //!
22    //! If the `AX_CONFIG_PATH` environment variable is set, it will load the configuration from the specified path.
23    //! Otherwise, it will fall back to the `axconfig.toml` file in the current directory and generate the default configuration.
24    //!
25    //! If the `PACKAGE` field in the configuration does not match the package name, it will panic with an error message.
26    axconfig_macros::include_configs!(path_env = "AX_CONFIG_PATH", fallback = "axconfig.toml");
27    assert_str_eq!(
28        PACKAGE,
29        env!("CARGO_PKG_NAME"),
30        "`PACKAGE` field in the configuration does not match the Package name. Please check your configuration file."
31    );
32}
33
34fn current_cpu_id() -> usize {
35    match raw_cpuid::CpuId::new().get_feature_info() {
36        Some(finfo) => finfo.initial_local_apic_id() as usize,
37        None => 0,
38    }
39}
40
41unsafe extern "C" fn rust_entry(magic: usize, mbi: usize) {
42    if magic == self::boot::MULTIBOOT_BOOTLOADER_MAGIC {
43        axplat::call_main(current_cpu_id(), mbi);
44    }
45}
46
47unsafe extern "C" fn rust_entry_secondary(_magic: usize) {
48    #[cfg(feature = "smp")]
49    if _magic == self::boot::MULTIBOOT_BOOTLOADER_MAGIC {
50        axplat::call_secondary_main(current_cpu_id());
51    }
52}