Skip to content

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

Open
@mimiqdev

Description

@mimiqdev

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions