[AVR32] constify function pointer tables
[deliverable/linux.git] / arch / avr32 / kernel / traps.c
CommitLineData
5f97f7f9
HS
1/*
2 * Copyright (C) 2004-2006 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
623b0355
HS
8
9#include <linux/bug.h>
5f97f7f9 10#include <linux/init.h>
5f97f7f9 11#include <linux/kallsyms.h>
623b0355 12#include <linux/module.h>
5f97f7f9 13#include <linux/notifier.h>
623b0355
HS
14#include <linux/sched.h>
15#include <linux/uaccess.h>
5f97f7f9 16
5f97f7f9 17#include <asm/addrspace.h>
5f97f7f9 18#include <asm/mmu_context.h>
623b0355
HS
19#include <asm/ocd.h>
20#include <asm/sysreg.h>
21#include <asm/traps.h>
5f97f7f9 22
5f97f7f9
HS
23static DEFINE_SPINLOCK(die_lock);
24
623b0355 25void NORET_TYPE die(const char *str, struct pt_regs *regs, long err)
5f97f7f9 26{
5f97f7f9
HS
27 static int die_counter;
28
29 console_verbose();
30 spin_lock_irq(&die_lock);
31 bust_spinlocks(1);
32
623b0355
HS
33 printk(KERN_ALERT "Oops: %s, sig: %ld [#%d]\n" KERN_EMERG,
34 str, err, ++die_counter);
35#ifdef CONFIG_PREEMPT
36 printk("PREEMPT ");
37#endif
38#ifdef CONFIG_FRAME_POINTER
39 printk("FRAME_POINTER ");
40#endif
41 if (current_cpu_data.features & AVR32_FEATURE_OCD) {
8dfe8f29 42 unsigned long did = ocd_read(DID);
623b0355
HS
43 printk("chip: 0x%03lx:0x%04lx rev %lu\n",
44 (did >> 1) & 0x7ff,
45 (did >> 12) & 0x7fff,
46 (did >> 28) & 0xf);
47 } else {
48 printk("cpu: arch %u r%u / core %u r%u\n",
49 current_cpu_data.arch_type,
50 current_cpu_data.arch_revision,
51 current_cpu_data.cpu_type,
52 current_cpu_data.cpu_revision);
5f97f7f9
HS
53 }
54
623b0355
HS
55 print_modules();
56 show_regs_log_lvl(regs, KERN_EMERG);
57 show_stack_log_lvl(current, regs->sp, regs, KERN_EMERG);
5f97f7f9 58 bust_spinlocks(0);
bcdcd8e7 59 add_taint(TAINT_DIE);
5f97f7f9 60 spin_unlock_irq(&die_lock);
623b0355
HS
61
62 if (in_interrupt())
63 panic("Fatal exception in interrupt");
64
65 if (panic_on_oops)
66 panic("Fatal exception");
67
68 do_exit(err);
5f97f7f9
HS
69}
70
623b0355
HS
71void _exception(long signr, struct pt_regs *regs, int code,
72 unsigned long addr)
5f97f7f9 73{
623b0355
HS
74 siginfo_t info;
75
5f97f7f9 76 if (!user_mode(regs))
623b0355
HS
77 die("Unhandled exception in kernel mode", regs, signr);
78
79 memset(&info, 0, sizeof(info));
80 info.si_signo = signr;
81 info.si_code = code;
82 info.si_addr = (void __user *)addr;
83 force_sig_info(signr, &info, current);
5f97f7f9 84
5f97f7f9 85 /*
623b0355
HS
86 * Init gets no signals that it doesn't have a handler for.
87 * That's all very well, but if it has caused a synchronous
88 * exception and we ignore the resulting signal, it will just
89 * generate the same exception over and over again and we get
90 * nowhere. Better to kill it and let the kernel panic.
5f97f7f9 91 */
b460cbc5 92 if (is_global_init(current)) {
623b0355
HS
93 __sighandler_t handler;
94
95 spin_lock_irq(&current->sighand->siglock);
96 handler = current->sighand->action[signr-1].sa.sa_handler;
97 spin_unlock_irq(&current->sighand->siglock);
98 if (handler == SIG_DFL) {
99 /* init has generated a synchronous exception
100 and it doesn't have a handler for the signal */
101 printk(KERN_CRIT "init has generated signal %ld "
102 "but has no handler for it\n", signr);
103 do_exit(signr);
104 }
105 }
106}
5f97f7f9 107
623b0355
HS
108asmlinkage void do_nmi(unsigned long ecr, struct pt_regs *regs)
109{
110 printk(KERN_ALERT "Got Non-Maskable Interrupt, dumping regs\n");
111 show_regs_log_lvl(regs, KERN_ALERT);
112 show_stack_log_lvl(current, regs->sp, regs, KERN_ALERT);
5f97f7f9
HS
113}
114
115asmlinkage void do_critical_exception(unsigned long ecr, struct pt_regs *regs)
116{
623b0355 117 die("Critical exception", regs, SIGKILL);
5f97f7f9
HS
118}
119
120asmlinkage void do_address_exception(unsigned long ecr, struct pt_regs *regs)
121{
623b0355 122 _exception(SIGBUS, regs, BUS_ADRALN, regs->pc);
5f97f7f9
HS
123}
124
125/* This way of handling undefined instructions is stolen from ARM */
126static LIST_HEAD(undef_hook);
e89b064a 127static DEFINE_SPINLOCK(undef_lock);
5f97f7f9
HS
128
129void register_undef_hook(struct undef_hook *hook)
130{
131 spin_lock_irq(&undef_lock);
132 list_add(&hook->node, &undef_hook);
133 spin_unlock_irq(&undef_lock);
134}
135
136void unregister_undef_hook(struct undef_hook *hook)
137{
138 spin_lock_irq(&undef_lock);
139 list_del(&hook->node);
140 spin_unlock_irq(&undef_lock);
141}
142
143static int do_cop_absent(u32 insn)
144{
145 int cop_nr;
146 u32 cpucr;
623b0355
HS
147
148 if ((insn & 0xfdf00000) == 0xf1900000)
5f97f7f9
HS
149 /* LDC0 */
150 cop_nr = 0;
151 else
152 cop_nr = (insn >> 13) & 0x7;
153
154 /* Try enabling the coprocessor */
155 cpucr = sysreg_read(CPUCR);
156 cpucr |= (1 << (24 + cop_nr));
157 sysreg_write(CPUCR, cpucr);
158
159 cpucr = sysreg_read(CPUCR);
623b0355
HS
160 if (!(cpucr & (1 << (24 + cop_nr))))
161 return -ENODEV;
5f97f7f9
HS
162
163 return 0;
164}
165
623b0355 166int is_valid_bugaddr(unsigned long pc)
5f97f7f9 167{
623b0355
HS
168 unsigned short opcode;
169
170 if (pc < PAGE_OFFSET)
171 return 0;
172 if (probe_kernel_address((u16 *)pc, opcode))
173 return 0;
5f97f7f9 174
623b0355 175 return opcode == AVR32_BUG_OPCODE;
5f97f7f9 176}
5f97f7f9
HS
177
178asmlinkage void do_illegal_opcode(unsigned long ecr, struct pt_regs *regs)
179{
180 u32 insn;
181 struct undef_hook *hook;
5f97f7f9 182 void __user *pc;
623b0355 183 long code;
5f97f7f9 184
623b0355
HS
185 if (!user_mode(regs) && (ecr == ECR_ILLEGAL_OPCODE)) {
186 enum bug_trap_type type;
187
608e2619 188 type = report_bug(regs->pc, regs);
623b0355
HS
189 switch (type) {
190 case BUG_TRAP_TYPE_NONE:
191 break;
192 case BUG_TRAP_TYPE_WARN:
193 regs->pc += 2;
194 return;
195 case BUG_TRAP_TYPE_BUG:
196 die("Kernel BUG", regs, SIGKILL);
197 }
198 }
5f97f7f9
HS
199
200 local_irq_enable();
201
623b0355
HS
202 if (user_mode(regs)) {
203 pc = (void __user *)instruction_pointer(regs);
204 if (get_user(insn, (u32 __user *)pc))
205 goto invalid_area;
5f97f7f9 206
623b0355 207 if (ecr == ECR_COPROC_ABSENT && !do_cop_absent(insn))
5f97f7f9 208 return;
5f97f7f9 209
623b0355
HS
210 spin_lock_irq(&undef_lock);
211 list_for_each_entry(hook, &undef_hook, node) {
212 if ((insn & hook->insn_mask) == hook->insn_val) {
213 if (hook->fn(regs, insn) == 0) {
214 spin_unlock_irq(&undef_lock);
215 return;
216 }
5f97f7f9
HS
217 }
218 }
623b0355 219 spin_unlock_irq(&undef_lock);
5f97f7f9 220 }
5f97f7f9 221
5f97f7f9 222 switch (ecr) {
5f97f7f9 223 case ECR_PRIVILEGE_VIOLATION:
623b0355 224 code = ILL_PRVOPC;
5f97f7f9
HS
225 break;
226 case ECR_COPROC_ABSENT:
623b0355 227 code = ILL_COPROC;
5f97f7f9
HS
228 break;
229 default:
623b0355
HS
230 code = ILL_ILLOPC;
231 break;
5f97f7f9
HS
232 }
233
623b0355 234 _exception(SIGILL, regs, code, regs->pc);
5f97f7f9
HS
235 return;
236
623b0355
HS
237invalid_area:
238 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->pc);
5f97f7f9
HS
239}
240
241asmlinkage void do_fpe(unsigned long ecr, struct pt_regs *regs)
242{
623b0355
HS
243 /* We have no FPU yet */
244 _exception(SIGILL, regs, ILL_COPROC, regs->pc);
5f97f7f9
HS
245}
246
247
248void __init trap_init(void)
249{
250
251}
This page took 0.155931 seconds and 5 git commands to generate.