Skip to content

Commit 925c496

Browse files
committed
Read composite CSRs as one 64-bit value
1 parent b665ade commit 925c496

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/register/macros.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,25 @@ macro_rules! set_clear_csr {
208208
clear_csr!($(#[$attr])*, $clear_field, $e);
209209
}
210210
}
211+
212+
macro_rules! read_composite_csr {
213+
($hi:expr, $lo:expr) => {
214+
/// Reads the CSR as a 64-bit value
215+
#[inline]
216+
pub fn read64() -> u64 {
217+
match () {
218+
#[cfg(riscv32)]
219+
() => loop {
220+
let hi = $hi;
221+
let lo = $lo;
222+
if hi == $hi {
223+
return ((hi as u64) << 32) | lo as u64;
224+
}
225+
},
226+
227+
#[cfg(not(riscv32))]
228+
() => $lo as u64,
229+
}
230+
}
231+
}
232+
}

src/register/mcycle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//! mcycle register
22
33
read_csr_as_usize!(0xB00, __read_mcycle);
4+
read_composite_csr!(super::mcycleh::read(), read());

src/register/minstret.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//! minstret register
22
33
read_csr_as_usize!(0xB02, __read_minstret);
4+
read_composite_csr!(super::minstreth::read(), read());

src/register/time.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//! time register
22
33
read_csr_as_usize!(0xC01, __read_time);
4+
read_composite_csr!(super::timeh::read(), read());

0 commit comments

Comments
 (0)