CSR Bit Fields

RISC-V mstatus CSR Register

Address 0x300Privilege MachineAccess RW / MXLENMachine status, trap, and interrupt CSRs

Machine-mode status register containing global interrupt enables, privilege-level stack, and extension state control fields.

The mstatus (Machine Status) CSR at address 0x300 is the central global state register in RISC-V machine mode. It controls the global interrupt enable (MIE, bit 3), saves pre-trap interrupt state (MPIE, bit 7), records the previous privilege level for trap return (MPP, bits 12:11), and manages floating-point, vector, and extension context state through FS/VS/XS. The SD bit at XLEN-1 summarizes whether any FS, VS, or XS state is dirty. mstatus is essential for trap handling, privilege switching, and context-switch optimization.

Field Map

Understand mstatus By Bit Fields

33 key fields
63

SD

RO

State-dirty summary bit; set when FS, VS, or XS is Dirty. In RV32 this appears at bit 31.

SD (bit 63) — State-dirty summary bit; set when FS, VS, or XS is Dirty. In RV32 this appears at bit 31.

What This Field Controls

  • - State-dirty summary bit; set when FS, VS, or XS is Dirty. In RV32 this appears at bit 31.

Common Values

00

No FS, VS, or XS field is Dirty.

11

At least one of FS, VS, or XS is Dirty.

62:43

WPRI

WPRI

Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

WPRI (bits 62:43) — Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

What This Field Controls

  • - Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

Common Values

This field is better understood together with surrounding context than as a fixed memorized enumeration.

42

MDT

WARL-H

M-mode-disable-trap bit (Smdbltrp); controls unexpected/double-trap behavior during sensitive M-mode trap phases. Explicitly writing it to 1 clears MIE; MRET/SRET executed in M-mode clears it.

MDT (bit 42) — M-mode-disable-trap bit (Smdbltrp); controls unexpected/double-trap behavior during sensitive M-mode trap phases. Explicitly writing it to 1 clears MIE; MRET/SRET executed in M-mode clears it.

What This Field Controls

  • - M-mode-disable-trap bit (Smdbltrp); controls unexpected/double-trap behavior during sensitive M-mode trap phases. Explicitly writing it to 1 clears MIE; MRET/SRET executed in M-mode clears it.

Common Values

00

Machine double-trap guard is not set.

11

Machine double-trap guard is set; later M-mode traps follow Smdbltrp rules.

41

MPELP

RW-H (Zicfilp)

Machine Previous Expected Landing Pad state defined by Zicfilp. A trap into M-mode saves the previous ELP here; MRET restores ELP according to the target privilege mode's LPE and then clears this field to NO_LP_EXPECTED.

MPELP (bit 41) — Machine Previous Expected Landing Pad state defined by Zicfilp. A trap into M-mode saves the previous ELP here; MRET restores ELP according to the target privilege mode's LPE and then clears this field to NO_LP_EXPECTED.

What This Field Controls

  • - Machine Previous Expected Landing Pad state defined by Zicfilp. A trap into M-mode saves the previous ELP here; MRET restores ELP according to the target privilege mode's LPE and then clears this field to NO_LP_EXPECTED.

Common Values

00

No landing-pad instruction is expected.

11

A landing-pad instruction is expected.

40

WPRI

WPRI

Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

WPRI (bit 40) — Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

What This Field Controls

  • - Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

Common Values

This field is better understood together with surrounding context than as a fixed memorized enumeration.

39

MPV

RW-H

Machine Previous Virtualization mode defined by the Hypervisor extension; records V before a trap into M-mode. This field does not exist without the Hypervisor extension.

MPV (bit 39) — Machine Previous Virtualization mode defined by the Hypervisor extension; records V before a trap into M-mode. This field does not exist without the Hypervisor extension.

What This Field Controls

  • - Machine Previous Virtualization mode defined by the Hypervisor extension; records V before a trap into M-mode. This field does not exist without the Hypervisor extension.

Common Values

00

Execution before the M-mode trap was not virtualized.

11

Execution before the M-mode trap was virtualized.

38

GVA

RW-H

Guest Virtual Address flag defined by the Hypervisor extension; indicates whether the address written to mtval is a guest virtual address. This field does not exist without the Hypervisor extension.

GVA (bit 38) — Guest Virtual Address flag defined by the Hypervisor extension; indicates whether the address written to mtval is a guest virtual address. This field does not exist without the Hypervisor extension.

What This Field Controls

  • - Guest Virtual Address flag defined by the Hypervisor extension; indicates whether the address written to mtval is a guest virtual address. This field does not exist without the Hypervisor extension.

Common Values

00

The address in mtval is not a guest virtual address.

11

The address in mtval is a guest virtual address.

37

MBE

WARL

Machine Big-Endian control. When MPRV=0, it controls non-instruction-fetch memory accesses made from M-mode; instruction fetches are always little-endian. SBE and UBE may be read-only copies of MBE.

MBE (bit 37) — Machine Big-Endian control. When MPRV=0, it controls non-instruction-fetch memory accesses made from M-mode; instruction fetches are always little-endian. SBE and UBE may be read-only copies of MBE.

What This Field Controls

  • - Machine Big-Endian control. When MPRV=0, it controls non-instruction-fetch memory accesses made from M-mode; instruction fetches are always little-endian. SBE and UBE may be read-only copies of MBE.

Common Values

0Little-endian

When MPRV=0, non-instruction-fetch M-mode memory accesses are little-endian; instruction fetch is always little-endian.

1Big-endian

When MPRV=0, non-instruction-fetch M-mode memory accesses are big-endian; instruction fetch remains little-endian.

36

SBE

WARL/RO0/RO-copy

S-mode data endianness control; 0 is little-endian and 1 is big-endian, while instruction fetch remains little-endian.

SBE (bit 36) — S-mode data endianness control; 0 is little-endian and 1 is big-endian, while instruction fetch remains little-endian.

What This Field Controls

  • - S-mode data endianness control; 0 is little-endian and 1 is big-endian, while instruction fetch remains little-endian.

Common Values

0Little-endian

S-mode explicit memory accesses are little-endian; instruction fetch is not affected by this bit.

1Big-endian

S-mode explicit memory accesses are big-endian; instruction fetch is not affected by this bit.

35:34

SXL

WARL/RO0

Effective XLEN encoding for S-mode on RV64; read-only zero if S-mode is not implemented.

SXL (bits 35:34) — Effective XLEN encoding for S-mode on RV64; read-only zero if S-mode is not implemented.

What This Field Controls

  • - Effective XLEN encoding for S-mode on RV64; read-only zero if S-mode is not implemented.

Common Values

132-bit

Effective XLEN is 32.

264-bit

Effective XLEN is 64.

3Reserved

Reserved encoding; portable software must not write or depend on it.

33:32

UXL

WARL/RO0

Effective XLEN encoding for U-mode on RV64; read-only zero if U-mode is not implemented.

UXL (bits 33:32) — Effective XLEN encoding for U-mode on RV64; read-only zero if U-mode is not implemented.

What This Field Controls

  • - Effective XLEN encoding for U-mode on RV64; read-only zero if U-mode is not implemented.

Common Values

132-bit

Effective XLEN is 32.

264-bit

Effective XLEN is 64.

3Reserved

Reserved encoding; portable software must not write or depend on it.

31:25

WPRI

WPRI

Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

WPRI (bits 31:25) — Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

What This Field Controls

  • - Reserved WPRI bits; software should preserve their values on writes and ignore their values on reads.

Common Values

This field is better understood together with surrounding context than as a fixed memorized enumeration.

24

SDT

WARL-H/RO0

S-mode-disable-trap bit defined by Ssdbltrp. Explicitly writing 1 clears SIE; a trap into S-mode sets it when it was 0, while a trap with it already set follows the double-trap rules; SRET clears it. It is read-only zero when Ssdbltrp is not implemented.

SDT (bit 24) — S-mode-disable-trap bit defined by Ssdbltrp. Explicitly writing 1 clears SIE; a trap into S-mode sets it when it was 0, while a trap with it already set follows the double-trap rules; SRET clears it. It is read-only zero when Ssdbltrp is not implemented.

What This Field Controls

  • - S-mode-disable-trap bit defined by Ssdbltrp. Explicitly writing 1 clears SIE; a trap into S-mode sets it when it was 0, while a trap with it already set follows the double-trap rules; SRET clears it. It is read-only zero when Ssdbltrp is not implemented.

Common Values

00

The S-mode double-trap guard is clear.

11

The S-mode double-trap guard is set.

23

SPELP

RW-H (Zicfilp)

S-mode Previous Expected Landing Pad state defined by Zicfilp. A trap into S/HS-mode saves the previous ELP here; SRET restores ELP according to the target privilege mode's LPE and then clears this field to NO_LP_EXPECTED.

SPELP (bit 23) — S-mode Previous Expected Landing Pad state defined by Zicfilp. A trap into S/HS-mode saves the previous ELP here; SRET restores ELP according to the target privilege mode's LPE and then clears this field to NO_LP_EXPECTED.

What This Field Controls

  • - S-mode Previous Expected Landing Pad state defined by Zicfilp. A trap into S/HS-mode saves the previous ELP here; SRET restores ELP according to the target privilege mode's LPE and then clears this field to NO_LP_EXPECTED.

Common Values

00

No landing-pad instruction is expected.

11

A landing-pad instruction is expected.

22

TSR

WARL/RO0

When set, SRET executed in S-mode traps to M-mode.

TSR (bit 22) — When set, SRET executed in S-mode traps to M-mode.

What This Field Controls

  • - When set, SRET executed in S-mode traps to M-mode.

Common Values

00

S-mode SRET does not trap because of TSR.

11

S-mode SRET raises an illegal-instruction exception.

21

TW

WARL/RO0

When set, lower-privilege WFI raises an illegal-instruction exception if it does not complete within an implementation-specific bounded time; an implementation may raise the exception immediately.

TW (bit 21) — When set, lower-privilege WFI raises an illegal-instruction exception if it does not complete within an implementation-specific bounded time; an implementation may raise the exception immediately.

What This Field Controls

  • - When set, lower-privilege WFI raises an illegal-instruction exception if it does not complete within an implementation-specific bounded time; an implementation may raise the exception immediately.

Common Values

00

Lower-privilege WFI is not forced to trap because of TW.

11

Lower-privilege WFI raises an illegal-instruction exception if it does not complete within the implementation-specific bounded time.

20

TVM

WARL/RO0

When set, S-mode accesses to satp or execution of SFENCE.VMA/SINVAL.VMA raise an illegal-instruction exception; read-only zero when S-mode is not implemented.

TVM (bit 20) — When set, S-mode accesses to satp or execution of SFENCE.VMA/SINVAL.VMA raise an illegal-instruction exception; read-only zero when S-mode is not implemented.

What This Field Controls

  • - When set, S-mode accesses to satp or execution of SFENCE.VMA/SINVAL.VMA raise an illegal-instruction exception; read-only zero when S-mode is not implemented.

Common Values

00

S-mode may access satp and execute address-translation fences under the usual rules.

11

S-mode accesses to satp or SFENCE.VMA/SINVAL.VMA trap.

19

MXR

RW/RO0

Allows loads from executable pages.

MXR (bit 19) — Allows loads from executable pages.

What This Field Controls

  • - Allows loads from executable pages.

Common Values

00

Loads do not read a page merely because it is executable.

11

Loads may read from executable pages.

18

SUM

RW/RO0

Allows S-mode to access U-mode pages.

SUM (bit 18) — Allows S-mode to access U-mode pages.

What This Field Controls

  • - Allows S-mode to access U-mode pages.

Common Values

00

S-mode cannot access pages with U=1 unless another architectural rule permits it.

11

S-mode may access pages with U=1, while instruction fetch remains constrained by the specification.

17

MPRV

RW/RO0

Data memory accesses use the effective privilege specified by MPP.

MPRV (bit 17) — Data memory accesses use the effective privilege specified by MPP.

What This Field Controls

  • - Data memory accesses use the effective privilege specified by MPP.

Common Values

00

Data memory accesses use the current privilege mode.

11

Data memory accesses use the effective privilege mode specified by MPP.

16:15

XS

RO/derived

Additional user-extension state status.

XS (bits 16:15) — Additional user-extension state status.

What This Field Controls

  • - Additional user-extension state status.

Common Values

0Off

The extension state is off; using the associated extension state traps or is unavailable.

1Initial

The extension state is in its initial state.

2Clean

The extension state matches the saved context in memory.

3Dirty

The extension state may have been modified and typically must be saved on context switch.

14:13

FS

WARL

Floating-point state status.

FS (bits 14:13) — Floating-point state status.

What This Field Controls

  • - Floating-point state status.

Common Values

0Off

The extension state is off; using the associated extension state traps or is unavailable.

1Initial

The extension state is in its initial state.

2Clean

The extension state matches the saved context in memory.

3Dirty

The extension state may have been modified and typically must be saved on context switch.

12:11

MPP

WARL

Privilege mode before entering the M-mode trap.

MPP (bits 12:11) — Privilege mode before entering the M-mode trap.

What This Field Controls

  • - Privilege mode before entering the M-mode trap.

Common Values

0U

Previous privilege mode before the M-mode trap was User.

1S

Previous privilege mode before the M-mode trap was Supervisor.

2Reserved

This encoding is reserved; portable software must not write or depend on it.

3M

Previous privilege mode before the M-mode trap was Machine.

10:9

VS

WARL/RO0

Vector state status; controls availability of vector instructions/vector CSRs and tracks dirty state.

VS (bits 10:9) — Vector state status; controls availability of vector instructions/vector CSRs and tracks dirty state.

What This Field Controls

  • - Vector state status; controls availability of vector instructions/vector CSRs and tracks dirty state.

Common Values

0Off

The extension state is off; using the associated extension state traps or is unavailable.

1Initial

The extension state is in its initial state.

2Clean

The extension state matches the saved context in memory.

3Dirty

The extension state may have been modified and typically must be saved on context switch.

8

SPP

WARL/RO0

Privilege mode before entering the S-mode trap.

SPP (bit 8) — Privilege mode before entering the S-mode trap.

What This Field Controls

  • - Privilege mode before entering the S-mode trap.

Common Values

0U

Previous privilege mode before the S-mode trap was User.

1S

Previous privilege mode before the S-mode trap was Supervisor.

7

MPIE

RW

Saved MIE value before entering an M-mode trap.

MPIE (bit 7) — Saved MIE value before entering an M-mode trap.

What This Field Controls

  • - Saved MIE value before entering an M-mode trap.

Common Values

00

MIE was 0 before the M-mode trap, or the saved post-return interrupt state is disabled.

11

MIE was 1 before the M-mode trap and MRET can restore it under the rules.

6

UBE

WARL/RO0/RO-copy

U-mode explicit load/store endianness control; 0=little-endian, 1=big-endian. It is read-only zero if U-mode is not implemented and may be a read-only copy of MBE or SBE.

UBE (bit 6) — U-mode explicit load/store endianness control; 0=little-endian, 1=big-endian. It is read-only zero if U-mode is not implemented and may be a read-only copy of MBE or SBE.

What This Field Controls

  • - U-mode explicit load/store endianness control; 0=little-endian, 1=big-endian. It is read-only zero if U-mode is not implemented and may be a read-only copy of MBE or SBE.

Common Values

0Little-endian

U-mode explicit memory accesses are little-endian; instruction fetch is not affected by this bit.

1Big-endian

U-mode explicit memory accesses are big-endian; instruction fetch is not affected by this bit.

5

SPIE

RW/RO0

Saved SIE value before entering an S-mode trap; read-only zero if S-mode is not implemented.

SPIE (bit 5) — Saved SIE value before entering an S-mode trap; read-only zero if S-mode is not implemented.

What This Field Controls

  • - Saved SIE value before entering an S-mode trap; read-only zero if S-mode is not implemented.

Common Values

00

SIE was 0 before the S-mode trap, or the saved post-return interrupt state is disabled.

11

SIE was 1 before the S-mode trap and SRET can restore it under the rules.

4

WPRI

WPRI

Reserved WPRI (Writes Preserve, Reads Ignore).

WPRI (bit 4) — Reserved WPRI (Writes Preserve, Reads Ignore).

What This Field Controls

  • - Reserved WPRI (Writes Preserve, Reads Ignore).

Common Values

This field is better understood together with surrounding context than as a fixed memorized enumeration.

3

MIE

RW

Global interrupt enable for M-mode.

MIE (bit 3) — Global interrupt enable for M-mode.

What This Field Controls

  • - Global interrupt enable for M-mode.

Common Values

0Disabled

When currently running in M-mode, global machine interrupts are disabled.

1Enabled

When currently running in M-mode, global machine interrupts are enabled; delivery also depends on mie/mip and delegation state.

2

WPRI

WPRI

Reserved WPRI.

WPRI (bit 2) — Reserved WPRI.

What This Field Controls

  • - Reserved WPRI.

Common Values

This field is better understood together with surrounding context than as a fixed memorized enumeration.

1

SIE

RW/RO0

Global interrupt enable for S-mode; read-only zero if S-mode is not implemented.

SIE (bit 1) — Global interrupt enable for S-mode; read-only zero if S-mode is not implemented.

What This Field Controls

  • - Global interrupt enable for S-mode; read-only zero if S-mode is not implemented.

Common Values

0Disabled

When currently running in S-mode, global supervisor interrupts are disabled.

1Enabled

When currently running in S-mode, global supervisor interrupts are enabled; delivery also depends on sie/sip and delegation state.

0

WPRI

WPRI

Reserved WPRI (Writes Preserve, Reads Ignore).

WPRI (bit 0) — Reserved WPRI (Writes Preserve, Reads Ignore).

What This Field Controls

  • - Reserved WPRI (Writes Preserve, Reads Ignore).

Common Values

This field is better understood together with surrounding context than as a fixed memorized enumeration.

Official Basis & Search Notes

mstatus is a RW CSR in machine status, trap, and interrupt csrs at 0x300. Check privilege and implemented extensions before interpreting its bit fields.

The official CSR table defines mstatus at 0x300 as a Machine RW CSR; individual fields can still be WARL, read-only, or hardware-updated.
RV64 and RV32 use different field positions; on RV32, MBE, SBE, GVA, MPV, MPELP, and MDT reside in mstatush.
SPELP/MPELP are defined by Zicfilp, SDT by Ssdbltrp, and MDT by Smdbltrp; extension-dependent fields are not unconditionally writable bits.

Assembly Operation Examples

Read/write mstatus using csrr/csrw/csrs/csrc instructions. Ref: RISC-V Privileged Architecture §2.8

csrr t0, mstatus
Read full mstatus value into t0
csrs mstatus, t0
Atomically set bits in mstatus where t0 has 1s (e.g., enable MIE)
csrc mstatus, t0
Atomically clear bits in mstatus where t0 has 1s (e.g., disable MIE)
li t0, 0x00002008; csrs mstatus, t0
Enable MIE(bit3)+set FS=Initial(bit13,01)

Relationship With Other CSRs

mstatus is the core M-mode status register. sstatus is the restricted view of S-mode-relevant mstatus fields, including SIE, SPIE, SPP, SUM, and MXR. mstatus.MIE controls global interrupt enable for M-mode; M-mode interrupt delivery also depends on mie/mip and delegation state. FS/VS/XS fields control FP/vector/extension register context save policy.

Key Bit Field Reference

MIE(bit3) global interrupt enable | MPIE(bit7) saved MIE before trap | MPP(bits12:11) pre-trap privilege (00=U,01=S,11=M) | FS(bits14:13) FPU state (00=Off,01=Initial,10=Clean,11=Dirty) | SD(XLEN-1; RV64 bit63, RV32 bit31) state dirty summary (set when FS, VS, or XS is Dirty)

What To Check First When Reading This CSR

  • - mstatus is the M-mode CSR at address 0x300; a direct access below M-mode raises an illegal-instruction exception.
  • - Select the RV32 or RV64 field map according to the current MXLEN; several high-order RV32 status fields reside in mstatush.
  • - Interpret WPRI, WARL, and extension-dependent fields according to their official field rules and the implemented behavior.

Risk Checks Before Writing

  • - Preserve bits that are not being changed so reserved or implementation-defined fields are not written with invalid values.
  • - Prefer CSRRS/CSRRC for local set/clear operations to avoid CSRRW overwriting concurrently updated status bits.

Put It Back Into A Real Flow

1

During initialization or the relevant privileged flow, software reads mstatus to observe the current state.

2

Modify only the target fields while preserving all other bits.

3

Read back the CSR or validate through later trap, interrupt, or context-switch behavior that the setting took effect.

FAQ

Can mstatus be accessed from any privilege level?

Do not decide from the CSR name alone. The official CSR address encoding and tables define the lowest access privilege; this entry records mstatus as Machine. Access with insufficient privilege or to an unimplemented CSR raises an illegal-instruction exception.

What is easiest to miss when writing mstatus?

Do not overwrite the whole CSR as if it were an ordinary integer. Modify only target fields, preserve unchanged bits, and follow the specification for WARL, WLRL, WPRI, or reserved fields.