2013-01-18 16:42:18 +07:00
|
|
|
/*
|
|
|
|
* Traps/Non-MMU Exception handling for ARC
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2013-01-23 18:00:36 +07:00
|
|
|
* vineetg: May 2011
|
|
|
|
* -user-space unaligned access emulation
|
|
|
|
*
|
2013-01-18 16:42:18 +07:00
|
|
|
* Rahul Trivedi: Codito Technologies 2004
|
|
|
|
*/
|
|
|
|
|
2017-02-09 00:51:30 +07:00
|
|
|
#include <linux/sched/signal.h>
|
2013-01-18 16:42:18 +07:00
|
|
|
#include <linux/kdebug.h>
|
|
|
|
#include <linux/uaccess.h>
|
2013-03-06 18:23:44 +07:00
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/kprobes.h>
|
|
|
|
#include <linux/kgdb.h>
|
2013-01-18 16:42:18 +07:00
|
|
|
#include <asm/setup.h>
|
2013-01-23 18:00:36 +07:00
|
|
|
#include <asm/unaligned.h>
|
2013-04-09 16:50:45 +07:00
|
|
|
#include <asm/kprobes.h>
|
2013-01-18 16:42:18 +07:00
|
|
|
|
|
|
|
void __init trap_init(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-12 16:43:40 +07:00
|
|
|
void die(const char *str, struct pt_regs *regs, unsigned long address)
|
2013-01-18 16:42:18 +07:00
|
|
|
{
|
2013-06-12 16:43:40 +07:00
|
|
|
show_kernel_fault_diag(str, regs, address);
|
2013-01-18 16:42:18 +07:00
|
|
|
|
|
|
|
/* DEAD END */
|
|
|
|
__asm__("flag 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper called for bulk of exceptions NOT needing specific handling
|
|
|
|
* -for user faults enqueues requested signal
|
|
|
|
* -for kernel, chk if due to copy_(to|from)_user, otherwise die()
|
|
|
|
*/
|
2013-06-12 16:43:40 +07:00
|
|
|
static noinline int
|
2018-04-20 07:20:58 +07:00
|
|
|
unhandled_exception(const char *str, struct pt_regs *regs,
|
|
|
|
int signo, int si_code, void __user *addr)
|
2013-01-18 16:42:18 +07:00
|
|
|
{
|
|
|
|
if (user_mode(regs)) {
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
|
2018-04-20 07:20:58 +07:00
|
|
|
tsk->thread.fault_address = (__force unsigned int)addr;
|
2013-01-18 16:42:18 +07:00
|
|
|
|
2018-04-20 07:20:58 +07:00
|
|
|
force_sig_fault(signo, si_code, addr, tsk);
|
2013-01-18 16:42:18 +07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* If not due to copy_(to|from)_user, we are doomed */
|
|
|
|
if (fixup_exception(regs))
|
|
|
|
return 0;
|
|
|
|
|
2018-04-20 07:20:58 +07:00
|
|
|
die(str, regs, (unsigned long)addr);
|
2013-01-18 16:42:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DO_ERROR_INFO(signr, str, name, sicode) \
|
2013-06-12 16:43:40 +07:00
|
|
|
int name(unsigned long address, struct pt_regs *regs) \
|
2018-04-20 07:20:58 +07:00
|
|
|
{ \
|
|
|
|
return unhandled_exception(str, regs, signr, sicode, \
|
|
|
|
(void __user *)address); \
|
2013-01-18 16:42:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Entry points for exceptions NOT needing specific handling
|
|
|
|
*/
|
|
|
|
DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
|
|
|
|
DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
|
|
|
|
DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
|
2017-06-13 21:03:45 +07:00
|
|
|
DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", __weak do_memory_error, BUS_ADRERR)
|
2013-01-18 16:42:18 +07:00
|
|
|
DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
|
2013-04-04 16:07:52 +07:00
|
|
|
DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
|
2017-12-21 03:37:54 +07:00
|
|
|
DO_ERROR_INFO(SIGSEGV, "gcc generated __builtin_trap", do_trap5_error, 0)
|
2013-01-18 16:42:18 +07:00
|
|
|
|
2013-01-23 18:00:36 +07:00
|
|
|
/*
|
|
|
|
* Entry Point for Misaligned Data access Exception, for emulating in software
|
|
|
|
*/
|
2013-06-12 16:43:40 +07:00
|
|
|
int do_misaligned_access(unsigned long address, struct pt_regs *regs,
|
|
|
|
struct callee_regs *cregs)
|
2013-01-23 18:00:36 +07:00
|
|
|
{
|
2013-09-18 19:38:01 +07:00
|
|
|
/* If emulation not enabled, or failed, kill the task */
|
2013-06-12 16:43:40 +07:00
|
|
|
if (misaligned_fixup(address, regs, cregs) != 0)
|
|
|
|
return do_misaligned_error(address, regs);
|
2013-04-04 16:07:52 +07:00
|
|
|
|
2013-01-23 18:00:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-18 16:42:18 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Entry point for miscll errors such as Nested Exceptions
|
|
|
|
* -Duplicate TLB entry is handled seperately though
|
|
|
|
*/
|
2013-06-12 16:43:40 +07:00
|
|
|
void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
|
2013-01-18 16:42:18 +07:00
|
|
|
{
|
2017-08-29 16:14:20 +07:00
|
|
|
die("Unhandled Machine Check Exception", regs, address);
|
2013-01-18 16:42:18 +07:00
|
|
|
}
|
|
|
|
|
2013-01-22 18:33:59 +07:00
|
|
|
|
2013-01-18 16:42:18 +07:00
|
|
|
/*
|
|
|
|
* Entry point for traps induced by ARCompact TRAP_S <n> insn
|
|
|
|
* This is same family as TRAP0/SWI insn (use the same vector).
|
|
|
|
* The only difference being SWI insn take no operand, while TRAP_S does
|
|
|
|
* which reflects in ECR Reg as 8 bit param.
|
|
|
|
* Thus TRAP_S <n> can be used for specific purpose
|
|
|
|
* -1 used for software breakpointing (gdb)
|
|
|
|
* -2 used by kprobes
|
2017-12-21 03:37:54 +07:00
|
|
|
* -5 __builtin_trap() generated by gcc (2018.03 onwards) for toggle such as
|
|
|
|
* -fno-isolate-erroneous-paths-dereference
|
2013-01-18 16:42:18 +07:00
|
|
|
*/
|
2013-06-12 16:43:40 +07:00
|
|
|
void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
|
2013-01-18 16:42:18 +07:00
|
|
|
{
|
2013-06-12 16:43:40 +07:00
|
|
|
unsigned int param = regs->ecr_param;
|
2013-01-18 16:42:18 +07:00
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
case 1:
|
2013-06-12 16:43:40 +07:00
|
|
|
trap_is_brkpt(address, regs);
|
2013-01-18 16:42:18 +07:00
|
|
|
break;
|
|
|
|
|
2013-01-22 18:33:59 +07:00
|
|
|
case 2:
|
2013-06-12 16:43:40 +07:00
|
|
|
trap_is_kprobe(address, regs);
|
2013-01-22 18:33:59 +07:00
|
|
|
break;
|
|
|
|
|
2013-01-18 16:42:24 +07:00
|
|
|
case 3:
|
|
|
|
case 4:
|
2013-06-12 16:43:40 +07:00
|
|
|
kgdb_trap(regs);
|
2013-01-18 16:42:24 +07:00
|
|
|
break;
|
|
|
|
|
2017-12-21 03:37:54 +07:00
|
|
|
case 5:
|
|
|
|
do_trap5_error(address, regs);
|
|
|
|
break;
|
2013-01-18 16:42:18 +07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Entry point for Instruction Error Exception
|
2013-01-22 18:33:59 +07:00
|
|
|
* -For a corner case, ARC kprobes implementation resorts to using
|
|
|
|
* this exception, hence the check
|
2013-01-18 16:42:18 +07:00
|
|
|
*/
|
2013-06-12 16:43:40 +07:00
|
|
|
void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs)
|
2013-01-18 16:42:18 +07:00
|
|
|
{
|
2013-06-12 16:43:40 +07:00
|
|
|
int rc;
|
|
|
|
|
2013-01-22 18:33:59 +07:00
|
|
|
/* Check if this exception is caused by kprobes */
|
2013-06-12 16:43:40 +07:00
|
|
|
rc = notify_die(DIE_IERR, "kprobe_ierr", regs, address, 0, SIGILL);
|
|
|
|
if (rc == NOTIFY_STOP)
|
2013-01-22 18:33:59 +07:00
|
|
|
return;
|
|
|
|
|
2013-06-12 16:43:40 +07:00
|
|
|
insterror_is_error(address, regs);
|
2013-01-18 16:42:18 +07:00
|
|
|
}
|
2017-12-08 23:45:57 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* abort() call generated by older gcc for __builtin_trap()
|
|
|
|
*/
|
|
|
|
void abort(void)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__("trap_s 5\n");
|
|
|
|
}
|