GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / microblaze / kernel / exceptions.c
blobba5e963dc6982149aeb298abf431148d63c7cc68
1 /*
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 <linux/uaccess.h>
25 #include <linux/errno.h>
26 #include <linux/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_PRIVILEGED_EXCEPTION 0x07
36 static DEFINE_SPINLOCK(die_lock);
38 void die(const char *str, struct pt_regs *fp, long err)
40 console_verbose();
41 spin_lock_irq(&die_lock);
42 printk(KERN_WARNING "Oops: %s, sig: %ld\n", str, err);
43 show_regs(fp);
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
48 do_exit(err);
51 /* for user application debugging */
52 void sw_exception(struct pt_regs *regs)
54 _exception(SIGTRAP, regs, TRAP_BRKPT, regs->r16);
57 void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
59 siginfo_t info;
61 if (kernel_mode(regs)) {
62 die("Exception in kernel mode", regs, signr);
64 info.si_signo = signr;
65 info.si_errno = 0;
66 info.si_code = code;
67 info.si_addr = (void __user *) addr;
68 force_sig_info(signr, &info, current);
71 asmlinkage void full_exception(struct pt_regs *regs, unsigned int type,
72 int fsr, int addr)
74 #ifdef CONFIG_MMU
75 int code;
76 addr = regs->pc;
77 #endif
80 switch (type & 0x1F) {
81 case MICROBLAZE_ILL_OPCODE_EXCEPTION:
82 if (user_mode(regs)) {
83 pr_debug(KERN_WARNING "Illegal opcode exception " \
84 "in user mode.\n");
85 _exception(SIGILL, regs, ILL_ILLOPC, addr);
86 return;
88 printk(KERN_WARNING "Illegal opcode exception " \
89 "in kernel mode.\n");
90 die("opcode exception", regs, SIGBUS);
91 break;
92 case MICROBLAZE_IBUS_EXCEPTION:
93 if (user_mode(regs)) {
94 pr_debug(KERN_WARNING "Instruction bus error " \
95 "exception in user mode.\n");
96 _exception(SIGBUS, regs, BUS_ADRERR, addr);
97 return;
99 printk(KERN_WARNING "Instruction bus error exception " \
100 "in kernel mode.\n");
101 die("bus exception", regs, SIGBUS);
102 break;
103 case MICROBLAZE_DBUS_EXCEPTION:
104 if (user_mode(regs)) {
105 pr_debug(KERN_WARNING "Data bus error exception " \
106 "in user mode.\n");
107 _exception(SIGBUS, regs, BUS_ADRERR, addr);
108 return;
110 printk(KERN_WARNING "Data bus error exception " \
111 "in kernel mode.\n");
112 die("bus exception", regs, SIGBUS);
113 break;
114 case MICROBLAZE_DIV_ZERO_EXCEPTION:
115 if (user_mode(regs)) {
116 pr_debug(KERN_WARNING "Divide by zero exception " \
117 "in user mode\n");
118 _exception(SIGILL, regs, FPE_INTDIV, addr);
119 return;
121 printk(KERN_WARNING "Divide by zero exception " \
122 "in kernel mode.\n");
123 die("Divide by zero exception", regs, SIGBUS);
124 break;
125 case MICROBLAZE_FPU_EXCEPTION:
126 pr_debug(KERN_WARNING "FPU exception\n");
127 /* IEEE FP exception */
128 /* I removed fsr variable and use code var for storing fsr */
129 if (fsr & FSR_IO)
130 fsr = FPE_FLTINV;
131 else if (fsr & FSR_OF)
132 fsr = FPE_FLTOVF;
133 else if (fsr & FSR_UF)
134 fsr = FPE_FLTUND;
135 else if (fsr & FSR_DZ)
136 fsr = FPE_FLTDIV;
137 else if (fsr & FSR_DO)
138 fsr = FPE_FLTRES;
139 _exception(SIGFPE, regs, fsr, addr);
140 break;
142 #ifdef CONFIG_MMU
143 case MICROBLAZE_PRIVILEGED_EXCEPTION:
144 pr_debug(KERN_WARNING "Privileged exception\n");
145 /* "brk r0,r0" - used as debug breakpoint - old toolchain */
146 if (get_user(code, (unsigned long *)regs->pc) == 0
147 && code == 0x980c0000) {
148 _exception(SIGTRAP, regs, TRAP_BRKPT, addr);
149 } else {
150 _exception(SIGILL, regs, ILL_PRVOPC, addr);
152 break;
153 #endif
154 default:
155 printk(KERN_WARNING "Unexpected exception %02x "
156 "PC=%08x in %s mode\n", type, (unsigned int) addr,
157 kernel_mode(regs) ? "kernel" : "user");
159 return;