Skip to content

[misa] Clearing U does not clear dependent S #276

Description

@kkapapu

Environment

Describe the bug

misa initially has both User (U, bit 20) and Supervisor (S, bit 18) set. Clearing only U should also clear S because S depends on U. NutShell leaves misa unchanged (both bits still set).

Minimal trigger:

csrr s0, misa
li   t0, (1 << 20)    # U
csrc misa, t0         # clear U while S is still 1
csrr s1, misa         # mismatch here

Observed values:

Stage Value Meaning
Initial misa 0x8000000000141105 MXL=RV64, extensions include U|S|M|I|C|A
After csrc (Sail) 0x8000000000001105 U and S both clearedM|I|C|A
After csrc (NutShell) 0x8000000000141105 U and S both still set (write ineffective w.r.t. dependency)

Mismatch at pc = 0x8000000c on s1:

  • riscv-Sail (right): 0x8000000000001105
  • NutShell (wrong): 0x8000000000141105

Expected behavior

Per RISC-V Privileged Spec (machine.adoc — misa extension dependencies):

If an ISA feature x depends on an ISA feature y, then attempting to enable feature x but disable feature y results in both features being disabled.
For example, setting "F"=0 and "D"=1 results in both "F" and "D" being cleared.
Similarly, setting "U"=0 and "S"=1 results in both "U" and "S" being cleared.

Clearing U while S remains set is exactly that illegal combination: the write must clear both U and S.

After csrc misa, (1<<20)
Expected (Sail) misa = 0x8000000000001105 (U=0, S=0)
Actual (NutShell) misa = 0x8000000000141105 (U=1, S=1 unchanged)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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