c6396b48fcd2d8ea124ac7ae1d252a2896e0b2f9
[deliverable/linux.git] / arch / arc / kernel / traps.c
1 /*
2 * Traps/Non-MMU Exception handling for ARC
3 *
4 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
5 *
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 as
8 * published by the Free Software Foundation.
9 *
10 * Rahul Trivedi: Codito Technologies 2004
11 */
12
13 #include <linux/sched.h>
14 #include <linux/kdebug.h>
15 #include <linux/uaccess.h>
16 #include <asm/ptrace.h>
17 #include <asm/setup.h>
18 #include <asm/kprobes.h>
19
20 void __init trap_init(void)
21 {
22 return;
23 }
24
25 void die(const char *str, struct pt_regs *regs, unsigned long address,
26 unsigned long cause_reg)
27 {
28 show_kernel_fault_diag(str, regs, address, cause_reg);
29
30 /* DEAD END */
31 __asm__("flag 1");
32 }
33
34 /*
35 * Helper called for bulk of exceptions NOT needing specific handling
36 * -for user faults enqueues requested signal
37 * -for kernel, chk if due to copy_(to|from)_user, otherwise die()
38 */
39 static noinline int handle_exception(unsigned long cause, char *str,
40 struct pt_regs *regs, siginfo_t *info)
41 {
42 if (user_mode(regs)) {
43 struct task_struct *tsk = current;
44
45 tsk->thread.fault_address = (__force unsigned int)info->si_addr;
46 tsk->thread.cause_code = cause;
47
48 force_sig_info(info->si_signo, info, tsk);
49
50 } else {
51 /* If not due to copy_(to|from)_user, we are doomed */
52 if (fixup_exception(regs))
53 return 0;
54
55 die(str, regs, (unsigned long)info->si_addr, cause);
56 }
57
58 return 1;
59 }
60
61 #define DO_ERROR_INFO(signr, str, name, sicode) \
62 int name(unsigned long cause, unsigned long address, struct pt_regs *regs) \
63 { \
64 siginfo_t info = { \
65 .si_signo = signr, \
66 .si_errno = 0, \
67 .si_code = sicode, \
68 .si_addr = (void __user *)address, \
69 }; \
70 return handle_exception(cause, str, regs, &info);\
71 }
72
73 /*
74 * Entry points for exceptions NOT needing specific handling
75 */
76 DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
77 DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
78 DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
79 DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", do_memory_error, BUS_ADRERR)
80 DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
81
82 DO_ERROR_INFO(SIGSEGV, "Misaligned Access", do_misaligned_access, SEGV_ACCERR)
83
84 /*
85 * Entry point for miscll errors such as Nested Exceptions
86 * -Duplicate TLB entry is handled seperately though
87 */
88 void do_machine_check_fault(unsigned long cause, unsigned long address,
89 struct pt_regs *regs)
90 {
91 die("Machine Check Exception", regs, address, cause);
92 }
93
94
95 /*
96 * Entry point for traps induced by ARCompact TRAP_S <n> insn
97 * This is same family as TRAP0/SWI insn (use the same vector).
98 * The only difference being SWI insn take no operand, while TRAP_S does
99 * which reflects in ECR Reg as 8 bit param.
100 * Thus TRAP_S <n> can be used for specific purpose
101 * -1 used for software breakpointing (gdb)
102 * -2 used by kprobes
103 */
104 void do_non_swi_trap(unsigned long cause, unsigned long address,
105 struct pt_regs *regs)
106 {
107 unsigned int param = cause & 0xff;
108
109 switch (param) {
110 case 1:
111 trap_is_brkpt(cause, address, regs);
112 break;
113
114 case 2:
115 trap_is_kprobe(param, address, regs);
116 break;
117
118 default:
119 break;
120 }
121 }
122
123 /*
124 * Entry point for Instruction Error Exception
125 * -For a corner case, ARC kprobes implementation resorts to using
126 * this exception, hence the check
127 */
128 void do_insterror_or_kprobe(unsigned long cause,
129 unsigned long address,
130 struct pt_regs *regs)
131 {
132 /* Check if this exception is caused by kprobes */
133 if (notify_die(DIE_IERR, "kprobe_ierr", regs, address,
134 cause, SIGILL) == NOTIFY_STOP)
135 return;
136
137 insterror_is_error(cause, address, regs);
138 }
This page took 0.06476 seconds and 4 git commands to generate.