Skip to content

Commit 87e4408

Browse files
committed
riscv: add composite write macro util
1 parent dc00b03 commit 87e4408

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

riscv/src/register/macros.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,30 @@ macro_rules! read_composite_csr {
449449
};
450450
}
451451

452+
/// Convenience macro to write a composite value to a CSR register.
453+
///
454+
/// - `RV32`: writes 32-bits into `hi` and 32-bits into `lo` to create a 64-bit value
455+
/// - `RV64`: writes a 64-bit value into `lo`
456+
#[macro_export]
457+
macro_rules! write_composite_csr {
458+
($hi:expr, $lo:expr) => {
459+
/// Writes the CSR as a 64-bit value
460+
#[inline]
461+
pub unsafe fn write64(bits: u64) {
462+
match () {
463+
#[cfg(target_arch = "riscv32")]
464+
() => {
465+
$hi((bits >> 32) as usize);
466+
$lo(bits as usize);
467+
}
468+
469+
#[cfg(not(target_arch = "riscv32"))]
470+
() => $lo(bits as usize),
471+
}
472+
}
473+
};
474+
}
475+
452476
macro_rules! set_pmp {
453477
() => {
454478
/// Set the pmp configuration corresponding to the index.

0 commit comments

Comments
 (0)