riscv / riscv-isa-manual

RISC-V Instruction Set Manual
https://riscv.org/
Creative Commons Attribution 4.0 International
3.57k stars 617 forks source link

What's the difference between "RV32 only" and "*XLEN=32 only" #903

Open liweiwei90 opened 1 year ago

liweiwei90 commented 1 year ago

In current privilege spec, most upper half CSRs are described as "RV32 only". But htimedeltah is described as "HSXLEN=32 only", and mseccfgh is described as "RV32 only" and "MXLEN=32 only" in two different position(Table 2.5 and section 3.1.19).

Does "RV32 only" mean "MXLEN=32 only" or "*XLEN=32 only" based on privilege mode of the CSRs?

If so, how about "RV32 only" instructions?

aswaterman commented 1 year ago

In the unprivileged spec, "XLEN=32 only" and "RV32 only" mean the same thing.

HSXLEN=32 means something more specific: it means RV32 is the selected mode within HS-mode. (Recall that different modes can have different XLEN.)

liweiwei90 commented 1 year ago

@aswaterman Thanks for your explanation. However, I still have some question:

aswaterman commented 1 year ago

@jhauser-us should confirm my answers, but I think that:

liweiwei90 commented 1 year ago
  • The currently active XLEN is the one that matters, so HSXLEN is not relevant in M-mode. The full henvcfg is accessed, and henvcfgh is illegal.

However, the length of henvcfg is stated as HSXLEN in the spec.

jhauser-us commented 1 year ago

@liweiwei90: Thanks for raising this issue. I'm sorry the issue has languished for so long without a proper resolution. The Architecture Review Committee discussed the matter earlier this week and is working to provide a clarification/correction soon for Privileged ISA version 1.13.

In 1.13, CSRs henvcfg and htimedelta will be described as always being 64-bit, even for RV32. Also, the high-half CSRs henvcfgh and htimedeltah will exist only for RV32 code (that is, only when the current XLEN = 32). With these fixes, it should become clear that accesses to these CSRs will work the same way that accesses to 64-bit unprivileged counters do (time/timeh, cycle/cycleh, etc.).

liweiwei90 commented 1 year ago

Thanks for your clarification. If henvcfgh/htimedeltah will exist only when the current XLEN == 32 instead of HSXLEN == 32, do you mean the length of other *XLEN CSRs will also be current XLEN? Or this is only suitable to the always 64-bit CSRs?

jhauser-us commented 1 year ago

do you mean the length of other XLEN CSRs will also be current* XLEN?

No.

Or this is only suitable to the always 64-bit CSRs?

For CSRs that are always 64-bit (like henvcfg), high-half CSRs (like henvcfgh) will be accessible only when the current XLEN = 32, i.e., only for RV32 code.

liweiwei90 commented 1 year ago

OK. Thanks.

jhauser-us commented 1 year ago

Should be addressed by commit f0f67a2.