14 #include <linux/kernel.h>
15 #include <linux/ptrace.h>
27 #include <linux/perf_event.h>
30 #include <asm/kprobes.h>
31 #include <asm/traps.h>
35 # define TRAP_RESERVED_INST 4
36 # define TRAP_ILLEGAL_SLOT_INST 6
37 # define TRAP_ADDRESS_ERROR 9
38 # ifdef CONFIG_CPU_SH2A
40 # define TRAP_FPU_ERROR 13
41 # define TRAP_DIVZERO_ERROR 17
42 # define TRAP_DIVOVF_ERROR 18
45 #define TRAP_RESERVED_INST 12
46 #define TRAP_ILLEGAL_SLOT_INST 13
51 #ifdef __LITTLE_ENDIAN__
52 if ((count == 1) && dst[0] & 0x80) {
57 if ((count == 2) && dst[1] & 0x80) {
62 if ((count == 1) && dst[3] & 0x80) {
67 if ((count == 2) && dst[2] & 0x80) {
90 unsigned long *rm, *rn;
92 unsigned char __user *srcu, *dstu;
94 index = (instruction>>8)&15;
97 index = (instruction>>4)&15;
100 count = 1<<(instruction&3);
110 switch (instruction>>12) {
112 if (instruction & 8) {
114 srcu = (
unsigned char __user *)*rm;
115 srcu += regs->
regs[0];
116 dst = (
unsigned char *)rn;
117 *(
unsigned long *)dst = 0;
119 #if !defined(__LITTLE_ENDIAN__)
122 if (ma->
from(dst, srcu, count))
128 src = (
unsigned char *)rm;
129 #if !defined(__LITTLE_ENDIAN__)
132 dstu = (
unsigned char __user *)*rn;
133 dstu += regs->
regs[0];
135 if (ma->
to(dstu, src, count))
142 src = (
unsigned char*) rm;
143 dstu = (
unsigned char __user *)*rn;
144 dstu += (instruction&0x000F)<<2;
146 if (ma->
to(dstu, src, 4))
154 src = (
unsigned char*) rm;
155 dstu = (
unsigned char __user *)*rn;
156 #if !defined(__LITTLE_ENDIAN__)
159 if (ma->
to(dstu, src, count))
165 srcu = (
unsigned char __user *)*rm;
166 srcu += (instruction & 0x000F) << 2;
167 dst = (
unsigned char *)rn;
168 *(
unsigned long *)dst = 0;
170 if (ma->
from(dst, srcu, 4))
176 srcu = (
unsigned char __user *)*rm;
179 dst = (
unsigned char*) rn;
180 *(
unsigned long*)dst = 0;
182 #if !defined(__LITTLE_ENDIAN__)
185 if (ma->
from(dst, srcu, count))
192 switch ((instruction&0xFF00)>>8) {
194 src = (
unsigned char *) ®s->
regs[0];
195 #
if !defined(__LITTLE_ENDIAN__)
198 dstu = (
unsigned char __user *)*rm;
199 dstu += (instruction & 0x000F) << 1;
201 if (ma->
to(dstu, src, 2))
207 srcu = (
unsigned char __user *)*rm;
208 srcu += (instruction & 0x000F) << 1;
209 dst = (
unsigned char *) ®s->
regs[0];
210 *(
unsigned long *)dst = 0;
212 #if !defined(__LITTLE_ENDIAN__)
215 if (ma->
from(dst, srcu, 2))
224 srcu = (
unsigned char __user *)regs->
pc;
226 srcu += (instruction & 0x00FF) << 1;
227 dst = (
unsigned char *)rn;
228 *(
unsigned long *)dst = 0;
230 #if !defined(__LITTLE_ENDIAN__)
234 if (ma->
from(dst, srcu, 2))
241 srcu = (
unsigned char __user *)(regs->
pc & ~0x3);
243 srcu += (instruction & 0x00FF) << 2;
244 dst = (
unsigned char *)rn;
245 *(
unsigned long *)dst = 0;
247 if (ma->
from(dst, srcu, 4))
266 static inline int handle_delayslot(
struct pt_regs *regs,
280 die(
"delay-slot-insn faulting in handle_unaligned_delayslot",
284 return handle_unaligned_ins(instruction, regs, ma);
300 #define SH_PC_8BIT_OFFSET(instr) ((((signed char)(instr))*2) + 4)
301 #define SH_PC_12BIT_OFFSET(instr) ((((signed short)(instr<<4))>>3) + 4)
316 index = (instruction>>8)&15;
333 switch (instruction&0xF000) {
335 if (instruction==0x000B) {
337 ret = handle_delayslot(regs, instruction, ma);
341 else if ((instruction&0x00FF)==0x0023) {
343 ret = handle_delayslot(regs, instruction, ma);
347 else if ((instruction&0x00FF)==0x0003) {
349 ret = handle_delayslot(regs, instruction, ma);
351 regs->
pr = regs->
pc + 4;
368 if ((instruction&0x00FF)==0x002B) {
370 ret = handle_delayslot(regs, instruction, ma);
374 else if ((instruction&0x00FF)==0x000B) {
376 ret = handle_delayslot(regs, instruction, ma);
378 regs->
pr = regs->
pc + 4;
395 switch (instruction&0x0F00) {
404 ret = handle_delayslot(regs, instruction, ma);
406 #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
407 if ((regs->
sr & 0x00000001) != 0)
418 ret = handle_delayslot(regs, instruction, ma);
420 #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
421 if ((regs->
sr & 0x00000001) == 0)
435 ret = handle_delayslot(regs, instruction, ma);
441 ret = handle_delayslot(regs, instruction, ma);
443 regs->
pr = regs->
pc + 4;
455 ret = handle_unaligned_ins(instruction, regs, ma);
473 unsigned long writeaccess,
483 #ifdef CONFIG_CPU_HAS_SR_RB
491 unsigned int user_action;
498 sizeof(instruction))) {
535 "access (PC %lx PR %lx)\n",
current->comm, regs->
pc,
541 info.si_addr = (
void __user *)address;
547 die(
"unaligned program counter", regs, error_code);
551 sizeof(instruction))) {
556 die(
"insn faulting in do_address_error", regs, 0);
573 unsigned short inst = 0;
582 get_user(inst, ((
unsigned short *) regs->
pc));
587 if ((inst == 0xf000) || (inst == 0x4000))
593 #define is_dsp_inst(regs) (0)
596 #ifdef CONFIG_CPU_SH2A
598 unsigned long r6,
unsigned long r7,
604 case TRAP_DIVZERO_ERROR:
607 case TRAP_DIVOVF_ERROR:
617 unsigned long r6,
unsigned long r7,
624 #ifdef CONFIG_SH_FPU_EMU
625 unsigned short inst = 0;
644 tsk->
thread.dsp_status.status |= SR_DSP;
656 #ifdef CONFIG_SH_FPU_EMU
657 static int emulate_branch(
unsigned short inst,
struct pt_regs *regs)
670 if (((inst & 0xf000) == 0xb000) ||
671 ((inst & 0xf0ff) == 0x0003) ||
672 ((inst & 0xf0ff) == 0x400b))
673 regs->
pr = regs->
pc + 4;
675 if ((inst & 0xfd00) == 0x8d00) {
680 if ((inst & 0xe000) == 0xa000) {
685 if ((inst & 0xf0df) == 0x0003) {
686 regs->
pc += regs->
regs[(inst & 0x0f00) >> 8] + 4;
690 if ((inst & 0xf0df) == 0x400b) {
691 regs->
pc = regs->
regs[(inst & 0x0f00) >> 8];
695 if ((inst & 0xffff) == 0x000b) {
705 unsigned long r6,
unsigned long r7,
715 #ifdef CONFIG_SH_FPU_EMU
716 get_user(inst, (
unsigned short *)regs->
pc + 1);
719 if (!emulate_branch(inst, regs))
734 unsigned long r6,
unsigned long r7,
752 asm volatile(
"ldc %0, vbr"
763 extern void *exception_handling_table[];
766 old_handler = exception_handling_table[vec];
767 exception_handling_table[vec] = handler;
776 #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_FPU) || \
777 defined(CONFIG_SH_FPU_EMU)
785 #elif defined(CONFIG_SH_FPU)
786 set_exception_table_evt(0x800, fpu_state_restore_trap_handler);
787 set_exception_table_evt(0x820, fpu_state_restore_trap_handler);
790 #ifdef CONFIG_CPU_SH2
793 #ifdef CONFIG_CPU_SH2A