File tree Expand file tree Collapse file tree 6 files changed +35
-0
lines changed Expand file tree Collapse file tree 6 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
88## [ Unreleased]
99
10+ ### Added
11+
12+ - CSR helper macro ` write_composite_csr ` for writing 64-bit CSRs on 32-bit targets.
13+ - Write utilities for ` mcycle ` , ` minstret `
14+
1015## [ v0.13.0] - 2025-02-18
1116
1217### Added
Original file line number Diff line number Diff 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+
452476macro_rules! set_pmp {
453477 ( ) => {
454478 /// Set the pmp configuration corresponding to the index.
Original file line number Diff line number Diff line change 11//! mcycle register
22
33read_csr_as_usize ! ( 0xB00 ) ;
4+ write_csr_as_usize ! ( 0xB00 ) ;
45read_composite_csr ! ( super :: mcycleh:: read( ) , read( ) ) ;
6+ write_composite_csr ! ( super :: mcycleh:: write, write) ;
Original file line number Diff line number Diff line change 11//! mcycleh register
22
33read_csr_as_usize_rv32 ! ( 0xB80 ) ;
4+ write_csr_as_usize_rv32 ! ( 0xB80 ) ;
Original file line number Diff line number Diff line change 11//! minstret register
22
33read_csr_as_usize ! ( 0xB02 ) ;
4+ write_csr_as_usize ! ( 0xB02 ) ;
45read_composite_csr ! ( super :: minstreth:: read( ) , read( ) ) ;
6+ write_composite_csr ! ( super :: minstreth:: write, write) ;
Original file line number Diff line number Diff line change 11//! minstreth register
22
33read_csr_as_usize_rv32 ! ( 0xB82 ) ;
4+ write_csr_as_usize_rv32 ! ( 0xB82 ) ;
You can’t perform that action at this time.
0 commit comments