Skip to content

Commit 80cd885

Browse files
committed
doc(port_riscv): enhance the documentation regarding non-M-mode
1 parent 53a23ce commit 80cd885

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/r3_port_riscv/src/lib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,4 @@ The trap handler stores a first-level state directly below the current stack poi
197197

198198
## Processor Modes
199199

200-
All code executes in Machine mode. The value of `mstatus.MPP` is always `M` (`0b11`).
200+
All code executes in Machine mode by default. The value of `mstatus.MPP` is always `M` (`0b11`). Other modes can be selected by [`ThreadingOptions::PRIVILEGE_LEVEL`], which changes all CSRs and CSR values accordingly.

src/r3_port_riscv/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub trait EntryPoint {
9797
///
9898
/// - The processor should be in the privilege mode specified by
9999
/// [`ThreadingOptions::PRIVILEGE_LEVEL`] and have interrupts masked for
100-
// this privilege level.
100+
/// this privilege level.
101101
/// - This method hasn't been entered yet.
102102
///
103103
unsafe fn start() -> !;
@@ -110,7 +110,7 @@ pub trait EntryPoint {
110110
///
111111
/// - The processor should be in the privilege mode specified by
112112
/// [`ThreadingOptions::PRIVILEGE_LEVEL`] and have interrupts masked for
113-
// this privilege level
113+
/// this privilege level
114114
/// - The register state of the background context should be preserved so
115115
/// that the handler can restore it later.
116116
///

src/r3_port_riscv/src/threading/cfg.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ pub trait ThreadingOptions {
1818
/// The RISC-V privilege level wherein the kernel and apllication operate.
1919
/// The default value is [`PRIVILEGE_LEVEL_MACHINE`]. Must be in the range
2020
/// `0..4`.
21+
///
22+
/// There are a few points that should be kept in mind when specifying this
23+
/// option:
24+
///
25+
/// - It's [`EntryPoint`][]'s caller that is responsible for ensuring the
26+
/// specified privilege level is entered. Calling the entry points from
27+
/// other privilege levels will cause an undefined behavior.
28+
///
29+
/// - The current version of `riscv-rt` can only start in M-mode.
30+
/// Consequently, [`use_rt!`][] is incompatible with other modes.
31+
///
32+
/// - The current version of [`riscv`][] provides wrapper functions which
33+
/// are hard-coded to use M-mode-only CSRs, such as `mstatus.MIE`.
34+
/// They don't work in lower privilege levels. You must use [CPU Lock][]
35+
/// or the correct CSR (e.g., [`riscv::register::sstatus`]) the
36+
/// specified privilege level directly.
37+
///
38+
/// [`EntryPoint`]: crate::EntryPoint
39+
/// [CPU Lock]: r3_core#system-states
2140
const PRIVILEGE_LEVEL: u8 = PRIVILEGE_LEVEL_MACHINE;
2241
}
2342

0 commit comments

Comments
 (0)