Skip to content

Commit 52fe009

Browse files
committed
Fix illegal instruction handling for SLLI, SRLI, and SRAI
According to the RISC-V specification, specifically for RV32I, instructions like SLLI, SRLI, and SRAI should generate an illegal instruction exception if the imm[5] bit is not zero. However, the current implementation does not handle this error condition. Addresse the issue by adding proper handling for illegal instruction exceptions in cases where imm[5] is non-zero for SLLI, SRLI, and SRAI instructions.
1 parent 50b8a07 commit 52fe009

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/decode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ static inline bool op_op_imm(rv_insn_t *ir, const uint32_t insn)
465465
break;
466466
case 1: /* SLLI: Shift Left Logical */
467467
ir->opcode = rv_insn_slli;
468+
if (unlikely(ir->imm & (1 << 5)))
469+
return false;
468470
break;
469471
case 2: /* SLTI: Set on Less Than Immediate */
470472
ir->opcode = rv_insn_slti;
@@ -482,6 +484,8 @@ static inline bool op_op_imm(rv_insn_t *ir, const uint32_t insn)
482484
ir->opcode = (ir->imm & ~0x1f)
483485
? rv_insn_srai /* SRAI: Shift Right Arithmetic */
484486
: rv_insn_srli; /* SRLI: Shift Right Logical */
487+
if (unlikely(ir->imm & (1 << 5)))
488+
return false;
485489
break;
486490
case 6: /* ORI: OR Immediate */
487491
ir->opcode = rv_insn_ori;

0 commit comments

Comments
 (0)