Skip to content

Add mcounteren register#2403

Open
SamuelRiedel wants to merge 11 commits into
lowRISC:masterfrom
SamuelRiedel:mcounteren
Open

Add mcounteren register#2403
SamuelRiedel wants to merge 11 commits into
lowRISC:masterfrom
SamuelRiedel:mcounteren

Conversation

@SamuelRiedel
Copy link
Copy Markdown
Contributor

@SamuelRiedel SamuelRiedel commented May 11, 2026

This PR adds the mcounteren register, which has so far been tied to zero and implements the U-mode performance counter aliases. The mcounteren register can be locked with an external MUBI signal (mcounteren_writable_i).

DV:
This PR adds two directed tests:

  • mcounteren_test goes through multiple configurations of the mcounteren register and validates that u-mode can only access the ones enabled.
  • mcounteren_lock_test verifies that the mcounteren CSR cannot be modified without the mcounteren_writable_i signal being set.

To Dos:

  • For the directed tests and the cosim to pass, we have to update riscv-isa-sim to also support those performance counters: Enable ZIHPM unpriviledged performance counters riscv-isa-sim#29
  • Currently, u-mode counter reads will lead to illegal instruction exceptions. However, we are not gating the value at the CSR module's interface for simplicity. The signal will not leave the core, but we should double-check that this is no security issue.
  • The dv/uvm/core_ibex/directed_tests/directed_testlist.yaml changes a lot everytime I regenerate it after even small modifications. This polluted the diff quite a bit. Is this expected?

Copy link
Copy Markdown
Contributor

@gautschimi gautschimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look all good to me! Just a few minor comments. (I did not look at the two WIP commits about formal)

Comment thread rtl/ibex_cs_registers.sv
Comment thread rtl/ibex_top.sv
Comment thread dv/uvm/core_ibex/directed_tests/mcounteren_test/mcounteren_test.S
Comment thread dv/uvm/core_ibex/directed_tests/directed_testlist.yaml
@SamuelRiedel
Copy link
Copy Markdown
Contributor Author

I disabled the check of the mcounteren CSR in the formal verification for now. Another reason for the failure of the formal verification was that we ran out of memory on the runner that has twice as many cores but half as much memory available. I'll address this in a separate PR and rebase once merged.

Copy link
Copy Markdown
Contributor

@gautschimi gautschimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

I mostly looked at RTL, but the changes in python, C, yaml, etc. look also good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants