On misaligned fetch, set EPC to target, not branch itself
authorAndrew Waterman <aswaterman@gmail.com>
Sat, 3 Jan 2015 01:29:05 +0000 (17:29 -0800)
committerAndrew Waterman <aswaterman@gmail.com>
Sat, 3 Jan 2015 01:29:05 +0000 (17:29 -0800)
riscv/decode.h
riscv/insns/jal.h
riscv/insns/jalr.h
riscv/mmu.h

index b325c5909357819d89cb3fa2f4f2e8c1e2ae9679..6d1ffbe1f5286f93921c775d58dfa8a9789e4f27 100644 (file)
@@ -155,11 +155,7 @@ private:
    ((x) & 0x3f) < 0x3f ? 6 : \
    8)
 
-#define set_pc(x) \
-  do { if ((x) & 3 /* For now... */) \
-         throw trap_instruction_address_misaligned(x); \
-       npc = sext_xprlen(x); \
-     } while(0)
+#define set_pc(x) (npc = sext_xprlen(x))
 
 #define validate_csr(which, write) ({ \
   unsigned my_priv = (STATE.sr & SR_S) ? 1 : 0; \
index 2694deef1c7394c969283afea3f55340dd3dd868..cd599641e21553a9d064199b47774032e3c6042b 100644 (file)
@@ -1,2 +1,3 @@
-WRITE_RD(npc);
+reg_t tmp = npc;
 set_pc(JUMP_TARGET);
+WRITE_RD(tmp);
index 3924aa45f3cf54536d6c292acd1cec22a950eb3d..386e8db1f569793e2ba3cba20da2020ca183cede 100644 (file)
@@ -1,3 +1,3 @@
-reg_t temp = RS1;
-WRITE_RD(npc);
-set_pc((temp + insn.i_imm()) & ~1);
+reg_t tmp = npc;
+set_pc((RS1 + insn.i_imm()) & ~reg_t(1));
+WRITE_RD(tmp);
index 08d41be012b52fda13b5b46e9437da91b90d775d..d24ed187bf30e1f868c8a059c133b771c39e9b46 100644 (file)
@@ -167,7 +167,9 @@ private:
     void* data = tlb_data[idx] + addr;
 
     if (unlikely(addr & (bytes-1)))
-      store ? throw trap_store_address_misaligned(addr) : throw trap_load_address_misaligned(addr);
+      store ? throw trap_store_address_misaligned(addr) :
+      fetch ? throw trap_instruction_address_misaligned(addr) :
+      throw trap_load_address_misaligned(addr);
 
     if (likely(tag == expected_tag))
       return data;