1
1
macro_rules! read_csr {
2
- ( $csr_number: expr , $asm_fn: ident) => {
2
+ ( $csr_number: literal , $asm_fn: ident) => {
3
3
/// Reads the CSR
4
4
#[ inline]
5
5
unsafe fn _read( ) -> usize {
6
6
match ( ) {
7
7
#[ cfg( all( riscv, feature = "inline-asm" ) ) ]
8
8
( ) => {
9
9
let r: usize ;
10
- core:: arch:: asm!( "csrrs {0}, {1}, x0" , out( reg) r, const $csr_number ) ;
10
+ core:: arch:: asm!( concat! ( "csrrs {0}, " , stringify! ( $csr_number ) , ", x0") , out( reg) r) ;
11
11
r
12
12
}
13
13
@@ -28,15 +28,15 @@ macro_rules! read_csr {
28
28
}
29
29
30
30
macro_rules! read_csr_rv32 {
31
- ( $csr_number: expr , $asm_fn: ident) => {
31
+ ( $csr_number: literal , $asm_fn: ident) => {
32
32
/// Reads the CSR
33
33
#[ inline]
34
34
unsafe fn _read( ) -> usize {
35
35
match ( ) {
36
36
#[ cfg( all( riscv32, feature = "inline-asm" ) ) ]
37
37
( ) => {
38
38
let r: usize ;
39
- core:: arch:: asm!( "csrrs {0}, {1}, x0" , out( reg) r, const $csr_number ) ;
39
+ core:: arch:: asm!( concat! ( "csrrs {0}, " , stringify! ( $csr_number ) , ", x0") , out( reg) r) ;
40
40
r
41
41
}
42
42
@@ -57,7 +57,7 @@ macro_rules! read_csr_rv32 {
57
57
}
58
58
59
59
macro_rules! read_csr_as {
60
- ( $register: ident, $csr_number: expr , $asm_fn: ident) => {
60
+ ( $register: ident, $csr_number: literal , $asm_fn: ident) => {
61
61
read_csr!( $csr_number, $asm_fn) ;
62
62
63
63
/// Reads the CSR
@@ -71,7 +71,7 @@ macro_rules! read_csr_as {
71
71
}
72
72
73
73
macro_rules! read_csr_as_usize {
74
- ( $csr_number: expr , $asm_fn: ident) => {
74
+ ( $csr_number: literal , $asm_fn: ident) => {
75
75
read_csr!( $csr_number, $asm_fn) ;
76
76
77
77
/// Reads the CSR
@@ -83,7 +83,7 @@ macro_rules! read_csr_as_usize {
83
83
}
84
84
85
85
macro_rules! read_csr_as_usize_rv32 {
86
- ( $csr_number: expr , $asm_fn: ident) => {
86
+ ( $csr_number: literal , $asm_fn: ident) => {
87
87
read_csr_rv32!( $csr_number, $asm_fn) ;
88
88
89
89
/// Reads the CSR
@@ -95,14 +95,14 @@ macro_rules! read_csr_as_usize_rv32 {
95
95
}
96
96
97
97
macro_rules! write_csr {
98
- ( $csr_number: expr , $asm_fn: ident) => {
98
+ ( $csr_number: literal , $asm_fn: ident) => {
99
99
/// Writes the CSR
100
100
#[ inline]
101
101
#[ allow( unused_variables) ]
102
102
unsafe fn _write( bits: usize ) {
103
103
match ( ) {
104
104
#[ cfg( all( riscv, feature = "inline-asm" ) ) ]
105
- ( ) => core:: arch:: asm!( "csrrw x0, {1}, {0}" , in( reg) bits, const $csr_number ) ,
105
+ ( ) => core:: arch:: asm!( concat! ( "csrrw x0, " , stringify! ( $csr_number ) , ", {0}") , in( reg) bits) ,
106
106
107
107
#[ cfg( all( riscv, not( feature = "inline-asm" ) ) ) ]
108
108
( ) => {
@@ -121,14 +121,14 @@ macro_rules! write_csr {
121
121
}
122
122
123
123
macro_rules! write_csr_rv32 {
124
- ( $csr_number: expr , $asm_fn: ident) => {
124
+ ( $csr_number: literal , $asm_fn: ident) => {
125
125
/// Writes the CSR
126
126
#[ inline]
127
127
#[ allow( unused_variables) ]
128
128
unsafe fn _write( bits: usize ) {
129
129
match ( ) {
130
130
#[ cfg( all( riscv32, feature = "inline-asm" ) ) ]
131
- ( ) => core:: arch:: asm!( "csrrw x0, {1}, {0}" , in( reg) bits, const $csr_number ) ,
131
+ ( ) => core:: arch:: asm!( concat! ( "csrrw x0, " , stringify! ( $csr_number ) , ", {0}") , in( reg) bits) ,
132
132
133
133
#[ cfg( all( riscv32, not( feature = "inline-asm" ) ) ) ]
134
134
( ) => {
@@ -147,7 +147,7 @@ macro_rules! write_csr_rv32 {
147
147
}
148
148
149
149
macro_rules! write_csr_as_usize {
150
- ( $csr_number: expr , $asm_fn: ident) => {
150
+ ( $csr_number: literal , $asm_fn: ident) => {
151
151
write_csr!( $csr_number, $asm_fn) ;
152
152
153
153
/// Writes the CSR
@@ -159,7 +159,7 @@ macro_rules! write_csr_as_usize {
159
159
}
160
160
161
161
macro_rules! write_csr_as_usize_rv32 {
162
- ( $csr_number: expr , $asm_fn: ident) => {
162
+ ( $csr_number: literal , $asm_fn: ident) => {
163
163
write_csr_rv32!( $csr_number, $asm_fn) ;
164
164
165
165
/// Writes the CSR
@@ -171,14 +171,14 @@ macro_rules! write_csr_as_usize_rv32 {
171
171
}
172
172
173
173
macro_rules! set {
174
- ( $csr_number: expr , $asm_fn: ident) => {
174
+ ( $csr_number: literal , $asm_fn: ident) => {
175
175
/// Set the CSR
176
176
#[ inline]
177
177
#[ allow( unused_variables) ]
178
178
unsafe fn _set( bits: usize ) {
179
179
match ( ) {
180
180
#[ cfg( all( riscv, feature = "inline-asm" ) ) ]
181
- ( ) => core:: arch:: asm!( "csrrs x0, {1}, {0}" , in( reg) bits, const $csr_number ) ,
181
+ ( ) => core:: arch:: asm!( concat! ( "csrrs x0, " , stringify! ( $csr_number ) , ", {0}") , in( reg) bits) ,
182
182
183
183
#[ cfg( all( riscv, not( feature = "inline-asm" ) ) ) ]
184
184
( ) => {
@@ -197,14 +197,14 @@ macro_rules! set {
197
197
}
198
198
199
199
macro_rules! clear {
200
- ( $csr_number: expr , $asm_fn: ident) => {
200
+ ( $csr_number: literal , $asm_fn: ident) => {
201
201
/// Clear the CSR
202
202
#[ inline]
203
203
#[ allow( unused_variables) ]
204
204
unsafe fn _clear( bits: usize ) {
205
205
match ( ) {
206
206
#[ cfg( all( riscv, feature = "inline-asm" ) ) ]
207
- ( ) => core:: arch:: asm!( "csrrc x0, {1}, {0}" , in( reg) bits, const $csr_number ) ,
207
+ ( ) => core:: arch:: asm!( concat! ( "csrrc x0, " , stringify! ( $csr_number ) , ", {0}") , in( reg) bits) ,
208
208
209
209
#[ cfg( all( riscv, not( feature = "inline-asm" ) ) ) ]
210
210
( ) => {
0 commit comments