CSR Bit Fields

RISC-V sscratch CSR Register

Address 0x140Privilege SupervisorAccess RW / SXLENSupervisor status, trap, and interrupt CSRs

Supervisor scratch register, an SXLEN-bit read/write CSR dedicated for S-mode software use.

Field Map

Understand sscratch By Bit Fields

1 key fields
SXLEN-1:0

VALUE

RW

Complete scratch value for S-mode use; the privileged architecture does not define internal bit fields for this value.

VALUE (bits SXLEN-1:0) — Complete scratch value for S-mode use; the privileged architecture does not define internal bit fields for this value.

What This Field Controls

  • - Complete scratch value for S-mode use; the privileged architecture does not define internal bit fields for this value.

Common Values

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

Official Basis & Search Notes

sscratch is the SXLEN-bit Supervisor-mode read/write scratch CSR at 0x140. It typically holds a hart-local supervisor context pointer; its contents are defined by S-mode software convention, not by hardware bit fields.

The official manual defines sscratch as an SXLEN-bit read/write register dedicated for supervisor use.
A typical use is swapping it with a general-purpose register on entry to an S-mode trap handler to obtain a hart-local supervisor context pointer.
sscratch has no standardized internal bit fields; the VALUE row represents the complete software-managed value.

What To Check First When Reading This CSR

  • - sscratch is an SXLEN-bit Supervisor-mode read/write CSR at 0x140.
  • - The meaning of the value is defined by S-mode software convention; hardware does not automatically interpret it for ordinary traps.
  • - Access with insufficient privilege or to an unimplemented CSR raises an illegal-instruction exception.

Risk Checks Before Writing

  • - Writing sscratch changes the scratch value that S-mode trap-entry software may rely on.
  • - If it is used as a hart-local context pointer, keep the same software convention across trap entry, nested traps, and return paths.

Put It Back Into A Real Flow

1

S-mode initialization writes the agreed scratch value for each hart.

2

Trap entry swaps or reads sscratch with CSR instructions and a general-purpose register.

3

Trap handling and return code restore or update the value according to the same S-mode software convention.

FAQ

Can sscratch 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 sscratch as Supervisor. Access with insufficient privilege or to an unimplemented CSR raises an illegal-instruction exception.

What is easiest to miss when writing sscratch?

Do not treat sscratch as a hardware-defined bit-field register. The written value is interpreted by S-mode trap software convention, and an accidental overwrite can break the context pointer or temporary value used by trap entry.