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/ptrace.h>
25 #include <linux/slab.h>
26 #include <linux/user.h>
27 #include <linux/a.out.h>
28 #include <linux/interrupt.h>
29 #include <linux/init.h>
30 #include <linux/module.h>
31 #include <linux/prctl.h>
32 #include <linux/delay.h>
33 #include <linux/kprobes.h>
35 #include <asm/kdebug.h>
36 #include <asm/pgtable.h>
37 #include <asm/uaccess.h>
38 #include <asm/system.h>
40 #include <asm/machdep.h>
47 #ifdef CONFIG_PMAC_BACKLIGHT
48 #include <asm/backlight.h>
51 #include <asm/firmware.h>
52 #include <asm/processor.h>
53 #include <asm/systemcfg.h>
56 #ifdef CONFIG_PPC64 /* XXX */
57 #define _IO_BASE pci_io_base
60 #ifdef CONFIG_DEBUGGER
61 int (*__debugger)(struct pt_regs *regs);
62 int (*__debugger_ipi)(struct pt_regs *regs);
63 int (*__debugger_bpt)(struct pt_regs *regs);
64 int (*__debugger_sstep)(struct pt_regs *regs);
65 int (*__debugger_iabr_match)(struct pt_regs *regs);
66 int (*__debugger_dabr_match)(struct pt_regs *regs);
67 int (*__debugger_fault_handler)(struct pt_regs *regs);
69 EXPORT_SYMBOL(__debugger);
70 EXPORT_SYMBOL(__debugger_ipi);
71 EXPORT_SYMBOL(__debugger_bpt);
72 EXPORT_SYMBOL(__debugger_sstep);
73 EXPORT_SYMBOL(__debugger_iabr_match);
74 EXPORT_SYMBOL(__debugger_dabr_match);
75 EXPORT_SYMBOL(__debugger_fault_handler);
78 struct notifier_block *powerpc_die_chain;
79 static DEFINE_SPINLOCK(die_notifier_lock);
81 int register_die_notifier(struct notifier_block *nb)
86 spin_lock_irqsave(&die_notifier_lock, flags);
87 err = notifier_chain_register(&powerpc_die_chain, nb);
88 spin_unlock_irqrestore(&die_notifier_lock, flags);
93 * Trap & Exception support
96 static DEFINE_SPINLOCK(die_lock);
98 int die(const char *str, struct pt_regs *regs, long err)
100 static int die_counter;
107 spin_lock_irq(&die_lock);
109 #ifdef CONFIG_PMAC_BACKLIGHT
110 if (_machine == _MACH_Pmac) {
111 set_backlight_enable(1);
112 set_backlight_level(BACKLIGHT_MAX);
115 printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
116 #ifdef CONFIG_PREEMPT
121 printk("SMP NR_CPUS=%d ", NR_CPUS);
124 #ifdef CONFIG_DEBUG_PAGEALLOC
125 printk("DEBUG_PAGEALLOC ");
133 switch (systemcfg->platform) {
134 case PLATFORM_PSERIES:
138 case PLATFORM_PSERIES_LPAR:
139 printk("PSERIES LPAR ");
142 case PLATFORM_ISERIES_LPAR:
143 printk("ISERIES LPAR ");
146 case PLATFORM_POWERMAC:
161 spin_unlock_irq(&die_lock);
164 panic("Fatal exception in interrupt");
168 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
171 panic("Fatal exception");
178 void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
182 if (!user_mode(regs)) {
183 if (die("Exception in kernel mode", regs, signr))
187 memset(&info, 0, sizeof(info));
188 info.si_signo = signr;
190 info.si_addr = (void __user *) addr;
191 force_sig_info(signr, &info, current);
194 * Init gets no signals that it doesn't have a handler for.
195 * That's all very well, but if it has caused a synchronous
196 * exception and we ignore the resulting signal, it will just
197 * generate the same exception over and over again and we get
198 * nowhere. Better to kill it and let the kernel panic.
200 if (current->pid == 1) {
201 __sighandler_t handler;
203 spin_lock_irq(¤t->sighand->siglock);
204 handler = current->sighand->action[signr-1].sa.sa_handler;
205 spin_unlock_irq(¤t->sighand->siglock);
206 if (handler == SIG_DFL) {
207 /* init has generated a synchronous exception
208 and it doesn't have a handler for the signal */
209 printk(KERN_CRIT "init has generated signal %d "
210 "but has no handler for it\n", signr);
217 void system_reset_exception(struct pt_regs *regs)
219 /* See if any machine dependent calls */
220 if (ppc_md.system_reset_exception)
221 ppc_md.system_reset_exception(regs);
223 die("System Reset", regs, SIGABRT);
225 /* Must die if the interrupt is not recoverable */
226 if (!(regs->msr & MSR_RI))
227 panic("Unrecoverable System Reset");
229 /* What should we do here? We could issue a shutdown or hard reset. */
234 * I/O accesses can cause machine checks on powermacs.
235 * Check if the NIP corresponds to the address of a sync
236 * instruction for which there is an entry in the exception
238 * Note that the 601 only takes a machine check on TEA
239 * (transfer error ack) signal assertion, and does not
240 * set any of the top 16 bits of SRR1.
243 static inline int check_io_access(struct pt_regs *regs)
245 #ifdef CONFIG_PPC_PMAC
246 unsigned long msr = regs->msr;
247 const struct exception_table_entry *entry;
248 unsigned int *nip = (unsigned int *)regs->nip;
250 if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
251 && (entry = search_exception_tables(regs->nip)) != NULL) {
253 * Check that it's a sync instruction, or somewhere
254 * in the twi; isync; nop sequence that inb/inw/inl uses.
255 * As the address is in the exception table
256 * we should be able to read the instr there.
257 * For the debug message, we look at the preceding
260 if (*nip == 0x60000000) /* nop */
262 else if (*nip == 0x4c00012c) /* isync */
264 if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
269 rb = (*nip >> 11) & 0x1f;
270 printk(KERN_DEBUG "%s bad port %lx at %p\n",
271 (*nip & 0x100)? "OUT to": "IN from",
272 regs->gpr[rb] - _IO_BASE, nip);
274 regs->nip = entry->fixup;
278 #endif /* CONFIG_PPC_PMAC */
282 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
283 /* On 4xx, the reason for the machine check or program exception
285 #define get_reason(regs) ((regs)->dsisr)
286 #ifndef CONFIG_FSL_BOOKE
287 #define get_mc_reason(regs) ((regs)->dsisr)
289 #define get_mc_reason(regs) (mfspr(SPRN_MCSR))
291 #define REASON_FP ESR_FP
292 #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
293 #define REASON_PRIVILEGED ESR_PPR
294 #define REASON_TRAP ESR_PTR
296 /* single-step stuff */
297 #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
298 #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
301 /* On non-4xx, the reason for the machine check or program
302 exception is in the MSR. */
303 #define get_reason(regs) ((regs)->msr)
304 #define get_mc_reason(regs) ((regs)->msr)
305 #define REASON_FP 0x100000
306 #define REASON_ILLEGAL 0x80000
307 #define REASON_PRIVILEGED 0x40000
308 #define REASON_TRAP 0x20000
310 #define single_stepping(regs) ((regs)->msr & MSR_SE)
311 #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
315 * This is "fall-back" implementation for configurations
316 * which don't provide platform-specific machine check info
318 void __attribute__ ((weak))
319 platform_machine_check(struct pt_regs *regs)
323 void machine_check_exception(struct pt_regs *regs)
328 /* See if any machine dependent calls */
329 if (ppc_md.machine_check_exception)
330 recover = ppc_md.machine_check_exception(regs);
335 unsigned long reason = get_mc_reason(regs);
337 if (user_mode(regs)) {
339 _exception(SIGBUS, regs, BUS_ADRERR, regs->nip);
343 #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
344 /* the qspan pci read routines can cause machine checks -- Cort */
345 bad_page_fault(regs, regs->dar, SIGBUS);
349 if (debugger_fault_handler(regs)) {
354 if (check_io_access(regs))
357 #if defined(CONFIG_4xx) && !defined(CONFIG_440A)
358 if (reason & ESR_IMCP) {
359 printk("Instruction");
360 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
363 printk(" machine check in kernel mode.\n");
364 #elif defined(CONFIG_440A)
365 printk("Machine check in kernel mode.\n");
366 if (reason & ESR_IMCP){
367 printk("Instruction Synchronous Machine Check exception\n");
368 mtspr(SPRN_ESR, reason & ~ESR_IMCP);
371 u32 mcsr = mfspr(SPRN_MCSR);
373 printk("Instruction Read PLB Error\n");
375 printk("Data Read PLB Error\n");
377 printk("Data Write PLB Error\n");
378 if (mcsr & MCSR_TLBP)
379 printk("TLB Parity Error\n");
380 if (mcsr & MCSR_ICP){
381 flush_instruction_cache();
382 printk("I-Cache Parity Error\n");
384 if (mcsr & MCSR_DCSP)
385 printk("D-Cache Search Parity Error\n");
386 if (mcsr & MCSR_DCFP)
387 printk("D-Cache Flush Parity Error\n");
388 if (mcsr & MCSR_IMPE)
389 printk("Machine Check exception is imprecise\n");
392 mtspr(SPRN_MCSR, mcsr);
394 #elif defined (CONFIG_E500)
395 printk("Machine check in kernel mode.\n");
396 printk("Caused by (from MCSR=%lx): ", reason);
398 if (reason & MCSR_MCP)
399 printk("Machine Check Signal\n");
400 if (reason & MCSR_ICPERR)
401 printk("Instruction Cache Parity Error\n");
402 if (reason & MCSR_DCP_PERR)
403 printk("Data Cache Push Parity Error\n");
404 if (reason & MCSR_DCPERR)
405 printk("Data Cache Parity Error\n");
406 if (reason & MCSR_GL_CI)
407 printk("Guarded Load or Cache-Inhibited stwcx.\n");
408 if (reason & MCSR_BUS_IAERR)
409 printk("Bus - Instruction Address Error\n");
410 if (reason & MCSR_BUS_RAERR)
411 printk("Bus - Read Address Error\n");
412 if (reason & MCSR_BUS_WAERR)
413 printk("Bus - Write Address Error\n");
414 if (reason & MCSR_BUS_IBERR)
415 printk("Bus - Instruction Data Error\n");
416 if (reason & MCSR_BUS_RBERR)
417 printk("Bus - Read Data Bus Error\n");
418 if (reason & MCSR_BUS_WBERR)
419 printk("Bus - Read Data Bus Error\n");
420 if (reason & MCSR_BUS_IPERR)
421 printk("Bus - Instruction Parity Error\n");
422 if (reason & MCSR_BUS_RPERR)
423 printk("Bus - Read Parity Error\n");
424 #elif defined (CONFIG_E200)
425 printk("Machine check in kernel mode.\n");
426 printk("Caused by (from MCSR=%lx): ", reason);
428 if (reason & MCSR_MCP)
429 printk("Machine Check Signal\n");
430 if (reason & MCSR_CP_PERR)
431 printk("Cache Push Parity Error\n");
432 if (reason & MCSR_CPERR)
433 printk("Cache Parity Error\n");
434 if (reason & MCSR_EXCP_ERR)
435 printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
436 if (reason & MCSR_BUS_IRERR)
437 printk("Bus - Read Bus Error on instruction fetch\n");
438 if (reason & MCSR_BUS_DRERR)
439 printk("Bus - Read Bus Error on data load\n");
440 if (reason & MCSR_BUS_WRERR)
441 printk("Bus - Write Bus Error on buffered store or cache line push\n");
442 #else /* !CONFIG_4xx && !CONFIG_E500 && !CONFIG_E200 */
443 printk("Machine check in kernel mode.\n");
444 printk("Caused by (from SRR1=%lx): ", reason);
445 switch (reason & 0x601F0000) {
447 printk("Machine check signal\n");
449 case 0: /* for 601 */
451 case 0x140000: /* 7450 MSS error and TEA */
452 printk("Transfer error ack signal\n");
455 printk("Data parity error signal\n");
458 printk("Address parity error signal\n");
461 printk("L1 Data Cache error\n");
464 printk("L1 Instruction Cache error\n");
467 printk("L2 data cache parity error\n");
470 printk("Unknown values in msr\n");
472 #endif /* CONFIG_4xx */
475 * Optional platform-provided routine to print out
476 * additional info, e.g. bus error registers.
478 platform_machine_check(regs);
479 #endif /* CONFIG_PPC64 */
481 if (debugger_fault_handler(regs))
483 die("Machine check", regs, SIGBUS);
485 /* Must die if the interrupt is not recoverable */
486 if (!(regs->msr & MSR_RI))
487 panic("Unrecoverable Machine check");
490 void SMIException(struct pt_regs *regs)
492 die("System Management Interrupt", regs, SIGABRT);
495 void unknown_exception(struct pt_regs *regs)
497 printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
498 regs->nip, regs->msr, regs->trap);
500 _exception(SIGTRAP, regs, 0, 0);
503 void instruction_breakpoint_exception(struct pt_regs *regs)
505 if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5,
506 5, SIGTRAP) == NOTIFY_STOP)
508 if (debugger_iabr_match(regs))
510 _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
513 void RunModeException(struct pt_regs *regs)
515 _exception(SIGTRAP, regs, 0, 0);
518 void __kprobes single_step_exception(struct pt_regs *regs)
520 regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */
522 if (notify_die(DIE_SSTEP, "single_step", regs, 5,
523 5, SIGTRAP) == NOTIFY_STOP)
525 if (debugger_sstep(regs))
528 _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
532 * After we have successfully emulated an instruction, we have to
533 * check if the instruction was being single-stepped, and if so,
534 * pretend we got a single-step exception. This was pointed out
535 * by Kumar Gala. -- paulus
537 static void emulate_single_step(struct pt_regs *regs)
539 if (single_stepping(regs)) {
540 clear_single_step(regs);
541 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
545 static void parse_fpe(struct pt_regs *regs)
550 flush_fp_to_thread(current);
552 fpscr = current->thread.fpscr.val;
554 /* Invalid operation */
555 if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
559 else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX))
563 else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX))
567 else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX))
571 else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX))
574 _exception(SIGFPE, regs, code, regs->nip);
578 * Illegal instruction emulation support. Originally written to
579 * provide the PVR to user applications using the mfspr rd, PVR.
580 * Return non-zero if we can't emulate, or -EFAULT if the associated
581 * memory access caused an access fault. Return zero on success.
583 * There are a couple of ways to do this, either "decode" the instruction
584 * or directly match lots of bits. In this case, matching lots of
585 * bits is faster and easier.
588 #define INST_MFSPR_PVR 0x7c1f42a6
589 #define INST_MFSPR_PVR_MASK 0xfc1fffff
591 #define INST_DCBA 0x7c0005ec
592 #define INST_DCBA_MASK 0x7c0007fe
594 #define INST_MCRXR 0x7c000400
595 #define INST_MCRXR_MASK 0x7c0007fe
597 #define INST_STRING 0x7c00042a
598 #define INST_STRING_MASK 0x7c0007fe
599 #define INST_STRING_GEN_MASK 0x7c00067e
600 #define INST_LSWI 0x7c0004aa
601 #define INST_LSWX 0x7c00042a
602 #define INST_STSWI 0x7c0005aa
603 #define INST_STSWX 0x7c00052a
605 static int emulate_string_inst(struct pt_regs *regs, u32 instword)
607 u8 rT = (instword >> 21) & 0x1f;
608 u8 rA = (instword >> 16) & 0x1f;
609 u8 NB_RB = (instword >> 11) & 0x1f;
614 /* Early out if we are an invalid form of lswx */
615 if ((instword & INST_STRING_MASK) == INST_LSWX)
616 if ((rT == rA) || (rT == NB_RB))
619 EA = (rA == 0) ? 0 : regs->gpr[rA];
621 switch (instword & INST_STRING_MASK) {
625 num_bytes = regs->xer & 0x7f;
629 num_bytes = (NB_RB == 0) ? 32 : NB_RB;
635 while (num_bytes != 0)
638 u32 shift = 8 * (3 - (pos & 0x3));
640 switch ((instword & INST_STRING_MASK)) {
643 if (get_user(val, (u8 __user *)EA))
645 /* first time updating this reg,
649 regs->gpr[rT] |= val << shift;
653 val = regs->gpr[rT] >> shift;
654 if (put_user(val, (u8 __user *)EA))
658 /* move EA to next address */
662 /* manage our position within the register */
673 static int emulate_instruction(struct pt_regs *regs)
678 if (!user_mode(regs))
680 CHECK_FULL_REGS(regs);
682 if (get_user(instword, (u32 __user *)(regs->nip)))
685 /* Emulate the mfspr rD, PVR. */
686 if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
687 rd = (instword >> 21) & 0x1f;
688 regs->gpr[rd] = mfspr(SPRN_PVR);
692 /* Emulating the dcba insn is just a no-op. */
693 if ((instword & INST_DCBA_MASK) == INST_DCBA)
696 /* Emulate the mcrxr insn. */
697 if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
698 int shift = (instword >> 21) & 0x1c;
699 unsigned long msk = 0xf0000000UL >> shift;
701 regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
702 regs->xer &= ~0xf0000000UL;
706 /* Emulate load/store string insn. */
707 if ((instword & INST_STRING_GEN_MASK) == INST_STRING)
708 return emulate_string_inst(regs, instword);
714 * Look through the list of trap instructions that are used for BUG(),
715 * BUG_ON() and WARN_ON() and see if we hit one. At this point we know
716 * that the exception was caused by a trap instruction of some kind.
717 * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
720 extern struct bug_entry __start___bug_table[], __stop___bug_table[];
722 #ifndef CONFIG_MODULES
723 #define module_find_bug(x) NULL
726 struct bug_entry *find_bug(unsigned long bugaddr)
728 struct bug_entry *bug;
730 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
731 if (bugaddr == bug->bug_addr)
733 return module_find_bug(bugaddr);
736 static int check_bug_trap(struct pt_regs *regs)
738 struct bug_entry *bug;
741 if (regs->msr & MSR_PR)
742 return 0; /* not in kernel */
743 addr = regs->nip; /* address of trap instruction */
744 if (addr < PAGE_OFFSET)
746 bug = find_bug(regs->nip);
749 if (bug->line & BUG_WARNING_TRAP) {
750 /* this is a WARN_ON rather than BUG/BUG_ON */
752 xmon_printf(KERN_ERR "Badness in %s at %s:%ld\n",
753 bug->function, bug->file,
754 bug->line & ~BUG_WARNING_TRAP);
755 #endif /* CONFIG_XMON */
756 printk(KERN_ERR "Badness in %s at %s:%ld\n",
757 bug->function, bug->file,
758 bug->line & ~BUG_WARNING_TRAP);
763 xmon_printf(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
764 bug->function, bug->file, bug->line);
766 #endif /* CONFIG_XMON */
767 printk(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
768 bug->function, bug->file, bug->line);
773 void __kprobes program_check_exception(struct pt_regs *regs)
775 unsigned int reason = get_reason(regs);
776 extern int do_mathemu(struct pt_regs *regs);
778 #ifdef CONFIG_MATH_EMULATION
779 /* (reason & REASON_ILLEGAL) would be the obvious thing here,
780 * but there seems to be a hardware bug on the 405GP (RevD)
781 * that means ESR is sometimes set incorrectly - either to
782 * ESR_DST (!?) or 0. In the process of chasing this with the
783 * hardware people - not sure if it can happen on any illegal
784 * instruction or only on FP instructions, whether there is a
785 * pattern to occurences etc. -dgibson 31/Mar/2003 */
786 if (!(reason & REASON_TRAP) && do_mathemu(regs) == 0) {
787 emulate_single_step(regs);
790 #endif /* CONFIG_MATH_EMULATION */
792 if (reason & REASON_FP) {
793 /* IEEE FP exception */
797 if (reason & REASON_TRAP) {
799 if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
802 if (debugger_bpt(regs))
804 if (check_bug_trap(regs)) {
808 _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
812 /* Try to emulate it if we should. */
813 if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
814 switch (emulate_instruction(regs)) {
817 emulate_single_step(regs);
820 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
825 if (reason & REASON_PRIVILEGED)
826 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
828 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
831 void alignment_exception(struct pt_regs *regs)
835 fixed = fix_alignment(regs);
838 regs->nip += 4; /* skip over emulated instruction */
839 emulate_single_step(regs);
843 /* Operand address was bad */
844 if (fixed == -EFAULT) {
846 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->dar);
848 /* Search exception table */
849 bad_page_fault(regs, regs->dar, SIGSEGV);
852 _exception(SIGBUS, regs, BUS_ADRALN, regs->dar);
855 void StackOverflow(struct pt_regs *regs)
857 printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
858 current, regs->gpr[1]);
861 panic("kernel stack overflow");
864 void nonrecoverable_exception(struct pt_regs *regs)
866 printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
867 regs->nip, regs->msr);
869 die("nonrecoverable exception", regs, SIGKILL);
872 void trace_syscall(struct pt_regs *regs)
874 printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
875 current, current->pid, regs->nip, regs->link, regs->gpr[0],
876 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
879 void kernel_fp_unavailable_exception(struct pt_regs *regs)
881 printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
882 "%lx at %lx\n", regs->trap, regs->nip);
883 die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
886 void altivec_unavailable_exception(struct pt_regs *regs)
888 #if !defined(CONFIG_ALTIVEC)
889 if (user_mode(regs)) {
890 /* A user program has executed an altivec instruction,
891 but this kernel doesn't support altivec. */
892 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
896 printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
897 "%lx at %lx\n", regs->trap, regs->nip);
898 die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
902 extern perf_irq_t perf_irq;
905 #if defined(CONFIG_PPC64) || defined(CONFIG_E500)
906 void performance_monitor_exception(struct pt_regs *regs)
913 void SoftwareEmulation(struct pt_regs *regs)
915 extern int do_mathemu(struct pt_regs *);
916 extern int Soft_emulate_8xx(struct pt_regs *);
919 CHECK_FULL_REGS(regs);
921 if (!user_mode(regs)) {
923 die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
926 #ifdef CONFIG_MATH_EMULATION
927 errcode = do_mathemu(regs);
929 errcode = Soft_emulate_8xx(regs);
933 _exception(SIGFPE, regs, 0, 0);
934 else if (errcode == -EFAULT)
935 _exception(SIGSEGV, regs, 0, 0);
937 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
939 emulate_single_step(regs);
941 #endif /* CONFIG_8xx */
943 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
945 void DebugException(struct pt_regs *regs, unsigned long debug_status)
947 if (debug_status & DBSR_IC) { /* instruction completion */
948 regs->msr &= ~MSR_DE;
949 if (user_mode(regs)) {
950 current->thread.dbcr0 &= ~DBCR0_IC;
952 /* Disable instruction completion */
953 mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
954 /* Clear the instruction completion event */
955 mtspr(SPRN_DBSR, DBSR_IC);
956 if (debugger_sstep(regs))
959 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
962 #endif /* CONFIG_4xx || CONFIG_BOOKE */
964 #if !defined(CONFIG_TAU_INT)
965 void TAUException(struct pt_regs *regs)
967 printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
968 regs->nip, regs->msr, regs->trap, print_tainted());
970 #endif /* CONFIG_INT_TAU */
972 #ifdef CONFIG_ALTIVEC
973 void altivec_assist_exception(struct pt_regs *regs)
977 if (!user_mode(regs)) {
978 printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
979 " at %lx\n", regs->nip);
980 die("Kernel VMX/Altivec assist exception", regs, SIGILL);
983 flush_altivec_to_thread(current);
985 err = emulate_altivec(regs);
987 regs->nip += 4; /* skip emulated instruction */
988 emulate_single_step(regs);
992 if (err == -EFAULT) {
993 /* got an error reading the instruction */
994 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
996 /* didn't recognize the instruction */
997 /* XXX quick hack for now: set the non-Java bit in the VSCR */
998 if (printk_ratelimit())
999 printk(KERN_ERR "Unrecognized altivec instruction "
1000 "in %s at %lx\n", current->comm, regs->nip);
1001 current->thread.vscr.u[3] |= 0x10000;
1004 #endif /* CONFIG_ALTIVEC */
1006 #ifdef CONFIG_FSL_BOOKE
1007 void CacheLockingException(struct pt_regs *regs, unsigned long address,
1008 unsigned long error_code)
1010 /* We treat cache locking instructions from the user
1011 * as priv ops, in the future we could try to do
1014 if (error_code & (ESR_DLK|ESR_ILK))
1015 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
1018 #endif /* CONFIG_FSL_BOOKE */
1021 void SPEFloatingPointException(struct pt_regs *regs)
1023 unsigned long spefscr;
1027 spefscr = current->thread.spefscr;
1028 fpexc_mode = current->thread.fpexc_mode;
1030 /* Hardware does not neccessarily set sticky
1031 * underflow/overflow/invalid flags */
1032 if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
1034 spefscr |= SPEFSCR_FOVFS;
1036 else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
1038 spefscr |= SPEFSCR_FUNFS;
1040 else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
1042 else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
1044 spefscr |= SPEFSCR_FINVS;
1046 else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
1049 current->thread.spefscr = spefscr;
1051 _exception(SIGFPE, regs, code, regs->nip);
1057 * We enter here if we get an unrecoverable exception, that is, one
1058 * that happened at a point where the RI (recoverable interrupt) bit
1059 * in the MSR is 0. This indicates that SRR0/1 are live, and that
1060 * we therefore lost state by taking this exception.
1062 void unrecoverable_exception(struct pt_regs *regs)
1064 printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
1065 regs->trap, regs->nip);
1066 die("Unrecoverable exception", regs, SIGABRT);
1069 #ifdef CONFIG_BOOKE_WDT
1071 * Default handler for a Watchdog exception,
1072 * spins until a reboot occurs
1074 void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
1076 /* Generic WatchdogHandler, implement your own */
1077 mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
1081 void WatchdogException(struct pt_regs *regs)
1083 printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
1084 WatchdogHandler(regs);
1089 * We enter here if we discover during exception entry that we are
1090 * running in supervisor mode with a userspace value in the stack pointer.
1092 void kernel_bad_stack(struct pt_regs *regs)
1094 printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
1095 regs->gpr[1], regs->nip);
1096 die("Bad kernel stack pointer", regs, SIGABRT);
1099 void __init trap_init(void)