]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/mn10300/kernel/traps.c
MN10300: And Panasonic AM34 subarch and implement SMP
[mirror_ubuntu-artful-kernel.git] / arch / mn10300 / kernel / traps.c
CommitLineData
b920de1b
DH
1/* MN10300 Exception handling
2 *
3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Modified by David Howells (dhowells@redhat.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
11 */
12#include <linux/sched.h>
13#include <linux/kernel.h>
14#include <linux/string.h>
15#include <linux/errno.h>
16#include <linux/ptrace.h>
17#include <linux/timer.h>
18#include <linux/mm.h>
19#include <linux/smp.h>
b920de1b
DH
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24#include <linux/kallsyms.h>
25#include <linux/pci.h>
26#include <linux/kdebug.h>
27#include <linux/bug.h>
28#include <linux/irq.h>
29#include <asm/processor.h>
30#include <asm/system.h>
31#include <asm/uaccess.h>
32#include <asm/io.h>
33#include <asm/atomic.h>
34#include <asm/smp.h>
35#include <asm/pgalloc.h>
36#include <asm/cacheflush.h>
37#include <asm/cpu-regs.h>
38#include <asm/busctl-regs.h>
2f2a2132 39#include <unit/leds.h>
b920de1b
DH
40#include <asm/fpu.h>
41#include <asm/gdb-stub.h>
42#include <asm/sections.h>
43
44#if (CONFIG_INTERRUPT_VECTOR_BASE & 0xffffff)
45#error "INTERRUPT_VECTOR_BASE not aligned to 16MiB boundary!"
46#endif
47
368dd5ac
AT
48#ifdef CONFIG_SMP
49struct pt_regs *___frame[NR_CPUS]; /* current frame pointer */
50EXPORT_SYMBOL(___frame);
51#else /* CONFIG_SMP */
b920de1b
DH
52struct pt_regs *__frame; /* current frame pointer */
53EXPORT_SYMBOL(__frame);
368dd5ac 54#endif /* CONFIG_SMP */
b920de1b
DH
55
56int kstack_depth_to_print = 24;
57
58spinlock_t die_lock = __SPIN_LOCK_UNLOCKED(die_lock);
59
60ATOMIC_NOTIFIER_HEAD(mn10300_die_chain);
61
62/*
63 * These constants are for searching for possible module text
64 * segments. MODULE_RANGE is a guess of how much space is likely
65 * to be vmalloced.
66 */
67#define MODULE_RANGE (8 * 1024 * 1024)
68
69#define DO_ERROR(signr, prologue, str, name) \
70asmlinkage void name(struct pt_regs *regs, u32 intcode) \
71{ \
72 prologue; \
73 if (die_if_no_fixup(str, regs, intcode)) \
74 return; \
75 force_sig(signr, current); \
76}
77
78#define DO_EINFO(signr, prologue, str, name, sicode) \
79asmlinkage void name(struct pt_regs *regs, u32 intcode) \
80{ \
81 siginfo_t info; \
82 prologue; \
83 if (die_if_no_fixup(str, regs, intcode)) \
84 return; \
85 info.si_signo = signr; \
86 if (signr == SIGILL && sicode == ILL_ILLOPC) { \
87 uint8_t opcode; \
88 if (get_user(opcode, (uint8_t __user *)regs->pc) == 0) \
89 if (opcode == 0xff) \
90 info.si_signo = SIGTRAP; \
91 } \
92 info.si_errno = 0; \
93 info.si_code = sicode; \
94 info.si_addr = (void *) regs->pc; \
95 force_sig_info(info.si_signo, &info, current); \
96}
97
98DO_ERROR(SIGTRAP, {}, "trap", trap);
99DO_ERROR(SIGSEGV, {}, "ibreak", ibreak);
100DO_ERROR(SIGSEGV, {}, "obreak", obreak);
101DO_EINFO(SIGSEGV, {}, "access error", access_error, SEGV_ACCERR);
102DO_EINFO(SIGSEGV, {}, "insn access error", insn_acc_error, SEGV_ACCERR);
103DO_EINFO(SIGSEGV, {}, "data access error", data_acc_error, SEGV_ACCERR);
104DO_EINFO(SIGILL, {}, "privileged opcode", priv_op, ILL_PRVOPC);
105DO_EINFO(SIGILL, {}, "invalid opcode", invalid_op, ILL_ILLOPC);
106DO_EINFO(SIGILL, {}, "invalid ex opcode", invalid_exop, ILL_ILLOPC);
107DO_EINFO(SIGBUS, {}, "invalid address", mem_error, BUS_ADRERR);
108DO_EINFO(SIGBUS, {}, "bus error", bus_error, BUS_ADRERR);
b920de1b
DH
109
110DO_ERROR(SIGTRAP,
111#ifndef CONFIG_MN10300_USING_JTAG
112 DCR &= ~0x0001,
113#else
114 {},
115#endif
116 "single step", istep);
117
118/*
119 * handle NMI
120 */
121asmlinkage void nmi(struct pt_regs *regs, enum exception_code code)
122{
123 /* see if gdbstub wants to deal with it */
124#ifdef CONFIG_GDBSTUB
125 if (gdbstub_intercept(regs, code))
126 return;
127#endif
128
129 printk(KERN_WARNING "--- Register Dump ---\n");
130 show_registers(regs);
131 printk(KERN_WARNING "---------------------\n");
132}
133
134/*
135 * show a stack trace from the specified stack pointer
136 */
137void show_trace(unsigned long *sp)
138{
139 unsigned long *stack, addr, module_start, module_end;
140 int i;
141
ad361c98 142 printk(KERN_EMERG "\nCall Trace:");
b920de1b
DH
143
144 stack = sp;
145 i = 0;
146 module_start = VMALLOC_START;
147 module_end = VMALLOC_END;
148
149 while (((long) stack & (THREAD_SIZE - 1)) != 0) {
150 addr = *stack++;
151 if (__kernel_text_address(addr)) {
152#if 1
153 printk(" [<%08lx>]", addr);
154 print_symbol(" %s", addr);
155 printk("\n");
156#else
157 if ((i % 6) == 0)
ad361c98 158 printk(KERN_EMERG " ");
b920de1b
DH
159 printk("[<%08lx>] ", addr);
160 i++;
161#endif
162 }
163 }
164
165 printk("\n");
166}
167
168/*
169 * show the raw stack from the specified stack pointer
170 */
171void show_stack(struct task_struct *task, unsigned long *sp)
172{
173 unsigned long *stack;
174 int i;
175
176 if (!sp)
177 sp = (unsigned long *) &sp;
178
179 stack = sp;
180 printk(KERN_EMERG "Stack:");
181 for (i = 0; i < kstack_depth_to_print; i++) {
182 if (((long) stack & (THREAD_SIZE - 1)) == 0)
183 break;
184 if ((i % 8) == 0)
ad361c98 185 printk(KERN_EMERG " ");
b920de1b
DH
186 printk("%08lx ", *stack++);
187 }
188
189 show_trace(sp);
190}
191
192/*
193 * the architecture-independent dump_stack generator
194 */
195void dump_stack(void)
196{
197 unsigned long stack;
198
199 show_stack(current, &stack);
200}
201EXPORT_SYMBOL(dump_stack);
202
203/*
204 * dump the register file in the specified exception frame
205 */
206void show_registers_only(struct pt_regs *regs)
207{
208 unsigned long ssp;
209
210 ssp = (unsigned long) regs + sizeof(*regs);
211
212 printk(KERN_EMERG "PC: %08lx EPSW: %08lx SSP: %08lx mode: %s\n",
213 regs->pc, regs->epsw, ssp, user_mode(regs) ? "User" : "Super");
214 printk(KERN_EMERG "d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
215 regs->d0, regs->d1, regs->d2, regs->d3);
216 printk(KERN_EMERG "a0: %08lx a1: %08lx a2: %08lx a3: %08lx\n",
217 regs->a0, regs->a1, regs->a2, regs->a3);
218 printk(KERN_EMERG "e0: %08lx e1: %08lx e2: %08lx e3: %08lx\n",
219 regs->e0, regs->e1, regs->e2, regs->e3);
220 printk(KERN_EMERG "e4: %08lx e5: %08lx e6: %08lx e7: %08lx\n",
221 regs->e4, regs->e5, regs->e6, regs->e7);
222 printk(KERN_EMERG "lar: %08lx lir: %08lx mdr: %08lx usp: %08lx\n",
223 regs->lar, regs->lir, regs->mdr, regs->sp);
224 printk(KERN_EMERG "cvf: %08lx crl: %08lx crh: %08lx drq: %08lx\n",
225 regs->mcvf, regs->mcrl, regs->mcrh, regs->mdrq);
226 printk(KERN_EMERG "threadinfo=%p task=%p)\n",
227 current_thread_info(), current);
228
368dd5ac
AT
229 if ((unsigned long) current >= PAGE_OFFSET &&
230 (unsigned long) current < (unsigned long)high_memory)
b920de1b
DH
231 printk(KERN_EMERG "Process %s (pid: %d)\n",
232 current->comm, current->pid);
233
368dd5ac
AT
234#ifdef CONFIG_SMP
235 printk(KERN_EMERG "CPUID: %08x\n", CPUID);
236#endif
b920de1b
DH
237 printk(KERN_EMERG "CPUP: %04hx\n", CPUP);
238 printk(KERN_EMERG "TBR: %08x\n", TBR);
239 printk(KERN_EMERG "DEAR: %08x\n", DEAR);
240 printk(KERN_EMERG "sISR: %08x\n", sISR);
241 printk(KERN_EMERG "NMICR: %04hx\n", NMICR);
242 printk(KERN_EMERG "BCBERR: %08x\n", BCBERR);
243 printk(KERN_EMERG "BCBEAR: %08x\n", BCBEAR);
244 printk(KERN_EMERG "MMUFCR: %08x\n", MMUFCR);
245 printk(KERN_EMERG "IPTEU : %08x IPTEL2: %08x\n", IPTEU, IPTEL2);
246 printk(KERN_EMERG "DPTEU: %08x DPTEL2: %08x\n", DPTEU, DPTEL2);
247}
248
249/*
250 * dump the registers and the stack
251 */
252void show_registers(struct pt_regs *regs)
253{
254 unsigned long sp;
255 int i;
256
257 show_registers_only(regs);
258
259 if (!user_mode(regs))
260 sp = (unsigned long) regs + sizeof(*regs);
261 else
262 sp = regs->sp;
263
264 /* when in-kernel, we also print out the stack and code at the
265 * time of the fault..
266 */
267 if (!user_mode(regs)) {
268 printk(KERN_EMERG "\n");
269 show_stack(current, (unsigned long *) sp);
270
271#if 0
ad361c98 272 printk(KERN_EMERG "\nCode: ");
b920de1b
DH
273 if (regs->pc < PAGE_OFFSET)
274 goto bad;
275
276 for (i = 0; i < 20; i++) {
277 unsigned char c;
278 if (__get_user(c, &((unsigned char *) regs->pc)[i]))
279 goto bad;
280 printk("%02x ", c);
281 }
282#else
283 i = 0;
284#endif
285 }
286
287 printk("\n");
288 return;
289
290#if 0
291bad:
292 printk(KERN_EMERG " Bad PC value.");
293 break;
294#endif
295}
296
297/*
298 *
299 */
300void show_trace_task(struct task_struct *tsk)
301{
302 unsigned long sp = tsk->thread.sp;
303
304 /* User space on another CPU? */
305 if ((sp ^ (unsigned long) tsk) & (PAGE_MASK << 1))
306 return;
307
308 show_trace((unsigned long *) sp);
309}
310
311/*
312 * note the untimely death of part of the kernel
313 */
314void die(const char *str, struct pt_regs *regs, enum exception_code code)
315{
316 console_verbose();
317 spin_lock_irq(&die_lock);
ad361c98 318 printk(KERN_EMERG "\n%s: %04x\n",
b920de1b
DH
319 str, code & 0xffff);
320 show_registers(regs);
321
322 if (regs->pc >= 0x02000000 && regs->pc < 0x04000000 &&
323 (regs->epsw & (EPSW_IM | EPSW_IE)) != (EPSW_IM | EPSW_IE)) {
324 printk(KERN_EMERG "Exception in usermode interrupt handler\n");
ad361c98 325 printk(KERN_EMERG "\nPlease connect to kernel debugger !!\n");
b920de1b
DH
326 asm volatile ("0: bra 0b");
327 }
328
329 spin_unlock_irq(&die_lock);
330 do_exit(SIGSEGV);
331}
332
333/*
334 * see if there's a fixup handler we can force a jump to when an exception
335 * happens due to something kernel code did
336 */
337int die_if_no_fixup(const char *str, struct pt_regs *regs,
338 enum exception_code code)
339{
340 if (user_mode(regs))
341 return 0;
342
343 peripheral_leds_display_exception(code);
344
345 switch (code) {
346 /* see if we can fixup the kernel accessing memory */
347 case EXCEP_ITLBMISS:
348 case EXCEP_DTLBMISS:
349 case EXCEP_IAERROR:
350 case EXCEP_DAERROR:
351 case EXCEP_MEMERR:
352 case EXCEP_MISALIGN:
353 case EXCEP_BUSERROR:
354 case EXCEP_ILLDATACC:
355 case EXCEP_IOINSACC:
356 case EXCEP_PRIVINSACC:
357 case EXCEP_PRIVDATACC:
358 case EXCEP_DATINSACC:
359 if (fixup_exception(regs))
360 return 1;
361 case EXCEP_UNIMPINS:
362 if (regs->pc && *(uint8_t *)regs->pc == 0xff)
363 if (notify_die(DIE_BREAKPOINT, str, regs, code, 0, 0))
364 return 1;
365 break;
366 default:
367 break;
368 }
369
370 /* see if gdbstub wants to deal with it */
371#ifdef CONFIG_GDBSTUB
372 if (gdbstub_intercept(regs, code))
373 return 1;
374#endif
375
376 if (notify_die(DIE_GPF, str, regs, code, 0, 0))
377 return 1;
378
379 /* make the process die as the last resort */
380 die(str, regs, code);
381}
382
383/*
384 * handle unsupported syscall instructions (syscall 1-15)
385 */
386static asmlinkage void unsupported_syscall(struct pt_regs *regs,
387 enum exception_code code)
388{
389 struct task_struct *tsk = current;
390 siginfo_t info;
391
392 /* catch a kernel BUG() */
393 if (code == EXCEP_SYSCALL15 && !user_mode(regs)) {
394 if (report_bug(regs->pc, regs) == BUG_TRAP_TYPE_BUG) {
395#ifdef CONFIG_GDBSTUB
aa409e02 396 gdbstub_intercept(regs, code);
b920de1b
DH
397#endif
398 }
399 }
400
401 regs->pc -= 2; /* syscall return addr is _after_ the instruction */
402
403 die_if_no_fixup("An unsupported syscall insn was used by the kernel\n",
404 regs, code);
405
406 info.si_signo = SIGILL;
407 info.si_errno = ENOSYS;
408 info.si_code = ILL_ILLTRP;
409 info.si_addr = (void *) regs->pc;
410 force_sig_info(SIGILL, &info, tsk);
411}
412
413/*
414 * display the register file when the stack pointer gets clobbered
415 */
416asmlinkage void do_double_fault(struct pt_regs *regs)
417{
418 struct task_struct *tsk = current;
419
420 strcpy(tsk->comm, "emergency tsk");
421 tsk->pid = 0;
422 console_verbose();
423 printk(KERN_EMERG "--- double fault ---\n");
424 show_registers(regs);
425}
426
427/*
428 * asynchronous bus error (external, usually I/O DMA)
429 */
430asmlinkage void io_bus_error(u32 bcberr, u32 bcbear, struct pt_regs *regs)
431{
432 console_verbose();
433
ad361c98
JP
434 printk(KERN_EMERG "Asynchronous I/O Bus Error\n");
435 printk(KERN_EMERG "==========================\n");
b920de1b
DH
436
437 if (bcberr & BCBERR_BEME)
438 printk(KERN_EMERG "- Multiple recorded errors\n");
439
440 printk(KERN_EMERG "- Faulting Buses:%s%s%s\n",
441 bcberr & BCBERR_BEMR_CI ? " CPU-Ins-Fetch" : "",
442 bcberr & BCBERR_BEMR_CD ? " CPU-Data" : "",
443 bcberr & BCBERR_BEMR_DMA ? " DMA" : "");
444
445 printk(KERN_EMERG "- %s %s access made to %s at address %08x\n",
446 bcberr & BCBERR_BEBST ? "Burst" : "Single",
447 bcberr & BCBERR_BERW ? "Read" : "Write",
448 bcberr & BCBERR_BESB_MON ? "Monitor Space" :
449 bcberr & BCBERR_BESB_IO ? "Internal CPU I/O Space" :
450 bcberr & BCBERR_BESB_EX ? "External I/O Bus" :
451 bcberr & BCBERR_BESB_OPEX ? "External Memory Bus" :
452 "On Chip Memory",
453 bcbear
454 );
455
456 printk(KERN_EMERG "- Detected by the %s\n",
457 bcberr&BCBERR_BESD ? "Bus Control Unit" : "Slave Bus");
458
459#ifdef CONFIG_PCI
460#define BRIDGEREGB(X) (*(volatile __u8 *)(0xBE040000 + (X)))
461#define BRIDGEREGW(X) (*(volatile __u16 *)(0xBE040000 + (X)))
462#define BRIDGEREGL(X) (*(volatile __u32 *)(0xBE040000 + (X)))
463
464 printk(KERN_EMERG "- PCI Memory Paging Reg: %08x\n",
465 *(volatile __u32 *) (0xBFFFFFF4));
466 printk(KERN_EMERG "- PCI Bridge Base Address 0: %08x\n",
467 BRIDGEREGL(PCI_BASE_ADDRESS_0));
468 printk(KERN_EMERG "- PCI Bridge AMPCI Base Address: %08x\n",
469 BRIDGEREGL(0x48));
470 printk(KERN_EMERG "- PCI Bridge Command: %04hx\n",
471 BRIDGEREGW(PCI_COMMAND));
472 printk(KERN_EMERG "- PCI Bridge Status: %04hx\n",
473 BRIDGEREGW(PCI_STATUS));
474 printk(KERN_EMERG "- PCI Bridge Int Status: %08hx\n",
475 BRIDGEREGL(0x4c));
476#endif
477
478 printk(KERN_EMERG "\n");
479 show_registers(regs);
480
481 panic("Halted due to asynchronous I/O Bus Error\n");
482}
483
484/*
485 * handle an exception for which a handler has not yet been installed
486 */
487asmlinkage void uninitialised_exception(struct pt_regs *regs,
488 enum exception_code code)
489{
490
491 /* see if gdbstub wants to deal with it */
492#ifdef CONFIG_GDBSTUB
493 if (gdbstub_intercept(regs, code))
494 return;
495#endif
496
497 peripheral_leds_display_exception(code);
498 printk(KERN_EMERG "Uninitialised Exception 0x%04x\n", code & 0xFFFF);
499 show_registers(regs);
500
501 for (;;)
502 continue;
503}
504
505/*
506 * set an interrupt stub to jump to a handler
507 * ! NOTE: this does *not* flush the caches
508 */
509void __init __set_intr_stub(enum exception_code code, void *handler)
510{
511 unsigned long addr;
512 u8 *vector = (u8 *)(CONFIG_INTERRUPT_VECTOR_BASE + code);
513
514 addr = (unsigned long) handler - (unsigned long) vector;
515 vector[0] = 0xdc; /* JMP handler */
516 vector[1] = addr;
517 vector[2] = addr >> 8;
518 vector[3] = addr >> 16;
519 vector[4] = addr >> 24;
520 vector[5] = 0xcb;
521 vector[6] = 0xcb;
522 vector[7] = 0xcb;
523}
524
525/*
526 * set an interrupt stub to jump to a handler
527 */
528void __init set_intr_stub(enum exception_code code, void *handler)
529{
530 unsigned long addr;
531 u8 *vector = (u8 *)(CONFIG_INTERRUPT_VECTOR_BASE + code);
368dd5ac 532 unsigned long flags;
b920de1b
DH
533
534 addr = (unsigned long) handler - (unsigned long) vector;
368dd5ac
AT
535
536 flags = arch_local_cli_save();
537
b920de1b
DH
538 vector[0] = 0xdc; /* JMP handler */
539 vector[1] = addr;
540 vector[2] = addr >> 8;
541 vector[3] = addr >> 16;
542 vector[4] = addr >> 24;
543 vector[5] = 0xcb;
544 vector[6] = 0xcb;
545 vector[7] = 0xcb;
546
368dd5ac
AT
547 arch_local_irq_restore(flags);
548
b478491f 549#ifndef CONFIG_MN10300_CACHE_SNOOP
b920de1b
DH
550 mn10300_dcache_flush_inv();
551 mn10300_icache_inv();
b478491f 552#endif
b920de1b
DH
553}
554
b920de1b
DH
555/*
556 * initialise the exception table
557 */
558void __init trap_init(void)
559{
560 set_excp_vector(EXCEP_TRAP, trap);
561 set_excp_vector(EXCEP_ISTEP, istep);
562 set_excp_vector(EXCEP_IBREAK, ibreak);
563 set_excp_vector(EXCEP_OBREAK, obreak);
564
565 set_excp_vector(EXCEP_PRIVINS, priv_op);
566 set_excp_vector(EXCEP_UNIMPINS, invalid_op);
567 set_excp_vector(EXCEP_UNIMPEXINS, invalid_exop);
568 set_excp_vector(EXCEP_MEMERR, mem_error);
569 set_excp_vector(EXCEP_MISALIGN, misalignment);
570 set_excp_vector(EXCEP_BUSERROR, bus_error);
571 set_excp_vector(EXCEP_ILLINSACC, insn_acc_error);
572 set_excp_vector(EXCEP_ILLDATACC, data_acc_error);
573 set_excp_vector(EXCEP_IOINSACC, insn_acc_error);
574 set_excp_vector(EXCEP_PRIVINSACC, insn_acc_error);
575 set_excp_vector(EXCEP_PRIVDATACC, data_acc_error);
576 set_excp_vector(EXCEP_DATINSACC, insn_acc_error);
b920de1b
DH
577 set_excp_vector(EXCEP_FPU_UNIMPINS, fpu_invalid_op);
578 set_excp_vector(EXCEP_FPU_OPERATION, fpu_exception);
579
580 set_excp_vector(EXCEP_NMI, nmi);
581
582 set_excp_vector(EXCEP_SYSCALL1, unsupported_syscall);
583 set_excp_vector(EXCEP_SYSCALL2, unsupported_syscall);
584 set_excp_vector(EXCEP_SYSCALL3, unsupported_syscall);
585 set_excp_vector(EXCEP_SYSCALL4, unsupported_syscall);
586 set_excp_vector(EXCEP_SYSCALL5, unsupported_syscall);
587 set_excp_vector(EXCEP_SYSCALL6, unsupported_syscall);
588 set_excp_vector(EXCEP_SYSCALL7, unsupported_syscall);
589 set_excp_vector(EXCEP_SYSCALL8, unsupported_syscall);
590 set_excp_vector(EXCEP_SYSCALL9, unsupported_syscall);
591 set_excp_vector(EXCEP_SYSCALL10, unsupported_syscall);
592 set_excp_vector(EXCEP_SYSCALL11, unsupported_syscall);
593 set_excp_vector(EXCEP_SYSCALL12, unsupported_syscall);
594 set_excp_vector(EXCEP_SYSCALL13, unsupported_syscall);
595 set_excp_vector(EXCEP_SYSCALL14, unsupported_syscall);
596 set_excp_vector(EXCEP_SYSCALL15, unsupported_syscall);
597}
598
599/*
600 * determine if a program counter value is a valid bug address
601 */
602int is_valid_bugaddr(unsigned long pc)
603{
604 return pc >= PAGE_OFFSET;
605}