Skip to content

Commit

Permalink
Allow CSRRS/C to read CLEN-wide values
Browse files Browse the repository at this point in the history
  • Loading branch information
andresag01 committed Feb 12, 2024
1 parent fb9489c commit 28d3162
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
30 changes: 19 additions & 11 deletions src/insns/csrr_32bit.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,33 @@ endif::[]
Synopsis::
CSR access (CSRRWI, CSRRS, CSRRSI, CSRRC, CSRRCI) 32-bit encodings

Register Source Mnemonics::
`csrr[s|c] rd, rs1, csr`

Immediate Source Mnemonics::
`csrr[w|s|c]i rd, imm, csr`
Mnemonics for accessing capability CSRs at CLEN-wide aliases::
`csrrs cd, rs1, csr` +
`csrrc cd, rs1, csr` +
`csrrwi cd, imm, csr` +
`csrrsi cd, imm, csr` +
`csrrci cd, imm, csr`

Mnemonics for accessing XLEN-wide CSRs or capability CSRs at XLEN-wide aliases::
`csrrs rd, rs1, csr` +
`csrrc rd, rs1, csr` +
`csrrwi rd, imm, csr` +
`csrrsi rd, imm, csr` +
`csrrci rd, imm, csr`

Encoding::
include::wavedrom/csr-instr.adoc[]

Description::
These are standard RISC-V CSR instructions with extended functionality for
accessing CLEN-wide CSRs, such as <<mtvec>>/<<mtvecc>> which can be
accessing CLEN-wide CSRs, such as <<mtvec>>/<<mtvecc>>, which can be
accessed through either the RISC-V address or the capability address alias.
+
Unlike <<CSRRW>> these instruction perform the same update to CLEN-wide CSRs
to either the XLEN or CLEN-wide alias as they only every perform an XLEN-wide update.
Where a CLEN-wide CSR is updated, through either alias, the final address is determined
as defined by RISC-V for these instructions. The metadata and tag are updated
as defined in xref:extended_CSR_writing[xrefstyle=short].
Unlike <<CSRRW>>, these instructions only update the address field when writing
capability CSRs regardless of the CSR's alias used. The final address to write
to the capability CSR is determined as defined by RISC-V for these
instructions. The metadata and tag are updated as defined in
xref:extended_CSR_writing[xrefstyle=short].
+
See xref:aliased_CSRs[xrefstyle=short] for a list of CLEN-wide CSRs and
xref:extended_CSR_writing[xrefstyle=short] for the action taken on writing an XLEN-wide value to each one.
Expand Down
10 changes: 5 additions & 5 deletions src/insns/csrrw_32bit.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ endif::[]
Synopsis::
CSR access (CSRRW) 32-bit encodings

Mnemonic (XLEN-wide target, and XLEN-wide aliases of CLEN-wide CSRs)::
`csrrw rd, rs1, csr`

Mnemonics (CLEN-wide target)::
Mnemonics for accessing capability CSRs at CLEN-wide aliases::
`csrrw cd, cs1, csr`

Mnemonics for accessing XLEN-wide CSRs or capability CSRs at XLEN-wide aliases::
`csrrw rd, rs1, csr`

Encoding::
include::wavedrom/csrw-instr.adoc[]

Description::
This is a standard RISC-V CSR instructions with extended functionality for
accessing CLEN-wide CSRs, such as <<mtvec>>/<<mtvecc>> which can be
accessing CLEN-wide CSRs, such as <<mtvec>>/<<mtvecc>>, which can be
accessed through either the RISC-V address or the capability address alias.
+
See xref:aliased_CSRs[xrefstyle=short] for a list of CLEN-wide CSRs and
Expand Down
20 changes: 13 additions & 7 deletions src/riscv-integration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,21 @@ whole CSR with the CLEN width register operand.

There are special rules for updating specific CLEN-wide CSRs as shown in <<extended_CSR_writing>>.

{non-csrrw-and} specify *x* registers and so only access the address field
of the capability when specifying a capability CSR such as <<mtvecc>>.
They calculate the final address using the standard
RISC-V behaviour (set bits, clear bits etc.) and that final address is
updated in the capability. The update typically uses the semantics of a <<CSETADDR>>
instruction which clears the tag if the capability is sealed, or if the
updated address is not representable. <<extended_CSR_writing>> shows the
When <<CSRRS>> and <<CSRRC>> instructions are accessing a capability width CSR,
such as <<mtvecc>>, then the destination operand is a *c* register and the
source operand is an *x* register. Therefore, the instructions atomically read
CLEN bits from the CSR, calculate the final address using standard RISC-V
behaviour (set bits, clear bits, etc), and that final address is written to the
CSR capability's address field. The update typically uses the semantics of a
<<CSETADDR>> instruction which clears the tag if the capability is sealed, or
if the updated address is not representable. <<extended_CSR_writing>> shows the
exact action taken for each capability width CSR.

The <<CSRRWI>>, <<CSRRSI>> and <<CSRRCI>> variants are similar to <<CSRRW>>,
<<CSRRS>>, and <<CSRRC>> respectively, when accessing a capability width CSR
except that they update the capability's address only using an XLEN-bit value
obtained by zero-extending a 5-bit unsigned immediate field.

All CSR instructions cause CHERI exceptions if the <<pcc>> does not grant
<<asr_perm>> and the CSR accessed is privileged.

Expand Down

0 comments on commit 28d3162

Please sign in to comment.