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/signal.h>
13 #include <linux/sched/debug.h>
14 #include <linux/signal.h>
15 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/user.h>
19 #include <linux/string.h>
20 #include <linux/linkage.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
24 #include <asm/asm-offsets.h>
25 #include <asm/setup.h>
27 #include <linux/uaccess.h>
28 #include <asm/pgtable.h>
29 #include <asm/siginfo.h>
30 #include <asm/unaligned.h>
32 void show_backtrace(struct pt_regs
*, unsigned long);
34 extern asmlinkage
void __break_hijack_kernel_event(void);
36 /*****************************************************************************/
38 * instruction access error
40 asmlinkage
void insn_access_error(unsigned long esfr1
, unsigned long epcr0
, unsigned long esr0
)
44 die_if_kernel("-- Insn Access Error --\n"
49 info
.si_signo
= SIGSEGV
;
50 info
.si_code
= SEGV_ACCERR
;
52 info
.si_addr
= (void __user
*) ((epcr0
& EPCR0_V
) ? (epcr0
& EPCR0_PC
) : __frame
->pc
);
54 force_sig_info(info
.si_signo
, &info
, current
);
55 } /* end insn_access_error() */
57 /*****************************************************************************/
60 * - illegal instruction
61 * - privileged instruction
65 asmlinkage
void illegal_instruction(unsigned long esfr1
, unsigned long epcr0
, unsigned long esr0
)
69 die_if_kernel("-- Illegal Instruction --\n"
76 info
.si_addr
= (void __user
*) ((epcr0
& EPCR0_V
) ? (epcr0
& EPCR0_PC
) : __frame
->pc
);
78 switch (__frame
->tbr
& TBR_TT
) {
79 case TBR_TT_ILLEGAL_INSTR
:
80 info
.si_signo
= SIGILL
;
81 info
.si_code
= ILL_ILLOPC
;
83 case TBR_TT_PRIV_INSTR
:
84 info
.si_signo
= SIGILL
;
85 info
.si_code
= ILL_PRVOPC
;
87 case TBR_TT_TRAP2
... TBR_TT_TRAP126
:
88 info
.si_signo
= SIGILL
;
89 info
.si_code
= ILL_ILLTRP
;
91 /* GDB uses "tira gr0, #1" as a breakpoint instruction. */
94 info
.si_signo
= SIGTRAP
;
96 (__frame
->__status
& REG__STATUS_STEPPED
) ? TRAP_TRACE
: TRAP_BRKPT
;
100 force_sig_info(info
.si_signo
, &info
, current
);
101 } /* end illegal_instruction() */
103 /*****************************************************************************/
105 * handle atomic operations with errors
106 * - arguments in gr8, gr9, gr10
107 * - original memory value placed in gr5
108 * - replacement memory value placed in gr9
110 asmlinkage
void atomic_operation(unsigned long esfr1
, unsigned long epcr0
,
113 static DEFINE_SPINLOCK(atomic_op_lock
);
114 unsigned long x
, y
, z
;
115 unsigned long __user
*p
;
124 if (!user_mode(__frame
))
127 switch (__frame
->tbr
& TBR_TT
) {
129 * u32 __atomic_user_cmpxchg32(u32 *ptr, u32 test, u32 new)
131 case TBR_TT_ATOMIC_CMPXCHG32
:
132 p
= (unsigned long __user
*) __frame
->gr8
;
137 ret
= get_user(z
, p
);
144 spin_lock_irq(&atomic_op_lock
);
146 if (__get_user(z
, p
) == 0) {
150 if (__put_user(y
, p
) == 0)
155 spin_unlock_irq(&atomic_op_lock
);
159 * u32 __atomic_kernel_xchg32(void *v, u32 new)
161 case TBR_TT_ATOMIC_XCHG32
:
162 p
= (unsigned long __user
*) __frame
->gr8
;
166 ret
= get_user(z
, p
);
170 spin_lock_irq(&atomic_op_lock
);
172 if (__get_user(z
, p
) == 0) {
173 if (__put_user(y
, p
) == 0)
178 spin_unlock_irq(&atomic_op_lock
);
182 * ulong __atomic_kernel_XOR_return(ulong i, ulong *v)
184 case TBR_TT_ATOMIC_XOR
:
185 p
= (unsigned long __user
*) __frame
->gr8
;
189 ret
= get_user(z
, p
);
193 spin_lock_irq(&atomic_op_lock
);
195 if (__get_user(z
, p
) == 0) {
197 if (__put_user(y
, p
) == 0)
202 spin_unlock_irq(&atomic_op_lock
);
206 * ulong __atomic_kernel_OR_return(ulong i, ulong *v)
208 case TBR_TT_ATOMIC_OR
:
209 p
= (unsigned long __user
*) __frame
->gr8
;
213 ret
= get_user(z
, p
);
217 spin_lock_irq(&atomic_op_lock
);
219 if (__get_user(z
, p
) == 0) {
221 if (__put_user(y
, p
) == 0)
226 spin_unlock_irq(&atomic_op_lock
);
230 * ulong __atomic_kernel_AND_return(ulong i, ulong *v)
232 case TBR_TT_ATOMIC_AND
:
233 p
= (unsigned long __user
*) __frame
->gr8
;
237 ret
= get_user(z
, p
);
241 spin_lock_irq(&atomic_op_lock
);
243 if (__get_user(z
, p
) == 0) {
245 if (__put_user(y
, p
) == 0)
250 spin_unlock_irq(&atomic_op_lock
);
254 * int __atomic_user_sub_return(atomic_t *v, int i)
256 case TBR_TT_ATOMIC_SUB
:
257 p
= (unsigned long __user
*) __frame
->gr8
;
261 ret
= get_user(z
, p
);
265 spin_lock_irq(&atomic_op_lock
);
267 if (__get_user(z
, p
) == 0) {
269 if (__put_user(y
, p
) == 0)
274 spin_unlock_irq(&atomic_op_lock
);
278 * int __atomic_user_add_return(atomic_t *v, int i)
280 case TBR_TT_ATOMIC_ADD
:
281 p
= (unsigned long __user
*) __frame
->gr8
;
285 ret
= get_user(z
, p
);
289 spin_lock_irq(&atomic_op_lock
);
291 if (__get_user(z
, p
) == 0) {
293 if (__put_user(y
, p
) == 0)
298 spin_unlock_irq(&atomic_op_lock
);
306 spin_unlock_irq(&atomic_op_lock
);
308 if (!user_mode(__frame
))
315 spin_unlock_irq(&atomic_op_lock
);
317 if (!user_mode(__frame
))
321 die_if_kernel("-- Atomic Op Error --\n");
323 info
.si_signo
= SIGSEGV
;
324 info
.si_code
= SEGV_ACCERR
;
326 info
.si_addr
= (void __user
*) __frame
->pc
;
328 force_sig_info(info
.si_signo
, &info
, current
);
331 /*****************************************************************************/
335 asmlinkage
void media_exception(unsigned long msr0
, unsigned long msr1
)
339 die_if_kernel("-- Media Exception --\n"
344 info
.si_signo
= SIGFPE
;
345 info
.si_code
= FPE_MDAOVF
;
347 info
.si_addr
= (void __user
*) __frame
->pc
;
349 force_sig_info(info
.si_signo
, &info
, current
);
350 } /* end media_exception() */
352 /*****************************************************************************/
354 * instruction or data access exception
356 asmlinkage
void memory_access_exception(unsigned long esr0
,
365 fixup
= search_exception_table(__frame
->pc
);
372 die_if_kernel("-- Memory Access Exception --\n"
378 info
.si_signo
= SIGSEGV
;
379 info
.si_code
= SEGV_ACCERR
;
383 if ((esr0
& (ESRx_VALID
| ESR0_EAV
)) == (ESRx_VALID
| ESR0_EAV
))
384 info
.si_addr
= (void __user
*) ear0
;
386 force_sig_info(info
.si_signo
, &info
, current
);
388 } /* end memory_access_exception() */
390 /*****************************************************************************/
393 * - double-word data load from CPU control area (0xFExxxxxx)
394 * - read performed on inactive or self-refreshing SDRAM
395 * - error notification from slave device
396 * - misaligned address
397 * - access to out of bounds memory region
398 * - user mode accessing privileged memory region
399 * - write to R/O memory region
401 asmlinkage
void data_access_error(unsigned long esfr1
, unsigned long esr15
, unsigned long ear15
)
405 die_if_kernel("-- Data Access Error --\n"
410 info
.si_signo
= SIGSEGV
;
411 info
.si_code
= SEGV_ACCERR
;
413 info
.si_addr
= (void __user
*)
414 (((esr15
& (ESRx_VALID
|ESR15_EAV
)) == (ESRx_VALID
|ESR15_EAV
)) ? ear15
: 0);
416 force_sig_info(info
.si_signo
, &info
, current
);
417 } /* end data_access_error() */
419 /*****************************************************************************/
421 * data store error - should only happen if accessing inactive or self-refreshing SDRAM
423 asmlinkage
void data_store_error(unsigned long esfr1
, unsigned long esr15
)
425 die_if_kernel("-- Data Store Error --\n"
429 } /* end data_store_error() */
431 /*****************************************************************************/
435 asmlinkage
void division_exception(unsigned long esfr1
, unsigned long esr0
, unsigned long isr
)
439 die_if_kernel("-- Division Exception --\n"
444 info
.si_signo
= SIGFPE
;
445 info
.si_code
= FPE_INTDIV
;
447 info
.si_addr
= (void __user
*) __frame
->pc
;
449 force_sig_info(info
.si_signo
, &info
, current
);
450 } /* end division_exception() */
452 /*****************************************************************************/
456 asmlinkage
void compound_exception(unsigned long esfr1
,
457 unsigned long esr0
, unsigned long esr14
, unsigned long esr15
,
458 unsigned long msr0
, unsigned long msr1
)
460 die_if_kernel("-- Compound Exception --\n"
466 esr0
, esr14
, esr15
, msr0
, msr1
);
468 } /* end compound_exception() */
470 void show_stack(struct task_struct
*task
, unsigned long *sp
)
474 void show_trace_task(struct task_struct
*tsk
)
476 printk("CONTEXT: stack=0x%lx frame=0x%p LR=0x%lx RET=0x%lx\n",
477 tsk
->thread
.sp
, tsk
->thread
.frame
, tsk
->thread
.lr
, tsk
->thread
.sched_lr
);
480 static const char *regnames
[] = {
481 "PSR ", "ISR ", "CCR ", "CCCR",
482 "LR ", "LCR ", "PC ", "_stt",
483 "sys ", "GR8*", "GNE0", "GNE1",
485 "TBR ", "SP ", "FP ", "GR3 ",
486 "GR4 ", "GR5 ", "GR6 ", "GR7 ",
487 "GR8 ", "GR9 ", "GR10", "GR11",
488 "GR12", "GR13", "GR14", "GR15",
489 "GR16", "GR17", "GR18", "GR19",
490 "GR20", "GR21", "GR22", "GR23",
491 "GR24", "GR25", "GR26", "GR27",
492 "EFRM", "CURR", "GR30", "BFRM"
495 void show_regs(struct pt_regs
*regs
)
501 show_regs_print_info(KERN_DEFAULT
);
503 printk("Frame: @%08lx [%s]\n",
504 (unsigned long) regs
,
505 regs
->psr
& PSR_S
? "kernel" : "user");
507 reg
= (unsigned long *) regs
;
508 for (loop
= 0; loop
< NR_PT_REGS
; loop
++) {
509 printk("%s %08lx", regnames
[loop
+ 0], reg
[loop
+ 0]);
511 if (loop
== NR_PT_REGS
- 1 || loop
% 5 == 4)
518 void die_if_kernel(const char *str
, ...)
523 if (user_mode(__frame
))
527 vsnprintf(buffer
, sizeof(buffer
), str
, va
);
531 printk("\n===================================\n");
532 printk("%s\n", buffer
);
533 show_backtrace(__frame
, 0);
535 __break_hijack_kernel_event();
539 /*****************************************************************************/
541 * dump the contents of an exception frame
543 static void show_backtrace_regs(struct pt_regs
*frame
)
548 /* print the registers for this frame */
549 printk("<-- %s Frame: @%p -->\n",
550 frame
->psr
& PSR_S
? "Kernel Mode" : "User Mode",
553 reg
= (unsigned long *) frame
;
554 for (loop
= 0; loop
< NR_PT_REGS
; loop
++) {
555 printk("%s %08lx", regnames
[loop
+ 0], reg
[loop
+ 0]);
557 if (loop
== NR_PT_REGS
- 1 || loop
% 5 == 4)
563 printk("--------\n");
564 } /* end show_backtrace_regs() */
566 /*****************************************************************************/
568 * generate a backtrace of the kernel stack
570 void show_backtrace(struct pt_regs
*frame
, unsigned long sp
)
572 struct pt_regs
*frame0
;
573 unsigned long tos
= 0, stop
= 0, base
;
576 base
= ((((unsigned long) frame
) + 8191) & ~8191) - sizeof(struct user_context
);
577 frame0
= (struct pt_regs
*) base
;
581 stop
= (unsigned long) frame
;
584 printk("\nProcess %s (pid: %d)\n\n", current
->comm
, current
->pid
);
587 /* dump stack segment between frames */
588 //printk("%08lx -> %08lx\n", tos, stop);
592 printk(" %04lx :", tos
& 0xffff);
594 printk(" %08lx", *(unsigned long *) tos
);
607 /* dump frame 0 outside of the loop */
612 if (((unsigned long) frame
) + sizeof(*frame
) != tos
) {
613 printk("-- TOS %08lx does not follow frame %p --\n",
618 show_backtrace_regs(frame
);
620 /* dump the stack between this frame and the next */
621 stop
= (unsigned long) frame
->next_frame
;
625 (stop
< base
&& stop
+ sizeof(*frame
) > base
) ||
627 printk("-- next_frame %08lx is invalid (range %08lx-%08lx) --\n",
632 /* move to next frame */
633 frame
= frame
->next_frame
;
636 /* we can always dump frame 0, even if the rest of the stack is corrupt */
637 show_backtrace_regs(frame0
);
639 } /* end show_backtrace() */
641 /*****************************************************************************/
645 void __init
trap_init (void)
647 } /* end trap_init() */