mcounteren
Machine counter enable
- Address
0x306- Group
- Machine-level CSRs
- Privilege
MRW(privileged spec CSR listing, Machine Trap Setup)- Access
- read/write; lowest privilege M (machine)
- Address range
- Standard read/write
- Name in riscv-unified-db
- Machine Counter Enable
Privileged spec: Machine counter enable
Description
The counter-enable mcounteren register is a 32-bit register that controls the availability
of the hardware performance-monitoring counters to
When S is implemented:
S-mode
Otherwise, when U is implemented:
U-mode
Otherwise:
the next-lower privileged mode
.
The settings in this register only control accessibility. The act of reading or writing this register does not affect the underlying counters, which continue to increment even when not accessible.
When the CY, TM, IR, or HPMn bit in the mcounteren register is clear, attempts to read the
cycle, time, instret, or hpmcountern register while executing in
When S is implemented:
S-mode
Otherwise, when U is implemented:
U-mode
Otherwise:
S-mode or U-mode
will cause an IllegalInstruction exception. When one of these bits is set, access to the
corresponding register is permitted in
When S is implemented:
S-mode
Otherwise, when U is implemented:
U-mode
Otherwise:
the next implemented privilege mode (S-mode if implemented, otherwise U-mode).
Note: The counter-enable bits support two common use cases with minimal hardware. For harts that do not need high-performance timers and counters, machine-mode software can trap accesses and implement all features in software. For harts that need high-performance timers and counters but are not concerned with obfuscating the underlying hardware counters, the counters can be directly exposed to lower privilege modes.
The cycle, instret, and hpmcountern CSRs are read-only shadows of mcycle, minstret,
and mhpmcounter n, respectively. The time CSR is a read-only shadow of the memory-mapped
mtime register.
When possible_xlens.include?(32):
Analogously, on RV32I the cycleh, instreth and hpmcounternh CSRs are
read-only shadows of mcycleh, minstreth and mhpmcounternh, respectively.
On RV32I the timeh CSR is a read-only shadow of the upper 32 bits of the memory-mapped mtime
register, while time shadows only the lower 32 bits of mtime.
Note: Implementations can convert reads of the time and timeh CSRs into loads to the
memory-mapped mtime register, or emulate this functionality on behalf of less-privileged
modes in M-mode software.
When !ext?(:U):
In harts with U-mode, the mcounteren CSR must be implemented, but all fields are WARL and may
be read-only zero, indicating reads to the corresponding counter will cause an
IllegalInstruction exception when executing in a less-privileged mode.
In harts without U-mode, the mcounteren register should not exist.
When S is implemented:
The cycle, instret, and hpmcountern CSRs can also be made available to U-mode
through the scounteren CSR
When H is implemented:
and to VS-mode and/or VU-mode through hcounteren
.
When Smcdeleg is implemented:
When the Smcdeleg/Ssccfg extensions are enabled (menvcfg.CDE=1), mcounteren further
allows M-mode to delegate select counters to S-mode. When a counter i is delegated
(mcounteren[i]=1 and menvcfg.CDE=1), the register state associated with counter i
can be read or written via sireg*, while siselect holds 0x40+i.
From riscv-unified-db, reformatted.
Fields
| Field | Bits | Type | Description |
|---|---|---|---|
CY | 0 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
TM | 1 | RO | Placeholder for delegating |
IR | 2 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM3 | 3 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM4 | 4 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM5 | 5 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM6 | 6 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM7 | 7 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM8 | 8 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM9 | 9 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM10 | 10 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM11 | 11 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM12 | 12 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM13 | 13 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM14 | 14 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM15 | 15 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM16 | 16 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM17 | 17 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM18 | 18 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM19 | 19 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM20 | 20 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM21 | 21 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM22 | 22 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM23 | 23 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM24 | 24 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM25 | 25 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM26 | 26 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM27 | 27 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM28 | 28 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM29 | 29 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM30 | 30 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When | |
HPM31 | 31 | When set, the When S is implemented: S-mode. Otherwise: U-mode. When S is implemented: When When H is implemented: When When |
Fields from riscv-unified-db; field types computed by IDL functions there are not shown.
Specification and related pages
- The RISC-V Instruction Set Manual, Volume II: CSR listing (src/priv/csrs.adoc)
- riscv-opcodes csrs.csv
- riscv-unified-db: spec/std/isa/csr/I/mcounteren.yaml
- csrrw, csrrs, csrrc (Zicsr instructions that access CSRs)