xref: /openbmc/linux/arch/powerpc/kernel/traps.c (revision 80947e7c99c29ce3a78bdc1933b310468455a82f)
114cf11afSPaul Mackerras /*
214cf11afSPaul Mackerras  *  Copyright (C) 1995-1996  Gary Thomas (gdt@linuxppc.org)
314cf11afSPaul Mackerras  *
414cf11afSPaul Mackerras  *  This program is free software; you can redistribute it and/or
514cf11afSPaul Mackerras  *  modify it under the terms of the GNU General Public License
614cf11afSPaul Mackerras  *  as published by the Free Software Foundation; either version
714cf11afSPaul Mackerras  *  2 of the License, or (at your option) any later version.
814cf11afSPaul Mackerras  *
914cf11afSPaul Mackerras  *  Modified by Cort Dougan (cort@cs.nmt.edu)
1014cf11afSPaul Mackerras  *  and Paul Mackerras (paulus@samba.org)
1114cf11afSPaul Mackerras  */
1214cf11afSPaul Mackerras 
1314cf11afSPaul Mackerras /*
1414cf11afSPaul Mackerras  * This file handles the architecture-dependent parts of hardware exceptions
1514cf11afSPaul Mackerras  */
1614cf11afSPaul Mackerras 
1714cf11afSPaul Mackerras #include <linux/errno.h>
1814cf11afSPaul Mackerras #include <linux/sched.h>
1914cf11afSPaul Mackerras #include <linux/kernel.h>
2014cf11afSPaul Mackerras #include <linux/mm.h>
2114cf11afSPaul Mackerras #include <linux/stddef.h>
2214cf11afSPaul Mackerras #include <linux/unistd.h>
238dad3f92SPaul Mackerras #include <linux/ptrace.h>
2414cf11afSPaul Mackerras #include <linux/slab.h>
2514cf11afSPaul Mackerras #include <linux/user.h>
2614cf11afSPaul Mackerras #include <linux/interrupt.h>
2714cf11afSPaul Mackerras #include <linux/init.h>
2814cf11afSPaul Mackerras #include <linux/module.h>
298dad3f92SPaul Mackerras #include <linux/prctl.h>
3014cf11afSPaul Mackerras #include <linux/delay.h>
3114cf11afSPaul Mackerras #include <linux/kprobes.h>
32cc532915SMichael Ellerman #include <linux/kexec.h>
335474c120SMichael Hanselmann #include <linux/backlight.h>
3473c9ceabSJeremy Fitzhardinge #include <linux/bug.h>
351eeb66a1SChristoph Hellwig #include <linux/kdebug.h>
36*80947e7cSGeert Uytterhoeven #include <linux/debugfs.h>
3714cf11afSPaul Mackerras 
38*80947e7cSGeert Uytterhoeven #include <asm/emulated_ops.h>
3914cf11afSPaul Mackerras #include <asm/pgtable.h>
4014cf11afSPaul Mackerras #include <asm/uaccess.h>
4114cf11afSPaul Mackerras #include <asm/system.h>
4214cf11afSPaul Mackerras #include <asm/io.h>
4386417780SPaul Mackerras #include <asm/machdep.h>
4486417780SPaul Mackerras #include <asm/rtas.h>
45f7f6f4feSDavid Gibson #include <asm/pmc.h>
46dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC32
4714cf11afSPaul Mackerras #include <asm/reg.h>
4886417780SPaul Mackerras #endif
4914cf11afSPaul Mackerras #ifdef CONFIG_PMAC_BACKLIGHT
5014cf11afSPaul Mackerras #include <asm/backlight.h>
5114cf11afSPaul Mackerras #endif
52dc1c1ca3SStephen Rothwell #ifdef CONFIG_PPC64
5386417780SPaul Mackerras #include <asm/firmware.h>
54dc1c1ca3SStephen Rothwell #include <asm/processor.h>
55dc1c1ca3SStephen Rothwell #endif
56c0ce7d08SDavid Wilder #include <asm/kexec.h>
5716c57b36SKumar Gala #include <asm/ppc-opcode.h>
58620165f9SKumar Gala #ifdef CONFIG_FSL_BOOKE
59620165f9SKumar Gala #include <asm/dbell.h>
60620165f9SKumar Gala #endif
61dc1c1ca3SStephen Rothwell 
627dbb922cSOlof Johansson #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
6314cf11afSPaul Mackerras int (*__debugger)(struct pt_regs *regs);
6414cf11afSPaul Mackerras int (*__debugger_ipi)(struct pt_regs *regs);
6514cf11afSPaul Mackerras int (*__debugger_bpt)(struct pt_regs *regs);
6614cf11afSPaul Mackerras int (*__debugger_sstep)(struct pt_regs *regs);
6714cf11afSPaul Mackerras int (*__debugger_iabr_match)(struct pt_regs *regs);
6814cf11afSPaul Mackerras int (*__debugger_dabr_match)(struct pt_regs *regs);
6914cf11afSPaul Mackerras int (*__debugger_fault_handler)(struct pt_regs *regs);
7014cf11afSPaul Mackerras 
7114cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger);
7214cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_ipi);
7314cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_bpt);
7414cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_sstep);
7514cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_iabr_match);
7614cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_dabr_match);
7714cf11afSPaul Mackerras EXPORT_SYMBOL(__debugger_fault_handler);
7814cf11afSPaul Mackerras #endif
7914cf11afSPaul Mackerras 
8014cf11afSPaul Mackerras /*
8114cf11afSPaul Mackerras  * Trap & Exception support
8214cf11afSPaul Mackerras  */
8314cf11afSPaul Mackerras 
846031d9d9Santon@samba.org #ifdef CONFIG_PMAC_BACKLIGHT
856031d9d9Santon@samba.org static void pmac_backlight_unblank(void)
866031d9d9Santon@samba.org {
876031d9d9Santon@samba.org 	mutex_lock(&pmac_backlight_mutex);
886031d9d9Santon@samba.org 	if (pmac_backlight) {
896031d9d9Santon@samba.org 		struct backlight_properties *props;
906031d9d9Santon@samba.org 
916031d9d9Santon@samba.org 		props = &pmac_backlight->props;
926031d9d9Santon@samba.org 		props->brightness = props->max_brightness;
936031d9d9Santon@samba.org 		props->power = FB_BLANK_UNBLANK;
946031d9d9Santon@samba.org 		backlight_update_status(pmac_backlight);
956031d9d9Santon@samba.org 	}
966031d9d9Santon@samba.org 	mutex_unlock(&pmac_backlight_mutex);
976031d9d9Santon@samba.org }
986031d9d9Santon@samba.org #else
996031d9d9Santon@samba.org static inline void pmac_backlight_unblank(void) { }
1006031d9d9Santon@samba.org #endif
1016031d9d9Santon@samba.org 
10214cf11afSPaul Mackerras int die(const char *str, struct pt_regs *regs, long err)
10314cf11afSPaul Mackerras {
10434c2a14fSanton@samba.org 	static struct {
10534c2a14fSanton@samba.org 		spinlock_t lock;
10634c2a14fSanton@samba.org 		u32 lock_owner;
10734c2a14fSanton@samba.org 		int lock_owner_depth;
10834c2a14fSanton@samba.org 	} die = {
10934c2a14fSanton@samba.org 		.lock =			__SPIN_LOCK_UNLOCKED(die.lock),
11034c2a14fSanton@samba.org 		.lock_owner =		-1,
11134c2a14fSanton@samba.org 		.lock_owner_depth =	0
11234c2a14fSanton@samba.org 	};
113c0ce7d08SDavid Wilder 	static int die_counter;
11434c2a14fSanton@samba.org 	unsigned long flags;
11514cf11afSPaul Mackerras 
11614cf11afSPaul Mackerras 	if (debugger(regs))
11714cf11afSPaul Mackerras 		return 1;
11814cf11afSPaul Mackerras 
119293e4688Santon@samba.org 	oops_enter();
120293e4688Santon@samba.org 
12134c2a14fSanton@samba.org 	if (die.lock_owner != raw_smp_processor_id()) {
12214cf11afSPaul Mackerras 		console_verbose();
12334c2a14fSanton@samba.org 		spin_lock_irqsave(&die.lock, flags);
12434c2a14fSanton@samba.org 		die.lock_owner = smp_processor_id();
12534c2a14fSanton@samba.org 		die.lock_owner_depth = 0;
12614cf11afSPaul Mackerras 		bust_spinlocks(1);
1276031d9d9Santon@samba.org 		if (machine_is(powermac))
1286031d9d9Santon@samba.org 			pmac_backlight_unblank();
12934c2a14fSanton@samba.org 	} else {
13034c2a14fSanton@samba.org 		local_save_flags(flags);
13134c2a14fSanton@samba.org 	}
1325474c120SMichael Hanselmann 
13334c2a14fSanton@samba.org 	if (++die.lock_owner_depth < 3) {
13414cf11afSPaul Mackerras 		printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
13514cf11afSPaul Mackerras #ifdef CONFIG_PREEMPT
13614cf11afSPaul Mackerras 		printk("PREEMPT ");
13714cf11afSPaul Mackerras #endif
13814cf11afSPaul Mackerras #ifdef CONFIG_SMP
13914cf11afSPaul Mackerras 		printk("SMP NR_CPUS=%d ", NR_CPUS);
14014cf11afSPaul Mackerras #endif
14114cf11afSPaul Mackerras #ifdef CONFIG_DEBUG_PAGEALLOC
14214cf11afSPaul Mackerras 		printk("DEBUG_PAGEALLOC ");
14314cf11afSPaul Mackerras #endif
14414cf11afSPaul Mackerras #ifdef CONFIG_NUMA
14514cf11afSPaul Mackerras 		printk("NUMA ");
14614cf11afSPaul Mackerras #endif
147ae7f4463Santon@samba.org 		printk("%s\n", ppc_md.name ? ppc_md.name : "");
148e8222502SBenjamin Herrenschmidt 
14914cf11afSPaul Mackerras 		print_modules();
15014cf11afSPaul Mackerras 		show_regs(regs);
15134c2a14fSanton@samba.org 	} else {
15234c2a14fSanton@samba.org 		printk("Recursive die() failure, output suppressed\n");
15334c2a14fSanton@samba.org 	}
15434c2a14fSanton@samba.org 
15514cf11afSPaul Mackerras 	bust_spinlocks(0);
15634c2a14fSanton@samba.org 	die.lock_owner = -1;
157bcdcd8e7SPavel Emelianov 	add_taint(TAINT_DIE);
15834c2a14fSanton@samba.org 	spin_unlock_irqrestore(&die.lock, flags);
159cc532915SMichael Ellerman 
160c0ce7d08SDavid Wilder 	if (kexec_should_crash(current) ||
161c0ce7d08SDavid Wilder 		kexec_sr_activated(smp_processor_id()))
162cc532915SMichael Ellerman 		crash_kexec(regs);
163c0ce7d08SDavid Wilder 	crash_kexec_secondary(regs);
16414cf11afSPaul Mackerras 
16514cf11afSPaul Mackerras 	if (in_interrupt())
16614cf11afSPaul Mackerras 		panic("Fatal exception in interrupt");
16714cf11afSPaul Mackerras 
168cea6a4baSHorms 	if (panic_on_oops)
169012c437dSHorms 		panic("Fatal exception");
170cea6a4baSHorms 
171293e4688Santon@samba.org 	oops_exit();
17214cf11afSPaul Mackerras 	do_exit(err);
17314cf11afSPaul Mackerras 
17414cf11afSPaul Mackerras 	return 0;
17514cf11afSPaul Mackerras }
17614cf11afSPaul Mackerras 
17714cf11afSPaul Mackerras void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
17814cf11afSPaul Mackerras {
17914cf11afSPaul Mackerras 	siginfo_t info;
180d0c3d534SOlof Johansson 	const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \
181d0c3d534SOlof Johansson 			"at %08lx nip %08lx lr %08lx code %x\n";
182d0c3d534SOlof Johansson 	const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \
183d0c3d534SOlof Johansson 			"at %016lx nip %016lx lr %016lx code %x\n";
18414cf11afSPaul Mackerras 
18514cf11afSPaul Mackerras 	if (!user_mode(regs)) {
18614cf11afSPaul Mackerras 		if (die("Exception in kernel mode", regs, signr))
18714cf11afSPaul Mackerras 			return;
188d0c3d534SOlof Johansson 	} else if (show_unhandled_signals &&
189d0c3d534SOlof Johansson 		    unhandled_signal(current, signr) &&
190d0c3d534SOlof Johansson 		    printk_ratelimit()) {
191d0c3d534SOlof Johansson 			printk(regs->msr & MSR_SF ? fmt64 : fmt32,
192d0c3d534SOlof Johansson 				current->comm, current->pid, signr,
193d0c3d534SOlof Johansson 				addr, regs->nip, regs->link, code);
19414cf11afSPaul Mackerras 		}
19514cf11afSPaul Mackerras 
19614cf11afSPaul Mackerras 	memset(&info, 0, sizeof(info));
19714cf11afSPaul Mackerras 	info.si_signo = signr;
19814cf11afSPaul Mackerras 	info.si_code = code;
19914cf11afSPaul Mackerras 	info.si_addr = (void __user *) addr;
20014cf11afSPaul Mackerras 	force_sig_info(signr, &info, current);
20114cf11afSPaul Mackerras 
20214cf11afSPaul Mackerras 	/*
20314cf11afSPaul Mackerras 	 * Init gets no signals that it doesn't have a handler for.
20414cf11afSPaul Mackerras 	 * That's all very well, but if it has caused a synchronous
20514cf11afSPaul Mackerras 	 * exception and we ignore the resulting signal, it will just
20614cf11afSPaul Mackerras 	 * generate the same exception over and over again and we get
20714cf11afSPaul Mackerras 	 * nowhere.  Better to kill it and let the kernel panic.
20814cf11afSPaul Mackerras 	 */
209b460cbc5SSerge E. Hallyn 	if (is_global_init(current)) {
21014cf11afSPaul Mackerras 		__sighandler_t handler;
21114cf11afSPaul Mackerras 
21214cf11afSPaul Mackerras 		spin_lock_irq(&current->sighand->siglock);
21314cf11afSPaul Mackerras 		handler = current->sighand->action[signr-1].sa.sa_handler;
21414cf11afSPaul Mackerras 		spin_unlock_irq(&current->sighand->siglock);
21514cf11afSPaul Mackerras 		if (handler == SIG_DFL) {
21614cf11afSPaul Mackerras 			/* init has generated a synchronous exception
21714cf11afSPaul Mackerras 			   and it doesn't have a handler for the signal */
21814cf11afSPaul Mackerras 			printk(KERN_CRIT "init has generated signal %d "
21914cf11afSPaul Mackerras 			       "but has no handler for it\n", signr);
22014cf11afSPaul Mackerras 			do_exit(signr);
22114cf11afSPaul Mackerras 		}
22214cf11afSPaul Mackerras 	}
22314cf11afSPaul Mackerras }
22414cf11afSPaul Mackerras 
22514cf11afSPaul Mackerras #ifdef CONFIG_PPC64
22614cf11afSPaul Mackerras void system_reset_exception(struct pt_regs *regs)
22714cf11afSPaul Mackerras {
22814cf11afSPaul Mackerras 	/* See if any machine dependent calls */
229c902be71SArnd Bergmann 	if (ppc_md.system_reset_exception) {
230c902be71SArnd Bergmann 		if (ppc_md.system_reset_exception(regs))
231c902be71SArnd Bergmann 			return;
232c902be71SArnd Bergmann 	}
23314cf11afSPaul Mackerras 
234c0ce7d08SDavid Wilder #ifdef CONFIG_KEXEC
235c0ce7d08SDavid Wilder 	cpu_set(smp_processor_id(), cpus_in_sr);
236c0ce7d08SDavid Wilder #endif
237c0ce7d08SDavid Wilder 
2388dad3f92SPaul Mackerras 	die("System Reset", regs, SIGABRT);
23914cf11afSPaul Mackerras 
240eac8392fSDavid Wilder 	/*
241eac8392fSDavid Wilder 	 * Some CPUs when released from the debugger will execute this path.
242eac8392fSDavid Wilder 	 * These CPUs entered the debugger via a soft-reset. If the CPU was
243eac8392fSDavid Wilder 	 * hung before entering the debugger it will return to the hung
244eac8392fSDavid Wilder 	 * state when exiting this function.  This causes a problem in
245eac8392fSDavid Wilder 	 * kdump since the hung CPU(s) will not respond to the IPI sent
246eac8392fSDavid Wilder 	 * from kdump. To prevent the problem we call crash_kexec_secondary()
247eac8392fSDavid Wilder 	 * here. If a kdump had not been initiated or we exit the debugger
248eac8392fSDavid Wilder 	 * with the "exit and recover" command (x) crash_kexec_secondary()
249eac8392fSDavid Wilder 	 * will return after 5ms and the CPU returns to its previous state.
250eac8392fSDavid Wilder 	 */
251eac8392fSDavid Wilder 	crash_kexec_secondary(regs);
252eac8392fSDavid Wilder 
25314cf11afSPaul Mackerras 	/* Must die if the interrupt is not recoverable */
25414cf11afSPaul Mackerras 	if (!(regs->msr & MSR_RI))
25514cf11afSPaul Mackerras 		panic("Unrecoverable System Reset");
25614cf11afSPaul Mackerras 
25714cf11afSPaul Mackerras 	/* What should we do here? We could issue a shutdown or hard reset. */
25814cf11afSPaul Mackerras }
25914cf11afSPaul Mackerras #endif
26014cf11afSPaul Mackerras 
26114cf11afSPaul Mackerras /*
26214cf11afSPaul Mackerras  * I/O accesses can cause machine checks on powermacs.
26314cf11afSPaul Mackerras  * Check if the NIP corresponds to the address of a sync
26414cf11afSPaul Mackerras  * instruction for which there is an entry in the exception
26514cf11afSPaul Mackerras  * table.
26614cf11afSPaul Mackerras  * Note that the 601 only takes a machine check on TEA
26714cf11afSPaul Mackerras  * (transfer error ack) signal assertion, and does not
26814cf11afSPaul Mackerras  * set any of the top 16 bits of SRR1.
26914cf11afSPaul Mackerras  *  -- paulus.
27014cf11afSPaul Mackerras  */
27114cf11afSPaul Mackerras static inline int check_io_access(struct pt_regs *regs)
27214cf11afSPaul Mackerras {
27368a64357SBenjamin Herrenschmidt #ifdef CONFIG_PPC32
27414cf11afSPaul Mackerras 	unsigned long msr = regs->msr;
27514cf11afSPaul Mackerras 	const struct exception_table_entry *entry;
27614cf11afSPaul Mackerras 	unsigned int *nip = (unsigned int *)regs->nip;
27714cf11afSPaul Mackerras 
27814cf11afSPaul Mackerras 	if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
27914cf11afSPaul Mackerras 	    && (entry = search_exception_tables(regs->nip)) != NULL) {
28014cf11afSPaul Mackerras 		/*
28114cf11afSPaul Mackerras 		 * Check that it's a sync instruction, or somewhere
28214cf11afSPaul Mackerras 		 * in the twi; isync; nop sequence that inb/inw/inl uses.
28314cf11afSPaul Mackerras 		 * As the address is in the exception table
28414cf11afSPaul Mackerras 		 * we should be able to read the instr there.
28514cf11afSPaul Mackerras 		 * For the debug message, we look at the preceding
28614cf11afSPaul Mackerras 		 * load or store.
28714cf11afSPaul Mackerras 		 */
28814cf11afSPaul Mackerras 		if (*nip == 0x60000000)		/* nop */
28914cf11afSPaul Mackerras 			nip -= 2;
29014cf11afSPaul Mackerras 		else if (*nip == 0x4c00012c)	/* isync */
29114cf11afSPaul Mackerras 			--nip;
29214cf11afSPaul Mackerras 		if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
29314cf11afSPaul Mackerras 			/* sync or twi */
29414cf11afSPaul Mackerras 			unsigned int rb;
29514cf11afSPaul Mackerras 
29614cf11afSPaul Mackerras 			--nip;
29714cf11afSPaul Mackerras 			rb = (*nip >> 11) & 0x1f;
29814cf11afSPaul Mackerras 			printk(KERN_DEBUG "%s bad port %lx at %p\n",
29914cf11afSPaul Mackerras 			       (*nip & 0x100)? "OUT to": "IN from",
30014cf11afSPaul Mackerras 			       regs->gpr[rb] - _IO_BASE, nip);
30114cf11afSPaul Mackerras 			regs->msr |= MSR_RI;
30214cf11afSPaul Mackerras 			regs->nip = entry->fixup;
30314cf11afSPaul Mackerras 			return 1;
30414cf11afSPaul Mackerras 		}
30514cf11afSPaul Mackerras 	}
30668a64357SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */
30714cf11afSPaul Mackerras 	return 0;
30814cf11afSPaul Mackerras }
30914cf11afSPaul Mackerras 
31014cf11afSPaul Mackerras #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
31114cf11afSPaul Mackerras /* On 4xx, the reason for the machine check or program exception
31214cf11afSPaul Mackerras    is in the ESR. */
31314cf11afSPaul Mackerras #define get_reason(regs)	((regs)->dsisr)
31414cf11afSPaul Mackerras #ifndef CONFIG_FSL_BOOKE
31514cf11afSPaul Mackerras #define get_mc_reason(regs)	((regs)->dsisr)
31614cf11afSPaul Mackerras #else
31786d7a9a9SBecky Bruce #define get_mc_reason(regs)	(mfspr(SPRN_MCSR) & MCSR_MASK)
31814cf11afSPaul Mackerras #endif
31914cf11afSPaul Mackerras #define REASON_FP		ESR_FP
32014cf11afSPaul Mackerras #define REASON_ILLEGAL		(ESR_PIL | ESR_PUO)
32114cf11afSPaul Mackerras #define REASON_PRIVILEGED	ESR_PPR
32214cf11afSPaul Mackerras #define REASON_TRAP		ESR_PTR
32314cf11afSPaul Mackerras 
32414cf11afSPaul Mackerras /* single-step stuff */
32514cf11afSPaul Mackerras #define single_stepping(regs)	(current->thread.dbcr0 & DBCR0_IC)
32614cf11afSPaul Mackerras #define clear_single_step(regs)	(current->thread.dbcr0 &= ~DBCR0_IC)
32714cf11afSPaul Mackerras 
32814cf11afSPaul Mackerras #else
32914cf11afSPaul Mackerras /* On non-4xx, the reason for the machine check or program
33014cf11afSPaul Mackerras    exception is in the MSR. */
33114cf11afSPaul Mackerras #define get_reason(regs)	((regs)->msr)
33214cf11afSPaul Mackerras #define get_mc_reason(regs)	((regs)->msr)
33314cf11afSPaul Mackerras #define REASON_FP		0x100000
33414cf11afSPaul Mackerras #define REASON_ILLEGAL		0x80000
33514cf11afSPaul Mackerras #define REASON_PRIVILEGED	0x40000
33614cf11afSPaul Mackerras #define REASON_TRAP		0x20000
33714cf11afSPaul Mackerras 
33814cf11afSPaul Mackerras #define single_stepping(regs)	((regs)->msr & MSR_SE)
33914cf11afSPaul Mackerras #define clear_single_step(regs)	((regs)->msr &= ~MSR_SE)
34014cf11afSPaul Mackerras #endif
34114cf11afSPaul Mackerras 
34247c0bd1aSBenjamin Herrenschmidt #if defined(CONFIG_4xx)
34347c0bd1aSBenjamin Herrenschmidt int machine_check_4xx(struct pt_regs *regs)
34414cf11afSPaul Mackerras {
3451a6a4ffeSKumar Gala 	unsigned long reason = get_mc_reason(regs);
34614cf11afSPaul Mackerras 
34714cf11afSPaul Mackerras 	if (reason & ESR_IMCP) {
34814cf11afSPaul Mackerras 		printk("Instruction");
34914cf11afSPaul Mackerras 		mtspr(SPRN_ESR, reason & ~ESR_IMCP);
35014cf11afSPaul Mackerras 	} else
35114cf11afSPaul Mackerras 		printk("Data");
35214cf11afSPaul Mackerras 	printk(" machine check in kernel mode.\n");
35347c0bd1aSBenjamin Herrenschmidt 
35447c0bd1aSBenjamin Herrenschmidt 	return 0;
35547c0bd1aSBenjamin Herrenschmidt }
35647c0bd1aSBenjamin Herrenschmidt 
35747c0bd1aSBenjamin Herrenschmidt int machine_check_440A(struct pt_regs *regs)
35847c0bd1aSBenjamin Herrenschmidt {
35947c0bd1aSBenjamin Herrenschmidt 	unsigned long reason = get_mc_reason(regs);
36047c0bd1aSBenjamin Herrenschmidt 
36114cf11afSPaul Mackerras 	printk("Machine check in kernel mode.\n");
36214cf11afSPaul Mackerras 	if (reason & ESR_IMCP){
36314cf11afSPaul Mackerras 		printk("Instruction Synchronous Machine Check exception\n");
36414cf11afSPaul Mackerras 		mtspr(SPRN_ESR, reason & ~ESR_IMCP);
36514cf11afSPaul Mackerras 	}
36614cf11afSPaul Mackerras 	else {
36714cf11afSPaul Mackerras 		u32 mcsr = mfspr(SPRN_MCSR);
36814cf11afSPaul Mackerras 		if (mcsr & MCSR_IB)
36914cf11afSPaul Mackerras 			printk("Instruction Read PLB Error\n");
37014cf11afSPaul Mackerras 		if (mcsr & MCSR_DRB)
37114cf11afSPaul Mackerras 			printk("Data Read PLB Error\n");
37214cf11afSPaul Mackerras 		if (mcsr & MCSR_DWB)
37314cf11afSPaul Mackerras 			printk("Data Write PLB Error\n");
37414cf11afSPaul Mackerras 		if (mcsr & MCSR_TLBP)
37514cf11afSPaul Mackerras 			printk("TLB Parity Error\n");
37614cf11afSPaul Mackerras 		if (mcsr & MCSR_ICP){
37714cf11afSPaul Mackerras 			flush_instruction_cache();
37814cf11afSPaul Mackerras 			printk("I-Cache Parity Error\n");
37914cf11afSPaul Mackerras 		}
38014cf11afSPaul Mackerras 		if (mcsr & MCSR_DCSP)
38114cf11afSPaul Mackerras 			printk("D-Cache Search Parity Error\n");
38214cf11afSPaul Mackerras 		if (mcsr & MCSR_DCFP)
38314cf11afSPaul Mackerras 			printk("D-Cache Flush Parity Error\n");
38414cf11afSPaul Mackerras 		if (mcsr & MCSR_IMPE)
38514cf11afSPaul Mackerras 			printk("Machine Check exception is imprecise\n");
38614cf11afSPaul Mackerras 
38714cf11afSPaul Mackerras 		/* Clear MCSR */
38814cf11afSPaul Mackerras 		mtspr(SPRN_MCSR, mcsr);
38914cf11afSPaul Mackerras 	}
39047c0bd1aSBenjamin Herrenschmidt 	return 0;
39147c0bd1aSBenjamin Herrenschmidt }
39214cf11afSPaul Mackerras #elif defined(CONFIG_E500)
39347c0bd1aSBenjamin Herrenschmidt int machine_check_e500(struct pt_regs *regs)
39447c0bd1aSBenjamin Herrenschmidt {
39547c0bd1aSBenjamin Herrenschmidt 	unsigned long reason = get_mc_reason(regs);
39647c0bd1aSBenjamin Herrenschmidt 
39714cf11afSPaul Mackerras 	printk("Machine check in kernel mode.\n");
39814cf11afSPaul Mackerras 	printk("Caused by (from MCSR=%lx): ", reason);
39914cf11afSPaul Mackerras 
40014cf11afSPaul Mackerras 	if (reason & MCSR_MCP)
40114cf11afSPaul Mackerras 		printk("Machine Check Signal\n");
40214cf11afSPaul Mackerras 	if (reason & MCSR_ICPERR)
40314cf11afSPaul Mackerras 		printk("Instruction Cache Parity Error\n");
40414cf11afSPaul Mackerras 	if (reason & MCSR_DCP_PERR)
40514cf11afSPaul Mackerras 		printk("Data Cache Push Parity Error\n");
40614cf11afSPaul Mackerras 	if (reason & MCSR_DCPERR)
40714cf11afSPaul Mackerras 		printk("Data Cache Parity Error\n");
40814cf11afSPaul Mackerras 	if (reason & MCSR_BUS_IAERR)
40914cf11afSPaul Mackerras 		printk("Bus - Instruction Address Error\n");
41014cf11afSPaul Mackerras 	if (reason & MCSR_BUS_RAERR)
41114cf11afSPaul Mackerras 		printk("Bus - Read Address Error\n");
41214cf11afSPaul Mackerras 	if (reason & MCSR_BUS_WAERR)
41314cf11afSPaul Mackerras 		printk("Bus - Write Address Error\n");
41414cf11afSPaul Mackerras 	if (reason & MCSR_BUS_IBERR)
41514cf11afSPaul Mackerras 		printk("Bus - Instruction Data Error\n");
41614cf11afSPaul Mackerras 	if (reason & MCSR_BUS_RBERR)
41714cf11afSPaul Mackerras 		printk("Bus - Read Data Bus Error\n");
41814cf11afSPaul Mackerras 	if (reason & MCSR_BUS_WBERR)
41914cf11afSPaul Mackerras 		printk("Bus - Read Data Bus Error\n");
42014cf11afSPaul Mackerras 	if (reason & MCSR_BUS_IPERR)
42114cf11afSPaul Mackerras 		printk("Bus - Instruction Parity Error\n");
42214cf11afSPaul Mackerras 	if (reason & MCSR_BUS_RPERR)
42314cf11afSPaul Mackerras 		printk("Bus - Read Parity Error\n");
42447c0bd1aSBenjamin Herrenschmidt 
42547c0bd1aSBenjamin Herrenschmidt 	return 0;
42647c0bd1aSBenjamin Herrenschmidt }
42714cf11afSPaul Mackerras #elif defined(CONFIG_E200)
42847c0bd1aSBenjamin Herrenschmidt int machine_check_e200(struct pt_regs *regs)
42947c0bd1aSBenjamin Herrenschmidt {
43047c0bd1aSBenjamin Herrenschmidt 	unsigned long reason = get_mc_reason(regs);
43147c0bd1aSBenjamin Herrenschmidt 
43214cf11afSPaul Mackerras 	printk("Machine check in kernel mode.\n");
43314cf11afSPaul Mackerras 	printk("Caused by (from MCSR=%lx): ", reason);
43414cf11afSPaul Mackerras 
43514cf11afSPaul Mackerras 	if (reason & MCSR_MCP)
43614cf11afSPaul Mackerras 		printk("Machine Check Signal\n");
43714cf11afSPaul Mackerras 	if (reason & MCSR_CP_PERR)
43814cf11afSPaul Mackerras 		printk("Cache Push Parity Error\n");
43914cf11afSPaul Mackerras 	if (reason & MCSR_CPERR)
44014cf11afSPaul Mackerras 		printk("Cache Parity Error\n");
44114cf11afSPaul Mackerras 	if (reason & MCSR_EXCP_ERR)
44214cf11afSPaul Mackerras 		printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
44314cf11afSPaul Mackerras 	if (reason & MCSR_BUS_IRERR)
44414cf11afSPaul Mackerras 		printk("Bus - Read Bus Error on instruction fetch\n");
44514cf11afSPaul Mackerras 	if (reason & MCSR_BUS_DRERR)
44614cf11afSPaul Mackerras 		printk("Bus - Read Bus Error on data load\n");
44714cf11afSPaul Mackerras 	if (reason & MCSR_BUS_WRERR)
44814cf11afSPaul Mackerras 		printk("Bus - Write Bus Error on buffered store or cache line push\n");
44947c0bd1aSBenjamin Herrenschmidt 
45047c0bd1aSBenjamin Herrenschmidt 	return 0;
45147c0bd1aSBenjamin Herrenschmidt }
45247c0bd1aSBenjamin Herrenschmidt #else
45347c0bd1aSBenjamin Herrenschmidt int machine_check_generic(struct pt_regs *regs)
45447c0bd1aSBenjamin Herrenschmidt {
45547c0bd1aSBenjamin Herrenschmidt 	unsigned long reason = get_mc_reason(regs);
45647c0bd1aSBenjamin Herrenschmidt 
45714cf11afSPaul Mackerras 	printk("Machine check in kernel mode.\n");
45814cf11afSPaul Mackerras 	printk("Caused by (from SRR1=%lx): ", reason);
45914cf11afSPaul Mackerras 	switch (reason & 0x601F0000) {
46014cf11afSPaul Mackerras 	case 0x80000:
46114cf11afSPaul Mackerras 		printk("Machine check signal\n");
46214cf11afSPaul Mackerras 		break;
46314cf11afSPaul Mackerras 	case 0:		/* for 601 */
46414cf11afSPaul Mackerras 	case 0x40000:
46514cf11afSPaul Mackerras 	case 0x140000:	/* 7450 MSS error and TEA */
46614cf11afSPaul Mackerras 		printk("Transfer error ack signal\n");
46714cf11afSPaul Mackerras 		break;
46814cf11afSPaul Mackerras 	case 0x20000:
46914cf11afSPaul Mackerras 		printk("Data parity error signal\n");
47014cf11afSPaul Mackerras 		break;
47114cf11afSPaul Mackerras 	case 0x10000:
47214cf11afSPaul Mackerras 		printk("Address parity error signal\n");
47314cf11afSPaul Mackerras 		break;
47414cf11afSPaul Mackerras 	case 0x20000000:
47514cf11afSPaul Mackerras 		printk("L1 Data Cache error\n");
47614cf11afSPaul Mackerras 		break;
47714cf11afSPaul Mackerras 	case 0x40000000:
47814cf11afSPaul Mackerras 		printk("L1 Instruction Cache error\n");
47914cf11afSPaul Mackerras 		break;
48014cf11afSPaul Mackerras 	case 0x00100000:
48114cf11afSPaul Mackerras 		printk("L2 data cache parity error\n");
48214cf11afSPaul Mackerras 		break;
48314cf11afSPaul Mackerras 	default:
48414cf11afSPaul Mackerras 		printk("Unknown values in msr\n");
48514cf11afSPaul Mackerras 	}
48675918a4bSOlof Johansson 	return 0;
48775918a4bSOlof Johansson }
48847c0bd1aSBenjamin Herrenschmidt #endif /* everything else */
48975918a4bSOlof Johansson 
49075918a4bSOlof Johansson void machine_check_exception(struct pt_regs *regs)
49175918a4bSOlof Johansson {
49275918a4bSOlof Johansson 	int recover = 0;
49375918a4bSOlof Johansson 
49447c0bd1aSBenjamin Herrenschmidt 	/* See if any machine dependent calls. In theory, we would want
49547c0bd1aSBenjamin Herrenschmidt 	 * to call the CPU first, and call the ppc_md. one if the CPU
49647c0bd1aSBenjamin Herrenschmidt 	 * one returns a positive number. However there is existing code
49747c0bd1aSBenjamin Herrenschmidt 	 * that assumes the board gets a first chance, so let's keep it
49847c0bd1aSBenjamin Herrenschmidt 	 * that way for now and fix things later. --BenH.
49947c0bd1aSBenjamin Herrenschmidt 	 */
50075918a4bSOlof Johansson 	if (ppc_md.machine_check_exception)
50175918a4bSOlof Johansson 		recover = ppc_md.machine_check_exception(regs);
50247c0bd1aSBenjamin Herrenschmidt 	else if (cur_cpu_spec->machine_check)
50347c0bd1aSBenjamin Herrenschmidt 		recover = cur_cpu_spec->machine_check(regs);
50475918a4bSOlof Johansson 
50547c0bd1aSBenjamin Herrenschmidt 	if (recover > 0)
50675918a4bSOlof Johansson 		return;
50775918a4bSOlof Johansson 
50875918a4bSOlof Johansson 	if (user_mode(regs)) {
50975918a4bSOlof Johansson 		regs->msr |= MSR_RI;
51075918a4bSOlof Johansson 		_exception(SIGBUS, regs, BUS_ADRERR, regs->nip);
51175918a4bSOlof Johansson 		return;
51275918a4bSOlof Johansson 	}
51375918a4bSOlof Johansson 
51475918a4bSOlof Johansson #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
51547c0bd1aSBenjamin Herrenschmidt 	/* the qspan pci read routines can cause machine checks -- Cort
51647c0bd1aSBenjamin Herrenschmidt 	 *
51747c0bd1aSBenjamin Herrenschmidt 	 * yuck !!! that totally needs to go away ! There are better ways
51847c0bd1aSBenjamin Herrenschmidt 	 * to deal with that than having a wart in the mcheck handler.
51947c0bd1aSBenjamin Herrenschmidt 	 * -- BenH
52047c0bd1aSBenjamin Herrenschmidt 	 */
52175918a4bSOlof Johansson 	bad_page_fault(regs, regs->dar, SIGBUS);
52275918a4bSOlof Johansson 	return;
52375918a4bSOlof Johansson #endif
52475918a4bSOlof Johansson 
52575918a4bSOlof Johansson 	if (debugger_fault_handler(regs)) {
52675918a4bSOlof Johansson 		regs->msr |= MSR_RI;
52775918a4bSOlof Johansson 		return;
52875918a4bSOlof Johansson 	}
52975918a4bSOlof Johansson 
53075918a4bSOlof Johansson 	if (check_io_access(regs))
53175918a4bSOlof Johansson 		return;
53275918a4bSOlof Johansson 
53314cf11afSPaul Mackerras 	if (debugger_fault_handler(regs))
53414cf11afSPaul Mackerras 		return;
5358dad3f92SPaul Mackerras 	die("Machine check", regs, SIGBUS);
53614cf11afSPaul Mackerras 
53714cf11afSPaul Mackerras 	/* Must die if the interrupt is not recoverable */
53814cf11afSPaul Mackerras 	if (!(regs->msr & MSR_RI))
53914cf11afSPaul Mackerras 		panic("Unrecoverable Machine check");
54014cf11afSPaul Mackerras }
54114cf11afSPaul Mackerras 
54214cf11afSPaul Mackerras void SMIException(struct pt_regs *regs)
54314cf11afSPaul Mackerras {
54414cf11afSPaul Mackerras 	die("System Management Interrupt", regs, SIGABRT);
54514cf11afSPaul Mackerras }
54614cf11afSPaul Mackerras 
547dc1c1ca3SStephen Rothwell void unknown_exception(struct pt_regs *regs)
54814cf11afSPaul Mackerras {
54914cf11afSPaul Mackerras 	printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
55014cf11afSPaul Mackerras 	       regs->nip, regs->msr, regs->trap);
55114cf11afSPaul Mackerras 
55214cf11afSPaul Mackerras 	_exception(SIGTRAP, regs, 0, 0);
55314cf11afSPaul Mackerras }
55414cf11afSPaul Mackerras 
555dc1c1ca3SStephen Rothwell void instruction_breakpoint_exception(struct pt_regs *regs)
55614cf11afSPaul Mackerras {
55714cf11afSPaul Mackerras 	if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5,
55814cf11afSPaul Mackerras 					5, SIGTRAP) == NOTIFY_STOP)
55914cf11afSPaul Mackerras 		return;
56014cf11afSPaul Mackerras 	if (debugger_iabr_match(regs))
56114cf11afSPaul Mackerras 		return;
56214cf11afSPaul Mackerras 	_exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
56314cf11afSPaul Mackerras }
56414cf11afSPaul Mackerras 
56514cf11afSPaul Mackerras void RunModeException(struct pt_regs *regs)
56614cf11afSPaul Mackerras {
56714cf11afSPaul Mackerras 	_exception(SIGTRAP, regs, 0, 0);
56814cf11afSPaul Mackerras }
56914cf11afSPaul Mackerras 
5708dad3f92SPaul Mackerras void __kprobes single_step_exception(struct pt_regs *regs)
57114cf11afSPaul Mackerras {
57214cf11afSPaul Mackerras 	regs->msr &= ~(MSR_SE | MSR_BE);  /* Turn off 'trace' bits */
57314cf11afSPaul Mackerras 
57414cf11afSPaul Mackerras 	if (notify_die(DIE_SSTEP, "single_step", regs, 5,
57514cf11afSPaul Mackerras 					5, SIGTRAP) == NOTIFY_STOP)
57614cf11afSPaul Mackerras 		return;
57714cf11afSPaul Mackerras 	if (debugger_sstep(regs))
57814cf11afSPaul Mackerras 		return;
57914cf11afSPaul Mackerras 
58014cf11afSPaul Mackerras 	_exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
58114cf11afSPaul Mackerras }
58214cf11afSPaul Mackerras 
58314cf11afSPaul Mackerras /*
58414cf11afSPaul Mackerras  * After we have successfully emulated an instruction, we have to
58514cf11afSPaul Mackerras  * check if the instruction was being single-stepped, and if so,
58614cf11afSPaul Mackerras  * pretend we got a single-step exception.  This was pointed out
58714cf11afSPaul Mackerras  * by Kumar Gala.  -- paulus
58814cf11afSPaul Mackerras  */
5898dad3f92SPaul Mackerras static void emulate_single_step(struct pt_regs *regs)
59014cf11afSPaul Mackerras {
59114cf11afSPaul Mackerras 	if (single_stepping(regs)) {
59214cf11afSPaul Mackerras 		clear_single_step(regs);
59314cf11afSPaul Mackerras 		_exception(SIGTRAP, regs, TRAP_TRACE, 0);
59414cf11afSPaul Mackerras 	}
59514cf11afSPaul Mackerras }
59614cf11afSPaul Mackerras 
5975fad293bSKumar Gala static inline int __parse_fpscr(unsigned long fpscr)
598dc1c1ca3SStephen Rothwell {
5995fad293bSKumar Gala 	int ret = 0;
600dc1c1ca3SStephen Rothwell 
601dc1c1ca3SStephen Rothwell 	/* Invalid operation */
602dc1c1ca3SStephen Rothwell 	if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
6035fad293bSKumar Gala 		ret = FPE_FLTINV;
604dc1c1ca3SStephen Rothwell 
605dc1c1ca3SStephen Rothwell 	/* Overflow */
606dc1c1ca3SStephen Rothwell 	else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX))
6075fad293bSKumar Gala 		ret = FPE_FLTOVF;
608dc1c1ca3SStephen Rothwell 
609dc1c1ca3SStephen Rothwell 	/* Underflow */
610dc1c1ca3SStephen Rothwell 	else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX))
6115fad293bSKumar Gala 		ret = FPE_FLTUND;
612dc1c1ca3SStephen Rothwell 
613dc1c1ca3SStephen Rothwell 	/* Divide by zero */
614dc1c1ca3SStephen Rothwell 	else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX))
6155fad293bSKumar Gala 		ret = FPE_FLTDIV;
616dc1c1ca3SStephen Rothwell 
617dc1c1ca3SStephen Rothwell 	/* Inexact result */
618dc1c1ca3SStephen Rothwell 	else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX))
6195fad293bSKumar Gala 		ret = FPE_FLTRES;
6205fad293bSKumar Gala 
6215fad293bSKumar Gala 	return ret;
6225fad293bSKumar Gala }
6235fad293bSKumar Gala 
6245fad293bSKumar Gala static void parse_fpe(struct pt_regs *regs)
6255fad293bSKumar Gala {
6265fad293bSKumar Gala 	int code = 0;
6275fad293bSKumar Gala 
6285fad293bSKumar Gala 	flush_fp_to_thread(current);
6295fad293bSKumar Gala 
6305fad293bSKumar Gala 	code = __parse_fpscr(current->thread.fpscr.val);
631dc1c1ca3SStephen Rothwell 
632dc1c1ca3SStephen Rothwell 	_exception(SIGFPE, regs, code, regs->nip);
633dc1c1ca3SStephen Rothwell }
634dc1c1ca3SStephen Rothwell 
635dc1c1ca3SStephen Rothwell /*
636dc1c1ca3SStephen Rothwell  * Illegal instruction emulation support.  Originally written to
63714cf11afSPaul Mackerras  * provide the PVR to user applications using the mfspr rd, PVR.
63814cf11afSPaul Mackerras  * Return non-zero if we can't emulate, or -EFAULT if the associated
63914cf11afSPaul Mackerras  * memory access caused an access fault.  Return zero on success.
64014cf11afSPaul Mackerras  *
64114cf11afSPaul Mackerras  * There are a couple of ways to do this, either "decode" the instruction
64214cf11afSPaul Mackerras  * or directly match lots of bits.  In this case, matching lots of
64314cf11afSPaul Mackerras  * bits is faster and easier.
64486417780SPaul Mackerras  *
64514cf11afSPaul Mackerras  */
64614cf11afSPaul Mackerras static int emulate_string_inst(struct pt_regs *regs, u32 instword)
64714cf11afSPaul Mackerras {
64814cf11afSPaul Mackerras 	u8 rT = (instword >> 21) & 0x1f;
64914cf11afSPaul Mackerras 	u8 rA = (instword >> 16) & 0x1f;
65014cf11afSPaul Mackerras 	u8 NB_RB = (instword >> 11) & 0x1f;
65114cf11afSPaul Mackerras 	u32 num_bytes;
65214cf11afSPaul Mackerras 	unsigned long EA;
65314cf11afSPaul Mackerras 	int pos = 0;
65414cf11afSPaul Mackerras 
65514cf11afSPaul Mackerras 	/* Early out if we are an invalid form of lswx */
65616c57b36SKumar Gala 	if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX)
65714cf11afSPaul Mackerras 		if ((rT == rA) || (rT == NB_RB))
65814cf11afSPaul Mackerras 			return -EINVAL;
65914cf11afSPaul Mackerras 
66014cf11afSPaul Mackerras 	EA = (rA == 0) ? 0 : regs->gpr[rA];
66114cf11afSPaul Mackerras 
66216c57b36SKumar Gala 	switch (instword & PPC_INST_STRING_MASK) {
66316c57b36SKumar Gala 		case PPC_INST_LSWX:
66416c57b36SKumar Gala 		case PPC_INST_STSWX:
66514cf11afSPaul Mackerras 			EA += NB_RB;
66614cf11afSPaul Mackerras 			num_bytes = regs->xer & 0x7f;
66714cf11afSPaul Mackerras 			break;
66816c57b36SKumar Gala 		case PPC_INST_LSWI:
66916c57b36SKumar Gala 		case PPC_INST_STSWI:
67014cf11afSPaul Mackerras 			num_bytes = (NB_RB == 0) ? 32 : NB_RB;
67114cf11afSPaul Mackerras 			break;
67214cf11afSPaul Mackerras 		default:
67314cf11afSPaul Mackerras 			return -EINVAL;
67414cf11afSPaul Mackerras 	}
67514cf11afSPaul Mackerras 
67614cf11afSPaul Mackerras 	while (num_bytes != 0)
67714cf11afSPaul Mackerras 	{
67814cf11afSPaul Mackerras 		u8 val;
67914cf11afSPaul Mackerras 		u32 shift = 8 * (3 - (pos & 0x3));
68014cf11afSPaul Mackerras 
68116c57b36SKumar Gala 		switch ((instword & PPC_INST_STRING_MASK)) {
68216c57b36SKumar Gala 			case PPC_INST_LSWX:
68316c57b36SKumar Gala 			case PPC_INST_LSWI:
68414cf11afSPaul Mackerras 				if (get_user(val, (u8 __user *)EA))
68514cf11afSPaul Mackerras 					return -EFAULT;
68614cf11afSPaul Mackerras 				/* first time updating this reg,
68714cf11afSPaul Mackerras 				 * zero it out */
68814cf11afSPaul Mackerras 				if (pos == 0)
68914cf11afSPaul Mackerras 					regs->gpr[rT] = 0;
69014cf11afSPaul Mackerras 				regs->gpr[rT] |= val << shift;
69114cf11afSPaul Mackerras 				break;
69216c57b36SKumar Gala 			case PPC_INST_STSWI:
69316c57b36SKumar Gala 			case PPC_INST_STSWX:
69414cf11afSPaul Mackerras 				val = regs->gpr[rT] >> shift;
69514cf11afSPaul Mackerras 				if (put_user(val, (u8 __user *)EA))
69614cf11afSPaul Mackerras 					return -EFAULT;
69714cf11afSPaul Mackerras 				break;
69814cf11afSPaul Mackerras 		}
69914cf11afSPaul Mackerras 		/* move EA to next address */
70014cf11afSPaul Mackerras 		EA += 1;
70114cf11afSPaul Mackerras 		num_bytes--;
70214cf11afSPaul Mackerras 
70314cf11afSPaul Mackerras 		/* manage our position within the register */
70414cf11afSPaul Mackerras 		if (++pos == 4) {
70514cf11afSPaul Mackerras 			pos = 0;
70614cf11afSPaul Mackerras 			if (++rT == 32)
70714cf11afSPaul Mackerras 				rT = 0;
70814cf11afSPaul Mackerras 		}
70914cf11afSPaul Mackerras 	}
71014cf11afSPaul Mackerras 
71114cf11afSPaul Mackerras 	return 0;
71214cf11afSPaul Mackerras }
71314cf11afSPaul Mackerras 
714c3412dcbSWill Schmidt static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
715c3412dcbSWill Schmidt {
716c3412dcbSWill Schmidt 	u32 ra,rs;
717c3412dcbSWill Schmidt 	unsigned long tmp;
718c3412dcbSWill Schmidt 
719c3412dcbSWill Schmidt 	ra = (instword >> 16) & 0x1f;
720c3412dcbSWill Schmidt 	rs = (instword >> 21) & 0x1f;
721c3412dcbSWill Schmidt 
722c3412dcbSWill Schmidt 	tmp = regs->gpr[rs];
723c3412dcbSWill Schmidt 	tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL);
724c3412dcbSWill Schmidt 	tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL);
725c3412dcbSWill Schmidt 	tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
726c3412dcbSWill Schmidt 	regs->gpr[ra] = tmp;
727c3412dcbSWill Schmidt 
728c3412dcbSWill Schmidt 	return 0;
729c3412dcbSWill Schmidt }
730c3412dcbSWill Schmidt 
731c1469f13SKumar Gala static int emulate_isel(struct pt_regs *regs, u32 instword)
732c1469f13SKumar Gala {
733c1469f13SKumar Gala 	u8 rT = (instword >> 21) & 0x1f;
734c1469f13SKumar Gala 	u8 rA = (instword >> 16) & 0x1f;
735c1469f13SKumar Gala 	u8 rB = (instword >> 11) & 0x1f;
736c1469f13SKumar Gala 	u8 BC = (instword >> 6) & 0x1f;
737c1469f13SKumar Gala 	u8 bit;
738c1469f13SKumar Gala 	unsigned long tmp;
739c1469f13SKumar Gala 
740c1469f13SKumar Gala 	tmp = (rA == 0) ? 0 : regs->gpr[rA];
741c1469f13SKumar Gala 	bit = (regs->ccr >> (31 - BC)) & 0x1;
742c1469f13SKumar Gala 
743c1469f13SKumar Gala 	regs->gpr[rT] = bit ? tmp : regs->gpr[rB];
744c1469f13SKumar Gala 
745c1469f13SKumar Gala 	return 0;
746c1469f13SKumar Gala }
747c1469f13SKumar Gala 
74814cf11afSPaul Mackerras static int emulate_instruction(struct pt_regs *regs)
74914cf11afSPaul Mackerras {
75014cf11afSPaul Mackerras 	u32 instword;
75114cf11afSPaul Mackerras 	u32 rd;
75214cf11afSPaul Mackerras 
753fab5db97SPaul Mackerras 	if (!user_mode(regs) || (regs->msr & MSR_LE))
75414cf11afSPaul Mackerras 		return -EINVAL;
75514cf11afSPaul Mackerras 	CHECK_FULL_REGS(regs);
75614cf11afSPaul Mackerras 
75714cf11afSPaul Mackerras 	if (get_user(instword, (u32 __user *)(regs->nip)))
75814cf11afSPaul Mackerras 		return -EFAULT;
75914cf11afSPaul Mackerras 
76014cf11afSPaul Mackerras 	/* Emulate the mfspr rD, PVR. */
76116c57b36SKumar Gala 	if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) {
762*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(mfpvr);
76314cf11afSPaul Mackerras 		rd = (instword >> 21) & 0x1f;
76414cf11afSPaul Mackerras 		regs->gpr[rd] = mfspr(SPRN_PVR);
76514cf11afSPaul Mackerras 		return 0;
76614cf11afSPaul Mackerras 	}
76714cf11afSPaul Mackerras 
76814cf11afSPaul Mackerras 	/* Emulating the dcba insn is just a no-op.  */
769*80947e7cSGeert Uytterhoeven 	if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) {
770*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(dcba);
77114cf11afSPaul Mackerras 		return 0;
772*80947e7cSGeert Uytterhoeven 	}
77314cf11afSPaul Mackerras 
77414cf11afSPaul Mackerras 	/* Emulate the mcrxr insn.  */
77516c57b36SKumar Gala 	if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) {
77686417780SPaul Mackerras 		int shift = (instword >> 21) & 0x1c;
77714cf11afSPaul Mackerras 		unsigned long msk = 0xf0000000UL >> shift;
77814cf11afSPaul Mackerras 
779*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(mcrxr);
78014cf11afSPaul Mackerras 		regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
78114cf11afSPaul Mackerras 		regs->xer &= ~0xf0000000UL;
78214cf11afSPaul Mackerras 		return 0;
78314cf11afSPaul Mackerras 	}
78414cf11afSPaul Mackerras 
78514cf11afSPaul Mackerras 	/* Emulate load/store string insn. */
786*80947e7cSGeert Uytterhoeven 	if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) {
787*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(string);
78814cf11afSPaul Mackerras 		return emulate_string_inst(regs, instword);
789*80947e7cSGeert Uytterhoeven 	}
79014cf11afSPaul Mackerras 
791c3412dcbSWill Schmidt 	/* Emulate the popcntb (Population Count Bytes) instruction. */
79216c57b36SKumar Gala 	if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) {
793*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(popcntb);
794c3412dcbSWill Schmidt 		return emulate_popcntb_inst(regs, instword);
795c3412dcbSWill Schmidt 	}
796c3412dcbSWill Schmidt 
797c1469f13SKumar Gala 	/* Emulate isel (Integer Select) instruction */
79816c57b36SKumar Gala 	if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) {
799*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(isel);
800c1469f13SKumar Gala 		return emulate_isel(regs, instword);
801c1469f13SKumar Gala 	}
802c1469f13SKumar Gala 
80314cf11afSPaul Mackerras 	return -EINVAL;
80414cf11afSPaul Mackerras }
80514cf11afSPaul Mackerras 
80673c9ceabSJeremy Fitzhardinge int is_valid_bugaddr(unsigned long addr)
80714cf11afSPaul Mackerras {
80873c9ceabSJeremy Fitzhardinge 	return is_kernel_addr(addr);
80914cf11afSPaul Mackerras }
81014cf11afSPaul Mackerras 
8118dad3f92SPaul Mackerras void __kprobes program_check_exception(struct pt_regs *regs)
81214cf11afSPaul Mackerras {
81314cf11afSPaul Mackerras 	unsigned int reason = get_reason(regs);
81414cf11afSPaul Mackerras 	extern int do_mathemu(struct pt_regs *regs);
81514cf11afSPaul Mackerras 
816aa42c69cSKim Phillips 	/* We can now get here via a FP Unavailable exception if the core
81704903a30SKumar Gala 	 * has no FPU, in that case the reason flags will be 0 */
81814cf11afSPaul Mackerras 
81914cf11afSPaul Mackerras 	if (reason & REASON_FP) {
82014cf11afSPaul Mackerras 		/* IEEE FP exception */
821dc1c1ca3SStephen Rothwell 		parse_fpe(regs);
8228dad3f92SPaul Mackerras 		return;
8238dad3f92SPaul Mackerras 	}
8248dad3f92SPaul Mackerras 	if (reason & REASON_TRAP) {
82514cf11afSPaul Mackerras 		/* trap exception */
826dc1c1ca3SStephen Rothwell 		if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
827dc1c1ca3SStephen Rothwell 				== NOTIFY_STOP)
828dc1c1ca3SStephen Rothwell 			return;
82914cf11afSPaul Mackerras 		if (debugger_bpt(regs))
83014cf11afSPaul Mackerras 			return;
83173c9ceabSJeremy Fitzhardinge 
83273c9ceabSJeremy Fitzhardinge 		if (!(regs->msr & MSR_PR) &&  /* not user-mode */
833608e2619SHeiko Carstens 		    report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
83414cf11afSPaul Mackerras 			regs->nip += 4;
83514cf11afSPaul Mackerras 			return;
83614cf11afSPaul Mackerras 		}
8378dad3f92SPaul Mackerras 		_exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
8388dad3f92SPaul Mackerras 		return;
8398dad3f92SPaul Mackerras 	}
8408dad3f92SPaul Mackerras 
841cd8a5673SPaul Mackerras 	local_irq_enable();
842cd8a5673SPaul Mackerras 
84304903a30SKumar Gala #ifdef CONFIG_MATH_EMULATION
84404903a30SKumar Gala 	/* (reason & REASON_ILLEGAL) would be the obvious thing here,
84504903a30SKumar Gala 	 * but there seems to be a hardware bug on the 405GP (RevD)
84604903a30SKumar Gala 	 * that means ESR is sometimes set incorrectly - either to
84704903a30SKumar Gala 	 * ESR_DST (!?) or 0.  In the process of chasing this with the
84804903a30SKumar Gala 	 * hardware people - not sure if it can happen on any illegal
84904903a30SKumar Gala 	 * instruction or only on FP instructions, whether there is a
85004903a30SKumar Gala 	 * pattern to occurences etc. -dgibson 31/Mar/2003 */
8515fad293bSKumar Gala 	switch (do_mathemu(regs)) {
8525fad293bSKumar Gala 	case 0:
85304903a30SKumar Gala 		emulate_single_step(regs);
85404903a30SKumar Gala 		return;
8555fad293bSKumar Gala 	case 1: {
8565fad293bSKumar Gala 			int code = 0;
8575fad293bSKumar Gala 			code = __parse_fpscr(current->thread.fpscr.val);
8585fad293bSKumar Gala 			_exception(SIGFPE, regs, code, regs->nip);
8595fad293bSKumar Gala 			return;
86004903a30SKumar Gala 		}
8615fad293bSKumar Gala 	case -EFAULT:
8625fad293bSKumar Gala 		_exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
8635fad293bSKumar Gala 		return;
8645fad293bSKumar Gala 	}
8655fad293bSKumar Gala 	/* fall through on any other errors */
86604903a30SKumar Gala #endif /* CONFIG_MATH_EMULATION */
86704903a30SKumar Gala 
8688dad3f92SPaul Mackerras 	/* Try to emulate it if we should. */
8698dad3f92SPaul Mackerras 	if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
87014cf11afSPaul Mackerras 		switch (emulate_instruction(regs)) {
87114cf11afSPaul Mackerras 		case 0:
87214cf11afSPaul Mackerras 			regs->nip += 4;
87314cf11afSPaul Mackerras 			emulate_single_step(regs);
8748dad3f92SPaul Mackerras 			return;
87514cf11afSPaul Mackerras 		case -EFAULT:
87614cf11afSPaul Mackerras 			_exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
8778dad3f92SPaul Mackerras 			return;
8788dad3f92SPaul Mackerras 		}
8798dad3f92SPaul Mackerras 	}
8808dad3f92SPaul Mackerras 
88114cf11afSPaul Mackerras 	if (reason & REASON_PRIVILEGED)
88214cf11afSPaul Mackerras 		_exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
88314cf11afSPaul Mackerras 	else
88414cf11afSPaul Mackerras 		_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
88514cf11afSPaul Mackerras }
88614cf11afSPaul Mackerras 
887dc1c1ca3SStephen Rothwell void alignment_exception(struct pt_regs *regs)
88814cf11afSPaul Mackerras {
8894393c4f6SBenjamin Herrenschmidt 	int sig, code, fixed = 0;
89014cf11afSPaul Mackerras 
891e9370ae1SPaul Mackerras 	/* we don't implement logging of alignment exceptions */
892e9370ae1SPaul Mackerras 	if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS))
89314cf11afSPaul Mackerras 		fixed = fix_alignment(regs);
89414cf11afSPaul Mackerras 
89514cf11afSPaul Mackerras 	if (fixed == 1) {
89614cf11afSPaul Mackerras 		regs->nip += 4;	/* skip over emulated instruction */
89714cf11afSPaul Mackerras 		emulate_single_step(regs);
89814cf11afSPaul Mackerras 		return;
89914cf11afSPaul Mackerras 	}
90014cf11afSPaul Mackerras 
90114cf11afSPaul Mackerras 	/* Operand address was bad */
90214cf11afSPaul Mackerras 	if (fixed == -EFAULT) {
9034393c4f6SBenjamin Herrenschmidt 		sig = SIGSEGV;
9044393c4f6SBenjamin Herrenschmidt 		code = SEGV_ACCERR;
9054393c4f6SBenjamin Herrenschmidt 	} else {
9064393c4f6SBenjamin Herrenschmidt 		sig = SIGBUS;
9074393c4f6SBenjamin Herrenschmidt 		code = BUS_ADRALN;
90814cf11afSPaul Mackerras 	}
9094393c4f6SBenjamin Herrenschmidt 	if (user_mode(regs))
9104393c4f6SBenjamin Herrenschmidt 		_exception(sig, regs, code, regs->dar);
9114393c4f6SBenjamin Herrenschmidt 	else
9124393c4f6SBenjamin Herrenschmidt 		bad_page_fault(regs, regs->dar, sig);
91314cf11afSPaul Mackerras }
91414cf11afSPaul Mackerras 
91514cf11afSPaul Mackerras void StackOverflow(struct pt_regs *regs)
91614cf11afSPaul Mackerras {
91714cf11afSPaul Mackerras 	printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
91814cf11afSPaul Mackerras 	       current, regs->gpr[1]);
91914cf11afSPaul Mackerras 	debugger(regs);
92014cf11afSPaul Mackerras 	show_regs(regs);
92114cf11afSPaul Mackerras 	panic("kernel stack overflow");
92214cf11afSPaul Mackerras }
92314cf11afSPaul Mackerras 
92414cf11afSPaul Mackerras void nonrecoverable_exception(struct pt_regs *regs)
92514cf11afSPaul Mackerras {
92614cf11afSPaul Mackerras 	printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
92714cf11afSPaul Mackerras 	       regs->nip, regs->msr);
92814cf11afSPaul Mackerras 	debugger(regs);
92914cf11afSPaul Mackerras 	die("nonrecoverable exception", regs, SIGKILL);
93014cf11afSPaul Mackerras }
93114cf11afSPaul Mackerras 
93214cf11afSPaul Mackerras void trace_syscall(struct pt_regs *regs)
93314cf11afSPaul Mackerras {
93414cf11afSPaul Mackerras 	printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
93519c5870cSAlexey Dobriyan 	       current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
93614cf11afSPaul Mackerras 	       regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
93714cf11afSPaul Mackerras }
93814cf11afSPaul Mackerras 
939dc1c1ca3SStephen Rothwell void kernel_fp_unavailable_exception(struct pt_regs *regs)
940dc1c1ca3SStephen Rothwell {
941dc1c1ca3SStephen Rothwell 	printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
942dc1c1ca3SStephen Rothwell 			  "%lx at %lx\n", regs->trap, regs->nip);
943dc1c1ca3SStephen Rothwell 	die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
944dc1c1ca3SStephen Rothwell }
945dc1c1ca3SStephen Rothwell 
946dc1c1ca3SStephen Rothwell void altivec_unavailable_exception(struct pt_regs *regs)
947dc1c1ca3SStephen Rothwell {
948dc1c1ca3SStephen Rothwell 	if (user_mode(regs)) {
949dc1c1ca3SStephen Rothwell 		/* A user program has executed an altivec instruction,
950dc1c1ca3SStephen Rothwell 		   but this kernel doesn't support altivec. */
951dc1c1ca3SStephen Rothwell 		_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
952dc1c1ca3SStephen Rothwell 		return;
953dc1c1ca3SStephen Rothwell 	}
9546c4841c2SAnton Blanchard 
955dc1c1ca3SStephen Rothwell 	printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
956dc1c1ca3SStephen Rothwell 			"%lx at %lx\n", regs->trap, regs->nip);
957dc1c1ca3SStephen Rothwell 	die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
958dc1c1ca3SStephen Rothwell }
959dc1c1ca3SStephen Rothwell 
960ce48b210SMichael Neuling void vsx_unavailable_exception(struct pt_regs *regs)
961ce48b210SMichael Neuling {
962ce48b210SMichael Neuling 	if (user_mode(regs)) {
963ce48b210SMichael Neuling 		/* A user program has executed an vsx instruction,
964ce48b210SMichael Neuling 		   but this kernel doesn't support vsx. */
965ce48b210SMichael Neuling 		_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
966ce48b210SMichael Neuling 		return;
967ce48b210SMichael Neuling 	}
968ce48b210SMichael Neuling 
969ce48b210SMichael Neuling 	printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception "
970ce48b210SMichael Neuling 			"%lx at %lx\n", regs->trap, regs->nip);
971ce48b210SMichael Neuling 	die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
972ce48b210SMichael Neuling }
973ce48b210SMichael Neuling 
974dc1c1ca3SStephen Rothwell void performance_monitor_exception(struct pt_regs *regs)
975dc1c1ca3SStephen Rothwell {
976dc1c1ca3SStephen Rothwell 	perf_irq(regs);
977dc1c1ca3SStephen Rothwell }
978dc1c1ca3SStephen Rothwell 
9798dad3f92SPaul Mackerras #ifdef CONFIG_8xx
98014cf11afSPaul Mackerras void SoftwareEmulation(struct pt_regs *regs)
98114cf11afSPaul Mackerras {
98214cf11afSPaul Mackerras 	extern int do_mathemu(struct pt_regs *);
98314cf11afSPaul Mackerras 	extern int Soft_emulate_8xx(struct pt_regs *);
9845dd57a13SScott Wood #if defined(CONFIG_MATH_EMULATION) || defined(CONFIG_8XX_MINIMAL_FPEMU)
98514cf11afSPaul Mackerras 	int errcode;
9865dd57a13SScott Wood #endif
98714cf11afSPaul Mackerras 
98814cf11afSPaul Mackerras 	CHECK_FULL_REGS(regs);
98914cf11afSPaul Mackerras 
99014cf11afSPaul Mackerras 	if (!user_mode(regs)) {
99114cf11afSPaul Mackerras 		debugger(regs);
99214cf11afSPaul Mackerras 		die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
99314cf11afSPaul Mackerras 	}
99414cf11afSPaul Mackerras 
99514cf11afSPaul Mackerras #ifdef CONFIG_MATH_EMULATION
99614cf11afSPaul Mackerras 	errcode = do_mathemu(regs);
997*80947e7cSGeert Uytterhoeven 	if (errcode >= 0)
998*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(math);
9995fad293bSKumar Gala 
10005fad293bSKumar Gala 	switch (errcode) {
10015fad293bSKumar Gala 	case 0:
10025fad293bSKumar Gala 		emulate_single_step(regs);
10035fad293bSKumar Gala 		return;
10045fad293bSKumar Gala 	case 1: {
10055fad293bSKumar Gala 			int code = 0;
10065fad293bSKumar Gala 			code = __parse_fpscr(current->thread.fpscr.val);
10075fad293bSKumar Gala 			_exception(SIGFPE, regs, code, regs->nip);
10085fad293bSKumar Gala 			return;
10095fad293bSKumar Gala 		}
10105fad293bSKumar Gala 	case -EFAULT:
10115fad293bSKumar Gala 		_exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
10125fad293bSKumar Gala 		return;
10135fad293bSKumar Gala 	default:
10145fad293bSKumar Gala 		_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
10155fad293bSKumar Gala 		return;
10165fad293bSKumar Gala 	}
10175fad293bSKumar Gala 
10185dd57a13SScott Wood #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
101914cf11afSPaul Mackerras 	errcode = Soft_emulate_8xx(regs);
1020*80947e7cSGeert Uytterhoeven 	if (errcode >= 0)
1021*80947e7cSGeert Uytterhoeven 		PPC_WARN_EMULATED(8xx);
1022*80947e7cSGeert Uytterhoeven 
10235fad293bSKumar Gala 	switch (errcode) {
10245fad293bSKumar Gala 	case 0:
102514cf11afSPaul Mackerras 		emulate_single_step(regs);
10265fad293bSKumar Gala 		return;
10275fad293bSKumar Gala 	case 1:
10285fad293bSKumar Gala 		_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
10295fad293bSKumar Gala 		return;
10305fad293bSKumar Gala 	case -EFAULT:
10315fad293bSKumar Gala 		_exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
10325fad293bSKumar Gala 		return;
10335fad293bSKumar Gala 	}
10345dd57a13SScott Wood #else
10355dd57a13SScott Wood 	_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
10365fad293bSKumar Gala #endif
103714cf11afSPaul Mackerras }
10388dad3f92SPaul Mackerras #endif /* CONFIG_8xx */
103914cf11afSPaul Mackerras 
104014cf11afSPaul Mackerras #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
104114cf11afSPaul Mackerras 
1042f8279621SKumar Gala void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)
104314cf11afSPaul Mackerras {
104414cf11afSPaul Mackerras 	if (debug_status & DBSR_IC) {	/* instruction completion */
104514cf11afSPaul Mackerras 		regs->msr &= ~MSR_DE;
1046f8279621SKumar Gala 
104714cf11afSPaul Mackerras 		/* Disable instruction completion */
104814cf11afSPaul Mackerras 		mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
104914cf11afSPaul Mackerras 		/* Clear the instruction completion event */
105014cf11afSPaul Mackerras 		mtspr(SPRN_DBSR, DBSR_IC);
1051f8279621SKumar Gala 
1052f8279621SKumar Gala 		if (notify_die(DIE_SSTEP, "single_step", regs, 5,
1053f8279621SKumar Gala 			       5, SIGTRAP) == NOTIFY_STOP) {
105414cf11afSPaul Mackerras 			return;
105514cf11afSPaul Mackerras 		}
1056f8279621SKumar Gala 
1057f8279621SKumar Gala 		if (debugger_sstep(regs))
1058f8279621SKumar Gala 			return;
1059f8279621SKumar Gala 
1060f8279621SKumar Gala 		if (user_mode(regs)) {
1061f8279621SKumar Gala 			current->thread.dbcr0 &= ~DBCR0_IC;
1062f8279621SKumar Gala 		}
1063f8279621SKumar Gala 
1064f8279621SKumar Gala 		_exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
1065d6a61bfcSLuis Machado 	} else if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) {
1066d6a61bfcSLuis Machado 		regs->msr &= ~MSR_DE;
1067d6a61bfcSLuis Machado 
1068d6a61bfcSLuis Machado 		if (user_mode(regs)) {
1069d6a61bfcSLuis Machado 			current->thread.dbcr0 &= ~(DBSR_DAC1R | DBSR_DAC1W |
1070d6a61bfcSLuis Machado 								DBCR0_IDM);
1071d6a61bfcSLuis Machado 		} else {
1072d6a61bfcSLuis Machado 			/* Disable DAC interupts */
1073d6a61bfcSLuis Machado 			mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~(DBSR_DAC1R |
1074d6a61bfcSLuis Machado 						DBSR_DAC1W | DBCR0_IDM));
1075d6a61bfcSLuis Machado 
1076d6a61bfcSLuis Machado 			/* Clear the DAC event */
1077d6a61bfcSLuis Machado 			mtspr(SPRN_DBSR, (DBSR_DAC1R | DBSR_DAC1W));
1078d6a61bfcSLuis Machado 		}
1079d6a61bfcSLuis Machado 		/* Setup and send the trap to the handler */
1080d6a61bfcSLuis Machado 		do_dabr(regs, mfspr(SPRN_DAC1), debug_status);
108114cf11afSPaul Mackerras 	}
108214cf11afSPaul Mackerras }
108314cf11afSPaul Mackerras #endif /* CONFIG_4xx || CONFIG_BOOKE */
108414cf11afSPaul Mackerras 
108514cf11afSPaul Mackerras #if !defined(CONFIG_TAU_INT)
108614cf11afSPaul Mackerras void TAUException(struct pt_regs *regs)
108714cf11afSPaul Mackerras {
108814cf11afSPaul Mackerras 	printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx    %s\n",
108914cf11afSPaul Mackerras 	       regs->nip, regs->msr, regs->trap, print_tainted());
109014cf11afSPaul Mackerras }
109114cf11afSPaul Mackerras #endif /* CONFIG_INT_TAU */
109214cf11afSPaul Mackerras 
109314cf11afSPaul Mackerras #ifdef CONFIG_ALTIVEC
1094dc1c1ca3SStephen Rothwell void altivec_assist_exception(struct pt_regs *regs)
109514cf11afSPaul Mackerras {
109614cf11afSPaul Mackerras 	int err;
109714cf11afSPaul Mackerras 
109814cf11afSPaul Mackerras 	if (!user_mode(regs)) {
109914cf11afSPaul Mackerras 		printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
110014cf11afSPaul Mackerras 		       " at %lx\n", regs->nip);
11018dad3f92SPaul Mackerras 		die("Kernel VMX/Altivec assist exception", regs, SIGILL);
110214cf11afSPaul Mackerras 	}
110314cf11afSPaul Mackerras 
1104dc1c1ca3SStephen Rothwell 	flush_altivec_to_thread(current);
1105dc1c1ca3SStephen Rothwell 
1106*80947e7cSGeert Uytterhoeven 	PPC_WARN_EMULATED(altivec);
110714cf11afSPaul Mackerras 	err = emulate_altivec(regs);
110814cf11afSPaul Mackerras 	if (err == 0) {
110914cf11afSPaul Mackerras 		regs->nip += 4;		/* skip emulated instruction */
111014cf11afSPaul Mackerras 		emulate_single_step(regs);
111114cf11afSPaul Mackerras 		return;
111214cf11afSPaul Mackerras 	}
111314cf11afSPaul Mackerras 
111414cf11afSPaul Mackerras 	if (err == -EFAULT) {
111514cf11afSPaul Mackerras 		/* got an error reading the instruction */
111614cf11afSPaul Mackerras 		_exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
111714cf11afSPaul Mackerras 	} else {
111814cf11afSPaul Mackerras 		/* didn't recognize the instruction */
111914cf11afSPaul Mackerras 		/* XXX quick hack for now: set the non-Java bit in the VSCR */
112014cf11afSPaul Mackerras 		if (printk_ratelimit())
112114cf11afSPaul Mackerras 			printk(KERN_ERR "Unrecognized altivec instruction "
112214cf11afSPaul Mackerras 			       "in %s at %lx\n", current->comm, regs->nip);
112314cf11afSPaul Mackerras 		current->thread.vscr.u[3] |= 0x10000;
112414cf11afSPaul Mackerras 	}
112514cf11afSPaul Mackerras }
112614cf11afSPaul Mackerras #endif /* CONFIG_ALTIVEC */
112714cf11afSPaul Mackerras 
1128ce48b210SMichael Neuling #ifdef CONFIG_VSX
1129ce48b210SMichael Neuling void vsx_assist_exception(struct pt_regs *regs)
1130ce48b210SMichael Neuling {
1131ce48b210SMichael Neuling 	if (!user_mode(regs)) {
1132ce48b210SMichael Neuling 		printk(KERN_EMERG "VSX assist exception in kernel mode"
1133ce48b210SMichael Neuling 		       " at %lx\n", regs->nip);
1134ce48b210SMichael Neuling 		die("Kernel VSX assist exception", regs, SIGILL);
1135ce48b210SMichael Neuling 	}
1136ce48b210SMichael Neuling 
1137ce48b210SMichael Neuling 	flush_vsx_to_thread(current);
1138ce48b210SMichael Neuling 	printk(KERN_INFO "VSX assist not supported at %lx\n", regs->nip);
1139ce48b210SMichael Neuling 	_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
1140ce48b210SMichael Neuling }
1141ce48b210SMichael Neuling #endif /* CONFIG_VSX */
1142ce48b210SMichael Neuling 
114314cf11afSPaul Mackerras #ifdef CONFIG_FSL_BOOKE
1144620165f9SKumar Gala 
1145620165f9SKumar Gala void doorbell_exception(struct pt_regs *regs)
1146620165f9SKumar Gala {
1147620165f9SKumar Gala #ifdef CONFIG_SMP
1148620165f9SKumar Gala 	int cpu = smp_processor_id();
1149620165f9SKumar Gala 	int msg;
1150620165f9SKumar Gala 
1151620165f9SKumar Gala 	if (num_online_cpus() < 2)
1152620165f9SKumar Gala 		return;
1153620165f9SKumar Gala 
1154620165f9SKumar Gala 	for (msg = 0; msg < 4; msg++)
1155620165f9SKumar Gala 		if (test_and_clear_bit(msg, &dbell_smp_message[cpu]))
1156620165f9SKumar Gala 			smp_message_recv(msg);
1157620165f9SKumar Gala #else
1158620165f9SKumar Gala 	printk(KERN_WARNING "Received doorbell on non-smp system\n");
1159620165f9SKumar Gala #endif
1160620165f9SKumar Gala }
1161620165f9SKumar Gala 
116214cf11afSPaul Mackerras void CacheLockingException(struct pt_regs *regs, unsigned long address,
116314cf11afSPaul Mackerras 			   unsigned long error_code)
116414cf11afSPaul Mackerras {
116514cf11afSPaul Mackerras 	/* We treat cache locking instructions from the user
116614cf11afSPaul Mackerras 	 * as priv ops, in the future we could try to do
116714cf11afSPaul Mackerras 	 * something smarter
116814cf11afSPaul Mackerras 	 */
116914cf11afSPaul Mackerras 	if (error_code & (ESR_DLK|ESR_ILK))
117014cf11afSPaul Mackerras 		_exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
117114cf11afSPaul Mackerras 	return;
117214cf11afSPaul Mackerras }
117314cf11afSPaul Mackerras #endif /* CONFIG_FSL_BOOKE */
117414cf11afSPaul Mackerras 
117514cf11afSPaul Mackerras #ifdef CONFIG_SPE
117614cf11afSPaul Mackerras void SPEFloatingPointException(struct pt_regs *regs)
117714cf11afSPaul Mackerras {
11786a800f36SLiu Yu 	extern int do_spe_mathemu(struct pt_regs *regs);
117914cf11afSPaul Mackerras 	unsigned long spefscr;
118014cf11afSPaul Mackerras 	int fpexc_mode;
118114cf11afSPaul Mackerras 	int code = 0;
11826a800f36SLiu Yu 	int err;
11836a800f36SLiu Yu 
11846a800f36SLiu Yu 	preempt_disable();
11856a800f36SLiu Yu 	if (regs->msr & MSR_SPE)
11866a800f36SLiu Yu 		giveup_spe(current);
11876a800f36SLiu Yu 	preempt_enable();
118814cf11afSPaul Mackerras 
118914cf11afSPaul Mackerras 	spefscr = current->thread.spefscr;
119014cf11afSPaul Mackerras 	fpexc_mode = current->thread.fpexc_mode;
119114cf11afSPaul Mackerras 
119214cf11afSPaul Mackerras 	if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
119314cf11afSPaul Mackerras 		code = FPE_FLTOVF;
119414cf11afSPaul Mackerras 	}
119514cf11afSPaul Mackerras 	else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
119614cf11afSPaul Mackerras 		code = FPE_FLTUND;
119714cf11afSPaul Mackerras 	}
119814cf11afSPaul Mackerras 	else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
119914cf11afSPaul Mackerras 		code = FPE_FLTDIV;
120014cf11afSPaul Mackerras 	else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
120114cf11afSPaul Mackerras 		code = FPE_FLTINV;
120214cf11afSPaul Mackerras 	}
120314cf11afSPaul Mackerras 	else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
120414cf11afSPaul Mackerras 		code = FPE_FLTRES;
120514cf11afSPaul Mackerras 
12066a800f36SLiu Yu 	err = do_spe_mathemu(regs);
12076a800f36SLiu Yu 	if (err == 0) {
12086a800f36SLiu Yu 		regs->nip += 4;		/* skip emulated instruction */
12096a800f36SLiu Yu 		emulate_single_step(regs);
121014cf11afSPaul Mackerras 		return;
121114cf11afSPaul Mackerras 	}
12126a800f36SLiu Yu 
12136a800f36SLiu Yu 	if (err == -EFAULT) {
12146a800f36SLiu Yu 		/* got an error reading the instruction */
12156a800f36SLiu Yu 		_exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
12166a800f36SLiu Yu 	} else if (err == -EINVAL) {
12176a800f36SLiu Yu 		/* didn't recognize the instruction */
12186a800f36SLiu Yu 		printk(KERN_ERR "unrecognized spe instruction "
12196a800f36SLiu Yu 		       "in %s at %lx\n", current->comm, regs->nip);
12206a800f36SLiu Yu 	} else {
12216a800f36SLiu Yu 		_exception(SIGFPE, regs, code, regs->nip);
12226a800f36SLiu Yu 	}
12236a800f36SLiu Yu 
12246a800f36SLiu Yu 	return;
12256a800f36SLiu Yu }
12266a800f36SLiu Yu 
12276a800f36SLiu Yu void SPEFloatingPointRoundException(struct pt_regs *regs)
12286a800f36SLiu Yu {
12296a800f36SLiu Yu 	extern int speround_handler(struct pt_regs *regs);
12306a800f36SLiu Yu 	int err;
12316a800f36SLiu Yu 
12326a800f36SLiu Yu 	preempt_disable();
12336a800f36SLiu Yu 	if (regs->msr & MSR_SPE)
12346a800f36SLiu Yu 		giveup_spe(current);
12356a800f36SLiu Yu 	preempt_enable();
12366a800f36SLiu Yu 
12376a800f36SLiu Yu 	regs->nip -= 4;
12386a800f36SLiu Yu 	err = speround_handler(regs);
12396a800f36SLiu Yu 	if (err == 0) {
12406a800f36SLiu Yu 		regs->nip += 4;		/* skip emulated instruction */
12416a800f36SLiu Yu 		emulate_single_step(regs);
12426a800f36SLiu Yu 		return;
12436a800f36SLiu Yu 	}
12446a800f36SLiu Yu 
12456a800f36SLiu Yu 	if (err == -EFAULT) {
12466a800f36SLiu Yu 		/* got an error reading the instruction */
12476a800f36SLiu Yu 		_exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
12486a800f36SLiu Yu 	} else if (err == -EINVAL) {
12496a800f36SLiu Yu 		/* didn't recognize the instruction */
12506a800f36SLiu Yu 		printk(KERN_ERR "unrecognized spe instruction "
12516a800f36SLiu Yu 		       "in %s at %lx\n", current->comm, regs->nip);
12526a800f36SLiu Yu 	} else {
12536a800f36SLiu Yu 		_exception(SIGFPE, regs, 0, regs->nip);
12546a800f36SLiu Yu 		return;
12556a800f36SLiu Yu 	}
12566a800f36SLiu Yu }
125714cf11afSPaul Mackerras #endif
125814cf11afSPaul Mackerras 
1259dc1c1ca3SStephen Rothwell /*
1260dc1c1ca3SStephen Rothwell  * We enter here if we get an unrecoverable exception, that is, one
1261dc1c1ca3SStephen Rothwell  * that happened at a point where the RI (recoverable interrupt) bit
1262dc1c1ca3SStephen Rothwell  * in the MSR is 0.  This indicates that SRR0/1 are live, and that
1263dc1c1ca3SStephen Rothwell  * we therefore lost state by taking this exception.
1264dc1c1ca3SStephen Rothwell  */
1265dc1c1ca3SStephen Rothwell void unrecoverable_exception(struct pt_regs *regs)
1266dc1c1ca3SStephen Rothwell {
1267dc1c1ca3SStephen Rothwell 	printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
1268dc1c1ca3SStephen Rothwell 	       regs->trap, regs->nip);
1269dc1c1ca3SStephen Rothwell 	die("Unrecoverable exception", regs, SIGABRT);
1270dc1c1ca3SStephen Rothwell }
1271dc1c1ca3SStephen Rothwell 
127214cf11afSPaul Mackerras #ifdef CONFIG_BOOKE_WDT
127314cf11afSPaul Mackerras /*
127414cf11afSPaul Mackerras  * Default handler for a Watchdog exception,
127514cf11afSPaul Mackerras  * spins until a reboot occurs
127614cf11afSPaul Mackerras  */
127714cf11afSPaul Mackerras void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
127814cf11afSPaul Mackerras {
127914cf11afSPaul Mackerras 	/* Generic WatchdogHandler, implement your own */
128014cf11afSPaul Mackerras 	mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
128114cf11afSPaul Mackerras 	return;
128214cf11afSPaul Mackerras }
128314cf11afSPaul Mackerras 
128414cf11afSPaul Mackerras void WatchdogException(struct pt_regs *regs)
128514cf11afSPaul Mackerras {
128614cf11afSPaul Mackerras 	printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
128714cf11afSPaul Mackerras 	WatchdogHandler(regs);
128814cf11afSPaul Mackerras }
128914cf11afSPaul Mackerras #endif
1290dc1c1ca3SStephen Rothwell 
1291dc1c1ca3SStephen Rothwell /*
1292dc1c1ca3SStephen Rothwell  * We enter here if we discover during exception entry that we are
1293dc1c1ca3SStephen Rothwell  * running in supervisor mode with a userspace value in the stack pointer.
1294dc1c1ca3SStephen Rothwell  */
1295dc1c1ca3SStephen Rothwell void kernel_bad_stack(struct pt_regs *regs)
1296dc1c1ca3SStephen Rothwell {
1297dc1c1ca3SStephen Rothwell 	printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
1298dc1c1ca3SStephen Rothwell 	       regs->gpr[1], regs->nip);
1299dc1c1ca3SStephen Rothwell 	die("Bad kernel stack pointer", regs, SIGABRT);
1300dc1c1ca3SStephen Rothwell }
130114cf11afSPaul Mackerras 
130214cf11afSPaul Mackerras void __init trap_init(void)
130314cf11afSPaul Mackerras {
130414cf11afSPaul Mackerras }
1305*80947e7cSGeert Uytterhoeven 
1306*80947e7cSGeert Uytterhoeven 
1307*80947e7cSGeert Uytterhoeven #ifdef CONFIG_PPC_EMULATED_STATS
1308*80947e7cSGeert Uytterhoeven 
1309*80947e7cSGeert Uytterhoeven #define WARN_EMULATED_SETUP(type)	.type = { .name = #type }
1310*80947e7cSGeert Uytterhoeven 
1311*80947e7cSGeert Uytterhoeven struct ppc_emulated ppc_emulated = {
1312*80947e7cSGeert Uytterhoeven #ifdef CONFIG_ALTIVEC
1313*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(altivec),
1314*80947e7cSGeert Uytterhoeven #endif
1315*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(dcba),
1316*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(dcbz),
1317*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(fp_pair),
1318*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(isel),
1319*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(mcrxr),
1320*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(mfpvr),
1321*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(multiple),
1322*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(popcntb),
1323*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(spe),
1324*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(string),
1325*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(unaligned),
1326*80947e7cSGeert Uytterhoeven #ifdef CONFIG_MATH_EMULATION
1327*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(math),
1328*80947e7cSGeert Uytterhoeven #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
1329*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(8xx),
1330*80947e7cSGeert Uytterhoeven #endif
1331*80947e7cSGeert Uytterhoeven #ifdef CONFIG_VSX
1332*80947e7cSGeert Uytterhoeven 	WARN_EMULATED_SETUP(vsx),
1333*80947e7cSGeert Uytterhoeven #endif
1334*80947e7cSGeert Uytterhoeven };
1335*80947e7cSGeert Uytterhoeven 
1336*80947e7cSGeert Uytterhoeven u32 ppc_warn_emulated;
1337*80947e7cSGeert Uytterhoeven 
1338*80947e7cSGeert Uytterhoeven void ppc_warn_emulated_print(const char *type)
1339*80947e7cSGeert Uytterhoeven {
1340*80947e7cSGeert Uytterhoeven 	if (printk_ratelimit())
1341*80947e7cSGeert Uytterhoeven 		pr_warning("%s used emulated %s instruction\n", current->comm,
1342*80947e7cSGeert Uytterhoeven 			   type);
1343*80947e7cSGeert Uytterhoeven }
1344*80947e7cSGeert Uytterhoeven 
1345*80947e7cSGeert Uytterhoeven static int __init ppc_warn_emulated_init(void)
1346*80947e7cSGeert Uytterhoeven {
1347*80947e7cSGeert Uytterhoeven 	struct dentry *dir, *d;
1348*80947e7cSGeert Uytterhoeven 	unsigned int i;
1349*80947e7cSGeert Uytterhoeven 	struct ppc_emulated_entry *entries = (void *)&ppc_emulated;
1350*80947e7cSGeert Uytterhoeven 
1351*80947e7cSGeert Uytterhoeven 	if (!powerpc_debugfs_root)
1352*80947e7cSGeert Uytterhoeven 		return -ENODEV;
1353*80947e7cSGeert Uytterhoeven 
1354*80947e7cSGeert Uytterhoeven 	dir = debugfs_create_dir("emulated_instructions",
1355*80947e7cSGeert Uytterhoeven 				 powerpc_debugfs_root);
1356*80947e7cSGeert Uytterhoeven 	if (!dir)
1357*80947e7cSGeert Uytterhoeven 		return -ENOMEM;
1358*80947e7cSGeert Uytterhoeven 
1359*80947e7cSGeert Uytterhoeven 	d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir,
1360*80947e7cSGeert Uytterhoeven 			       &ppc_warn_emulated);
1361*80947e7cSGeert Uytterhoeven 	if (!d)
1362*80947e7cSGeert Uytterhoeven 		goto fail;
1363*80947e7cSGeert Uytterhoeven 
1364*80947e7cSGeert Uytterhoeven 	for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) {
1365*80947e7cSGeert Uytterhoeven 		d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir,
1366*80947e7cSGeert Uytterhoeven 				       (u32 *)&entries[i].val.counter);
1367*80947e7cSGeert Uytterhoeven 		if (!d)
1368*80947e7cSGeert Uytterhoeven 			goto fail;
1369*80947e7cSGeert Uytterhoeven 	}
1370*80947e7cSGeert Uytterhoeven 
1371*80947e7cSGeert Uytterhoeven 	return 0;
1372*80947e7cSGeert Uytterhoeven 
1373*80947e7cSGeert Uytterhoeven fail:
1374*80947e7cSGeert Uytterhoeven 	debugfs_remove_recursive(dir);
1375*80947e7cSGeert Uytterhoeven 	return -ENOMEM;
1376*80947e7cSGeert Uytterhoeven }
1377*80947e7cSGeert Uytterhoeven 
1378*80947e7cSGeert Uytterhoeven device_initcall(ppc_warn_emulated_init);
1379*80947e7cSGeert Uytterhoeven 
1380*80947e7cSGeert Uytterhoeven #endif /* CONFIG_PPC_EMULATED_STATS */
1381