2 * HW exception handling
4 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2008 PetaLogix
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
13 * This file handles the architecture-dependent parts of hardware exceptions
16 #include <linux/kernel.h>
17 #include <linux/signal.h>
18 #include <linux/sched.h>
19 #include <linux/kallsyms.h>
20 #include <linux/module.h>
22 #include <asm/exceptions.h>
23 #include <asm/entry.h> /* For KM CPU var */
24 #include <asm/uaccess.h>
25 #include <asm/errno.h>
26 #include <asm/ptrace.h>
27 #include <asm/current.h>
29 #define MICROBLAZE_ILL_OPCODE_EXCEPTION 0x02
30 #define MICROBLAZE_IBUS_EXCEPTION 0x03
31 #define MICROBLAZE_DBUS_EXCEPTION 0x04
32 #define MICROBLAZE_DIV_ZERO_EXCEPTION 0x05
33 #define MICROBLAZE_FPU_EXCEPTION 0x06
34 #define MICROBLAZE_PRIVILEG_EXCEPTION 0x07
36 static DEFINE_SPINLOCK(die_lock);
38 void die(const char *str, struct pt_regs *fp, long err)
41 spin_lock_irq(&die_lock);
42 printk(KERN_WARNING "Oops: %s, sig: %ld\n", str, err);
44 spin_unlock_irq(&die_lock);
45 /* do_exit() should take care of panic'ing from an interrupt
46 * context so we don't handle it here
51 void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
55 if (kernel_mode(regs)) {
57 die("Exception in kernel mode", regs, signr);
59 info.si_signo = signr;
62 info.si_addr = (void __user *) addr;
63 force_sig_info(signr, &info, current);
66 asmlinkage void full_exception(struct pt_regs *regs, unsigned int type,
70 printk(KERN_WARNING "Exception %02x in %s mode, FSR=%08x PC=%08x ESR=%08x\n",
71 type, user_mode(regs) ? "user" : "kernel", fsr,
72 (unsigned int) regs->pc, (unsigned int) regs->esr);
75 switch (type & 0x1F) {
76 case MICROBLAZE_ILL_OPCODE_EXCEPTION:
77 _exception(SIGILL, regs, ILL_ILLOPC, addr);
79 case MICROBLAZE_IBUS_EXCEPTION:
80 if (user_mode(regs)) {
81 printk(KERN_WARNING "Instruction bus error exception in user mode.\n");
82 _exception(SIGBUS, regs, BUS_ADRERR, addr);
85 printk(KERN_WARNING "Instruction bus error exception in kernel mode.\n");
86 die("bus exception", regs, SIGBUS);
88 case MICROBLAZE_DBUS_EXCEPTION:
89 if (user_mode(regs)) {
90 printk(KERN_WARNING "Data bus error exception in user mode.\n");
91 _exception(SIGBUS, regs, BUS_ADRERR, addr);
94 printk(KERN_WARNING "Data bus error exception in kernel mode.\n");
95 die("bus exception", regs, SIGBUS);
97 case MICROBLAZE_DIV_ZERO_EXCEPTION:
98 printk(KERN_WARNING "Divide by zero exception\n");
99 _exception(SIGILL, regs, ILL_ILLOPC, addr);
102 case MICROBLAZE_FPU_EXCEPTION:
103 /* IEEE FP exception */
104 /* I removed fsr variable and use code var for storing fsr */
107 else if (fsr & FSR_OF)
109 else if (fsr & FSR_UF)
111 else if (fsr & FSR_DZ)
113 else if (fsr & FSR_DO)
115 _exception(SIGFPE, regs, fsr, addr);
119 printk(KERN_WARNING "Unexpected exception %02x "
120 "PC=%08x in %s mode\n", type, (unsigned int) addr,
121 kernel_mode(regs) ? "kernel" : "user");