10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/types.h>
13 #include <linux/sched.h>
14 #include <linux/signal.h>
15 #include <linux/perf_event.h>
17 #include <asm/uaccess.h>
18 #include <asm/processor.h>
26 #define FPUL (fregs->fpul)
27 #define FPSCR (fregs->fpscr)
28 #define FPSCR_RM (FPSCR&3)
29 #define FPSCR_DN ((FPSCR>>18)&1)
30 #define FPSCR_PR ((FPSCR>>19)&1)
31 #define FPSCR_SZ ((FPSCR>>20)&1)
32 #define FPSCR_FR ((FPSCR>>21)&1)
33 #define FPSCR_MASK 0x003fffffUL
35 #define BANK(n) (n^(FPSCR_FR?16:0))
36 #define FR ((unsigned long*)(fregs->fp_regs))
37 #define FR0 (FR[BANK(0)])
38 #define FRn (FR[BANK(n)])
39 #define FRm (FR[BANK(m)])
40 #define DR ((unsigned long long*)(fregs->fp_regs))
41 #define DRn (DR[BANK(n)/2])
42 #define DRm (DR[BANK(m)/2])
44 #define XREG(n) (n^16)
45 #define XFn (FR[BANK(XREG(n))])
46 #define XFm (FR[BANK(XREG(m))])
47 #define XDn (DR[BANK(XREG(n))/2])
48 #define XDm (DR[BANK(XREG(m))/2])
50 #define R0 (regs->regs[0])
51 #define Rn (regs->regs[n])
52 #define Rm (regs->regs[m])
54 #define WRITE(d,a) ({if(put_user(d, (typeof (d)*)a)) return -EFAULT;})
55 #define READ(d,a) ({if(get_user(d, (typeof (d)*)a)) return -EFAULT;})
57 #define PACK_S(r,f) FP_PACK_SP(&r,f)
58 #define UNPACK_S(f,r) FP_UNPACK_SP(f,&r)
60 {u32 t[2]; FP_PACK_DP(t,f); ((u32*)&r)[0]=t[1]; ((u32*)&r)[1]=t[0];}
61 #define UNPACK_D(f,r) \
62 {u32 t[2]; t[0]=((u32*)&r)[1]; t[1]=((u32*)&r)[0]; FP_UNPACK_DP(f,t);}
65 #define BOTH_PRmn(op,x) \
66 FP_DECL_EX; if(FPSCR_PR) op(D,x,DRm,DRn); else op(S,x,FRm,FRn);
68 #define CMP_X(SZ,R,M,N) do{ \
69 FP_DECL_##SZ(Fm); FP_DECL_##SZ(Fn); \
70 UNPACK_##SZ(Fm, M); UNPACK_##SZ(Fn, N); \
71 FP_CMP_##SZ(R, Fn, Fm, 2); }while(0)
72 #define EQ_X(SZ,R,M,N) do{ \
73 FP_DECL_##SZ(Fm); FP_DECL_##SZ(Fn); \
74 UNPACK_##SZ(Fm, M); UNPACK_##SZ(Fn, N); \
75 FP_CMP_EQ_##SZ(R, Fn, Fm); }while(0)
76 #define CMP(OP) ({ int r; BOTH_PRmn(OP##_X,r); r; })
99 #define ARITH_X(SZ,OP,M,N) do{ \
100 FP_DECL_##SZ(Fm); FP_DECL_##SZ(Fn); FP_DECL_##SZ(Fr); \
101 UNPACK_##SZ(Fm, M); UNPACK_##SZ(Fn, N); \
102 FP_##OP##_##SZ(Fr, Fn, Fm); \
103 PACK_##SZ(N, Fr); }while(0)
152 #define FMOV_EXT(x) if(x&1) x+=16-1
276 #define NOTYETn(i) static int i(struct sh_fpu_soft_struct *fregs, int n) \
277 { printk( #i " not yet done.\n"); return 0; }
285 #define EMU_FLOAT_X(SZ,N) do { \
287 FP_FROM_INT_##SZ(Fn, FPUL, 32, int); \
288 PACK_##SZ(N, Fn); }while(0)
301 #define EMU_FTRC_X(SZ,N) do { \
303 UNPACK_##SZ(Fn, N); \
304 FP_TO_INT_##SZ(FPUL, Fn, 32, 1); }while(0)
393 fld0, fld1, fcnvsd, fcnvds, fnop_n, fnop_n, fipr, id_fxfd
398 fmov_mem_reg, fmov_inc_reg, fmov_reg_mem, fmov_reg_dec,
399 fmov_reg_reg, id_fnxd, fmac, fnop_mn};
406 fxchg(fregs, flag[x >> 2]);
420 return (fnxd[x])(fregs,
n);
426 int n = (code >> 8) & 0xf, m = (code >> 4) & 0xf, x = code & 0xf;
427 return (fnmx[x])(fregs,
regs,
m,
n);
433 int n = ((code >> 8) & 0xf);
436 switch (code & 0xf0ff) {
464 if ((code & 0xf000) == 0xf000)
465 return id_fnmx(fregs, regs, code);
467 return id_sys(fregs, regs, code);
479 unsigned long du,
dl;
480 unsigned long x = fpu->fpul;
481 int exp = 1023 - 126;
483 if (x != 0 && (x & 0x7f800000) == 0) {
484 du = (x & 0x80000000);
485 while ((x & 0x00800000) == 0) {
490 du |= (exp << 20) | (x >> 3);
505 static int ieee_fpe_handler(
struct pt_regs *regs)
507 unsigned short insn = *(
unsigned short *)regs->
pc;
508 unsigned short finsn;
509 unsigned long nextpc;
518 (nib[0] == 0x4 && nib[2] == 0x0 && nib[3] == 0
xb))
519 regs->
pr = regs->
pc + 4;
521 if (nib[0] == 0xa || nib[0] == 0
xb) {
522 nextpc = regs->
pc + 4 + ((
short) ((insn & 0xfff) << 4) >> 3);
523 finsn = *(
unsigned short *) (regs->
pc + 2);
524 }
else if (nib[0] == 0x8 && nib[1] == 0xd) {
526 nextpc = regs->
pc + 4 + ((
char) (insn & 0xff) << 1);
528 nextpc = regs->
pc + 4;
529 finsn = *(
unsigned short *) (regs->
pc + 2);
530 }
else if (nib[0] == 0x8 && nib[1] == 0xf) {
532 nextpc = regs->
pc + 4;
534 nextpc = regs->
pc + 4 + ((
char) (insn & 0xff) << 1);
535 finsn = *(
unsigned short *) (regs->
pc + 2);
536 }
else if (nib[0] == 0x4 && nib[3] == 0
xb &&
537 (nib[2] == 0x0 || nib[2] == 0x2)) {
538 nextpc = regs->
regs[nib[1]];
539 finsn = *(
unsigned short *) (regs->
pc + 2);
540 }
else if (nib[0] == 0x0 && nib[3] == 0x3 &&
541 (nib[2] == 0x0 || nib[2] == 0x2)) {
542 nextpc = regs->
pc + 4 + regs->
regs[nib[1]];
543 finsn = *(
unsigned short *) (regs->
pc + 2);
544 }
else if (insn == 0x000b) {
546 finsn = *(
unsigned short *) (regs->
pc + 2);
548 nextpc = regs->
pc + 2;
552 if ((finsn & 0xf1ff) == 0xf0ad) {
555 if ((tsk->
thread.xstate->softfpu.fpscr & (1 << 17))) {
557 denormal_to_double (&tsk->
thread.xstate->softfpu,
559 tsk->
thread.xstate->softfpu.fpscr &=
560 ~(FPSCR_CAUSE_MASK | FPSCR_FLAG_MASK);
578 unsigned long r6,
unsigned long r7,
584 if (ieee_fpe_handler (®s))
591 info.si_addr = (
void __user *)regs.
pc;
606 for (i = 0; i < 16; i++) {
630 return fpu_emulate(inst, fpu, regs);