Path: blob/master/arch/microblaze/kernel/exceptions.c
10817 views
/*1* HW exception handling2*3* Copyright (C) 2008-2009 Michal Simek <[email protected]>4* Copyright (C) 2008 PetaLogix5*6* This file is subject to the terms and conditions of the GNU General7* Public License. See the file COPYING in the main directory of this8* archive for more details.9*/1011/*12* This file handles the architecture-dependent parts of hardware exceptions13*/1415#include <linux/kernel.h>16#include <linux/signal.h>17#include <linux/sched.h>18#include <linux/kallsyms.h>19#include <linux/module.h>2021#include <asm/exceptions.h>22#include <asm/entry.h> /* For KM CPU var */23#include <linux/uaccess.h>24#include <linux/errno.h>25#include <linux/ptrace.h>26#include <asm/current.h>27#include <asm/cacheflush.h>2829#define MICROBLAZE_ILL_OPCODE_EXCEPTION 0x0230#define MICROBLAZE_IBUS_EXCEPTION 0x0331#define MICROBLAZE_DBUS_EXCEPTION 0x0432#define MICROBLAZE_DIV_ZERO_EXCEPTION 0x0533#define MICROBLAZE_FPU_EXCEPTION 0x0634#define MICROBLAZE_PRIVILEGED_EXCEPTION 0x073536static DEFINE_SPINLOCK(die_lock);3738void die(const char *str, struct pt_regs *fp, long err)39{40console_verbose();41spin_lock_irq(&die_lock);42printk(KERN_WARNING "Oops: %s, sig: %ld\n", str, err);43show_regs(fp);44spin_unlock_irq(&die_lock);45/* do_exit() should take care of panic'ing from an interrupt46* context so we don't handle it here47*/48do_exit(err);49}5051/* for user application debugging */52asmlinkage void sw_exception(struct pt_regs *regs)53{54_exception(SIGTRAP, regs, TRAP_BRKPT, regs->r16);55flush_dcache_range(regs->r16, regs->r16 + 0x4);56flush_icache_range(regs->r16, regs->r16 + 0x4);57}5859void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)60{61siginfo_t info;6263if (kernel_mode(regs)) {64die("Exception in kernel mode", regs, signr);65}66info.si_signo = signr;67info.si_errno = 0;68info.si_code = code;69info.si_addr = (void __user *) addr;70force_sig_info(signr, &info, current);71}7273asmlinkage void full_exception(struct pt_regs *regs, unsigned int type,74int fsr, int addr)75{76#ifdef CONFIG_MMU77addr = regs->pc;78#endif7980#if 081printk(KERN_WARNING "Exception %02x in %s mode, FSR=%08x PC=%08x " \82"ESR=%08x\n",83type, user_mode(regs) ? "user" : "kernel", fsr,84(unsigned int) regs->pc, (unsigned int) regs->esr);85#endif8687switch (type & 0x1F) {88case MICROBLAZE_ILL_OPCODE_EXCEPTION:89if (user_mode(regs)) {90pr_debug("Illegal opcode exception in user mode\n");91_exception(SIGILL, regs, ILL_ILLOPC, addr);92return;93}94printk(KERN_WARNING "Illegal opcode exception " \95"in kernel mode.\n");96die("opcode exception", regs, SIGBUS);97break;98case MICROBLAZE_IBUS_EXCEPTION:99if (user_mode(regs)) {100pr_debug("Instruction bus error exception in user mode\n");101_exception(SIGBUS, regs, BUS_ADRERR, addr);102return;103}104printk(KERN_WARNING "Instruction bus error exception " \105"in kernel mode.\n");106die("bus exception", regs, SIGBUS);107break;108case MICROBLAZE_DBUS_EXCEPTION:109if (user_mode(regs)) {110pr_debug("Data bus error exception in user mode\n");111_exception(SIGBUS, regs, BUS_ADRERR, addr);112return;113}114printk(KERN_WARNING "Data bus error exception " \115"in kernel mode.\n");116die("bus exception", regs, SIGBUS);117break;118case MICROBLAZE_DIV_ZERO_EXCEPTION:119if (user_mode(regs)) {120pr_debug("Divide by zero exception in user mode\n");121_exception(SIGILL, regs, FPE_INTDIV, addr);122return;123}124printk(KERN_WARNING "Divide by zero exception " \125"in kernel mode.\n");126die("Divide by zero exception", regs, SIGBUS);127break;128case MICROBLAZE_FPU_EXCEPTION:129pr_debug("FPU exception\n");130/* IEEE FP exception */131/* I removed fsr variable and use code var for storing fsr */132if (fsr & FSR_IO)133fsr = FPE_FLTINV;134else if (fsr & FSR_OF)135fsr = FPE_FLTOVF;136else if (fsr & FSR_UF)137fsr = FPE_FLTUND;138else if (fsr & FSR_DZ)139fsr = FPE_FLTDIV;140else if (fsr & FSR_DO)141fsr = FPE_FLTRES;142_exception(SIGFPE, regs, fsr, addr);143break;144145#ifdef CONFIG_MMU146case MICROBLAZE_PRIVILEGED_EXCEPTION:147pr_debug("Privileged exception\n");148_exception(SIGILL, regs, ILL_PRVOPC, addr);149break;150#endif151default:152/* FIXME what to do in unexpected exception */153printk(KERN_WARNING "Unexpected exception %02x "154"PC=%08x in %s mode\n", type, (unsigned int) addr,155kernel_mode(regs) ? "kernel" : "user");156}157return;158}159160161