1
+ /// `RV64`: Convenience macro to wrap the `csrrs` assembly instruction for reading a CSR register.
2
+ ///
3
+ /// This macro should generally not be called directly.
4
+ ///
5
+ /// Instead, use the [read_csr_as](crate::read_csr_as) or [read_csr_as_usize](crate::read_csr_as_usize) macros.
6
+ #[ macro_export]
1
7
macro_rules! read_csr {
2
8
( $csr_number: literal) => {
3
9
/// Reads the CSR
@@ -18,6 +24,12 @@ macro_rules! read_csr {
18
24
} ;
19
25
}
20
26
27
+ /// `RV32`: Convenience macro to wrap the `csrrs` assembly instruction for reading a CSR register.
28
+ ///
29
+ /// This macro should generally not be called directly.
30
+ ///
31
+ /// Instead, use the [read_csr_as_rv32](crate::read_csr_as_rv32) or [read_csr_as_usize_rv32](crate::read_csr_as_usize_rv32) macros.
32
+ #[ macro_export]
21
33
macro_rules! read_csr_rv32 {
22
34
( $csr_number: literal) => {
23
35
/// Reads the CSR
@@ -38,9 +50,13 @@ macro_rules! read_csr_rv32 {
38
50
} ;
39
51
}
40
52
53
+ /// `RV64`: Convenience macro to read a CSR register value as a `register` type.
54
+ ///
55
+ /// The `register` type must be a defined type in scope of the macro call.
56
+ #[ macro_export]
41
57
macro_rules! read_csr_as {
42
58
( $register: ident, $csr_number: literal) => {
43
- read_csr!( $csr_number) ;
59
+ $crate :: read_csr!( $csr_number) ;
44
60
45
61
/// Reads the CSR
46
62
#[ inline]
@@ -52,9 +68,13 @@ macro_rules! read_csr_as {
52
68
} ;
53
69
}
54
70
71
+ /// `RV32`: Convenience macro to read a CSR register value as a `register` type.
72
+ ///
73
+ /// The `register` type must be a defined type in scope of the macro call.
74
+ #[ macro_export]
55
75
macro_rules! read_csr_as_rv32 {
56
76
( $register: ident, $csr_number: literal) => {
57
- read_csr_rv32!( $csr_number) ;
77
+ $crate :: read_csr_rv32!( $csr_number) ;
58
78
59
79
/// Reads the CSR
60
80
#[ inline]
@@ -66,9 +86,11 @@ macro_rules! read_csr_as_rv32 {
66
86
} ;
67
87
}
68
88
89
+ /// `RV64`: Convenience macro to read a CSR register value as a [`usize`].
90
+ #[ macro_export]
69
91
macro_rules! read_csr_as_usize {
70
92
( $csr_number: literal) => {
71
- read_csr!( $csr_number) ;
93
+ $crate :: read_csr!( $csr_number) ;
72
94
73
95
/// Reads the CSR
74
96
#[ inline]
@@ -78,9 +100,11 @@ macro_rules! read_csr_as_usize {
78
100
} ;
79
101
}
80
102
103
+ /// `RV32`: Convenience macro to read a CSR register value as a [`usize`].
104
+ #[ macro_export]
81
105
macro_rules! read_csr_as_usize_rv32 {
82
106
( $csr_number: literal) => {
83
- read_csr_rv32!( $csr_number) ;
107
+ $crate :: read_csr_rv32!( $csr_number) ;
84
108
85
109
/// Reads the CSR
86
110
#[ inline]
@@ -90,6 +114,12 @@ macro_rules! read_csr_as_usize_rv32 {
90
114
} ;
91
115
}
92
116
117
+ /// `RV64`: Convenience macro to wrap the `csrrw` assembly instruction for writing to CSR registers.
118
+ ///
119
+ /// This macro should generally not be called directly.
120
+ ///
121
+ /// Instead, use the [write_csr_as_usize](crate::write_csr_as_usize) macro.
122
+ #[ macro_export]
93
123
macro_rules! write_csr {
94
124
( $csr_number: literal) => {
95
125
/// Writes the CSR
@@ -107,6 +137,12 @@ macro_rules! write_csr {
107
137
} ;
108
138
}
109
139
140
+ /// `RV32`: Convenience macro to wrap the `csrrw` assembly instruction for writing to CSR registers.
141
+ ///
142
+ /// This macro should generally not be called directly.
143
+ ///
144
+ /// Instead, use the [write_csr_as_usize_rv32](crate::write_csr_as_usize_rv32) macro.
145
+ #[ macro_export]
110
146
macro_rules! write_csr_rv32 {
111
147
( $csr_number: literal) => {
112
148
/// Writes the CSR
@@ -124,9 +160,11 @@ macro_rules! write_csr_rv32 {
124
160
} ;
125
161
}
126
162
163
+ /// `RV64`: Convenience macro to write a [`usize`] value to a CSR register.
164
+ #[ macro_export]
127
165
macro_rules! write_csr_as_usize {
128
166
( $csr_number: literal) => {
129
- write_csr!( $csr_number) ;
167
+ $crate :: write_csr!( $csr_number) ;
130
168
131
169
/// Writes the CSR
132
170
#[ inline]
@@ -136,9 +174,11 @@ macro_rules! write_csr_as_usize {
136
174
} ;
137
175
}
138
176
177
+ /// `RV32`: Convenience macro to write a [`usize`] value to a CSR register.
178
+ #[ macro_export]
139
179
macro_rules! write_csr_as_usize_rv32 {
140
180
( $csr_number: literal) => {
141
- write_csr_rv32!( $csr_number) ;
181
+ $crate :: write_csr_rv32!( $csr_number) ;
142
182
143
183
/// Writes the CSR
144
184
#[ inline]
@@ -148,6 +188,10 @@ macro_rules! write_csr_as_usize_rv32 {
148
188
} ;
149
189
}
150
190
191
+ /// `RV64`: Convenience macro around the `csrrs` assembly instruction to set the CSR register.
192
+ ///
193
+ /// This macro is intended for use with the [set_csr](crate::set_csr) or [set_clear_csr](crate::set_clear_csr) macros.
194
+ #[ macro_export]
151
195
macro_rules! set {
152
196
( $csr_number: literal) => {
153
197
/// Set the CSR
@@ -165,6 +209,10 @@ macro_rules! set {
165
209
} ;
166
210
}
167
211
212
+ /// `RV32`: Convenience macro around the `csrrs` assembly instruction to set the CSR register.
213
+ ///
214
+ /// This macro is intended for use with the [set_csr](crate::set_csr) or [set_clear_csr](crate::set_clear_csr) macros.
215
+ #[ macro_export]
168
216
macro_rules! set_rv32 {
169
217
( $csr_number: literal) => {
170
218
/// Set the CSR
@@ -182,6 +230,10 @@ macro_rules! set_rv32 {
182
230
} ;
183
231
}
184
232
233
+ /// `RV64`: Convenience macro around the `csrrc` assembly instruction to clear the CSR register.
234
+ ///
235
+ /// This macro is intended for use with the [clear_csr](crate::clear_csr) or [set_clear_csr](crate::set_clear_csr) macros.
236
+ #[ macro_export]
185
237
macro_rules! clear {
186
238
( $csr_number: literal) => {
187
239
/// Clear the CSR
@@ -199,6 +251,10 @@ macro_rules! clear {
199
251
} ;
200
252
}
201
253
254
+ /// `RV32`: Convenience macro around the `csrrc` assembly instruction to clear the CSR register.
255
+ ///
256
+ /// This macro is intended for use with the [clear_csr](crate::clear_csr) or [set_clear_csr](crate::set_clear_csr) macros.
257
+ #[ macro_export]
202
258
macro_rules! clear_rv32 {
203
259
( $csr_number: literal) => {
204
260
/// Clear the CSR
@@ -216,6 +272,8 @@ macro_rules! clear_rv32 {
216
272
} ;
217
273
}
218
274
275
+ /// Convenience macro to define field setter functions for a CSR type.
276
+ #[ macro_export]
219
277
macro_rules! set_csr {
220
278
( $( #[ $attr: meta] ) * , $set_field: ident, $e: expr) => {
221
279
$( #[ $attr] ) *
@@ -226,6 +284,8 @@ macro_rules! set_csr {
226
284
} ;
227
285
}
228
286
287
+ /// Convenience macro to define field clear functions for a CSR type.
288
+ #[ macro_export]
229
289
macro_rules! clear_csr {
230
290
( $( #[ $attr: meta] ) * , $clear_field: ident, $e: expr) => {
231
291
$( #[ $attr] ) *
@@ -236,13 +296,20 @@ macro_rules! clear_csr {
236
296
} ;
237
297
}
238
298
299
+ /// Convenience macro to define field setter and clear functions for a CSR type.
300
+ #[ macro_export]
239
301
macro_rules! set_clear_csr {
240
302
( $( #[ $attr: meta] ) * , $set_field: ident, $clear_field: ident, $e: expr) => {
241
- set_csr!( $( #[ $attr] ) * , $set_field, $e) ;
242
- clear_csr!( $( #[ $attr] ) * , $clear_field, $e) ;
303
+ $crate :: set_csr!( $( #[ $attr] ) * , $set_field, $e) ;
304
+ $crate :: clear_csr!( $( #[ $attr] ) * , $clear_field, $e) ;
243
305
}
244
306
}
245
307
308
+ /// Convenience macro to read a composite value from a CSR register.
309
+ ///
310
+ /// - `RV32`: reads 32-bits from `hi` and 32-bits from `lo` to create a 64-bit value
311
+ /// - `RV64`: reads a 64-bit value from `lo`
312
+ #[ macro_export]
246
313
macro_rules! read_composite_csr {
247
314
( $hi: expr, $lo: expr) => {
248
315
/// Reads the CSR as a 64-bit value
0 commit comments