]>
Commit | Line | Data |
---|---|---|
6bc9a396 CL |
1 | /* |
2 | * arch/score/kernel/traps.c | |
3 | * | |
4 | * Score Processor version. | |
5 | * | |
6 | * Copyright (C) 2009 Sunplus Core Technology Co., Ltd. | |
7 | * Chen Liqin <liqin.chen@sunplusct.com> | |
8 | * Lennox Wu <lennox.wu@sunplusct.com> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, see the file COPYING, or write | |
22 | * to the Free Software Foundation, Inc., | |
23 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
24 | */ | |
25 | ||
0f296af8 | 26 | #include <linux/extable.h> |
68e21be2 | 27 | #include <linux/sched/mm.h> |
3f07c014 | 28 | #include <linux/sched/signal.h> |
b17b0153 | 29 | #include <linux/sched/debug.h> |
589ee628 | 30 | #include <linux/mm_types.h> |
6bc9a396 CL |
31 | |
32 | #include <asm/cacheflush.h> | |
33 | #include <asm/irq.h> | |
34 | #include <asm/irq_regs.h> | |
7c0f6ba6 | 35 | #include <linux/uaccess.h> |
6bc9a396 CL |
36 | |
37 | unsigned long exception_handlers[32]; | |
38 | ||
39 | /* | |
40 | * The architecture-independent show_stack generator | |
41 | */ | |
42 | void show_stack(struct task_struct *task, unsigned long *sp) | |
43 | { | |
44 | int i; | |
45 | long stackdata; | |
46 | ||
47 | sp = sp ? sp : (unsigned long *)&sp; | |
48 | ||
49 | printk(KERN_NOTICE "Stack: "); | |
50 | i = 1; | |
51 | while ((long) sp & (PAGE_SIZE - 1)) { | |
52 | if (i && ((i % 8) == 0)) | |
53 | printk(KERN_NOTICE "\n"); | |
54 | if (i > 40) { | |
55 | printk(KERN_NOTICE " ..."); | |
56 | break; | |
57 | } | |
58 | ||
59 | if (__get_user(stackdata, sp++)) { | |
60 | printk(KERN_NOTICE " (Bad stack address)"); | |
61 | break; | |
62 | } | |
63 | ||
64 | printk(KERN_NOTICE " %08lx", stackdata); | |
65 | i++; | |
66 | } | |
67 | printk(KERN_NOTICE "\n"); | |
68 | } | |
69 | ||
70 | static void show_trace(long *sp) | |
71 | { | |
72 | int i; | |
73 | long addr; | |
74 | ||
75 | sp = sp ? sp : (long *) &sp; | |
76 | ||
77 | printk(KERN_NOTICE "Call Trace: "); | |
78 | i = 1; | |
79 | while ((long) sp & (PAGE_SIZE - 1)) { | |
80 | if (__get_user(addr, sp++)) { | |
81 | if (i && ((i % 6) == 0)) | |
82 | printk(KERN_NOTICE "\n"); | |
83 | printk(KERN_NOTICE " (Bad stack address)\n"); | |
84 | break; | |
85 | } | |
86 | ||
87 | if (kernel_text_address(addr)) { | |
88 | if (i && ((i % 6) == 0)) | |
89 | printk(KERN_NOTICE "\n"); | |
90 | if (i > 40) { | |
91 | printk(KERN_NOTICE " ..."); | |
92 | break; | |
93 | } | |
94 | ||
95 | printk(KERN_NOTICE " [<%08lx>]", addr); | |
96 | i++; | |
97 | } | |
98 | } | |
99 | printk(KERN_NOTICE "\n"); | |
100 | } | |
101 | ||
102 | static void show_code(unsigned int *pc) | |
103 | { | |
104 | long i; | |
105 | ||
106 | printk(KERN_NOTICE "\nCode:"); | |
107 | ||
108 | for (i = -3; i < 6; i++) { | |
109 | unsigned long insn; | |
110 | if (__get_user(insn, pc + i)) { | |
111 | printk(KERN_NOTICE " (Bad address in epc)\n"); | |
112 | break; | |
113 | } | |
114 | printk(KERN_NOTICE "%c%08lx%c", (i ? ' ' : '<'), | |
115 | insn, (i ? ' ' : '>')); | |
116 | } | |
117 | } | |
118 | ||
119 | /* | |
120 | * FIXME: really the generic show_regs should take a const pointer argument. | |
121 | */ | |
122 | void show_regs(struct pt_regs *regs) | |
123 | { | |
a43cb95d TH |
124 | show_regs_print_info(KERN_DEFAULT); |
125 | ||
6bc9a396 CL |
126 | printk("r0 : %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", |
127 | regs->regs[0], regs->regs[1], regs->regs[2], regs->regs[3], | |
128 | regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]); | |
129 | printk("r8 : %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", | |
130 | regs->regs[8], regs->regs[9], regs->regs[10], regs->regs[11], | |
131 | regs->regs[12], regs->regs[13], regs->regs[14], regs->regs[15]); | |
132 | printk("r16: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", | |
133 | regs->regs[16], regs->regs[17], regs->regs[18], regs->regs[19], | |
134 | regs->regs[20], regs->regs[21], regs->regs[22], regs->regs[23]); | |
135 | printk("r24: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", | |
136 | regs->regs[24], regs->regs[25], regs->regs[26], regs->regs[27], | |
137 | regs->regs[28], regs->regs[29], regs->regs[30], regs->regs[31]); | |
138 | ||
139 | printk("CEH : %08lx\n", regs->ceh); | |
140 | printk("CEL : %08lx\n", regs->cel); | |
141 | ||
142 | printk("EMA:%08lx, epc:%08lx %s\nPSR: %08lx\nECR:%08lx\nCondition : %08lx\n", | |
143 | regs->cp0_ema, regs->cp0_epc, print_tainted(), regs->cp0_psr, | |
144 | regs->cp0_ecr, regs->cp0_condition); | |
145 | } | |
146 | ||
147 | static void show_registers(struct pt_regs *regs) | |
148 | { | |
149 | show_regs(regs); | |
150 | printk(KERN_NOTICE "Process %s (pid: %d, stackpage=%08lx)\n", | |
151 | current->comm, current->pid, (unsigned long) current); | |
152 | show_stack(current_thread_info()->task, (long *) regs->regs[0]); | |
153 | show_trace((long *) regs->regs[0]); | |
154 | show_code((unsigned int *) regs->cp0_epc); | |
155 | printk(KERN_NOTICE "\n"); | |
156 | } | |
157 | ||
6bc9a396 CL |
158 | void __die(const char *str, struct pt_regs *regs, const char *file, |
159 | const char *func, unsigned long line) | |
160 | { | |
161 | console_verbose(); | |
162 | printk("%s", str); | |
163 | if (file && func) | |
164 | printk(" in %s:%s, line %ld", file, func, line); | |
165 | printk(":\n"); | |
166 | show_registers(regs); | |
167 | do_exit(SIGSEGV); | |
168 | } | |
169 | ||
170 | void __die_if_kernel(const char *str, struct pt_regs *regs, | |
171 | const char *file, const char *func, unsigned long line) | |
172 | { | |
173 | if (!user_mode(regs)) | |
174 | __die(str, regs, file, func, line); | |
175 | } | |
176 | ||
177 | asmlinkage void do_adelinsn(struct pt_regs *regs) | |
178 | { | |
179 | printk("do_ADE-linsn:ema:0x%08lx:epc:0x%08lx\n", | |
180 | regs->cp0_ema, regs->cp0_epc); | |
181 | die_if_kernel("do_ade execution Exception\n", regs); | |
182 | force_sig(SIGBUS, current); | |
183 | } | |
184 | ||
185 | asmlinkage void do_adedata(struct pt_regs *regs) | |
186 | { | |
187 | const struct exception_table_entry *fixup; | |
188 | fixup = search_exception_tables(regs->cp0_epc); | |
189 | if (fixup) { | |
190 | regs->cp0_epc = fixup->fixup; | |
191 | return; | |
192 | } | |
193 | printk("do_ADE-data:ema:0x%08lx:epc:0x%08lx\n", | |
194 | regs->cp0_ema, regs->cp0_epc); | |
195 | die_if_kernel("do_ade execution Exception\n", regs); | |
196 | force_sig(SIGBUS, current); | |
197 | } | |
198 | ||
199 | asmlinkage void do_pel(struct pt_regs *regs) | |
200 | { | |
201 | die_if_kernel("do_pel execution Exception", regs); | |
202 | force_sig(SIGFPE, current); | |
203 | } | |
204 | ||
205 | asmlinkage void do_cee(struct pt_regs *regs) | |
206 | { | |
207 | die_if_kernel("do_cee execution Exception", regs); | |
208 | force_sig(SIGFPE, current); | |
209 | } | |
210 | ||
211 | asmlinkage void do_cpe(struct pt_regs *regs) | |
212 | { | |
213 | die_if_kernel("do_cpe execution Exception", regs); | |
214 | force_sig(SIGFPE, current); | |
215 | } | |
216 | ||
217 | asmlinkage void do_be(struct pt_regs *regs) | |
218 | { | |
219 | die_if_kernel("do_be execution Exception", regs); | |
220 | force_sig(SIGBUS, current); | |
221 | } | |
222 | ||
223 | asmlinkage void do_ov(struct pt_regs *regs) | |
224 | { | |
225 | siginfo_t info; | |
226 | ||
227 | die_if_kernel("do_ov execution Exception", regs); | |
228 | ||
229 | info.si_code = FPE_INTOVF; | |
230 | info.si_signo = SIGFPE; | |
231 | info.si_errno = 0; | |
232 | info.si_addr = (void *)regs->cp0_epc; | |
233 | force_sig_info(SIGFPE, &info, current); | |
234 | } | |
235 | ||
236 | asmlinkage void do_tr(struct pt_regs *regs) | |
237 | { | |
238 | die_if_kernel("do_tr execution Exception", regs); | |
239 | force_sig(SIGTRAP, current); | |
240 | } | |
241 | ||
242 | asmlinkage void do_ri(struct pt_regs *regs) | |
243 | { | |
244 | unsigned long epc_insn; | |
245 | unsigned long epc = regs->cp0_epc; | |
246 | ||
247 | read_tsk_long(current, epc, &epc_insn); | |
248 | if (current->thread.single_step == 1) { | |
249 | if ((epc == current->thread.addr1) || | |
250 | (epc == current->thread.addr2)) { | |
0402c91a | 251 | user_disable_single_step(current); |
6bc9a396 CL |
252 | force_sig(SIGTRAP, current); |
253 | return; | |
254 | } else | |
255 | BUG(); | |
256 | } else if ((epc_insn == BREAKPOINT32_INSN) || | |
257 | ((epc_insn & 0x0000FFFF) == 0x7002) || | |
258 | ((epc_insn & 0xFFFF0000) == 0x70020000)) { | |
259 | force_sig(SIGTRAP, current); | |
260 | return; | |
261 | } else { | |
262 | die_if_kernel("do_ri execution Exception", regs); | |
263 | force_sig(SIGILL, current); | |
264 | } | |
265 | } | |
266 | ||
267 | asmlinkage void do_ccu(struct pt_regs *regs) | |
268 | { | |
269 | die_if_kernel("do_ccu execution Exception", regs); | |
270 | force_sig(SIGILL, current); | |
271 | } | |
272 | ||
273 | asmlinkage void do_reserved(struct pt_regs *regs) | |
274 | { | |
275 | /* | |
276 | * Game over - no way to handle this if it ever occurs. Most probably | |
277 | * caused by a new unknown cpu type or after another deadly | |
278 | * hard/software error. | |
279 | */ | |
280 | die_if_kernel("do_reserved execution Exception", regs); | |
281 | show_regs(regs); | |
282 | panic("Caught reserved exception - should not happen."); | |
283 | } | |
284 | ||
285 | /* | |
286 | * NMI exception handler. | |
287 | */ | |
288 | void nmi_exception_handler(struct pt_regs *regs) | |
289 | { | |
290 | die_if_kernel("nmi_exception_handler execution Exception", regs); | |
291 | die("NMI", regs); | |
292 | } | |
293 | ||
294 | /* Install CPU exception handler */ | |
295 | void *set_except_vector(int n, void *addr) | |
296 | { | |
297 | unsigned long handler = (unsigned long) addr; | |
298 | unsigned long old_handler = exception_handlers[n]; | |
299 | ||
300 | exception_handlers[n] = handler; | |
301 | return (void *)old_handler; | |
302 | } | |
303 | ||
304 | void __init trap_init(void) | |
305 | { | |
306 | int i; | |
307 | ||
308 | pgd_current = (unsigned long)init_mm.pgd; | |
309 | /* DEBUG EXCEPTION */ | |
310 | memcpy((void *)DEBUG_VECTOR_BASE_ADDR, | |
311 | &debug_exception_vector, DEBUG_VECTOR_SIZE); | |
312 | /* NMI EXCEPTION */ | |
313 | memcpy((void *)GENERAL_VECTOR_BASE_ADDR, | |
314 | &general_exception_vector, GENERAL_VECTOR_SIZE); | |
315 | ||
316 | /* | |
317 | * Initialise exception handlers | |
318 | */ | |
319 | for (i = 0; i <= 31; i++) | |
320 | set_except_vector(i, handle_reserved); | |
321 | ||
322 | set_except_vector(1, handle_nmi); | |
323 | set_except_vector(2, handle_adelinsn); | |
324 | set_except_vector(3, handle_tlb_refill); | |
325 | set_except_vector(4, handle_tlb_invaild); | |
326 | set_except_vector(5, handle_ibe); | |
327 | set_except_vector(6, handle_pel); | |
328 | set_except_vector(7, handle_sys); | |
329 | set_except_vector(8, handle_ccu); | |
330 | set_except_vector(9, handle_ri); | |
331 | set_except_vector(10, handle_tr); | |
332 | set_except_vector(11, handle_adedata); | |
333 | set_except_vector(12, handle_adedata); | |
334 | set_except_vector(13, handle_tlb_refill); | |
335 | set_except_vector(14, handle_tlb_invaild); | |
336 | set_except_vector(15, handle_mod); | |
337 | set_except_vector(16, handle_cee); | |
338 | set_except_vector(17, handle_cpe); | |
339 | set_except_vector(18, handle_dbe); | |
340 | flush_icache_range(DEBUG_VECTOR_BASE_ADDR, IRQ_VECTOR_BASE_ADDR); | |
341 | ||
f1f10076 | 342 | mmgrab(&init_mm); |
6bc9a396 CL |
343 | current->active_mm = &init_mm; |
344 | cpu_cache_init(); | |
345 | } |