axplat/
lib.rs

1#![cfg_attr(not(test), no_std)]
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3#![doc = include_str!("../README.md")]
4
5#[macro_use]
6extern crate axplat_macros;
7
8pub mod console;
9pub mod init;
10#[cfg(feature = "irq")]
11pub mod irq;
12pub mod mem;
13pub mod power;
14pub mod time;
15
16pub use axplat_macros::main;
17pub use crate_interface::impl_interface as impl_plat_interface;
18
19#[cfg(feature = "smp")]
20pub use axplat_macros::secondary_main;
21
22#[doc(hidden)]
23pub mod __priv {
24    pub use const_str::equal as const_str_eq;
25    pub use crate_interface::{call_interface, def_interface};
26}
27
28/// Checks that two strings are equal. If they are not equal, it will cause a compile-time
29/// error. And the message will be printed if it is provided.
30///
31/// # Example
32///
33/// ```rust
34/// extern crate axplat;
35/// const A: &str = "hello";
36/// const B: &str = "hello";
37/// axplat::assert_str_eq!(A, B);
38/// ```
39///
40/// ```compile_fail
41/// extern crate axplat;
42/// const A: &str = "hello";
43/// const B: &str = "world";
44/// axplat::assert_str_eq!(A, B, "A and B are not equal!");
45/// ```
46#[macro_export]
47macro_rules! assert_str_eq {
48    ($expect:expr, $actual:expr, $mes:literal) => {
49        const _: () = assert!($crate::__priv::const_str_eq!($expect, $actual), $mes);
50    };
51    ($expect:expr, $actual:expr $(,)?) => {
52        const _: () = assert!(
53            $crate::__priv::const_str_eq!($expect, $actual),
54            "assertion failed: expected != actual.",
55        );
56    };
57}
58
59/// Call the function decorated by [`axplat::main`][main] for the primary core.
60///
61/// This function should only be called by the platform implementer, not the kernel.
62pub fn call_main(cpu_id: usize, arg: usize) -> ! {
63    unsafe { __axplat_main(cpu_id, arg) }
64}
65
66/// Call the function decorated by [`axplat::secondary_main`][secondary_main] for secondary cores.
67///
68/// This function should only be called by the platform implementer, not the kernel.
69#[cfg(feature = "smp")]
70pub fn call_secondary_main(cpu_id: usize) -> ! {
71    unsafe { __axplat_secondary_main(cpu_id) }
72}
73
74unsafe extern "Rust" {
75    fn __axplat_main(cpu_id: usize, arg: usize) -> !;
76    fn __axplat_secondary_main(cpu_id: usize) -> !;
77}