When only M-mode is implemented, should M-mode be able to access mhpmcounter* via the hpmcounter* CSR number?


Ricardo Ramirez
 

When only M-mode is implemented, should M-mode be able to access mhpmcounter* via the hpmcounter* CSR number? The spec appears to be unclear. On one hand, it says that all counters should be implemented (even if hardwired to 0), and M-mode can usually access any implemented CSR. But the CSR number is for a User CSR, and U-mode is not implemented.
 


John Hauser
 

When only M-mode is implemented, should M-mode be able to access
mhpmcounter* via the hpmcounter* CSR number? The spec appears to be
unclear. On one hand, it says that all counters should be implemented
(even if hardwired to 0), and M-mode can usually access any
implemented CSR. But the CSR number is for a User CSR, and U-mode is
not implemented.
In the latest ratified Privileged Architecture document, 1.12, the
hpmcounter* CSRs are specified as _unprivileged_ CSRs, not user CSRs.

- John Hauser


Anthony Coulter
 

One way to appreciate the difference between "unprivileged CSRs" and "user mode" is to consider the related question: If a microcontroller implements the floating-point extension but does not implement user mode, does it support the fflags and frm CSRs? Of course it does.

"To implement user mode" is to have a hidden bit of state that determines whether privileged instructions cause traps. Whereas for a feature to be "unprivileged" just means that it won't cause those traps regardless of the current value of the hidden bits of state, if any are supported at all.