staging: tidspbridge: remove cmm_init() and cmm_exit()
[linux-2.6.git] / arch / hexagon / kernel / traps.c
blobf08857d0715b87d3162d4fcd2fbadfad68df0e3b
1 /*
2 * Kernel traps/events for Hexagon processor
4 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
21 #include <linux/init.h>
22 #include <linux/sched.h>
23 #include <linux/module.h>
24 #include <linux/kallsyms.h>
25 #include <linux/kdebug.h>
26 #include <linux/syscalls.h>
27 #include <linux/signal.h>
28 #include <linux/tracehook.h>
29 #include <asm/traps.h>
30 #include <asm/vm_fault.h>
31 #include <asm/syscall.h>
32 #include <asm/registers.h>
33 #include <asm/unistd.h>
34 #include <asm/sections.h>
35 #ifdef CONFIG_KGDB
36 # include <linux/kgdb.h>
37 #endif
39 #define TRAP_SYSCALL 1
40 #define TRAP_DEBUG 0xdb
42 void __init trap_init(void)
46 #ifdef CONFIG_GENERIC_BUG
47 /* Maybe should resemble arch/sh/kernel/traps.c ?? */
48 int is_valid_bugaddr(unsigned long addr)
50 return 1;
52 #endif /* CONFIG_GENERIC_BUG */
54 static const char *ex_name(int ex)
56 switch (ex) {
57 case HVM_GE_C_XPROT:
58 case HVM_GE_C_XUSER:
59 return "Execute protection fault";
60 case HVM_GE_C_RPROT:
61 case HVM_GE_C_RUSER:
62 return "Read protection fault";
63 case HVM_GE_C_WPROT:
64 case HVM_GE_C_WUSER:
65 return "Write protection fault";
66 case HVM_GE_C_XMAL:
67 return "Misaligned instruction";
68 case HVM_GE_C_RMAL:
69 return "Misaligned data load";
70 case HVM_GE_C_WMAL:
71 return "Misaligned data store";
72 case HVM_GE_C_INVI:
73 case HVM_GE_C_PRIVI:
74 return "Illegal instruction";
75 case HVM_GE_C_BUS:
76 return "Precise bus error";
77 case HVM_GE_C_CACHE:
78 return "Cache error";
80 case 0xdb:
81 return "Debugger trap";
83 default:
84 return "Unrecognized exception";
88 static void do_show_stack(struct task_struct *task, unsigned long *fp,
89 unsigned long ip)
91 int kstack_depth_to_print = 24;
92 unsigned long offset, size;
93 const char *name = NULL;
94 unsigned long *newfp;
95 unsigned long low, high;
96 char tmpstr[128];
97 char *modname;
98 int i;
100 if (task == NULL)
101 task = current;
103 printk(KERN_INFO "CPU#%d, %s/%d, Call Trace:\n",
104 raw_smp_processor_id(), task->comm,
105 task_pid_nr(task));
107 if (fp == NULL) {
108 if (task == current) {
109 asm("%0 = r30" : "=r" (fp));
110 } else {
111 fp = (unsigned long *)
112 ((struct hexagon_switch_stack *)
113 task->thread.switch_sp)->fp;
117 if ((((unsigned long) fp) & 0x3) || ((unsigned long) fp < 0x1000)) {
118 printk(KERN_INFO "-- Corrupt frame pointer %p\n", fp);
119 return;
122 /* Saved link reg is one word above FP */
123 if (!ip)
124 ip = *(fp+1);
126 /* Expect kernel stack to be in-bounds */
127 low = (unsigned long)task_stack_page(task);
128 high = low + THREAD_SIZE - 8;
129 low += sizeof(struct thread_info);
131 for (i = 0; i < kstack_depth_to_print; i++) {
133 name = kallsyms_lookup(ip, &size, &offset, &modname, tmpstr);
135 printk(KERN_INFO "[%p] 0x%lx: %s + 0x%lx", fp, ip, name,
136 offset);
137 if (((unsigned long) fp < low) || (high < (unsigned long) fp))
138 printk(KERN_CONT " (FP out of bounds!)");
139 if (modname)
140 printk(KERN_CONT " [%s] ", modname);
141 printk(KERN_CONT "\n");
143 newfp = (unsigned long *) *fp;
145 if (((unsigned long) newfp) & 0x3) {
146 printk(KERN_INFO "-- Corrupt frame pointer %p\n",
147 newfp);
148 break;
151 /* Attempt to continue past exception. */
152 if (0 == newfp) {
153 struct pt_regs *regs = (struct pt_regs *) (((void *)fp)
154 + 8);
156 if (regs->syscall_nr != -1) {
157 printk(KERN_INFO "-- trap0 -- syscall_nr: %ld",
158 regs->syscall_nr);
159 printk(KERN_CONT " psp: %lx elr: %lx\n",
160 pt_psp(regs), pt_elr(regs));
161 break;
162 } else {
163 /* really want to see more ... */
164 kstack_depth_to_print += 6;
165 printk(KERN_INFO "-- %s (0x%lx) badva: %lx\n",
166 ex_name(pt_cause(regs)), pt_cause(regs),
167 pt_badva(regs));
170 newfp = (unsigned long *) regs->r30;
171 ip = pt_elr(regs);
172 } else {
173 ip = *(newfp + 1);
176 /* If link reg is null, we are done. */
177 if (ip == 0x0)
178 break;
180 /* If newfp isn't larger, we're tracing garbage. */
181 if (newfp > fp)
182 fp = newfp;
183 else
184 break;
188 void show_stack(struct task_struct *task, unsigned long *fp)
190 /* Saved link reg is one word above FP */
191 do_show_stack(task, fp, 0);
194 void dump_stack(void)
196 unsigned long *fp;
197 asm("%0 = r30" : "=r" (fp));
198 show_stack(current, fp);
200 EXPORT_SYMBOL(dump_stack);
202 int die(const char *str, struct pt_regs *regs, long err)
204 static struct {
205 spinlock_t lock;
206 int counter;
207 } die = {
208 .lock = __SPIN_LOCK_UNLOCKED(die.lock),
209 .counter = 0
212 console_verbose();
213 oops_enter();
215 spin_lock_irq(&die.lock);
216 bust_spinlocks(1);
217 printk(KERN_EMERG "Oops: %s[#%d]:\n", str, ++die.counter);
219 if (notify_die(DIE_OOPS, str, regs, err, pt_cause(regs), SIGSEGV) ==
220 NOTIFY_STOP)
221 return 1;
223 print_modules();
224 show_regs(regs);
225 do_show_stack(current, &regs->r30, pt_elr(regs));
227 bust_spinlocks(0);
228 add_taint(TAINT_DIE);
230 spin_unlock_irq(&die.lock);
232 if (in_interrupt())
233 panic("Fatal exception in interrupt");
235 if (panic_on_oops)
236 panic("Fatal exception");
238 oops_exit();
239 do_exit(err);
240 return 0;
243 int die_if_kernel(char *str, struct pt_regs *regs, long err)
245 if (!user_mode(regs))
246 return die(str, regs, err);
247 else
248 return 0;
252 * It's not clear that misaligned fetches are ever recoverable.
254 static void misaligned_instruction(struct pt_regs *regs)
256 die_if_kernel("Misaligned Instruction", regs, 0);
257 force_sig(SIGBUS, current);
261 * Misaligned loads and stores, on the other hand, can be
262 * emulated, and probably should be, some day. But for now
263 * they will be considered fatal.
265 static void misaligned_data_load(struct pt_regs *regs)
267 die_if_kernel("Misaligned Data Load", regs, 0);
268 force_sig(SIGBUS, current);
271 static void misaligned_data_store(struct pt_regs *regs)
273 die_if_kernel("Misaligned Data Store", regs, 0);
274 force_sig(SIGBUS, current);
277 static void illegal_instruction(struct pt_regs *regs)
279 die_if_kernel("Illegal Instruction", regs, 0);
280 force_sig(SIGILL, current);
284 * Precise bus errors may be recoverable with a a retry,
285 * but for now, treat them as irrecoverable.
287 static void precise_bus_error(struct pt_regs *regs)
289 die_if_kernel("Precise Bus Error", regs, 0);
290 force_sig(SIGBUS, current);
294 * If anything is to be done here other than panic,
295 * it will probably be complex and migrate to another
296 * source module. For now, just die.
298 static void cache_error(struct pt_regs *regs)
300 die("Cache Error", regs, 0);
304 * General exception handler
306 void do_genex(struct pt_regs *regs)
309 * Decode Cause and Dispatch
311 switch (pt_cause(regs)) {
312 case HVM_GE_C_XPROT:
313 case HVM_GE_C_XUSER:
314 execute_protection_fault(regs);
315 break;
316 case HVM_GE_C_RPROT:
317 case HVM_GE_C_RUSER:
318 read_protection_fault(regs);
319 break;
320 case HVM_GE_C_WPROT:
321 case HVM_GE_C_WUSER:
322 write_protection_fault(regs);
323 break;
324 case HVM_GE_C_XMAL:
325 misaligned_instruction(regs);
326 break;
327 case HVM_GE_C_RMAL:
328 misaligned_data_load(regs);
329 break;
330 case HVM_GE_C_WMAL:
331 misaligned_data_store(regs);
332 break;
333 case HVM_GE_C_INVI:
334 case HVM_GE_C_PRIVI:
335 illegal_instruction(regs);
336 break;
337 case HVM_GE_C_BUS:
338 precise_bus_error(regs);
339 break;
340 case HVM_GE_C_CACHE:
341 cache_error(regs);
342 break;
343 default:
344 /* Halt and catch fire */
345 panic("Unrecognized exception 0x%lx\n", pt_cause(regs));
346 break;
350 /* Indirect system call dispatch */
351 long sys_syscall(void)
353 printk(KERN_ERR "sys_syscall invoked!\n");
354 return -ENOSYS;
357 void do_trap0(struct pt_regs *regs)
359 unsigned long syscallret = 0;
360 syscall_fn syscall;
362 switch (pt_cause(regs)) {
363 case TRAP_SYSCALL:
364 /* System call is trap0 #1 */
366 /* allow strace to catch syscall args */
367 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE) &&
368 tracehook_report_syscall_entry(regs)))
369 return; /* return -ENOSYS somewhere? */
371 /* Interrupts should be re-enabled for syscall processing */
372 __vmsetie(VM_INT_ENABLE);
375 * System call number is in r6, arguments in r0..r5.
376 * Fortunately, no Linux syscall has more than 6 arguments,
377 * and Hexagon ABI passes first 6 arguments in registers.
378 * 64-bit arguments are passed in odd/even register pairs.
379 * Fortunately, we have no system calls that take more
380 * than three arguments with more than one 64-bit value.
381 * Should that change, we'd need to redesign to copy
382 * between user and kernel stacks.
384 regs->syscall_nr = regs->r06;
387 * GPR R0 carries the first parameter, and is also used
388 * to report the return value. We need a backup of
389 * the user's value in case we need to do a late restart
390 * of the system call.
392 regs->restart_r0 = regs->r00;
394 if ((unsigned long) regs->syscall_nr >= __NR_syscalls) {
395 regs->r00 = -1;
396 } else {
397 syscall = (syscall_fn)
398 (sys_call_table[regs->syscall_nr]);
399 syscallret = syscall(regs->r00, regs->r01,
400 regs->r02, regs->r03,
401 regs->r04, regs->r05);
405 * If it was a sigreturn system call, don't overwrite
406 * r0 value in stack frame with return value.
408 * __NR_sigreturn doesn't seem to exist in new unistd.h
411 if (regs->syscall_nr != __NR_rt_sigreturn)
412 regs->r00 = syscallret;
414 /* allow strace to get the syscall return state */
415 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE)))
416 tracehook_report_syscall_exit(regs, 0);
418 break;
419 case TRAP_DEBUG:
420 /* Trap0 0xdb is debug breakpoint */
421 if (user_mode(regs)) {
422 struct siginfo info;
424 info.si_signo = SIGTRAP;
425 info.si_errno = 0;
427 * Some architecures add some per-thread state
428 * to distinguish between breakpoint traps and
429 * trace traps. We may want to do that, and
430 * set the si_code value appropriately, or we
431 * may want to use a different trap0 flavor.
433 info.si_code = TRAP_BRKPT;
434 info.si_addr = (void __user *) pt_elr(regs);
435 send_sig_info(SIGTRAP, &info, current);
436 } else {
437 #ifdef CONFIG_KGDB
438 kgdb_handle_exception(pt_cause(regs), SIGTRAP,
439 TRAP_BRKPT, regs);
440 #endif
442 break;
444 /* Ignore other trap0 codes for now, especially 0 (Angel calls) */
448 * Machine check exception handler
450 void do_machcheck(struct pt_regs *regs)
452 /* Halt and catch fire */
453 __vmstop();