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
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 "Misaligned data load";
71 return "Misaligned data store";
74 return "Illegal instruction";
76 return "Precise bus error";
81 return "Debugger trap";
84 return "Unrecognized exception";
88 static void do_show_stack(struct task_struct
*task
, unsigned long *fp
,
91 int kstack_depth_to_print
= 24;
92 unsigned long offset
, size
;
93 const char *name
= NULL
;
95 unsigned long low
, high
;
103 printk(KERN_INFO
"CPU#%d, %s/%d, Call Trace:\n",
104 raw_smp_processor_id(), task
->comm
,
108 if (task
== current
) {
109 asm("%0 = r30" : "=r" (fp
));
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
);
122 /* Saved link reg is one word above FP */
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
,
137 if (((unsigned long) fp
< low
) || (high
< (unsigned long) fp
))
138 printk(KERN_CONT
" (FP out of bounds!)");
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",
151 /* Attempt to continue past exception. */
153 struct pt_regs
*regs
= (struct pt_regs
*) (((void *)fp
)
156 if (regs
->syscall_nr
!= -1) {
157 printk(KERN_INFO
"-- trap0 -- syscall_nr: %ld",
159 printk(KERN_CONT
" psp: %lx elr: %lx\n",
160 pt_psp(regs
), pt_elr(regs
));
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
),
170 newfp
= (unsigned long *) regs
->r30
;
176 /* If link reg is null, we are done. */
180 /* If newfp isn't larger, we're tracing garbage. */
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)
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
)
208 .lock
= __SPIN_LOCK_UNLOCKED(die
.lock
),
215 spin_lock_irq(&die
.lock
);
217 printk(KERN_EMERG
"Oops: %s[#%d]:\n", str
, ++die
.counter
);
219 if (notify_die(DIE_OOPS
, str
, regs
, err
, pt_cause(regs
), SIGSEGV
) ==
225 do_show_stack(current
, ®s
->r30
, pt_elr(regs
));
228 add_taint(TAINT_DIE
);
230 spin_unlock_irq(&die
.lock
);
233 panic("Fatal exception in interrupt");
236 panic("Fatal exception");
243 int die_if_kernel(char *str
, struct pt_regs
*regs
, long err
)
245 if (!user_mode(regs
))
246 return die(str
, regs
, err
);
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
)) {
314 execute_protection_fault(regs
);
318 read_protection_fault(regs
);
322 write_protection_fault(regs
);
325 misaligned_instruction(regs
);
328 misaligned_data_load(regs
);
331 misaligned_data_store(regs
);
335 illegal_instruction(regs
);
338 precise_bus_error(regs
);
344 /* Halt and catch fire */
345 panic("Unrecognized exception 0x%lx\n", pt_cause(regs
));
350 /* Indirect system call dispatch */
351 long sys_syscall(void)
353 printk(KERN_ERR
"sys_syscall invoked!\n");
357 void do_trap0(struct pt_regs
*regs
)
359 unsigned long syscallret
= 0;
362 switch (pt_cause(regs
)) {
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
) {
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);
420 /* Trap0 0xdb is debug breakpoint */
421 if (user_mode(regs
)) {
424 info
.si_signo
= SIGTRAP
;
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
);
438 kgdb_handle_exception(pt_cause(regs
), SIGTRAP
,
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 */