build-full.rs 5.0 KB

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