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