aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2007-05-08 02:31:48 -0400
committerPaul Mundt <lethal@hera.kernel.org>2007-05-08 21:35:01 -0400
commit53f983a90d7908bcece51f86180c7c9b575a1e4d (patch)
treeda5914e6f18e8dd55563697de7339af2d99d9c18
parentbd0799977cb9b68aa6a39e9630aeea4778a58385 (diff)
sh: Fix PC adjustments for varying opcode length.
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>
-rw-r--r--arch/sh/kernel/cpu/sh4/fpu.c3
-rw-r--r--arch/sh/kernel/kgdb_stub.c2
-rw-r--r--arch/sh/kernel/process.c4
-rw-r--r--arch/sh/kernel/signal.c11
-rw-r--r--arch/sh/kernel/traps.c4
5 files changed, 14 insertions, 10 deletions
diff --git a/arch/sh/kernel/cpu/sh4/fpu.c b/arch/sh/kernel/cpu/sh4/fpu.c
index 7624677f6628..d61dd599169f 100644
--- a/arch/sh/kernel/cpu/sh4/fpu.c
+++ b/arch/sh/kernel/cpu/sh4/fpu.c
@@ -16,6 +16,7 @@
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/signal.h> 17#include <linux/signal.h>
18#include <asm/processor.h> 18#include <asm/processor.h>
19#include <asm/system.h>
19#include <asm/io.h> 20#include <asm/io.h>
20 21
21/* The PR (precision) bit in the FP Status Register must be clear when 22/* The PR (precision) bit in the FP Status Register must be clear when
@@ -265,7 +266,7 @@ ieee_fpe_handler (struct pt_regs *regs)
265 nextpc = regs->pr; 266 nextpc = regs->pr;
266 finsn = *(unsigned short *) (regs->pc + 2); 267 finsn = *(unsigned short *) (regs->pc + 2);
267 } else { 268 } else {
268 nextpc = regs->pc + 2; 269 nextpc = regs->pc + instruction_size(insn);
269 finsn = insn; 270 finsn = insn;
270 } 271 }
271 272
diff --git a/arch/sh/kernel/kgdb_stub.c b/arch/sh/kernel/kgdb_stub.c
index ffe3e3ee580d..a5323364cbca 100644
--- a/arch/sh/kernel/kgdb_stub.c
+++ b/arch/sh/kernel/kgdb_stub.c
@@ -867,7 +867,7 @@ static void kgdb_command_loop(const int excep_code, const int trapa_value)
867 trap 0xff, since that indicates a compiled-in breakpoint which 867 trap 0xff, since that indicates a compiled-in breakpoint which
868 will not be replaced (and we would retake the trap forever) */ 868 will not be replaced (and we would retake the trap forever) */
869 if ((excep_code == TRAP_VEC) && (trapa_value != (0x3c << 2))) 869 if ((excep_code == TRAP_VEC) && (trapa_value != (0x3c << 2)))
870 trap_registers.pc -= instruction_size(trap_registers.pc); 870 trap_registers.pc -= 2;
871 871
872 /* Undo any stepping we may have done */ 872 /* Undo any stepping we may have done */
873 undo_single_step(); 873 undo_single_step();
diff --git a/arch/sh/kernel/process.c b/arch/sh/kernel/process.c
index 209cc9b42186..9005b2f12aaa 100644
--- a/arch/sh/kernel/process.c
+++ b/arch/sh/kernel/process.c
@@ -498,7 +498,7 @@ asmlinkage void debug_trap_handler(unsigned long r4, unsigned long r5,
498 struct pt_regs *regs = RELOC_HIDE(&__regs, 0); 498 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
499 499
500 /* Rewind */ 500 /* Rewind */
501 regs->pc -= instruction_size(regs->pc); 501 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
502 502
503 if (notify_die(DIE_TRAP, regs, regs->tra & 0xff, 503 if (notify_die(DIE_TRAP, regs, regs->tra & 0xff,
504 SIGTRAP) == NOTIFY_STOP) 504 SIGTRAP) == NOTIFY_STOP)
@@ -517,7 +517,7 @@ asmlinkage void bug_trap_handler(unsigned long r4, unsigned long r5,
517 struct pt_regs *regs = RELOC_HIDE(&__regs, 0); 517 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
518 518
519 /* Rewind */ 519 /* Rewind */
520 regs->pc -= instruction_size(regs->pc); 520 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
521 521
522 if (notify_die(DIE_TRAP, regs, TRAPA_BUG_OPCODE & 0xff, 522 if (notify_die(DIE_TRAP, regs, TRAPA_BUG_OPCODE & 0xff,
523 SIGTRAP) == NOTIFY_STOP) 523 SIGTRAP) == NOTIFY_STOP)
diff --git a/arch/sh/kernel/signal.c b/arch/sh/kernel/signal.c
index d7d98d691c64..b32c35a7c0a3 100644
--- a/arch/sh/kernel/signal.c
+++ b/arch/sh/kernel/signal.c
@@ -500,7 +500,9 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
500 } 500 }
501 /* fallthrough */ 501 /* fallthrough */
502 case -ERESTARTNOINTR: 502 case -ERESTARTNOINTR:
503 regs->pc -= instruction_size(regs->pc); 503 regs->pc -= instruction_size(
504 ctrl_inw(regs->pc - 4));
505 break;
504 } 506 }
505 } else { 507 } else {
506 /* gUSA handling */ 508 /* gUSA handling */
@@ -516,7 +518,8 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
516 regs->regs[15] = regs->regs[1]; 518 regs->regs[15] = regs->regs[1];
517 if (regs->pc < regs->regs[0]) 519 if (regs->pc < regs->regs[0])
518 /* Go to rewind point #1 */ 520 /* Go to rewind point #1 */
519 regs->pc = regs->regs[0] + offset - 2; 521 regs->pc = regs->regs[0] + offset -
522 instruction_size(ctrl_inw(regs->pc-4));
520 } 523 }
521#ifdef CONFIG_PREEMPT 524#ifdef CONFIG_PREEMPT
522 local_irq_restore(flags); 525 local_irq_restore(flags);
@@ -600,9 +603,9 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
600 regs->regs[0] == -ERESTARTSYS || 603 regs->regs[0] == -ERESTARTSYS ||
601 regs->regs[0] == -ERESTARTNOINTR) { 604 regs->regs[0] == -ERESTARTNOINTR) {
602 regs->regs[0] = save_r0; 605 regs->regs[0] = save_r0;
603 regs->pc -= instruction_size(regs->pc); 606 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
604 } else if (regs->regs[0] == -ERESTART_RESTARTBLOCK) { 607 } else if (regs->regs[0] == -ERESTART_RESTARTBLOCK) {
605 regs->pc -= instruction_size(regs->pc); 608 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
606 regs->regs[3] = __NR_restart_syscall; 609 regs->regs[3] = __NR_restart_syscall;
607 } 610 }
608 } 611 }
diff --git a/arch/sh/kernel/traps.c b/arch/sh/kernel/traps.c
index 7b40f0ff3dfc..1446d12ba220 100644
--- a/arch/sh/kernel/traps.c
+++ b/arch/sh/kernel/traps.c
@@ -505,7 +505,7 @@ static int handle_unaligned_access(u16 instruction, struct pt_regs *regs)
505 simple: 505 simple:
506 ret = handle_unaligned_ins(instruction,regs); 506 ret = handle_unaligned_ins(instruction,regs);
507 if (ret==0) 507 if (ret==0)
508 regs->pc += 2; 508 regs->pc += instruction_size(instruction);
509 return ret; 509 return ret;
510} 510}
511#endif /* CONFIG_CPU_SH2A */ 511#endif /* CONFIG_CPU_SH2A */
@@ -682,7 +682,7 @@ asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5,
682 682
683 err = do_fpu_inst(inst, regs); 683 err = do_fpu_inst(inst, regs);
684 if (!err) { 684 if (!err) {
685 regs->pc += 2; 685 regs->pc += instruction_size(inst);
686 return; 686 return;
687 } 687 }
688 /* not a FPU inst. */ 688 /* not a FPU inst. */