Skip to content

Commit

Permalink
Misc changes
Browse files Browse the repository at this point in the history
- add assertion before get_ppn_and_offset()
- RVOP should return false once block map has been cleared otherwise
  invalid previous block will be used
- The prev block might be invalid after __trap_handler(). To prevent
  that, simply set prev to NULL
  • Loading branch information
ChinYikMing committed Dec 8, 2024
1 parent 29a45bd commit 4ef0ff4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ static uint32_t peripheral_update_ctr = 64;
, if (unlikely(need_clear_block_map)) { \
block_map_clear(rv); \
need_clear_block_map = false; \
goto end_op; \
rv->csr_cycle = cycle; \
rv->PC = PC; \
return false; \
}), ); \
if (unlikely(RVOP_NO_NEXT(ir))) \
goto end_op; \
Expand Down Expand Up @@ -561,6 +563,7 @@ FORCE_INLINE bool insn_is_unconditional_branch(uint8_t opcode)
case rv_insn_jal:
case rv_insn_jalr:
case rv_insn_mret:
case rv_insn_csrrw:
#if RV32_HAS(SYSTEM)
case rv_insn_sret:
#endif
Expand Down Expand Up @@ -1138,6 +1141,8 @@ static void __trap_handler(riscv_t *rv)
rv->compressed = is_compressed(insn);
ir->impl(rv, ir, rv->csr_cycle, rv->PC);
}

prev = NULL;
}
#endif /* RV32_HAS(SYSTEM) */

Expand Down
3 changes: 3 additions & 0 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#error "Do not manage to build this file unless you enable system support."
#endif

#include <assert.h>

#include "devices/plic.h"
#include "devices/uart.h"
#include "riscv_private.h"
Expand Down Expand Up @@ -234,6 +236,7 @@ MMU_FAULT_CHECK_IMPL(write, pagefault_store)
uint32_t ppn; \
uint32_t offset; \
do { \
assert(pte); \
ppn = *pte >> (RV_PG_SHIFT - 2) << RV_PG_SHIFT; \
offset = level == 1 ? addr & MASK((RV_PG_SHIFT + 10)) \
: addr & MASK(RV_PG_SHIFT); \
Expand Down

0 comments on commit 4ef0ff4

Please sign in to comment.