Skip to content

Commit

Permalink
riscv: only define SXL/UXL setters for RV64
Browse files Browse the repository at this point in the history
Removes setters for the `SXL` and `UXL` fields in the `mstatus` CSR.

Provides a note in the documentation for RV32 users.

Authored-by: rmsyn <[email protected]>
Co-authored-by: romancardenas <[email protected]>
  • Loading branch information
rmsyn and romancardenas committed Dec 14, 2024
1 parent d28cd3e commit 906b027
Showing 1 changed file with 10 additions and 43 deletions.
53 changes: 10 additions & 43 deletions riscv/src/register/mstatus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
pub use super::misa::XLEN;
#[cfg(not(target_arch = "riscv32"))]
use crate::bits::{bf_extract, bf_insert};
#[cfg(target_arch = "riscv32")]
use crate::result::Error;
use crate::result::Result;

#[cfg(not(target_arch = "riscv32"))]
read_write_csr! {
Expand Down Expand Up @@ -253,28 +250,13 @@ impl Mstatus {
/// Note this updates a previously read [`Mstatus`] value, but does not
/// affect the mstatus CSR itself.
///
/// **NOTE**: panics on RISCV-32 platforms.
#[inline]
pub fn set_uxl(&mut self, uxl: XLEN) {
self.try_set_uxl(uxl).unwrap();
}

/// Attempts to update Effective xlen in U-mode (i.e., `UXLEN`).
/// # Note
///
/// Note this updates a previously read [`Mstatus`] value, but does not
/// affect the mstatus CSR itself.
/// In RISCV-32, `UXL` does not exist, and `UXLEN` is always [`XLEN::XLEN32`].
#[inline]
#[cfg_attr(not(target_arch = "riscv64"), allow(unused_variables))]
pub fn try_set_uxl(&mut self, uxl: XLEN) -> Result<()> {
match () {
#[cfg(not(target_arch = "riscv32"))]
() => {
self.bits = bf_insert(self.bits, 32, 2, uxl as usize);
Ok(())
}
#[cfg(target_arch = "riscv32")]
() => Err(Error::Unimplemented),
}
#[cfg(not(target_arch = "riscv32"))]
pub fn set_uxl(&mut self, uxl: XLEN) {
self.bits = bf_insert(self.bits, 32, 2, uxl as usize);
}

/// Effective xlen in S-mode (i.e., `SXLEN`).
Expand All @@ -295,28 +277,13 @@ impl Mstatus {
/// Note this updates a previously read [`Mstatus`] value, but does not
/// affect the mstatus CSR itself.
///
/// **NOTE**: panics on RISCV-32 platforms.
#[inline]
pub fn set_sxl(&mut self, sxl: XLEN) {
self.try_set_sxl(sxl).unwrap();
}

/// Attempts to update Effective xlen in S-mode (i.e., `SXLEN`).
/// # Note
///
/// Note this updates a previously read [`Mstatus`] value, but does not
/// affect the mstatus CSR itself.
/// In RISCV-32, `SXL` does not exist, and `SXLEN` is always [`XLEN::XLEN32`].
#[inline]
#[cfg_attr(not(target_arch = "riscv64"), allow(unused_variables))]
pub fn try_set_sxl(&mut self, sxl: XLEN) -> Result<()> {
match () {
#[cfg(not(target_arch = "riscv32"))]
() => {
self.bits = bf_insert(self.bits, 34, 2, sxl as usize);
Ok(())
}
#[cfg(target_arch = "riscv32")]
() => Err(Error::Unimplemented),
}
#[cfg(not(target_arch = "riscv32"))]
pub fn set_sxl(&mut self, sxl: XLEN) {
self.bits = bf_insert(self.bits, 34, 2, sxl as usize);
}

/// S-mode non-instruction-fetch memory endianness.
Expand Down

0 comments on commit 906b027

Please sign in to comment.