CSR Bit Fields

RISC-V scause CSR Register

Address 0x142Privilege SupervisorAccess RW / XLENSupervisor status, trap, and interrupt CSRs

Supervisor trap cause register; records the event type and cause code that triggered an S-mode trap.

Field Map

Understand scause By Bit Fields

2 key fields
XLEN-1

Interrupt

WLRL

1=Interrupt, 0=Exception; handled as part of the WLRL cause value.

Interrupt (bits XLEN-1) — 1=Interrupt, 0=Exception; handled as part of the WLRL cause value.

What This Field Controls

  • - 1=Interrupt, 0=Exception; handled as part of the WLRL cause value.

Common Values

00

This is a synchronous exception; the low field is interpreted as an exception cause code.

11

This is an interrupt; the low field is interpreted as an interrupt cause code.

XLEN-2:0

Exception Code

WLRL

Cause code; software must not assume that arbitrary written cause codes are retained, and must interpret only official and implemented legal values.

Exception Code (bits XLEN-2:0) — Cause code; software must not assume that arbitrary written cause codes are retained, and must interpret only official and implemented legal values.

What This Field Controls

  • - Cause code; software must not assume that arbitrary written cause codes are retained, and must interpret only official and implemented legal values.

Common Values

Synchronous exceptions
0Instruction address misaligned

Synchronous exception cause code 0.

1Instruction access fault

Synchronous exception cause code 1.

2Illegal instruction

Synchronous exception cause code 2.

3Breakpoint

Synchronous exception cause code 3.

4Load address misaligned

Synchronous exception cause code 4.

5Load access fault

Synchronous exception cause code 5.

6Store/AMO address misaligned

Synchronous exception cause code 6.

7Store/AMO access fault

Synchronous exception cause code 7.

8Environment call from U-mode

Synchronous exception cause code 8.

9Environment call from S-mode

Synchronous exception cause code 9.

12Instruction page fault

Synchronous exception cause code 12.

13Load page fault

Synchronous exception cause code 13.

15Store/AMO page fault

Synchronous exception cause code 15.

18Software check

Synchronous exception cause code 18.

19Hardware error

Synchronous exception cause code 19.

Interrupts
1Supervisor software interrupt

When Interrupt is 1, low cause code 1 indicates a supervisor software interrupt.

5Supervisor timer interrupt

When Interrupt is 1, low cause code 5 indicates a supervisor timer interrupt.

9Supervisor external interrupt

When Interrupt is 1, low cause code 9 indicates a supervisor external interrupt.

13Counter-overflow interrupt

When Interrupt is 1, low cause code 13 indicates a counter-overflow interrupt.

Official Basis & Search Notes

scause is a RW CSR in supervisor status, trap, and interrupt csrs at 0x142. Check privilege and implemented extensions before interpreting its bit fields.

scause address, lowest access privilege, and access class are checked against the official CSR table: 0x142, Supervisor, RW.
Read it as part of supervisor 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.

What To Check First When Reading This CSR

  • - First confirm that the current hart implements scause; unimplemented or insufficiently privileged accesses raise an illegal-instruction exception.
  • - Use address 0x142 and the lowest access privilege (Supervisor) 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 scause 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 scause 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 scause as Supervisor. Access with insufficient privilege or to an unimplemented CSR raises an illegal-instruction exception.

What is easiest to miss when writing scause?

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.