Atomic Read/Write CSR Immediate
Atomically write CSR using a 5-bit immediate, and load the previous value into 'xd'.
Read the old value of the CSR, zero-extends the value to `XLEN` bits, and then write it to integer register xd. The 5-bit uimm field is zero-extended and 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.
csrrwi xd, csr, imm
| 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 | imm | 1 | 0 | 1 | xd | 111 | 00 | 11 | |||||||||||||||||||||||
| Variable | Bits | Width |
|---|---|---|
csr | [31:20] | 12 |
imm | [19:15] | 5 |
xd | [11:7] | 5 |
Csr csr_handle = direct_csr_lookup(csr);
# 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 zero-extended immediate to the CSR,
# performing any WARL transformations first
csr_sw_write(csr_handle, {{MXLEN-5{1'b0}}, imm});
Zicsr
| S | U | VS | VU |
|---|---|---|---|
| Always | Always | Always | Always |
| When | Use |
|---|---|
| xd == 0 | csrwi csr, imm |
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.