@@ -39,18 +39,13 @@ pub mod pmpcfg0 {
39
39
///Returns the pmp byte associated with the index
40
40
#[ inline]
41
41
pub fn pmp_byte ( & self , index : usize ) -> usize {
42
+ #[ cfg( riscv32) ]
43
+ assert ! ( index < 4 ) ;
44
+
45
+ #[ cfg( riscv64) ]
42
46
assert ! ( index < 8 ) ;
43
- match index {
44
- 0 => self . bits . get_bits ( 0 ..8 ) ,
45
- 1 => self . bits . get_bits ( 8 ..16 ) ,
46
- 2 => self . bits . get_bits ( 16 ..24 ) ,
47
- 3 => self . bits . get_bits ( 24 ..32 ) ,
48
- 4 => self . bits . get_bits ( 32 ..40 ) ,
49
- 5 => self . bits . get_bits ( 40 ..48 ) ,
50
- 6 => self . bits . get_bits ( 48 ..56 ) ,
51
- 7 => self . bits . get_bits ( 56 ..64 ) ,
52
- _ => panic ! ( ) ,
53
- }
47
+
48
+ self . bits . get_bits ( 8 * index..8 * ( index + 1 ) )
54
49
}
55
50
56
51
#[ inline]
@@ -60,22 +55,22 @@ pub mod pmpcfg0 {
60
55
1 => Range :: TOR ,
61
56
2 => Range :: NA4 ,
62
57
3 => Range :: NAPOT ,
63
- _ => panic ! ( ) ,
58
+ _ => unreachable ! ( ) ,
64
59
}
65
60
}
66
61
67
62
#[ inline]
68
- fn permission ( & self , byte : usize ) -> Permission {
69
- match byte. get_bits ( 0 ..4 ) {
70
- 0 => Permission :: NONE ,
71
- 1 => Permission :: R ,
72
- 2 => Permission :: W ,
73
- 3 => Permission :: RW ,
74
- 4 => Permission :: X ,
75
- 5 => Permission :: RX ,
76
- 6 => Permission :: WX ,
77
- 7 => Permission :: RWX ,
78
- _ => panic ! ( ) ,
63
+ fn permission ( & self , byte : usize ) -> Option < Permission > {
64
+ match byte. get_bits ( 0 ..3 ) {
65
+ 0 => Some ( Permission :: NONE ) ,
66
+ 1 => Some ( Permission :: R ) ,
67
+ 2 => Some ( Permission :: W ) ,
68
+ 3 => Some ( Permission :: RW ) ,
69
+ 4 => Some ( Permission :: X ) ,
70
+ 5 => Some ( Permission :: RX ) ,
71
+ 6 => Some ( Permission :: WX ) ,
72
+ 7 => Some ( Permission :: RWX ) ,
73
+ _ => None ,
79
74
}
80
75
}
81
76
@@ -84,7 +79,7 @@ pub mod pmpcfg0 {
84
79
pub fn pmp_cfg ( & self , index : usize ) -> Pmpconfig {
85
80
assert ! ( index < 8 ) ;
86
81
let byte = self . pmp_byte ( index) ;
87
- let p = self . permission ( byte) ;
82
+ let p = self . permission ( byte) . unwrap ( ) ;
88
83
let r = self . range ( byte) ;
89
84
let l = byte. get_bit ( 7 ) ;
90
85
0 commit comments