← Home

mstatus

Machine Status

Address: 0x300 (768) · Privilege: M · Length: MXLEN · Writable · Defined by: Sm

The mstatus register tracks and controls the hart's current operating state.

Fields

RV32

31:2423:1615:87:0
SD—SPELPTSRTWTVMMXRSUMMPRVXSFSMPPVSSPPMPIEUBESPIE—MIE—SIE—

RV64

63:5655:4847:4039:3231:2423:1615:87:0
SD—MDTMPELP—MPVGVAMBESBESXLUXL—SPELPTSRTWTVMMXRSUMMPRVXSFSMPPVSSPPMPIEUBESPIE—MIE—SIE—
BitsFieldAliasDescriptionTypeReset
RV32 [31]
RV64 [63]
SDRead-only bit that summarizes whether either the FS, XS, or VS fields signal the presence of some dirty state.
# this is read-only if FS and VS are both read-only
# otherwise, it is read-only with hardware update

if (implemented?(ExtensionName::F)) {
  return CsrFieldType::ROH;
} else if (implemented?(ExtensionName::V)) {
  return CsrFieldType::ROH;
} else {
  return CsrFieldType::RO;
}
# the reset value is known if both FS and VS are legal
# make this a function call so that it can be displayed succinctly in docs

if (mstatus_sd_has_known_reset()) {
  return mstatus_sd_reset_value();
} else {
  return UNDEFINED_LEGAL;
}
[42]MDTWritten 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.RW-H1
[41]MPELPHolds the previous Expected Landing Pad (`ELP`) state when entering M-mode from a trap, and is restored to `ELP` on `MRET`. Defined by the Zicfilp extension. Encoded as: * 0 - `NO_LP_EXPECTED` - no landing pad instruction expected. * 1 - `LP_EXPECTED` - a landing pad instruction is expected.RW-HUNDEFINED_LEGAL
[39]MPVWritten 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.RW-HUNDEFINED_LEGAL
[38]GVAWhen 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 `stval`, GVA is set to 1. For any other trap into HS-mode, GVA is set to 0.RW-H0
[37]MBEControls 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.
return (M_MODE_ENDIANNESS == "dynamic") ? CsrFieldType::RW : CsrFieldType::RO;
return (M_MODE_ENDIANNESS == "big") ? 1 : 0;
[36]SBEControls 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.
return (S_MODE_ENDIANNESS == "dynamic") ? CsrFieldType::RW : CsrFieldType::RO;
if (S_MODE_ENDIANNESS == "little") {
  return 0;
} else if (S_MODE_ENDIANNESS == "big") {
  return 1;
} else {
  return 0; # little endian
}
[35:34]SXLSets 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 `mstatus.SXL` to be greater than `mstatus.UXL`. It is UNDEFINED_LEGAL to set the MSB of SXL. --
return (implemented?(ExtensionName::S) && $array_size(SXLEN) > 1) ? CsrFieldType::RW : CsrFieldType::RO;
if ($array_size(SXLEN) == 1 && $array_includes?(SXLEN, 32)) {
  return 1;
} else if ($array_size(SXLEN) == 1 && $array_includes?(SXLEN, 64)) {
  return 2;
} else {
  return 2;
}
[33:32]UXLU-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 `mstatus.SXL` to be greater than `mstatus.UXL`. It is UNDEFINED_LEGAL to set the MSB of UXL. --
return ($array_size(UXLEN) > 1) ? CsrFieldType::RW : CsrFieldType::RO;
if ($array_size(UXLEN) == 1 && UXLEN[0] == 32) {
  return 1;
} else if ($array_size(UXLEN) == 1 && UXLEN[0] == 64) {
  return 2;
} else {
  return 2;
}
[23]SPELPHolds the previous Expected Landing Pad (`ELP`) state when entering (H)S-mode from a trap, and is restored to `ELP` on `SRET`. Defined by the Zicfilp extension. Encoded as: * 0 - `NO_LP_EXPECTED` - no landing pad instruction expected. * 1 - `LP_EXPECTED` - a landing pad instruction is expected.RW-HUNDEFINED_LEGAL
[22]TSRWhen 1, attempts to execute the `sret` instruction while executing in HS/S-mode will raise an Illegal Instruction exception. Does not affect the behavior of `sret` in VS_mode (see `hstatus.VTSR`).RWUNDEFINED_LEGAL
[21]TWWhen 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 `wfi` instruction is permitted to wait forever in (H)S-mode but must trap after an implementation-defined wait period in U-mode.RWUNDEFINED_LEGAL
[20]TVMWhen 1, an `Illegal Instruction` trap occurs when * writing the `satp` CSR, executing an `sfence.vma`, or executing an `sinval.vma` while in (H)S-mode (but not VS-mode) * writing the `hgtap` CSR, executing an `hfence.gvma`, or executing an `hinval.gvma` while in HS-mode Notably, `mstatus.TVM` does *not* cause *`hfence.vvma`, `sfence.w.inval`, or `sfence.inval.ir` to trap. * Any additional traps in VS-mode (controlled via `hstatus.VTVM` instead).
if (CSR[misa].S == 1'b0) {
  return CsrFieldType::RO;
} else if (!(implemented?(ExtensionName::Sv32) || implemented?(ExtensionName::Sv39) || implemented?(ExtensionName::Sv48) || implemented?(ExtensionName::Sv57))) {
  return CsrFieldType::RO;
} else {
  return CsrFieldType::RW;
}
if (CSR[misa].S == 1'b0) {
  return 0;
} else if (!(implemented?(ExtensionName::Sv32) || implemented?(ExtensionName::Sv39) || implemented?(ExtensionName::Sv48) || implemented?(ExtensionName::Sv57))) {
  return 0;
} else {
  return UNDEFINED_LEGAL;
}
[19]MXRWhen 1, loads from pages marked readable *or executable* are allowed. When 0, loads from pages marked executable raise a Page Fault exception.RWUNDEFINED_LEGAL
[18]SUMWhen 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.
# only writable if there is some translation supported
if (has_virt_mem?()) {
  return CsrFieldType::RW;
} else {
  return CsrFieldType::RO;
}
if (has_virt_mem?()) {
  return UNDEFINED_LEGAL;
} else {
  # read-only zero when there is no virtual memory
  return 0;
}
[17]MPRVWhen 1, loads and stores behave as if the current virtualization mode:privilege level was `mstatus.MPV`:`mstatus.MPP`. `mstatus.MPRV` is cleared on any exception return (`mret` or `sret` instruction, regardless of the trap handler privilege mode).
return (CSR[misa].U == 1'b1) ? CsrFieldType::RWH : CsrFieldType::RO;
0
[16:15]XSSummarizes 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.RO0
[14:13]FSWhen 0, floating point instructions (from F and D extensions) are disabled, and cause `ILLEGAL INSTRUCTION` exceptions. When a floating point register, or the fCSR register is written, FS 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 floating point unit.
if (implemented?(ExtensionName::F) && (!MISA_CSR_IMPLEMENTED || CSR[misa].F == 1'b1)) {
  # "If the F extension is implemented, the FS field shall not be read-only zero."
  return CsrFieldType::RWH;
} else if (MISA_CSR_IMPLEMENTED && (CSR[misa].S == 1'b0) && (CSR[misa].F == 1'b0)) {
  # "If neither the F extension nor S-mode is implemented, then FS is read-only zero"
  return CsrFieldType::RO;
} else {
  # " If S-mode is implemented but the F extension is not, FS may optionally be read-only zero."
  # there will be no hardware update in this case because we know the F extension isn't implemented
  return $array_size(MSTATUS_FS_LEGAL_VALUES) == 1 ? CsrFieldType::RO : CsrFieldType::RW;
}
if (MISA_CSR_IMPLEMENTED && (CSR[misa].S == 1'b0) && (CSR[misa].F == 1'b0)) {
  # must be read-only-0
  return 0;
}
return $array_size(MSTATUS_FS_LEGAL_VALUES) == 1 ? MSTATUS_FS_LEGAL_VALUES[0] : UNDEFINED_LEGAL;
[12:11]MPPWritten by hardware in two cases: * Written with the prior nominal privilege level when entering M-mode from an exception/interrupt. * Written with 0 when executing an `mret` instruction to return from an exception in M-mode. Can also be written by software without immediate side-effect. Affects execution in two cases: * On a return from an exception from M-mode, the machine will enter the privilege level stored in MPP before clearing the field. * When `mstatus.MPRV` is set, loads and stores behave as if the current privilege level were MPP.RW-H
return 2'b11;
[10:9]VSWhen 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.
if (implemented?(ExtensionName::V) && (!MISA_CSR_IMPLEMENTED || CSR[misa].V == 1'b1)) {
  # "If the V extension is implemented, the VS field shall not be read-only zero."
  return CsrFieldType::RWH;
} else if (MISA_CSR_IMPLEMENTED && (CSR[misa].S == 1'b0) && (CSR[misa].V == 1'b0)) {
  # "If neither the V extension nor S-mode is implemented, then VS is read-only zero"
  return CsrFieldType::RO;
} else {
  # " If S-mode is implemented but the V extension is not, VS may optionally be read-only zero."
  # there will be no hardware update in this case because we know the V extension isn't implemented
  return $array_size(MSTATUS_VS_LEGAL_VALUES) == 1 ? CsrFieldType::RO : CsrFieldType::RW;
}
if ((!implemented?(ExtensionName::S) && !implemented?(ExtensionName::V)) || (MISA_CSR_IMPLEMENTED && (CSR[misa].S == 1'b0) && (CSR[misa].V == 1'b0))) {
  # must be read-only-0
  return 0;
}
return $array_size(MSTATUS_VS_LEGAL_VALUES) == 1 ? MSTATUS_VS_LEGAL_VALUES[0] : UNDEFINED_LEGAL;
[8]SPPWritten by hardware in two cases: * Written with the prior nominal privilege level when entering (H)S-mode from an exception/interrupt. * Written with 0 when executing an `sret` instruction to return from an exception in (H)S-mode or (unlikely) M-mode. Can also be written by software without immediate side-effect. Affects execution in one case: * On a return from an exception using the `sret` instruction in (H)S-mode or (unlikely) M-mode, the machine will enter the privilege level stored in SPP before clearing the field. Notably, `mstatus.SPP` does not affect exception return in VS-mode (see `vsstatus.SPP`).RW-HUNDEFINED_LEGAL
[7]MPIEWritten by hardware in two cases: * Written with prior value of `mstatus.MIE` when entering M-mode from an exception/interrupt. * Written with the value 1 when returning from an exception in M-mode (via the `mret` instruction). Can also be written by software without immediate side effect. Other than serving as a record of nested traps as described above, `mstatus.MPIE` does not affect execution.RW-HUNDEFINED_LEGAL
[6]UBEControls 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.
return (U_MODE_ENDIANNESS == "dynamic") ? CsrFieldType::RW : CsrFieldType::RO;
if (U_MODE_ENDIANNESS == "little") {
  return 0;
} else if (U_MODE_ENDIANNESS == "big") {
  return 1;
} else {
  return UNDEFINED_LEGAL;
}
[5]SPIEWritten by hardware in two cases: * Written with prior value of `mstatus.SIE` when entering (H)S-mode from an exception/interrupt. * Written with the value 1 when returning from an exception via the `sret` instruction in (H)S-mode or (unlikely) M-mode. Can also be written by software without immediate side effect. Other than serving as a record of nested traps as described above, `mstatus.SPIE` does not affect execution.
return (CSR[misa].S == 1'b1) ? CsrFieldType::RWH : CsrFieldType::RO;
if (CSR[misa].S == 1'b1) {
  return UNDEFINED_LEGAL;
}
return 0;
[3]MIEWritten by hardware in two cases: * Written with the value 0 when entering M-mode from an exception/interrupt. * Written with the prior value of `mstatus.MPIE` when returning from an exception in M-mode (via `mret`). Affects execution by: * When 0, all interrupts are disabled when the current privilege level is M. * When 1, interrupts that are not otherwise disabled with a field in `mie` are enabled.RW-H0
[1]SIEWritten by hardware in two cases: * Written with the value 0 when entering (H)S-mode from an exception/interrupt. * Written with the prior value of `mstatus.SPIE` when returning from an exception via `sret` in (H)S-mode or (unlikely) M-mode. Affects execution by: * When 0, all (H)S-mode interrupts are disabled when the current privilege level is (H)S (M-mode interrupts are still enabled). * When 1, (H)S-mode interrupts that are not otherwise disabled with a field in `sie` are enabled.
return (CSR[misa].S == 1'b1) ? CsrFieldType::RWH : CsrFieldType::RO;
if (CSR[misa].S == 1'b1) {
  return UNDEFINED_LEGAL;
}
return 0;

Version af3eaf9+cheriot.f635218

Data from the RISC-V Unified Database, copyright RISC-V International and contributors.

CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.

This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.