Skip to content

Commit

Permalink
Merge pull request #1256 from riscv/csr-fix
Browse files Browse the repository at this point in the history
Clarify behavior of CSR access side effects
  • Loading branch information
aswaterman committed Mar 12, 2024
2 parents 6f6c947 + c0e3faa commit 157641b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/zicsr.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ of the CSR, zero-extends the value to XLEN bits, and writes it to
integer register _rd_. The initial value in integer register _rs1_ is
treated as a bit mask that specifies bit positions to be set in the CSR.
Any bit that is high in _rs1_ will cause the corresponding bit to be set
in the CSR, if that CSR bit is writable. Other bits in the CSR are not
explicitly written.
in the CSR, if that CSR bit is writable.

The CSRRC (Atomic Read and Clear Bits in CSR) instruction reads the
value of the CSR, zero-extends the value to XLEN bits, and writes it to
integer register _rd_. The initial value in integer register _rs1_ is
treated as a bit mask that specifies bit positions to be cleared in the
CSR. Any bit that is high in _rs1_ will cause the corresponding bit to
be cleared in the CSR, if that CSR bit is writable. Other bits in the
CSR are not explicitly written.
be cleared in the CSR, if that CSR bit is writable.

For both CSRRS and CSRRC, if _rs1_=`x0`, then the instruction will not
write to the CSR at all, and so shall not cause any of the side effects
Expand Down Expand Up @@ -105,6 +103,19 @@ CSR
<<csrsideeffects>> summarizes the behavior of the CSR
instructions with respect to whether they read and/or write the CSR.

In addition to side effects that occur as a consequence of reading or
writing a CSR, individual fields within a CSR might have side effects
when written. The CSRRW[I] instructions action side effects for all
such fields within the written CSR. The CSRRS[I] an CSRRC[I] instructions
only action side effects for fields for which the _rs1_ or _uimm_ argument
has at least one bit set corresponding to that field.
[NOTE]
====
As of this writing, no standard CSRs have side effects on field writes.
Hence, whether a standard CSR access has any side effects can be determined
solely from the opcode.
====

For any event or consequence that occurs due to a CSR having a
particular value, if a write to the CSR gives it that value, the
resulting event or consequence is said to be an _indirect effect_ of the
Expand Down

0 comments on commit 157641b

Please sign in to comment.