CSR Bit Fields

RISC-V mcounteren CSR Register

Address 0x306Privilege MachineAccess RW / 32-bitMachine delegation, environment-configuration, and state-enable CSRs

Machine counter-enable register; controls availability of hardware performance-monitoring counters to the next-lower privileged mode.

Field Map

Understand mcounteren By Bit Fields

5 key fields
0

CY

WARL

Controls lower-privilege read access to cycle.

CY (bit 0) — Controls lower-privilege read access to cycle.

What This Field Controls

  • - Controls lower-privilege read access to cycle.

Common Values

0Access disabled

A less-privileged access to the corresponding CSR raises an illegal-instruction exception.

1Access enabled

Permits access from the next implemented lower privilege mode; lower-level controls such as hcounteren, when present, must also allow it.

1

TM

WARL

Controls lower-privilege read access to time; when clear, also blocks less-than-M access to stimecmp or vstimecmp.

TM (bit 1) — Controls lower-privilege read access to time; when clear, also blocks less-than-M access to stimecmp or vstimecmp.

What This Field Controls

  • - Controls lower-privilege read access to time; when clear, also blocks less-than-M access to stimecmp or vstimecmp.

Common Values

0Access disabled

A less-privileged access to the corresponding CSR raises an illegal-instruction exception.

1Access enabled

Permits access from the next implemented lower privilege mode; lower-level controls such as hcounteren, when present, must also allow it.

2

IR

WARL

Controls lower-privilege read access to instret.

IR (bit 2) — Controls lower-privilege read access to instret.

What This Field Controls

  • - Controls lower-privilege read access to instret.

Common Values

0Access disabled

A less-privileged access to the corresponding CSR raises an illegal-instruction exception.

1Access enabled

Permits access from the next implemented lower privilege mode; lower-level controls such as hcounteren, when present, must also allow it.

31:3

HPMn

WARL

Controls lower-privilege read access to hpmcounter3 through hpmcounter31.

HPMn (bits 31:3) — Controls lower-privilege read access to hpmcounter3 through hpmcounter31.

What This Field Controls

  • - Controls lower-privilege read access to hpmcounter3 through hpmcounter31.

Common Values

0Access disabled

A less-privileged access to the corresponding CSR raises an illegal-instruction exception.

1Access enabled

Permits access from the next implemented lower privilege mode; lower-level controls such as hcounteren, when present, must also allow it.

63:32

Reserved/RO0 (RV64)

RO0

mcounteren is a 32-bit register; in the RV64 CSR view, bits 63:32 contain no counter-enable bits and read as zero.

Reserved/RO0 (RV64) (bits 63:32) — mcounteren is a 32-bit register; in the RV64 CSR view, bits 63:32 contain no counter-enable bits and read as zero.

What This Field Controls

  • - mcounteren is a 32-bit register; in the RV64 CSR view, bits 63:32 contain no counter-enable bits and read as zero.

Common Values

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

Official Basis & Search Notes

mcounteren decides whether a lower privilege mode can read cycle, time, instret, and hpmcounter3-31. It does not affect whether the counters keep incrementing.

All mcounteren fields are WARL and may be implemented as read-only zero.
The TM bit controls access to stimecmp/vstimecmp from below M-mode in addition to time access.
mcounteren controls accessibility only; it is not a counter-inhibit register.

What To Check First When Reading This CSR

  • - mcounteren is a 32-bit register and must be implemented on harts with U-mode; on harts without U-mode it should not exist.
  • - All fields are WARL and may be read-only zero.
  • - The settings only control accessibility; the underlying counters continue to increment even when access is disabled.

Risk Checks Before Writing

  • - A clear CY, TM, IR, or HPMn bit causes lower-privilege reads of the corresponding counter CSR to raise an illegal-instruction exception.
  • - A clear TM bit also blocks less-than-M access to stimecmp or vstimecmp.
  • - Do not use mcounteren as a counter-inhibit control; use the relevant inhibit/configuration CSRs where specified.

Put It Back Into A Real Flow

1

Decide which counters the next lower privilege mode may read.

2

Set only the corresponding WARL enable bits and read back to confirm the accepted value.

3

Use hcounteren/scounteren or state-enable controls as additional lower-level gates where applicable.

FAQ

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

What is easiest to miss when writing mcounteren?

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.