@@ -23,6 +23,26 @@ pub enum Range {
23
23
NAPOT = 3 ,
24
24
}
25
25
26
+ #[ derive( Clone , Copy , Debug ) ]
27
+ pub struct Pmpcfg {
28
+ pub bits : usize ,
29
+ }
30
+
31
+ impl Pmpcfg {
32
+ #[ inline]
33
+ pub fn get_byte ( & self , index : usize ) -> PmpByte {
34
+ #[ cfg( riscv32) ]
35
+ assert ! ( index < 4 ) ;
36
+
37
+ #[ cfg( riscv64) ]
38
+ assert ! ( index < 8 ) ;
39
+
40
+ PmpByte {
41
+ byte : self . bits . get_bits ( 8 * index..8 * ( index + 1 ) ) as u8 ,
42
+ }
43
+ }
44
+ }
45
+
26
46
/// PmpByte holds the a single pmp configuration
27
47
#[ derive( Clone , Copy , Debug ) ]
28
48
pub struct PmpByte {
@@ -69,29 +89,9 @@ impl PmpByte {
69
89
/// Pmpcfg0 struct contains pmp0cfg - pmp3cfg for RV32, or pmp0cfg - pmp7cfg for RV64
70
90
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
71
91
pub mod pmpcfg0 {
72
- use super :: { BitField , Permission , PmpByte , Range } ;
73
-
74
- #[ derive( Clone , Copy , Debug ) ]
75
- pub struct Pmpcfg0 {
76
- pub bits : usize ,
77
- }
78
-
79
- impl Pmpcfg0 {
80
- #[ inline]
81
- pub fn get_byte ( & self , index : usize ) -> PmpByte {
82
- #[ cfg( riscv32) ]
83
- assert ! ( index < 4 ) ;
84
-
85
- #[ cfg( riscv64) ]
86
- assert ! ( index < 8 ) ;
92
+ use super :: { Permission , Pmpcfg , Range } ;
87
93
88
- PmpByte {
89
- byte : self . bits . get_bits ( 8 * index..8 * ( index + 1 ) ) as u8 ,
90
- }
91
- }
92
- }
93
-
94
- read_csr_as ! ( Pmpcfg0 , 0x3A0 , __read_pmpcfg0) ;
94
+ read_csr_as ! ( Pmpcfg , 0x3A0 , __read_pmpcfg0) ;
95
95
write_csr ! ( 0x3A0 , __write_pmpcfg0) ;
96
96
set ! ( 0x3A0 , __set_pmpcfg0) ;
97
97
clear ! ( 0x3A0 , __clear_pmpcfg0) ;
@@ -134,23 +134,9 @@ pub mod pmpcfg0 {
134
134
/// Pmpcfg1 struct contains pmp4cfg - pmp7cfg for RV32 only
135
135
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
136
136
pub mod pmpcfg1 {
137
- use super :: { BitField , Permission , PmpByte , Range } ;
138
-
139
- #[ derive( Clone , Copy , Debug ) ]
140
- pub struct Pmpcfg1 {
141
- pub bits : usize ,
142
- }
137
+ use super :: { Permission , Pmpcfg , Range } ;
143
138
144
- impl Pmpcfg1 {
145
- #[ inline]
146
- pub fn get_byte ( & self , index : usize ) -> PmpByte {
147
- PmpByte {
148
- byte : self . bits . get_bits ( 8 * index..8 * ( index + 1 ) ) as u8 ,
149
- }
150
- }
151
- }
152
-
153
- read_csr_as ! ( Pmpcfg1 , 0x3A1 , __read_pmpcfg1) ;
139
+ read_csr_as ! ( Pmpcfg , 0x3A1 , __read_pmpcfg1) ;
154
140
write_csr ! ( 0x3A1 , __write_pmpcfg1) ;
155
141
set ! ( 0x3A1 , __set_pmpcfg1) ;
156
142
clear ! ( 0x3A1 , __clear_pmpcfg1) ;
@@ -193,23 +179,9 @@ pub mod pmpcfg1 {
193
179
/// Pmpcfg0 struct contains pmp8cfg - pmp11cfg for RV32, or pmp8cfg - pmp15cfg for RV64
194
180
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
195
181
pub mod pmpcfg2 {
196
- use super :: { BitField , Permission , PmpByte , Range } ;
182
+ use super :: { Permission , Pmpcfg , Range } ;
197
183
198
- #[ derive( Clone , Copy , Debug ) ]
199
- pub struct Pmpcfg2 {
200
- pub bits : usize ,
201
- }
202
-
203
- impl Pmpcfg2 {
204
- #[ inline]
205
- pub fn get_byte ( & self , index : usize ) -> PmpByte {
206
- PmpByte {
207
- byte : self . bits . get_bits ( 8 * index..8 * ( index + 1 ) ) as u8 ,
208
- }
209
- }
210
- }
211
-
212
- read_csr_as ! ( Pmpcfg2 , 0x3A2 , __read_pmpcfg2) ;
184
+ read_csr_as ! ( Pmpcfg , 0x3A2 , __read_pmpcfg2) ;
213
185
write_csr ! ( 0x3A2 , __write_pmpcfg2) ;
214
186
set ! ( 0x3A2 , __set_pmpcfg2) ;
215
187
clear ! ( 0x3A2 , __clear_pmpcfg2) ;
@@ -252,22 +224,9 @@ pub mod pmpcfg2 {
252
224
/// Pmpcfg0 struct contains pmp12cfg - pmp15cfg for RV32 only
253
225
/// get_byte() method retrieves a single pmp<x>cfg held in a PmpByte struct
254
226
pub mod pmpcfg3 {
255
- use super :: { BitField , Permission , PmpByte , Range } ;
256
-
257
- #[ derive( Clone , Copy , Debug ) ]
258
- pub struct Pmpcfg3 {
259
- pub bits : usize ,
260
- }
261
- impl Pmpcfg3 {
262
- #[ inline]
263
- pub fn get_byte ( & self , index : usize ) -> PmpByte {
264
- PmpByte {
265
- byte : self . bits . get_bits ( 8 * index..8 * ( index + 1 ) ) as u8 ,
266
- }
267
- }
268
- }
227
+ use super :: { Permission , Pmpcfg , Range } ;
269
228
270
- read_csr_as ! ( Pmpcfg3 , 0x3A3 , __read_pmpcfg3) ;
229
+ read_csr_as ! ( Pmpcfg , 0x3A3 , __read_pmpcfg3) ;
271
230
write_csr ! ( 0x3A3 , __write_pmpcfg3) ;
272
231
set ! ( 0x3A3 , __set_pmpcfg3) ;
273
232
clear ! ( 0x3A3 , __clear_pmpcfg3) ;
0 commit comments