vserver 1.9.3
[linux-2.6.git] / arch / ppc / kernel / traps.c
1 /*
2  *  arch/ppc/kernel/traps.c
3  *
4  *  Copyright (C) 1995-1996  Gary Thomas (gdt@linuxppc.org)
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  as published by the Free Software Foundation; either version
9  *  2 of the License, or (at your option) any later version.
10  *
11  *  Modified by Cort Dougan (cort@cs.nmt.edu)
12  *  and Paul Mackerras (paulus@cs.anu.edu.au)
13  */
14
15 /*
16  * This file handles the architecture-dependent parts of hardware exceptions
17  */
18
19 #include <linux/errno.h>
20 #include <linux/sched.h>
21 #include <linux/kernel.h>
22 #include <linux/mm.h>
23 #include <linux/stddef.h>
24 #include <linux/unistd.h>
25 #include <linux/ptrace.h>
26 #include <linux/slab.h>
27 #include <linux/user.h>
28 #include <linux/a.out.h>
29 #include <linux/interrupt.h>
30 #include <linux/config.h>
31 #include <linux/init.h>
32 #include <linux/module.h>
33 #include <linux/prctl.h>
34
35 #include <asm/pgtable.h>
36 #include <asm/uaccess.h>
37 #include <asm/system.h>
38 #include <asm/io.h>
39 #include <asm/reg.h>
40 #include <asm/xmon.h>
41 #ifdef CONFIG_PMAC_BACKLIGHT
42 #include <asm/backlight.h>
43 #endif
44
45 #ifdef CONFIG_XMON
46 void (*debugger)(struct pt_regs *regs) = xmon;
47 int (*debugger_bpt)(struct pt_regs *regs) = xmon_bpt;
48 int (*debugger_sstep)(struct pt_regs *regs) = xmon_sstep;
49 int (*debugger_iabr_match)(struct pt_regs *regs) = xmon_iabr_match;
50 int (*debugger_dabr_match)(struct pt_regs *regs) = xmon_dabr_match;
51 void (*debugger_fault_handler)(struct pt_regs *regs);
52 #else
53 #ifdef CONFIG_KGDB
54 void (*debugger)(struct pt_regs *regs);
55 int (*debugger_bpt)(struct pt_regs *regs);
56 int (*debugger_sstep)(struct pt_regs *regs);
57 int (*debugger_iabr_match)(struct pt_regs *regs);
58 int (*debugger_dabr_match)(struct pt_regs *regs);
59 void (*debugger_fault_handler)(struct pt_regs *regs);
60 #else
61 #define debugger(regs)                  do { } while (0)
62 #define debugger_bpt(regs)              0
63 #define debugger_sstep(regs)            0
64 #define debugger_iabr_match(regs)       0
65 #define debugger_dabr_match(regs)       0
66 #define debugger_fault_handler          ((void (*)(struct pt_regs *))0)
67 #endif
68 #endif
69
70 /*
71  * Trap & Exception support
72  */
73
74
75 spinlock_t die_lock = SPIN_LOCK_UNLOCKED;
76
77 void die(const char * str, struct pt_regs * fp, long err)
78 {
79         static int die_counter;
80         int nl = 0;
81         console_verbose();
82         spin_lock_irq(&die_lock);
83 #ifdef CONFIG_PMAC_BACKLIGHT
84         set_backlight_enable(1);
85         set_backlight_level(BACKLIGHT_MAX);
86 #endif
87         printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
88 #ifdef CONFIG_PREEMPT
89         printk("PREEMPT ");
90         nl = 1;
91 #endif
92 #ifdef CONFIG_SMP
93         printk("SMP NR_CPUS=%d ", NR_CPUS);
94         nl = 1;
95 #endif
96         if (nl)
97                 printk("\n");
98         show_regs(fp);
99         spin_unlock_irq(&die_lock);
100         /* do_exit() should take care of panic'ing from an interrupt
101          * context so we don't handle it here
102          */
103         do_exit(err);
104 }
105
106 void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
107 {
108         siginfo_t info;
109
110         if (!user_mode(regs)) {
111                 debugger(regs);
112                 die("Exception in kernel mode", regs, signr);
113         }
114         info.si_signo = signr;
115         info.si_errno = 0;
116         info.si_code = code;
117         info.si_addr = (void __user *) addr;
118         force_sig_info(signr, &info, current);
119 }
120
121 /*
122  * I/O accesses can cause machine checks on powermacs.
123  * Check if the NIP corresponds to the address of a sync
124  * instruction for which there is an entry in the exception
125  * table.
126  * Note that the 601 only takes a machine check on TEA
127  * (transfer error ack) signal assertion, and does not
128  * set any of the top 16 bits of SRR1.
129  *  -- paulus.
130  */
131 static inline int check_io_access(struct pt_regs *regs)
132 {
133 #ifdef CONFIG_PPC_PMAC
134         unsigned long msr = regs->msr;
135         const struct exception_table_entry *entry;
136         unsigned int *nip = (unsigned int *)regs->nip;
137
138         if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
139             && (entry = search_exception_tables(regs->nip)) != NULL) {
140                 /*
141                  * Check that it's a sync instruction, or somewhere
142                  * in the twi; isync; nop sequence that inb/inw/inl uses.
143                  * As the address is in the exception table
144                  * we should be able to read the instr there.
145                  * For the debug message, we look at the preceding
146                  * load or store.
147                  */
148                 if (*nip == 0x60000000)         /* nop */
149                         nip -= 2;
150                 else if (*nip == 0x4c00012c)    /* isync */
151                         --nip;
152                 if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
153                         /* sync or twi */
154                         unsigned int rb;
155
156                         --nip;
157                         rb = (*nip >> 11) & 0x1f;
158                         printk(KERN_DEBUG "%s bad port %lx at %p\n",
159                                (*nip & 0x100)? "OUT to": "IN from",
160                                regs->gpr[rb] - _IO_BASE, nip);
161                         regs->msr |= MSR_RI;
162                         regs->nip = entry->fixup;
163                         return 1;
164                 }
165         }
166 #endif /* CONFIG_PPC_PMAC */
167         return 0;
168 }
169
170 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
171 /* On 4xx, the reason for the machine check or program exception
172    is in the ESR. */
173 #define get_reason(regs)        ((regs)->dsisr)
174 #ifndef CONFIG_E500
175 #define get_mc_reason(regs)     ((regs)->dsisr)
176 #else
177 #define get_mc_reason(regs)     (mfspr(SPRN_MCSR))
178 #endif
179 #define REASON_FP               0
180 #define REASON_ILLEGAL          ESR_PIL
181 #define REASON_PRIVILEGED       ESR_PPR
182 #define REASON_TRAP             ESR_PTR
183
184 /* single-step stuff */
185 #define single_stepping(regs)   (current->thread.dbcr0 & DBCR0_IC)
186 #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
187
188 #else
189 /* On non-4xx, the reason for the machine check or program
190    exception is in the MSR. */
191 #define get_reason(regs)        ((regs)->msr)
192 #define get_mc_reason(regs)     ((regs)->msr)
193 #define REASON_FP               0x100000
194 #define REASON_ILLEGAL          0x80000
195 #define REASON_PRIVILEGED       0x40000
196 #define REASON_TRAP             0x20000
197
198 #define single_stepping(regs)   ((regs)->msr & MSR_SE)
199 #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
200 #endif
201
202 void MachineCheckException(struct pt_regs *regs)
203 {
204         unsigned long reason = get_mc_reason(regs);
205
206         if (user_mode(regs)) {
207                 regs->msr |= MSR_RI;
208                 _exception(SIGBUS, regs, BUS_ADRERR, regs->nip);
209                 return;
210         }
211
212 #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
213         /* the qspan pci read routines can cause machine checks -- Cort */
214         bad_page_fault(regs, regs->dar, SIGBUS);
215         return;
216 #endif
217
218         if (debugger_fault_handler) {
219                 debugger_fault_handler(regs);
220                 regs->msr |= MSR_RI;
221                 return;
222         }
223
224         if (check_io_access(regs))
225                 return;
226
227 #if defined(CONFIG_4xx) && !defined(CONFIG_440A)
228         if (reason & ESR_IMCP) {
229                 printk("Instruction");
230                 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
231         } else
232                 printk("Data");
233         printk(" machine check in kernel mode.\n");
234 #elif defined(CONFIG_440A)
235         printk("Machine check in kernel mode.\n");
236         if (reason & ESR_IMCP){
237                 printk("Instruction Synchronous Machine Check exception\n");
238                 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
239         }
240         else {
241                 u32 mcsr = mfspr(SPRN_MCSR);
242                 if (mcsr & MCSR_IB)
243                         printk("Instruction Read PLB Error\n");
244                 if (mcsr & MCSR_DRB)
245                         printk("Data Read PLB Error\n");
246                 if (mcsr & MCSR_DWB)
247                         printk("Data Write PLB Error\n");
248                 if (mcsr & MCSR_TLBP)
249                         printk("TLB Parity Error\n");
250                 if (mcsr & MCSR_ICP){
251                         flush_instruction_cache();
252                         printk("I-Cache Parity Error\n");
253                 }
254                 if (mcsr & MCSR_DCSP)
255                         printk("D-Cache Search Parity Error\n");
256                 if (mcsr & MCSR_DCFP)
257                         printk("D-Cache Flush Parity Error\n");
258                 if (mcsr & MCSR_IMPE)
259                         printk("Machine Check exception is imprecise\n");
260
261                 /* Clear MCSR */
262                 mtspr(SPRN_MCSR, mcsr);
263         }
264 #elif defined (CONFIG_E500)
265         printk("Machine check in kernel mode.\n");
266         printk("Caused by (from MCSR=%lx): ", reason);
267
268         if (reason & MCSR_MCP)
269                 printk("Machine Check Signal\n");
270         if (reason & MCSR_ICPERR)
271                 printk("Instruction Cache Parity Error\n");
272         if (reason & MCSR_DCP_PERR)
273                 printk("Data Cache Push Parity Error\n");
274         if (reason & MCSR_DCPERR)
275                 printk("Data Cache Parity Error\n");
276         if (reason & MCSR_GL_CI)
277                 printk("Guarded Load or Cache-Inhibited stwcx.\n");
278         if (reason & MCSR_BUS_IAERR)
279                 printk("Bus - Instruction Address Error\n");
280         if (reason & MCSR_BUS_RAERR)
281                 printk("Bus - Read Address Error\n");
282         if (reason & MCSR_BUS_WAERR)
283                 printk("Bus - Write Address Error\n");
284         if (reason & MCSR_BUS_IBERR)
285                 printk("Bus - Instruction Data Error\n");
286         if (reason & MCSR_BUS_RBERR)
287                 printk("Bus - Read Data Bus Error\n");
288         if (reason & MCSR_BUS_WBERR)
289                 printk("Bus - Read Data Bus Error\n");
290         if (reason & MCSR_BUS_IPERR)
291                 printk("Bus - Instruction Parity Error\n");
292         if (reason & MCSR_BUS_RPERR)
293                 printk("Bus - Read Parity Error\n");
294 #else /* !CONFIG_4xx && !CONFIG_E500 */
295         printk("Machine check in kernel mode.\n");
296         printk("Caused by (from SRR1=%lx): ", reason);
297         switch (reason & 0x601F0000) {
298         case 0x80000:
299                 printk("Machine check signal\n");
300                 break;
301         case 0:         /* for 601 */
302         case 0x40000:
303         case 0x140000:  /* 7450 MSS error and TEA */
304                 printk("Transfer error ack signal\n");
305                 break;
306         case 0x20000:
307                 printk("Data parity error signal\n");
308                 break;
309         case 0x10000:
310                 printk("Address parity error signal\n");
311                 break;
312         case 0x20000000:
313                 printk("L1 Data Cache error\n");
314                 break;
315         case 0x40000000:
316                 printk("L1 Instruction Cache error\n");
317                 break;
318         case 0x00100000:
319                 printk("L2 data cache parity error\n");
320                 break;
321         default:
322                 printk("Unknown values in msr\n");
323         }
324 #endif /* CONFIG_4xx */
325
326         debugger(regs);
327         die("machine check", regs, SIGBUS);
328 }
329
330 void SMIException(struct pt_regs *regs)
331 {
332         debugger(regs);
333 #if !(defined(CONFIG_XMON) || defined(CONFIG_KGDB))
334         show_regs(regs);
335         panic("System Management Interrupt");
336 #endif
337 }
338
339 void UnknownException(struct pt_regs *regs)
340 {
341         printk("Bad trap at PC: %lx, MSR: %lx, vector=%lx    %s\n",
342                regs->nip, regs->msr, regs->trap, print_tainted());
343         _exception(SIGTRAP, regs, 0, 0);
344 }
345
346 void InstructionBreakpoint(struct pt_regs *regs)
347 {
348         if (debugger_iabr_match(regs))
349                 return;
350         _exception(SIGTRAP, regs, TRAP_BRKPT, 0);
351 }
352
353 void RunModeException(struct pt_regs *regs)
354 {
355         _exception(SIGTRAP, regs, 0, 0);
356 }
357
358 /* Illegal instruction emulation support.  Originally written to
359  * provide the PVR to user applications using the mfspr rd, PVR.
360  * Return non-zero if we can't emulate, or -EFAULT if the associated
361  * memory access caused an access fault.  Return zero on success.
362  *
363  * There are a couple of ways to do this, either "decode" the instruction
364  * or directly match lots of bits.  In this case, matching lots of
365  * bits is faster and easier.
366  *
367  */
368 #define INST_MFSPR_PVR          0x7c1f42a6
369 #define INST_MFSPR_PVR_MASK     0xfc1fffff
370
371 #define INST_DCBA               0x7c0005ec
372 #define INST_DCBA_MASK          0x7c0007fe
373
374 #define INST_MCRXR              0x7c000400
375 #define INST_MCRXR_MASK         0x7c0007fe
376
377 static int emulate_instruction(struct pt_regs *regs)
378 {
379         u32 instword;
380         u32 rd;
381
382         if (!user_mode(regs))
383                 return -EINVAL;
384         CHECK_FULL_REGS(regs);
385
386         if (get_user(instword, (u32 __user *)(regs->nip)))
387                 return -EFAULT;
388
389         /* Emulate the mfspr rD, PVR.
390          */
391         if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
392                 rd = (instword >> 21) & 0x1f;
393                 regs->gpr[rd] = mfspr(PVR);
394                 return 0;
395         }
396
397         /* Emulating the dcba insn is just a no-op.  */
398         if ((instword & INST_DCBA_MASK) == INST_DCBA)
399                 return 0;
400
401         /* Emulate the mcrxr insn.  */
402         if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
403                 int shift = (instword >> 21) & 0x1c;
404                 unsigned long msk = 0xf0000000UL >> shift;
405
406                 regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
407                 regs->xer &= ~0xf0000000UL;
408                 return 0;
409         }
410
411         return -EINVAL;
412 }
413
414 /*
415  * After we have successfully emulated an instruction, we have to
416  * check if the instruction was being single-stepped, and if so,
417  * pretend we got a single-step exception.  This was pointed out
418  * by Kumar Gala.  -- paulus
419  */
420 static void emulate_single_step(struct pt_regs *regs)
421 {
422         if (single_stepping(regs)) {
423                 clear_single_step(regs);
424                 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
425         }
426 }
427
428 /*
429  * Look through the list of trap instructions that are used for BUG(),
430  * BUG_ON() and WARN_ON() and see if we hit one.  At this point we know
431  * that the exception was caused by a trap instruction of some kind.
432  * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
433  * otherwise.
434  */
435 extern struct bug_entry __start___bug_table[], __stop___bug_table[];
436
437 #ifndef CONFIG_MODULES
438 #define module_find_bug(x)      NULL
439 #endif
440
441 static struct bug_entry *find_bug(unsigned long bugaddr)
442 {
443         struct bug_entry *bug;
444
445         for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
446                 if (bugaddr == bug->bug_addr)
447                         return bug;
448         return module_find_bug(bugaddr);
449 }
450
451 int check_bug_trap(struct pt_regs *regs)
452 {
453         struct bug_entry *bug;
454         unsigned long addr;
455
456         if (regs->msr & MSR_PR)
457                 return 0;       /* not in kernel */
458         addr = regs->nip;       /* address of trap instruction */
459         if (addr < PAGE_OFFSET)
460                 return 0;
461         bug = find_bug(regs->nip);
462         if (bug == NULL)
463                 return 0;
464         if (bug->line & BUG_WARNING_TRAP) {
465                 /* this is a WARN_ON rather than BUG/BUG_ON */
466 #ifdef CONFIG_XMON
467                 xmon_printf(KERN_ERR "Badness in %s at %s:%d\n",
468                        bug->function, bug->file,
469                        bug->line & ~BUG_WARNING_TRAP);
470 #endif /* CONFIG_XMON */                
471                 printk(KERN_ERR "Badness in %s at %s:%d\n",
472                        bug->function, bug->file,
473                        bug->line & ~BUG_WARNING_TRAP);
474                 dump_stack();
475                 return 1;
476         }
477 #ifdef CONFIG_XMON
478         xmon_printf(KERN_CRIT "kernel BUG in %s at %s:%d!\n",
479                bug->function, bug->file, bug->line);
480         xmon(regs);
481 #endif /* CONFIG_XMON */
482         printk(KERN_CRIT "kernel BUG in %s at %s:%d!\n",
483                bug->function, bug->file, bug->line);
484
485         return 0;
486 }
487
488 void ProgramCheckException(struct pt_regs *regs)
489 {
490         unsigned int reason = get_reason(regs);
491         extern int do_mathemu(struct pt_regs *regs);
492
493 #ifdef CONFIG_MATH_EMULATION
494         /* (reason & REASON_ILLEGAL) would be the obvious thing here,
495          * but there seems to be a hardware bug on the 405GP (RevD)
496          * that means ESR is sometimes set incorrectly - either to
497          * ESR_DST (!?) or 0.  In the process of chasing this with the
498          * hardware people - not sure if it can happen on any illegal
499          * instruction or only on FP instructions, whether there is a
500          * pattern to occurences etc. -dgibson 31/Mar/2003 */
501         if (!(reason & REASON_TRAP) && do_mathemu(regs) == 0) {
502                 emulate_single_step(regs);
503                 return;
504         }
505 #endif /* CONFIG_MATH_EMULATION */
506
507         if (reason & REASON_FP) {
508                 /* IEEE FP exception */
509                 int code = 0;
510                 u32 fpscr;
511
512                 /* We must make sure the FP state is consistent with
513                  * our MSR_FP in regs
514                  */
515                 preempt_disable();
516                 if (regs->msr & MSR_FP)
517                         giveup_fpu(current);
518                 preempt_enable();
519
520                 fpscr = current->thread.fpscr;
521                 fpscr &= fpscr << 22;   /* mask summary bits with enables */
522                 if (fpscr & FPSCR_VX)
523                         code = FPE_FLTINV;
524                 else if (fpscr & FPSCR_OX)
525                         code = FPE_FLTOVF;
526                 else if (fpscr & FPSCR_UX)
527                         code = FPE_FLTUND;
528                 else if (fpscr & FPSCR_ZX)
529                         code = FPE_FLTDIV;
530                 else if (fpscr & FPSCR_XX)
531                         code = FPE_FLTRES;
532                 _exception(SIGFPE, regs, code, regs->nip);
533                 return;
534         }
535
536         if (reason & REASON_TRAP) {
537                 /* trap exception */
538                 if (debugger_bpt(regs))
539                         return;
540                 if (check_bug_trap(regs)) {
541                         regs->nip += 4;
542                         return;
543                 }
544                 _exception(SIGTRAP, regs, TRAP_BRKPT, 0);
545                 return;
546         }
547
548         /* Try to emulate it if we should. */
549         if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
550                 switch (emulate_instruction(regs)) {
551                 case 0:
552                         regs->nip += 4;
553                         emulate_single_step(regs);
554                         return;
555                 case -EFAULT:
556                         _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
557                         return;
558                 }
559         }
560
561         if (reason & REASON_PRIVILEGED)
562                 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
563         else
564                 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
565 }
566
567 void SingleStepException(struct pt_regs *regs)
568 {
569         regs->msr &= ~MSR_SE;  /* Turn off 'trace' bit */
570         if (debugger_sstep(regs))
571                 return;
572         _exception(SIGTRAP, regs, TRAP_TRACE, 0);
573 }
574
575 void AlignmentException(struct pt_regs *regs)
576 {
577         int fixed;
578
579         fixed = fix_alignment(regs);
580         if (fixed == 1) {
581                 regs->nip += 4; /* skip over emulated instruction */
582                 return;
583         }
584         if (fixed == -EFAULT) {
585                 /* fixed == -EFAULT means the operand address was bad */
586                 if (user_mode(regs))
587                         _exception(SIGSEGV, regs, SEGV_ACCERR, regs->dar);
588                 else
589                         bad_page_fault(regs, regs->dar, SIGSEGV);
590                 return;
591         }
592         _exception(SIGBUS, regs, BUS_ADRALN, regs->dar);
593 }
594
595 void StackOverflow(struct pt_regs *regs)
596 {
597         printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
598                current, regs->gpr[1]);
599         debugger(regs);
600         show_regs(regs);
601         panic("kernel stack overflow");
602 }
603
604 void nonrecoverable_exception(struct pt_regs *regs)
605 {
606         printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
607                regs->nip, regs->msr);
608         debugger(regs);
609         die("nonrecoverable exception", regs, SIGKILL);
610 }
611
612 void trace_syscall(struct pt_regs *regs)
613 {
614         printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
615                current, current->pid, regs->nip, regs->link, regs->gpr[0],
616                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
617 }
618
619 #ifdef CONFIG_8xx
620 void SoftwareEmulation(struct pt_regs *regs)
621 {
622         extern int do_mathemu(struct pt_regs *);
623         extern int Soft_emulate_8xx(struct pt_regs *);
624         int errcode;
625
626         CHECK_FULL_REGS(regs);
627
628         if (!user_mode(regs)) {
629                 debugger(regs);
630                 die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
631         }
632
633 #ifdef CONFIG_MATH_EMULATION
634         errcode = do_mathemu(regs);
635 #else
636         errcode = Soft_emulate_8xx(regs);
637 #endif
638         if (errcode) {
639                 if (errcode > 0)
640                         _exception(SIGFPE, regs, 0, 0);
641                 else if (errcode == -EFAULT)
642                         _exception(SIGSEGV, regs, 0, 0);
643                 else
644                         _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
645         } else
646                 emulate_single_step(regs);
647 }
648 #endif /* CONFIG_8xx */
649
650 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
651
652 void DebugException(struct pt_regs *regs, unsigned long debug_status)
653 {
654 #if 0
655         if (debug_status & DBSR_TIE) {          /* trap instruction*/
656                 if (!user_mode(regs) && debugger_bpt(regs))
657                         return;
658                 _exception(SIGTRAP, regs, 0, 0);
659
660         }
661 #endif
662         if (debug_status & DBSR_IC) {   /* instruction completion */
663                 if (!user_mode(regs) && debugger_sstep(regs))
664                         return;
665                 current->thread.dbcr0 &= ~DBCR0_IC;
666                 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
667         }
668 }
669 #endif /* CONFIG_4xx || CONFIG_BOOKE */
670
671 #if !defined(CONFIG_TAU_INT)
672 void TAUException(struct pt_regs *regs)
673 {
674         printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx    %s\n",
675                regs->nip, regs->msr, regs->trap, print_tainted());
676 }
677 #endif /* CONFIG_INT_TAU */
678
679 void AltivecUnavailException(struct pt_regs *regs)
680 {
681         static int kernel_altivec_count;
682
683 #ifndef CONFIG_ALTIVEC
684         if (user_mode(regs)) {
685                 /* A user program has executed an altivec instruction,
686                    but this kernel doesn't support altivec. */
687                 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
688                 return;
689         }
690 #endif
691         /* The kernel has executed an altivec instruction without
692            first enabling altivec.  Whinge but let it do it. */
693         if (++kernel_altivec_count < 10)
694                 printk(KERN_ERR "AltiVec used in kernel (task=%p, pc=%lx)\n",
695                        current, regs->nip);
696         regs->msr |= MSR_VEC;
697 }
698
699 #ifdef CONFIG_ALTIVEC
700 void AltivecAssistException(struct pt_regs *regs)
701 {
702         int err;
703
704         preempt_disable();
705         if (regs->msr & MSR_VEC)
706                 giveup_altivec(current);
707         preempt_enable();
708
709         err = emulate_altivec(regs);
710         if (err == 0) {
711                 regs->nip += 4;         /* skip emulated instruction */
712                 emulate_single_step(regs);
713                 return;
714         }
715
716         if (err == -EFAULT) {
717                 /* got an error reading the instruction */
718                 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
719         } else {
720                 /* didn't recognize the instruction */
721                 /* XXX quick hack for now: set the non-Java bit in the VSCR */
722                 printk(KERN_ERR "unrecognized altivec instruction "
723                        "in %s at %lx\n", current->comm, regs->nip);
724                 current->thread.vscr.u[3] |= 0x10000;
725         }
726 }
727 #endif /* CONFIG_ALTIVEC */
728
729 #ifdef CONFIG_FSL_BOOKE
730 void CacheLockingException(struct pt_regs *regs, unsigned long address,
731                            unsigned long error_code)
732 {
733         /* We treat cache locking instructions from the user
734          * as priv ops, in the future we could try to do
735          * something smarter
736          */
737         if (error_code & (ESR_DLK|ESR_ILK))
738                 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
739         return;
740 }
741 #endif /* CONFIG_FSL_BOOKE */
742
743 #ifdef CONFIG_SPE
744 void SPEFloatingPointException(struct pt_regs *regs)
745 {
746         unsigned long spefscr;
747         int fpexc_mode;
748         int code = 0;
749
750         spefscr = current->thread.spefscr;
751         fpexc_mode = current->thread.fpexc_mode;
752
753         /* Hardware does not neccessarily set sticky
754          * underflow/overflow/invalid flags */
755         if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
756                 code = FPE_FLTOVF;
757                 spefscr |= SPEFSCR_FOVFS;
758         }
759         else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
760                 code = FPE_FLTUND;
761                 spefscr |= SPEFSCR_FUNFS;
762         }
763         else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
764                 code = FPE_FLTDIV;
765         else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
766                 code = FPE_FLTINV;
767                 spefscr |= SPEFSCR_FINVS;
768         }
769         else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
770                 code = FPE_FLTRES;
771
772         current->thread.spefscr = spefscr;
773
774         _exception(SIGFPE, regs, code, regs->nip);
775         return;
776 }
777 #endif
778
779 void __init trap_init(void)
780 {
781 }