@@ -12,13 +12,13 @@ macro_rules! read_csr {
12
12
/// Reads the CSR.
13
13
///
14
14
/// **WARNING**: panics on non-`riscv` targets.
15
- #[ inline]
15
+ #[ inline( always ) ]
16
16
unsafe fn _read( ) -> usize {
17
17
_try_read( ) . unwrap( )
18
18
}
19
19
20
20
/// Attempts to read the CSR.
21
- #[ inline]
21
+ #[ inline( always ) ]
22
22
unsafe fn _try_read( ) -> $crate:: result:: Result <usize > {
23
23
match ( ) {
24
24
#[ cfg( $( $cfg) ,* ) ]
@@ -155,13 +155,13 @@ macro_rules! write_csr {
155
155
/// Writes the CSR.
156
156
///
157
157
/// **WARNING**: panics on non-`riscv` targets.
158
- #[ inline]
158
+ #[ inline( always ) ]
159
159
unsafe fn _write( bits: usize ) {
160
160
_try_write( bits) . unwrap( ) ;
161
161
}
162
162
163
163
/// Attempts to write the CSR.
164
- #[ inline]
164
+ #[ inline( always ) ]
165
165
#[ cfg_attr( not( $( $cfg) ,* ) , allow( unused_variables) ) ]
166
166
unsafe fn _try_write( bits: usize ) -> $crate:: result:: Result <( ) > {
167
167
match ( ) {
@@ -195,9 +195,29 @@ macro_rules! write_csr_as {
195
195
( $csr_type: ty, $csr_number: literal) => {
196
196
$crate:: write_csr_as!( $csr_type, $csr_number, any( target_arch = "riscv32" , target_arch = "riscv64" ) ) ;
197
197
} ;
198
+ ( safe $csr_type: ty, $csr_number: literal) => {
199
+ $crate:: write_csr_as!( safe $csr_type, $csr_number, any( target_arch = "riscv32" , target_arch = "riscv64" ) ) ;
200
+ } ;
198
201
( $csr_type: ty, $csr_number: literal, $( $cfg: meta) ,* ) => {
199
202
$crate:: write_csr!( $csr_number, $( $cfg) ,* ) ;
200
203
204
+ /// Writes the CSR.
205
+ ///
206
+ /// **WARNING**: panics on non-`riscv` targets.
207
+ #[ inline]
208
+ pub unsafe fn write( value: $csr_type) {
209
+ _write( value. bits) ;
210
+ }
211
+
212
+ /// Attempts to write the CSR.
213
+ #[ inline]
214
+ pub unsafe fn try_write( value: $csr_type) -> $crate:: result:: Result <( ) > {
215
+ _try_write( value. bits)
216
+ }
217
+ } ;
218
+ ( safe $csr_type: ty, $csr_number: literal, $( $cfg: meta) ,* ) => {
219
+ $crate:: write_csr!( $csr_number, $( $cfg) ,* ) ;
220
+
201
221
/// Writes the CSR.
202
222
///
203
223
/// **WARNING**: panics on non-`riscv` targets.
@@ -220,6 +240,9 @@ macro_rules! write_csr_as_rv32 {
220
240
( $csr_type: ty, $csr_number: literal) => {
221
241
$crate:: write_csr_as!( $csr_type, $csr_number, target_arch = "riscv32" ) ;
222
242
} ;
243
+ ( safe $csr_type: ty, $csr_number: literal) => {
244
+ $crate:: write_csr_as!( safe $csr_type, $csr_number, target_arch = "riscv32" ) ;
245
+ } ;
223
246
}
224
247
225
248
/// Convenience macro to write a [`usize`] value to a CSR register.
@@ -228,9 +251,29 @@ macro_rules! write_csr_as_usize {
228
251
( $csr_number: literal) => {
229
252
$crate:: write_csr_as_usize!( $csr_number, any( target_arch = "riscv32" , target_arch = "riscv64" ) ) ;
230
253
} ;
254
+ ( safe $csr_number: literal) => {
255
+ $crate:: write_csr_as_usize!( safe $csr_number, any( target_arch = "riscv32" , target_arch = "riscv64" ) ) ;
256
+ } ;
231
257
( $csr_number: literal, $( $cfg: meta) ,* ) => {
232
258
$crate:: write_csr!( $csr_number, $( $cfg) ,* ) ;
233
259
260
+ /// Writes the CSR.
261
+ ///
262
+ /// **WARNING**: panics on non-`riscv` targets.
263
+ #[ inline]
264
+ pub unsafe fn write( bits: usize ) {
265
+ _write( bits) ;
266
+ }
267
+
268
+ /// Attempts to write the CSR.
269
+ #[ inline]
270
+ pub unsafe fn try_write( bits: usize ) -> $crate:: result:: Result <( ) > {
271
+ _try_write( bits)
272
+ }
273
+ } ;
274
+ ( safe $csr_number: literal, $( $cfg: meta) ,* ) => {
275
+ $crate:: write_csr!( $csr_number, $( $cfg) ,* ) ;
276
+
234
277
/// Writes the CSR.
235
278
///
236
279
/// **WARNING**: panics on non-`riscv` targets.
@@ -253,6 +296,9 @@ macro_rules! write_csr_as_usize_rv32 {
253
296
( $csr_number: literal) => {
254
297
$crate:: write_csr_as_usize!( $csr_number, target_arch = "riscv32" ) ;
255
298
} ;
299
+ ( safe $csr_number: literal) => {
300
+ $crate:: write_csr_as_usize!( safe $csr_number, target_arch = "riscv32" ) ;
301
+ } ;
256
302
}
257
303
258
304
/// Convenience macro around the `csrrs` assembly instruction to set the CSR register.
@@ -267,13 +313,13 @@ macro_rules! set {
267
313
/// Set the CSR.
268
314
///
269
315
/// **WARNING**: panics on non-`riscv` targets.
270
- #[ inline]
316
+ #[ inline( always ) ]
271
317
unsafe fn _set( bits: usize ) {
272
318
_try_set( bits) . unwrap( ) ;
273
319
}
274
320
275
321
/// Attempts to set the CSR.
276
- #[ inline]
322
+ #[ inline( always ) ]
277
323
#[ cfg_attr( not( $( $cfg) ,* ) , allow( unused_variables) ) ]
278
324
unsafe fn _try_set( bits: usize ) -> $crate:: result:: Result <( ) > {
279
325
match ( ) {
@@ -311,13 +357,13 @@ macro_rules! clear {
311
357
/// Clear the CSR.
312
358
///
313
359
/// **WARNING**: panics on non-`riscv` targets.
314
- #[ inline]
360
+ #[ inline( always ) ]
315
361
unsafe fn _clear( bits: usize ) {
316
362
_try_clear( bits) . unwrap( ) ;
317
363
}
318
364
319
365
/// Attempts to clear the CSR.
320
- #[ inline]
366
+ #[ inline( always ) ]
321
367
#[ cfg_attr( not( $( $cfg) ,* ) , allow( unused_variables) ) ]
322
368
unsafe fn _try_clear( bits: usize ) -> $crate:: result:: Result <( ) > {
323
369
match ( ) {
0 commit comments