Skip to content

Commit d28cd3e

Browse files
rmsynromancardenas
andcommitted
riscv: recommend Mstatush for mbe + sbe
Recommends using the `Mstatush` register for the `mbe` and `sbe` fields on RISCV-32 platforms. Authored-by: rmsyn <[email protected]> Co-authored-by: romancardenas <[email protected]>
1 parent 43170a6 commit d28cd3e

File tree

1 file changed

+15
-42
lines changed

1 file changed

+15
-42
lines changed

riscv/src/register/mstatus.rs

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! mstatus register
22
33
pub use super::misa::XLEN;
4+
#[cfg(not(target_arch = "riscv32"))]
45
use crate::bits::{bf_extract, bf_insert};
56
#[cfg(target_arch = "riscv32")]
67
use crate::result::Error;
@@ -336,29 +337,15 @@ impl Mstatus {
336337
/// affect the mstatus CSR itself. See [`set_sbe`] to directly update the
337338
/// CSR.
338339
///
339-
/// **NOTE**: panics on RISCV-32 platforms.
340-
#[inline]
341-
pub fn set_sbe(&mut self, endianness: Endianness) {
342-
self.try_set_sbe(endianness).unwrap();
343-
}
344-
345-
/// Update S-mode non-instruction-fetch memory endianness
340+
/// # Note
346341
///
347-
/// Note this updates a previously read [`Mstatus`] value, but does not
348-
/// affect the mstatus CSR itself. See [`set_sbe`] to directly update the
349-
/// CSR.
342+
/// On RISCV-32 platforms, this function does not exist on the [`Mstatus`] instance.
343+
///
344+
/// Instead, RISCV-32 users should use the [`Mstatush`](crate::register::mstatush::Mstatush) register.
350345
#[inline]
351-
#[cfg_attr(not(target_arch = "riscv64"), allow(unused_variables))]
352-
pub fn try_set_sbe(&mut self, endianness: Endianness) -> Result<()> {
353-
match () {
354-
#[cfg(not(target_arch = "riscv32"))]
355-
() => {
356-
self.bits = bf_insert(self.bits, 36, 1, endianness as usize);
357-
Ok(())
358-
}
359-
#[cfg(target_arch = "riscv32")]
360-
() => Err(Error::Unimplemented),
361-
}
346+
#[cfg(not(target_arch = "riscv32"))]
347+
pub fn set_sbe(&mut self, endianness: Endianness) {
348+
self.bits = bf_insert(self.bits, 36, 1, endianness as usize);
362349
}
363350

364351
/// M-mode non-instruction-fetch memory endianness
@@ -379,29 +366,15 @@ impl Mstatus {
379366
/// affect the mstatus CSR itself. See [`set_mbe`] to directly update the
380367
/// CSR.
381368
///
382-
/// **NOTE**: panics on RISCV-32 platforms.
383-
#[inline]
384-
pub fn set_mbe(&mut self, endianness: Endianness) {
385-
self.try_set_mbe(endianness).unwrap();
386-
}
387-
388-
/// Update M-mode non-instruction-fetch memory endianness
369+
/// # Note
389370
///
390-
/// Note this updates a previously read [`Mstatus`] value, but does not
391-
/// affect the mstatus CSR itself. See [`set_mbe`] to directly update the
392-
/// CSR.
371+
/// On RISCV-32 platforms, this function does not exist on the [`Mstatus`] instance.
372+
///
373+
/// Instead, RISCV-32 users should use the [`Mstatush`](crate::register::mstatush::Mstatush) register.
393374
#[inline]
394-
#[cfg_attr(not(target_arch = "riscv64"), allow(unused_variables))]
395-
pub fn try_set_mbe(&mut self, endianness: Endianness) -> Result<()> {
396-
match () {
397-
#[cfg(not(target_arch = "riscv32"))]
398-
() => {
399-
self.bits = bf_insert(self.bits, 37, 1, endianness as usize);
400-
Ok(())
401-
}
402-
#[cfg(target_arch = "riscv32")]
403-
() => Err(Error::Unimplemented),
404-
}
375+
#[cfg(not(target_arch = "riscv32"))]
376+
pub fn set_mbe(&mut self, endianness: Endianness) {
377+
self.bits = bf_insert(self.bits, 37, 1, endianness as usize);
405378
}
406379
}
407380

0 commit comments

Comments
 (0)