2 * Kernel traps/events for Hexagon processor
4 * Copyright (c) 2010-2011, The Linux Foundation. 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
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>
36 # include <linux/kgdb.h>
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)
52 #endif /* CONFIG_GENERIC_BUG */
54 static const char *ex_name(int ex)
59 return "Execute protection fault";
62 return "Read protection fault";
65 return "Write protection fault";
67 return "Misaligned instruction";
69 return "Multiple writes to same register in packet";
71 return "Program counter values that are not properly aligned";
73 return "Misaligned data load";
75 return "Misaligned data store";
78 return "Illegal instruction";
80 return "Precise bus error";
85 return "Debugger trap";
88 return "Unrecognized exception";
92 static void do_show_stack(struct task_struct *task, unsigned long *fp,
95 int kstack_depth_to_print = 24;
96 unsigned long offset, size;
97 const char *name = NULL;
99 unsigned long low, high;
107 printk(KERN_INFO "CPU#%d, %s/%d, Call Trace:\n",
108 raw_smp_processor_id(), task->comm,
112 if (task == current) {
113 asm("%0 = r30" : "=r" (fp));
115 fp = (unsigned long *)
116 ((struct hexagon_switch_stack *)
117 task->thread.switch_sp)->fp;
121 if ((((unsigned long) fp) & 0x3) || ((unsigned long) fp < 0x1000)) {
122 printk(KERN_INFO "-- Corrupt frame pointer %p\n", fp);
126 /* Saved link reg is one word above FP */
130 /* Expect kernel stack to be in-bounds */
131 low = (unsigned long)task_stack_page(task);
132 high = low + THREAD_SIZE - 8;
133 low += sizeof(struct thread_info);
135 for (i = 0; i < kstack_depth_to_print; i++) {
137 name = kallsyms_lookup(ip, &size, &offset, &modname, tmpstr);
139 printk(KERN_INFO "[%p] 0x%lx: %s + 0x%lx", fp, ip, name,
141 if (((unsigned long) fp < low) || (high < (unsigned long) fp))
142 printk(KERN_CONT " (FP out of bounds!)");
144 printk(KERN_CONT " [%s] ", modname);
145 printk(KERN_CONT "\n");
147 newfp = (unsigned long *) *fp;
149 if (((unsigned long) newfp) & 0x3) {
150 printk(KERN_INFO "-- Corrupt frame pointer %p\n",
155 /* Attempt to continue past exception. */
157 struct pt_regs *regs = (struct pt_regs *) (((void *)fp)
160 if (regs->syscall_nr != -1) {
161 printk(KERN_INFO "-- trap0 -- syscall_nr: %ld",
163 printk(KERN_CONT " psp: %lx elr: %lx\n",
164 pt_psp(regs), pt_elr(regs));
167 /* really want to see more ... */
168 kstack_depth_to_print += 6;
169 printk(KERN_INFO "-- %s (0x%lx) badva: %lx\n",
170 ex_name(pt_cause(regs)), pt_cause(regs),
174 newfp = (unsigned long *) regs->r30;
180 /* If link reg is null, we are done. */
184 /* If newfp isn't larger, we're tracing garbage. */
192 void show_stack(struct task_struct *task, unsigned long *fp)
194 /* Saved link reg is one word above FP */
195 do_show_stack(task, fp, 0);
198 void dump_stack(void)
201 asm("%0 = r30" : "=r" (fp));
202 show_stack(current, fp);
204 EXPORT_SYMBOL(dump_stack);
206 int die(const char *str, struct pt_regs *regs, long err)
212 .lock = __SPIN_LOCK_UNLOCKED(die.lock),
219 spin_lock_irq(&die.lock);
221 printk(KERN_EMERG "Oops: %s[#%d]:\n", str, ++die.counter);
223 if (notify_die(DIE_OOPS, str, regs, err, pt_cause(regs), SIGSEGV) ==
229 do_show_stack(current, ®s->r30, pt_elr(regs));
232 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
234 spin_unlock_irq(&die.lock);
237 panic("Fatal exception in interrupt");
240 panic("Fatal exception");
247 int die_if_kernel(char *str, struct pt_regs *regs, long err)
249 if (!user_mode(regs))
250 return die(str, regs, err);
256 * It's not clear that misaligned fetches are ever recoverable.
258 static void misaligned_instruction(struct pt_regs *regs)
260 die_if_kernel("Misaligned Instruction", regs, 0);
261 force_sig(SIGBUS, current);
265 * Misaligned loads and stores, on the other hand, can be
266 * emulated, and probably should be, some day. But for now
267 * they will be considered fatal.
269 static void misaligned_data_load(struct pt_regs *regs)
271 die_if_kernel("Misaligned Data Load", regs, 0);
272 force_sig(SIGBUS, current);
275 static void misaligned_data_store(struct pt_regs *regs)
277 die_if_kernel("Misaligned Data Store", regs, 0);
278 force_sig(SIGBUS, current);
281 static void illegal_instruction(struct pt_regs *regs)
283 die_if_kernel("Illegal Instruction", regs, 0);
284 force_sig(SIGILL, current);
288 * Precise bus errors may be recoverable with a a retry,
289 * but for now, treat them as irrecoverable.
291 static void precise_bus_error(struct pt_regs *regs)
293 die_if_kernel("Precise Bus Error", regs, 0);
294 force_sig(SIGBUS, current);
298 * If anything is to be done here other than panic,
299 * it will probably be complex and migrate to another
300 * source module. For now, just die.
302 static void cache_error(struct pt_regs *regs)
304 die("Cache Error", regs, 0);
308 * General exception handler
310 void do_genex(struct pt_regs *regs)
313 * Decode Cause and Dispatch
315 switch (pt_cause(regs)) {
318 execute_protection_fault(regs);
322 read_protection_fault(regs);
326 write_protection_fault(regs);
329 misaligned_instruction(regs);
332 illegal_instruction(regs);
335 misaligned_instruction(regs);
338 misaligned_data_load(regs);
341 misaligned_data_store(regs);
345 illegal_instruction(regs);
348 precise_bus_error(regs);
354 /* Halt and catch fire */
355 panic("Unrecognized exception 0x%lx\n", pt_cause(regs));
360 /* Indirect system call dispatch */
361 long sys_syscall(void)
363 printk(KERN_ERR "sys_syscall invoked!\n");
367 void do_trap0(struct pt_regs *regs)
371 switch (pt_cause(regs)) {
373 /* System call is trap0 #1 */
375 /* allow strace to catch syscall args */
376 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE) &&
377 tracehook_report_syscall_entry(regs)))
378 return; /* return -ENOSYS somewhere? */
380 /* Interrupts should be re-enabled for syscall processing */
381 __vmsetie(VM_INT_ENABLE);
384 * System call number is in r6, arguments in r0..r5.
385 * Fortunately, no Linux syscall has more than 6 arguments,
386 * and Hexagon ABI passes first 6 arguments in registers.
387 * 64-bit arguments are passed in odd/even register pairs.
388 * Fortunately, we have no system calls that take more
389 * than three arguments with more than one 64-bit value.
390 * Should that change, we'd need to redesign to copy
391 * between user and kernel stacks.
393 regs->syscall_nr = regs->r06;
396 * GPR R0 carries the first parameter, and is also used
397 * to report the return value. We need a backup of
398 * the user's value in case we need to do a late restart
399 * of the system call.
401 regs->restart_r0 = regs->r00;
403 if ((unsigned long) regs->syscall_nr >= __NR_syscalls) {
406 syscall = (syscall_fn)
407 (sys_call_table[regs->syscall_nr]);
408 regs->r00 = syscall(regs->r00, regs->r01,
409 regs->r02, regs->r03,
410 regs->r04, regs->r05);
413 /* allow strace to get the syscall return state */
414 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE)))
415 tracehook_report_syscall_exit(regs, 0);
419 /* Trap0 0xdb is debug breakpoint */
420 if (user_mode(regs)) {
423 info.si_signo = SIGTRAP;
426 * Some architecures add some per-thread state
427 * to distinguish between breakpoint traps and
428 * trace traps. We may want to do that, and
429 * set the si_code value appropriately, or we
430 * may want to use a different trap0 flavor.
432 info.si_code = TRAP_BRKPT;
433 info.si_addr = (void __user *) pt_elr(regs);
434 send_sig_info(SIGTRAP, &info, current);
437 kgdb_handle_exception(pt_cause(regs), SIGTRAP,
443 /* Ignore other trap0 codes for now, especially 0 (Angel calls) */
447 * Machine check exception handler
449 void do_machcheck(struct pt_regs *regs)
451 /* Halt and catch fire */