aboutsummaryrefslogtreecommitdiff
path: root/machine/misaligned_ldst.c
diff options
context:
space:
mode:
Diffstat (limited to 'machine/misaligned_ldst.c')
-rw-r--r--machine/misaligned_ldst.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/machine/misaligned_ldst.c b/machine/misaligned_ldst.c
index 8c96c18..2fccd50 100644
--- a/machine/misaligned_ldst.c
+++ b/machine/misaligned_ldst.c
@@ -3,6 +3,7 @@
#include "unprivileged_memory.h"
#include "mtrap.h"
#include "config.h"
+#include "pk.h"
union byte_array {
uint8_t bytes[8];
@@ -15,6 +16,7 @@ void misaligned_load_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
union byte_array val;
uintptr_t mstatus;
insn_t insn = get_insn(mepc, &mstatus);
+ uintptr_t npc = mepc + insn_len(insn);
uintptr_t addr = read_csr(mbadaddr);
int shift = 0, fp = 0, len;
@@ -74,7 +76,7 @@ void misaligned_load_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
else
SET_F32_RD(insn, regs, val.intx);
- write_csr(mepc, mepc + 4);
+ write_csr(mepc, npc);
}
void misaligned_store_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
@@ -82,6 +84,7 @@ void misaligned_store_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
union byte_array val;
uintptr_t mstatus;
insn_t insn = get_insn(mepc, &mstatus);
+ uintptr_t npc = mepc + insn_len(insn);
int len;
val.intx = GET_RS2(insn, regs);
@@ -130,5 +133,5 @@ void misaligned_store_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
for (int i = 0; i < len; i++)
store_uint8_t((void *)(addr + i), val.bytes[i], mepc);
- write_csr(mepc, mepc + 4);
+ write_csr(mepc, npc);
}