Skip to contentSkip to conversation

target-openrisc: Correct wrong epcr register in interrupt handler

PATCH New Sebastian Macke 1 participant 1 message Oct 19, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 target-openrisc: Correct wrong epcr register in interrupt handler

This patch corrects several rare bugs during an interrupt process.
Most of the time the pc is already correct and therefore no special treatment of the exception type is necessary.

Tested by checking crashing programs which otherwise work in or1ksim.

---
 target-openrisc/interrupt.c |   25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
target-openrisc/interrupt.c +7 -18
index 16ef4b3..2153e7e 100644
@@ -30,26 +30,15 @@ void openrisc_cpu_do_interrupt(CPUState *cs)
     OpenRISCCPU *cpu = OPENRISC_CPU(cs);
     CPUOpenRISCState *env = &cpu->env;
 #ifndef CONFIG_USER_ONLY
-    if (env->flags & D_FLAG) { /* Delay Slot insn */
+
+    env->epcr = env->pc;
+    if (env->flags & D_FLAG) {
         env->flags &= ~D_FLAG;
         env->sr |= SR_DSX;
-        if (env->exception_index == EXCP_TICK    ||
-            env->exception_index == EXCP_INT     ||
-            env->exception_index == EXCP_SYSCALL ||
-            env->exception_index == EXCP_FPE) {
-            env->epcr = env->jmp_pc;
-        } else {
-            env->epcr = env->pc - 4;
-        }
-    } else {
-        if (env->exception_index == EXCP_TICK    ||
-            env->exception_index == EXCP_INT     ||
-            env->exception_index == EXCP_SYSCALL ||
-            env->exception_index == EXCP_FPE) {
-            env->epcr = env->npc;
-        } else {
-            env->epcr = env->pc;
-        }
+        env->epcr -= 4;
+    }
+    if (env->exception_index == EXCP_SYSCALL) {
+        env->epcr += 4;
     }
      /* For machine-state changed between user-mode and supervisor mode,
Signature · 1 line
1.7.9.5