]>
Commit | Line | Data |
---|---|---|
c4df4bc1 MS |
1 | /* |
2 | * HW exception handling | |
3 | * | |
4 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> | |
5 | * Copyright (C) 2008 PetaLogix | |
6 | * | |
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. | |
10 | */ | |
11 | ||
12 | /* | |
13 | * This file handles the architecture-dependent parts of hardware exceptions | |
14 | */ | |
15 | ||
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> | |
21 | ||
22 | #include <asm/exceptions.h> | |
23 | #include <asm/entry.h> /* For KM CPU var */ | |
4bb73c3d MS |
24 | #include <linux/uaccess.h> |
25 | #include <linux/errno.h> | |
26 | #include <linux/ptrace.h> | |
c4df4bc1 | 27 | #include <asm/current.h> |
17b93146 | 28 | #include <asm/cacheflush.h> |
c4df4bc1 MS |
29 | |
30 | #define MICROBLAZE_ILL_OPCODE_EXCEPTION 0x02 | |
31 | #define MICROBLAZE_IBUS_EXCEPTION 0x03 | |
32 | #define MICROBLAZE_DBUS_EXCEPTION 0x04 | |
33 | #define MICROBLAZE_DIV_ZERO_EXCEPTION 0x05 | |
34 | #define MICROBLAZE_FPU_EXCEPTION 0x06 | |
4bb73c3d | 35 | #define MICROBLAZE_PRIVILEGED_EXCEPTION 0x07 |
c4df4bc1 MS |
36 | |
37 | static DEFINE_SPINLOCK(die_lock); | |
38 | ||
39 | void die(const char *str, struct pt_regs *fp, long err) | |
40 | { | |
41 | console_verbose(); | |
42 | spin_lock_irq(&die_lock); | |
43 | printk(KERN_WARNING "Oops: %s, sig: %ld\n", str, err); | |
44 | show_regs(fp); | |
45 | spin_unlock_irq(&die_lock); | |
46 | /* do_exit() should take care of panic'ing from an interrupt | |
47 | * context so we don't handle it here | |
48 | */ | |
49 | do_exit(err); | |
50 | } | |
51 | ||
751f1605 | 52 | /* for user application debugging */ |
f699980b | 53 | asmlinkage void sw_exception(struct pt_regs *regs) |
751f1605 MS |
54 | { |
55 | _exception(SIGTRAP, regs, TRAP_BRKPT, regs->r16); | |
17b93146 MS |
56 | flush_dcache_range(regs->r16, regs->r16 + 0x4); |
57 | flush_icache_range(regs->r16, regs->r16 + 0x4); | |
751f1605 MS |
58 | } |
59 | ||
c4df4bc1 MS |
60 | void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) |
61 | { | |
62 | siginfo_t info; | |
63 | ||
64 | if (kernel_mode(regs)) { | |
c4df4bc1 MS |
65 | die("Exception in kernel mode", regs, signr); |
66 | } | |
67 | info.si_signo = signr; | |
68 | info.si_errno = 0; | |
69 | info.si_code = code; | |
70 | info.si_addr = (void __user *) addr; | |
71 | force_sig_info(signr, &info, current); | |
72 | } | |
73 | ||
74 | asmlinkage void full_exception(struct pt_regs *regs, unsigned int type, | |
75 | int fsr, int addr) | |
76 | { | |
4bb73c3d | 77 | #ifdef CONFIG_MMU |
4bb73c3d MS |
78 | addr = regs->pc; |
79 | #endif | |
80 | ||
c4df4bc1 | 81 | #if 0 |
bfc32ad0 MS |
82 | printk(KERN_WARNING "Exception %02x in %s mode, FSR=%08x PC=%08x " \ |
83 | "ESR=%08x\n", | |
c4df4bc1 MS |
84 | type, user_mode(regs) ? "user" : "kernel", fsr, |
85 | (unsigned int) regs->pc, (unsigned int) regs->esr); | |
86 | #endif | |
87 | ||
88 | switch (type & 0x1F) { | |
89 | case MICROBLAZE_ILL_OPCODE_EXCEPTION: | |
4bb73c3d | 90 | if (user_mode(regs)) { |
c4554c32 | 91 | pr_debug("Illegal opcode exception in user mode\n"); |
4bb73c3d MS |
92 | _exception(SIGILL, regs, ILL_ILLOPC, addr); |
93 | return; | |
94 | } | |
bfc32ad0 MS |
95 | printk(KERN_WARNING "Illegal opcode exception " \ |
96 | "in kernel mode.\n"); | |
4bb73c3d | 97 | die("opcode exception", regs, SIGBUS); |
c4df4bc1 MS |
98 | break; |
99 | case MICROBLAZE_IBUS_EXCEPTION: | |
100 | if (user_mode(regs)) { | |
c4554c32 | 101 | pr_debug("Instruction bus error exception in user mode\n"); |
c4df4bc1 MS |
102 | _exception(SIGBUS, regs, BUS_ADRERR, addr); |
103 | return; | |
104 | } | |
bfc32ad0 MS |
105 | printk(KERN_WARNING "Instruction bus error exception " \ |
106 | "in kernel mode.\n"); | |
c4df4bc1 MS |
107 | die("bus exception", regs, SIGBUS); |
108 | break; | |
109 | case MICROBLAZE_DBUS_EXCEPTION: | |
110 | if (user_mode(regs)) { | |
c4554c32 | 111 | pr_debug("Data bus error exception in user mode\n"); |
c4df4bc1 MS |
112 | _exception(SIGBUS, regs, BUS_ADRERR, addr); |
113 | return; | |
114 | } | |
bfc32ad0 MS |
115 | printk(KERN_WARNING "Data bus error exception " \ |
116 | "in kernel mode.\n"); | |
c4df4bc1 MS |
117 | die("bus exception", regs, SIGBUS); |
118 | break; | |
119 | case MICROBLAZE_DIV_ZERO_EXCEPTION: | |
4bb73c3d | 120 | if (user_mode(regs)) { |
c4554c32 | 121 | pr_debug("Divide by zero exception in user mode\n"); |
15ec0908 | 122 | _exception(SIGFPE, regs, FPE_INTDIV, addr); |
4bb73c3d MS |
123 | return; |
124 | } | |
bfc32ad0 MS |
125 | printk(KERN_WARNING "Divide by zero exception " \ |
126 | "in kernel mode.\n"); | |
f3ff8212 | 127 | die("Divide by zero exception", regs, SIGBUS); |
c4df4bc1 | 128 | break; |
c4df4bc1 | 129 | case MICROBLAZE_FPU_EXCEPTION: |
c4554c32 | 130 | pr_debug("FPU exception\n"); |
c4df4bc1 MS |
131 | /* IEEE FP exception */ |
132 | /* I removed fsr variable and use code var for storing fsr */ | |
133 | if (fsr & FSR_IO) | |
134 | fsr = FPE_FLTINV; | |
135 | else if (fsr & FSR_OF) | |
136 | fsr = FPE_FLTOVF; | |
137 | else if (fsr & FSR_UF) | |
138 | fsr = FPE_FLTUND; | |
139 | else if (fsr & FSR_DZ) | |
140 | fsr = FPE_FLTDIV; | |
141 | else if (fsr & FSR_DO) | |
142 | fsr = FPE_FLTRES; | |
143 | _exception(SIGFPE, regs, fsr, addr); | |
144 | break; | |
145 | ||
4bb73c3d MS |
146 | #ifdef CONFIG_MMU |
147 | case MICROBLAZE_PRIVILEGED_EXCEPTION: | |
c4554c32 | 148 | pr_debug("Privileged exception\n"); |
04256096 | 149 | _exception(SIGILL, regs, ILL_PRVOPC, addr); |
4bb73c3d MS |
150 | break; |
151 | #endif | |
c4df4bc1 | 152 | default: |
4bb73c3d | 153 | /* FIXME what to do in unexpected exception */ |
c4df4bc1 MS |
154 | printk(KERN_WARNING "Unexpected exception %02x " |
155 | "PC=%08x in %s mode\n", type, (unsigned int) addr, | |
156 | kernel_mode(regs) ? "kernel" : "user"); | |
157 | } | |
158 | return; | |
159 | } |