Skip to content

Commit 6f8864b

Browse files
committed
Specify can_branch and decode the sret instruction
sret instruction is used for returning from a trap when trap occurs in S-mode level. Thus, the execution flow will not be sequential. During basic block translation, the sret instruction should be considered as can_branch instruction. Moreover, the existing system instruction decoder does not support decoding the sret instruction. Thus, the ir->opcode should be set correctly to support decoding the sret instruction. The implementation of sret instruction is simply returning false for now, the improved implementation will be completed and tested in #438 since the sret instruction involves privilege mode changing.
1 parent 69fae57 commit 6f8864b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/decode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,12 @@ static inline bool op_system(rv_insn_t *ir, const uint32_t insn)
826826
break;
827827
case 0x105: /* WFI: Wait for Interrupt */
828828
case 0x002: /* URET: return from traps in U-mode */
829-
case 0x102: /* SRET: return from traps in S-mode */
830829
case 0x202: /* HRET: return from traps in H-mode */
831-
/* illegal instruciton */
830+
/* illegal instruction */
832831
return false;
832+
case 0x102: /* SRET: return from traps in S-mode */
833+
ir->opcode = rv_insn_sret;
834+
break;
833835
case 0x302: /* MRET */
834836
ir->opcode = rv_insn_mret;
835837
break;

src/decode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ enum op_field {
7777
/* RISC-V Privileged Instruction */ \
7878
_(wfi, 0, 4, 0, ENC(rs1, rd)) \
7979
_(uret, 0, 4, 0, ENC(rs1, rd)) \
80-
_(sret, 0, 4, 0, ENC(rs1, rd)) \
80+
_(sret, 1, 4, 0, ENC(rs1, rd)) \
8181
_(hret, 0, 4, 0, ENC(rs1, rd)) \
8282
_(mret, 1, 4, 0, ENC(rs1, rd)) \
8383
/* RV32 Zifencei Standard Extension */ \

0 commit comments

Comments
 (0)