Skip to content

Refactor illegal instruction warning handling - #328

Merged
MikeOpenHWGroup merged 4 commits into
openhwfoundation:mainfrom
MikeOpenHWGroup:refactor_illegal_insn_warn
Sep 2, 2026
Merged

MikeOpenHWGroup merged 4 commits into
openhwfoundation:mainfrom
MikeOpenHWGroup:refactor_illegal_insn_warn

Conversation

@MikeOpenHWGroup

Copy link
Copy Markdown

The controller has a bit of behavioural code that prints a warning if an illegal instruction is decoded. This PR will terminate the simulation if the PC does not advance (such circumstances will result in an infinite loop that spews "Illegal instruction..." messages every clock cycle).

The controller has a bit of behavioural code that prints a warning if an illegal instruction is decoded.  This PR will terminate the simulation if the PC does not advance (such circumstances will result in an infinite loop that spews "Illegal instruction..." messages every clock cycle).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the simulation-only illegal-instruction warning logic in cve2_controller to detect when the core is repeatedly decoding an illegal instruction without making forward progress, and to terminate the simulation to avoid infinite warning spam.

Changes:

  • Adds a “last PC” tracker in the controller’s simulation-only block.
  • Attempts to terminate the simulation when the same illegal instruction is seen at an unchanged PC.
  • Minor formatting updates to $display time formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rtl/cve2_controller.sv Outdated
Comment on lines +160 to +164
logic [31:0] pc_last = 0;
always_ff @(negedge clk_i) begin
// print warning in case of decoding errors
// print warning in case of decoding errors (terminate if the PC doesn't advance).
if ((ctrl_fsm_cs == DECODE) && instr_valid_i && !instr_fetch_err_i && illegal_insn_d) begin
$display("%m @ %t: Illegal instruction (hart %0x) at PC 0x%h: 0x%h", $time, cve2_core.hart_id_i,
cve2_id_stage.pc_id_i, cve2_id_stage.instr_rdata_i);
$display("%m @ %0t: Illegal instruction (hart %0x) at PC 0x%h: 0x%h",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi @MikeOpenHWGroup,

On top of what Copilot said, I think that the premise that two illegal instructions decoded in a row on the same PC value does not necessarily mean an issue deserving termination. Consider that between two illegal instructions the PC may change to other values on legal instructions.
An indication of a problem where the termination of the test is necessary is when PC is stuck with the same upon many illegal instructions, i.e. when it seems to indicate that there is a indefinite loop.

On this case, maybe we don't need such kind of changes on the code, but rather rely on the timeout for the execution of a test.

@MikeOpenHWGroup MikeOpenHWGroup Jul 27, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The purpose of this code is to catch back-to-back illegal instructions at the same address. In this case, the core is stuck and the current code will create a very large (and useless) logfile. It is important to terminate such simulations. I have pushed in a version that addresses Copilot's comments.

@cairo-caplan cairo-caplan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hello @MikeOpenHWGroup ,

I approve the changes proposed by this PR. I would like to add two points though:

  1. Signal prev_illegal can effectively be removed, as it is not used anymore: it is implied that if the current instruction is illegal and it has the same PC as the previous one, the previous instruction was also illegal.
  2. This code may change again the future to acknowledge instructions routed to a coprocessor through the CV-X-IF, since they are illegal to the CVE2 itself. But that does not block this to be merged now

@MikeOpenHWGroup

Copy link
Copy Markdown
Author

Good feedback @cairo-caplan. I removed prev_illegal. As you say, we can deal with the necessary update in the future when we add support for the CV-X-IF in the testbench.

@MikeOpenHWGroup
MikeOpenHWGroup merged commit d079e8c into openhwfoundation:main Sep 2, 2026
3 checks passed
@MikeOpenHWGroup
MikeOpenHWGroup deleted the refactor_illegal_insn_warn branch September 3, 2026 18:53
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.

3 participants