2 * arch/ppc/kernel/traps.c
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
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.
11 * Modified by Cort Dougan (cort@cs.nmt.edu)
12 * and Paul Mackerras (paulus@cs.anu.edu.au)
16 * This file handles the architecture-dependent parts of hardware exceptions
19 #include <linux/errno.h>
20 #include <linux/sched.h>
21 #include <linux/kernel.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>
35 #include <asm/pgtable.h>
36 #include <asm/uaccess.h>
37 #include <asm/system.h>
41 #ifdef CONFIG_PMAC_BACKLIGHT
42 #include <asm/backlight.h>
47 extern int xmon_bpt(struct pt_regs *regs);
48 extern int xmon_sstep(struct pt_regs *regs);
49 extern int xmon_iabr_match(struct pt_regs *regs);
50 extern int xmon_dabr_match(struct pt_regs *regs);
52 void (*debugger)(struct pt_regs *regs) = xmon;
53 int (*debugger_bpt)(struct pt_regs *regs) = xmon_bpt;
54 int (*debugger_sstep)(struct pt_regs *regs) = xmon_sstep;
55 int (*debugger_iabr_match)(struct pt_regs *regs) = xmon_iabr_match;
56 int (*debugger_dabr_match)(struct pt_regs *regs) = xmon_dabr_match;
57 void (*debugger_fault_handler)(struct pt_regs *regs);
60 void (*debugger)(struct pt_regs *regs);
61 int (*debugger_bpt)(struct pt_regs *regs);
62 int (*debugger_sstep)(struct pt_regs *regs);
63 int (*debugger_iabr_match)(struct pt_regs *regs);
64 int (*debugger_dabr_match)(struct pt_regs *regs);
65 void (*debugger_fault_handler)(struct pt_regs *regs);
67 #define debugger(regs) do { } while (0)
68 #define debugger_bpt(regs) 0
69 #define debugger_sstep(regs) 0
70 #define debugger_iabr_match(regs) 0
71 #define debugger_dabr_match(regs) 0
72 #define debugger_fault_handler ((void (*)(struct pt_regs *))0)
77 * Trap & Exception support
80 DEFINE_SPINLOCK(die_lock);
82 int die(const char * str, struct pt_regs * fp, long err)
84 static int die_counter;
87 spin_lock_irq(&die_lock);
88 #ifdef CONFIG_PMAC_BACKLIGHT
89 if (_machine == _MACH_Pmac) {
90 set_backlight_enable(1);
91 set_backlight_level(BACKLIGHT_MAX);
94 printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
100 printk("SMP NR_CPUS=%d ", NR_CPUS);
106 spin_unlock_irq(&die_lock);
107 /* do_exit() should take care of panic'ing from an interrupt
108 * context so we don't handle it here
113 void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
117 if (!user_mode(regs)) {
119 die("Exception in kernel mode", regs, signr);
121 info.si_signo = signr;
124 info.si_addr = (void __user *) addr;
125 force_sig_info(signr, &info, current);
128 * Init gets no signals that it doesn't have a handler for.
129 * That's all very well, but if it has caused a synchronous
130 * exception and we ignore the resulting signal, it will just
131 * generate the same exception over and over again and we get
132 * nowhere. Better to kill it and let the kernel panic.
134 if (current->pid == 1) {
135 __sighandler_t handler;
137 spin_lock_irq(¤t->sighand->siglock);
138 handler = current->sighand->action[signr-1].sa.sa_handler;
139 spin_unlock_irq(¤t->sighand->siglock);
140 if (handler == SIG_DFL) {
141 /* init has generated a synchronous exception
142 and it doesn't have a handler for the signal */
143 printk(KERN_CRIT "init has generated signal %d "
144 "but has no handler for it\n", signr);
151 * I/O accesses can cause machine checks on powermacs.
152 * Check if the NIP corresponds to the address of a sync
153 * instruction for which there is an entry in the exception
155 * Note that the 601 only takes a machine check on TEA
156 * (transfer error ack) signal assertion, and does not
157 * set any of the top 16 bits of SRR1.
160 static inline int check_io_access(struct pt_regs *regs)
162 #if defined CONFIG_PPC_PMAC || defined CONFIG_8xx
163 unsigned long msr = regs->msr;
164 const struct exception_table_entry *entry;
165 unsigned int *nip = (unsigned int *)regs->nip;
167 if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
168 && (entry = search_exception_tables(regs->nip)) != NULL) {
170 * Check that it's a sync instruction, or somewhere
171 * in the twi; isync; nop sequence that inb/inw/inl uses.
172 * As the address is in the exception table
173 * we should be able to read the instr there.
174 * For the debug message, we look at the preceding
177 if (*nip == 0x60000000) /* nop */
179 else if (*nip == 0x4c00012c) /* isync */
181 /* eieio from I/O string functions */
182 else if ((*nip) == 0x7c0006ac || *(nip+1) == 0x7c0006ac)
184 if (*nip == 0x7c0004ac || (*nip >> 26) == 3 ||
185 (*(nip+1) >> 26) == 3) {
190 rb = (*nip >> 11) & 0x1f;
191 printk(KERN_DEBUG "%s bad port %lx at %p\n",
192 (*nip & 0x100)? "OUT to": "IN from",
193 regs->gpr[rb] - _IO_BASE, nip);
195 regs->nip = entry->fixup;
199 #endif /* CONFIG_PPC_PMAC */
203 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
204 /* On 4xx, the reason for the machine check or program exception
206 #define get_reason(regs) ((regs)->dsisr)
207 #ifndef CONFIG_FSL_BOOKE
208 #define get_mc_reason(regs) ((regs)->dsisr)
210 #define get_mc_reason(regs) (mfspr(SPRN_MCSR))
212 #define REASON_FP ESR_FP
213 #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
214 #define REASON_PRIVILEGED ESR_PPR
215 #define REASON_TRAP ESR_PTR
217 /* single-step stuff */
218 #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
219 #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
222 /* On non-4xx, the reason for the machine check or program
223 exception is in the MSR. */
224 #define get_reason(regs) ((regs)->msr)
225 #define get_mc_reason(regs) ((regs)->msr)
226 #define REASON_FP 0x100000
227 #define REASON_ILLEGAL 0x80000
228 #define REASON_PRIVILEGED 0x40000
229 #define REASON_TRAP 0x20000
231 #define single_stepping(regs) ((regs)->msr & MSR_SE)
232 #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
236 * This is "fall-back" implementation for configurations
237 * which don't provide platform-specific machine check info
239 void __attribute__ ((weak))
240 platform_machine_check(struct pt_regs *regs)
244 void machine_check_exception(struct pt_regs *regs)
246 unsigned long reason = get_mc_reason(regs);
248 if (user_mode(regs)) {
250 _exception(SIGBUS, regs, BUS_ADRERR, regs->nip);
254 #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
255 /* the qspan pci read routines can cause machine checks -- Cort */
256 bad_page_fault(regs, regs->dar, SIGBUS);
260 if (debugger_fault_handler) {
261 debugger_fault_handler(regs);
266 if (check_io_access(regs))
269 #if defined(CONFIG_4xx) && !defined(CONFIG_440A)
270 if (reason & ESR_IMCP) {
271 printk("Instruction");
272 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
275 printk(" machine check in kernel mode.\n");
276 #elif defined(CONFIG_440A)
277 printk("Machine check in kernel mode.\n");
278 if (reason & ESR_IMCP){
279 printk("Instruction Synchronous Machine Check exception\n");
280 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
283 u32 mcsr = mfspr(SPRN_MCSR);
285 printk("Instruction Read PLB Error\n");
287 printk("Data Read PLB Error\n");
289 printk("Data Write PLB Error\n");
290 if (mcsr & MCSR_TLBP)
291 printk("TLB Parity Error\n");
292 if (mcsr & MCSR_ICP){
293 flush_instruction_cache();
294 printk("I-Cache Parity Error\n");
296 if (mcsr & MCSR_DCSP)
297 printk("D-Cache Search Parity Error\n");
298 if (mcsr & MCSR_DCFP)
299 printk("D-Cache Flush Parity Error\n");
300 if (mcsr & MCSR_IMPE)
301 printk("Machine Check exception is imprecise\n");
304 mtspr(SPRN_MCSR, mcsr);
306 #elif defined (CONFIG_E500)
307 printk("Machine check in kernel mode.\n");
308 printk("Caused by (from MCSR=%lx): ", reason);
310 if (reason & MCSR_MCP)
311 printk("Machine Check Signal\n");
312 if (reason & MCSR_ICPERR)
313 printk("Instruction Cache Parity Error\n");
314 if (reason & MCSR_DCP_PERR)
315 printk("Data Cache Push Parity Error\n");
316 if (reason & MCSR_DCPERR)
317 printk("Data Cache Parity Error\n");
318 if (reason & MCSR_GL_CI)
319 printk("Guarded Load or Cache-Inhibited stwcx.\n");
320 if (reason & MCSR_BUS_IAERR)
321 printk("Bus - Instruction Address Error\n");
322 if (reason & MCSR_BUS_RAERR)
323 printk("Bus - Read Address Error\n");
324 if (reason & MCSR_BUS_WAERR)
325 printk("Bus - Write Address Error\n");
326 if (reason & MCSR_BUS_IBERR)
327 printk("Bus - Instruction Data Error\n");
328 if (reason & MCSR_BUS_RBERR)
329 printk("Bus - Read Data Bus Error\n");
330 if (reason & MCSR_BUS_WBERR)
331 printk("Bus - Read Data Bus Error\n");
332 if (reason & MCSR_BUS_IPERR)
333 printk("Bus - Instruction Parity Error\n");
334 if (reason & MCSR_BUS_RPERR)
335 printk("Bus - Read Parity Error\n");
336 #elif defined (CONFIG_E200)
337 printk("Machine check in kernel mode.\n");
338 printk("Caused by (from MCSR=%lx): ", reason);
340 if (reason & MCSR_MCP)
341 printk("Machine Check Signal\n");
342 if (reason & MCSR_CP_PERR)
343 printk("Cache Push Parity Error\n");
344 if (reason & MCSR_CPERR)
345 printk("Cache Parity Error\n");
346 if (reason & MCSR_EXCP_ERR)
347 printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
348 if (reason & MCSR_BUS_IRERR)
349 printk("Bus - Read Bus Error on instruction fetch\n");
350 if (reason & MCSR_BUS_DRERR)
351 printk("Bus - Read Bus Error on data load\n");
352 if (reason & MCSR_BUS_WRERR)
353 printk("Bus - Write Bus Error on buffered store or cache line push\n");
354 #else /* !CONFIG_4xx && !CONFIG_E500 && !CONFIG_E200 */
355 printk("Machine check in kernel mode.\n");
356 printk("Caused by (from SRR1=%lx): ", reason);
357 switch (reason & 0x601F0000) {
359 printk("Machine check signal\n");
361 case 0: /* for 601 */
363 case 0x140000: /* 7450 MSS error and TEA */
364 printk("Transfer error ack signal\n");
367 printk("Data parity error signal\n");
370 printk("Address parity error signal\n");
373 printk("L1 Data Cache error\n");
376 printk("L1 Instruction Cache error\n");
379 printk("L2 data cache parity error\n");
382 printk("Unknown values in msr\n");
384 #endif /* CONFIG_4xx */
387 * Optional platform-provided routine to print out
388 * additional info, e.g. bus error registers.
390 platform_machine_check(regs);
393 die("machine check", regs, SIGBUS);
396 void SMIException(struct pt_regs *regs)
399 #if !(defined(CONFIG_XMON) || defined(CONFIG_KGDB))
401 panic("System Management Interrupt");
405 void unknown_exception(struct pt_regs *regs)
407 printk("Bad trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
408 regs->nip, regs->msr, regs->trap, print_tainted());
409 _exception(SIGTRAP, regs, 0, 0);
412 void instruction_breakpoint_exception(struct pt_regs *regs)
414 if (debugger_iabr_match(regs))
416 _exception(SIGTRAP, regs, TRAP_BRKPT, 0);
419 void RunModeException(struct pt_regs *regs)
421 _exception(SIGTRAP, regs, 0, 0);
424 /* Illegal instruction emulation support. Originally written to
425 * provide the PVR to user applications using the mfspr rd, PVR.
426 * Return non-zero if we can't emulate, or -EFAULT if the associated
427 * memory access caused an access fault. Return zero on success.
429 * There are a couple of ways to do this, either "decode" the instruction
430 * or directly match lots of bits. In this case, matching lots of
431 * bits is faster and easier.
434 #define INST_MFSPR_PVR 0x7c1f42a6
435 #define INST_MFSPR_PVR_MASK 0xfc1fffff
437 #define INST_DCBA 0x7c0005ec
438 #define INST_DCBA_MASK 0x7c0007fe
440 #define INST_MCRXR 0x7c000400
441 #define INST_MCRXR_MASK 0x7c0007fe
443 #define INST_STRING 0x7c00042a
444 #define INST_STRING_MASK 0x7c0007fe
445 #define INST_STRING_GEN_MASK 0x7c00067e
446 #define INST_LSWI 0x7c0004aa
447 #define INST_LSWX 0x7c00042a
448 #define INST_STSWI 0x7c0005aa
449 #define INST_STSWX 0x7c00052a
451 static int emulate_string_inst(struct pt_regs *regs, u32 instword)
453 u8 rT = (instword >> 21) & 0x1f;
454 u8 rA = (instword >> 16) & 0x1f;
455 u8 NB_RB = (instword >> 11) & 0x1f;
460 /* Early out if we are an invalid form of lswx */
461 if ((instword & INST_STRING_MASK) == INST_LSWX)
462 if ((rT == rA) || (rT == NB_RB))
465 EA = (rA == 0) ? 0 : regs->gpr[rA];
467 switch (instword & INST_STRING_MASK) {
471 num_bytes = regs->xer & 0x7f;
475 num_bytes = (NB_RB == 0) ? 32 : NB_RB;
481 while (num_bytes != 0)
484 u32 shift = 8 * (3 - (pos & 0x3));
486 switch ((instword & INST_STRING_MASK)) {
489 if (get_user(val, (u8 __user *)EA))
491 /* first time updating this reg,
495 regs->gpr[rT] |= val << shift;
499 val = regs->gpr[rT] >> shift;
500 if (put_user(val, (u8 __user *)EA))
504 /* move EA to next address */
508 /* manage our position within the register */
519 static int emulate_instruction(struct pt_regs *regs)
524 if (!user_mode(regs))
526 CHECK_FULL_REGS(regs);
528 if (get_user(instword, (u32 __user *)(regs->nip)))
531 /* Emulate the mfspr rD, PVR.
533 if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
534 rd = (instword >> 21) & 0x1f;
535 regs->gpr[rd] = mfspr(SPRN_PVR);
539 /* Emulating the dcba insn is just a no-op. */
540 if ((instword & INST_DCBA_MASK) == INST_DCBA)
543 /* Emulate the mcrxr insn. */
544 if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
545 int shift = (instword >> 21) & 0x1c;
546 unsigned long msk = 0xf0000000UL >> shift;
548 regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
549 regs->xer &= ~0xf0000000UL;
553 /* Emulate load/store string insn. */
554 if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
555 return emulate_string_inst(regs, instword);
561 * After we have successfully emulated an instruction, we have to
562 * check if the instruction was being single-stepped, and if so,
563 * pretend we got a single-step exception. This was pointed out
564 * by Kumar Gala. -- paulus
566 static void emulate_single_step(struct pt_regs *regs)
568 if (single_stepping(regs)) {
569 clear_single_step(regs);
570 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
575 * Look through the list of trap instructions that are used for BUG(),
576 * BUG_ON() and WARN_ON() and see if we hit one. At this point we know
577 * that the exception was caused by a trap instruction of some kind.
578 * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
581 extern struct bug_entry __start___bug_table[], __stop___bug_table[];
583 #ifndef CONFIG_MODULES
584 #define module_find_bug(x) NULL
587 struct bug_entry *find_bug(unsigned long bugaddr)
589 struct bug_entry *bug;
591 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
592 if (bugaddr == bug->bug_addr)
594 return module_find_bug(bugaddr);
597 int check_bug_trap(struct pt_regs *regs)
599 struct bug_entry *bug;
602 if (regs->msr & MSR_PR)
603 return 0; /* not in kernel */
604 addr = regs->nip; /* address of trap instruction */
605 if (addr < PAGE_OFFSET)
607 bug = find_bug(regs->nip);
610 if (bug->line & BUG_WARNING_TRAP) {
611 /* this is a WARN_ON rather than BUG/BUG_ON */
613 xmon_printf(KERN_ERR "Badness in %s at %s:%ld\n",
614 bug->function, bug->file,
615 bug->line & ~BUG_WARNING_TRAP);
616 #endif /* CONFIG_XMON */
617 printk(KERN_ERR "Badness in %s at %s:%ld\n",
618 bug->function, bug->file,
619 bug->line & ~BUG_WARNING_TRAP);
624 xmon_printf(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
625 bug->function, bug->file, bug->line);
627 #endif /* CONFIG_XMON */
628 printk(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
629 bug->function, bug->file, bug->line);
634 void program_check_exception(struct pt_regs *regs)
636 unsigned int reason = get_reason(regs);
637 extern int do_mathemu(struct pt_regs *regs);
639 #ifdef CONFIG_MATH_EMULATION
640 /* (reason & REASON_ILLEGAL) would be the obvious thing here,
641 * but there seems to be a hardware bug on the 405GP (RevD)
642 * that means ESR is sometimes set incorrectly - either to
643 * ESR_DST (!?) or 0. In the process of chasing this with the
644 * hardware people - not sure if it can happen on any illegal
645 * instruction or only on FP instructions, whether there is a
646 * pattern to occurences etc. -dgibson 31/Mar/2003 */
647 if (!(reason & REASON_TRAP) && do_mathemu(regs) == 0) {
648 emulate_single_step(regs);
651 #endif /* CONFIG_MATH_EMULATION */
653 if (reason & REASON_FP) {
654 /* IEEE FP exception */
658 /* We must make sure the FP state is consistent with
662 if (regs->msr & MSR_FP)
666 fpscr = current->thread.fpscr.val;
667 fpscr &= fpscr << 22; /* mask summary bits with enables */
668 if (fpscr & FPSCR_VX)
670 else if (fpscr & FPSCR_OX)
672 else if (fpscr & FPSCR_UX)
674 else if (fpscr & FPSCR_ZX)
676 else if (fpscr & FPSCR_XX)
678 _exception(SIGFPE, regs, code, regs->nip);
682 if (reason & REASON_TRAP) {
684 if (debugger_bpt(regs))
686 if (check_bug_trap(regs)) {
690 _exception(SIGTRAP, regs, TRAP_BRKPT, 0);
694 /* Try to emulate it if we should. */
695 if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
696 switch (emulate_instruction(regs)) {
699 emulate_single_step(regs);
702 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
707 if (reason & REASON_PRIVILEGED)
708 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
710 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
713 void single_step_exception(struct pt_regs *regs)
715 regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */
716 if (debugger_sstep(regs))
718 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
721 void alignment_exception(struct pt_regs *regs)
725 fixed = fix_alignment(regs);
727 regs->nip += 4; /* skip over emulated instruction */
728 emulate_single_step(regs);
731 if (fixed == -EFAULT) {
732 /* fixed == -EFAULT means the operand address was bad */
734 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->dar);
736 bad_page_fault(regs, regs->dar, SIGSEGV);
739 _exception(SIGBUS, regs, BUS_ADRALN, regs->dar);
742 void StackOverflow(struct pt_regs *regs)
744 printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
745 current, regs->gpr[1]);
748 panic("kernel stack overflow");
751 void nonrecoverable_exception(struct pt_regs *regs)
753 printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
754 regs->nip, regs->msr);
756 die("nonrecoverable exception", regs, SIGKILL);
759 void trace_syscall(struct pt_regs *regs)
761 printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
762 current, current->pid, regs->nip, regs->link, regs->gpr[0],
763 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
767 void SoftwareEmulation(struct pt_regs *regs)
769 extern int do_mathemu(struct pt_regs *);
770 extern int Soft_emulate_8xx(struct pt_regs *);
773 CHECK_FULL_REGS(regs);
775 if (!user_mode(regs)) {
777 die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
780 #ifdef CONFIG_MATH_EMULATION
781 errcode = do_mathemu(regs);
783 errcode = Soft_emulate_8xx(regs);
787 _exception(SIGFPE, regs, 0, 0);
788 else if (errcode == -EFAULT)
789 _exception(SIGSEGV, regs, 0, 0);
791 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
793 emulate_single_step(regs);
795 #endif /* CONFIG_8xx */
797 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
799 void DebugException(struct pt_regs *regs, unsigned long debug_status)
801 if (debug_status & DBSR_IC) { /* instruction completion */
802 regs->msr &= ~MSR_DE;
803 if (user_mode(regs)) {
804 current->thread.dbcr0 &= ~DBCR0_IC;
806 /* Disable instruction completion */
807 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
808 /* Clear the instruction completion event */
809 mtspr(SPRN_DBSR, DBSR_IC);
810 if (debugger_sstep(regs))
813 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
816 #endif /* CONFIG_4xx || CONFIG_BOOKE */
818 #if !defined(CONFIG_TAU_INT)
819 void TAUException(struct pt_regs *regs)
821 printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
822 regs->nip, regs->msr, regs->trap, print_tainted());
824 #endif /* CONFIG_INT_TAU */
827 * FP unavailable trap from kernel - print a message, but let
828 * the task use FP in the kernel until it returns to user mode.
830 void kernel_fp_unavailable_exception(struct pt_regs *regs)
833 printk(KERN_ERR "floating point used in kernel (task=%p, pc=%lx)\n",
837 void altivec_unavailable_exception(struct pt_regs *regs)
839 static int kernel_altivec_count;
841 #ifndef CONFIG_ALTIVEC
842 if (user_mode(regs)) {
843 /* A user program has executed an altivec instruction,
844 but this kernel doesn't support altivec. */
845 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
849 /* The kernel has executed an altivec instruction without
850 first enabling altivec. Whinge but let it do it. */
851 if (++kernel_altivec_count < 10)
852 printk(KERN_ERR "AltiVec used in kernel (task=%p, pc=%lx)\n",
854 regs->msr |= MSR_VEC;
857 #ifdef CONFIG_ALTIVEC
858 void altivec_assist_exception(struct pt_regs *regs)
863 if (regs->msr & MSR_VEC)
864 giveup_altivec(current);
866 if (!user_mode(regs)) {
867 printk(KERN_ERR "altivec assist exception in kernel mode"
868 " at %lx\n", regs->nip);
870 die("altivec assist exception", regs, SIGFPE);
874 err = emulate_altivec(regs);
876 regs->nip += 4; /* skip emulated instruction */
877 emulate_single_step(regs);
881 if (err == -EFAULT) {
882 /* got an error reading the instruction */
883 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
885 /* didn't recognize the instruction */
886 /* XXX quick hack for now: set the non-Java bit in the VSCR */
887 printk(KERN_ERR "unrecognized altivec instruction "
888 "in %s at %lx\n", current->comm, regs->nip);
889 current->thread.vscr.u[3] |= 0x10000;
892 #endif /* CONFIG_ALTIVEC */
895 void performance_monitor_exception(struct pt_regs *regs)
901 #ifdef CONFIG_FSL_BOOKE
902 void CacheLockingException(struct pt_regs *regs, unsigned long address,
903 unsigned long error_code)
905 /* We treat cache locking instructions from the user
906 * as priv ops, in the future we could try to do
909 if (error_code & (ESR_DLK|ESR_ILK))
910 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
913 #endif /* CONFIG_FSL_BOOKE */
916 void SPEFloatingPointException(struct pt_regs *regs)
918 unsigned long spefscr;
922 spefscr = current->thread.spefscr;
923 fpexc_mode = current->thread.fpexc_mode;
925 /* Hardware does not neccessarily set sticky
926 * underflow/overflow/invalid flags */
927 if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
929 spefscr |= SPEFSCR_FOVFS;
931 else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
933 spefscr |= SPEFSCR_FUNFS;
935 else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
937 else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
939 spefscr |= SPEFSCR_FINVS;
941 else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
944 current->thread.spefscr = spefscr;
946 _exception(SIGFPE, regs, code, regs->nip);
951 #ifdef CONFIG_BOOKE_WDT
953 * Default handler for a Watchdog exception,
954 * spins until a reboot occurs
956 void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
958 /* Generic WatchdogHandler, implement your own */
959 mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
963 void WatchdogException(struct pt_regs *regs)
965 printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
966 WatchdogHandler(regs);
970 void __init trap_init(void)