CSR Bit Fields

RISC-V mstatus CSR Register

Address 0x300Privilege MachineAccess RW / XLENMachine 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.

Bit Overview
bit 3 = only bit 3; bits 12..11 = bits 12 down to 11
MSBLSB
SD63ROReserved0
Field Map

Understand mstatus By Bit Fields

24 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.

42

MDT

RW-H

Machine Disable Trap bit; set by hardware on trap entry to M-mode and cleared by MRET, controlling double-trap behavior.

MDT (bit 42) — Machine Disable Trap bit; set by hardware on trap entry to M-mode and cleared by MRET, controlling double-trap behavior.

What This Field Controls

  • - Machine Disable Trap bit; set by hardware on trap entry to M-mode and cleared by MRET, controlling double-trap behavior.

Common Values

00

Machine double-trap guard is not set.

11

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

39

MPV

RW-H

Machine Previous Virtualization mode; records whether execution was virtualized before trapping to M-mode.

MPV (bit 39) — Machine Previous Virtualization mode; records whether execution was virtualized before trapping to M-mode.

What This Field Controls

  • - Machine Previous Virtualization mode; records whether execution was virtualized before trapping to M-mode.

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; indicates whether the address written to mtval is a guest virtual address.

GVA (bit 38) — Guest Virtual Address flag; indicates whether the address written to mtval is a guest virtual address.

What This Field Controls

  • - Guest Virtual Address flag; indicates whether the address written to mtval is a guest virtual address.

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

RW

Machine Big-Endian control. 0=little-endian, 1=big-endian. Controls explicit memory accesses in 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. 0=little-endian, 1=big-endian. Controls explicit memory accesses in 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. 0=little-endian, 1=big-endian. Controls explicit memory accesses in M-mode. Instruction fetches are always little-endian. SBE and UBE may be read-only copies of MBE.

Common Values

0Little-endian

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

1Big-endian

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

36

SBE

RW/RO

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

RW

Effective XLEN encoding for S-mode on RV64.

SXL (bits 35:34) — Effective XLEN encoding for S-mode on RV64.

What This Field Controls

  • - Effective XLEN encoding for S-mode on RV64.

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

RW

Effective XLEN encoding for U-mode on RV64.

UXL (bits 33:32) — Effective XLEN encoding for U-mode on RV64.

What This Field Controls

  • - Effective XLEN encoding for U-mode on RV64.

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.

22

TSR

RW

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

RW

When set, WFI in lower privilege modes may trap as an illegal instruction.

TW (bit 21) — When set, WFI in lower privilege modes may trap as an illegal instruction.

What This Field Controls

  • - When set, WFI in lower privilege modes may trap as an illegal instruction.

Common Values

00

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

11

Lower-privilege WFI may raise an illegal-instruction exception if it does not complete promptly.

20

TVM

RW

When set, S-mode accesses to satp or SFENCE.VMA trap.

TVM (bit 20) — When set, S-mode accesses to satp or SFENCE.VMA trap.

What This Field Controls

  • - When set, S-mode accesses to satp or SFENCE.VMA trap.

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

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

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

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

RW

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

RW

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

RW

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

RW

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

RW

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

RW

User-mode endianness; 0=little-endian, 1=big-endian.

UBE (bit 6) — User-mode endianness; 0=little-endian, 1=big-endian.

What This Field Controls

  • - User-mode endianness; 0=little-endian, 1=big-endian.

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

Saved SIE value before entering an S-mode trap.

SPIE (bit 5) — Saved SIE value before entering an S-mode trap.

What This Field Controls

  • - Saved SIE value before entering an S-mode trap.

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.

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.

1

SIE

RW

Global interrupt enable for S-mode.

SIE (bit 1) — Global interrupt enable for S-mode.

What This Field Controls

  • - Global interrupt enable for S-mode.

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.

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.

mstatus address, lowest access privilege, and access class are checked against the official CSR table: 0x300, Machine, RW.
Read it as part of machine status, trap, and interrupt csrs before interpreting the bit-field table on this page.
Modify only target fields and preserve unchanged bits; interpret WPRI and reserved fields only as the official specification and implementation define them.

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

  • - First confirm that the current hart implements mstatus; unimplemented or insufficiently privileged accesses raise an illegal-instruction exception.
  • - Use address 0x300 and the lowest access privilege (Machine) to decide whether software may read it directly.
  • - Do not assume fixed values for reserved, WARL, or WLRL bits; interpret the value according to the specification and implementation.

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.