From 4dd429865bf3864a70fe48c755c9ae91dd86a482 Mon Sep 17 00:00:00 2001 From: RinHizakura Date: Mon, 22 Aug 2022 20:12:29 +0800 Subject: [PATCH] Fix set PC restriction when RV32C is enabled --- elf.c | 4 +++- emulate.c | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/elf.c b/elf.c index 479d79028..5e7d4e2fc 100644 --- a/elf.c +++ b/elf.c @@ -300,7 +300,9 @@ bool elf_get_data_section_range(elf_t *e, uint32_t *start, uint32_t *end) bool elf_load(elf_t *e, struct riscv_t *rv, memory_t *mem) { - rv_set_pc(rv, e->hdr->e_entry); /* set the entry point */ + /* set the entry point */ + if (!rv_set_pc(rv, e->hdr->e_entry)) + return false; /* loop over all of the program headers */ for (int p = 0; p < e->hdr->e_phnum; ++p) { diff --git a/emulate.c b/emulate.c index 527a38392..26720915f 100644 --- a/emulate.c +++ b/emulate.c @@ -1851,7 +1851,11 @@ riscv_user_t rv_userdata(struct riscv_t *rv) bool rv_set_pc(struct riscv_t *rv, riscv_word_t pc) { assert(rv); +#ifdef ENABLE_RV32C + if (pc & 1) +#else if (pc & 3) +#endif return false; rv->PC = pc;