traps.c (292dcc86dd69e343630ab49ce96a418345c174fc) traps.c (8dad3f9257414f151cd821bfe01f54d7f52d2507)
1/*
2 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
3 *
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.
8 *

--- 7 unchanged lines hidden (view full) ---

16
17#include <linux/config.h>
18#include <linux/errno.h>
19#include <linux/sched.h>
20#include <linux/kernel.h>
21#include <linux/mm.h>
22#include <linux/stddef.h>
23#include <linux/unistd.h>
1/*
2 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
3 *
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.
8 *

--- 7 unchanged lines hidden (view full) ---

16
17#include <linux/config.h>
18#include <linux/errno.h>
19#include <linux/sched.h>
20#include <linux/kernel.h>
21#include <linux/mm.h>
22#include <linux/stddef.h>
23#include <linux/unistd.h>
24#include <linux/ptrace.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>
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>
30#include <linux/delay.h>
31#include <linux/kprobes.h>
32#include <asm/kdebug.h>
32#include <linux/delay.h>
33#include <linux/kprobes.h>
34#include <asm/kdebug.h>
33#ifdef CONFIG_PPC32
34#include <linux/ptrace.h>
35#include <linux/prctl.h>
36#endif
37
38#include <asm/pgtable.h>
39#include <asm/uaccess.h>
40#include <asm/system.h>
41#include <asm/io.h>
42#ifdef CONFIG_PPC32
43#include <asm/reg.h>
44#include <asm/xmon.h>

--- 6 unchanged lines hidden (view full) ---

51#include <asm/processor.h>
52#include <asm/ppcdebug.h>
53#include <asm/rtas.h>
54#include <asm/systemcfg.h>
55#include <asm/machdep.h>
56#include <asm/pmc.h>
57#endif
58
35
36#include <asm/pgtable.h>
37#include <asm/uaccess.h>
38#include <asm/system.h>
39#include <asm/io.h>
40#ifdef CONFIG_PPC32
41#include <asm/reg.h>
42#include <asm/xmon.h>

--- 6 unchanged lines hidden (view full) ---

49#include <asm/processor.h>
50#include <asm/ppcdebug.h>
51#include <asm/rtas.h>
52#include <asm/systemcfg.h>
53#include <asm/machdep.h>
54#include <asm/pmc.h>
55#endif
56
59#ifdef CONFIG_PPC64
60#define __KPROBES __kprobes
61#else
62#define __KPROBES
63#endif
64
65#ifdef CONFIG_DEBUGGER
66int (*__debugger)(struct pt_regs *regs);
67int (*__debugger_ipi)(struct pt_regs *regs);
68int (*__debugger_bpt)(struct pt_regs *regs);
69int (*__debugger_sstep)(struct pt_regs *regs);
70int (*__debugger_iabr_match)(struct pt_regs *regs);
71int (*__debugger_dabr_match)(struct pt_regs *regs);
72int (*__debugger_fault_handler)(struct pt_regs *regs);

--- 33 unchanged lines hidden (view full) ---

106 int nl = 0;
107
108 if (debugger(regs))
109 return 1;
110
111 console_verbose();
112 spin_lock_irq(&die_lock);
113 bust_spinlocks(1);
57#ifdef CONFIG_DEBUGGER
58int (*__debugger)(struct pt_regs *regs);
59int (*__debugger_ipi)(struct pt_regs *regs);
60int (*__debugger_bpt)(struct pt_regs *regs);
61int (*__debugger_sstep)(struct pt_regs *regs);
62int (*__debugger_iabr_match)(struct pt_regs *regs);
63int (*__debugger_dabr_match)(struct pt_regs *regs);
64int (*__debugger_fault_handler)(struct pt_regs *regs);

--- 33 unchanged lines hidden (view full) ---

98 int nl = 0;
99
100 if (debugger(regs))
101 return 1;
102
103 console_verbose();
104 spin_lock_irq(&die_lock);
105 bust_spinlocks(1);
114#if defined(CONFIG_PPC32) && defined(CONFIG_PMAC_BACKLIGHT)
106#ifdef CONFIG_PMAC_BACKLIGHT
115 if (_machine == _MACH_Pmac) {
116 set_backlight_enable(1);
117 set_backlight_level(BACKLIGHT_MAX);
118 }
119#endif
120 printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
121#ifdef CONFIG_PREEMPT
122 printk("PREEMPT ");

--- 47 unchanged lines hidden (view full) ---

170
171 if (panic_on_oops) {
172#ifdef CONFIG_PPC64
173 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
174 ssleep(5);
175#endif
176 panic("Fatal exception");
177 }
107 if (_machine == _MACH_Pmac) {
108 set_backlight_enable(1);
109 set_backlight_level(BACKLIGHT_MAX);
110 }
111#endif
112 printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
113#ifdef CONFIG_PREEMPT
114 printk("PREEMPT ");

--- 47 unchanged lines hidden (view full) ---

162
163 if (panic_on_oops) {
164#ifdef CONFIG_PPC64
165 printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
166 ssleep(5);
167#endif
168 panic("Fatal exception");
169 }
178#ifdef CONFIG_PPC32
179 do_exit(err);
170 do_exit(err);
180#else
181 do_exit(SIGSEGV);
182#endif
183
184 return 0;
185}
186
187void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
188{
189 siginfo_t info;
190
191 if (!user_mode(regs)) {
192 if (die("Exception in kernel mode", regs, signr))
193 return;
194 }
195
196 memset(&info, 0, sizeof(info));
197 info.si_signo = signr;
198 info.si_code = code;
199 info.si_addr = (void __user *) addr;
200 force_sig_info(signr, &info, current);
201
171
172 return 0;
173}
174
175void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
176{
177 siginfo_t info;
178
179 if (!user_mode(regs)) {
180 if (die("Exception in kernel mode", regs, signr))
181 return;
182 }
183
184 memset(&info, 0, sizeof(info));
185 info.si_signo = signr;
186 info.si_code = code;
187 info.si_addr = (void __user *) addr;
188 force_sig_info(signr, &info, current);
189
202#ifdef CONFIG_PPC32
203 /*
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.
209 */
210 if (current->pid == 1) {

--- 5 unchanged lines hidden (view full) ---

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);
221 do_exit(signr);
222 }
223 }
190 /*
191 * Init gets no signals that it doesn't have a handler for.
192 * That's all very well, but if it has caused a synchronous
193 * exception and we ignore the resulting signal, it will just
194 * generate the same exception over and over again and we get
195 * nowhere. Better to kill it and let the kernel panic.
196 */
197 if (current->pid == 1) {

--- 5 unchanged lines hidden (view full) ---

203 if (handler == SIG_DFL) {
204 /* init has generated a synchronous exception
205 and it doesn't have a handler for the signal */
206 printk(KERN_CRIT "init has generated signal %d "
207 "but has no handler for it\n", signr);
208 do_exit(signr);
209 }
210 }
224#endif
225}
226
227#ifdef CONFIG_PPC64
228void system_reset_exception(struct pt_regs *regs)
229{
230 /* See if any machine dependent calls */
231 if (ppc_md.system_reset_exception)
232 ppc_md.system_reset_exception(regs);
233
211}
212
213#ifdef CONFIG_PPC64
214void system_reset_exception(struct pt_regs *regs)
215{
216 /* See if any machine dependent calls */
217 if (ppc_md.system_reset_exception)
218 ppc_md.system_reset_exception(regs);
219
234 die("System Reset", regs, 0);
220 die("System Reset", regs, SIGABRT);
235
236 /* Must die if the interrupt is not recoverable */
237 if (!(regs->msr & MSR_RI))
238 panic("Unrecoverable System Reset");
239
240 /* What should we do here? We could issue a shutdown or hard reset. */
241}
242#endif
243
221
222 /* Must die if the interrupt is not recoverable */
223 if (!(regs->msr & MSR_RI))
224 panic("Unrecoverable System Reset");
225
226 /* What should we do here? We could issue a shutdown or hard reset. */
227}
228#endif
229
244#ifdef CONFIG_PPC32
245/*
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
249 * table.
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.

--- 32 unchanged lines hidden (view full) ---

285 regs->msr |= MSR_RI;
286 regs->nip = entry->fixup;
287 return 1;
288 }
289 }
290#endif /* CONFIG_PPC_PMAC */
291 return 0;
292}
230/*
231 * I/O accesses can cause machine checks on powermacs.
232 * Check if the NIP corresponds to the address of a sync
233 * instruction for which there is an entry in the exception
234 * table.
235 * Note that the 601 only takes a machine check on TEA
236 * (transfer error ack) signal assertion, and does not
237 * set any of the top 16 bits of SRR1.

--- 32 unchanged lines hidden (view full) ---

270 regs->msr |= MSR_RI;
271 regs->nip = entry->fixup;
272 return 1;
273 }
274 }
275#endif /* CONFIG_PPC_PMAC */
276 return 0;
277}
293#endif /* CONFIG_PPC32 */
294
295#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
296
297/* On 4xx, the reason for the machine check or program exception
298 is in the ESR. */
299#define get_reason(regs) ((regs)->dsisr)
300#ifndef CONFIG_FSL_BOOKE
301#define get_mc_reason(regs) ((regs)->dsisr)

--- 19 unchanged lines hidden (view full) ---

321#define REASON_ILLEGAL 0x80000
322#define REASON_PRIVILEGED 0x40000
323#define REASON_TRAP 0x20000
324
325#define single_stepping(regs) ((regs)->msr & MSR_SE)
326#define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
327#endif
328
278
279#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
280
281/* On 4xx, the reason for the machine check or program exception
282 is in the ESR. */
283#define get_reason(regs) ((regs)->dsisr)
284#ifndef CONFIG_FSL_BOOKE
285#define get_mc_reason(regs) ((regs)->dsisr)

--- 19 unchanged lines hidden (view full) ---

305#define REASON_ILLEGAL 0x80000
306#define REASON_PRIVILEGED 0x40000
307#define REASON_TRAP 0x20000
308
309#define single_stepping(regs) ((regs)->msr & MSR_SE)
310#define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
311#endif
312
329#ifdef CONFIG_PPC32
330/*
331 * This is "fall-back" implementation for configurations
332 * which don't provide platform-specific machine check info
333 */
334void __attribute__ ((weak))
335platform_machine_check(struct pt_regs *regs)
336{
337}
313/*
314 * This is "fall-back" implementation for configurations
315 * which don't provide platform-specific machine check info
316 */
317void __attribute__ ((weak))
318platform_machine_check(struct pt_regs *regs)
319{
320}
338#endif
339
340void machine_check_exception(struct pt_regs *regs)
341{
342#ifdef CONFIG_PPC64
343 int recover = 0;
344
345 /* See if any machine dependent calls */
346 if (ppc_md.machine_check_exception)

--- 145 unchanged lines hidden (view full) ---

492 * Optional platform-provided routine to print out
493 * additional info, e.g. bus error registers.
494 */
495 platform_machine_check(regs);
496#endif /* CONFIG_PPC32 */
497
498 if (debugger_fault_handler(regs))
499 return;
321
322void machine_check_exception(struct pt_regs *regs)
323{
324#ifdef CONFIG_PPC64
325 int recover = 0;
326
327 /* See if any machine dependent calls */
328 if (ppc_md.machine_check_exception)

--- 145 unchanged lines hidden (view full) ---

474 * Optional platform-provided routine to print out
475 * additional info, e.g. bus error registers.
476 */
477 platform_machine_check(regs);
478#endif /* CONFIG_PPC32 */
479
480 if (debugger_fault_handler(regs))
481 return;
500 die("Machine check", regs,
501#ifdef CONFIG_PPC32
502 SIGBUS
503#else
504 0
505#endif
506 );
482 die("Machine check", regs, SIGBUS);
507
508 /* Must die if the interrupt is not recoverable */
509 if (!(regs->msr & MSR_RI))
510 panic("Unrecoverable Machine check");
511}
512
513#ifdef CONFIG_PPC32
514void SMIException(struct pt_regs *regs)

--- 22 unchanged lines hidden (view full) ---

537
538#ifdef CONFIG_PPC32
539void RunModeException(struct pt_regs *regs)
540{
541 _exception(SIGTRAP, regs, 0, 0);
542}
543#endif
544
483
484 /* Must die if the interrupt is not recoverable */
485 if (!(regs->msr & MSR_RI))
486 panic("Unrecoverable Machine check");
487}
488
489#ifdef CONFIG_PPC32
490void SMIException(struct pt_regs *regs)

--- 22 unchanged lines hidden (view full) ---

513
514#ifdef CONFIG_PPC32
515void RunModeException(struct pt_regs *regs)
516{
517 _exception(SIGTRAP, regs, 0, 0);
518}
519#endif
520
545void __KPROBES single_step_exception(struct pt_regs *regs)
521void __kprobes single_step_exception(struct pt_regs *regs)
546{
522{
547#ifdef CONFIG_PPC32
548 regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */
523 regs->msr &= ~(MSR_SE | MSR_BE); /* Turn off 'trace' bits */
549#else
550 regs->msr &= ~MSR_SE; /* Turn off 'trace' bit */
551#endif
552
553 if (notify_die(DIE_SSTEP, "single_step", regs, 5,
554 5, SIGTRAP) == NOTIFY_STOP)
555 return;
556 if (debugger_sstep(regs))
557 return;
558
559 _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
560}
561
562/*
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
567 */
524
525 if (notify_die(DIE_SSTEP, "single_step", regs, 5,
526 5, SIGTRAP) == NOTIFY_STOP)
527 return;
528 if (debugger_sstep(regs))
529 return;
530
531 _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
532}
533
534/*
535 * After we have successfully emulated an instruction, we have to
536 * check if the instruction was being single-stepped, and if so,
537 * pretend we got a single-step exception. This was pointed out
538 * by Kumar Gala. -- paulus
539 */
568static inline void emulate_single_step(struct pt_regs *regs)
540static void emulate_single_step(struct pt_regs *regs)
569{
570 if (single_stepping(regs)) {
541{
542 if (single_stepping(regs)) {
571#ifdef CONFIG_PPC32
572 clear_single_step(regs);
573 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
543 clear_single_step(regs);
544 _exception(SIGTRAP, regs, TRAP_TRACE, 0);
574#else
575 single_step_exception(regs);
545 single_step_exception(regs);
576#endif
577 }
578}
579
580static void parse_fpe(struct pt_regs *regs)
581{
582 int code = 0;
583 unsigned long fpscr;
584
546 }
547}
548
549static void parse_fpe(struct pt_regs *regs)
550{
551 int code = 0;
552 unsigned long fpscr;
553
585#ifdef CONFIG_PPC32
586 /* We must make sure the FP state is consistent with
587 * our MSR_FP in regs
588 */
589 preempt_disable();
590 if (regs->msr & MSR_FP)
591 giveup_fpu(current);
592 preempt_enable();
593#else
594 flush_fp_to_thread(current);
554 flush_fp_to_thread(current);
595#endif
596
597 fpscr = current->thread.fpscr;
598
599 /* Invalid operation */
600 if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
601 code = FPE_FLTINV;
602
603 /* Overflow */

--- 128 unchanged lines hidden (view full) ---

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);
736 return 0;
737 }
738
739 /* Emulating the dcba insn is just a no-op. */
555
556 fpscr = current->thread.fpscr;
557
558 /* Invalid operation */
559 if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
560 code = FPE_FLTINV;
561
562 /* Overflow */

--- 128 unchanged lines hidden (view full) ---

691 /* Emulate the mfspr rD, PVR. */
692 if ((instword & INST_MFSPR_PVR_MASK) == INST_MFSPR_PVR) {
693 rd = (instword >> 21) & 0x1f;
694 regs->gpr[rd] = mfspr(SPRN_PVR);
695 return 0;
696 }
697
698 /* Emulating the dcba insn is just a no-op. */
740 if ((instword & INST_DCBA_MASK) == INST_DCBA) {
741#ifdef CONFIG_PPC64
742 static int warned;
743
744 if (!warned) {
745 printk(KERN_WARNING
746 "process %d (%s) uses obsolete 'dcba' insn\n",
747 current->pid, current->comm);
748 warned = 1;
749 }
750#endif /* CONFIG_PPC64 */
699 if ((instword & INST_DCBA_MASK) == INST_DCBA)
751 return 0;
700 return 0;
752 }
753
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;
758#ifdef CONFIG_PPC64
759 static int warned;
760

--- 51 unchanged lines hidden (view full) ---

812 addr = regs->nip; /* address of trap instruction */
813 if (addr < PAGE_OFFSET)
814 return 0;
815 bug = find_bug(regs->nip);
816 if (bug == NULL)
817 return 0;
818 if (bug->line & BUG_WARNING_TRAP) {
819 /* this is a WARN_ON rather than BUG/BUG_ON */
701
702 /* Emulate the mcrxr insn. */
703 if ((instword & INST_MCRXR_MASK) == INST_MCRXR) {
704 unsigned int shift = (instword >> 21) & 0x1c;
705 unsigned long msk = 0xf0000000UL >> shift;
706#ifdef CONFIG_PPC64
707 static int warned;
708

--- 51 unchanged lines hidden (view full) ---

760 addr = regs->nip; /* address of trap instruction */
761 if (addr < PAGE_OFFSET)
762 return 0;
763 bug = find_bug(regs->nip);
764 if (bug == NULL)
765 return 0;
766 if (bug->line & BUG_WARNING_TRAP) {
767 /* this is a WARN_ON rather than BUG/BUG_ON */
820#if defined(CONFIG_PPC32) && defined(CONFIG_XMON)
768#ifdef 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);
824#endif
825 printk(KERN_ERR "Badness in %s at %s:%d\n",
826 bug->function, bug->file,
827 bug->line & ~BUG_WARNING_TRAP);
828#ifdef CONFIG_PPC32

--- 9 unchanged lines hidden (view full) ---

838 xmon(regs);
839#endif
840 printk(KERN_CRIT "kernel BUG in %s at %s:%d!\n",
841 bug->function, bug->file, bug->line);
842
843 return 0;
844}
845
769 xmon_printf(KERN_ERR "Badness in %s at %s:%d\n",
770 bug->function, bug->file,
771 bug->line & ~BUG_WARNING_TRAP);
772#endif
773 printk(KERN_ERR "Badness in %s at %s:%d\n",
774 bug->function, bug->file,
775 bug->line & ~BUG_WARNING_TRAP);
776#ifdef CONFIG_PPC32

--- 9 unchanged lines hidden (view full) ---

786 xmon(regs);
787#endif
788 printk(KERN_CRIT "kernel BUG in %s at %s:%d!\n",
789 bug->function, bug->file, bug->line);
790
791 return 0;
792}
793
846void __KPROBES program_check_exception(struct pt_regs *regs)
794void __kprobes program_check_exception(struct pt_regs *regs)
847{
848 unsigned int reason = get_reason(regs);
795{
796 unsigned int reason = get_reason(regs);
849#if defined(CONFIG_PPC32) && defined(CONFIG_MATH_EMULATION)
850 extern int do_mathemu(struct pt_regs *regs);
851
797 extern int do_mathemu(struct pt_regs *regs);
798
799#ifdef CONFIG_MATH_EMULATION
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);
861 return;
862 }
800 /* (reason & REASON_ILLEGAL) would be the obvious thing here,
801 * but there seems to be a hardware bug on the 405GP (RevD)
802 * that means ESR is sometimes set incorrectly - either to
803 * ESR_DST (!?) or 0. In the process of chasing this with the
804 * hardware people - not sure if it can happen on any illegal
805 * instruction or only on FP instructions, whether there is a
806 * pattern to occurences etc. -dgibson 31/Mar/2003 */
807 if (!(reason & REASON_TRAP) && do_mathemu(regs) == 0) {
808 emulate_single_step(regs);
809 return;
810 }
863#endif
811#endif /* CONFIG_MATH_EMULATION */
864
812
865#ifdef CONFIG_PPC64
866 if (debugger_fault_handler(regs))
867 return;
868#endif
869
870 if (reason & REASON_FP) {
871 /* IEEE FP exception */
872 parse_fpe(regs);
813 if (reason & REASON_FP) {
814 /* IEEE FP exception */
815 parse_fpe(regs);
873 } else if (reason & REASON_TRAP) {
816 return;
817 }
818 if (reason & REASON_TRAP) {
874 /* trap exception */
819 /* trap exception */
875#ifdef CONFIG_PPC64
876 if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
877 == NOTIFY_STOP)
878 return;
820 if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
821 == NOTIFY_STOP)
822 return;
879#endif
880 if (debugger_bpt(regs))
881 return;
882 if (check_bug_trap(regs)) {
883 regs->nip += 4;
884 return;
885 }
823 if (debugger_bpt(regs))
824 return;
825 if (check_bug_trap(regs)) {
826 regs->nip += 4;
827 return;
828 }
886 _exception(SIGTRAP, regs, TRAP_BRKPT,
887#ifdef CONFIG_PPC32
888 0
889#else
890 regs->nip
891#endif
892 );
893 } else
894#ifdef CONFIG_PPC32
895 if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED))
896#endif
897 {
898 /* Privileged or illegal instruction; try to emulate it. */
829 _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
830 return;
831 }
832
833 /* Try to emulate it if we should. */
834 if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
899 switch (emulate_instruction(regs)) {
900 case 0:
901 regs->nip += 4;
902 emulate_single_step(regs);
835 switch (emulate_instruction(regs)) {
836 case 0:
837 regs->nip += 4;
838 emulate_single_step(regs);
903 break;
839 return;
904 case -EFAULT:
905 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
840 case -EFAULT:
841 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
906 break;
907 default:
908 if (reason & REASON_PRIVILEGED)
909 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
910 else
911 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
912 break;
842 return;
913 }
914 }
843 }
844 }
845
846 if (reason & REASON_PRIVILEGED)
847 _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
848 else
849 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
915}
916
917void alignment_exception(struct pt_regs *regs)
918{
919 int fixed;
920
921 fixed = fix_alignment(regs);
922
923 if (fixed == 1) {
924 regs->nip += 4; /* skip over emulated instruction */
925 emulate_single_step(regs);
926 return;
927 }
928
929 /* Operand address was bad */
930 if (fixed == -EFAULT) {
931 if (user_mode(regs))
850}
851
852void alignment_exception(struct pt_regs *regs)
853{
854 int fixed;
855
856 fixed = fix_alignment(regs);
857
858 if (fixed == 1) {
859 regs->nip += 4; /* skip over emulated instruction */
860 emulate_single_step(regs);
861 return;
862 }
863
864 /* Operand address was bad */
865 if (fixed == -EFAULT) {
866 if (user_mode(regs))
932 _exception(SIGSEGV, regs,
933#ifdef CONFIG_PPC32
934 SEGV_ACCERR,
935#else
936 SEGV_MAPERR,
937#endif
938 regs->dar);
867 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->dar);
939 else
940 /* Search exception table */
941 bad_page_fault(regs, regs->dar, SIGSEGV);
942 return;
943 }
868 else
869 /* Search exception table */
870 bad_page_fault(regs, regs->dar, SIGSEGV);
871 return;
872 }
944 _exception(SIGBUS, regs, BUS_ADRALN,
945#ifdef CONFIG_PPC32
946 regs->dar
947#else
948 regs->nip
949#endif
950 );
873 _exception(SIGBUS, regs, BUS_ADRALN, regs->dar);
951}
952
953#ifdef CONFIG_PPC32
954void StackOverflow(struct pt_regs *regs)
955{
956 printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
957 current, regs->gpr[1]);
958 debugger(regs);

--- 12 unchanged lines hidden (view full) ---

971void trace_syscall(struct pt_regs *regs)
972{
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());
976}
977#endif /* CONFIG_PPC32 */
978
874}
875
876#ifdef CONFIG_PPC32
877void StackOverflow(struct pt_regs *regs)
878{
879 printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
880 current, regs->gpr[1]);
881 debugger(regs);

--- 12 unchanged lines hidden (view full) ---

894void trace_syscall(struct pt_regs *regs)
895{
896 printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
897 current, current->pid, regs->nip, regs->link, regs->gpr[0],
898 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
899}
900#endif /* CONFIG_PPC32 */
901
979#ifdef CONFIG_PPC64
980void kernel_fp_unavailable_exception(struct pt_regs *regs)
981{
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);
985}
902void kernel_fp_unavailable_exception(struct pt_regs *regs)
903{
904 printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
905 "%lx at %lx\n", regs->trap, regs->nip);
906 die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
907}
986#endif
987
988void altivec_unavailable_exception(struct pt_regs *regs)
989{
908
909void altivec_unavailable_exception(struct pt_regs *regs)
910{
990#if !defined(CONFIG_ALTIVEC) || defined(CONFIG_PPC64)
911#if !defined(CONFIG_ALTIVEC)
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);
995 return;
996 }
997#endif
912 if (user_mode(regs)) {
913 /* A user program has executed an altivec instruction,
914 but this kernel doesn't support altivec. */
915 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
916 return;
917 }
918#endif
998#ifdef CONFIG_PPC32
999 {
1000 static int kernel_altivec_count;
1001
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;
1008 }
1009#else
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);
919 printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
920 "%lx at %lx\n", regs->trap, regs->nip);
921 die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
1013#endif
1014}
1015
1016#ifdef CONFIG_PPC64
1017extern perf_irq_t perf_irq;
1018#endif
1019
1020#if defined(CONFIG_PPC64) || defined(CONFIG_E500)
1021void performance_monitor_exception(struct pt_regs *regs)
1022{
1023 perf_irq(regs);
1024}
1025#endif
1026
922}
923
924#ifdef CONFIG_PPC64
925extern perf_irq_t perf_irq;
926#endif
927
928#if defined(CONFIG_PPC64) || defined(CONFIG_E500)
929void performance_monitor_exception(struct pt_regs *regs)
930{
931 perf_irq(regs);
932}
933#endif
934
1027
1028#if defined(CONFIG_PPC32) && defined(CONFIG_8xx)
935#ifdef CONFIG_8xx
1029void SoftwareEmulation(struct pt_regs *regs)
1030{
1031 extern int do_mathemu(struct pt_regs *);
1032 extern int Soft_emulate_8xx(struct pt_regs *);
1033 int errcode;
1034
1035 CHECK_FULL_REGS(regs);
1036

--- 12 unchanged lines hidden (view full) ---

1049 _exception(SIGFPE, regs, 0, 0);
1050 else if (errcode == -EFAULT)
1051 _exception(SIGSEGV, regs, 0, 0);
1052 else
1053 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
1054 } else
1055 emulate_single_step(regs);
1056}
936void SoftwareEmulation(struct pt_regs *regs)
937{
938 extern int do_mathemu(struct pt_regs *);
939 extern int Soft_emulate_8xx(struct pt_regs *);
940 int errcode;
941
942 CHECK_FULL_REGS(regs);
943

--- 12 unchanged lines hidden (view full) ---

956 _exception(SIGFPE, regs, 0, 0);
957 else if (errcode == -EFAULT)
958 _exception(SIGSEGV, regs, 0, 0);
959 else
960 _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
961 } else
962 emulate_single_step(regs);
963}
1057#endif /* defined(CONFIG_PPC32) && defined(CONFIG_8xx) */
964#endif /* CONFIG_8xx */
1058
1059#ifdef CONFIG_PPC32
1060#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
1061
1062void DebugException(struct pt_regs *regs, unsigned long debug_status)
1063{
1064 if (debug_status & DBSR_IC) { /* instruction completion */
1065 regs->msr &= ~MSR_DE;

--- 20 unchanged lines hidden (view full) ---

1086}
1087#endif /* CONFIG_INT_TAU */
1088#endif /* CONFIG_PPC32*/
1089
1090#ifdef CONFIG_ALTIVEC
1091void altivec_assist_exception(struct pt_regs *regs)
1092{
1093 int err;
965
966#ifdef CONFIG_PPC32
967#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
968
969void DebugException(struct pt_regs *regs, unsigned long debug_status)
970{
971 if (debug_status & DBSR_IC) { /* instruction completion */
972 regs->msr &= ~MSR_DE;

--- 20 unchanged lines hidden (view full) ---

993}
994#endif /* CONFIG_INT_TAU */
995#endif /* CONFIG_PPC32*/
996
997#ifdef CONFIG_ALTIVEC
998void altivec_assist_exception(struct pt_regs *regs)
999{
1000 int err;
1094#ifdef CONFIG_PPC64
1095 siginfo_t info;
1096#endif
1097
1001
1098#ifdef CONFIG_PPC32
1099 preempt_disable();
1100 if (regs->msr & MSR_VEC)
1101 giveup_altivec(current);
1102 preempt_enable();
1103#endif
1104 if (!user_mode(regs)) {
1105 printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
1106 " at %lx\n", regs->nip);
1002 if (!user_mode(regs)) {
1003 printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
1004 " at %lx\n", regs->nip);
1107 die("Kernel "
1108#ifdef CONFIG_PPC64
1109 "VMX/"
1110#endif
1111 "Altivec assist exception", regs, SIGILL);
1005 die("Kernel VMX/Altivec assist exception", regs, SIGILL);
1112 }
1113
1006 }
1007
1114#ifdef CONFIG_PPC64
1115 flush_altivec_to_thread(current);
1008 flush_altivec_to_thread(current);
1116#endif /* CONFIG_PPC64 */
1117
1118 err = emulate_altivec(regs);
1119 if (err == 0) {
1120 regs->nip += 4; /* skip emulated instruction */
1121 emulate_single_step(regs);
1122 return;
1123 }
1124
1125 if (err == -EFAULT) {
1126 /* got an error reading the instruction */
1009
1010 err = emulate_altivec(regs);
1011 if (err == 0) {
1012 regs->nip += 4; /* skip emulated instruction */
1013 emulate_single_step(regs);
1014 return;
1015 }
1016
1017 if (err == -EFAULT) {
1018 /* got an error reading the instruction */
1127#ifdef CONFIG_PPC32
1128 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
1019 _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
1129#else
1130 info.si_signo = SIGSEGV;
1131 info.si_errno = 0;
1132 info.si_code = SEGV_MAPERR;
1133 info.si_addr = (void __user *) regs->nip;
1134 force_sig_info(SIGSEGV, &info, current);
1135#endif
1136 } else {
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;
1143 }
1144}
1145#endif /* CONFIG_ALTIVEC */
1146
1020 } else {
1021 /* didn't recognize the instruction */
1022 /* XXX quick hack for now: set the non-Java bit in the VSCR */
1023 if (printk_ratelimit())
1024 printk(KERN_ERR "Unrecognized altivec instruction "
1025 "in %s at %lx\n", current->comm, regs->nip);
1026 current->thread.vscr.u[3] |= 0x10000;
1027 }
1028}
1029#endif /* CONFIG_ALTIVEC */
1030
1147#ifdef CONFIG_PPC32
1148#ifdef CONFIG_FSL_BOOKE
1149void CacheLockingException(struct pt_regs *regs, unsigned long address,
1150 unsigned long error_code)
1151{
1152 /* We treat cache locking instructions from the user
1153 * as priv ops, in the future we could try to do
1154 * something smarter
1155 */

--- 33 unchanged lines hidden (view full) ---

1189 code = FPE_FLTRES;
1190
1191 current->thread.spefscr = spefscr;
1192
1193 _exception(SIGFPE, regs, code, regs->nip);
1194 return;
1195}
1196#endif
1031#ifdef CONFIG_FSL_BOOKE
1032void CacheLockingException(struct pt_regs *regs, unsigned long address,
1033 unsigned long error_code)
1034{
1035 /* We treat cache locking instructions from the user
1036 * as priv ops, in the future we could try to do
1037 * something smarter
1038 */

--- 33 unchanged lines hidden (view full) ---

1072 code = FPE_FLTRES;
1073
1074 current->thread.spefscr = spefscr;
1075
1076 _exception(SIGFPE, regs, code, regs->nip);
1077 return;
1078}
1079#endif
1197#endif /* CONFIG_PPC32 */
1198
1080
1199#ifdef CONFIG_PPC64
1200/*
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.
1205 */
1206void unrecoverable_exception(struct pt_regs *regs)
1207{
1208 printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
1209 regs->trap, regs->nip);
1210 die("Unrecoverable exception", regs, SIGABRT);
1211}
1081/*
1082 * We enter here if we get an unrecoverable exception, that is, one
1083 * that happened at a point where the RI (recoverable interrupt) bit
1084 * in the MSR is 0. This indicates that SRR0/1 are live, and that
1085 * we therefore lost state by taking this exception.
1086 */
1087void unrecoverable_exception(struct pt_regs *regs)
1088{
1089 printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
1090 regs->trap, regs->nip);
1091 die("Unrecoverable exception", regs, SIGABRT);
1092}
1212#endif /* CONFIG_PPC64 */
1213
1093
1214#ifdef CONFIG_PPC32
1215#ifdef CONFIG_BOOKE_WDT
1216/*
1217 * Default handler for a Watchdog exception,
1218 * spins until a reboot occurs
1219 */
1220void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
1221{
1222 /* Generic WatchdogHandler, implement your own */
1223 mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
1224 return;
1225}
1226
1227void WatchdogException(struct pt_regs *regs)
1228{
1229 printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
1230 WatchdogHandler(regs);
1231}
1232#endif
1094#ifdef CONFIG_BOOKE_WDT
1095/*
1096 * Default handler for a Watchdog exception,
1097 * spins until a reboot occurs
1098 */
1099void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
1100{
1101 /* Generic WatchdogHandler, implement your own */
1102 mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
1103 return;
1104}
1105
1106void WatchdogException(struct pt_regs *regs)
1107{
1108 printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
1109 WatchdogHandler(regs);
1110}
1111#endif
1233#endif /* CONFIG_PPC32 */
1234
1112
1235#ifdef CONFIG_PPC64
1236/*
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.
1239 */
1240void kernel_bad_stack(struct pt_regs *regs)
1241{
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);
1245}
1113/*
1114 * We enter here if we discover during exception entry that we are
1115 * running in supervisor mode with a userspace value in the stack pointer.
1116 */
1117void kernel_bad_stack(struct pt_regs *regs)
1118{
1119 printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
1120 regs->gpr[1], regs->nip);
1121 die("Bad kernel stack pointer", regs, SIGABRT);
1122}
1246#endif
1247
1248void __init trap_init(void)
1249{
1250}
1123
1124void __init trap_init(void)
1125{
1126}