Skip to content

[dv] CSR testbench fixes - #2465

Open
SamuelRiedel wants to merge 3 commits into
lowRISC:masterfrom
SamuelRiedel:csr-tb-fixes
Open

[dv] CSR testbench fixes#2465
SamuelRiedel wants to merge 3 commits into
lowRISC:masterfrom
SamuelRiedel:csr-tb-fixes

Conversation

@SamuelRiedel

Copy link
Copy Markdown
Contributor

Fix tb_cs_registers golden model and testbench:

  • Fix reset signal always being low under newer Verilator version
  • Implement SMEPMP write suppression (rule 4b) in the golden model
  • Fix incorrect PMP address register locking in the golden model

@ZhongYic00 and @brdr-life, does this resolve #2242 for you?

Closes #2242

Fixes lowRISC#2242

Signed-off-by: Samuel Riedel <sriedel@lowrisc.org>
Signed-off-by: Samuel Riedel <sriedel@lowrisc.org>
Signed-off-by: Samuel Riedel <sriedel@lowrisc.org>
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@SamuelRiedel

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document. By submitting this pull request comment, I am hereby confirming my acceptance of the terms of the CLA Document and my agreement to be legally bound by its terms.

@ZhongYic00

Copy link
Copy Markdown

LGTM 👏🏻

Comment on lines +46 to +47
// Note: under Verilator, in_rst_ni is an inout that eval_initial forces to 0,
// so we rely solely on the DPI reset driver (dpi_rst_ni).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is eval_initial?


// Returns a per-byte mask for bytes whose write must be suppressed under
// SMEPMP rule 4b: MML=1, RLB=0, and the candidate byte has lock=1 with
// {X,W,R} in {0x4(X), 0x2(W), 0x6(W+X), 0x5(X+R)}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suspect the latest official release of the RISC-V Priv spec (version 20260120) doesn't have "SMEPMP rule 4b" as such anymore. Some content that may have been it seems to have been moved into a "Historical Rationale for Extensions" appendix (A.1.4.b), which doesn't seem as strong a thing to reference. Perhaps clarify or replace this reference?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found some other things confusing, but perhaps that was because I am had little prior knowledge of PMP.

  1. I was confused that if this only restricted locked cfgs then it seemed to be redundant w.r.t. PmpCfgRegister::GetLockMask(), until I realised that this checked the value being written, rather than the existing value. Just me not catching the intended meaning of "candidate".
  2. I was additionally confused for some time about why these particular combinations of permissions were included, until I read 3.1.19 "Adding a rule with executable privileges that either is M-mode-only or a locked Shared-Region..." and the table in 6.2 together closely.

A larger explanatory comment here would be nice to avoid any future misunderstanding, but ultimately anyone making changes here should have a good understanding of the spec (which I apparently didn't) already.

Comment on lines +205 to +206
register_value_ = (register_value_ & (lock_mask | suppress_mask)) |
(candidate & ~lock_mask & ~suppress_mask);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is quite right. If both masks are all zeros (allow any bit to be cleared), then the existing register value will be entirely lost.

How about:

register_value_ &= (~newval | lock_mask | suppress_mask);

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.

[dv] tb_cs_registers golden-model error in ePMP extension

3 participants