1 /* traps.c: high-level exception handler for FR-V
3 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/sched.h>
13 #include <linux/signal.h>
14 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/user.h>
18 #include <linux/string.h>
19 #include <linux/linkage.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
23 #include <asm/asm-offsets.h>
24 #include <asm/setup.h>
26 #include <asm/uaccess.h>
27 #include <asm/pgtable.h>
28 #include <asm/siginfo.h>
29 #include <asm/unaligned.h>
31 void show_backtrace(struct pt_regs
*, unsigned long);
33 extern asmlinkage
void __break_hijack_kernel_event(void);
35 /*****************************************************************************/
37 * instruction access error
39 asmlinkage
void insn_access_error(unsigned long esfr1
, unsigned long epcr0
, unsigned long esr0
)
43 die_if_kernel("-- Insn Access Error --\n"
48 info
.si_signo
= SIGSEGV
;
49 info
.si_code
= SEGV_ACCERR
;
51 info
.si_addr
= (void __user
*) ((epcr0
& EPCR0_V
) ? (epcr0
& EPCR0_PC
) : __frame
->pc
);
53 force_sig_info(info
.si_signo
, &info
, current
);
54 } /* end insn_access_error() */
56 /*****************************************************************************/
59 * - illegal instruction
60 * - privileged instruction
64 asmlinkage
void illegal_instruction(unsigned long esfr1
, unsigned long epcr0
, unsigned long esr0
)
68 die_if_kernel("-- Illegal Instruction --\n"
75 info
.si_addr
= (void __user
*) ((epcr0
& EPCR0_V
) ? (epcr0
& EPCR0_PC
) : __frame
->pc
);
77 switch (__frame
->tbr
& TBR_TT
) {
78 case TBR_TT_ILLEGAL_INSTR
:
79 info
.si_signo
= SIGILL
;
80 info
.si_code
= ILL_ILLOPC
;
82 case TBR_TT_PRIV_INSTR
:
83 info
.si_signo
= SIGILL
;
84 info
.si_code
= ILL_PRVOPC
;
86 case TBR_TT_TRAP2
... TBR_TT_TRAP126
:
87 info
.si_signo
= SIGILL
;
88 info
.si_code
= ILL_ILLTRP
;
90 /* GDB uses "tira gr0, #1" as a breakpoint instruction. */
93 info
.si_signo
= SIGTRAP
;
95 (__frame
->__status
& REG__STATUS_STEPPED
) ? TRAP_TRACE
: TRAP_BRKPT
;
99 force_sig_info(info
.si_signo
, &info
, current
);
100 } /* end illegal_instruction() */
102 /*****************************************************************************/
104 * handle atomic operations with errors
105 * - arguments in gr8, gr9, gr10
106 * - original memory value placed in gr5
107 * - replacement memory value placed in gr9
109 asmlinkage
void atomic_operation(unsigned long esfr1
, unsigned long epcr0
,
112 static DEFINE_SPINLOCK(atomic_op_lock
);
113 unsigned long x
, y
, z
;
114 unsigned long __user
*p
;
123 if (!user_mode(__frame
))
126 switch (__frame
->tbr
& TBR_TT
) {
128 * u32 __atomic_user_cmpxchg32(u32 *ptr, u32 test, u32 new)
130 case TBR_TT_ATOMIC_CMPXCHG32
:
131 p
= (unsigned long __user
*) __frame
->gr8
;
136 ret
= get_user(z
, p
);
143 spin_lock_irq(&atomic_op_lock
);
145 if (__get_user(z
, p
) == 0) {
149 if (__put_user(y
, p
) == 0)
154 spin_unlock_irq(&atomic_op_lock
);
158 * u32 __atomic_kernel_xchg32(void *v, u32 new)
160 case TBR_TT_ATOMIC_XCHG32
:
161 p
= (unsigned long __user
*) __frame
->gr8
;
165 ret
= get_user(z
, p
);
169 spin_lock_irq(&atomic_op_lock
);
171 if (__get_user(z
, p
) == 0) {
172 if (__put_user(y
, p
) == 0)
177 spin_unlock_irq(&atomic_op_lock
);
181 * ulong __atomic_kernel_XOR_return(ulong i, ulong *v)
183 case TBR_TT_ATOMIC_XOR
:
184 p
= (unsigned long __user
*) __frame
->gr8
;
188 ret
= get_user(z
, p
);
192 spin_lock_irq(&atomic_op_lock
);
194 if (__get_user(z
, p
) == 0) {
196 if (__put_user(y
, p
) == 0)
201 spin_unlock_irq(&atomic_op_lock
);
205 * ulong __atomic_kernel_OR_return(ulong i, ulong *v)
207 case TBR_TT_ATOMIC_OR
:
208 p
= (unsigned long __user
*) __frame
->gr8
;
212 ret
= get_user(z
, p
);
216 spin_lock_irq(&atomic_op_lock
);
218 if (__get_user(z
, p
) == 0) {
220 if (__put_user(y
, p
) == 0)
225 spin_unlock_irq(&atomic_op_lock
);
229 * ulong __atomic_kernel_AND_return(ulong i, ulong *v)
231 case TBR_TT_ATOMIC_AND
:
232 p
= (unsigned long __user
*) __frame
->gr8
;
236 ret
= get_user(z
, p
);
240 spin_lock_irq(&atomic_op_lock
);
242 if (__get_user(z
, p
) == 0) {
244 if (__put_user(y
, p
) == 0)
249 spin_unlock_irq(&atomic_op_lock
);
253 * int __atomic_user_sub_return(atomic_t *v, int i)
255 case TBR_TT_ATOMIC_SUB
:
256 p
= (unsigned long __user
*) __frame
->gr8
;
260 ret
= get_user(z
, p
);
264 spin_lock_irq(&atomic_op_lock
);
266 if (__get_user(z
, p
) == 0) {
268 if (__put_user(y
, p
) == 0)
273 spin_unlock_irq(&atomic_op_lock
);
277 * int __atomic_user_add_return(atomic_t *v, int i)
279 case TBR_TT_ATOMIC_ADD
:
280 p
= (unsigned long __user
*) __frame
->gr8
;
284 ret
= get_user(z
, p
);
288 spin_lock_irq(&atomic_op_lock
);
290 if (__get_user(z
, p
) == 0) {
292 if (__put_user(y
, p
) == 0)
297 spin_unlock_irq(&atomic_op_lock
);
305 spin_unlock_irq(&atomic_op_lock
);
307 if (!user_mode(__frame
))
314 spin_unlock_irq(&atomic_op_lock
);
316 if (!user_mode(__frame
))
320 die_if_kernel("-- Atomic Op Error --\n");
322 info
.si_signo
= SIGSEGV
;
323 info
.si_code
= SEGV_ACCERR
;
325 info
.si_addr
= (void __user
*) __frame
->pc
;
327 force_sig_info(info
.si_signo
, &info
, current
);
330 /*****************************************************************************/
334 asmlinkage
void media_exception(unsigned long msr0
, unsigned long msr1
)
338 die_if_kernel("-- Media Exception --\n"
343 info
.si_signo
= SIGFPE
;
344 info
.si_code
= FPE_MDAOVF
;
346 info
.si_addr
= (void __user
*) __frame
->pc
;
348 force_sig_info(info
.si_signo
, &info
, current
);
349 } /* end media_exception() */
351 /*****************************************************************************/
353 * instruction or data access exception
355 asmlinkage
void memory_access_exception(unsigned long esr0
,
364 fixup
= search_exception_table(__frame
->pc
);
371 die_if_kernel("-- Memory Access Exception --\n"
377 info
.si_signo
= SIGSEGV
;
378 info
.si_code
= SEGV_ACCERR
;
382 if ((esr0
& (ESRx_VALID
| ESR0_EAV
)) == (ESRx_VALID
| ESR0_EAV
))
383 info
.si_addr
= (void __user
*) ear0
;
385 force_sig_info(info
.si_signo
, &info
, current
);
387 } /* end memory_access_exception() */
389 /*****************************************************************************/
392 * - double-word data load from CPU control area (0xFExxxxxx)
393 * - read performed on inactive or self-refreshing SDRAM
394 * - error notification from slave device
395 * - misaligned address
396 * - access to out of bounds memory region
397 * - user mode accessing privileged memory region
398 * - write to R/O memory region
400 asmlinkage
void data_access_error(unsigned long esfr1
, unsigned long esr15
, unsigned long ear15
)
404 die_if_kernel("-- Data Access Error --\n"
409 info
.si_signo
= SIGSEGV
;
410 info
.si_code
= SEGV_ACCERR
;
412 info
.si_addr
= (void __user
*)
413 (((esr15
& (ESRx_VALID
|ESR15_EAV
)) == (ESRx_VALID
|ESR15_EAV
)) ? ear15
: 0);
415 force_sig_info(info
.si_signo
, &info
, current
);
416 } /* end data_access_error() */
418 /*****************************************************************************/
420 * data store error - should only happen if accessing inactive or self-refreshing SDRAM
422 asmlinkage
void data_store_error(unsigned long esfr1
, unsigned long esr15
)
424 die_if_kernel("-- Data Store Error --\n"
428 } /* end data_store_error() */
430 /*****************************************************************************/
434 asmlinkage
void division_exception(unsigned long esfr1
, unsigned long esr0
, unsigned long isr
)
438 die_if_kernel("-- Division Exception --\n"
443 info
.si_signo
= SIGFPE
;
444 info
.si_code
= FPE_INTDIV
;
446 info
.si_addr
= (void __user
*) __frame
->pc
;
448 force_sig_info(info
.si_signo
, &info
, current
);
449 } /* end division_exception() */
451 /*****************************************************************************/
455 asmlinkage
void compound_exception(unsigned long esfr1
,
456 unsigned long esr0
, unsigned long esr14
, unsigned long esr15
,
457 unsigned long msr0
, unsigned long msr1
)
459 die_if_kernel("-- Compound Exception --\n"
465 esr0
, esr14
, esr15
, msr0
, msr1
);
467 } /* end compound_exception() */
469 void show_stack(struct task_struct
*task
, unsigned long *sp
)
473 void show_trace_task(struct task_struct
*tsk
)
475 printk("CONTEXT: stack=0x%lx frame=0x%p LR=0x%lx RET=0x%lx\n",
476 tsk
->thread
.sp
, tsk
->thread
.frame
, tsk
->thread
.lr
, tsk
->thread
.sched_lr
);
479 static const char *regnames
[] = {
480 "PSR ", "ISR ", "CCR ", "CCCR",
481 "LR ", "LCR ", "PC ", "_stt",
482 "sys ", "GR8*", "GNE0", "GNE1",
484 "TBR ", "SP ", "FP ", "GR3 ",
485 "GR4 ", "GR5 ", "GR6 ", "GR7 ",
486 "GR8 ", "GR9 ", "GR10", "GR11",
487 "GR12", "GR13", "GR14", "GR15",
488 "GR16", "GR17", "GR18", "GR19",
489 "GR20", "GR21", "GR22", "GR23",
490 "GR24", "GR25", "GR26", "GR27",
491 "EFRM", "CURR", "GR30", "BFRM"
494 void show_regs(struct pt_regs
*regs
)
500 show_regs_print_info(KERN_DEFAULT
);
502 printk("Frame: @%08lx [%s]\n",
503 (unsigned long) regs
,
504 regs
->psr
& PSR_S
? "kernel" : "user");
506 reg
= (unsigned long *) regs
;
507 for (loop
= 0; loop
< NR_PT_REGS
; loop
++) {
508 printk("%s %08lx", regnames
[loop
+ 0], reg
[loop
+ 0]);
510 if (loop
== NR_PT_REGS
- 1 || loop
% 5 == 4)
517 void die_if_kernel(const char *str
, ...)
522 if (user_mode(__frame
))
526 vsnprintf(buffer
, sizeof(buffer
), str
, va
);
530 printk("\n===================================\n");
531 printk("%s\n", buffer
);
532 show_backtrace(__frame
, 0);
534 __break_hijack_kernel_event();
538 /*****************************************************************************/
540 * dump the contents of an exception frame
542 static void show_backtrace_regs(struct pt_regs
*frame
)
547 /* print the registers for this frame */
548 printk("<-- %s Frame: @%p -->\n",
549 frame
->psr
& PSR_S
? "Kernel Mode" : "User Mode",
552 reg
= (unsigned long *) frame
;
553 for (loop
= 0; loop
< NR_PT_REGS
; loop
++) {
554 printk("%s %08lx", regnames
[loop
+ 0], reg
[loop
+ 0]);
556 if (loop
== NR_PT_REGS
- 1 || loop
% 5 == 4)
562 printk("--------\n");
563 } /* end show_backtrace_regs() */
565 /*****************************************************************************/
567 * generate a backtrace of the kernel stack
569 void show_backtrace(struct pt_regs
*frame
, unsigned long sp
)
571 struct pt_regs
*frame0
;
572 unsigned long tos
= 0, stop
= 0, base
;
575 base
= ((((unsigned long) frame
) + 8191) & ~8191) - sizeof(struct user_context
);
576 frame0
= (struct pt_regs
*) base
;
580 stop
= (unsigned long) frame
;
583 printk("\nProcess %s (pid: %d)\n\n", current
->comm
, current
->pid
);
586 /* dump stack segment between frames */
587 //printk("%08lx -> %08lx\n", tos, stop);
591 printk(" %04lx :", tos
& 0xffff);
593 printk(" %08lx", *(unsigned long *) tos
);
606 /* dump frame 0 outside of the loop */
611 if (((unsigned long) frame
) + sizeof(*frame
) != tos
) {
612 printk("-- TOS %08lx does not follow frame %p --\n",
617 show_backtrace_regs(frame
);
619 /* dump the stack between this frame and the next */
620 stop
= (unsigned long) frame
->next_frame
;
624 (stop
< base
&& stop
+ sizeof(*frame
) > base
) ||
626 printk("-- next_frame %08lx is invalid (range %08lx-%08lx) --\n",
631 /* move to next frame */
632 frame
= frame
->next_frame
;
635 /* we can always dump frame 0, even if the rest of the stack is corrupt */
636 show_backtrace_regs(frame0
);
638 } /* end show_backtrace() */
640 /*****************************************************************************/
644 void __init
trap_init (void)
646 } /* end trap_init() */