axplat/
lib.rs

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