]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
sh: Fix PC adjustments for varying opcode length.
authorPaul Mundt <lethal@linux-sh.org>
Tue, 8 May 2007 06:31:48 +0000 (15:31 +0900)
committerPaul Mundt <lethal@hera.kernel.org>
Wed, 9 May 2007 01:35:01 +0000 (01:35 +0000)
There are a few different cases for figuring out how to
size the instruction. We read in the instruction located
at regs->pc - 4 when rewinding the opcode to figure out if
there's a 32-bit opcode before the faulting instruction, with
a default of a - 2 adjustment on a mismatch. In practice this
works for the cases where pc - 4 is just another 16-bit opcode,
or we happen to have a 32-bit and a 16-bit immediately
preceeding the pc value.

In the cases where we aren't rewinding, this is much less ugly..

We also don't bother fixing up the places where we're explicitly
dealing with 16-bit instructions, since this might lead to
confusion regarding the encoding size possibilities on other
CPU variants.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/kernel/cpu/sh4/fpu.c
arch/sh/kernel/kgdb_stub.c
arch/sh/kernel/process.c
arch/sh/kernel/signal.c
arch/sh/kernel/traps.c

index 7624677f66281e7ef31b99d9b48caf1bc7534b5d..d61dd599169f97b0acb1f42fc9b19acc2dd26835 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/sched.h>
 #include <linux/signal.h>
 #include <asm/processor.h>
+#include <asm/system.h>
 #include <asm/io.h>
 
 /* The PR (precision) bit in the FP Status Register must be clear when
@@ -265,7 +266,7 @@ ieee_fpe_handler (struct pt_regs *regs)
                nextpc = regs->pr;
                finsn = *(unsigned short *) (regs->pc + 2);
        } else {
-               nextpc = regs->pc + 2;
+               nextpc = regs->pc + instruction_size(insn);
                finsn = insn;
        }
 
index ffe3e3ee580d6bf85bff97a9bf21ecee850a2a14..a5323364cbca7c7c884d9c407ce02d7c777d9511 100644 (file)
@@ -867,7 +867,7 @@ static void kgdb_command_loop(const int excep_code, const int trapa_value)
           trap 0xff, since that indicates a compiled-in breakpoint which
           will not be replaced (and we would retake the trap forever) */
        if ((excep_code == TRAP_VEC) && (trapa_value != (0x3c << 2)))
-               trap_registers.pc -= instruction_size(trap_registers.pc);
+               trap_registers.pc -= 2;
 
        /* Undo any stepping we may have done */
        undo_single_step();
index 209cc9b42186cee0537de22c70b85811a699cd18..9005b2f12aaa1ec885bb70962ea07203e3a21c0e 100644 (file)
@@ -498,7 +498,7 @@ asmlinkage void debug_trap_handler(unsigned long r4, unsigned long r5,
        struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
 
        /* Rewind */
-       regs->pc -= instruction_size(regs->pc);
+       regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
 
        if (notify_die(DIE_TRAP, regs, regs->tra & 0xff,
                       SIGTRAP) == NOTIFY_STOP)
@@ -517,7 +517,7 @@ asmlinkage void bug_trap_handler(unsigned long r4, unsigned long r5,
        struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
 
        /* Rewind */
-       regs->pc -= instruction_size(regs->pc);
+       regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
 
        if (notify_die(DIE_TRAP, regs, TRAPA_BUG_OPCODE & 0xff,
                       SIGTRAP) == NOTIFY_STOP)
index d7d98d691c64f38c2aa4909998a4dcdf50ff232c..b32c35a7c0a3e42512765962e8b71c0c1096a5c8 100644 (file)
@@ -500,7 +500,9 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
                                }
                        /* fallthrough */
                        case -ERESTARTNOINTR:
-                               regs->pc -= instruction_size(regs->pc);
+                               regs->pc -= instruction_size(
+                                               ctrl_inw(regs->pc - 4));
+                               break;
                }
        } else {
                /* gUSA handling */
@@ -516,7 +518,8 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
                        regs->regs[15] = regs->regs[1];
                        if (regs->pc < regs->regs[0])
                                /* Go to rewind point #1 */
-                               regs->pc = regs->regs[0] + offset - 2;
+                               regs->pc = regs->regs[0] + offset -
+                                       instruction_size(ctrl_inw(regs->pc-4));
                }
 #ifdef CONFIG_PREEMPT
                local_irq_restore(flags);
@@ -600,9 +603,9 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
                    regs->regs[0] == -ERESTARTSYS ||
                    regs->regs[0] == -ERESTARTNOINTR) {
                        regs->regs[0] = save_r0;
-                       regs->pc -= instruction_size(regs->pc);
+                       regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
                } else if (regs->regs[0] == -ERESTART_RESTARTBLOCK) {
-                       regs->pc -= instruction_size(regs->pc);
+                       regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
                        regs->regs[3] = __NR_restart_syscall;
                }
        }
index 7b40f0ff3dfc8701a8121dfddaaf3f9044db97c0..1446d12ba220cb7e6c6b60c2d8f3397f7ffd6db6 100644 (file)
@@ -505,7 +505,7 @@ static int handle_unaligned_access(u16 instruction, struct pt_regs *regs)
  simple:
        ret = handle_unaligned_ins(instruction,regs);
        if (ret==0)
-               regs->pc += 2;
+               regs->pc += instruction_size(instruction);
        return ret;
 }
 #endif /* CONFIG_CPU_SH2A */
@@ -682,7 +682,7 @@ asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5,
 
        err = do_fpu_inst(inst, regs);
        if (!err) {
-               regs->pc += 2;
+               regs->pc += instruction_size(inst);
                return;
        }
        /* not a FPU inst. */