build-full.rs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. use rustsbi::RustSBI;
  2. use sbi_spec::{
  3. binary::{Physical, SbiRet, SharedPtr},
  4. nacl::shmem_size::NATIVE,
  5. };
  6. #[derive(RustSBI)]
  7. struct FullyImplemented {
  8. console: DummyConsole,
  9. cppc: DummyCppc,
  10. hsm: DummyHsm,
  11. ipi: DummyIpi,
  12. nacl: DummyNacl,
  13. pmu: DummyPmu,
  14. reset: DummyReset,
  15. fence: DummyFence,
  16. sta: DummySta,
  17. susp: DummySusp,
  18. timer: DummyTimer,
  19. info: DummyEnvInfo,
  20. }
  21. #[derive(RustSBI)]
  22. struct AlternateName {
  23. dbcn: DummyConsole,
  24. cppc: DummyCppc,
  25. hsm: DummyHsm,
  26. ipi: DummyIpi,
  27. nacl: DummyNacl,
  28. pmu: DummyPmu,
  29. srst: DummyReset,
  30. rfnc: DummyFence,
  31. sta: DummySta,
  32. susp: DummySusp,
  33. time: DummyTimer,
  34. info: DummyEnvInfo,
  35. }
  36. #[test]
  37. fn rustsbi_impl_id() {
  38. let sbi = FullyImplemented {
  39. console: DummyConsole,
  40. cppc: DummyCppc,
  41. hsm: DummyHsm,
  42. ipi: DummyIpi,
  43. nacl: DummyNacl,
  44. pmu: DummyPmu,
  45. reset: DummyReset,
  46. fence: DummyFence,
  47. sta: DummySta,
  48. susp: DummySusp,
  49. timer: DummyTimer,
  50. info: DummyEnvInfo,
  51. };
  52. assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
  53. let sbi = AlternateName {
  54. dbcn: DummyConsole,
  55. cppc: DummyCppc,
  56. hsm: DummyHsm,
  57. ipi: DummyIpi,
  58. nacl: DummyNacl,
  59. pmu: DummyPmu,
  60. srst: DummyReset,
  61. rfnc: DummyFence,
  62. sta: DummySta,
  63. susp: DummySusp,
  64. time: DummyTimer,
  65. info: DummyEnvInfo,
  66. };
  67. assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
  68. }
  69. #[test]
  70. fn extension_impl() {
  71. let sbi = FullyImplemented {
  72. console: DummyConsole,
  73. cppc: DummyCppc,
  74. hsm: DummyHsm,
  75. ipi: DummyIpi,
  76. nacl: DummyNacl,
  77. pmu: DummyPmu,
  78. reset: DummyReset,
  79. fence: DummyFence,
  80. sta: DummySta,
  81. susp: DummySusp,
  82. timer: DummyTimer,
  83. info: DummyEnvInfo,
  84. };
  85. assert_eq!(
  86. sbi.handle_ecall(0x4442434E, 0x0, [0; 6]).error,
  87. -1isize as _
  88. );
  89. }
  90. struct DummyConsole;
  91. impl rustsbi::Console for DummyConsole {
  92. fn write(&self, _: Physical<&[u8]>) -> SbiRet {
  93. // special return value for test cases
  94. SbiRet::failed()
  95. }
  96. fn read(&self, _: Physical<&mut [u8]>) -> SbiRet {
  97. unimplemented!()
  98. }
  99. fn write_byte(&self, _: u8) -> SbiRet {
  100. unimplemented!()
  101. }
  102. }
  103. struct DummyCppc;
  104. impl rustsbi::Cppc for DummyCppc {
  105. fn probe(&self, _: u32) -> SbiRet {
  106. unimplemented!()
  107. }
  108. fn read(&self, _: u32) -> SbiRet {
  109. unimplemented!()
  110. }
  111. fn read_hi(&self, _: u32) -> SbiRet {
  112. unimplemented!()
  113. }
  114. fn write(&self, _: u32, _: u64) -> SbiRet {
  115. unimplemented!()
  116. }
  117. }
  118. struct DummyHsm;
  119. impl rustsbi::Hsm for DummyHsm {
  120. fn hart_start(&self, _: usize, _: usize, _: usize) -> SbiRet {
  121. unimplemented!()
  122. }
  123. fn hart_stop(&self) -> SbiRet {
  124. unimplemented!()
  125. }
  126. fn hart_get_status(&self, _: usize) -> SbiRet {
  127. unimplemented!()
  128. }
  129. }
  130. struct DummyIpi;
  131. impl rustsbi::Ipi for DummyIpi {
  132. fn send_ipi(&self, _: rustsbi::HartMask) -> SbiRet {
  133. unimplemented!()
  134. }
  135. }
  136. struct DummyNacl;
  137. impl rustsbi::Nacl for DummyNacl {
  138. fn probe_feature(&self, _: u32) -> SbiRet {
  139. unimplemented!()
  140. }
  141. fn set_shmem(&self, _: SharedPtr<[u8; NATIVE]>, _: usize) -> SbiRet {
  142. unimplemented!()
  143. }
  144. fn sync_csr(&self, _: usize) -> SbiRet {
  145. unimplemented!()
  146. }
  147. fn sync_hfence(&self, _: usize) -> SbiRet {
  148. unimplemented!()
  149. }
  150. fn sync_sret(&self) -> SbiRet {
  151. unimplemented!()
  152. }
  153. }
  154. struct DummyPmu;
  155. impl rustsbi::Pmu for DummyPmu {
  156. fn num_counters(&self) -> usize {
  157. unimplemented!()
  158. }
  159. fn counter_get_info(&self, _: usize) -> SbiRet {
  160. unimplemented!()
  161. }
  162. fn counter_config_matching(&self, _: usize, _: usize, _: usize, _: usize, _: u64) -> SbiRet {
  163. unimplemented!()
  164. }
  165. fn counter_start(&self, _: usize, _: usize, _: usize, _: u64) -> SbiRet {
  166. unimplemented!()
  167. }
  168. fn counter_stop(&self, _: usize, _: usize, _: usize) -> SbiRet {
  169. unimplemented!()
  170. }
  171. fn counter_fw_read(&self, _: usize) -> SbiRet {
  172. unimplemented!()
  173. }
  174. }
  175. struct DummyReset;
  176. impl rustsbi::Reset for DummyReset {
  177. fn system_reset(&self, _: u32, _: u32) -> SbiRet {
  178. unimplemented!()
  179. }
  180. }
  181. struct DummyFence;
  182. impl rustsbi::Fence for DummyFence {
  183. fn remote_fence_i(&self, _: rustsbi::HartMask) -> SbiRet {
  184. unimplemented!()
  185. }
  186. fn remote_sfence_vma(&self, _: rustsbi::HartMask, _: usize, _: usize) -> SbiRet {
  187. unimplemented!()
  188. }
  189. fn remote_sfence_vma_asid(&self, _: rustsbi::HartMask, _: usize, _: usize, _: usize) -> SbiRet {
  190. unimplemented!()
  191. }
  192. }
  193. struct DummySta;
  194. impl rustsbi::Sta for DummySta {
  195. fn set_shmem(&self, _: SharedPtr<[u8; 64]>, _: usize) -> SbiRet {
  196. unimplemented!()
  197. }
  198. }
  199. struct DummySusp;
  200. impl rustsbi::Susp for DummySusp {
  201. fn system_suspend(&self, _: u32, _: usize, _: usize) -> SbiRet {
  202. unimplemented!()
  203. }
  204. }
  205. struct DummyTimer;
  206. impl rustsbi::Timer for DummyTimer {
  207. fn set_timer(&self, _: u64) {
  208. unimplemented!()
  209. }
  210. }
  211. struct DummyEnvInfo;
  212. impl rustsbi::EnvInfo for DummyEnvInfo {
  213. fn mvendorid(&self) -> usize {
  214. unimplemented!()
  215. }
  216. fn marchid(&self) -> usize {
  217. unimplemented!()
  218. }
  219. fn mimpid(&self) -> usize {
  220. unimplemented!()
  221. }
  222. }