[ALSA] hda-codec - Add model for HP q965
[linux-2.6/verdex.git] / arch / avr32 / kernel / traps.c
blob7e803f4d7a12902972da2ce1325acd0bc43cafc2
1 /*
2 * Copyright (C) 2004-2006 Atmel Corporation
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 */
8 #undef DEBUG
9 #include <linux/sched.h>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/kallsyms.h>
13 #include <linux/notifier.h>
15 #include <asm/traps.h>
16 #include <asm/sysreg.h>
17 #include <asm/addrspace.h>
18 #include <asm/ocd.h>
19 #include <asm/mmu_context.h>
20 #include <asm/uaccess.h>
22 static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
24 unsigned long p;
25 int i;
27 printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
29 for (p = bottom & ~31; p < top; ) {
30 printk("%04lx: ", p & 0xffff);
32 for (i = 0; i < 8; i++, p += 4) {
33 unsigned int val;
35 if (p < bottom || p >= top)
36 printk(" ");
37 else {
38 if (__get_user(val, (unsigned int __user *)p)) {
39 printk("\n");
40 goto out;
42 printk("%08x ", val);
45 printk("\n");
48 out:
49 return;
52 #ifdef CONFIG_FRAME_POINTER
53 static inline void __show_trace(struct task_struct *tsk, unsigned long *sp,
54 struct pt_regs *regs)
56 unsigned long __user *fp;
57 unsigned long __user *last_fp = NULL;
59 if (regs) {
60 fp = (unsigned long __user *)regs->r7;
61 } else if (tsk == current) {
62 register unsigned long __user *real_fp __asm__("r7");
63 fp = real_fp;
64 } else {
65 fp = (unsigned long __user *)tsk->thread.cpu_context.r7;
69 * Walk the stack until (a) we get an exception, (b) the frame
70 * pointer becomes zero, or (c) the frame pointer gets stuck
71 * at the same value.
73 while (fp && fp != last_fp) {
74 unsigned long lr, new_fp = 0;
76 last_fp = fp;
77 if (__get_user(lr, fp))
78 break;
79 if (fp && __get_user(new_fp, fp + 1))
80 break;
81 fp = (unsigned long __user *)new_fp;
83 printk(" [<%08lx>] ", lr);
84 print_symbol("%s\n", lr);
86 printk("\n");
88 #else
89 static inline void __show_trace(struct task_struct *tsk, unsigned long *sp,
90 struct pt_regs *regs)
92 unsigned long addr;
94 while (!kstack_end(sp)) {
95 addr = *sp++;
96 if (kernel_text_address(addr)) {
97 printk(" [<%08lx>] ", addr);
98 print_symbol("%s\n", addr);
102 #endif
104 void show_trace(struct task_struct *tsk, unsigned long *sp,
105 struct pt_regs *regs)
107 if (regs &&
108 (((regs->sr & MODE_MASK) == MODE_EXCEPTION) ||
109 ((regs->sr & MODE_MASK) == MODE_USER)))
110 return;
112 printk ("Call trace:");
113 #ifdef CONFIG_KALLSYMS
114 printk("\n");
115 #endif
117 __show_trace(tsk, sp, regs);
118 printk("\n");
121 void show_stack(struct task_struct *tsk, unsigned long *sp)
123 unsigned long stack;
125 if (!tsk)
126 tsk = current;
127 if (sp == 0) {
128 if (tsk == current) {
129 register unsigned long *real_sp __asm__("sp");
130 sp = real_sp;
131 } else {
132 sp = (unsigned long *)tsk->thread.cpu_context.ksp;
136 stack = (unsigned long)sp;
137 dump_mem("Stack: ", stack,
138 THREAD_SIZE + (unsigned long)tsk->thread_info);
139 show_trace(tsk, sp, NULL);
142 void dump_stack(void)
144 show_stack(NULL, NULL);
146 EXPORT_SYMBOL(dump_stack);
148 ATOMIC_NOTIFIER_HEAD(avr32_die_chain);
150 int register_die_notifier(struct notifier_block *nb)
152 pr_debug("register_die_notifier: %p\n", nb);
154 return atomic_notifier_chain_register(&avr32_die_chain, nb);
156 EXPORT_SYMBOL(register_die_notifier);
158 int unregister_die_notifier(struct notifier_block *nb)
160 return atomic_notifier_chain_unregister(&avr32_die_chain, nb);
162 EXPORT_SYMBOL(unregister_die_notifier);
164 static DEFINE_SPINLOCK(die_lock);
166 void __die(const char *str, struct pt_regs *regs, unsigned long err,
167 const char *file, const char *func, unsigned long line)
169 struct task_struct *tsk = current;
170 static int die_counter;
172 console_verbose();
173 spin_lock_irq(&die_lock);
174 bust_spinlocks(1);
176 printk(KERN_ALERT "%s", str);
177 if (file && func)
178 printk(" in %s:%s, line %ld", file, func, line);
179 printk("[#%d]:\n", ++die_counter);
180 print_modules();
181 show_regs(regs);
182 printk("Process %s (pid: %d, stack limit = 0x%p)\n",
183 tsk->comm, tsk->pid, tsk->thread_info + 1);
185 if (!user_mode(regs) || in_interrupt()) {
186 dump_mem("Stack: ", regs->sp,
187 THREAD_SIZE + (unsigned long)tsk->thread_info);
190 bust_spinlocks(0);
191 spin_unlock_irq(&die_lock);
192 do_exit(SIGSEGV);
195 void __die_if_kernel(const char *str, struct pt_regs *regs, unsigned long err,
196 const char *file, const char *func, unsigned long line)
198 if (!user_mode(regs))
199 __die(str, regs, err, file, func, line);
202 asmlinkage void do_nmi(unsigned long ecr, struct pt_regs *regs)
204 #ifdef CONFIG_SUBARCH_AVR32B
206 * The exception entry always saves RSR_EX. For NMI, this is
207 * wrong; it should be RSR_NMI
209 regs->sr = sysreg_read(RSR_NMI);
210 #endif
212 printk("NMI taken!!!!\n");
213 die("NMI", regs, ecr);
214 BUG();
217 asmlinkage void do_critical_exception(unsigned long ecr, struct pt_regs *regs)
219 printk("Unable to handle critical exception %lu at pc = %08lx!\n",
220 ecr, regs->pc);
221 die("Oops", regs, ecr);
222 BUG();
225 asmlinkage void do_address_exception(unsigned long ecr, struct pt_regs *regs)
227 siginfo_t info;
229 die_if_kernel("Oops: Address exception in kernel mode", regs, ecr);
231 #ifdef DEBUG
232 if (ecr == ECR_ADDR_ALIGN_X)
233 pr_debug("Instruction Address Exception at pc = %08lx\n",
234 regs->pc);
235 else if (ecr == ECR_ADDR_ALIGN_R)
236 pr_debug("Data Address Exception (Read) at pc = %08lx\n",
237 regs->pc);
238 else if (ecr == ECR_ADDR_ALIGN_W)
239 pr_debug("Data Address Exception (Write) at pc = %08lx\n",
240 regs->pc);
241 else
242 BUG();
244 show_regs(regs);
245 #endif
247 info.si_signo = SIGBUS;
248 info.si_errno = 0;
249 info.si_code = BUS_ADRALN;
250 info.si_addr = (void __user *)regs->pc;
252 force_sig_info(SIGBUS, &info, current);
255 /* This way of handling undefined instructions is stolen from ARM */
256 static LIST_HEAD(undef_hook);
257 static spinlock_t undef_lock = SPIN_LOCK_UNLOCKED;
259 void register_undef_hook(struct undef_hook *hook)
261 spin_lock_irq(&undef_lock);
262 list_add(&hook->node, &undef_hook);
263 spin_unlock_irq(&undef_lock);
266 void unregister_undef_hook(struct undef_hook *hook)
268 spin_lock_irq(&undef_lock);
269 list_del(&hook->node);
270 spin_unlock_irq(&undef_lock);
273 static int do_cop_absent(u32 insn)
275 int cop_nr;
276 u32 cpucr;
277 if ( (insn & 0xfdf00000) == 0xf1900000 )
278 /* LDC0 */
279 cop_nr = 0;
280 else
281 cop_nr = (insn >> 13) & 0x7;
283 /* Try enabling the coprocessor */
284 cpucr = sysreg_read(CPUCR);
285 cpucr |= (1 << (24 + cop_nr));
286 sysreg_write(CPUCR, cpucr);
288 cpucr = sysreg_read(CPUCR);
289 if ( !(cpucr & (1 << (24 + cop_nr))) ){
290 printk("Coprocessor #%i not found!\n", cop_nr);
291 return -1;
294 return 0;
297 #ifdef CONFIG_BUG
298 #ifdef CONFIG_DEBUG_BUGVERBOSE
299 static inline void do_bug_verbose(struct pt_regs *regs, u32 insn)
301 char *file;
302 u16 line;
303 char c;
305 if (__get_user(line, (u16 __user *)(regs->pc + 2)))
306 return;
307 if (__get_user(file, (char * __user *)(regs->pc + 4))
308 || (unsigned long)file < PAGE_OFFSET
309 || __get_user(c, file))
310 file = "<bad filename>";
312 printk(KERN_ALERT "kernel BUG at %s:%d!\n", file, line);
314 #else
315 static inline void do_bug_verbose(struct pt_regs *regs, u32 insn)
319 #endif
320 #endif
322 asmlinkage void do_illegal_opcode(unsigned long ecr, struct pt_regs *regs)
324 u32 insn;
325 struct undef_hook *hook;
326 siginfo_t info;
327 void __user *pc;
329 if (!user_mode(regs))
330 goto kernel_trap;
332 local_irq_enable();
334 pc = (void __user *)instruction_pointer(regs);
335 if (__get_user(insn, (u32 __user *)pc))
336 goto invalid_area;
338 if (ecr == ECR_COPROC_ABSENT) {
339 if (do_cop_absent(insn) == 0)
340 return;
343 spin_lock_irq(&undef_lock);
344 list_for_each_entry(hook, &undef_hook, node) {
345 if ((insn & hook->insn_mask) == hook->insn_val) {
346 if (hook->fn(regs, insn) == 0) {
347 spin_unlock_irq(&undef_lock);
348 return;
352 spin_unlock_irq(&undef_lock);
354 invalid_area:
356 #ifdef DEBUG
357 printk("Illegal instruction at pc = %08lx\n", regs->pc);
358 if (regs->pc < TASK_SIZE) {
359 unsigned long ptbr, pgd, pte, *p;
361 ptbr = sysreg_read(PTBR);
362 p = (unsigned long *)ptbr;
363 pgd = p[regs->pc >> 22];
364 p = (unsigned long *)((pgd & 0x1ffff000) | 0x80000000);
365 pte = p[(regs->pc >> 12) & 0x3ff];
366 printk("page table: 0x%08lx -> 0x%08lx -> 0x%08lx\n", ptbr, pgd, pte);
368 #endif
370 info.si_signo = SIGILL;
371 info.si_errno = 0;
372 info.si_addr = (void __user *)regs->pc;
373 switch (ecr) {
374 case ECR_ILLEGAL_OPCODE:
375 case ECR_UNIMPL_INSTRUCTION:
376 info.si_code = ILL_ILLOPC;
377 break;
378 case ECR_PRIVILEGE_VIOLATION:
379 info.si_code = ILL_PRVOPC;
380 break;
381 case ECR_COPROC_ABSENT:
382 info.si_code = ILL_COPROC;
383 break;
384 default:
385 BUG();
388 force_sig_info(SIGILL, &info, current);
389 return;
391 kernel_trap:
392 #ifdef CONFIG_BUG
393 if (__kernel_text_address(instruction_pointer(regs))) {
394 insn = *(u16 *)instruction_pointer(regs);
395 if (insn == AVR32_BUG_OPCODE) {
396 do_bug_verbose(regs, insn);
397 die("Kernel BUG", regs, 0);
398 return;
401 #endif
403 die("Oops: Illegal instruction in kernel code", regs, ecr);
406 asmlinkage void do_fpe(unsigned long ecr, struct pt_regs *regs)
408 siginfo_t info;
410 printk("Floating-point exception at pc = %08lx\n", regs->pc);
412 /* We have no FPU... */
413 info.si_signo = SIGILL;
414 info.si_errno = 0;
415 info.si_addr = (void __user *)regs->pc;
416 info.si_code = ILL_COPROC;
418 force_sig_info(SIGILL, &info, current);
422 void __init trap_init(void)