Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}
}
Loading