Skip to content

Commit

Permalink
Specify can_branch and decode the sret instruction
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ChinYikMing committed May 26, 2024
1 parent 69fae57 commit 33e5068
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,8 @@ static inline bool op_system(rv_insn_t *ir, const uint32_t insn)
case 0x105: /* WFI: Wait for Interrupt */
case 0x002: /* URET: return from traps in U-mode */
case 0x102: /* SRET: return from traps in S-mode */
ir->opcode = rv_insn_sret;
break;
case 0x202: /* HRET: return from traps in H-mode */
/* illegal instruciton */
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum op_field {
/* RISC-V Privileged Instruction */ \
_(wfi, 0, 4, 0, ENC(rs1, rd)) \
_(uret, 0, 4, 0, ENC(rs1, rd)) \
_(sret, 0, 4, 0, ENC(rs1, rd)) \
_(sret, 1, 4, 0, ENC(rs1, rd)) \
_(hret, 0, 4, 0, ENC(rs1, rd)) \
_(mret, 1, 4, 0, ENC(rs1, rd)) \
/* RV32 Zifencei Standard Extension */ \
Expand Down

0 comments on commit 33e5068

Please sign in to comment.