Skip to main content

axplat/
lib.rs

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