Read composite CSRs as one 64-bit value
This commit is contained in:
parent
b665adeb95
commit
925c496949
|
@ -208,3 +208,25 @@ macro_rules! set_clear_csr {
|
||||||
clear_csr!($(#[$attr])*, $clear_field, $e);
|
clear_csr!($(#[$attr])*, $clear_field, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! read_composite_csr {
|
||||||
|
($hi:expr, $lo:expr) => {
|
||||||
|
/// Reads the CSR as a 64-bit value
|
||||||
|
#[inline]
|
||||||
|
pub fn read64() -> u64 {
|
||||||
|
match () {
|
||||||
|
#[cfg(riscv32)]
|
||||||
|
() => loop {
|
||||||
|
let hi = $hi;
|
||||||
|
let lo = $lo;
|
||||||
|
if hi == $hi {
|
||||||
|
return ((hi as u64) << 32) | lo as u64;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
#[cfg(not(riscv32))]
|
||||||
|
() => $lo as u64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
//! mcycle register
|
//! mcycle register
|
||||||
|
|
||||||
read_csr_as_usize!(0xB00, __read_mcycle);
|
read_csr_as_usize!(0xB00, __read_mcycle);
|
||||||
|
read_composite_csr!(super::mcycleh::read(), read());
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
//! minstret register
|
//! minstret register
|
||||||
|
|
||||||
read_csr_as_usize!(0xB02, __read_minstret);
|
read_csr_as_usize!(0xB02, __read_minstret);
|
||||||
|
read_composite_csr!(super::minstreth::read(), read());
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
//! time register
|
//! time register
|
||||||
|
|
||||||
read_csr_as_usize!(0xC01, __read_time);
|
read_csr_as_usize!(0xC01, __read_time);
|
||||||
|
read_composite_csr!(super::timeh::read(), read());
|
||||||
|
|
Loading…
Reference in New Issue