Browse Source

Fix weird formatting in mod.rs
Update assert! logic in mcounteren.rs and scounteren.rs
Fix comment typo on `scounteren`

dkhayes117 4 years ago
parent
commit
6878e5f774

+ 1 - 1
src/register/cycle.rs

@@ -1,6 +1,6 @@
 //! cycle register
 //! Shadow of mcycle register
-//! must have `scounter::cy` or `mcounteren::cy` bit enabled depending on whether
+//! must have `scounteren::cy` or `mcounteren::cy` bit enabled depending on whether
 //! S-mode is implemented or not
 
 read_csr_as_usize!(0xC00, __read_cycle);

+ 1 - 1
src/register/cycleh.rs

@@ -1,6 +1,6 @@
 //! cycleh register
 //! Shadow of mcycleh register (rv32)
-//! must have `scounter::cy` or `mcounteren::cy` bit enabled depending on whether
+//! must have `scounteren::cy` or `mcounteren::cy` bit enabled depending on whether
 //! S-mode is implemented or not
 
 read_csr_as_usize_rv32!(0xC80, __read_cycleh);

+ 1 - 1
src/register/instret.rs

@@ -1,6 +1,6 @@
 //! instret register
 //! Shadow of minstret register
-//! must have `scounter::ir` or `mcounteren::ir` bit enabled depending on whether
+//! must have `scounteren::ir` or `mcounteren::ir` bit enabled depending on whether
 //! S-mode is implemented or not
 
 read_csr_as_usize!(0xC02, __read_instret);

+ 1 - 1
src/register/instreth.rs

@@ -1,6 +1,6 @@
 //! instreth register
 //! Shadow of minstreth register (rv32)
-//! must have `scounter::ir` or `mcounteren::ir` bit enabled depending on whether
+//! must have `scounteren::ir` or `mcounteren::ir` bit enabled depending on whether
 //! S-mode is implemented or not
 
 read_csr_as_usize!(0xC82, __read_instreth);

+ 3 - 3
src/register/mcounteren.rs

@@ -30,7 +30,7 @@ impl Mcounteren {
     /// User "hpm[x]" Enable (bits 3-31)
     #[inline]
     pub fn hpm(&self, index: usize) -> bool {
-        assert!(((3..32).contains(&index)));
+        assert!(3 <= index && index < 32);
         self.bits.get_bit(index)
     }
 }
@@ -54,12 +54,12 @@ set_clear_csr!(
 
 #[inline]
 pub unsafe fn set_hpm(index: usize) {
-    assert!(((3..32).contains(&index)));
+    assert!(3 <= index && index < 32);
     _set(1 << index);
 }
 
 #[inline]
 pub unsafe fn clear_hpm(index: usize) {
-    assert!(((3..32).contains(&index)));
+    assert!(3 <= index && index < 32);
     _clear(1 << index);
 }

+ 12 - 17
src/register/mod.rs

@@ -30,23 +30,22 @@ pub mod utval;
 pub mod fcsr;
 
 // User Counter/Timers
+
 pub mod cycle;
+pub mod cycleh;
 mod hpmcounterx;
-pub mod instret;
-pub mod time;
-
 pub use self::hpmcounterx::*;
-
-pub mod cycleh;
+pub mod instret;
 pub mod instreth;
+pub mod time;
 pub mod timeh;
 
 // Supervisor Trap Setup
 // TODO: sedeleg, sideleg
-pub mod scounteren;
 pub mod sie;
 pub mod sstatus;
 pub mod stvec;
+pub mod scounteren;
 
 // Supervisor Trap Handling
 pub mod scause;
@@ -65,12 +64,13 @@ pub mod mimpid;
 pub mod mvendorid;
 
 // Machine Trap Setup
+pub mod medeleg;
+pub mod mideleg;
+pub mod mie;
 pub mod misa;
 pub mod mstatus;
-// TODO: medeleg, mideleg
-pub mod mcounteren;
-pub mod mie;
 pub mod mtvec;
+pub mod mcounteren;
 
 // Machine Trap Handling
 pub mod mcause;
@@ -81,26 +81,21 @@ pub mod mtval;
 
 // Machine Protection and Translation
 mod pmpcfgx;
-
 pub use self::pmpcfgx::*;
-
 mod pmpaddrx;
-
 pub use self::pmpaddrx::*;
 
 // Machine Counter/Timers
 pub mod mcycle;
+pub mod mcycleh;
 mod mhpmcounterx;
-pub mod minstret;
-
 pub use self::mhpmcounterx::*;
-
-pub mod mcycleh;
+pub mod minstret;
 pub mod minstreth;
 
+
 // Machine Counter Setup
 mod mhpmeventx;
-
 pub use self::mhpmeventx::*;
 
 // TODO: Debug/Trace Registers (shared with Debug Mode)

+ 3 - 3
src/register/scounteren.rs

@@ -30,7 +30,7 @@ impl Scounteren {
     /// User "hpm[x]" Enable (bits 3-31)
     #[inline]
     pub fn hpm(&self, index: usize) -> bool {
-        assert!(((3..32).contains(&index)));
+        assert!(3 <= index && index < 32);
         self.bits.get_bit(index)
     }
 }
@@ -54,12 +54,12 @@ set_clear_csr!(
 
 #[inline]
 pub unsafe fn set_hpm(index: usize) {
-    assert!(((3..32).contains(&index)));
+    assert!(3 <= index && index < 32);
     _set(1 << index);
 }
 
 #[inline]
 pub unsafe fn clear_hpm(index: usize) {
-    assert!(((3..32).contains(&index)));
+    assert!(3 <= index && index < 32);
     _clear(1 << index);
 }