mstatus
Machine status register
- Address
0x300- Group
- Machine-level CSRs
- Privilege
MRW(privileged spec CSR listing, Machine Trap Setup)- Access
- read/write; lowest privilege M (machine)
- Address range
- Standard read/write
- Name in riscv-unified-db
- Machine Status
Privileged spec: Machine status register
Description
The mstatus register tracks and controls the hart's current operating state.
From riscv-unified-db, reformatted.
Fields
| Field | Bits | Type | Description |
|---|---|---|---|
SD | RV32 31 / RV64 63 | State Dirty. Read-only bit that summarizes whether either the FS, XS, or VS fields signal the presence of some dirty state. | |
MDT | 42 | RW-H | Machine Disable Trap. Written to 1 when entering M-mode from an exception/interrupt. When returning via an MRET instruction, the bit is written to 0. On reset in set to 1, and software should write it to 0 when boot sequence is done. When mstatus.MDT=1, direct write by CSR instruction cannot set mstatus.MIE to 1, if not written together. |
MPELP | 41 | RW-H | M-mode Previous Expected Landing Pad state. Holds the previous Expected Landing Pad ( Defined by the Zicfilp extension. Encoded as:
|
MPV | 39 | RW-H | Machine Previous Virtualization mode. Written with the prior virtualization mode when entering M-mode from an exception/interrupt. When returning via an MRET instruction, the virtualization mode becomes the value of MPV unless MPP=3, in which case the virtualization mode is always 0. Can also be written by software. |
GVA | 38 | RW-H | Guest Virtual Address. When a trap is taken and a guest virtual address is written into mtval, GVA is set.
GVA is written by the implementation whenever a trap is taken into
HS mode. For any trap (breakpoint, address misaligned, access fault,
page fault, or guest-page fault) that writes a guest virtual address to
|
MBE | 37 | M-mode Big Endian. Controls the endianness of data M-mode (0 = little, 1 = big). Instructions are always little endian, regardless of the data setting. Since the CPU does not support big endian, this is hardwired to 0. Since the CPU does not support little endian, this is hardwired to 1. | |
SBE | 36 | S-mode Big Endian. Controls the endianness of S-mode (0 = little, 1 = big). Instructions are always little endian, regardless of the data setting. Since the CPU does not support big endian, this is hardwired to 0. Since the CPU does not support little endian, this is hardwired to 1. | |
SXL | 35-34 | S-mode XLEN. Sets the effective XLEN for S-mode (0 = 32-bit, 1 = 64-bit, 2 = 128-bit [reserved]). Since the CPU only supports SXLEN==32, this is hardwired to 1. Since the CPU only supports SXLEN==64, this is hardwired to 2. It is not valid to have SXLEN less than UXLEN. It is UNDEFINED_LEGAL what will happen if a software sets It is UNDEFINED_LEGAL to set the MSB of SXL. | |
UXL | 33-32 | U-mode XLEN. U-mode XLEN. Sets the effective XLEN for U-mode (1 = 32-bit, 2 = 64-bit, 3 = 128-bit [reserved]). Since the CPU only supports UXLEN==32, this is hardwired to 1. Since the CPU only supports UXLEN==64, this is hardwired to 2. It is not valid to have SXLEN less than UXLEN. It is UNDEFINED_LEGAL what will happen if a software sets It is UNDEFINED_LEGAL to set the MSB of UXL. | |
SPELP | 23 | RW-H | S-mode Previous Expected Landing Pad state. Holds the previous Expected Landing Pad ( Defined by the Zicfilp extension. Encoded as:
|
TSR | 22 | RW | Trap SRET. When 1, attempts to execute the Does not affect the behavior of |
TW | 21 | RW | Timeout Wait. When 1, the WFI instruction will raise an Illegal Instruction trap after an implementaion-defined wait period when executed in a mode other than M-mode. When 0, the |
TVM | 20 | Trap Virtual Memory. When 1, an
Notably, *
| |
MXR | 19 | RW | Make eXecutable Readable. When 1, loads from pages marked readable or executable are allowed. When 0, loads from pages marked executable raise a Page Fault exception. |
SUM | 18 | permit Supervisor Memory Access. When 0, an S-mode read or an M-mode read with mstatus.MPRV=1 and mstatus.MPP=01 to a 'U' (user) page will cause an ILLEGAL INSTRUCTION exception. | |
MPRV | 17 | Modify PRiVilege. When 1, loads and stores behave as if the current virtualization mode:privilege level was
| |
XS | 16-15 | RO | custom (X) extension context Status. Summarizes the current state of any custom extension state. Either 0 - Off, 1 - Initial, 2 - Clean, 3 - Dirty. Since there are no custom extensions in the base spec, this field is read-only 0. |
FS | 14-13 | Floating point context Status. When 0, floating point instructions (from F and D extensions) are disabled,
and cause | |
MPP | 12-11 | RW-H | M-mode Previous Privilege. Written by hardware in two cases:
Can also be written by software without immediate side-effect. Affects execution in two cases:
|
VS | 10-9 | Vector context Status. When 0, vector instructions (from the V extension) are disabled, and cause ILLEGAL INSTRUCTION exceptions. When a vector register or vector CSR is written, VS obtains the value 3. Values 1 and 2 are valid write values for software, but are not interpreted by hardware other than to possibly enable a previously-disabled vector unit. | |
SPP | 8 | RW-H | S-mode Previous Privilege. Written by hardware in two cases:
Can also be written by software without immediate side-effect. Affects execution in one case:
Notably, |
MPIE | 7 | RW-H | M-mode Previous Interrupt Enable. Written by hardware in two cases:
Can also be written by software without immediate side effect. Other than serving as a record of nested traps as described above, |
UBE | 6 | U-mode Big Endian. Controls the endianness of U-mode (0 = little, 1 = big). Instructions are always little endian, regardless of the data setting. Since the CPU does not support big endian in U-mode, this is hardwired to 0. Since the CPU does not support little endian in U-mode, this is hardwired to 1. | |
SPIE | 5 | S-mode Previous Interrupt Enable. Written by hardware in two cases:
Can also be written by software without immediate side effect. Other than serving as a record of nested traps as described above, | |
MIE | 3 | RW-H | M-mode Interrupt Enable. Written by hardware in two cases:
Affects execution by:
|
SIE | 1 | S-mode Interrupt Enable. Written by hardware in two cases:
Affects execution by:
|
Fields from riscv-unified-db; field types computed by IDL functions there are not shown.
Specification and related pages
- The RISC-V Instruction Set Manual, Volume II: CSR listing (src/priv/csrs.adoc)
- riscv-opcodes csrs.csv
- riscv-unified-db: spec/std/isa/csr/mstatus.yaml
- csrrw, csrrs, csrrc (Zicsr instructions that access CSRs)