-
Notifications
You must be signed in to change notification settings - Fork 749
Add mcounteren register
#2403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mcounteren register
#2403
Changes from all commits
caf5d18
a3156a1
3be372e
e761c27
a8412c6
d8ceb5e
635efe2
abd0c51
f8180f8
42811c3
230cefc
fb642e3
3e4615e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,7 @@ module top import ibex_pkg::*; #( | |
|
|
||
| // CPU Control Signals | ||
| input ibex_mubi_t fetch_enable_i, | ||
| input ibex_mubi_t mcounteren_writable_i, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of making this an input as opposed to a parameter? Is there a use-case to be able to switch this dynamically during runtime?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. This allows locking the |
||
| output logic core_sleep_o, | ||
| output logic alert_minor_o, | ||
| output logic alert_major_internal_o, | ||
|
|
@@ -162,7 +163,9 @@ NotDebug: assume property (!ibex_top_i.u_ibex_core.debug_mode & !debug_req_i); | |
| ConstantBoot: assume property (boot_addr_i == $past(boot_addr_i)); | ||
| // 3. Always fetch enable | ||
| FetchEnable: assume property (fetch_enable_i == IbexMuBiOn); | ||
| // 4. Never try to sleep if we couldn't ever wake up | ||
| // 4. Always have mcounteren writable | ||
| McounterenWritable: assume property (mcounteren_writable_i == IbexMuBiOn); | ||
| // 5. Never try to sleep if we couldn't ever wake up | ||
| WFIStart: assume property (`IDC.ctrl_fsm_cs == SLEEP |-> ( | ||
| `CSR.mie_q.irq_software | | ||
| `CSR.mie_q.irq_timer | | ||
|
|
@@ -441,18 +444,25 @@ logic ex_is_checkable_csr; | |
| assign ex_is_checkable_csr = ~( | ||
| ((CSR_MHPMCOUNTER3H <= `CSR_ADDR) && (`CSR_ADDR <= CSR_MHPMCOUNTER31H)) | | ||
| ((CSR_MHPMCOUNTER3 <= `CSR_ADDR) && (`CSR_ADDR <= CSR_MHPMCOUNTER31)) | | ||
| ((CSR_HPMCOUNTER3H <= `CSR_ADDR) && (`CSR_ADDR <= CSR_HPMCOUNTER31H)) | | ||
| ((CSR_HPMCOUNTER3 <= `CSR_ADDR) && (`CSR_ADDR <= CSR_HPMCOUNTER31)) | | ||
| ((CSR_MHPMEVENT3 <= `CSR_ADDR) && (`CSR_ADDR <= CSR_MHPMEVENT31)) | | ||
| (`CSR_ADDR == CSR_CPUCTRLSTS) | (`CSR_ADDR == CSR_SECURESEED) | | ||
| (`CSR_ADDR == CSR_MIE) | | ||
| (`CSR_ADDR == CSR_MCYCLE) | (`CSR_ADDR == CSR_MCYCLEH) | | ||
| (`CSR_ADDR == CSR_CYCLE) | (`CSR_ADDR == CSR_CYCLEH) | | ||
|
|
||
| // TODO: | ||
| (`CSR_ADDR == CSR_MINSTRET) | (`CSR_ADDR == CSR_MINSTRETH) | | ||
| (`CSR_ADDR == CSR_INSTRET) | (`CSR_ADDR == CSR_INSTRETH) | | ||
| (`CSR_ADDR == CSR_MCOUNTINHIBIT) | ||
| ); | ||
|
|
||
| `undef INSTR | ||
|
|
||
| // Force mcounteren to always be zero to match the current Sail model. | ||
| McounterenStubbedZero: assume property (`CSR.mcounteren_q == 32'h0); | ||
|
|
||
| ////////////////////// Decompression Invariant Defs ////////////////////// | ||
| // These will be used to show that the decompressed instruction stored is in fact the decompressed version of the compressed instruction. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Copyright lowRISC contributors. | ||
| # Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # This test verifies the mcounteren write-lock mechanism by dynamically setting | ||
| # the mcounteren_writable_i hardware input. It validates that register updates | ||
| # are silently ignored while locked and succeed when unlocked, using immediate | ||
| # software readbacks to confirm the state. Inter-process signaling with the UVM | ||
| # testbench is achieved by monitoring writes to mcycle (lock command) and | ||
| # mcycleh (unlock command). | ||
|
|
||
| #include "riscv_test.h" | ||
| #include "test_macros.h" | ||
|
|
||
| RVTEST_RV32M | ||
| RVTEST_CODE_BEGIN | ||
|
|
||
| # Initial Write (Unlocked) | ||
| li s0, 0x5 | ||
| csrw mcounteren, s0 | ||
| csrr t1, mcounteren | ||
| li t2, 0x5 | ||
| # If readback != 0x5, fail immediately | ||
| bne t1, t2, fail | ||
|
|
||
| # Tell UVM to lock by writing to mcycle, which is monitored by the UVM | ||
| # testbench to set `mcounteren_writable` | ||
| csrw mcycle, x0 | ||
|
|
||
| # Small delay loop to let the hardware pin force propagate | ||
| .rept 5 | ||
| nop | ||
| .endr | ||
|
|
||
| # Try to overwrite mcounteren with 0x0 while locked | ||
| li s1, 0x0 | ||
| csrw mcounteren, s1 | ||
| csrr t1, mcounteren | ||
| bne t1, s0, fail | ||
|
marnovandermaas marked this conversation as resolved.
marnovandermaas marked this conversation as resolved.
|
||
|
|
||
| # Tell UVM to unlock by writing to mcycleh | ||
| csrw mcycleh, x0 | ||
|
|
||
| .rept 5 | ||
| nop | ||
| .endr | ||
|
|
||
| # Try to overwrite it with 0x0 again. This time while unlocked | ||
| li s3, 0x0 | ||
| csrw mcounteren, s3 | ||
| csrr t1, mcounteren | ||
| bne t1, s3, fail | ||
|
|
||
| # Success Exit | ||
| j pass | ||
| TEST_PASSFAIL | ||
|
|
||
| RVTEST_CODE_END | ||
|
|
||
| RVTEST_DATA_BEGIN | ||
| TEST_DATA | ||
| RVTEST_DATA_END | ||
Uh oh!
There was an error while loading. Please reload this page.