Skip to content

Commit 8de908c

Browse files
committed
Change back to set_ to match cortex and tweak docs a bit
1 parent c05838a commit 8de908c

File tree

1 file changed

+84
-67
lines changed

1 file changed

+84
-67
lines changed

riscv/src/register/mstatus.rs

+84-67
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ impl Mstatus {
9595

9696
/// Update Supervisor Interrupt Enable
9797
///
98-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
99-
/// CSR itself. See [`set_sie`]/[`clear_sie`] to directly update the CSR.
98+
/// Note this updates a previously read [`Mstatus`] value, but does not
99+
/// affect the mstatus CSR itself. See [`set_sie`]/[`clear_sie`] to directly
100+
/// update the CSR.
100101
#[inline]
101-
pub fn update_sie(&self, sie: bool) -> Self {
102+
pub fn set_sie(&self, sie: bool) -> Self {
102103
self.bf_insert(1, 1, sie as usize)
103104
}
104105

@@ -110,10 +111,11 @@ impl Mstatus {
110111

111112
/// Update Machine Interrupt Enable
112113
///
113-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
114-
/// CSR itself. See [`set_mie`]/[`clear_mie`] to directly update the CSR.
114+
/// Note this updates a previously read [`Mstatus`] value, but does not
115+
/// affect the mstatus CSR itself. See [`set_mie`]/[`clear_mie`] to directly
116+
/// update the CSR.
115117
#[inline]
116-
pub fn update_mie(&self, mie: bool) -> Self {
118+
pub fn set_mie(&self, mie: bool) -> Self {
117119
self.bf_insert(3, 1, mie as usize)
118120
}
119121

@@ -123,12 +125,13 @@ impl Mstatus {
123125
self.bits & (1 << 5) != 0
124126
}
125127

126-
/// Updateervisor Previous Interrupt Enable
128+
/// Update Supervisor Previous Interrupt Enable
127129
///
128-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
129-
/// CSR itself. See [`set_spie`]` to directly update the CSR.
130+
/// Note this updates a previously read [`Mstatus`] value, but does not
131+
/// affect the mstatus CSR itself. See [`set_spie`]` to directly update the
132+
/// CSR.
130133
#[inline]
131-
pub fn update_spie(&self, spie: bool) -> Self {
134+
pub fn set_spie(&self, spie: bool) -> Self {
132135
self.bf_insert(5, 1, spie as usize)
133136
}
134137

@@ -140,10 +143,11 @@ impl Mstatus {
140143

141144
/// Update U-mode non-instruction-fetch memory endianness
142145
///
143-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
144-
/// CSR itself. See [`set_ube`] to directly update the CSR.
146+
/// Note this updates a previously read [`Mstatus`] value, but does not
147+
/// affect the mstatus CSR itself. See [`set_ube`] to directly update the
148+
/// CSR.
145149
#[inline]
146-
pub fn update_ube(&self, endianness: Endianness) -> Self {
150+
pub fn set_ube(&self, endianness: Endianness) -> Self {
147151
self.bf_insert(6, 1, endianness as usize)
148152
}
149153

@@ -155,10 +159,11 @@ impl Mstatus {
155159

156160
/// Update Machine Previous Interrupt Enable
157161
///
158-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
159-
/// CSR itself. See [`set_mpie`] to directly update the CSR.
162+
/// Note this updates a previously read [`Mstatus`] value, but does not
163+
/// affect the mstatus CSR itself. See [`set_mpie`] to directly update the
164+
/// CSR.
160165
#[inline]
161-
pub fn update_mpie(&self, mpie: bool) -> Self {
166+
pub fn set_mpie(&self, mpie: bool) -> Self {
162167
self.bf_insert(7, 1, mpie as usize)
163168
}
164169

@@ -173,10 +178,11 @@ impl Mstatus {
173178

174179
/// Update Supervisor Previous Privilege Mode
175180
///
176-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
177-
/// CSR itself. See [`set_spp`] to directly update the CSR.
181+
/// Note this updates a previously read [`Mstatus`] value, but does not
182+
/// affect the mstatus CSR itself. See [`set_spp`] to directly update the
183+
/// CSR.
178184
#[inline]
179-
pub fn update_spp(&self, spp: SPP) -> Self {
185+
pub fn set_spp(&self, spp: SPP) -> Self {
180186
self.bf_insert(8, 1, spp as usize)
181187
}
182188

@@ -194,17 +200,18 @@ impl Mstatus {
194200

195201
/// Update Machine Previous Privilege Mode
196202
///
197-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
198-
/// CSR itself. See [`set_mpp`] to directly update the CSR.
203+
/// Note this updates a previously read [`Mstatus`] value, but does not
204+
/// affect the mstatus CSR itself. See [`set_mpp`] to directly update the
205+
/// CSR.
199206
#[inline]
200-
pub fn update_mpp(&self, mpp: MPP) -> Self {
207+
pub fn set_mpp(&self, mpp: MPP) -> Self {
201208
self.bf_insert(11, 2, mpp as usize)
202209
}
203210

204211
/// Floating-point extension state
205212
///
206-
/// Encodes the status of the floating-point unit,
207-
/// including the CSR `fcsr` and floating-point data registers `f0–f31`.
213+
/// Encodes the status of the floating-point unit, including the CSR `fcsr`
214+
/// and floating-point data registers `f0–f31`.
208215
#[inline]
209216
pub fn fs(&self) -> FS {
210217
let fs = (self.bits >> 13) & 0x3; // bits 13-14
@@ -219,16 +226,18 @@ impl Mstatus {
219226

220227
/// Update Floating-point extension state
221228
///
222-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
223-
/// CSR itself. See [`set_fs`] to directly update the CSR.
229+
/// Note this updates a previously read [`Mstatus`] value, but does not
230+
/// affect the mstatus CSR itself. See [`set_fs`] to directly update the
231+
/// CSR.
224232
#[inline]
225-
pub fn update_fs(&self, fs: FS) -> Self {
233+
pub fn set_fs(&self, fs: FS) -> Self {
226234
self.bf_insert(13, 2, fs as usize)
227235
}
228236

229237
/// Additional extension state
230238
///
231-
/// Encodes the status of additional user-mode extensions and associated state.
239+
/// Encodes the status of additional user-mode extensions and associated
240+
/// state.
232241
#[inline]
233242
pub fn xs(&self) -> XS {
234243
let xs = (self.bits >> 15) & 0x3; // bits 15-16
@@ -243,10 +252,10 @@ impl Mstatus {
243252

244253
/// Update Additional extension state
245254
///
246-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
247-
/// CSR itself.
255+
/// Note this updates a previously read [`Mstatus`] value, but does not
256+
/// affect the mstatus CSR itself.
248257
#[inline]
249-
pub fn update_xs(&self, xs: XS) -> Self {
258+
pub fn set_xs(&self, xs: XS) -> Self {
250259
self.bf_insert(15, 2, xs as usize)
251260
}
252261

@@ -258,10 +267,11 @@ impl Mstatus {
258267

259268
/// Update Modify Memory PRiVilege
260269
///
261-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
262-
/// CSR itself. See [`set_mprv`]/[`clear_mprv`] to directly update the CSR.
270+
/// Note this updates a previously read [`Mstatus`] value, but does not
271+
/// affect the mstatus CSR itself. See [`set_mprv`]/[`clear_mprv`] to
272+
/// directly update the CSR.
263273
#[inline]
264-
pub fn update_mprv(&self, mprv: bool) -> Self {
274+
pub fn set_mprv(&self, mprv: bool) -> Self {
265275
self.bf_insert(17, 1, mprv as usize)
266276
}
267277

@@ -273,10 +283,11 @@ impl Mstatus {
273283

274284
/// Update Permit Supervisor User Memory access
275285
///
276-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
277-
/// CSR itself. See [`set_sum`]/[`clear_sum`] to directly update the CSR.
286+
/// Note this updates a previously read [`Mstatus`] value, but does not
287+
/// affect the mstatus CSR itself. See [`set_sum`]/[`clear_sum`] to directly
288+
/// update the CSR.
278289
#[inline]
279-
pub fn update_sum(&self, sum: bool) -> Self {
290+
pub fn set_sum(&self, sum: bool) -> Self {
280291
self.bf_insert(18, 1, sum as usize)
281292
}
282293

@@ -288,10 +299,11 @@ impl Mstatus {
288299

289300
/// Update Make eXecutable Readable
290301
///
291-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
292-
/// CSR itself. See [`set_mxr`]/[`clear_mxr`] to directly update the CSR.
302+
/// Note this updates a previously read [`Mstatus`] value, but does not affect
303+
/// the mstatus CSR itself. See [`set_mxr`]/[`clear_mxr`] to directly update
304+
/// the CSR.
293305
#[inline]
294-
pub fn update_mxr(&self, mxr: bool) -> Self {
306+
pub fn set_mxr(&self, mxr: bool) -> Self {
295307
self.bf_insert(19, 1, mxr as usize)
296308
}
297309

@@ -308,10 +320,11 @@ impl Mstatus {
308320

309321
/// Update Trap Virtual Memory
310322
///
311-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
312-
/// CSR itself. See [`set_tvm`]/[`clear_tvm`] to directly update the CSR.
323+
/// Note this updates a previously read [`Mstatus`] value, but does not
324+
/// affect the mstatus CSR itself. See [`set_tvm`]/[`clear_tvm`] to directly
325+
/// update the CSR.
313326
#[inline]
314-
pub fn update_tvm(&self, tvm: bool) -> Self {
327+
pub fn set_tvm(&self, tvm: bool) -> Self {
315328
self.bf_insert(20, 1, tvm as usize)
316329
}
317330

@@ -331,10 +344,11 @@ impl Mstatus {
331344

332345
/// Update Timeout Wait
333346
///
334-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
335-
/// CSR itself. See [`set_tw`]/[`clear_tw`] to directly update the CSR.
347+
/// Note this updates a previously read [`Mstatus`] value, but does not
348+
/// affect the mstatus CSR itself. See [`set_tw`]/[`clear_tw`] to directly
349+
/// update the CSR.
336350
#[inline]
337-
pub fn update_tw(&self, tw: bool) -> Self {
351+
pub fn set_tw(&self, tw: bool) -> Self {
338352
self.bf_insert(21, 1, tw as usize)
339353
}
340354

@@ -351,10 +365,11 @@ impl Mstatus {
351365

352366
/// Update Trap SRET
353367
///
354-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
355-
/// CSR itself. See [`set_tsr`]/[`clear_tsr`] to directly update the CSR.
368+
/// Note this updates a previously read [`Mstatus`] value, but does not
369+
/// affect the mstatus CSR itself. See [`set_tsr`]/[`clear_tsr`] to directly
370+
/// update the CSR.
356371
#[inline]
357-
pub fn update_tsr(&self, tsr: bool) -> Self {
372+
pub fn set_tsr(&self, tsr: bool) -> Self {
358373
self.bf_insert(22, 1, tsr as usize)
359374
}
360375

@@ -373,10 +388,10 @@ impl Mstatus {
373388

374389
/// Update Effective xlen in U-mode (i.e., `UXLEN`).
375390
///
376-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
377-
/// CSR itself.
391+
/// Note this updates a previously read [`Mstatus`] value, but does not
392+
/// affect the mstatus CSR itself.
378393
#[inline]
379-
pub fn update_uxl(&self, uxl: XLEN) -> Self {
394+
pub fn set_uxl(&self, uxl: XLEN) -> Self {
380395
#[cfg(riscv32)]
381396
{
382397
*self
@@ -400,10 +415,10 @@ impl Mstatus {
400415

401416
/// Update Effective xlen in S-mode (i.e., `SXLEN`).
402417
///
403-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
404-
/// CSR itself.
418+
/// Note this updates a previously read [`Mstatus`] value, but does not
419+
/// affect the mstatus CSR itself.
405420
#[inline]
406-
pub fn update_sxl(&self, sxl: XLEN) -> Self {
421+
pub fn set_sxl(&self, sxl: XLEN) -> Self {
407422
#[cfg(riscv32)]
408423
{
409424
*self
@@ -426,10 +441,11 @@ impl Mstatus {
426441

427442
/// Update S-mode non-instruction-fetch memory endianness
428443
///
429-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
430-
/// CSR itself. See [`set_sbe`] to directly update the CSR.
444+
/// Note this updates a previously read [`Mstatus`] value, but does not
445+
/// affect the mstatus CSR itself. See [`set_sbe`] to directly update the
446+
/// CSR.
431447
#[inline]
432-
pub fn update_sbe(&self, endianness: Endianness) -> Self {
448+
pub fn set_sbe(&self, endianness: Endianness) -> Self {
433449
#[cfg(riscv32)]
434450
{
435451
*self
@@ -451,10 +467,11 @@ impl Mstatus {
451467
}
452468
/// Update M-mode non-instruction-fetch memory endianness
453469
///
454-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
455-
/// CSR itself. See [`set_mbe`] to directly update the CSR.
470+
/// Note this updates a previously read [`Mstatus`] value, but does not
471+
/// affect the mstatus CSR itself. See [`set_mbe`] to directly update the
472+
/// CSR.
456473
#[inline]
457-
pub fn update_mbe(&self, endianness: Endianness) -> Self {
474+
pub fn set_mbe(&self, endianness: Endianness) -> Self {
458475
#[cfg(riscv32)]
459476
{
460477
*self
@@ -472,10 +489,10 @@ impl Mstatus {
472489
/// Update whether either the FS field or XS field signals the presence of
473490
/// some dirty state
474491
///
475-
/// Note this updates the [`Mstatus`] value, but does not affect the mstatus
476-
/// CSR itself.
492+
/// Note this updates a previously read [`Mstatus`] value, but does not
493+
/// affect the mstatus CSR itself.
477494
#[inline]
478-
pub fn update_sd(&self, sd: bool) -> Self {
495+
pub fn set_sd(&self, sd: bool) -> Self {
479496
self.bf_insert(usize::BITS as usize - 1, 1, sd as usize)
480497
}
481498
}
@@ -601,11 +618,11 @@ mod test {
601618
#[test]
602619
fn test_mpp() {
603620
let mut mstatus = Mstatus { bits: 0 };
604-
mstatus = mstatus.update_mpp(MPP::User);
621+
mstatus = mstatus.set_mpp(MPP::User);
605622
assert_eq!(mstatus.mpp(), MPP::User);
606-
mstatus = mstatus.update_mpp(MPP::Machine);
623+
mstatus = mstatus.set_mpp(MPP::Machine);
607624
assert_eq!(mstatus.mpp(), MPP::Machine);
608-
mstatus = mstatus.update_mpp(MPP::Supervisor);
625+
mstatus = mstatus.set_mpp(MPP::Supervisor);
609626
assert_eq!(mstatus.mpp(), MPP::Supervisor);
610627
}
611628
}

0 commit comments

Comments
 (0)