xtensa: fix high memory/reserved memory collision
[cris-mirror.git] / arch / arc / kernel / traps.c
blobb123558bf0bb4ee83ce78f3a814be78b9356de2a
1 /*
2 * Traps/Non-MMU Exception handling for ARC
4 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
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.
10 * vineetg: May 2011
11 * -user-space unaligned access emulation
13 * Rahul Trivedi: Codito Technologies 2004
16 #include <linux/sched/signal.h>
17 #include <linux/kdebug.h>
18 #include <linux/uaccess.h>
19 #include <linux/ptrace.h>
20 #include <linux/kprobes.h>
21 #include <linux/kgdb.h>
22 #include <asm/setup.h>
23 #include <asm/unaligned.h>
24 #include <asm/kprobes.h>
26 void __init trap_init(void)
28 return;
31 void die(const char *str, struct pt_regs *regs, unsigned long address)
33 show_kernel_fault_diag(str, regs, address);
35 /* DEAD END */
36 __asm__("flag 1");
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()
44 static noinline int
45 unhandled_exception(const char *str, struct pt_regs *regs, siginfo_t *info)
47 if (user_mode(regs)) {
48 struct task_struct *tsk = current;
50 tsk->thread.fault_address = (__force unsigned int)info->si_addr;
52 force_sig_info(info->si_signo, info, tsk);
54 } else {
55 /* If not due to copy_(to|from)_user, we are doomed */
56 if (fixup_exception(regs))
57 return 0;
59 die(str, regs, (unsigned long)info->si_addr);
62 return 1;
65 #define DO_ERROR_INFO(signr, str, name, sicode) \
66 int name(unsigned long address, struct pt_regs *regs) \
67 { \
68 siginfo_t info; \
70 clear_siginfo(&info); \
71 info.si_signo = signr; \
72 info.si_errno = 0; \
73 info.si_code = sicode; \
74 info.si_addr = (void __user *)address; \
76 return unhandled_exception(str, regs, &info);\
80 * Entry points for exceptions NOT needing specific handling
82 DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
83 DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
84 DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
85 DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", __weak do_memory_error, BUS_ADRERR)
86 DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
87 DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
88 DO_ERROR_INFO(SIGSEGV, "gcc generated __builtin_trap", do_trap5_error, 0)
91 * Entry Point for Misaligned Data access Exception, for emulating in software
93 int do_misaligned_access(unsigned long address, struct pt_regs *regs,
94 struct callee_regs *cregs)
96 /* If emulation not enabled, or failed, kill the task */
97 if (misaligned_fixup(address, regs, cregs) != 0)
98 return do_misaligned_error(address, regs);
100 return 0;
104 * Entry point for miscll errors such as Nested Exceptions
105 * -Duplicate TLB entry is handled seperately though
107 void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
109 die("Unhandled Machine Check Exception", regs, address);
114 * Entry point for traps induced by ARCompact TRAP_S <n> insn
115 * This is same family as TRAP0/SWI insn (use the same vector).
116 * The only difference being SWI insn take no operand, while TRAP_S does
117 * which reflects in ECR Reg as 8 bit param.
118 * Thus TRAP_S <n> can be used for specific purpose
119 * -1 used for software breakpointing (gdb)
120 * -2 used by kprobes
121 * -5 __builtin_trap() generated by gcc (2018.03 onwards) for toggle such as
122 * -fno-isolate-erroneous-paths-dereference
124 void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
126 unsigned int param = regs->ecr_param;
128 switch (param) {
129 case 1:
130 trap_is_brkpt(address, regs);
131 break;
133 case 2:
134 trap_is_kprobe(address, regs);
135 break;
137 case 3:
138 case 4:
139 kgdb_trap(regs);
140 break;
142 case 5:
143 do_trap5_error(address, regs);
144 break;
145 default:
146 break;
151 * Entry point for Instruction Error Exception
152 * -For a corner case, ARC kprobes implementation resorts to using
153 * this exception, hence the check
155 void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs)
157 int rc;
159 /* Check if this exception is caused by kprobes */
160 rc = notify_die(DIE_IERR, "kprobe_ierr", regs, address, 0, SIGILL);
161 if (rc == NOTIFY_STOP)
162 return;
164 insterror_is_error(address, regs);
168 * abort() call generated by older gcc for __builtin_trap()
170 void abort(void)
172 __asm__ __volatile__("trap_s 5\n");