123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- use rustsbi::RustSBI;
- use sbi_spec::{
- binary::{Physical, SbiRet, SharedPtr},
- nacl::shmem_size::NATIVE,
- };
- #[derive(RustSBI)]
- struct FullyImplemented {
- console: DummyConsole,
- cppc: DummyCppc,
- hsm: DummyHsm,
- ipi: DummyIpi,
- nacl: DummyNacl,
- pmu: DummyPmu,
- reset: DummyReset,
- fence: DummyFence,
- sta: DummySta,
- susp: DummySusp,
- timer: DummyTimer,
- info: DummyEnvInfo,
- }
- #[derive(RustSBI)]
- struct AlternateName {
- dbcn: DummyConsole,
- cppc: DummyCppc,
- hsm: DummyHsm,
- ipi: DummyIpi,
- nacl: DummyNacl,
- pmu: DummyPmu,
- srst: DummyReset,
- rfnc: DummyFence,
- sta: DummySta,
- susp: DummySusp,
- time: DummyTimer,
- info: DummyEnvInfo,
- }
- #[test]
- fn rustsbi_impl_id() {
- let sbi = FullyImplemented {
- console: DummyConsole,
- cppc: DummyCppc,
- hsm: DummyHsm,
- ipi: DummyIpi,
- nacl: DummyNacl,
- pmu: DummyPmu,
- reset: DummyReset,
- fence: DummyFence,
- sta: DummySta,
- susp: DummySusp,
- timer: DummyTimer,
- info: DummyEnvInfo,
- };
- assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
- let sbi = AlternateName {
- dbcn: DummyConsole,
- cppc: DummyCppc,
- hsm: DummyHsm,
- ipi: DummyIpi,
- nacl: DummyNacl,
- pmu: DummyPmu,
- srst: DummyReset,
- rfnc: DummyFence,
- sta: DummySta,
- susp: DummySusp,
- time: DummyTimer,
- info: DummyEnvInfo,
- };
- assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
- }
- #[test]
- fn extension_impl() {
- let sbi = FullyImplemented {
- console: DummyConsole,
- cppc: DummyCppc,
- hsm: DummyHsm,
- ipi: DummyIpi,
- nacl: DummyNacl,
- pmu: DummyPmu,
- reset: DummyReset,
- fence: DummyFence,
- sta: DummySta,
- susp: DummySusp,
- timer: DummyTimer,
- info: DummyEnvInfo,
- };
- assert_eq!(
- sbi.handle_ecall(0x4442434E, 0x0, [0; 6]).error,
- -1isize as _
- );
- }
- struct DummyConsole;
- impl rustsbi::Console for DummyConsole {
- fn write(&self, _: Physical<&[u8]>) -> SbiRet {
- // special return value for test cases
- SbiRet::failed()
- }
- fn read(&self, _: Physical<&mut [u8]>) -> SbiRet {
- unimplemented!()
- }
- fn write_byte(&self, _: u8) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyCppc;
- impl rustsbi::Cppc for DummyCppc {
- fn probe(&self, _: u32) -> SbiRet {
- unimplemented!()
- }
- fn read(&self, _: u32) -> SbiRet {
- unimplemented!()
- }
- fn read_hi(&self, _: u32) -> SbiRet {
- unimplemented!()
- }
- fn write(&self, _: u32, _: u64) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyHsm;
- impl rustsbi::Hsm for DummyHsm {
- fn hart_start(&self, _: usize, _: usize, _: usize) -> SbiRet {
- unimplemented!()
- }
- fn hart_stop(&self) -> SbiRet {
- unimplemented!()
- }
- fn hart_get_status(&self, _: usize) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyIpi;
- impl rustsbi::Ipi for DummyIpi {
- fn send_ipi(&self, _: rustsbi::HartMask) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyNacl;
- impl rustsbi::Nacl for DummyNacl {
- fn probe_feature(&self, _: u32) -> SbiRet {
- unimplemented!()
- }
- fn set_shmem(&self, _: SharedPtr<[u8; NATIVE]>, _: usize) -> SbiRet {
- unimplemented!()
- }
- fn sync_csr(&self, _: usize) -> SbiRet {
- unimplemented!()
- }
- fn sync_hfence(&self, _: usize) -> SbiRet {
- unimplemented!()
- }
- fn sync_sret(&self) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyPmu;
- impl rustsbi::Pmu for DummyPmu {
- fn num_counters(&self) -> usize {
- unimplemented!()
- }
- fn counter_get_info(&self, _: usize) -> SbiRet {
- unimplemented!()
- }
- fn counter_config_matching(&self, _: usize, _: usize, _: usize, _: usize, _: u64) -> SbiRet {
- unimplemented!()
- }
- fn counter_start(&self, _: usize, _: usize, _: usize, _: u64) -> SbiRet {
- unimplemented!()
- }
- fn counter_stop(&self, _: usize, _: usize, _: usize) -> SbiRet {
- unimplemented!()
- }
- fn counter_fw_read(&self, _: usize) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyReset;
- impl rustsbi::Reset for DummyReset {
- fn system_reset(&self, _: u32, _: u32) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyFence;
- impl rustsbi::Fence for DummyFence {
- fn remote_fence_i(&self, _: rustsbi::HartMask) -> SbiRet {
- unimplemented!()
- }
- fn remote_sfence_vma(&self, _: rustsbi::HartMask, _: usize, _: usize) -> SbiRet {
- unimplemented!()
- }
- fn remote_sfence_vma_asid(&self, _: rustsbi::HartMask, _: usize, _: usize, _: usize) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummySta;
- impl rustsbi::Sta for DummySta {
- fn set_shmem(&self, _: SharedPtr<[u8; 64]>, _: usize) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummySusp;
- impl rustsbi::Susp for DummySusp {
- fn system_suspend(&self, _: u32, _: usize, _: usize) -> SbiRet {
- unimplemented!()
- }
- }
- struct DummyTimer;
- impl rustsbi::Timer for DummyTimer {
- fn set_timer(&self, _: u64) {
- unimplemented!()
- }
- }
- struct DummyEnvInfo;
- impl rustsbi::EnvInfo for DummyEnvInfo {
- fn mvendorid(&self) -> usize {
- unimplemented!()
- }
- fn marchid(&self) -> usize {
- unimplemented!()
- }
- fn mimpid(&self) -> usize {
- unimplemented!()
- }
- }
|