1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
25cd27208SKumar Gala /*
35cd27208SKumar Gala * Copyright (C) 1999 Eddie C. Dost (ecd@atecom.com)
45cd27208SKumar Gala */
55cd27208SKumar Gala
65cd27208SKumar Gala #include <linux/types.h>
75cd27208SKumar Gala #include <linux/sched.h>
85cd27208SKumar Gala
97c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
105cd27208SKumar Gala #include <asm/reg.h>
11037f0eedSKevin Hao #include <asm/switch_to.h>
125cd27208SKumar Gala
13d2b194edSKumar Gala #include <asm/sfp-machine.h>
14d2b194edSKumar Gala #include <math-emu/double.h>
155cd27208SKumar Gala
165cd27208SKumar Gala #define FLOATFUNC(x) extern int x(void *, void *, void *, void *)
175cd27208SKumar Gala
18e05c0e81SKevin Hao /* The instructions list which may be not implemented by a hardware FPU */
19e05c0e81SKevin Hao FLOATFUNC(fre);
20e05c0e81SKevin Hao FLOATFUNC(frsqrtes);
21e05c0e81SKevin Hao FLOATFUNC(fsqrt);
22e05c0e81SKevin Hao FLOATFUNC(fsqrts);
23e05c0e81SKevin Hao FLOATFUNC(mtfsf);
24e05c0e81SKevin Hao FLOATFUNC(mtfsfi);
25e05c0e81SKevin Hao
26e05c0e81SKevin Hao #ifdef CONFIG_MATH_EMULATION_HW_UNIMPLEMENTED
27*7245fc5bSChristophe Leroy #undef FLOATFUNC
28e05c0e81SKevin Hao #define FLOATFUNC(x) static inline int x(void *op1, void *op2, void *op3, \
29*7245fc5bSChristophe Leroy void *op4) { return 0; }
30e05c0e81SKevin Hao #endif
31e05c0e81SKevin Hao
325cd27208SKumar Gala FLOATFUNC(fadd);
335cd27208SKumar Gala FLOATFUNC(fadds);
345cd27208SKumar Gala FLOATFUNC(fdiv);
355cd27208SKumar Gala FLOATFUNC(fdivs);
365cd27208SKumar Gala FLOATFUNC(fmul);
375cd27208SKumar Gala FLOATFUNC(fmuls);
385cd27208SKumar Gala FLOATFUNC(fsub);
395cd27208SKumar Gala FLOATFUNC(fsubs);
405cd27208SKumar Gala
415cd27208SKumar Gala FLOATFUNC(fmadd);
425cd27208SKumar Gala FLOATFUNC(fmadds);
435cd27208SKumar Gala FLOATFUNC(fmsub);
445cd27208SKumar Gala FLOATFUNC(fmsubs);
455cd27208SKumar Gala FLOATFUNC(fnmadd);
465cd27208SKumar Gala FLOATFUNC(fnmadds);
475cd27208SKumar Gala FLOATFUNC(fnmsub);
485cd27208SKumar Gala FLOATFUNC(fnmsubs);
495cd27208SKumar Gala
505cd27208SKumar Gala FLOATFUNC(fctiw);
515cd27208SKumar Gala FLOATFUNC(fctiwz);
525cd27208SKumar Gala FLOATFUNC(frsp);
535cd27208SKumar Gala
545cd27208SKumar Gala FLOATFUNC(fcmpo);
555cd27208SKumar Gala FLOATFUNC(fcmpu);
565cd27208SKumar Gala
575cd27208SKumar Gala FLOATFUNC(mcrfs);
585cd27208SKumar Gala FLOATFUNC(mffs);
595cd27208SKumar Gala FLOATFUNC(mtfsb0);
605cd27208SKumar Gala FLOATFUNC(mtfsb1);
615cd27208SKumar Gala
625cd27208SKumar Gala FLOATFUNC(lfd);
635cd27208SKumar Gala FLOATFUNC(lfs);
645cd27208SKumar Gala
655cd27208SKumar Gala FLOATFUNC(stfd);
665cd27208SKumar Gala FLOATFUNC(stfs);
675cd27208SKumar Gala FLOATFUNC(stfiwx);
685cd27208SKumar Gala
695cd27208SKumar Gala FLOATFUNC(fabs);
705cd27208SKumar Gala FLOATFUNC(fmr);
715cd27208SKumar Gala FLOATFUNC(fnabs);
725cd27208SKumar Gala FLOATFUNC(fneg);
735cd27208SKumar Gala
745cd27208SKumar Gala /* Optional */
755cd27208SKumar Gala FLOATFUNC(fres);
765cd27208SKumar Gala FLOATFUNC(frsqrte);
775cd27208SKumar Gala FLOATFUNC(fsel);
785cd27208SKumar Gala
795cd27208SKumar Gala
805cd27208SKumar Gala #define OP31 0x1f /* 31 */
815cd27208SKumar Gala #define LFS 0x30 /* 48 */
825cd27208SKumar Gala #define LFSU 0x31 /* 49 */
835cd27208SKumar Gala #define LFD 0x32 /* 50 */
845cd27208SKumar Gala #define LFDU 0x33 /* 51 */
855cd27208SKumar Gala #define STFS 0x34 /* 52 */
865cd27208SKumar Gala #define STFSU 0x35 /* 53 */
875cd27208SKumar Gala #define STFD 0x36 /* 54 */
885cd27208SKumar Gala #define STFDU 0x37 /* 55 */
895cd27208SKumar Gala #define OP59 0x3b /* 59 */
905cd27208SKumar Gala #define OP63 0x3f /* 63 */
915cd27208SKumar Gala
925cd27208SKumar Gala /* Opcode 31: */
935cd27208SKumar Gala /* X-Form: */
945cd27208SKumar Gala #define LFSX 0x217 /* 535 */
955cd27208SKumar Gala #define LFSUX 0x237 /* 567 */
965cd27208SKumar Gala #define LFDX 0x257 /* 599 */
975cd27208SKumar Gala #define LFDUX 0x277 /* 631 */
985cd27208SKumar Gala #define STFSX 0x297 /* 663 */
995cd27208SKumar Gala #define STFSUX 0x2b7 /* 695 */
1005cd27208SKumar Gala #define STFDX 0x2d7 /* 727 */
1015cd27208SKumar Gala #define STFDUX 0x2f7 /* 759 */
1025cd27208SKumar Gala #define STFIWX 0x3d7 /* 983 */
1035cd27208SKumar Gala
1045cd27208SKumar Gala /* Opcode 59: */
1055cd27208SKumar Gala /* A-Form: */
1065cd27208SKumar Gala #define FDIVS 0x012 /* 18 */
1075cd27208SKumar Gala #define FSUBS 0x014 /* 20 */
1085cd27208SKumar Gala #define FADDS 0x015 /* 21 */
1095cd27208SKumar Gala #define FSQRTS 0x016 /* 22 */
1105cd27208SKumar Gala #define FRES 0x018 /* 24 */
1115cd27208SKumar Gala #define FMULS 0x019 /* 25 */
11204ae9001SBenjamin Herrenschmidt #define FRSQRTES 0x01a /* 26 */
1135cd27208SKumar Gala #define FMSUBS 0x01c /* 28 */
1145cd27208SKumar Gala #define FMADDS 0x01d /* 29 */
1155cd27208SKumar Gala #define FNMSUBS 0x01e /* 30 */
1165cd27208SKumar Gala #define FNMADDS 0x01f /* 31 */
1175cd27208SKumar Gala
1185cd27208SKumar Gala /* Opcode 63: */
1195cd27208SKumar Gala /* A-Form: */
1205cd27208SKumar Gala #define FDIV 0x012 /* 18 */
1215cd27208SKumar Gala #define FSUB 0x014 /* 20 */
1225cd27208SKumar Gala #define FADD 0x015 /* 21 */
1235cd27208SKumar Gala #define FSQRT 0x016 /* 22 */
1245cd27208SKumar Gala #define FSEL 0x017 /* 23 */
12504ae9001SBenjamin Herrenschmidt #define FRE 0x018 /* 24 */
1265cd27208SKumar Gala #define FMUL 0x019 /* 25 */
1275cd27208SKumar Gala #define FRSQRTE 0x01a /* 26 */
1285cd27208SKumar Gala #define FMSUB 0x01c /* 28 */
1295cd27208SKumar Gala #define FMADD 0x01d /* 29 */
1305cd27208SKumar Gala #define FNMSUB 0x01e /* 30 */
1315cd27208SKumar Gala #define FNMADD 0x01f /* 31 */
1325cd27208SKumar Gala
1335cd27208SKumar Gala /* X-Form: */
1345cd27208SKumar Gala #define FCMPU 0x000 /* 0 */
1355cd27208SKumar Gala #define FRSP 0x00c /* 12 */
1365cd27208SKumar Gala #define FCTIW 0x00e /* 14 */
1375cd27208SKumar Gala #define FCTIWZ 0x00f /* 15 */
1385cd27208SKumar Gala #define FCMPO 0x020 /* 32 */
1395cd27208SKumar Gala #define MTFSB1 0x026 /* 38 */
1405cd27208SKumar Gala #define FNEG 0x028 /* 40 */
1415cd27208SKumar Gala #define MCRFS 0x040 /* 64 */
1425cd27208SKumar Gala #define MTFSB0 0x046 /* 70 */
1435cd27208SKumar Gala #define FMR 0x048 /* 72 */
1445cd27208SKumar Gala #define MTFSFI 0x086 /* 134 */
1455cd27208SKumar Gala #define FNABS 0x088 /* 136 */
1465cd27208SKumar Gala #define FABS 0x108 /* 264 */
1475cd27208SKumar Gala #define MFFS 0x247 /* 583 */
1485cd27208SKumar Gala #define MTFSF 0x2c7 /* 711 */
1495cd27208SKumar Gala
1505cd27208SKumar Gala
1515cd27208SKumar Gala #define AB 2
1525cd27208SKumar Gala #define AC 3
1535cd27208SKumar Gala #define ABC 4
1545cd27208SKumar Gala #define D 5
1555cd27208SKumar Gala #define DU 6
1565cd27208SKumar Gala #define X 7
1575cd27208SKumar Gala #define XA 8
1585cd27208SKumar Gala #define XB 9
1595cd27208SKumar Gala #define XCR 11
1605cd27208SKumar Gala #define XCRB 12
1615cd27208SKumar Gala #define XCRI 13
1625cd27208SKumar Gala #define XCRL 16
1635cd27208SKumar Gala #define XE 14
1645cd27208SKumar Gala #define XEU 15
1655cd27208SKumar Gala #define XFLB 10
1665cd27208SKumar Gala
1675cd27208SKumar Gala static int
record_exception(struct pt_regs * regs,int eflag)1685cd27208SKumar Gala record_exception(struct pt_regs *regs, int eflag)
1695cd27208SKumar Gala {
1705cd27208SKumar Gala u32 fpscr;
1715cd27208SKumar Gala
1725cd27208SKumar Gala fpscr = __FPU_FPSCR;
1735cd27208SKumar Gala
1745cd27208SKumar Gala if (eflag) {
1755cd27208SKumar Gala fpscr |= FPSCR_FX;
1765cd27208SKumar Gala if (eflag & EFLAG_OVERFLOW)
1775cd27208SKumar Gala fpscr |= FPSCR_OX;
1785cd27208SKumar Gala if (eflag & EFLAG_UNDERFLOW)
1795cd27208SKumar Gala fpscr |= FPSCR_UX;
1805cd27208SKumar Gala if (eflag & EFLAG_DIVZERO)
1815cd27208SKumar Gala fpscr |= FPSCR_ZX;
1825cd27208SKumar Gala if (eflag & EFLAG_INEXACT)
1835cd27208SKumar Gala fpscr |= FPSCR_XX;
184d2b194edSKumar Gala if (eflag & EFLAG_INVALID)
185d2b194edSKumar Gala fpscr |= FPSCR_VX;
1865cd27208SKumar Gala if (eflag & EFLAG_VXSNAN)
1875cd27208SKumar Gala fpscr |= FPSCR_VXSNAN;
1885cd27208SKumar Gala if (eflag & EFLAG_VXISI)
1895cd27208SKumar Gala fpscr |= FPSCR_VXISI;
1905cd27208SKumar Gala if (eflag & EFLAG_VXIDI)
1915cd27208SKumar Gala fpscr |= FPSCR_VXIDI;
1925cd27208SKumar Gala if (eflag & EFLAG_VXZDZ)
1935cd27208SKumar Gala fpscr |= FPSCR_VXZDZ;
1945cd27208SKumar Gala if (eflag & EFLAG_VXIMZ)
1955cd27208SKumar Gala fpscr |= FPSCR_VXIMZ;
1965cd27208SKumar Gala if (eflag & EFLAG_VXVC)
1975cd27208SKumar Gala fpscr |= FPSCR_VXVC;
1985cd27208SKumar Gala if (eflag & EFLAG_VXSOFT)
1995cd27208SKumar Gala fpscr |= FPSCR_VXSOFT;
2005cd27208SKumar Gala if (eflag & EFLAG_VXSQRT)
2015cd27208SKumar Gala fpscr |= FPSCR_VXSQRT;
2025cd27208SKumar Gala if (eflag & EFLAG_VXCVI)
2035cd27208SKumar Gala fpscr |= FPSCR_VXCVI;
2045cd27208SKumar Gala }
2055cd27208SKumar Gala
206d2b194edSKumar Gala // fpscr &= ~(FPSCR_VX);
2075cd27208SKumar Gala if (fpscr & (FPSCR_VXSNAN | FPSCR_VXISI | FPSCR_VXIDI |
2085cd27208SKumar Gala FPSCR_VXZDZ | FPSCR_VXIMZ | FPSCR_VXVC |
2095cd27208SKumar Gala FPSCR_VXSOFT | FPSCR_VXSQRT | FPSCR_VXCVI))
2105cd27208SKumar Gala fpscr |= FPSCR_VX;
2115cd27208SKumar Gala
2125cd27208SKumar Gala fpscr &= ~(FPSCR_FEX);
2135cd27208SKumar Gala if (((fpscr & FPSCR_VX) && (fpscr & FPSCR_VE)) ||
2145cd27208SKumar Gala ((fpscr & FPSCR_OX) && (fpscr & FPSCR_OE)) ||
2155cd27208SKumar Gala ((fpscr & FPSCR_UX) && (fpscr & FPSCR_UE)) ||
2165cd27208SKumar Gala ((fpscr & FPSCR_ZX) && (fpscr & FPSCR_ZE)) ||
2175cd27208SKumar Gala ((fpscr & FPSCR_XX) && (fpscr & FPSCR_XE)))
2185cd27208SKumar Gala fpscr |= FPSCR_FEX;
2195cd27208SKumar Gala
2205cd27208SKumar Gala __FPU_FPSCR = fpscr;
2215cd27208SKumar Gala
2225cd27208SKumar Gala return (fpscr & FPSCR_FEX) ? 1 : 0;
2235cd27208SKumar Gala }
2245cd27208SKumar Gala
2255cd27208SKumar Gala int
do_mathemu(struct pt_regs * regs)2265cd27208SKumar Gala do_mathemu(struct pt_regs *regs)
2275cd27208SKumar Gala {
228e448e1e7SChristophe Leroy void *op0 = NULL, *op1 = NULL, *op2 = NULL, *op3 = NULL;
2295cd27208SKumar Gala unsigned long pc = regs->nip;
2305cd27208SKumar Gala signed short sdisp;
2315cd27208SKumar Gala u32 insn = 0;
2325cd27208SKumar Gala int idx = 0;
2335cd27208SKumar Gala int (*func)(void *, void *, void *, void *);
2345cd27208SKumar Gala int type = 0;
2355cd27208SKumar Gala int eflag, trap;
2365cd27208SKumar Gala
237e448e1e7SChristophe Leroy if (get_user(insn, (u32 __user *)pc))
2385cd27208SKumar Gala return -EFAULT;
2395cd27208SKumar Gala
2405cd27208SKumar Gala switch (insn >> 26) {
2415cd27208SKumar Gala case LFS: func = lfs; type = D; break;
2425cd27208SKumar Gala case LFSU: func = lfs; type = DU; break;
2435cd27208SKumar Gala case LFD: func = lfd; type = D; break;
2445cd27208SKumar Gala case LFDU: func = lfd; type = DU; break;
2455cd27208SKumar Gala case STFS: func = stfs; type = D; break;
2465cd27208SKumar Gala case STFSU: func = stfs; type = DU; break;
2475cd27208SKumar Gala case STFD: func = stfd; type = D; break;
2485cd27208SKumar Gala case STFDU: func = stfd; type = DU; break;
2495cd27208SKumar Gala
2505cd27208SKumar Gala case OP31:
2515cd27208SKumar Gala switch ((insn >> 1) & 0x3ff) {
2525cd27208SKumar Gala case LFSX: func = lfs; type = XE; break;
2535cd27208SKumar Gala case LFSUX: func = lfs; type = XEU; break;
2545cd27208SKumar Gala case LFDX: func = lfd; type = XE; break;
2555cd27208SKumar Gala case LFDUX: func = lfd; type = XEU; break;
2565cd27208SKumar Gala case STFSX: func = stfs; type = XE; break;
2575cd27208SKumar Gala case STFSUX: func = stfs; type = XEU; break;
2585cd27208SKumar Gala case STFDX: func = stfd; type = XE; break;
2595cd27208SKumar Gala case STFDUX: func = stfd; type = XEU; break;
2605cd27208SKumar Gala case STFIWX: func = stfiwx; type = XE; break;
2615cd27208SKumar Gala default:
2625cd27208SKumar Gala goto illegal;
2635cd27208SKumar Gala }
2645cd27208SKumar Gala break;
2655cd27208SKumar Gala
2665cd27208SKumar Gala case OP59:
2675cd27208SKumar Gala switch ((insn >> 1) & 0x1f) {
2685cd27208SKumar Gala case FDIVS: func = fdivs; type = AB; break;
2695cd27208SKumar Gala case FSUBS: func = fsubs; type = AB; break;
2705cd27208SKumar Gala case FADDS: func = fadds; type = AB; break;
27104ae9001SBenjamin Herrenschmidt case FSQRTS: func = fsqrts; type = XB; break;
27204ae9001SBenjamin Herrenschmidt case FRES: func = fres; type = XB; break;
2735cd27208SKumar Gala case FMULS: func = fmuls; type = AC; break;
27404ae9001SBenjamin Herrenschmidt case FRSQRTES: func = frsqrtes;type = XB; break;
2755cd27208SKumar Gala case FMSUBS: func = fmsubs; type = ABC; break;
2765cd27208SKumar Gala case FMADDS: func = fmadds; type = ABC; break;
2775cd27208SKumar Gala case FNMSUBS: func = fnmsubs; type = ABC; break;
2785cd27208SKumar Gala case FNMADDS: func = fnmadds; type = ABC; break;
2795cd27208SKumar Gala default:
2805cd27208SKumar Gala goto illegal;
2815cd27208SKumar Gala }
2825cd27208SKumar Gala break;
2835cd27208SKumar Gala
2845cd27208SKumar Gala case OP63:
2855cd27208SKumar Gala if (insn & 0x20) {
2865cd27208SKumar Gala switch ((insn >> 1) & 0x1f) {
2875cd27208SKumar Gala case FDIV: func = fdiv; type = AB; break;
2885cd27208SKumar Gala case FSUB: func = fsub; type = AB; break;
2895cd27208SKumar Gala case FADD: func = fadd; type = AB; break;
29004ae9001SBenjamin Herrenschmidt case FSQRT: func = fsqrt; type = XB; break;
29104ae9001SBenjamin Herrenschmidt case FRE: func = fre; type = XB; break;
2925cd27208SKumar Gala case FSEL: func = fsel; type = ABC; break;
2935cd27208SKumar Gala case FMUL: func = fmul; type = AC; break;
29404ae9001SBenjamin Herrenschmidt case FRSQRTE: func = frsqrte; type = XB; break;
2955cd27208SKumar Gala case FMSUB: func = fmsub; type = ABC; break;
2965cd27208SKumar Gala case FMADD: func = fmadd; type = ABC; break;
2975cd27208SKumar Gala case FNMSUB: func = fnmsub; type = ABC; break;
2985cd27208SKumar Gala case FNMADD: func = fnmadd; type = ABC; break;
2995cd27208SKumar Gala default:
3005cd27208SKumar Gala goto illegal;
3015cd27208SKumar Gala }
3025cd27208SKumar Gala break;
3035cd27208SKumar Gala }
3045cd27208SKumar Gala
3055cd27208SKumar Gala switch ((insn >> 1) & 0x3ff) {
3065cd27208SKumar Gala case FCMPU: func = fcmpu; type = XCR; break;
3075cd27208SKumar Gala case FRSP: func = frsp; type = XB; break;
3085cd27208SKumar Gala case FCTIW: func = fctiw; type = XB; break;
3095cd27208SKumar Gala case FCTIWZ: func = fctiwz; type = XB; break;
3105cd27208SKumar Gala case FCMPO: func = fcmpo; type = XCR; break;
3115cd27208SKumar Gala case MTFSB1: func = mtfsb1; type = XCRB; break;
3125cd27208SKumar Gala case FNEG: func = fneg; type = XB; break;
3135cd27208SKumar Gala case MCRFS: func = mcrfs; type = XCRL; break;
3145cd27208SKumar Gala case MTFSB0: func = mtfsb0; type = XCRB; break;
3155cd27208SKumar Gala case FMR: func = fmr; type = XB; break;
3165cd27208SKumar Gala case MTFSFI: func = mtfsfi; type = XCRI; break;
3175cd27208SKumar Gala case FNABS: func = fnabs; type = XB; break;
3185cd27208SKumar Gala case FABS: func = fabs; type = XB; break;
3195cd27208SKumar Gala case MFFS: func = mffs; type = X; break;
3205cd27208SKumar Gala case MTFSF: func = mtfsf; type = XFLB; break;
3215cd27208SKumar Gala default:
3225cd27208SKumar Gala goto illegal;
3235cd27208SKumar Gala }
3245cd27208SKumar Gala break;
3255cd27208SKumar Gala
3265cd27208SKumar Gala default:
3275cd27208SKumar Gala goto illegal;
3285cd27208SKumar Gala }
3295cd27208SKumar Gala
3305cd27208SKumar Gala switch (type) {
3315cd27208SKumar Gala case AB:
3329c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3339c75a31cSMichael Neuling op1 = (void *)¤t->thread.TS_FPR((insn >> 16) & 0x1f);
3349c75a31cSMichael Neuling op2 = (void *)¤t->thread.TS_FPR((insn >> 11) & 0x1f);
3355cd27208SKumar Gala break;
3365cd27208SKumar Gala
3375cd27208SKumar Gala case AC:
3389c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3399c75a31cSMichael Neuling op1 = (void *)¤t->thread.TS_FPR((insn >> 16) & 0x1f);
3409c75a31cSMichael Neuling op2 = (void *)¤t->thread.TS_FPR((insn >> 6) & 0x1f);
3415cd27208SKumar Gala break;
3425cd27208SKumar Gala
3435cd27208SKumar Gala case ABC:
3449c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3459c75a31cSMichael Neuling op1 = (void *)¤t->thread.TS_FPR((insn >> 16) & 0x1f);
3469c75a31cSMichael Neuling op2 = (void *)¤t->thread.TS_FPR((insn >> 11) & 0x1f);
3479c75a31cSMichael Neuling op3 = (void *)¤t->thread.TS_FPR((insn >> 6) & 0x1f);
3485cd27208SKumar Gala break;
3495cd27208SKumar Gala
3505cd27208SKumar Gala case D:
3515cd27208SKumar Gala idx = (insn >> 16) & 0x1f;
3525cd27208SKumar Gala sdisp = (insn & 0xffff);
3539c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3545cd27208SKumar Gala op1 = (void *)((idx ? regs->gpr[idx] : 0) + sdisp);
3555cd27208SKumar Gala break;
3565cd27208SKumar Gala
3575cd27208SKumar Gala case DU:
3585cd27208SKumar Gala idx = (insn >> 16) & 0x1f;
3595cd27208SKumar Gala if (!idx)
3605cd27208SKumar Gala goto illegal;
3615cd27208SKumar Gala
3625cd27208SKumar Gala sdisp = (insn & 0xffff);
3639c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3645cd27208SKumar Gala op1 = (void *)(regs->gpr[idx] + sdisp);
3655cd27208SKumar Gala break;
3665cd27208SKumar Gala
3675cd27208SKumar Gala case X:
3689c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3695cd27208SKumar Gala break;
3705cd27208SKumar Gala
3715cd27208SKumar Gala case XA:
3729c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3739c75a31cSMichael Neuling op1 = (void *)¤t->thread.TS_FPR((insn >> 16) & 0x1f);
3745cd27208SKumar Gala break;
3755cd27208SKumar Gala
3765cd27208SKumar Gala case XB:
3779c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
3789c75a31cSMichael Neuling op1 = (void *)¤t->thread.TS_FPR((insn >> 11) & 0x1f);
3795cd27208SKumar Gala break;
3805cd27208SKumar Gala
3815cd27208SKumar Gala case XE:
3825cd27208SKumar Gala idx = (insn >> 16) & 0x1f;
3839c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
384cc7059b5SJames Yang op1 = (void *)((idx ? regs->gpr[idx] : 0)
385cc7059b5SJames Yang + regs->gpr[(insn >> 11) & 0x1f]);
3865cd27208SKumar Gala break;
3875cd27208SKumar Gala
3885cd27208SKumar Gala case XEU:
3895cd27208SKumar Gala idx = (insn >> 16) & 0x1f;
390cc7059b5SJames Yang if (!idx)
391cc7059b5SJames Yang goto illegal;
3929c75a31cSMichael Neuling op0 = (void *)¤t->thread.TS_FPR((insn >> 21) & 0x1f);
393cc7059b5SJames Yang op1 = (void *)(regs->gpr[idx]
3945cd27208SKumar Gala + regs->gpr[(insn >> 11) & 0x1f]);
3955cd27208SKumar Gala break;
3965cd27208SKumar Gala
3975cd27208SKumar Gala case XCR:
3985cd27208SKumar Gala op0 = (void *)®s->ccr;
399*7245fc5bSChristophe Leroy op1 = (void *)(long)((insn >> 23) & 0x7);
4009c75a31cSMichael Neuling op2 = (void *)¤t->thread.TS_FPR((insn >> 16) & 0x1f);
4019c75a31cSMichael Neuling op3 = (void *)¤t->thread.TS_FPR((insn >> 11) & 0x1f);
4025cd27208SKumar Gala break;
4035cd27208SKumar Gala
4045cd27208SKumar Gala case XCRL:
4055cd27208SKumar Gala op0 = (void *)®s->ccr;
406*7245fc5bSChristophe Leroy op1 = (void *)(long)((insn >> 23) & 0x7);
407*7245fc5bSChristophe Leroy op2 = (void *)(long)((insn >> 18) & 0x7);
4085cd27208SKumar Gala break;
4095cd27208SKumar Gala
4105cd27208SKumar Gala case XCRB:
411*7245fc5bSChristophe Leroy op0 = (void *)(long)((insn >> 21) & 0x1f);
4125cd27208SKumar Gala break;
4135cd27208SKumar Gala
4145cd27208SKumar Gala case XCRI:
415*7245fc5bSChristophe Leroy op0 = (void *)(long)((insn >> 23) & 0x7);
416*7245fc5bSChristophe Leroy op1 = (void *)(long)((insn >> 12) & 0xf);
4175cd27208SKumar Gala break;
4185cd27208SKumar Gala
4195cd27208SKumar Gala case XFLB:
420*7245fc5bSChristophe Leroy op0 = (void *)(long)((insn >> 17) & 0xff);
4219c75a31cSMichael Neuling op1 = (void *)¤t->thread.TS_FPR((insn >> 11) & 0x1f);
4225cd27208SKumar Gala break;
4235cd27208SKumar Gala
4245cd27208SKumar Gala default:
4255cd27208SKumar Gala goto illegal;
4265cd27208SKumar Gala }
4275cd27208SKumar Gala
4286761ee3dSKevin Hao /*
4296761ee3dSKevin Hao * If we support a HW FPU, we need to ensure the FP state
4306761ee3dSKevin Hao * is flushed into the thread_struct before attempting
4316761ee3dSKevin Hao * emulation
4326761ee3dSKevin Hao */
4336761ee3dSKevin Hao flush_fp_to_thread(current);
4346761ee3dSKevin Hao
4355cd27208SKumar Gala eflag = func(op0, op1, op2, op3);
4365cd27208SKumar Gala
4375cd27208SKumar Gala if (insn & 1) {
4385cd27208SKumar Gala regs->ccr &= ~(0x0f000000);
4395cd27208SKumar Gala regs->ccr |= (__FPU_FPSCR >> 4) & 0x0f000000;
4405cd27208SKumar Gala }
4415cd27208SKumar Gala
4425cd27208SKumar Gala trap = record_exception(regs, eflag);
4435cd27208SKumar Gala if (trap)
4445cd27208SKumar Gala return 1;
4455cd27208SKumar Gala
4465cd27208SKumar Gala switch (type) {
4475cd27208SKumar Gala case DU:
4485cd27208SKumar Gala case XEU:
4495cd27208SKumar Gala regs->gpr[idx] = (unsigned long)op1;
4505cd27208SKumar Gala break;
4515cd27208SKumar Gala
4525cd27208SKumar Gala default:
4535cd27208SKumar Gala break;
4545cd27208SKumar Gala }
4555cd27208SKumar Gala
45659dc5bfcSNicholas Piggin regs_add_return_ip(regs, 4);
4575cd27208SKumar Gala return 0;
4585cd27208SKumar Gala
4595cd27208SKumar Gala illegal:
4605cd27208SKumar Gala return -ENOSYS;
4615cd27208SKumar Gala }
462