Skip to content

Commit 906b027

Browse files
rmsynromancardenas
andcommitted
riscv: only define SXL/UXL setters for RV64
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]>
1 parent d28cd3e commit 906b027

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

riscv/src/register/mstatus.rs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
pub use super::misa::XLEN;
44
#[cfg(not(target_arch = "riscv32"))]
55
use crate::bits::{bf_extract, bf_insert};
6-
#[cfg(target_arch = "riscv32")]
7-
use crate::result::Error;
8-
use crate::result::Result;
96

107
#[cfg(not(target_arch = "riscv32"))]
118
read_write_csr! {
@@ -253,28 +250,13 @@ impl Mstatus {
253250
/// Note this updates a previously read [`Mstatus`] value, but does not
254251
/// affect the mstatus CSR itself.
255252
///
256-
/// **NOTE**: panics on RISCV-32 platforms.
257-
#[inline]
258-
pub fn set_uxl(&mut self, uxl: XLEN) {
259-
self.try_set_uxl(uxl).unwrap();
260-
}
261-
262-
/// Attempts to update Effective xlen in U-mode (i.e., `UXLEN`).
253+
/// # Note
263254
///
264-
/// Note this updates a previously read [`Mstatus`] value, but does not
265-
/// affect the mstatus CSR itself.
255+
/// In RISCV-32, `UXL` does not exist, and `UXLEN` is always [`XLEN::XLEN32`].
266256
#[inline]
267-
#[cfg_attr(not(target_arch = "riscv64"), allow(unused_variables))]
268-
pub fn try_set_uxl(&mut self, uxl: XLEN) -> Result<()> {
269-
match () {
270-
#[cfg(not(target_arch = "riscv32"))]
271-
() => {
272-
self.bits = bf_insert(self.bits, 32, 2, uxl as usize);
273-
Ok(())
274-
}
275-
#[cfg(target_arch = "riscv32")]
276-
() => Err(Error::Unimplemented),
277-
}
257+
#[cfg(not(target_arch = "riscv32"))]
258+
pub fn set_uxl(&mut self, uxl: XLEN) {
259+
self.bits = bf_insert(self.bits, 32, 2, uxl as usize);
278260
}
279261

280262
/// Effective xlen in S-mode (i.e., `SXLEN`).
@@ -295,28 +277,13 @@ impl Mstatus {
295277
/// Note this updates a previously read [`Mstatus`] value, but does not
296278
/// affect the mstatus CSR itself.
297279
///
298-
/// **NOTE**: panics on RISCV-32 platforms.
299-
#[inline]
300-
pub fn set_sxl(&mut self, sxl: XLEN) {
301-
self.try_set_sxl(sxl).unwrap();
302-
}
303-
304-
/// Attempts to update Effective xlen in S-mode (i.e., `SXLEN`).
280+
/// # Note
305281
///
306-
/// Note this updates a previously read [`Mstatus`] value, but does not
307-
/// affect the mstatus CSR itself.
282+
/// In RISCV-32, `SXL` does not exist, and `SXLEN` is always [`XLEN::XLEN32`].
308283
#[inline]
309-
#[cfg_attr(not(target_arch = "riscv64"), allow(unused_variables))]
310-
pub fn try_set_sxl(&mut self, sxl: XLEN) -> Result<()> {
311-
match () {
312-
#[cfg(not(target_arch = "riscv32"))]
313-
() => {
314-
self.bits = bf_insert(self.bits, 34, 2, sxl as usize);
315-
Ok(())
316-
}
317-
#[cfg(target_arch = "riscv32")]
318-
() => Err(Error::Unimplemented),
319-
}
284+
#[cfg(not(target_arch = "riscv32"))]
285+
pub fn set_sxl(&mut self, sxl: XLEN) {
286+
self.bits = bf_insert(self.bits, 34, 2, sxl as usize);
320287
}
321288

322289
/// S-mode non-instruction-fetch memory endianness.

0 commit comments

Comments
 (0)