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