1
- /// `RV64`: Convenience macro to wrap the `csrrs` assembly instruction for reading a CSR register.
1
+ /// Convenience macro to wrap the `csrrs` assembly instruction for reading a CSR register.
2
2
///
3
3
/// This macro should generally not be called directly.
4
4
///
@@ -10,14 +10,14 @@ macro_rules! read_csr {
10
10
#[ inline]
11
11
unsafe fn _read( ) -> usize {
12
12
match ( ) {
13
- #[ cfg( riscv ) ]
13
+ #[ cfg( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ]
14
14
( ) => {
15
15
let r: usize ;
16
16
core:: arch:: asm!( concat!( "csrrs {0}, " , stringify!( $csr_number) , ", x0" ) , out( reg) r) ;
17
17
r
18
18
}
19
19
20
- #[ cfg( not( riscv ) ) ]
20
+ #[ cfg( not( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ) ]
21
21
( ) => unimplemented!( ) ,
22
22
}
23
23
}
@@ -36,21 +36,21 @@ macro_rules! read_csr_rv32 {
36
36
#[ inline]
37
37
unsafe fn _read( ) -> usize {
38
38
match ( ) {
39
- #[ cfg( riscv32) ]
39
+ #[ cfg( target_arch = " riscv32" ) ]
40
40
( ) => {
41
41
let r: usize ;
42
42
core:: arch:: asm!( concat!( "csrrs {0}, " , stringify!( $csr_number) , ", x0" ) , out( reg) r) ;
43
43
r
44
44
}
45
45
46
- #[ cfg( not( riscv32) ) ]
46
+ #[ cfg( not( target_arch = " riscv32" ) ) ]
47
47
( ) => unimplemented!( ) ,
48
48
}
49
49
}
50
50
} ;
51
51
}
52
52
53
- /// `RV64`: Convenience macro to read a CSR register value as a `register` type.
53
+ /// Convenience macro to read a CSR register value as a `register` type.
54
54
///
55
55
/// The `register` type must be a defined type in scope of the macro call.
56
56
#[ macro_export]
@@ -86,7 +86,7 @@ macro_rules! read_csr_as_rv32 {
86
86
} ;
87
87
}
88
88
89
- /// `RV64`: Convenience macro to read a CSR register value as a [`usize`].
89
+ /// Convenience macro to read a CSR register value as a [`usize`].
90
90
#[ macro_export]
91
91
macro_rules! read_csr_as_usize {
92
92
( $csr_number: literal) => {
@@ -114,7 +114,7 @@ macro_rules! read_csr_as_usize_rv32 {
114
114
} ;
115
115
}
116
116
117
- /// `RV64`: Convenience macro to wrap the `csrrw` assembly instruction for writing to CSR registers.
117
+ /// Convenience macro to wrap the `csrrw` assembly instruction for writing to CSR registers.
118
118
///
119
119
/// This macro should generally not be called directly.
120
120
///
@@ -127,10 +127,10 @@ macro_rules! write_csr {
127
127
#[ allow( unused_variables) ]
128
128
unsafe fn _write( bits: usize ) {
129
129
match ( ) {
130
- #[ cfg( riscv ) ]
130
+ #[ cfg( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ]
131
131
( ) => core:: arch:: asm!( concat!( "csrrw x0, " , stringify!( $csr_number) , ", {0}" ) , in( reg) bits) ,
132
132
133
- #[ cfg( not( riscv ) ) ]
133
+ #[ cfg( not( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ) ]
134
134
( ) => unimplemented!( ) ,
135
135
}
136
136
}
@@ -150,17 +150,17 @@ macro_rules! write_csr_rv32 {
150
150
#[ allow( unused_variables) ]
151
151
unsafe fn _write( bits: usize ) {
152
152
match ( ) {
153
- #[ cfg( riscv32) ]
153
+ #[ cfg( target_arch = " riscv32" ) ]
154
154
( ) => core:: arch:: asm!( concat!( "csrrw x0, " , stringify!( $csr_number) , ", {0}" ) , in( reg) bits) ,
155
155
156
- #[ cfg( not( riscv32) ) ]
156
+ #[ cfg( not( target_arch = " riscv32" ) ) ]
157
157
( ) => unimplemented!( ) ,
158
158
}
159
159
}
160
160
} ;
161
161
}
162
162
163
- /// `RV64`: Convenience macro to write a [`usize`] value to a CSR register.
163
+ /// Convenience macro to write a [`usize`] value to a CSR register.
164
164
#[ macro_export]
165
165
macro_rules! write_csr_as_usize {
166
166
( $csr_number: literal) => {
@@ -188,7 +188,7 @@ macro_rules! write_csr_as_usize_rv32 {
188
188
} ;
189
189
}
190
190
191
- /// `RV64`: Convenience macro around the `csrrs` assembly instruction to set the CSR register.
191
+ /// Convenience macro around the `csrrs` assembly instruction to set the CSR register.
192
192
///
193
193
/// This macro is intended for use with the [set_csr](crate::set_csr) or [set_clear_csr](crate::set_clear_csr) macros.
194
194
#[ macro_export]
@@ -199,10 +199,10 @@ macro_rules! set {
199
199
#[ allow( unused_variables) ]
200
200
unsafe fn _set( bits: usize ) {
201
201
match ( ) {
202
- #[ cfg( riscv ) ]
202
+ #[ cfg( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ]
203
203
( ) => core:: arch:: asm!( concat!( "csrrs x0, " , stringify!( $csr_number) , ", {0}" ) , in( reg) bits) ,
204
204
205
- #[ cfg( not( riscv ) ) ]
205
+ #[ cfg( not( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ) ]
206
206
( ) => unimplemented!( ) ,
207
207
}
208
208
}
@@ -220,17 +220,17 @@ macro_rules! set_rv32 {
220
220
#[ allow( unused_variables) ]
221
221
unsafe fn _set( bits: usize ) {
222
222
match ( ) {
223
- #[ cfg( riscv32) ]
223
+ #[ cfg( target_arch = " riscv32" ) ]
224
224
( ) => core:: arch:: asm!( concat!( "csrrs x0, " , stringify!( $csr_number) , ", {0}" ) , in( reg) bits) ,
225
225
226
- #[ cfg( not( riscv32) ) ]
226
+ #[ cfg( not( target_arch = " riscv32" ) ) ]
227
227
( ) => unimplemented!( ) ,
228
228
}
229
229
}
230
230
} ;
231
231
}
232
232
233
- /// `RV64`: Convenience macro around the `csrrc` assembly instruction to clear the CSR register.
233
+ /// Convenience macro around the `csrrc` assembly instruction to clear the CSR register.
234
234
///
235
235
/// This macro is intended for use with the [clear_csr](crate::clear_csr) or [set_clear_csr](crate::set_clear_csr) macros.
236
236
#[ macro_export]
@@ -241,10 +241,10 @@ macro_rules! clear {
241
241
#[ allow( unused_variables) ]
242
242
unsafe fn _clear( bits: usize ) {
243
243
match ( ) {
244
- #[ cfg( riscv ) ]
244
+ #[ cfg( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ]
245
245
( ) => core:: arch:: asm!( concat!( "csrrc x0, " , stringify!( $csr_number) , ", {0}" ) , in( reg) bits) ,
246
246
247
- #[ cfg( not( riscv ) ) ]
247
+ #[ cfg( not( any ( target_arch = "riscv32" , target_arch = "riscv64" ) ) ) ]
248
248
( ) => unimplemented!( ) ,
249
249
}
250
250
}
@@ -262,10 +262,10 @@ macro_rules! clear_rv32 {
262
262
#[ allow( unused_variables) ]
263
263
unsafe fn _clear( bits: usize ) {
264
264
match ( ) {
265
- #[ cfg( riscv32) ]
265
+ #[ cfg( target_arch = " riscv32" ) ]
266
266
( ) => core:: arch:: asm!( concat!( "csrrc x0, " , stringify!( $csr_number) , ", {0}" ) , in( reg) bits) ,
267
267
268
- #[ cfg( not( riscv32) ) ]
268
+ #[ cfg( not( target_arch = " riscv32" ) ) ]
269
269
( ) => unimplemented!( ) ,
270
270
}
271
271
}
@@ -316,7 +316,7 @@ macro_rules! read_composite_csr {
316
316
#[ inline]
317
317
pub fn read64( ) -> u64 {
318
318
match ( ) {
319
- #[ cfg( riscv32) ]
319
+ #[ cfg( target_arch = " riscv32" ) ]
320
320
( ) => loop {
321
321
let hi = $hi;
322
322
let lo = $lo;
@@ -325,7 +325,7 @@ macro_rules! read_composite_csr {
325
325
}
326
326
} ,
327
327
328
- #[ cfg( not( riscv32) ) ]
328
+ #[ cfg( not( target_arch = " riscv32" ) ) ]
329
329
( ) => $lo as u64 ,
330
330
}
331
331
}
@@ -337,10 +337,10 @@ macro_rules! set_pmp {
337
337
/// Set the pmp configuration corresponding to the index
338
338
#[ inline]
339
339
pub unsafe fn set_pmp( index: usize , range: Range , permission: Permission , locked: bool ) {
340
- #[ cfg( riscv32) ]
340
+ #[ cfg( target_arch = " riscv32" ) ]
341
341
assert!( index < 4 ) ;
342
342
343
- #[ cfg( riscv64) ]
343
+ #[ cfg( target_arch = " riscv64" ) ]
344
344
assert!( index < 8 ) ;
345
345
346
346
let mut value = _read( ) ;
@@ -357,10 +357,10 @@ macro_rules! clear_pmp {
357
357
/// Clear the pmp configuration corresponding to the index
358
358
#[ inline]
359
359
pub unsafe fn clear_pmp( index: usize ) {
360
- #[ cfg( riscv32) ]
360
+ #[ cfg( target_arch = " riscv32" ) ]
361
361
assert!( index < 4 ) ;
362
362
363
- #[ cfg( riscv64) ]
363
+ #[ cfg( target_arch = " riscv64" ) ]
364
364
assert!( index < 8 ) ;
365
365
366
366
let mut value = _read( ) ;
0 commit comments