Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 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 | * |
Vineet Gupta | 2e651ea | 2013-01-23 16:30:36 +0530 | [diff] [blame] | 10 | * vineetg: May 2011 |
| 11 | * -user-space unaligned access emulation |
| 12 | * |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 13 | * Rahul Trivedi: Codito Technologies 2004 |
| 14 | */ |
| 15 | |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/kdebug.h> |
| 18 | #include <linux/uaccess.h> |
Sachin Kamat | 1ec9db1 | 2013-03-06 16:53:44 +0530 | [diff] [blame] | 19 | #include <linux/ptrace.h> |
| 20 | #include <linux/kprobes.h> |
| 21 | #include <linux/kgdb.h> |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 22 | #include <asm/setup.h> |
Vineet Gupta | 2e651ea | 2013-01-23 16:30:36 +0530 | [diff] [blame] | 23 | #include <asm/unaligned.h> |
Christian Ruppert | 5b00029 | 2013-04-09 11:50:45 +0200 | [diff] [blame] | 24 | #include <asm/kprobes.h> |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 25 | |
| 26 | void __init trap_init(void) |
| 27 | { |
| 28 | return; |
| 29 | } |
| 30 | |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 31 | void die(const char *str, struct pt_regs *regs, unsigned long address) |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 32 | { |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 33 | show_kernel_fault_diag(str, regs, address); |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 34 | |
| 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 Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 44 | static noinline int |
Vineet Gupta | 0dfb8ec | 2014-10-13 15:29:50 +0530 | [diff] [blame] | 45 | unhandled_exception(const char *str, struct pt_regs *regs, siginfo_t *info) |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 46 | { |
| 47 | if (user_mode(regs)) { |
| 48 | struct task_struct *tsk = current; |
| 49 | |
| 50 | tsk->thread.fault_address = (__force unsigned int)info->si_addr; |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 51 | |
| 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 Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 59 | die(str, regs, (unsigned long)info->si_addr); |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | #define DO_ERROR_INFO(signr, str, name, sicode) \ |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 66 | int name(unsigned long address, struct pt_regs *regs) \ |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 67 | { \ |
| 68 | siginfo_t info = { \ |
| 69 | .si_signo = signr, \ |
| 70 | .si_errno = 0, \ |
| 71 | .si_code = sicode, \ |
| 72 | .si_addr = (void __user *)address, \ |
| 73 | }; \ |
Vineet Gupta | 0dfb8ec | 2014-10-13 15:29:50 +0530 | [diff] [blame] | 74 | return unhandled_exception(str, regs, &info);\ |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Entry points for exceptions NOT needing specific handling |
| 79 | */ |
| 80 | DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC) |
| 81 | DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC) |
| 82 | DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC) |
| 83 | DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", do_memory_error, BUS_ADRERR) |
| 84 | DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT) |
Vineet Gupta | c723ea4 | 2013-04-04 14:37:52 +0530 | [diff] [blame] | 85 | DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN) |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 86 | |
Vineet Gupta | 2e651ea | 2013-01-23 16:30:36 +0530 | [diff] [blame] | 87 | /* |
| 88 | * Entry Point for Misaligned Data access Exception, for emulating in software |
| 89 | */ |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 90 | int do_misaligned_access(unsigned long address, struct pt_regs *regs, |
| 91 | struct callee_regs *cregs) |
Vineet Gupta | 2e651ea | 2013-01-23 16:30:36 +0530 | [diff] [blame] | 92 | { |
Vineet Gupta | 07ba69a | 2013-09-18 18:08:01 +0530 | [diff] [blame] | 93 | /* If emulation not enabled, or failed, kill the task */ |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 94 | if (misaligned_fixup(address, regs, cregs) != 0) |
| 95 | return do_misaligned_error(address, regs); |
Vineet Gupta | 2e651ea | 2013-01-23 16:30:36 +0530 | [diff] [blame] | 96 | |
Vineet Gupta | 2e651ea | 2013-01-23 16:30:36 +0530 | [diff] [blame] | 97 | return 0; |
| 98 | } |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Entry point for miscll errors such as Nested Exceptions |
| 102 | * -Duplicate TLB entry is handled seperately though |
| 103 | */ |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 104 | void do_machine_check_fault(unsigned long address, struct pt_regs *regs) |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 105 | { |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 106 | die("Machine Check Exception", regs, address); |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 107 | } |
| 108 | |
Vineet Gupta | 4d86dfb | 2013-01-22 17:03:59 +0530 | [diff] [blame] | 109 | |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 110 | /* |
| 111 | * Entry point for traps induced by ARCompact TRAP_S <n> insn |
| 112 | * This is same family as TRAP0/SWI insn (use the same vector). |
| 113 | * The only difference being SWI insn take no operand, while TRAP_S does |
| 114 | * which reflects in ECR Reg as 8 bit param. |
| 115 | * Thus TRAP_S <n> can be used for specific purpose |
| 116 | * -1 used for software breakpointing (gdb) |
| 117 | * -2 used by kprobes |
| 118 | */ |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 119 | void do_non_swi_trap(unsigned long address, struct pt_regs *regs) |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 120 | { |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 121 | unsigned int param = regs->ecr_param; |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 122 | |
| 123 | switch (param) { |
| 124 | case 1: |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 125 | trap_is_brkpt(address, regs); |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 126 | break; |
| 127 | |
Vineet Gupta | 4d86dfb | 2013-01-22 17:03:59 +0530 | [diff] [blame] | 128 | case 2: |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 129 | trap_is_kprobe(address, regs); |
Vineet Gupta | 4d86dfb | 2013-01-22 17:03:59 +0530 | [diff] [blame] | 130 | break; |
| 131 | |
Mischa Jonker | f46121b | 2013-01-18 15:12:24 +0530 | [diff] [blame] | 132 | case 3: |
| 133 | case 4: |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 134 | kgdb_trap(regs); |
Mischa Jonker | f46121b | 2013-01-18 15:12:24 +0530 | [diff] [blame] | 135 | break; |
| 136 | |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 137 | default: |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Entry point for Instruction Error Exception |
Vineet Gupta | 4d86dfb | 2013-01-22 17:03:59 +0530 | [diff] [blame] | 144 | * -For a corner case, ARC kprobes implementation resorts to using |
| 145 | * this exception, hence the check |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 146 | */ |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 147 | void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs) |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 148 | { |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 149 | int rc; |
| 150 | |
Vineet Gupta | 4d86dfb | 2013-01-22 17:03:59 +0530 | [diff] [blame] | 151 | /* Check if this exception is caused by kprobes */ |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 152 | rc = notify_die(DIE_IERR, "kprobe_ierr", regs, address, 0, SIGILL); |
| 153 | if (rc == NOTIFY_STOP) |
Vineet Gupta | 4d86dfb | 2013-01-22 17:03:59 +0530 | [diff] [blame] | 154 | return; |
| 155 | |
Vineet Gupta | 38a9ff6 | 2013-06-12 15:13:40 +0530 | [diff] [blame] | 156 | insterror_is_error(address, regs); |
Vineet Gupta | 054419e | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 157 | } |