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>
46 #ifdef CONFIG_PMAC_BACKLIGHT
47 #include <asm/backlight.h>
50 #include <asm/firmware.h>
51 #include <asm/processor.h>
54 #ifdef CONFIG_PPC64 /* XXX */
55 #define _IO_BASE pci_io_base
58 #ifdef CONFIG_DEBUGGER
59 int (*__debugger
)(struct pt_regs
*regs
);
60 int (*__debugger_ipi
)(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 int (*__debugger_fault_handler
)(struct pt_regs
*regs
);
67 EXPORT_SYMBOL(__debugger
);
68 EXPORT_SYMBOL(__debugger_ipi
);
69 EXPORT_SYMBOL(__debugger_bpt
);
70 EXPORT_SYMBOL(__debugger_sstep
);
71 EXPORT_SYMBOL(__debugger_iabr_match
);
72 EXPORT_SYMBOL(__debugger_dabr_match
);
73 EXPORT_SYMBOL(__debugger_fault_handler
);
76 struct notifier_block
*powerpc_die_chain
;
77 static DEFINE_SPINLOCK(die_notifier_lock
);
79 int register_die_notifier(struct notifier_block
*nb
)
84 spin_lock_irqsave(&die_notifier_lock
, flags
);
85 err
= notifier_chain_register(&powerpc_die_chain
, nb
);
86 spin_unlock_irqrestore(&die_notifier_lock
, flags
);
91 * Trap & Exception support
94 static DEFINE_SPINLOCK(die_lock
);
96 int die(const char *str
, struct pt_regs
*regs
, long err
)
98 static int die_counter
;
105 spin_lock_irq(&die_lock
);
107 #ifdef CONFIG_PMAC_BACKLIGHT
108 if (_machine
== _MACH_Pmac
) {
109 set_backlight_enable(1);
110 set_backlight_level(BACKLIGHT_MAX
);
113 printk("Oops: %s, sig: %ld [#%d]\n", str
, err
, ++die_counter
);
114 #ifdef CONFIG_PREEMPT
119 printk("SMP NR_CPUS=%d ", NR_CPUS
);
122 #ifdef CONFIG_DEBUG_PAGEALLOC
123 printk("DEBUG_PAGEALLOC ");
132 case PLATFORM_PSERIES
:
136 case PLATFORM_PSERIES_LPAR
:
137 printk("PSERIES LPAR ");
140 case PLATFORM_ISERIES_LPAR
:
141 printk("ISERIES LPAR ");
144 case PLATFORM_POWERMAC
:
159 spin_unlock_irq(&die_lock
);
162 panic("Fatal exception in interrupt");
166 printk(KERN_EMERG
"Fatal exception: panic in 5 seconds\n");
169 panic("Fatal exception");
176 void _exception(int signr
, struct pt_regs
*regs
, int code
, unsigned long addr
)
180 if (!user_mode(regs
)) {
181 if (die("Exception in kernel mode", regs
, signr
))
185 memset(&info
, 0, sizeof(info
));
186 info
.si_signo
= signr
;
188 info
.si_addr
= (void __user
*) addr
;
189 force_sig_info(signr
, &info
, current
);
192 * Init gets no signals that it doesn't have a handler for.
193 * That's all very well, but if it has caused a synchronous
194 * exception and we ignore the resulting signal, it will just
195 * generate the same exception over and over again and we get
196 * nowhere. Better to kill it and let the kernel panic.
198 if (current
->pid
== 1) {
199 __sighandler_t handler
;
201 spin_lock_irq(¤t
->sighand
->siglock
);
202 handler
= current
->sighand
->action
[signr
-1].sa
.sa_handler
;
203 spin_unlock_irq(¤t
->sighand
->siglock
);
204 if (handler
== SIG_DFL
) {
205 /* init has generated a synchronous exception
206 and it doesn't have a handler for the signal */
207 printk(KERN_CRIT
"init has generated signal %d "
208 "but has no handler for it\n", signr
);
215 void system_reset_exception(struct pt_regs
*regs
)
217 /* See if any machine dependent calls */
218 if (ppc_md
.system_reset_exception
)
219 ppc_md
.system_reset_exception(regs
);
221 die("System Reset", regs
, SIGABRT
);
223 /* Must die if the interrupt is not recoverable */
224 if (!(regs
->msr
& MSR_RI
))
225 panic("Unrecoverable System Reset");
227 /* What should we do here? We could issue a shutdown or hard reset. */
232 * I/O accesses can cause machine checks on powermacs.
233 * Check if the NIP corresponds to the address of a sync
234 * instruction for which there is an entry in the exception
236 * Note that the 601 only takes a machine check on TEA
237 * (transfer error ack) signal assertion, and does not
238 * set any of the top 16 bits of SRR1.
241 static inline int check_io_access(struct pt_regs
*regs
)
243 #ifdef CONFIG_PPC_PMAC
244 unsigned long msr
= regs
->msr
;
245 const struct exception_table_entry
*entry
;
246 unsigned int *nip
= (unsigned int *)regs
->nip
;
248 if (((msr
& 0xffff0000) == 0 || (msr
& (0x80000 | 0x40000)))
249 && (entry
= search_exception_tables(regs
->nip
)) != NULL
) {
251 * Check that it's a sync instruction, or somewhere
252 * in the twi; isync; nop sequence that inb/inw/inl uses.
253 * As the address is in the exception table
254 * we should be able to read the instr there.
255 * For the debug message, we look at the preceding
258 if (*nip
== 0x60000000) /* nop */
260 else if (*nip
== 0x4c00012c) /* isync */
262 if (*nip
== 0x7c0004ac || (*nip
>> 26) == 3) {
267 rb
= (*nip
>> 11) & 0x1f;
268 printk(KERN_DEBUG
"%s bad port %lx at %p\n",
269 (*nip
& 0x100)? "OUT to": "IN from",
270 regs
->gpr
[rb
] - _IO_BASE
, nip
);
272 regs
->nip
= entry
->fixup
;
276 #endif /* CONFIG_PPC_PMAC */
280 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
281 /* On 4xx, the reason for the machine check or program exception
283 #define get_reason(regs) ((regs)->dsisr)
284 #ifndef CONFIG_FSL_BOOKE
285 #define get_mc_reason(regs) ((regs)->dsisr)
287 #define get_mc_reason(regs) (mfspr(SPRN_MCSR))
289 #define REASON_FP ESR_FP
290 #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
291 #define REASON_PRIVILEGED ESR_PPR
292 #define REASON_TRAP ESR_PTR
294 /* single-step stuff */
295 #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
296 #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
299 /* On non-4xx, the reason for the machine check or program
300 exception is in the MSR. */
301 #define get_reason(regs) ((regs)->msr)
302 #define get_mc_reason(regs) ((regs)->msr)
303 #define REASON_FP 0x100000
304 #define REASON_ILLEGAL 0x80000
305 #define REASON_PRIVILEGED 0x40000
306 #define REASON_TRAP 0x20000
308 #define single_stepping(regs) ((regs)->msr & MSR_SE)
309 #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
313 * This is "fall-back" implementation for configurations
314 * which don't provide platform-specific machine check info
316 void __attribute__ ((weak
))
317 platform_machine_check(struct pt_regs
*regs
)
321 void machine_check_exception(struct pt_regs
*regs
)
326 /* See if any machine dependent calls */
327 if (ppc_md
.machine_check_exception
)
328 recover
= ppc_md
.machine_check_exception(regs
);
333 unsigned long reason
= get_mc_reason(regs
);
335 if (user_mode(regs
)) {
337 _exception(SIGBUS
, regs
, BUS_ADRERR
, regs
->nip
);
341 #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
342 /* the qspan pci read routines can cause machine checks -- Cort */
343 bad_page_fault(regs
, regs
->dar
, SIGBUS
);
347 if (debugger_fault_handler(regs
)) {
352 if (check_io_access(regs
))
355 #if defined(CONFIG_4xx) && !defined(CONFIG_440A)
356 if (reason
& ESR_IMCP
) {
357 printk("Instruction");
358 mtspr(SPRN_ESR
, reason
& ~ESR_IMCP
);
361 printk(" machine check in kernel mode.\n");
362 #elif defined(CONFIG_440A)
363 printk("Machine check in kernel mode.\n");
364 if (reason
& ESR_IMCP
){
365 printk("Instruction Synchronous Machine Check exception\n");
366 mtspr(SPRN_ESR
, reason
& ~ESR_IMCP
);
369 u32 mcsr
= mfspr(SPRN_MCSR
);
371 printk("Instruction Read PLB Error\n");
373 printk("Data Read PLB Error\n");
375 printk("Data Write PLB Error\n");
376 if (mcsr
& MCSR_TLBP
)
377 printk("TLB Parity Error\n");
378 if (mcsr
& MCSR_ICP
){
379 flush_instruction_cache();
380 printk("I-Cache Parity Error\n");
382 if (mcsr
& MCSR_DCSP
)
383 printk("D-Cache Search Parity Error\n");
384 if (mcsr
& MCSR_DCFP
)
385 printk("D-Cache Flush Parity Error\n");
386 if (mcsr
& MCSR_IMPE
)
387 printk("Machine Check exception is imprecise\n");
390 mtspr(SPRN_MCSR
, mcsr
);
392 #elif defined (CONFIG_E500)
393 printk("Machine check in kernel mode.\n");
394 printk("Caused by (from MCSR=%lx): ", reason
);
396 if (reason
& MCSR_MCP
)
397 printk("Machine Check Signal\n");
398 if (reason
& MCSR_ICPERR
)
399 printk("Instruction Cache Parity Error\n");
400 if (reason
& MCSR_DCP_PERR
)
401 printk("Data Cache Push Parity Error\n");
402 if (reason
& MCSR_DCPERR
)
403 printk("Data Cache Parity Error\n");
404 if (reason
& MCSR_GL_CI
)
405 printk("Guarded Load or Cache-Inhibited stwcx.\n");
406 if (reason
& MCSR_BUS_IAERR
)
407 printk("Bus - Instruction Address Error\n");
408 if (reason
& MCSR_BUS_RAERR
)
409 printk("Bus - Read Address Error\n");
410 if (reason
& MCSR_BUS_WAERR
)
411 printk("Bus - Write Address Error\n");
412 if (reason
& MCSR_BUS_IBERR
)
413 printk("Bus - Instruction Data Error\n");
414 if (reason
& MCSR_BUS_RBERR
)
415 printk("Bus - Read Data Bus Error\n");
416 if (reason
& MCSR_BUS_WBERR
)
417 printk("Bus - Read Data Bus Error\n");
418 if (reason
& MCSR_BUS_IPERR
)
419 printk("Bus - Instruction Parity Error\n");
420 if (reason
& MCSR_BUS_RPERR
)
421 printk("Bus - Read Parity Error\n");
422 #elif defined (CONFIG_E200)
423 printk("Machine check in kernel mode.\n");
424 printk("Caused by (from MCSR=%lx): ", reason
);
426 if (reason
& MCSR_MCP
)
427 printk("Machine Check Signal\n");
428 if (reason
& MCSR_CP_PERR
)
429 printk("Cache Push Parity Error\n");
430 if (reason
& MCSR_CPERR
)
431 printk("Cache Parity Error\n");
432 if (reason
& MCSR_EXCP_ERR
)
433 printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
434 if (reason
& MCSR_BUS_IRERR
)
435 printk("Bus - Read Bus Error on instruction fetch\n");
436 if (reason
& MCSR_BUS_DRERR
)
437 printk("Bus - Read Bus Error on data load\n");
438 if (reason
& MCSR_BUS_WRERR
)
439 printk("Bus - Write Bus Error on buffered store or cache line push\n");
440 #else /* !CONFIG_4xx && !CONFIG_E500 && !CONFIG_E200 */
441 printk("Machine check in kernel mode.\n");
442 printk("Caused by (from SRR1=%lx): ", reason
);
443 switch (reason
& 0x601F0000) {
445 printk("Machine check signal\n");
447 case 0: /* for 601 */
449 case 0x140000: /* 7450 MSS error and TEA */
450 printk("Transfer error ack signal\n");
453 printk("Data parity error signal\n");
456 printk("Address parity error signal\n");
459 printk("L1 Data Cache error\n");
462 printk("L1 Instruction Cache error\n");
465 printk("L2 data cache parity error\n");
468 printk("Unknown values in msr\n");
470 #endif /* CONFIG_4xx */
473 * Optional platform-provided routine to print out
474 * additional info, e.g. bus error registers.
476 platform_machine_check(regs
);
477 #endif /* CONFIG_PPC64 */
479 if (debugger_fault_handler(regs
))
481 die("Machine check", regs
, SIGBUS
);
483 /* Must die if the interrupt is not recoverable */
484 if (!(regs
->msr
& MSR_RI
))
485 panic("Unrecoverable Machine check");
488 void SMIException(struct pt_regs
*regs
)
490 die("System Management Interrupt", regs
, SIGABRT
);
493 void unknown_exception(struct pt_regs
*regs
)
495 printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
496 regs
->nip
, regs
->msr
, regs
->trap
);
498 _exception(SIGTRAP
, regs
, 0, 0);
501 void instruction_breakpoint_exception(struct pt_regs
*regs
)
503 if (notify_die(DIE_IABR_MATCH
, "iabr_match", regs
, 5,
504 5, SIGTRAP
) == NOTIFY_STOP
)
506 if (debugger_iabr_match(regs
))
508 _exception(SIGTRAP
, regs
, TRAP_BRKPT
, regs
->nip
);
511 void RunModeException(struct pt_regs
*regs
)
513 _exception(SIGTRAP
, regs
, 0, 0);
516 void __kprobes
single_step_exception(struct pt_regs
*regs
)
518 regs
->msr
&= ~(MSR_SE
| MSR_BE
); /* Turn off 'trace' bits */
520 if (notify_die(DIE_SSTEP
, "single_step", regs
, 5,
521 5, SIGTRAP
) == NOTIFY_STOP
)
523 if (debugger_sstep(regs
))
526 _exception(SIGTRAP
, regs
, TRAP_TRACE
, regs
->nip
);
530 * After we have successfully emulated an instruction, we have to
531 * check if the instruction was being single-stepped, and if so,
532 * pretend we got a single-step exception. This was pointed out
533 * by Kumar Gala. -- paulus
535 static void emulate_single_step(struct pt_regs
*regs
)
537 if (single_stepping(regs
)) {
538 clear_single_step(regs
);
539 _exception(SIGTRAP
, regs
, TRAP_TRACE
, 0);
543 static void parse_fpe(struct pt_regs
*regs
)
548 flush_fp_to_thread(current
);
550 fpscr
= current
->thread
.fpscr
.val
;
552 /* Invalid operation */
553 if ((fpscr
& FPSCR_VE
) && (fpscr
& FPSCR_VX
))
557 else if ((fpscr
& FPSCR_OE
) && (fpscr
& FPSCR_OX
))
561 else if ((fpscr
& FPSCR_UE
) && (fpscr
& FPSCR_UX
))
565 else if ((fpscr
& FPSCR_ZE
) && (fpscr
& FPSCR_ZX
))
569 else if ((fpscr
& FPSCR_XE
) && (fpscr
& FPSCR_XX
))
572 _exception(SIGFPE
, regs
, code
, regs
->nip
);
576 * Illegal instruction emulation support. Originally written to
577 * provide the PVR to user applications using the mfspr rd, PVR.
578 * Return non-zero if we can't emulate, or -EFAULT if the associated
579 * memory access caused an access fault. Return zero on success.
581 * There are a couple of ways to do this, either "decode" the instruction
582 * or directly match lots of bits. In this case, matching lots of
583 * bits is faster and easier.
586 #define INST_MFSPR_PVR 0x7c1f42a6
587 #define INST_MFSPR_PVR_MASK 0xfc1fffff
589 #define INST_DCBA 0x7c0005ec
590 #define INST_DCBA_MASK 0x7c0007fe
592 #define INST_MCRXR 0x7c000400
593 #define INST_MCRXR_MASK 0x7c0007fe
595 #define INST_STRING 0x7c00042a
596 #define INST_STRING_MASK 0x7c0007fe
597 #define INST_STRING_GEN_MASK 0x7c00067e
598 #define INST_LSWI 0x7c0004aa
599 #define INST_LSWX 0x7c00042a
600 #define INST_STSWI 0x7c0005aa
601 #define INST_STSWX 0x7c00052a
603 static int emulate_string_inst(struct pt_regs
*regs
, u32 instword
)
605 u8 rT
= (instword
>> 21) & 0x1f;
606 u8 rA
= (instword
>> 16) & 0x1f;
607 u8 NB_RB
= (instword
>> 11) & 0x1f;
612 /* Early out if we are an invalid form of lswx */
613 if ((instword
& INST_STRING_MASK
) == INST_LSWX
)
614 if ((rT
== rA
) || (rT
== NB_RB
))
617 EA
= (rA
== 0) ? 0 : regs
->gpr
[rA
];
619 switch (instword
& INST_STRING_MASK
) {
623 num_bytes
= regs
->xer
& 0x7f;
627 num_bytes
= (NB_RB
== 0) ? 32 : NB_RB
;
633 while (num_bytes
!= 0)
636 u32 shift
= 8 * (3 - (pos
& 0x3));
638 switch ((instword
& INST_STRING_MASK
)) {
641 if (get_user(val
, (u8 __user
*)EA
))
643 /* first time updating this reg,
647 regs
->gpr
[rT
] |= val
<< shift
;
651 val
= regs
->gpr
[rT
] >> shift
;
652 if (put_user(val
, (u8 __user
*)EA
))
656 /* move EA to next address */
660 /* manage our position within the register */
671 static int emulate_instruction(struct pt_regs
*regs
)
676 if (!user_mode(regs
))
678 CHECK_FULL_REGS(regs
);
680 if (get_user(instword
, (u32 __user
*)(regs
->nip
)))
683 /* Emulate the mfspr rD, PVR. */
684 if ((instword
& INST_MFSPR_PVR_MASK
) == INST_MFSPR_PVR
) {
685 rd
= (instword
>> 21) & 0x1f;
686 regs
->gpr
[rd
] = mfspr(SPRN_PVR
);
690 /* Emulating the dcba insn is just a no-op. */
691 if ((instword
& INST_DCBA_MASK
) == INST_DCBA
)
694 /* Emulate the mcrxr insn. */
695 if ((instword
& INST_MCRXR_MASK
) == INST_MCRXR
) {
696 int shift
= (instword
>> 21) & 0x1c;
697 unsigned long msk
= 0xf0000000UL
>> shift
;
699 regs
->ccr
= (regs
->ccr
& ~msk
) | ((regs
->xer
>> shift
) & msk
);
700 regs
->xer
&= ~0xf0000000UL
;
704 /* Emulate load/store string insn. */
705 if ((instword
& INST_STRING_GEN_MASK
) == INST_STRING
)
706 return emulate_string_inst(regs
, instword
);
712 * Look through the list of trap instructions that are used for BUG(),
713 * BUG_ON() and WARN_ON() and see if we hit one. At this point we know
714 * that the exception was caused by a trap instruction of some kind.
715 * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
718 extern struct bug_entry __start___bug_table
[], __stop___bug_table
[];
720 #ifndef CONFIG_MODULES
721 #define module_find_bug(x) NULL
724 struct bug_entry
*find_bug(unsigned long bugaddr
)
726 struct bug_entry
*bug
;
728 for (bug
= __start___bug_table
; bug
< __stop___bug_table
; ++bug
)
729 if (bugaddr
== bug
->bug_addr
)
731 return module_find_bug(bugaddr
);
734 static int check_bug_trap(struct pt_regs
*regs
)
736 struct bug_entry
*bug
;
739 if (regs
->msr
& MSR_PR
)
740 return 0; /* not in kernel */
741 addr
= regs
->nip
; /* address of trap instruction */
742 if (addr
< PAGE_OFFSET
)
744 bug
= find_bug(regs
->nip
);
747 if (bug
->line
& BUG_WARNING_TRAP
) {
748 /* this is a WARN_ON rather than BUG/BUG_ON */
749 printk(KERN_ERR
"Badness in %s at %s:%ld\n",
750 bug
->function
, bug
->file
,
751 bug
->line
& ~BUG_WARNING_TRAP
);
755 printk(KERN_CRIT
"kernel BUG in %s at %s:%ld!\n",
756 bug
->function
, bug
->file
, bug
->line
);
761 void __kprobes
program_check_exception(struct pt_regs
*regs
)
763 unsigned int reason
= get_reason(regs
);
764 extern int do_mathemu(struct pt_regs
*regs
);
766 #ifdef CONFIG_MATH_EMULATION
767 /* (reason & REASON_ILLEGAL) would be the obvious thing here,
768 * but there seems to be a hardware bug on the 405GP (RevD)
769 * that means ESR is sometimes set incorrectly - either to
770 * ESR_DST (!?) or 0. In the process of chasing this with the
771 * hardware people - not sure if it can happen on any illegal
772 * instruction or only on FP instructions, whether there is a
773 * pattern to occurences etc. -dgibson 31/Mar/2003 */
774 if (!(reason
& REASON_TRAP
) && do_mathemu(regs
) == 0) {
775 emulate_single_step(regs
);
778 #endif /* CONFIG_MATH_EMULATION */
780 if (reason
& REASON_FP
) {
781 /* IEEE FP exception */
785 if (reason
& REASON_TRAP
) {
787 if (notify_die(DIE_BPT
, "breakpoint", regs
, 5, 5, SIGTRAP
)
790 if (debugger_bpt(regs
))
792 if (check_bug_trap(regs
)) {
796 _exception(SIGTRAP
, regs
, TRAP_BRKPT
, regs
->nip
);
800 /* Try to emulate it if we should. */
801 if (reason
& (REASON_ILLEGAL
| REASON_PRIVILEGED
)) {
802 switch (emulate_instruction(regs
)) {
805 emulate_single_step(regs
);
808 _exception(SIGSEGV
, regs
, SEGV_MAPERR
, regs
->nip
);
813 if (reason
& REASON_PRIVILEGED
)
814 _exception(SIGILL
, regs
, ILL_PRVOPC
, regs
->nip
);
816 _exception(SIGILL
, regs
, ILL_ILLOPC
, regs
->nip
);
819 void alignment_exception(struct pt_regs
*regs
)
823 fixed
= fix_alignment(regs
);
826 regs
->nip
+= 4; /* skip over emulated instruction */
827 emulate_single_step(regs
);
831 /* Operand address was bad */
832 if (fixed
== -EFAULT
) {
834 _exception(SIGSEGV
, regs
, SEGV_ACCERR
, regs
->dar
);
836 /* Search exception table */
837 bad_page_fault(regs
, regs
->dar
, SIGSEGV
);
840 _exception(SIGBUS
, regs
, BUS_ADRALN
, regs
->dar
);
843 void StackOverflow(struct pt_regs
*regs
)
845 printk(KERN_CRIT
"Kernel stack overflow in process %p, r1=%lx\n",
846 current
, regs
->gpr
[1]);
849 panic("kernel stack overflow");
852 void nonrecoverable_exception(struct pt_regs
*regs
)
854 printk(KERN_ERR
"Non-recoverable exception at PC=%lx MSR=%lx\n",
855 regs
->nip
, regs
->msr
);
857 die("nonrecoverable exception", regs
, SIGKILL
);
860 void trace_syscall(struct pt_regs
*regs
)
862 printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
863 current
, current
->pid
, regs
->nip
, regs
->link
, regs
->gpr
[0],
864 regs
->ccr
&0x10000000?"Error=":"", regs
->gpr
[3], print_tainted());
867 void kernel_fp_unavailable_exception(struct pt_regs
*regs
)
869 printk(KERN_EMERG
"Unrecoverable FP Unavailable Exception "
870 "%lx at %lx\n", regs
->trap
, regs
->nip
);
871 die("Unrecoverable FP Unavailable Exception", regs
, SIGABRT
);
874 void altivec_unavailable_exception(struct pt_regs
*regs
)
876 #if !defined(CONFIG_ALTIVEC)
877 if (user_mode(regs
)) {
878 /* A user program has executed an altivec instruction,
879 but this kernel doesn't support altivec. */
880 _exception(SIGILL
, regs
, ILL_ILLOPC
, regs
->nip
);
884 printk(KERN_EMERG
"Unrecoverable VMX/Altivec Unavailable Exception "
885 "%lx at %lx\n", regs
->trap
, regs
->nip
);
886 die("Unrecoverable VMX/Altivec Unavailable Exception", regs
, SIGABRT
);
889 #if defined(CONFIG_PPC64) || defined(CONFIG_E500)
890 void performance_monitor_exception(struct pt_regs
*regs
)
897 void SoftwareEmulation(struct pt_regs
*regs
)
899 extern int do_mathemu(struct pt_regs
*);
900 extern int Soft_emulate_8xx(struct pt_regs
*);
903 CHECK_FULL_REGS(regs
);
905 if (!user_mode(regs
)) {
907 die("Kernel Mode Software FPU Emulation", regs
, SIGFPE
);
910 #ifdef CONFIG_MATH_EMULATION
911 errcode
= do_mathemu(regs
);
913 errcode
= Soft_emulate_8xx(regs
);
917 _exception(SIGFPE
, regs
, 0, 0);
918 else if (errcode
== -EFAULT
)
919 _exception(SIGSEGV
, regs
, 0, 0);
921 _exception(SIGILL
, regs
, ILL_ILLOPC
, regs
->nip
);
923 emulate_single_step(regs
);
925 #endif /* CONFIG_8xx */
927 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
929 void DebugException(struct pt_regs
*regs
, unsigned long debug_status
)
931 if (debug_status
& DBSR_IC
) { /* instruction completion */
932 regs
->msr
&= ~MSR_DE
;
933 if (user_mode(regs
)) {
934 current
->thread
.dbcr0
&= ~DBCR0_IC
;
936 /* Disable instruction completion */
937 mtspr(SPRN_DBCR0
, mfspr(SPRN_DBCR0
) & ~DBCR0_IC
);
938 /* Clear the instruction completion event */
939 mtspr(SPRN_DBSR
, DBSR_IC
);
940 if (debugger_sstep(regs
))
943 _exception(SIGTRAP
, regs
, TRAP_TRACE
, 0);
946 #endif /* CONFIG_4xx || CONFIG_BOOKE */
948 #if !defined(CONFIG_TAU_INT)
949 void TAUException(struct pt_regs
*regs
)
951 printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
952 regs
->nip
, regs
->msr
, regs
->trap
, print_tainted());
954 #endif /* CONFIG_INT_TAU */
956 #ifdef CONFIG_ALTIVEC
957 void altivec_assist_exception(struct pt_regs
*regs
)
961 if (!user_mode(regs
)) {
962 printk(KERN_EMERG
"VMX/Altivec assist exception in kernel mode"
963 " at %lx\n", regs
->nip
);
964 die("Kernel VMX/Altivec assist exception", regs
, SIGILL
);
967 flush_altivec_to_thread(current
);
969 err
= emulate_altivec(regs
);
971 regs
->nip
+= 4; /* skip emulated instruction */
972 emulate_single_step(regs
);
976 if (err
== -EFAULT
) {
977 /* got an error reading the instruction */
978 _exception(SIGSEGV
, regs
, SEGV_ACCERR
, regs
->nip
);
980 /* didn't recognize the instruction */
981 /* XXX quick hack for now: set the non-Java bit in the VSCR */
982 if (printk_ratelimit())
983 printk(KERN_ERR
"Unrecognized altivec instruction "
984 "in %s at %lx\n", current
->comm
, regs
->nip
);
985 current
->thread
.vscr
.u
[3] |= 0x10000;
988 #endif /* CONFIG_ALTIVEC */
990 #ifdef CONFIG_FSL_BOOKE
991 void CacheLockingException(struct pt_regs
*regs
, unsigned long address
,
992 unsigned long error_code
)
994 /* We treat cache locking instructions from the user
995 * as priv ops, in the future we could try to do
998 if (error_code
& (ESR_DLK
|ESR_ILK
))
999 _exception(SIGILL
, regs
, ILL_PRVOPC
, regs
->nip
);
1002 #endif /* CONFIG_FSL_BOOKE */
1005 void SPEFloatingPointException(struct pt_regs
*regs
)
1007 unsigned long spefscr
;
1011 spefscr
= current
->thread
.spefscr
;
1012 fpexc_mode
= current
->thread
.fpexc_mode
;
1014 /* Hardware does not neccessarily set sticky
1015 * underflow/overflow/invalid flags */
1016 if ((spefscr
& SPEFSCR_FOVF
) && (fpexc_mode
& PR_FP_EXC_OVF
)) {
1018 spefscr
|= SPEFSCR_FOVFS
;
1020 else if ((spefscr
& SPEFSCR_FUNF
) && (fpexc_mode
& PR_FP_EXC_UND
)) {
1022 spefscr
|= SPEFSCR_FUNFS
;
1024 else if ((spefscr
& SPEFSCR_FDBZ
) && (fpexc_mode
& PR_FP_EXC_DIV
))
1026 else if ((spefscr
& SPEFSCR_FINV
) && (fpexc_mode
& PR_FP_EXC_INV
)) {
1028 spefscr
|= SPEFSCR_FINVS
;
1030 else if ((spefscr
& (SPEFSCR_FG
| SPEFSCR_FX
)) && (fpexc_mode
& PR_FP_EXC_RES
))
1033 current
->thread
.spefscr
= spefscr
;
1035 _exception(SIGFPE
, regs
, code
, regs
->nip
);
1041 * We enter here if we get an unrecoverable exception, that is, one
1042 * that happened at a point where the RI (recoverable interrupt) bit
1043 * in the MSR is 0. This indicates that SRR0/1 are live, and that
1044 * we therefore lost state by taking this exception.
1046 void unrecoverable_exception(struct pt_regs
*regs
)
1048 printk(KERN_EMERG
"Unrecoverable exception %lx at %lx\n",
1049 regs
->trap
, regs
->nip
);
1050 die("Unrecoverable exception", regs
, SIGABRT
);
1053 #ifdef CONFIG_BOOKE_WDT
1055 * Default handler for a Watchdog exception,
1056 * spins until a reboot occurs
1058 void __attribute__ ((weak
)) WatchdogHandler(struct pt_regs
*regs
)
1060 /* Generic WatchdogHandler, implement your own */
1061 mtspr(SPRN_TCR
, mfspr(SPRN_TCR
)&(~TCR_WIE
));
1065 void WatchdogException(struct pt_regs
*regs
)
1067 printk (KERN_EMERG
"PowerPC Book-E Watchdog Exception\n");
1068 WatchdogHandler(regs
);
1073 * We enter here if we discover during exception entry that we are
1074 * running in supervisor mode with a userspace value in the stack pointer.
1076 void kernel_bad_stack(struct pt_regs
*regs
)
1078 printk(KERN_EMERG
"Bad kernel stack pointer %lx at %lx\n",
1079 regs
->gpr
[1], regs
->nip
);
1080 die("Bad kernel stack pointer", regs
, SIGABRT
);
1083 void __init
trap_init(void)