CSR Bit Fields

RISC-V stvec CSR Register

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

Supervisor trap-vector base-address register; holds S-mode trap handler entry address.

Field Map

Understand stvec By Bit Fields

2 key fields
1:0

MODE

RW

0=Direct mode, 1=Vectored mode

MODE (bits 1:0) — 0=Direct mode, 1=Vectored mode.

What This Field Controls

  • - 0=Direct mode, 1=Vectored mode

Common Values

0Direct

All synchronous exceptions and interrupts set pc to BASE.

1Vectored

Synchronous exceptions set pc to BASE; interrupts set pc to BASE + 4 x cause.

>=2Reserved

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

XLEN-1:2

BASE

RW

Trap handler base address

BASE (bits XLEN-1:2) — Trap handler base address.

What This Field Controls

  • - Trap handler base address

Common Values

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

Official Basis & Search Notes

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

stvec address, lowest access privilege, and access class are checked against the official CSR table: 0x105, 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 stvec; unimplemented or insufficiently privileged accesses raise an illegal-instruction exception.
  • - Use address 0x105 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 stvec 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 stvec 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 stvec as Supervisor. Access with insufficient privilege or to an unimplemented CSR raises an illegal-instruction exception.

What is easiest to miss when writing stvec?

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.