base.rs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //! Chapter 4. Base Extension (EID #0x10).
  2. /// Extension ID for RISC-V SBI Base extension.
  3. pub const EID_BASE: usize = 0x10;
  4. pub use fid::*;
  5. /// Default probe value for the target SBI extension is unavailable.
  6. pub const UNAVAILABLE_EXTENSION: usize = 0;
  7. /// SBI specification version.
  8. ///
  9. /// Not to be confused with 'implementation version'.
  10. ///
  11. /// Declared in §4.1.
  12. #[derive(Clone, Copy, Debug)]
  13. #[repr(transparent)]
  14. pub struct Version {
  15. raw: usize,
  16. }
  17. impl Version {
  18. /// Converts raw extension value into Version structure.
  19. #[inline]
  20. pub const fn from_raw(raw: usize) -> Self {
  21. Self { raw }
  22. }
  23. /// Reads the major version of RISC-V SBI specification.
  24. #[inline]
  25. pub const fn major(self) -> usize {
  26. (self.raw >> 24) & ((1 << 7) - 1)
  27. }
  28. /// Reads the minor version of RISC-V SBI specification.
  29. #[inline]
  30. pub const fn minor(self) -> usize {
  31. self.raw & ((1 << 24) - 1)
  32. }
  33. }
  34. impl core::fmt::Display for Version {
  35. #[inline]
  36. fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
  37. write!(f, "{}.{}", self.major(), self.minor())
  38. }
  39. }
  40. /// Declared in §4.8
  41. mod fid {
  42. /// Function ID to get the current SBI specification version.
  43. ///
  44. /// Declared in §4.1.
  45. pub const GET_SBI_SPEC_VERSION: usize = 0x0;
  46. /// Function ID to get the current SBI implementation ID.
  47. ///
  48. /// Declared in §4.2.
  49. pub const GET_SBI_IMPL_ID: usize = 0x1;
  50. /// Function ID to get the current SBI implementation version.
  51. ///
  52. /// Declared in §4.3.
  53. pub const GET_SBI_IMPL_VERSION: usize = 0x2;
  54. /// Function ID to probe information about one SBI extension from the current environment.
  55. ///
  56. /// Declared in §4.4.
  57. pub const PROBE_EXTENSION: usize = 0x3;
  58. /// Function ID to get the value of `mvendorid` register in the current environment.
  59. ///
  60. /// Declared in §4.5.
  61. pub const GET_MVENDORID: usize = 0x4;
  62. /// Function ID to get the value of `marchid` register in the current environment.
  63. ///
  64. /// Declared in §4.6.
  65. pub const GET_MARCHID: usize = 0x5;
  66. /// Function ID to get the value of `mimpid` register in the current environment.
  67. ///
  68. /// Declared in §4.7.
  69. pub const GET_MIMPID: usize = 0x6;
  70. }
  71. /// SBI Implementation IDs.
  72. ///
  73. /// Declared in §4.9.
  74. pub mod impl_id {
  75. /// Berkley Bootloader.
  76. pub const BBL: usize = 0;
  77. /// OpenSBI.
  78. pub const OPEN_SBI: usize = 1;
  79. /// Xvisor.
  80. pub const XVISOR: usize = 2;
  81. /// KVM.
  82. pub const KVM: usize = 3;
  83. /// RustSBI.
  84. pub const RUST_SBI: usize = 4;
  85. /// Diosix.
  86. pub const DIOSIX: usize = 5;
  87. /// Coffer.
  88. pub const COFFER: usize = 6;
  89. /// Xen Project
  90. pub const XEN: usize = 7;
  91. /// PolarFire Hart Software Services.
  92. pub const POLARFIRE_HSS: usize = 8;
  93. }