userspace/target/operating_system/macros/
syscall_modules.rs

1#[macro_export]
2macro_rules! syscall_modules {
3    (
4        $(
5            [
6                $syscall_number:expr;
7                $($syscall_path:tt)::+;
8                $syscall_constant_ident:ident;
9                $syscall_signature:ident;
10                $syscall_label:expr
11            ]
12        ),
13        *) => {
14        $(pub mod $($syscall_path)::+;)*
15        $(pub use $($syscall_path)::+::$($syscall_path)::+;)*
16
17        // $(
18        //     pub mod $($syscall_path)::+ {
19        //         $(pub use super::$($syscall_path)::+::$($syscall_path)::+;)*
20        //     }
21        // )*
22
23        pub mod numbers {
24            $(pub const $syscall_constant_ident : usize = $syscall_number;)*
25        }
26
27        pub mod labels {
28            $(pub const $syscall_constant_ident : &str = $syscall_label;)*
29        }
30
31        pub mod signatures {
32            $(pub type $syscall_constant_ident = crate::target::arch::traits::callable::$syscall_signature;)*
33        }
34
35        #[repr(usize)]
36        pub enum Syscall {
37            $(
38                $syscall_constant_ident = $syscall_number,
39            )*
40            TODO = usize::MAX,
41        }
42
43        impl Syscall {
44            pub fn to_no(&self) -> usize {
45                match self {
46                    $(Syscall::$syscall_constant_ident => $syscall_number,)*
47                    Syscall::TODO => <usize>::MAX,
48                }
49            }
50
51            pub fn from_no(n: usize) -> Syscall {
52                match n {
53                    $($syscall_number => Syscall::$syscall_constant_ident,)*
54                    _ => Syscall::TODO,
55                }
56            }
57        }
58
59        impl Into<usize> for Syscall {
60            fn into(self) -> usize {
61                self.to_no()
62            }
63        }
64    };
65}
66
67pub use syscall_modules;