blob: 74839d10d80f75608728e46ae6b458ed88451916 [file] [log] [blame]
Vineet Gupta054419e2013-01-18 15:12:18 +05301/*
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 *
Vineet Gupta2e651ea2013-01-23 16:30:36 +053010 * vineetg: May 2011
11 * -user-space unaligned access emulation
12 *
Vineet Gupta054419e2013-01-18 15:12:18 +053013 * Rahul Trivedi: Codito Technologies 2004
14 */
15
16#include <linux/sched.h>
17#include <linux/kdebug.h>
18#include <linux/uaccess.h>
Sachin Kamat1ec9db12013-03-06 16:53:44 +053019#include <linux/ptrace.h>
20#include <linux/kprobes.h>
21#include <linux/kgdb.h>
Vineet Gupta054419e2013-01-18 15:12:18 +053022#include <asm/setup.h>
Vineet Gupta2e651ea2013-01-23 16:30:36 +053023#include <asm/unaligned.h>
Christian Ruppert5b000292013-04-09 11:50:45 +020024#include <asm/kprobes.h>
Vineet Gupta054419e2013-01-18 15:12:18 +053025
26void __init trap_init(void)
27{
28 return;
29}
30
31void die(const char *str, struct pt_regs *regs, unsigned long address,
32 unsigned long cause_reg)
33{
34 show_kernel_fault_diag(str, regs, address, cause_reg);
35
36 /* DEAD END */
37 __asm__("flag 1");
38}
39
40/*
41 * Helper called for bulk of exceptions NOT needing specific handling
42 * -for user faults enqueues requested signal
43 * -for kernel, chk if due to copy_(to|from)_user, otherwise die()
44 */
45static noinline int handle_exception(unsigned long cause, char *str,
46 struct pt_regs *regs, siginfo_t *info)
47{
48 if (user_mode(regs)) {
49 struct task_struct *tsk = current;
50
51 tsk->thread.fault_address = (__force unsigned int)info->si_addr;
52 tsk->thread.cause_code = cause;
53
54 force_sig_info(info->si_signo, info, tsk);
55
56 } else {
57 /* If not due to copy_(to|from)_user, we are doomed */
58 if (fixup_exception(regs))
59 return 0;
60
61 die(str, regs, (unsigned long)info->si_addr, cause);
62 }
63
64 return 1;
65}
66
67#define DO_ERROR_INFO(signr, str, name, sicode) \
68int name(unsigned long cause, unsigned long address, struct pt_regs *regs) \
69{ \
70 siginfo_t info = { \
71 .si_signo = signr, \
72 .si_errno = 0, \
73 .si_code = sicode, \
74 .si_addr = (void __user *)address, \
75 }; \
76 return handle_exception(cause, str, regs, &info);\
77}
78
79/*
80 * Entry points for exceptions NOT needing specific handling
81 */
82DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
83DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
84DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
85DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", do_memory_error, BUS_ADRERR)
86DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
87
Vineet Gupta2e651ea2013-01-23 16:30:36 +053088#ifdef CONFIG_ARC_MISALIGN_ACCESS
89/*
90 * Entry Point for Misaligned Data access Exception, for emulating in software
91 */
92int do_misaligned_access(unsigned long cause, unsigned long address,
93 struct pt_regs *regs, struct callee_regs *cregs)
94{
95 if (misaligned_fixup(address, regs, cause, cregs) != 0) {
96 siginfo_t info;
97
98 info.si_signo = SIGBUS;
99 info.si_errno = 0;
100 info.si_code = BUS_ADRALN;
101 info.si_addr = (void __user *)address;
102 return handle_exception(cause, "Misaligned Access", regs,
103 &info);
104 }
105 return 0;
106}
107
108#else
Vineet Gupta054419e2013-01-18 15:12:18 +0530109DO_ERROR_INFO(SIGSEGV, "Misaligned Access", do_misaligned_access, SEGV_ACCERR)
Vineet Gupta2e651ea2013-01-23 16:30:36 +0530110#endif
Vineet Gupta054419e2013-01-18 15:12:18 +0530111
112/*
113 * Entry point for miscll errors such as Nested Exceptions
114 * -Duplicate TLB entry is handled seperately though
115 */
116void do_machine_check_fault(unsigned long cause, unsigned long address,
117 struct pt_regs *regs)
118{
119 die("Machine Check Exception", regs, address, cause);
120}
121
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530122
Vineet Gupta054419e2013-01-18 15:12:18 +0530123/*
124 * Entry point for traps induced by ARCompact TRAP_S <n> insn
125 * This is same family as TRAP0/SWI insn (use the same vector).
126 * The only difference being SWI insn take no operand, while TRAP_S does
127 * which reflects in ECR Reg as 8 bit param.
128 * Thus TRAP_S <n> can be used for specific purpose
129 * -1 used for software breakpointing (gdb)
130 * -2 used by kprobes
131 */
132void do_non_swi_trap(unsigned long cause, unsigned long address,
133 struct pt_regs *regs)
134{
135 unsigned int param = cause & 0xff;
136
137 switch (param) {
138 case 1:
139 trap_is_brkpt(cause, address, regs);
140 break;
141
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530142 case 2:
143 trap_is_kprobe(param, address, regs);
144 break;
145
Mischa Jonkerf46121b2013-01-18 15:12:24 +0530146 case 3:
147 case 4:
148 kgdb_trap(regs, param);
149 break;
150
Vineet Gupta054419e2013-01-18 15:12:18 +0530151 default:
152 break;
153 }
154}
155
156/*
157 * Entry point for Instruction Error Exception
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530158 * -For a corner case, ARC kprobes implementation resorts to using
159 * this exception, hence the check
Vineet Gupta054419e2013-01-18 15:12:18 +0530160 */
161void do_insterror_or_kprobe(unsigned long cause,
162 unsigned long address,
163 struct pt_regs *regs)
164{
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530165 /* Check if this exception is caused by kprobes */
166 if (notify_die(DIE_IERR, "kprobe_ierr", regs, address,
167 cause, SIGILL) == NOTIFY_STOP)
168 return;
169
Vineet Gupta054419e2013-01-18 15:12:18 +0530170 insterror_is_error(cause, address, regs);
171}