Skip to content

Commit 037f5ad

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 037f5ad

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/decode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ static inline bool op_system(rv_insn_t *ir, const uint32_t insn)
827827
case 0x105: /* WFI: Wait for Interrupt */
828828
case 0x002: /* URET: return from traps in U-mode */
829829
case 0x102: /* SRET: return from traps in S-mode */
830+
ir->opcode = rv_insn_sret;
831+
break;
830832
case 0x202: /* HRET: return from traps in H-mode */
831833
/* illegal instruciton */
832834
return false;

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)