Atomic Read/Write CSR
Atomically swap values in the CSRs and integer registers.
Read the old value of the CSR, zero-extends the value to `XLEN` bits, and then write it to integer register xd. The initial value in xs1 is written to the CSR. If `xd=x0`, then the instruction shall not read the CSR and shall not cause any of the side effects that might occur on a CSR read.
csrrw xd, csr, xs1
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| csr | xs1 | 00 | 1 | xd | 111 | 00 | 11 | ||||||||||||||||||||||||
| Variable | Bits | Width |
|---|---|---|
csr | [31:20] | 12 |
xs1 | [19:15] | 5 |
xd | [11:7] | 5 |
Csr csr_handle = direct_csr_lookup(csr);
Bits<MXLEN> initial_value = X[xs1];
# permission checks
if (csr_handle.valid == false) {
unimplemented_csr($encoding);
} else if (!compatible_mode?(csr_handle.mode, mode())) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
} else if (csr_handle.writable == false) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}
if (xd != 0) {
X[xd] = csr_sw_read(csr_handle);
}
# writes the value in X[xs1] to the CSR,
# performing any WARL transformations first
csr_sw_write(csr_handle, initial_value);
Zicsr
| S | U | VS | VU |
|---|---|---|---|
| Always | Always | Always | Always |
| When | Use |
|---|---|
| xd == 0 && csr == 0x001 | fsflags xs1 |
| xd == 0 && csr == 0x002 | fsrm xs1 |
| xd == 0 && csr == 0x003 | fscsr xs1 |
| csr == 0x001 | fsflags xd, xs1 |
| csr == 0x002 | fsrm xd, xs1 |
| csr == 0x003 | fscsr xd, xs1 |
| xd == 0 | csrw csr, xs1 |
Version af3eaf9+cheriot.f635218
Data from the RISC-V Unified Database, copyright RISC-V International and contributors.
CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.
This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.