Path: blob/master/arch/unicore32/kernel/fpu-ucf64.c
10817 views
/*1* linux/arch/unicore32/kernel/fpu-ucf64.c2*3* Code specific to PKUnity SoC and UniCore ISA4*5* Copyright (C) 2001-2010 GUAN Xue-tao6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*/11#include <linux/module.h>12#include <linux/types.h>13#include <linux/kernel.h>14#include <linux/signal.h>15#include <linux/sched.h>16#include <linux/init.h>1718#include <asm/fpu-ucf64.h>1920/*21* A special flag to tell the normalisation code not to normalise.22*/23#define F64_NAN_FLAG 0x1002425/*26* A bit pattern used to indicate the initial (unset) value of the27* exception mask, in case nothing handles an instruction. This28* doesn't include the NAN flag, which get masked out before29* we check for an error.30*/31#define F64_EXCEPTION_ERROR ((u32)-1 & ~F64_NAN_FLAG)3233/*34* Since we aren't building with -mfpu=f64, we need to code35* these instructions using their MRC/MCR equivalents.36*/37#define f64reg(_f64_) #_f64_3839#define cff(_f64_) ({ \40u32 __v; \41asm("cff %0, " f64reg(_f64_) "@ fmrx %0, " #_f64_ \42: "=r" (__v) : : "cc"); \43__v; \44})4546#define ctf(_f64_, _var_) \47asm("ctf %0, " f64reg(_f64_) "@ fmxr " #_f64_ ", %0" \48: : "r" (_var_) : "cc")4950/*51* Raise a SIGFPE for the current process.52* sicode describes the signal being raised.53*/54void ucf64_raise_sigfpe(unsigned int sicode, struct pt_regs *regs)55{56siginfo_t info;5758memset(&info, 0, sizeof(info));5960info.si_signo = SIGFPE;61info.si_code = sicode;62info.si_addr = (void __user *)(instruction_pointer(regs) - 4);6364/*65* This is the same as NWFPE, because it's not clear what66* this is used for67*/68current->thread.error_code = 0;69current->thread.trap_no = 6;7071send_sig_info(SIGFPE, &info, current);72}7374/*75* Handle exceptions of UniCore-F64.76*/77void ucf64_exchandler(u32 inst, u32 fpexc, struct pt_regs *regs)78{79u32 tmp = fpexc;80u32 exc = F64_EXCEPTION_ERROR & fpexc;8182pr_debug("UniCore-F64: instruction %08x fpscr %08x\n",83inst, fpexc);8485if (exc & FPSCR_CMPINSTR_BIT) {86if (exc & FPSCR_CON)87tmp |= FPSCR_CON;88else89tmp &= ~(FPSCR_CON);90exc &= ~(FPSCR_CMPINSTR_BIT | FPSCR_CON);91} else {92pr_debug(KERN_ERR "UniCore-F64 Error: unhandled exceptions\n");93pr_debug(KERN_ERR "UniCore-F64 FPSCR 0x%08x INST 0x%08x\n",94cff(FPSCR), inst);9596ucf64_raise_sigfpe(0, regs);97return;98}99100/*101* Update the FPSCR with the additional exception flags.102* Comparison instructions always return at least one of103* these flags set.104*/105tmp &= ~(FPSCR_TRAP | FPSCR_IOS | FPSCR_OFS | FPSCR_UFS |106FPSCR_IXS | FPSCR_HIS | FPSCR_IOC | FPSCR_OFC |107FPSCR_UFC | FPSCR_IXC | FPSCR_HIC);108109tmp |= exc;110ctf(FPSCR, tmp);111}112113/*114* F64 support code initialisation.115*/116static int __init ucf64_init(void)117{118ctf(FPSCR, 0x0); /* FPSCR_UFE | FPSCR_NDE perhaps better */119120printk(KERN_INFO "Enable UniCore-F64 support.\n");121122return 0;123}124125late_initcall(ucf64_init);126127128