mcounteren

Machine Counter Enable

The counter-enable mcounteren register is a 32-bit register that controls the availability of the hardware performance-monitoring counters to 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 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 the next implemented privilege mode (S-mode if implemented, otherwise U-mode).

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. 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.

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.

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.

Attributes

Defining Extension

  • U, version >= 0

CSR Address

0x306

Length

32-bit

Privilege Mode

M

Format

mcounteren format
Figure 1. mcounteren format

Field Summary

Name Location Type Reset Value

CY

0

RW
RO
UNDEFINED_LEGAL
0

TM

1

RO

0

IR

2

RW
RO
UNDEFINED_LEGAL
0

HPM3

3

RW
RO
UNDEFINED_LEGAL
0

HPM4

4

RW
RO
UNDEFINED_LEGAL
0

HPM5

5

RW
RO
UNDEFINED_LEGAL
0

HPM6

6

RW
RO
UNDEFINED_LEGAL
0

HPM7

7

RW
RO
UNDEFINED_LEGAL
0

HPM8

8

RW
RO
UNDEFINED_LEGAL
0

HPM9

9

RW
RO
UNDEFINED_LEGAL
0

HPM10

10

RW
RO
UNDEFINED_LEGAL
0

HPM11

11

RW
RO
UNDEFINED_LEGAL
0

HPM12

12

RW
RO
UNDEFINED_LEGAL
0

HPM13

13

RW
RO
UNDEFINED_LEGAL
0

HPM14

14

RW
RO
UNDEFINED_LEGAL
0

HPM15

15

RW
RO
UNDEFINED_LEGAL
0

HPM16

16

RW
RO
UNDEFINED_LEGAL
0

HPM17

17

RW
RO
UNDEFINED_LEGAL
0

HPM18

18

RW
RO
UNDEFINED_LEGAL
0

HPM19

19

RW
RO
UNDEFINED_LEGAL
0

HPM20

20

RW
RO
UNDEFINED_LEGAL
0

HPM21

21

RW
RO
UNDEFINED_LEGAL
0

HPM22

22

RW
RO
UNDEFINED_LEGAL
0

HPM23

23

RW
RO
UNDEFINED_LEGAL
0

HPM24

24

RW
RO
UNDEFINED_LEGAL
0

HPM25

25

RW
RO
UNDEFINED_LEGAL
0

HPM26

26

RW
RO
UNDEFINED_LEGAL
0

HPM27

27

RW
RO
UNDEFINED_LEGAL
0

HPM28

28

RW
RO
UNDEFINED_LEGAL
0

HPM29

29

RW
RO
UNDEFINED_LEGAL
0

HPM30

30

RW
RO
UNDEFINED_LEGAL
0

HPM31

31

RW
RO
UNDEFINED_LEGAL
0

Fields

CY

Location

0

Description

When set, the cycle CSR (an alias of mcycle) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

TM

Location

1

Description

Placeholder for delegating time to less-privileged modes; however, since time
is memory-mapped rather than a CSR, this field is always read-only zero.

Type

RO

Reset value

0

IR

Location

2

Description

When set, the instret CSR (an alias of minstret) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM3

Location

3

Description

When set, the hpmcounter3 CSR (an alias of mhpmcounter3) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM4

Location

4

Description

When set, the hpmcounter4 CSR (an alias of mhpmcounter4) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM5

Location

5

Description

When set, the hpmcounter5 CSR (an alias of mhpmcounter5) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM6

Location

6

Description

When set, the hpmcounter6 CSR (an alias of mhpmcounter6) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM7

Location

7

Description

When set, the hpmcounter7 CSR (an alias of mhpmcounter7) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM8

Location

8

Description

When set, the hpmcounter8 CSR (an alias of mhpmcounter8) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM9

Location

9

Description

When set, the hpmcounter9 CSR (an alias of mhpmcounter9) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM10

Location

10

Description

When set, the hpmcounter10 CSR (an alias of mhpmcounter10) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM11

Location

11

Description

When set, the hpmcounter11 CSR (an alias of mhpmcounter11) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM12

Location

12

Description

When set, the hpmcounter12 CSR (an alias of mhpmcounter12) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM13

Location

13

Description

When set, the hpmcounter13 CSR (an alias of mhpmcounter13) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM14

Location

14

Description

When set, the hpmcounter14 CSR (an alias of mhpmcounter14) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM15

Location

15

Description

When set, the hpmcounter15 CSR (an alias of mhpmcounter15) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM16

Location

16

Description

When set, the hpmcounter16 CSR (an alias of mhpmcounter16) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM17

Location

17

Description

When set, the hpmcounter17 CSR (an alias of mhpmcounter17) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM18

Location

18

Description

When set, the hpmcounter18 CSR (an alias of mhpmcounter18) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM19

Location

19

Description

When set, the hpmcounter19 CSR (an alias of mhpmcounter19) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM20

Location

20

Description

When set, the hpmcounter20 CSR (an alias of mhpmcounter20) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM21

Location

21

Description

When set, the hpmcounter21 CSR (an alias of mhpmcounter21) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM22

Location

22

Description

When set, the hpmcounter22 CSR (an alias of mhpmcounter22) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM23

Location

23

Description

When set, the hpmcounter23 CSR (an alias of mhpmcounter23) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM24

Location

24

Description

When set, the hpmcounter24 CSR (an alias of mhpmcounter24) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM25

Location

25

Description

When set, the hpmcounter25 CSR (an alias of mhpmcounter25) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM26

Location

26

Description

When set, the hpmcounter26 CSR (an alias of mhpmcounter26) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM27

Location

27

Description

When set, the hpmcounter27 CSR (an alias of mhpmcounter27) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM28

Location

28

Description

When set, the hpmcounter28 CSR (an alias of mhpmcounter28) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM29

Location

29

Description

When set, the hpmcounter29 CSR (an alias of mhpmcounter29) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM30

Location

30

Description

When set, the hpmcounter30 CSR (an alias of mhpmcounter30) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0

HPM31

Location

31

Description

When set, the hpmcounter31 CSR (an alias of mhpmcounter31) is accessible to
U-mode.


Type
RW
RO
Reset value
UNDEFINED_LEGAL
0