Skip to content
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

Wrong senvcfg check for systems without S-mode support #1898

Open
mimiqdev opened this issue Jan 21, 2025 · 2 comments · May be fixed by #1899
Open

Wrong senvcfg check for systems without S-mode support #1898

mimiqdev opened this issue Jan 21, 2025 · 2 comments · May be fixed by #1899

Comments

@mimiqdev
Copy link

In Spike's require_envcfg macro, it checks senvcfg even when S-mode is not supported:

#define require_envcfg(field) \
  do { \
    if (((STATE.prv != PRV_M) && (m##field == 0)) || \
        ((STATE.prv == PRV_U && !STATE.v) && (s##field == 0))) \
      throw trap_illegal_instruction(insn.bits()); \
    else if (STATE.v && ((h##field == 0) || \
                        ((STATE.prv == PRV_U) && (s##field == 0)))) \
      throw trap_virtual_instruction(insn.bits()); \
  } while (0);

This is problematic for systems that don't implement S-mode. The current implementation would incorrectly check s##field (like senvcfg.CBIE for CBO.FLUSH instruction) even when S-mode is not supported.
The discussion in the CMO spec repo riscv/riscv-CMOs#71

Possible fixes:

#define require_envcfg(field) \
  do { \
    if ((STATE.prv != PRV_M) && (m##field == 0)) \
      throw trap_illegal_instruction(insn.bits()); \
    if (p->extension_enabled_const('S') && (STATE.prv == PRV_U && !STATE.v) && (s##field == 0)) \
      throw trap_illegal_instruction(insn.bits()); \
    else if (STATE.v && ((h##field == 0) || \
                        (p->extension_enabled_const('S') && (STATE.prv == PRV_U) && (s##field == 0)))) \
      throw trap_virtual_instruction(insn.bits()); \
  } while (0);
@aswaterman
Copy link
Collaborator

Your proposed fix looks correct to me. Would you mind issuing a pull request?

@mimiqdev
Copy link
Author

Thanks for the reply, I'll create a PR.

@mimiqdev mimiqdev linked a pull request Jan 21, 2025 that will close this issue
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 a pull request may close this issue.

2 participants