Skip to content

Commit

Permalink
Merge pull request #249 from rmsyn/register/mstatush-csr-macro
Browse files Browse the repository at this point in the history
riscv: define `mstatush` CSR with macro helpers
  • Loading branch information
romancardenas authored Dec 18, 2024
2 parents 60800c1 + ed2a9ea commit 433366f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use CSR helper macros to define `misa` register
- Use CSR helper macros to define `mip` register
- Use CSR helper macros to define `mstatus` register
- Use CSR helper macros to define `mstatush` register

## [v0.12.1] - 2024-10-20

Expand Down
45 changes: 30 additions & 15 deletions riscv/src/register/mstatush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@
pub use super::mstatus::Endianness;

/// mstatus register
#[derive(Clone, Copy, Debug)]
pub struct Mstatush {
bits: usize,
read_write_csr! {
/// mstatus register
Mstatush: 0x310,
mask: 0x30,
}

impl Mstatush {
read_write_csr_field! {
Mstatush,
/// S-mode non-instruction-fetch memory endianness
#[inline]
pub fn sbe(&self) -> Endianness {
Endianness::from(self.bits & (1 << 4) != 0)
}
sbe,
Endianness: [4:4],
}

read_write_csr_field! {
Mstatush,
/// M-mode non-instruction-fetch memory endianness
#[inline]
pub fn mbe(&self) -> Endianness {
Endianness::from(self.bits & (1 << 5) != 0)
}
mbe,
Endianness: [5:5],
}

read_csr_as_rv32!(Mstatush, 0x310);
write_csr_rv32!(0x310);
set_rv32!(0x310);
clear_rv32!(0x310);

Expand All @@ -44,3 +42,20 @@ pub unsafe fn set_mbe(endianness: Endianness) {
Endianness::LittleEndian => _clear(1 << 5),
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_mstatush() {
let mut m = Mstatush::from_bits(0);

[Endianness::LittleEndian, Endianness::BigEndian]
.into_iter()
.for_each(|endianness| {
test_csr_field!(m, sbe: endianness);
test_csr_field!(m, mbe: endianness);
});
}
}

0 comments on commit 433366f

Please sign in to comment.