Skip to content

Commit 6a2bdbf

Browse files
committed
Refactoring
1 parent 4fb81f4 commit 6a2bdbf

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/register/mstatus.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,43 +49,43 @@ impl Mstatus {
4949
/// User Interrupt Enable
5050
#[inline]
5151
pub fn uie(&self) -> bool {
52-
self.bits & (1 << 0) == 1 << 0
52+
self.bits.get_bit(0)
5353
}
5454

5555
/// Supervisor Interrupt Enable
5656
#[inline]
5757
pub fn sie(&self) -> bool {
58-
self.bits & (1 << 1) == 1 << 1
58+
self.bits.get_bit(1)
5959
}
6060

6161
/// Machine Interrupt Enable
6262
#[inline]
6363
pub fn mie(&self) -> bool {
64-
self.bits & (1 << 3) == 1 << 3
64+
self.bits.get_bit(3)
6565
}
6666

6767
/// User Previous Interrupt Enable
6868
#[inline]
6969
pub fn upie(&self) -> bool {
70-
self.bits & (1 << 4) == 1 << 4
70+
self.bits.get_bit(4)
7171
}
7272

7373
/// Supervisor Previous Interrupt Enable
7474
#[inline]
7575
pub fn spie(&self) -> bool {
76-
self.bits & (1 << 5) == 1 << 5
76+
self.bits.get_bit(5)
7777
}
7878

7979
/// User Previous Interrupt Enable
8080
#[inline]
8181
pub fn mpie(&self) -> bool {
82-
self.bits & (1 << 7) == 1 << 7
82+
self.bits.get_bit(7)
8383
}
8484

8585
/// Supervisor Previous Privilege Mode
8686
#[inline]
8787
pub fn spp(&self) -> SPP {
88-
match self.bits & (1 << 8) == (1 << 8) {
88+
match self.bits.get_bit(8) {
8989
true => SPP::Supervisor,
9090
false => SPP::User,
9191
}
@@ -94,7 +94,7 @@ impl Mstatus {
9494
/// Machine Previous Privilege Mode
9595
#[inline]
9696
pub fn mpp(&self) -> MPP {
97-
match (self.bits & (0b11 << 11)) >> 11 {
97+
match self.bits.get_bits(11..13) {
9898
0b00 => MPP::User,
9999
0b01 => MPP::Supervisor,
100100
0b11 => MPP::Machine,
@@ -141,26 +141,33 @@ clear!(0x300, __clear_mstatus);
141141
set_clear_csr!(
142142
/// User Interrupt Enable
143143
, set_uie, clear_uie, 1 << 0);
144+
144145
set_clear_csr!(
145146
/// Supervisor Interrupt Enable
146147
, set_sie, clear_sie, 1 << 1);
148+
147149
set_clear_csr!(
148150
/// Machine Interrupt Enable
149151
, set_mie, clear_mie, 1 << 3);
152+
150153
set_csr!(
151154
/// User Previous Interrupt Enable
152155
, set_upie, 1 << 4);
156+
153157
set_csr!(
154158
/// Supervisor Previous Interrupt Enable
155159
, set_spie, 1 << 5);
160+
156161
set_csr!(
157162
/// Machine Previous Interrupt Enable
158163
, set_mpie, 1 << 7);
164+
159165
/// Supervisor Previous Privilege Mode
160166
#[inline]
161167
pub unsafe fn set_spp(spp: SPP) {
162168
_set((spp as usize) << 8);
163169
}
170+
164171
/// Machine Previous Privilege Mode
165172
#[inline]
166173
pub unsafe fn set_mpp(mpp: MPP) {

0 commit comments

Comments
 (0)