1 // SPDX-License-Identifier: GPL-2.0-only
3 * Traps/Non-MMU Exception handling for ARC
5 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
8 * -user-space unaligned access emulation
10 * Rahul Trivedi: Codito Technologies 2004
13 #include <linux/sched/signal.h>
14 #include <linux/kdebug.h>
15 #include <linux/uaccess.h>
16 #include <linux/ptrace.h>
17 #include <linux/kprobes.h>
18 #include <linux/kgdb.h>
19 #include <asm/setup.h>
20 #include <asm/unaligned.h>
21 #include <asm/kprobes.h>
23 void __init
trap_init(void)
28 void die(const char *str
, struct pt_regs
*regs
, unsigned long address
)
30 show_kernel_fault_diag(str
, regs
, address
);
37 * Helper called for bulk of exceptions NOT needing specific handling
38 * -for user faults enqueues requested signal
39 * -for kernel, chk if due to copy_(to|from)_user, otherwise die()
42 unhandled_exception(const char *str
, struct pt_regs
*regs
,
43 int signo
, int si_code
, void __user
*addr
)
45 if (user_mode(regs
)) {
46 struct task_struct
*tsk
= current
;
48 tsk
->thread
.fault_address
= (__force
unsigned int)addr
;
50 force_sig_fault(signo
, si_code
, addr
);
53 /* If not due to copy_(to|from)_user, we are doomed */
54 if (fixup_exception(regs
))
57 die(str
, regs
, (unsigned long)addr
);
63 #define DO_ERROR_INFO(signr, str, name, sicode) \
64 int name(unsigned long address, struct pt_regs *regs) \
66 return unhandled_exception(str, regs, signr, sicode, \
67 (void __user *)address); \
71 * Entry points for exceptions NOT needing specific handling
73 DO_ERROR_INFO(SIGILL
, "Priv Op/Disabled Extn", do_privilege_fault
, ILL_PRVOPC
)
74 DO_ERROR_INFO(SIGILL
, "Invalid Extn Insn", do_extension_fault
, ILL_ILLOPC
)
75 DO_ERROR_INFO(SIGILL
, "Illegal Insn (or Seq)", insterror_is_error
, ILL_ILLOPC
)
76 DO_ERROR_INFO(SIGBUS
, "Invalid Mem Access", __weak do_memory_error
, BUS_ADRERR
)
77 DO_ERROR_INFO(SIGTRAP
, "Breakpoint Set", trap_is_brkpt
, TRAP_BRKPT
)
78 DO_ERROR_INFO(SIGBUS
, "Misaligned Access", do_misaligned_error
, BUS_ADRALN
)
79 DO_ERROR_INFO(SIGSEGV
, "gcc generated __builtin_trap", do_trap5_error
, 0)
82 * Entry Point for Misaligned Data access Exception, for emulating in software
84 int do_misaligned_access(unsigned long address
, struct pt_regs
*regs
,
85 struct callee_regs
*cregs
)
87 /* If emulation not enabled, or failed, kill the task */
88 if (misaligned_fixup(address
, regs
, cregs
) != 0)
89 return do_misaligned_error(address
, regs
);
95 * Entry point for miscll errors such as Nested Exceptions
96 * -Duplicate TLB entry is handled seperately though
98 void do_machine_check_fault(unsigned long address
, struct pt_regs
*regs
)
100 die("Unhandled Machine Check Exception", regs
, address
);
105 * Entry point for traps induced by ARCompact TRAP_S <n> insn
106 * This is same family as TRAP0/SWI insn (use the same vector).
107 * The only difference being SWI insn take no operand, while TRAP_S does
108 * which reflects in ECR Reg as 8 bit param.
109 * Thus TRAP_S <n> can be used for specific purpose
110 * -1 used for software breakpointing (gdb)
112 * -5 __builtin_trap() generated by gcc (2018.03 onwards) for toggle such as
113 * -fno-isolate-erroneous-paths-dereference
115 void do_non_swi_trap(unsigned long address
, struct pt_regs
*regs
)
117 unsigned int param
= regs
->ecr_param
;
121 trap_is_brkpt(address
, regs
);
125 trap_is_kprobe(address
, regs
);
134 do_trap5_error(address
, regs
);
142 * Entry point for Instruction Error Exception
143 * -For a corner case, ARC kprobes implementation resorts to using
144 * this exception, hence the check
146 void do_insterror_or_kprobe(unsigned long address
, struct pt_regs
*regs
)
150 /* Check if this exception is caused by kprobes */
151 rc
= notify_die(DIE_IERR
, "kprobe_ierr", regs
, address
, 0, SIGILL
);
152 if (rc
== NOTIFY_STOP
)
155 insterror_is_error(address
, regs
);
159 * abort() call generated by older gcc for __builtin_trap()
163 __asm__
__volatile__("trap_s 5\n");