2 * Kernel traps/events for Hexagon processor
4 * Copyright (c) 2010-2013, 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 int die(const char *str
, struct pt_regs
*regs
, long err
)
204 .lock
= __SPIN_LOCK_UNLOCKED(die
.lock
),
211 spin_lock_irq(&die
.lock
);
213 printk(KERN_EMERG
"Oops: %s[#%d]:\n", str
, ++die
.counter
);
215 if (notify_die(DIE_OOPS
, str
, regs
, err
, pt_cause(regs
), SIGSEGV
) ==
221 do_show_stack(current
, ®s
->r30
, pt_elr(regs
));
224 add_taint(TAINT_DIE
, LOCKDEP_NOW_UNRELIABLE
);
226 spin_unlock_irq(&die
.lock
);
229 panic("Fatal exception in interrupt");
232 panic("Fatal exception");
239 int die_if_kernel(char *str
, struct pt_regs
*regs
, long err
)
241 if (!user_mode(regs
))
242 return die(str
, regs
, err
);
248 * It's not clear that misaligned fetches are ever recoverable.
250 static void misaligned_instruction(struct pt_regs
*regs
)
252 die_if_kernel("Misaligned Instruction", regs
, 0);
253 force_sig(SIGBUS
, current
);
257 * Misaligned loads and stores, on the other hand, can be
258 * emulated, and probably should be, some day. But for now
259 * they will be considered fatal.
261 static void misaligned_data_load(struct pt_regs
*regs
)
263 die_if_kernel("Misaligned Data Load", regs
, 0);
264 force_sig(SIGBUS
, current
);
267 static void misaligned_data_store(struct pt_regs
*regs
)
269 die_if_kernel("Misaligned Data Store", regs
, 0);
270 force_sig(SIGBUS
, current
);
273 static void illegal_instruction(struct pt_regs
*regs
)
275 die_if_kernel("Illegal Instruction", regs
, 0);
276 force_sig(SIGILL
, current
);
280 * Precise bus errors may be recoverable with a a retry,
281 * but for now, treat them as irrecoverable.
283 static void precise_bus_error(struct pt_regs
*regs
)
285 die_if_kernel("Precise Bus Error", regs
, 0);
286 force_sig(SIGBUS
, current
);
290 * If anything is to be done here other than panic,
291 * it will probably be complex and migrate to another
292 * source module. For now, just die.
294 static void cache_error(struct pt_regs
*regs
)
296 die("Cache Error", regs
, 0);
300 * General exception handler
302 void do_genex(struct pt_regs
*regs
)
305 * Decode Cause and Dispatch
307 switch (pt_cause(regs
)) {
310 execute_protection_fault(regs
);
314 read_protection_fault(regs
);
318 write_protection_fault(regs
);
321 misaligned_instruction(regs
);
324 illegal_instruction(regs
);
327 misaligned_instruction(regs
);
330 misaligned_data_load(regs
);
333 misaligned_data_store(regs
);
337 illegal_instruction(regs
);
340 precise_bus_error(regs
);
346 /* Halt and catch fire */
347 panic("Unrecognized exception 0x%lx\n", pt_cause(regs
));
352 /* Indirect system call dispatch */
353 long sys_syscall(void)
355 printk(KERN_ERR
"sys_syscall invoked!\n");
359 void do_trap0(struct pt_regs
*regs
)
363 switch (pt_cause(regs
)) {
365 /* System call is trap0 #1 */
367 /* allow strace to catch syscall args */
368 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE
) &&
369 tracehook_report_syscall_entry(regs
)))
370 return; /* return -ENOSYS somewhere? */
372 /* Interrupts should be re-enabled for syscall processing */
373 __vmsetie(VM_INT_ENABLE
);
376 * System call number is in r6, arguments in r0..r5.
377 * Fortunately, no Linux syscall has more than 6 arguments,
378 * and Hexagon ABI passes first 6 arguments in registers.
379 * 64-bit arguments are passed in odd/even register pairs.
380 * Fortunately, we have no system calls that take more
381 * than three arguments with more than one 64-bit value.
382 * Should that change, we'd need to redesign to copy
383 * between user and kernel stacks.
385 regs
->syscall_nr
= regs
->r06
;
388 * GPR R0 carries the first parameter, and is also used
389 * to report the return value. We need a backup of
390 * the user's value in case we need to do a late restart
391 * of the system call.
393 regs
->restart_r0
= regs
->r00
;
395 if ((unsigned long) regs
->syscall_nr
>= __NR_syscalls
) {
398 syscall
= (syscall_fn
)
399 (sys_call_table
[regs
->syscall_nr
]);
400 regs
->r00
= syscall(regs
->r00
, regs
->r01
,
401 regs
->r02
, regs
->r03
,
402 regs
->r04
, regs
->r05
);
405 /* allow strace to get the syscall return state */
406 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACE
)))
407 tracehook_report_syscall_exit(regs
, 0);
411 /* Trap0 0xdb is debug breakpoint */
412 if (user_mode(regs
)) {
415 info
.si_signo
= SIGTRAP
;
418 * Some architecures add some per-thread state
419 * to distinguish between breakpoint traps and
420 * trace traps. We may want to do that, and
421 * set the si_code value appropriately, or we
422 * may want to use a different trap0 flavor.
424 info
.si_code
= TRAP_BRKPT
;
425 info
.si_addr
= (void __user
*) pt_elr(regs
);
426 send_sig_info(SIGTRAP
, &info
, current
);
429 kgdb_handle_exception(pt_cause(regs
), SIGTRAP
,
435 /* Ignore other trap0 codes for now, especially 0 (Angel calls) */
439 * Machine check exception handler
441 void do_machcheck(struct pt_regs
*regs
)
443 /* Halt and catch fire */
448 * Treat this like the old 0xdb trap.
451 void do_debug_exception(struct pt_regs
*regs
)
453 regs
->hvmer
.vmest
&= ~HVM_VMEST_CAUSE_MSK
;
454 regs
->hvmer
.vmest
|= (TRAP_DEBUG
<< HVM_VMEST_CAUSE_SFT
);