blob: 42dd12a62ff5678128870616def1100519b8b398 [file] [log] [blame]
Michal Simekc4df4bc2009-03-27 14:25:13 +01001/*
2 * HW exception handling
3 *
4 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2008 PetaLogix
6 *
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
10 */
11
12/*
13 * This file handles the architecture-dependent parts of hardware exceptions
14 */
15
Michal Simekd64af912013-02-01 13:10:35 +010016#include <linux/export.h>
Michal Simekc4df4bc2009-03-27 14:25:13 +010017#include <linux/kernel.h>
18#include <linux/signal.h>
19#include <linux/sched.h>
20#include <linux/kallsyms.h>
Michal Simekc4df4bc2009-03-27 14:25:13 +010021
22#include <asm/exceptions.h>
23#include <asm/entry.h> /* For KM CPU var */
Michal Simek4bb73c32009-05-26 16:30:24 +020024#include <linux/uaccess.h>
25#include <linux/errno.h>
26#include <linux/ptrace.h>
Michal Simekc4df4bc2009-03-27 14:25:13 +010027#include <asm/current.h>
Michal Simek17b93142010-11-12 14:27:10 +010028#include <asm/cacheflush.h>
Michal Simekc4df4bc2009-03-27 14:25:13 +010029
30#define MICROBLAZE_ILL_OPCODE_EXCEPTION 0x02
31#define MICROBLAZE_IBUS_EXCEPTION 0x03
32#define MICROBLAZE_DBUS_EXCEPTION 0x04
33#define MICROBLAZE_DIV_ZERO_EXCEPTION 0x05
34#define MICROBLAZE_FPU_EXCEPTION 0x06
Michal Simek4bb73c32009-05-26 16:30:24 +020035#define MICROBLAZE_PRIVILEGED_EXCEPTION 0x07
Michal Simekc4df4bc2009-03-27 14:25:13 +010036
37static DEFINE_SPINLOCK(die_lock);
38
39void die(const char *str, struct pt_regs *fp, long err)
40{
41 console_verbose();
42 spin_lock_irq(&die_lock);
Michal Simek6bd55f02012-12-27 10:40:38 +010043 pr_warn("Oops: %s, sig: %ld\n", str, err);
Michal Simekc4df4bc2009-03-27 14:25:13 +010044 show_regs(fp);
45 spin_unlock_irq(&die_lock);
46 /* do_exit() should take care of panic'ing from an interrupt
47 * context so we don't handle it here
48 */
49 do_exit(err);
50}
51
Michal Simek751f1602010-08-03 11:26:51 +020052/* for user application debugging */
Michal Simekf6999802011-02-07 11:36:25 +010053asmlinkage void sw_exception(struct pt_regs *regs)
Michal Simek751f1602010-08-03 11:26:51 +020054{
55 _exception(SIGTRAP, regs, TRAP_BRKPT, regs->r16);
Michal Simek17b93142010-11-12 14:27:10 +010056 flush_dcache_range(regs->r16, regs->r16 + 0x4);
57 flush_icache_range(regs->r16, regs->r16 + 0x4);
Michal Simek751f1602010-08-03 11:26:51 +020058}
59
Michal Simekc4df4bc2009-03-27 14:25:13 +010060void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
61{
62 siginfo_t info;
63
Michal Simek6bd55f02012-12-27 10:40:38 +010064 if (kernel_mode(regs))
Michal Simekc4df4bc2009-03-27 14:25:13 +010065 die("Exception in kernel mode", regs, signr);
Michal Simek6bd55f02012-12-27 10:40:38 +010066
Michal Simekc4df4bc2009-03-27 14:25:13 +010067 info.si_signo = signr;
68 info.si_errno = 0;
69 info.si_code = code;
70 info.si_addr = (void __user *) addr;
71 force_sig_info(signr, &info, current);
72}
73
74asmlinkage void full_exception(struct pt_regs *regs, unsigned int type,
75 int fsr, int addr)
76{
Michal Simek4bb73c32009-05-26 16:30:24 +020077#ifdef CONFIG_MMU
Michal Simek4bb73c32009-05-26 16:30:24 +020078 addr = regs->pc;
79#endif
80
Michal Simekc4df4bc2009-03-27 14:25:13 +010081#if 0
Michal Simek6bd55f02012-12-27 10:40:38 +010082 pr_warn("Exception %02x in %s mode, FSR=%08x PC=%08x ESR=%08x\n",
Michal Simekc4df4bc2009-03-27 14:25:13 +010083 type, user_mode(regs) ? "user" : "kernel", fsr,
84 (unsigned int) regs->pc, (unsigned int) regs->esr);
85#endif
86
87 switch (type & 0x1F) {
88 case MICROBLAZE_ILL_OPCODE_EXCEPTION:
Michal Simek4bb73c32009-05-26 16:30:24 +020089 if (user_mode(regs)) {
Joe Perchesc4554c32010-09-11 22:10:51 -070090 pr_debug("Illegal opcode exception in user mode\n");
Michal Simek4bb73c32009-05-26 16:30:24 +020091 _exception(SIGILL, regs, ILL_ILLOPC, addr);
92 return;
93 }
Michal Simek6bd55f02012-12-27 10:40:38 +010094 pr_warn("Illegal opcode exception in kernel mode.\n");
Michal Simek4bb73c32009-05-26 16:30:24 +020095 die("opcode exception", regs, SIGBUS);
Michal Simekc4df4bc2009-03-27 14:25:13 +010096 break;
97 case MICROBLAZE_IBUS_EXCEPTION:
98 if (user_mode(regs)) {
Joe Perchesc4554c32010-09-11 22:10:51 -070099 pr_debug("Instruction bus error exception in user mode\n");
Michal Simekc4df4bc2009-03-27 14:25:13 +0100100 _exception(SIGBUS, regs, BUS_ADRERR, addr);
101 return;
102 }
Michal Simek6bd55f02012-12-27 10:40:38 +0100103 pr_warn("Instruction bus error exception in kernel mode.\n");
Michal Simekc4df4bc2009-03-27 14:25:13 +0100104 die("bus exception", regs, SIGBUS);
105 break;
106 case MICROBLAZE_DBUS_EXCEPTION:
107 if (user_mode(regs)) {
Joe Perchesc4554c32010-09-11 22:10:51 -0700108 pr_debug("Data bus error exception in user mode\n");
Michal Simekc4df4bc2009-03-27 14:25:13 +0100109 _exception(SIGBUS, regs, BUS_ADRERR, addr);
110 return;
111 }
Michal Simek6bd55f02012-12-27 10:40:38 +0100112 pr_warn("Data bus error exception in kernel mode.\n");
Michal Simekc4df4bc2009-03-27 14:25:13 +0100113 die("bus exception", regs, SIGBUS);
114 break;
115 case MICROBLAZE_DIV_ZERO_EXCEPTION:
Michal Simek4bb73c32009-05-26 16:30:24 +0200116 if (user_mode(regs)) {
Joe Perchesc4554c32010-09-11 22:10:51 -0700117 pr_debug("Divide by zero exception in user mode\n");
Edgar E. Iglesias15ec0902011-08-22 19:58:06 +0200118 _exception(SIGFPE, regs, FPE_INTDIV, addr);
Michal Simek4bb73c32009-05-26 16:30:24 +0200119 return;
120 }
Michal Simek6bd55f02012-12-27 10:40:38 +0100121 pr_warn("Divide by zero exception in kernel mode.\n");
Randy Dunlapf3ff8212010-04-21 14:11:34 -0700122 die("Divide by zero exception", regs, SIGBUS);
Michal Simekc4df4bc2009-03-27 14:25:13 +0100123 break;
Michal Simekc4df4bc2009-03-27 14:25:13 +0100124 case MICROBLAZE_FPU_EXCEPTION:
Joe Perchesc4554c32010-09-11 22:10:51 -0700125 pr_debug("FPU exception\n");
Michal Simekc4df4bc2009-03-27 14:25:13 +0100126 /* IEEE FP exception */
127 /* I removed fsr variable and use code var for storing fsr */
128 if (fsr & FSR_IO)
129 fsr = FPE_FLTINV;
130 else if (fsr & FSR_OF)
131 fsr = FPE_FLTOVF;
132 else if (fsr & FSR_UF)
133 fsr = FPE_FLTUND;
134 else if (fsr & FSR_DZ)
135 fsr = FPE_FLTDIV;
136 else if (fsr & FSR_DO)
137 fsr = FPE_FLTRES;
138 _exception(SIGFPE, regs, fsr, addr);
139 break;
140
Michal Simek4bb73c32009-05-26 16:30:24 +0200141#ifdef CONFIG_MMU
142 case MICROBLAZE_PRIVILEGED_EXCEPTION:
Joe Perchesc4554c32010-09-11 22:10:51 -0700143 pr_debug("Privileged exception\n");
Michal Simek04256092010-08-03 11:32:20 +0200144 _exception(SIGILL, regs, ILL_PRVOPC, addr);
Michal Simek4bb73c32009-05-26 16:30:24 +0200145 break;
146#endif
Michal Simekc4df4bc2009-03-27 14:25:13 +0100147 default:
Michal Simek4bb73c32009-05-26 16:30:24 +0200148 /* FIXME what to do in unexpected exception */
Michal Simek6bd55f02012-12-27 10:40:38 +0100149 pr_warn("Unexpected exception %02x PC=%08x in %s mode\n",
150 type, (unsigned int) addr,
Michal Simekc4df4bc2009-03-27 14:25:13 +0100151 kernel_mode(regs) ? "kernel" : "user");
152 }
153 return;
154}