2 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Modified by Cort Dougan (cort@cs.nmt.edu)
10 * and Paul Mackerras (paulus@samba.org)
14 * This file handles the architecture-dependent parts of hardware exceptions
17 #include <linux/config.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/slab.h>
25 #include <linux/user.h>
26 #include <linux/a.out.h>
27 #include <linux/interrupt.h>
28 #include <linux/init.h>
29 #include <linux/module.h>
30 #include <linux/delay.h>
31 #include <linux/kprobes.h>
32 #include <asm/kdebug.h>
34 #include <linux/ptrace.h>
35 #include <linux/prctl.h>
38 #include <asm/pgtable.h>
39 #include <asm/uaccess.h>
40 #include <asm/system.h>
45 #ifdef CONFIG_PMAC_BACKLIGHT
46 #include <asm/backlight.h>
48 #include <asm/perfmon.h>
51 #include <asm/processor.h>
52 #include <asm/ppcdebug.h>
54 #include <asm/systemcfg.h>
55 #include <asm/machdep.h>
60 #define __KPROBES __kprobes
65 #ifdef CONFIG_DEBUGGER
66 int (*__debugger)(struct pt_regs *regs);
67 int (*__debugger_ipi)(struct pt_regs *regs);
68 int (*__debugger_bpt)(struct pt_regs *regs);
69 int (*__debugger_sstep)(struct pt_regs *regs);
70 int (*__debugger_iabr_match)(struct pt_regs *regs);
71 int (*__debugger_dabr_match)(struct pt_regs *regs);
72 int (*__debugger_fault_handler)(struct pt_regs *regs);
74 EXPORT_SYMBOL(__debugger);
75 EXPORT_SYMBOL(__debugger_ipi);
76 EXPORT_SYMBOL(__debugger_bpt);
77 EXPORT_SYMBOL(__debugger_sstep);
78 EXPORT_SYMBOL(__debugger_iabr_match);
79 EXPORT_SYMBOL(__debugger_dabr_match);
80 EXPORT_SYMBOL(__debugger_fault_handler);
83 struct notifier_block *powerpc_die_chain;
84 static DEFINE_SPINLOCK(die_notifier_lock);
86 int register_die_notifier(struct notifier_block *nb)
91 spin_lock_irqsave(&die_notifier_lock, flags);
92 err = notifier_chain_register(&powerpc_die_chain, nb);
93 spin_unlock_irqrestore(&die_notifier_lock, flags);
98 * Trap & Exception support
101 static DEFINE_SPINLOCK(die_lock);
103 int die(const char *str, struct pt_regs *regs, long err)
105 static int die_counter;
112 spin_lock_irq(&die_lock);
114 #if defined(CONFIG_PPC32) && defined(CONFIG_PMAC_BACKLIGHT)
115 if (_machine == _MACH_Pmac) {
116 set_backlight_enable(1);
117 set_backlight_level(BACKLIGHT_MAX);
120 printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
121 #ifdef CONFIG_PREEMPT
126 printk("SMP NR_CPUS=%d ", NR_CPUS);
129 #ifdef CONFIG_DEBUG_PAGEALLOC
130 printk("DEBUG_PAGEALLOC ");
138 switch (systemcfg->platform) {
139 case PLATFORM_PSERIES:
143 case PLATFORM_PSERIES_LPAR:
144 printk("PSERIES LPAR ");
147 case PLATFORM_ISERIES_LPAR:
148 printk("ISERIES LPAR ");
151 case PLATFORM_POWERMAC:
166 spin_unlock_irq(&die_lock);
169 panic("Fatal exception in interrupt");
173 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
176 panic("Fatal exception");
187 void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
191 if (!user_mode(regs)) {
192 if (die("Exception in kernel mode", regs, signr))
196 memset(&info, 0, sizeof(info));
197 info.si_signo = signr;
199 info.si_addr = (void __user *) addr;
200 force_sig_info(signr, &info, current);
204 * Init gets no signals that it doesn't have a handler for.
205 * That's all very well, but if it has caused a synchronous
206 * exception and we ignore the resulting signal, it will just
207 * generate the same exception over and over again and we get
208 * nowhere. Better to kill it and let the kernel panic.
210 if (current->pid == 1) {
211 __sighandler_t handler;
213 spin_lock_irq(¤t->sighand->siglock);
214 handler = current->sighand->action[signr-1].sa.sa_handler;
215 spin_unlock_irq(¤t->sighand->siglock);
216 if (handler == SIG_DFL) {
217 /* init has generated a synchronous exception
218 and it doesn't have a handler for the signal */
219 printk(KERN_CRIT "init has generated signal %d "
220 "but has no handler for it\n", signr);
228 void system_reset_exception(struct pt_regs *regs)
230 /* See if any machine dependent calls */
231 if (ppc_md.system_reset_exception)
232 ppc_md.system_reset_exception(regs);
234 die("System Reset", regs, 0);
236 /* Must die if the interrupt is not recoverable */
237 if (!(regs->msr & MSR_RI))
238 panic("Unrecoverable System Reset");
240 /* What should we do here? We could issue a shutdown or hard reset. */
246 * I/O accesses can cause machine checks on powermacs.
247 * Check if the NIP corresponds to the address of a sync
248 * instruction for which there is an entry in the exception
250 * Note that the 601 only takes a machine check on TEA
251 * (transfer error ack) signal assertion, and does not
252 * set any of the top 16 bits of SRR1.
255 static inline int check_io_access(struct pt_regs *regs)
257 #ifdef CONFIG_PPC_PMAC
258 unsigned long msr = regs->msr;
259 const struct exception_table_entry *entry;
260 unsigned int *nip = (unsigned int *)regs->nip;
262 if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
263 && (entry = search_exception_tables(regs->nip)) != NULL) {
265 * Check that it's a sync instruction, or somewhere
266 * in the twi; isync; nop sequence that inb/inw/inl uses.
267 * As the address is in the exception table
268 * we should be able to read the instr there.
269 * For the debug message, we look at the preceding
272 if (*nip == 0x60000000) /* nop */
274 else if (*nip == 0x4c00012c) /* isync */
276 if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
281 rb = (*nip >> 11) & 0x1f;
282 printk(KERN_DEBUG "%s bad port %lx at %p\n",
283 (*nip & 0x100)? "OUT to": "IN from",
284 regs->gpr[rb] - _IO_BASE, nip);
286 regs->nip = entry->fixup;
290 #endif /* CONFIG_PPC_PMAC */
293 #endif /* CONFIG_PPC32 */
295 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
297 /* On 4xx, the reason for the machine check or program exception
299 #define get_reason(regs) ((regs)->dsisr)
300 #ifndef CONFIG_FSL_BOOKE
301 #define get_mc_reason(regs) ((regs)->dsisr)
303 #define get_mc_reason(regs) (mfspr(SPRN_MCSR))
305 #define REASON_FP ESR_FP
306 #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
307 #define REASON_PRIVILEGED ESR_PPR
308 #define REASON_TRAP ESR_PTR
310 /* single-step stuff */
311 #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
312 #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
316 /* On non-4xx, the reason for the machine check or program
317 exception is in the MSR. */
318 #define get_reason(regs) ((regs)->msr)
319 #define get_mc_reason(regs) ((regs)->msr)
320 #define REASON_FP 0x100000
321 #define REASON_ILLEGAL 0x80000
322 #define REASON_PRIVILEGED 0x40000
323 #define REASON_TRAP 0x20000
325 #define single_stepping(regs) ((regs)->msr & MSR_SE)
326 #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
331 * This is "fall-back" implementation for configurations
332 * which don't provide platform-specific machine check info
334 void __attribute__ ((weak))
335 platform_machine_check(struct pt_regs *regs)
340 void machine_check_exception(struct pt_regs *regs)
345 /* See if any machine dependent calls */
346 if (ppc_md.machine_check_exception)
347 recover = ppc_md.machine_check_exception(regs);
352 unsigned long reason = get_mc_reason(regs);
354 if (user_mode(regs)) {
356 _exception(SIGBUS, regs, BUS_ADRERR, regs->nip);
360 #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
361 /* the qspan pci read routines can cause machine checks -- Cort */
362 bad_page_fault(regs, regs->dar, SIGBUS);
366 if (debugger_fault_handler(regs)) {
371 if (check_io_access(regs))
374 #if defined(CONFIG_4xx) && !defined(CONFIG_440A)
375 if (reason & ESR_IMCP) {
376 printk("Instruction");
377 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
380 printk(" machine check in kernel mode.\n");
381 #elif defined(CONFIG_440A)
382 printk("Machine check in kernel mode.\n");
383 if (reason & ESR_IMCP){
384 printk("Instruction Synchronous Machine Check exception\n");
385 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
388 u32 mcsr = mfspr(SPRN_MCSR);
390 printk("Instruction Read PLB Error\n");
392 printk("Data Read PLB Error\n");
394 printk("Data Write PLB Error\n");
395 if (mcsr & MCSR_TLBP)
396 printk("TLB Parity Error\n");
397 if (mcsr & MCSR_ICP){
398 flush_instruction_cache();
399 printk("I-Cache Parity Error\n");
401 if (mcsr & MCSR_DCSP)
402 printk("D-Cache Search Parity Error\n");
403 if (mcsr & MCSR_DCFP)
404 printk("D-Cache Flush Parity Error\n");
405 if (mcsr & MCSR_IMPE)
406 printk("Machine Check exception is imprecise\n");
409 mtspr(SPRN_MCSR, mcsr);
411 #elif defined (CONFIG_E500)
412 printk("Machine check in kernel mode.\n");
413 printk("Caused by (from MCSR=%lx): ", reason);
415 if (reason & MCSR_MCP)
416 printk("Machine Check Signal\n");
417 if (reason & MCSR_ICPERR)
418 printk("Instruction Cache Parity Error\n");
419 if (reason & MCSR_DCP_PERR)
420 printk("Data Cache Push Parity Error\n");
421 if (reason & MCSR_DCPERR)
422 printk("Data Cache Parity Error\n");
423 if (reason & MCSR_GL_CI)
424 printk("Guarded Load or Cache-Inhibited stwcx.\n");
425 if (reason & MCSR_BUS_IAERR)
426 printk("Bus - Instruction Address Error\n");
427 if (reason & MCSR_BUS_RAERR)
428 printk("Bus - Read Address Error\n");
429 if (reason & MCSR_BUS_WAERR)
430 printk("Bus - Write Address Error\n");
431 if (reason & MCSR_BUS_IBERR)
432 printk("Bus - Instruction Data Error\n");
433 if (reason & MCSR_BUS_RBERR)
434 printk("Bus - Read Data Bus Error\n");
435 if (reason & MCSR_BUS_WBERR)
436 printk("Bus - Read Data Bus Error\n");
437 if (reason & MCSR_BUS_IPERR)
438 printk("Bus - Instruction Parity Error\n");
439 if (reason & MCSR_BUS_RPERR)
440 printk("Bus - Read Parity Error\n");
441 #elif defined (CONFIG_E200)
442 printk("Machine check in kernel mode.\n");
443 printk("Caused by (from MCSR=%lx): ", reason);
445 if (reason & MCSR_MCP)
446 printk("Machine Check Signal\n");
447 if (reason & MCSR_CP_PERR)
448 printk("Cache Push Parity Error\n");
449 if (reason & MCSR_CPERR)
450 printk("Cache Parity Error\n");
451 if (reason & MCSR_EXCP_ERR)
452 printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
453 if (reason & MCSR_BUS_IRERR)
454 printk("Bus - Read Bus Error on instruction fetch\n");
455 if (reason & MCSR_BUS_DRERR)
456 printk("Bus - Read Bus Error on data load\n");
457 if (reason & MCSR_BUS_WRERR)
458 printk("Bus - Write Bus Error on buffered store or cache line push\n");
459 #else /* !CONFIG_4xx && !CONFIG_E500 && !CONFIG_E200 */
460 printk("Machine check in kernel mode.\n");
461 printk("Caused by (from SRR1=%lx): ", reason);
462 switch (reason & 0x601F0000) {
464 printk("Machine check signal\n");
466 case 0: /* for 601 */
468 case 0x140000: /* 7450 MSS error and TEA */
469 printk("Transfer error ack signal\n");
472 printk("Data parity error signal\n");
475 printk("Address parity error signal\n");
478 printk("L1 Data Cache error\n");
481 printk("L1 Instruction Cache error\n");
484 printk("L2 data cache parity error\n");
487 printk("Unknown values in msr\n");
489 #endif /* CONFIG_4xx */
492 * Optional platform-provided routine to print out
493 * additional info, e.g. bus error registers.
495 platform_machine_check(regs);
496 #endif /* CONFIG_PPC32 */
498 if (debugger_fault_handler(regs))
500 die("Machine check", regs,
508 /* Must die if the interrupt is not recoverable */
509 if (!(regs->msr & MSR_RI))
510 panic("Unrecoverable Machine check");
514 void SMIException(struct pt_regs *regs)
516 die("System Management Interrupt", regs, SIGABRT);
520 void unknown_exception(struct pt_regs *regs)
522 printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
523 regs->nip, regs->msr, regs->trap);
525 _exception(SIGTRAP, regs, 0, 0);
528 void instruction_breakpoint_exception(struct pt_regs *regs)
530 if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5,
531 5, SIGTRAP) == NOTIFY_STOP)
533 if (debugger_iabr_match(regs))
535 _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
539 void RunModeException(struct pt_regs *regs)
541 _exception(SIGTRAP, regs, 0, 0);
545 void __KPROBES single_step_exception(struct pt_regs *regs)
548 regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */
550 regs->msr &= ~MSR_SE; /* Turn off 'trace' bit */
553 if (notify_die(DIE_SSTEP, "single_step", regs, 5,
554 5, SIGTRAP) == NOTIFY_STOP)
556 if (debugger_sstep(regs))
559 _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
563 * After we have successfully emulated an instruction, we have to
564 * check if the instruction was being single-stepped, and if so,
565 * pretend we got a single-step exception. This was pointed out
566 * by Kumar Gala. -- paulus
568 static inline void emulate_single_step(struct pt_regs *regs)
570 if (single_stepping(regs)) {
572 clear_single_step(regs);
573 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
575 single_step_exception(regs);
580 static void parse_fpe(struct pt_regs *regs)
586 /* We must make sure the FP state is consistent with
590 if (regs->msr & MSR_FP)
594 flush_fp_to_thread(current);
597 fpscr = current->thread.fpscr;
599 /* Invalid operation */
600 if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
604 else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX))
608 else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX))
612 else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX))
616 else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX))
619 _exception(SIGFPE, regs, code, regs->nip);
623 * Illegal instruction emulation support. Originally written to
624 * provide the PVR to user applications using the mfspr rd, PVR.
625 * Return non-zero if we can't emulate, or -EFAULT if the associated
626 * memory access caused an access fault. Return zero on success.
628 * There are a couple of ways to do this, either "decode" the instruction
629 * or directly match lots of bits. In this case, matching lots of
630 * bits is faster and easier.
632 #define INST_MFSPR_PVR 0x7c1f42a6
633 #define INST_MFSPR_PVR_MASK 0xfc1fffff
635 #define INST_DCBA 0x7c0005ec
636 #define INST_DCBA_MASK 0x7c0007fe
638 #define INST_MCRXR 0x7c000400
639 #define INST_MCRXR_MASK 0x7c0007fe
643 #define INST_STRING 0x7c00042a
644 #define INST_STRING_MASK 0x7c0007fe
645 #define INST_STRING_GEN_MASK 0x7c00067e
646 #define INST_LSWI 0x7c0004aa
647 #define INST_LSWX 0x7c00042a
648 #define INST_STSWI 0x7c0005aa
649 #define INST_STSWX 0x7c00052a
651 static int emulate_string_inst(struct pt_regs *regs, u32 instword)
653 u8 rT = (instword >> 21) & 0x1f;
654 u8 rA = (instword >> 16) & 0x1f;
655 u8 NB_RB = (instword >> 11) & 0x1f;
660 /* Early out if we are an invalid form of lswx */
661 if ((instword & INST_STRING_MASK) == INST_LSWX)
662 if ((rT == rA) || (rT == NB_RB))
665 EA = (rA == 0) ? 0 : regs->gpr[rA];
667 switch (instword & INST_STRING_MASK) {
671 num_bytes = regs->xer & 0x7f;
675 num_bytes = (NB_RB == 0) ? 32 : NB_RB;
681 while (num_bytes != 0)
684 u32 shift = 8 * (3 - (pos & 0x3));
686 switch ((instword & INST_STRING_MASK)) {
689 if (get_user(val, (u8 __user *)EA))
691 /* first time updating this reg,
695 regs->gpr[rT] |= val << shift;
699 val = regs->gpr[rT] >> shift;
700 if (put_user(val, (u8 __user *)EA))
704 /* move EA to next address */
708 /* manage our position within the register */
718 #endif /* CONFIG_PPC32 */
720 static int emulate_instruction(struct pt_regs *regs)
725 if (!user_mode(regs))
727 CHECK_FULL_REGS(regs);
729 if (get_user(instword, (u32 __user *)(regs->nip)))
732 /* Emulate the mfspr rD, PVR. */
733 if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
734 rd = (instword >> 21) & 0x1f;
735 regs->gpr[rd] = mfspr(SPRN_PVR);
739 /* Emulating the dcba insn is just a no-op. */
740 if ((instword & INST_DCBA_MASK) == INST_DCBA) {
746 "process %d (%s) uses obsolete 'dcba' insn\n",
747 current->pid, current->comm);
750 #endif /* CONFIG_PPC64 */
754 /* Emulate the mcrxr insn. */
755 if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
756 unsigned int shift = (instword >> 21) & 0x1c;
757 unsigned long msk = 0xf0000000UL >> shift;
763 "process %d (%s) uses obsolete 'mcrxr' insn\n",
764 current->pid, current->comm);
768 regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
769 regs->xer &= ~0xf0000000UL;
774 /* Emulate load/store string insn. */
775 if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
776 return emulate_string_inst(regs, instword);
783 * Look through the list of trap instructions that are used for BUG(),
784 * BUG_ON() and WARN_ON() and see if we hit one. At this point we know
785 * that the exception was caused by a trap instruction of some kind.
786 * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
789 extern struct bug_entry __start___bug_table[], __stop___bug_table[];
791 #ifndef CONFIG_MODULES
792 #define module_find_bug(x) NULL
795 struct bug_entry *find_bug(unsigned long bugaddr)
797 struct bug_entry *bug;
799 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
800 if (bugaddr == bug->bug_addr)
802 return module_find_bug(bugaddr);
805 static int check_bug_trap(struct pt_regs *regs)
807 struct bug_entry *bug;
810 if (regs->msr & MSR_PR)
811 return 0; /* not in kernel */
812 addr = regs->nip; /* address of trap instruction */
813 if (addr < PAGE_OFFSET)
815 bug = find_bug(regs->nip);
818 if (bug->line & BUG_WARNING_TRAP) {
819 /* this is a WARN_ON rather than BUG/BUG_ON */
820 #if defined(CONFIG_PPC32) && defined(CONFIG_XMON)
821 xmon_printf(KERN_ERR "Badness in %s at %s:%d\n",
822 bug->function, bug->file,
823 bug->line & ~BUG_WARNING_TRAP);
825 printk(KERN_ERR "Badness in %s at %s:%d\n",
826 bug->function, bug->file,
827 bug->line & ~BUG_WARNING_TRAP);
831 show_stack(current, (void *)regs->gpr[1]);
835 #if defined(CONFIG_PPC32) && defined(CONFIG_XMON)
836 xmon_printf(KERN_CRIT "kernel BUG in %s at %s:%d!\n",
837 bug->function, bug->file, bug->line);
840 printk(KERN_CRIT "kernel BUG in %s at %s:%d!\n",
841 bug->function, bug->file, bug->line);
846 void __KPROBES program_check_exception(struct pt_regs *regs)
848 unsigned int reason = get_reason(regs);
849 #if defined(CONFIG_PPC32) && defined(CONFIG_MATH_EMULATION)
850 extern int do_mathemu(struct pt_regs *regs);
852 /* (reason & REASON_ILLEGAL) would be the obvious thing here,
853 * but there seems to be a hardware bug on the 405GP (RevD)
854 * that means ESR is sometimes set incorrectly - either to
855 * ESR_DST (!?) or 0. In the process of chasing this with the
856 * hardware people - not sure if it can happen on any illegal
857 * instruction or only on FP instructions, whether there is a
858 * pattern to occurences etc. -dgibson 31/Mar/2003 */
859 if (!(reason & REASON_TRAP) && do_mathemu(regs) == 0) {
860 emulate_single_step(regs);
866 if (debugger_fault_handler(regs))
870 if (reason & REASON_FP) {
871 /* IEEE FP exception */
873 } else if (reason & REASON_TRAP) {
876 if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
880 if (debugger_bpt(regs))
882 if (check_bug_trap(regs)) {
886 _exception(SIGTRAP, regs, TRAP_BRKPT,
895 if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED))
898 /* Privileged or illegal instruction; try to emulate it. */
899 switch (emulate_instruction(regs)) {
902 emulate_single_step(regs);
905 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
908 if (reason & REASON_PRIVILEGED)
909 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
911 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
917 void alignment_exception(struct pt_regs *regs)
921 fixed = fix_alignment(regs);
924 regs->nip += 4; /* skip over emulated instruction */
925 emulate_single_step(regs);
929 /* Operand address was bad */
930 if (fixed == -EFAULT) {
932 _exception(SIGSEGV, regs,
940 /* Search exception table */
941 bad_page_fault(regs, regs->dar, SIGSEGV);
944 _exception(SIGBUS, regs, BUS_ADRALN,
954 void StackOverflow(struct pt_regs *regs)
956 printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
957 current, regs->gpr[1]);
960 panic("kernel stack overflow");
963 void nonrecoverable_exception(struct pt_regs *regs)
965 printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
966 regs->nip, regs->msr);
968 die("nonrecoverable exception", regs, SIGKILL);
971 void trace_syscall(struct pt_regs *regs)
973 printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
974 current, current->pid, regs->nip, regs->link, regs->gpr[0],
975 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
977 #endif /* CONFIG_PPC32 */
980 void kernel_fp_unavailable_exception(struct pt_regs *regs)
982 printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
983 "%lx at %lx\n", regs->trap, regs->nip);
984 die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
988 void altivec_unavailable_exception(struct pt_regs *regs)
990 #if !defined(CONFIG_ALTIVEC) || defined(CONFIG_PPC64)
991 if (user_mode(regs)) {
992 /* A user program has executed an altivec instruction,
993 but this kernel doesn't support altivec. */
994 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
1000 static int kernel_altivec_count;
1002 /* The kernel has executed an altivec instruction without
1003 first enabling altivec. Whinge but let it do it. */
1004 if (++kernel_altivec_count < 10)
1005 printk(KERN_ERR "AltiVec used in kernel (task=%p, pc=%lx)\n",
1006 current, regs->nip);
1007 regs->msr |= MSR_VEC;
1010 printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
1011 "%lx at %lx\n", regs->trap, regs->nip);
1012 die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
1017 extern perf_irq_t perf_irq;
1020 #if defined(CONFIG_PPC64) || defined(CONFIG_E500)
1021 void performance_monitor_exception(struct pt_regs *regs)
1028 #if defined(CONFIG_PPC32) && defined(CONFIG_8xx)
1029 void SoftwareEmulation(struct pt_regs *regs)
1031 extern int do_mathemu(struct pt_regs *);
1032 extern int Soft_emulate_8xx(struct pt_regs *);
1035 CHECK_FULL_REGS(regs);
1037 if (!user_mode(regs)) {
1039 die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
1042 #ifdef CONFIG_MATH_EMULATION
1043 errcode = do_mathemu(regs);
1045 errcode = Soft_emulate_8xx(regs);
1049 _exception(SIGFPE, regs, 0, 0);
1050 else if (errcode == -EFAULT)
1051 _exception(SIGSEGV, regs, 0, 0);
1053 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
1055 emulate_single_step(regs);
1057 #endif /* defined(CONFIG_PPC32) && defined(CONFIG_8xx) */
1060 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
1062 void DebugException(struct pt_regs *regs, unsigned long debug_status)
1064 if (debug_status & DBSR_IC) { /* instruction completion */
1065 regs->msr &= ~MSR_DE;
1066 if (user_mode(regs)) {
1067 current->thread.dbcr0 &= ~DBCR0_IC;
1069 /* Disable instruction completion */
1070 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
1071 /* Clear the instruction completion event */
1072 mtspr(SPRN_DBSR, DBSR_IC);
1073 if (debugger_sstep(regs))
1076 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
1079 #endif /* CONFIG_4xx || CONFIG_BOOKE */
1081 #if !defined(CONFIG_TAU_INT)
1082 void TAUException(struct pt_regs *regs)
1084 printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
1085 regs->nip, regs->msr, regs->trap, print_tainted());
1087 #endif /* CONFIG_INT_TAU */
1088 #endif /* CONFIG_PPC32*/
1090 #ifdef CONFIG_ALTIVEC
1091 void altivec_assist_exception(struct pt_regs *regs)
1100 if (regs->msr & MSR_VEC)
1101 giveup_altivec(current);
1104 if (!user_mode(regs)) {
1105 printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
1106 " at %lx\n", regs->nip);
1111 "Altivec assist exception", regs, SIGILL);
1115 flush_altivec_to_thread(current);
1116 #endif /* CONFIG_PPC64 */
1118 err = emulate_altivec(regs);
1120 regs->nip += 4; /* skip emulated instruction */
1121 emulate_single_step(regs);
1125 if (err == -EFAULT) {
1126 /* got an error reading the instruction */
1128 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
1130 info.si_signo = SIGSEGV;
1132 info.si_code = SEGV_MAPERR;
1133 info.si_addr = (void __user *) regs->nip;
1134 force_sig_info(SIGSEGV, &info, current);
1137 /* didn't recognize the instruction */
1138 /* XXX quick hack for now: set the non-Java bit in the VSCR */
1139 if (printk_ratelimit())
1140 printk(KERN_ERR "Unrecognized altivec instruction "
1141 "in %s at %lx\n", current->comm, regs->nip);
1142 current->thread.vscr.u[3] |= 0x10000;
1145 #endif /* CONFIG_ALTIVEC */
1148 #ifdef CONFIG_FSL_BOOKE
1149 void CacheLockingException(struct pt_regs *regs, unsigned long address,
1150 unsigned long error_code)
1152 /* We treat cache locking instructions from the user
1153 * as priv ops, in the future we could try to do
1156 if (error_code & (ESR_DLK|ESR_ILK))
1157 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
1160 #endif /* CONFIG_FSL_BOOKE */
1163 void SPEFloatingPointException(struct pt_regs *regs)
1165 unsigned long spefscr;
1169 spefscr = current->thread.spefscr;
1170 fpexc_mode = current->thread.fpexc_mode;
1172 /* Hardware does not neccessarily set sticky
1173 * underflow/overflow/invalid flags */
1174 if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
1176 spefscr |= SPEFSCR_FOVFS;
1178 else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
1180 spefscr |= SPEFSCR_FUNFS;
1182 else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
1184 else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
1186 spefscr |= SPEFSCR_FINVS;
1188 else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
1191 current->thread.spefscr = spefscr;
1193 _exception(SIGFPE, regs, code, regs->nip);
1197 #endif /* CONFIG_PPC32 */
1201 * We enter here if we get an unrecoverable exception, that is, one
1202 * that happened at a point where the RI (recoverable interrupt) bit
1203 * in the MSR is 0. This indicates that SRR0/1 are live, and that
1204 * we therefore lost state by taking this exception.
1206 void unrecoverable_exception(struct pt_regs *regs)
1208 printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
1209 regs->trap, regs->nip);
1210 die("Unrecoverable exception", regs, SIGABRT);
1212 #endif /* CONFIG_PPC64 */
1215 #ifdef CONFIG_BOOKE_WDT
1217 * Default handler for a Watchdog exception,
1218 * spins until a reboot occurs
1220 void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
1222 /* Generic WatchdogHandler, implement your own */
1223 mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
1227 void WatchdogException(struct pt_regs *regs)
1229 printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
1230 WatchdogHandler(regs);
1233 #endif /* CONFIG_PPC32 */
1237 * We enter here if we discover during exception entry that we are
1238 * running in supervisor mode with a userspace value in the stack pointer.
1240 void kernel_bad_stack(struct pt_regs *regs)
1242 printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
1243 regs->gpr[1], regs->nip);
1244 die("Bad kernel stack pointer", regs, SIGABRT);
1248 void __init trap_init(void)