xref: /dragonos-dsc/src/macros.rs (revision 29f2a1e928bffd4b9daaf7e0639e1d24a244c01b)
1f0737732Slongjin // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2f0737732Slongjin // file at the top-level directory of this distribution and at
3f0737732Slongjin // http://rust-lang.org/COPYRIGHT.
4f0737732Slongjin //
5f0737732Slongjin // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6f0737732Slongjin // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7f0737732Slongjin // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8f0737732Slongjin // option. This file may not be copied, modified, or distributed
9f0737732Slongjin // except according to those terms.
10f0737732Slongjin 
11943c158aSlongjin /// The macro to invoke a syscall.
12943c158aSlongjin ///
13943c158aSlongjin /// # Examples
14943c158aSlongjin ///
15943c158aSlongjin /// The following code will print `Hello, world!` to the screen with black background and white foreground.
16943c158aSlongjin /// ```
17943c158aSlongjin /// syscall!(SYS_PUTSTRING, "Hello, world!\n", 0x00ffffff, 0x00000000);
18943c158aSlongjin /// ```
19943c158aSlongjin ///
20943c158aSlongjin /// # Note
21943c158aSlongjin ///
22943c158aSlongjin /// This macro is not meant to be used directly, but rather as a dependency for other crates.
23f0737732Slongjin #[macro_export]
24f0737732Slongjin macro_rules! syscall {
25*29f2a1e9SLoGin     ($nr:ident) => {
26*29f2a1e9SLoGin         ::dsc::syscall0(::dsc::nr::$nr)
27*29f2a1e9SLoGin     };
28f0737732Slongjin 
29*29f2a1e9SLoGin     ($nr:ident, $a1:expr) => {
30*29f2a1e9SLoGin         ::dsc::syscall1(::dsc::nr::$nr, $a1 as usize)
31*29f2a1e9SLoGin     };
32f0737732Slongjin 
33*29f2a1e9SLoGin     ($nr:ident, $a1:expr, $a2:expr) => {
34*29f2a1e9SLoGin         ::dsc::syscall2(::dsc::nr::$nr, $a1 as usize, $a2 as usize)
35*29f2a1e9SLoGin     };
36f0737732Slongjin 
37*29f2a1e9SLoGin     ($nr:ident, $a1:expr, $a2:expr, $a3:expr) => {
38*29f2a1e9SLoGin         ::dsc::syscall3(::dsc::nr::$nr, $a1 as usize, $a2 as usize, $a3 as usize)
39*29f2a1e9SLoGin     };
40f0737732Slongjin 
41*29f2a1e9SLoGin     ($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => {
42*29f2a1e9SLoGin         ::dsc::syscall4(
43f0737732Slongjin             ::dsc::nr::$nr,
44*29f2a1e9SLoGin             $a1 as usize,
45*29f2a1e9SLoGin             $a2 as usize,
46*29f2a1e9SLoGin             $a3 as usize,
47*29f2a1e9SLoGin             $a4 as usize,
48*29f2a1e9SLoGin         )
49*29f2a1e9SLoGin     };
50f0737732Slongjin 
51*29f2a1e9SLoGin     ($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => {
52*29f2a1e9SLoGin         ::dsc::syscall5(
53f0737732Slongjin             ::dsc::nr::$nr,
54*29f2a1e9SLoGin             $a1 as usize,
55*29f2a1e9SLoGin             $a2 as usize,
56*29f2a1e9SLoGin             $a3 as usize,
57*29f2a1e9SLoGin             $a4 as usize,
58*29f2a1e9SLoGin             $a5 as usize,
59*29f2a1e9SLoGin         )
60*29f2a1e9SLoGin     };
61f0737732Slongjin 
62*29f2a1e9SLoGin     ($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => {
63*29f2a1e9SLoGin         ::dsc::syscall6(
64f0737732Slongjin             ::dsc::nr::$nr,
65*29f2a1e9SLoGin             $a1 as usize,
66*29f2a1e9SLoGin             $a2 as usize,
67*29f2a1e9SLoGin             $a3 as usize,
68*29f2a1e9SLoGin             $a4 as usize,
69*29f2a1e9SLoGin             $a5 as usize,
70*29f2a1e9SLoGin             $a6 as usize,
71*29f2a1e9SLoGin         )
72*29f2a1e9SLoGin     };
73f0737732Slongjin 
74*29f2a1e9SLoGin     ($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr, $a7:expr) => {
75*29f2a1e9SLoGin         ::dsc::syscall7(
76f0737732Slongjin             ::dsc::nr::$nr,
77*29f2a1e9SLoGin             $a1 as usize,
78*29f2a1e9SLoGin             $a2 as usize,
79*29f2a1e9SLoGin             $a3 as usize,
80*29f2a1e9SLoGin             $a4 as usize,
81*29f2a1e9SLoGin             $a5 as usize,
82*29f2a1e9SLoGin             $a6 as usize,
83*29f2a1e9SLoGin             $a7 as usize,
84*29f2a1e9SLoGin         )
85*29f2a1e9SLoGin     };
86f0737732Slongjin }
87