binary.rs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //! Capture 3. Binary Encoding
  2. pub use sbi_spec::binary::SbiRet;
  3. #[inline(always)]
  4. pub(crate) fn sbi_call_0(eid: usize, fid: usize) -> SbiRet {
  5. let (error, value);
  6. unsafe {
  7. core::arch::asm!(
  8. "ecall",
  9. in("a7") eid,
  10. in("a6") fid,
  11. lateout("a0") error,
  12. lateout("a1") value,
  13. );
  14. }
  15. SbiRet { error, value }
  16. }
  17. #[inline(always)]
  18. pub(crate) fn sbi_call_1(eid: usize, fid: usize, arg0: usize) -> SbiRet {
  19. let (error, value);
  20. unsafe {
  21. core::arch::asm!(
  22. "ecall",
  23. in("a7") eid,
  24. in("a6") fid,
  25. inlateout("a0") arg0 => error,
  26. lateout("a1") value,
  27. );
  28. }
  29. SbiRet { error, value }
  30. }
  31. #[inline(always)]
  32. pub(crate) fn sbi_call_2(eid: usize, fid: usize, arg0: usize, arg1: usize) -> SbiRet {
  33. let (error, value);
  34. unsafe {
  35. core::arch::asm!(
  36. "ecall",
  37. in("a7") eid,
  38. in("a6") fid,
  39. inlateout("a0") arg0 => error,
  40. inlateout("a1") arg1 => value,
  41. );
  42. }
  43. SbiRet { error, value }
  44. }
  45. #[inline(always)]
  46. pub(crate) fn sbi_call_3(eid: usize, fid: usize, arg0: usize, arg1: usize, arg2: usize) -> SbiRet {
  47. let (error, value);
  48. unsafe {
  49. core::arch::asm!(
  50. "ecall",
  51. in("a7") eid,
  52. in("a6") fid,
  53. inlateout("a0") arg0 => error,
  54. inlateout("a1") arg1 => value,
  55. in("a2") arg2,
  56. );
  57. }
  58. SbiRet { error, value }
  59. }
  60. #[inline(always)]
  61. pub(crate) fn sbi_call_4(
  62. eid: usize,
  63. fid: usize,
  64. arg0: usize,
  65. arg1: usize,
  66. arg2: usize,
  67. arg3: usize,
  68. ) -> SbiRet {
  69. let (error, value);
  70. unsafe {
  71. core::arch::asm!(
  72. "ecall",
  73. in("a7") eid,
  74. in("a6") fid,
  75. inlateout("a0") arg0 => error,
  76. inlateout("a1") arg1 => value,
  77. in("a2") arg2,
  78. in("a3") arg3,
  79. );
  80. }
  81. SbiRet { error, value }
  82. }
  83. #[inline(always)]
  84. pub(crate) fn sbi_call_5(
  85. eid: usize,
  86. fid: usize,
  87. arg0: usize,
  88. arg1: usize,
  89. arg2: usize,
  90. arg3: usize,
  91. arg4: usize,
  92. ) -> SbiRet {
  93. let (error, value);
  94. unsafe {
  95. core::arch::asm!(
  96. "ecall",
  97. in("a7") eid,
  98. in("a6") fid,
  99. inlateout("a0") arg0 => error,
  100. inlateout("a1") arg1 => value,
  101. in("a2") arg2,
  102. in("a3") arg3,
  103. in("a4") arg4,
  104. );
  105. }
  106. SbiRet { error, value }
  107. }
  108. #[cfg(target_pointer_width = "32")]
  109. #[inline(always)]
  110. pub(crate) fn sbi_call_6(
  111. eid: usize,
  112. fid: usize,
  113. arg0: usize,
  114. arg1: usize,
  115. arg2: usize,
  116. arg3: usize,
  117. arg4: usize,
  118. arg5: usize,
  119. ) -> SbiRet {
  120. let (error, value);
  121. unsafe {
  122. core::arch::asm!(
  123. "ecall",
  124. in("a7") eid,
  125. in("a6") fid,
  126. inlateout("a0") arg0 => error,
  127. inlateout("a1") arg1 => value,
  128. in("a2") arg2,
  129. in("a3") arg3,
  130. in("a4") arg4,
  131. in("a5") arg5,
  132. );
  133. }
  134. SbiRet { error, value }
  135. }