blob: e21692d2fdabc35a5f1120bb26bec82c828c4d0c [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
Vineet Gupta38a9ff62013-06-12 15:13:40 +053031void die(const char *str, struct pt_regs *regs, unsigned long address)
Vineet Gupta054419e2013-01-18 15:12:18 +053032{
Vineet Gupta38a9ff62013-06-12 15:13:40 +053033 show_kernel_fault_diag(str, regs, address);
Vineet Gupta054419e2013-01-18 15:12:18 +053034
35 /* DEAD END */
36 __asm__("flag 1");
37}
38
39/*
40 * Helper called for bulk of exceptions NOT needing specific handling
41 * -for user faults enqueues requested signal
42 * -for kernel, chk if due to copy_(to|from)_user, otherwise die()
43 */
Vineet Gupta38a9ff62013-06-12 15:13:40 +053044static noinline int
45handle_exception(const char *str, struct pt_regs *regs, siginfo_t *info)
Vineet Gupta054419e2013-01-18 15:12:18 +053046{
47 if (user_mode(regs)) {
48 struct task_struct *tsk = current;
49
50 tsk->thread.fault_address = (__force unsigned int)info->si_addr;
Vineet Gupta054419e2013-01-18 15:12:18 +053051
52 force_sig_info(info->si_signo, info, tsk);
53
54 } else {
55 /* If not due to copy_(to|from)_user, we are doomed */
56 if (fixup_exception(regs))
57 return 0;
58
Vineet Gupta38a9ff62013-06-12 15:13:40 +053059 die(str, regs, (unsigned long)info->si_addr);
Vineet Gupta054419e2013-01-18 15:12:18 +053060 }
61
62 return 1;
63}
64
65#define DO_ERROR_INFO(signr, str, name, sicode) \
Vineet Gupta38a9ff62013-06-12 15:13:40 +053066int name(unsigned long address, struct pt_regs *regs) \
Vineet Gupta054419e2013-01-18 15:12:18 +053067{ \
68 siginfo_t info = { \
69 .si_signo = signr, \
70 .si_errno = 0, \
71 .si_code = sicode, \
72 .si_addr = (void __user *)address, \
73 }; \
Vineet Gupta38a9ff62013-06-12 15:13:40 +053074 return handle_exception(str, regs, &info);\
Vineet Gupta054419e2013-01-18 15:12:18 +053075}
76
77/*
78 * Entry points for exceptions NOT needing specific handling
79 */
80DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
81DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
82DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
83DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", do_memory_error, BUS_ADRERR)
84DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
Vineet Guptac723ea42013-04-04 14:37:52 +053085DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
Vineet Gupta054419e2013-01-18 15:12:18 +053086
Vineet Gupta2e651ea2013-01-23 16:30:36 +053087#ifdef CONFIG_ARC_MISALIGN_ACCESS
88/*
89 * Entry Point for Misaligned Data access Exception, for emulating in software
90 */
Vineet Gupta38a9ff62013-06-12 15:13:40 +053091int do_misaligned_access(unsigned long address, struct pt_regs *regs,
92 struct callee_regs *cregs)
Vineet Gupta2e651ea2013-01-23 16:30:36 +053093{
Vineet Gupta38a9ff62013-06-12 15:13:40 +053094 if (misaligned_fixup(address, regs, cregs) != 0)
95 return do_misaligned_error(address, regs);
Vineet Gupta2e651ea2013-01-23 16:30:36 +053096
Vineet Gupta2e651ea2013-01-23 16:30:36 +053097 return 0;
98}
Vineet Gupta2e651ea2013-01-23 16:30:36 +053099#endif
Vineet Gupta054419e2013-01-18 15:12:18 +0530100
101/*
102 * Entry point for miscll errors such as Nested Exceptions
103 * -Duplicate TLB entry is handled seperately though
104 */
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530105void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
Vineet Gupta054419e2013-01-18 15:12:18 +0530106{
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530107 die("Machine Check Exception", regs, address);
Vineet Gupta054419e2013-01-18 15:12:18 +0530108}
109
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530110
Vineet Gupta054419e2013-01-18 15:12:18 +0530111/*
112 * Entry point for traps induced by ARCompact TRAP_S <n> insn
113 * This is same family as TRAP0/SWI insn (use the same vector).
114 * The only difference being SWI insn take no operand, while TRAP_S does
115 * which reflects in ECR Reg as 8 bit param.
116 * Thus TRAP_S <n> can be used for specific purpose
117 * -1 used for software breakpointing (gdb)
118 * -2 used by kprobes
119 */
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530120void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
Vineet Gupta054419e2013-01-18 15:12:18 +0530121{
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530122 unsigned int param = regs->ecr_param;
Vineet Gupta054419e2013-01-18 15:12:18 +0530123
124 switch (param) {
125 case 1:
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530126 trap_is_brkpt(address, regs);
Vineet Gupta054419e2013-01-18 15:12:18 +0530127 break;
128
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530129 case 2:
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530130 trap_is_kprobe(address, regs);
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530131 break;
132
Mischa Jonkerf46121b2013-01-18 15:12:24 +0530133 case 3:
134 case 4:
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530135 kgdb_trap(regs);
Mischa Jonkerf46121b2013-01-18 15:12:24 +0530136 break;
137
Vineet Gupta054419e2013-01-18 15:12:18 +0530138 default:
139 break;
140 }
141}
142
143/*
144 * Entry point for Instruction Error Exception
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530145 * -For a corner case, ARC kprobes implementation resorts to using
146 * this exception, hence the check
Vineet Gupta054419e2013-01-18 15:12:18 +0530147 */
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530148void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs)
Vineet Gupta054419e2013-01-18 15:12:18 +0530149{
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530150 int rc;
151
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530152 /* Check if this exception is caused by kprobes */
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530153 rc = notify_die(DIE_IERR, "kprobe_ierr", regs, address, 0, SIGILL);
154 if (rc == NOTIFY_STOP)
Vineet Gupta4d86dfb2013-01-22 17:03:59 +0530155 return;
156
Vineet Gupta38a9ff62013-06-12 15:13:40 +0530157 insterror_is_error(address, regs);
Vineet Gupta054419e2013-01-18 15:12:18 +0530158}