Skip to content

MRET/SRET Do Not Clear MPRV When Returning to a Less-Privileged Mode #252

@fly-1011

Description

@fly-1011

Bug Description:

MPRV is bit 17 of the mstatus CSR.

According to the RISC-V Privileged Specification:

An MRET or SRET instruction that changes the privilege mode to a mode less privileged than M also sets MPRV=0.

However, in NutShell, when using MRET or SRET to transition from M-mode to a lower-privilege mode, the MPRV bit remains set to 1, which violates the specification.

To Reproduce:

  1. Start in M-mode.
  2. Write mstatus with MPRV=1
  3. Execute MRET (or SRET) so that the privilege mode drops from M-mode to a lower privilege (e.g., U-mode).
  4. Compare mstatus between NutShell and Spike.

Test program and log information: test_MPRV.zip

Inconsistent information:

Image Image

sret also observed the same inconsistency.

Environment:

NutShell: commit e315a27

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions