macros.rs 2.4 KB

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