From 8ac3c95bfb03de4abbcca4d639056894a5e2df7f Mon Sep 17 00:00:00 2001 From: ChinYikMing Date: Sun, 21 Jul 2024 23:05:46 +0800 Subject: [PATCH] Add Wait for Interrupt instruction (WFI) The Wait for Interrupt instruction (WFI) provides a hint to the implementation that the current hart can be stalled until an interrupt might need servicing. As well, Linux kernel might call wait_for_interrupt() to enter idle state. In this commit, we could simply make PC + 4 and not really enter idle state. Related: #310 --- src/decode.c | 2 ++ src/rv32_template.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/decode.c b/src/decode.c index 71990cc9..c434b0fa 100644 --- a/src/decode.c +++ b/src/decode.c @@ -835,6 +835,8 @@ static inline bool op_system(rv_insn_t *ir, const uint32_t insn) ir->opcode = rv_insn_ebreak; break; case 0x105: /* WFI: Wait for Interrupt */ + ir->opcode = rv_insn_wfi; + break; case 0x002: /* URET: return from traps in U-mode */ case 0x202: /* HRET: return from traps in H-mode */ /* illegal instruction */ diff --git a/src/rv32_template.c b/src/rv32_template.c index 03a1273c..edd717c2 100644 --- a/src/rv32_template.c +++ b/src/rv32_template.c @@ -982,8 +982,9 @@ RVOP( RVOP( wfi, { + PC += 4; /* FIXME: Implement */ - return false; + goto end_op; }, GEN({ assert; /* FIXME: Implement */