Skip to content

Commit

Permalink
Fix CSRRWI instruction behavior according to RISC-V spec
Browse files Browse the repository at this point in the history
Refer to RISC-V Unprivileged ISA Version 20191213 9.1 CSR Instructions

----------------------------------------------------------------------
| 31                 20|19       15|14       12|11       7|6        0|
|         csr          |    rs1    |   funct3  |    rd    |  opcode  |
|     source/dest      | uimm[4:0] |   CSRRWI  |   dest   |  SYSTEM  |
----------------------------------------------------------------------

CSRRWI behavior likes below and it needs to work atomically

x[rd] = CSRs[csr]; CSRs[csr] = uimm

The uimm is equal to rs1's index, instead of rs1's register value

Close sysprog21#7
  • Loading branch information
feathertw committed Jan 6, 2022
1 parent fa38fc5 commit 54061df
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ static bool op_system(struct riscv_t *rv, uint32_t inst)
break;
}
case 5: { // CSRRWI
uint32_t tmp = csr_csrrc(rv, csr, rv->X[rs1]);
uint32_t tmp = csr_csrrw(rv, csr, rs1);
rv->X[rd] = rd ? tmp : rv->X[rd];
break;
}
Expand Down

0 comments on commit 54061df

Please sign in to comment.