Skip to content

Commit 5ef90e3

Browse files
committed
Fix set_spp and set_mpp functions
1 parent 6a2bdbf commit 5ef90e3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/register/mstatus.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,18 @@ set_csr!(
165165
/// Supervisor Previous Privilege Mode
166166
#[inline]
167167
pub unsafe fn set_spp(spp: SPP) {
168-
_set((spp as usize) << 8);
168+
match spp {
169+
SPP::Supervisor => _set(1 << 8),
170+
SPP::User => _clear(1 << 8),
171+
}
169172
}
170173

171174
/// Machine Previous Privilege Mode
172175
#[inline]
173176
pub unsafe fn set_mpp(mpp: MPP) {
174-
_set((mpp as usize) << 11);
177+
let mut value = _read();
178+
value.set_bits(11..13, mpp as usize);
179+
_write(value);
175180
}
176181

177182
/// Floating-point extension state

src/register/sstatus.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,17 @@ set_clear_csr!(
131131
#[inline]
132132
#[cfg(riscv)]
133133
pub unsafe fn set_spp(spp: SPP) {
134-
_set((spp as usize) << 8);
134+
match spp {
135+
SPP::Supervisor => _set(1 << 8),
136+
SPP::User => _clear(1 << 8),
137+
}
135138
}
136139

137140
/// The status of the floating-point unit
138141
#[inline]
139142
#[cfg(riscv)]
140143
pub unsafe fn set_fs(fs: FS) {
141-
_set((fs as usize) << 13);
144+
let mut value = _read();
145+
value.set_bits(13..15, fs as usize);
146+
_write(value);
142147
}

0 commit comments

Comments
 (0)