18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 1999  Eddie C. Dost  (ecd@atecom.com)
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/types.h>
78c2ecf20Sopenharmony_ci#include <linux/sched.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
108c2ecf20Sopenharmony_ci#include <asm/reg.h>
118c2ecf20Sopenharmony_ci#include <asm/switch_to.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <asm/sfp-machine.h>
148c2ecf20Sopenharmony_ci#include <math-emu/double.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define FLOATFUNC(x)	extern int x(void *, void *, void *, void *)
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* The instructions list which may be not implemented by a hardware FPU */
198c2ecf20Sopenharmony_ciFLOATFUNC(fre);
208c2ecf20Sopenharmony_ciFLOATFUNC(frsqrtes);
218c2ecf20Sopenharmony_ciFLOATFUNC(fsqrt);
228c2ecf20Sopenharmony_ciFLOATFUNC(fsqrts);
238c2ecf20Sopenharmony_ciFLOATFUNC(mtfsf);
248c2ecf20Sopenharmony_ciFLOATFUNC(mtfsfi);
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifdef CONFIG_MATH_EMULATION_HW_UNIMPLEMENTED
278c2ecf20Sopenharmony_ci#undef FLOATFUNC(x)
288c2ecf20Sopenharmony_ci#define FLOATFUNC(x)	static inline int x(void *op1, void *op2, void *op3, \
298c2ecf20Sopenharmony_ci						 void *op4) { }
308c2ecf20Sopenharmony_ci#endif
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciFLOATFUNC(fadd);
338c2ecf20Sopenharmony_ciFLOATFUNC(fadds);
348c2ecf20Sopenharmony_ciFLOATFUNC(fdiv);
358c2ecf20Sopenharmony_ciFLOATFUNC(fdivs);
368c2ecf20Sopenharmony_ciFLOATFUNC(fmul);
378c2ecf20Sopenharmony_ciFLOATFUNC(fmuls);
388c2ecf20Sopenharmony_ciFLOATFUNC(fsub);
398c2ecf20Sopenharmony_ciFLOATFUNC(fsubs);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciFLOATFUNC(fmadd);
428c2ecf20Sopenharmony_ciFLOATFUNC(fmadds);
438c2ecf20Sopenharmony_ciFLOATFUNC(fmsub);
448c2ecf20Sopenharmony_ciFLOATFUNC(fmsubs);
458c2ecf20Sopenharmony_ciFLOATFUNC(fnmadd);
468c2ecf20Sopenharmony_ciFLOATFUNC(fnmadds);
478c2ecf20Sopenharmony_ciFLOATFUNC(fnmsub);
488c2ecf20Sopenharmony_ciFLOATFUNC(fnmsubs);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciFLOATFUNC(fctiw);
518c2ecf20Sopenharmony_ciFLOATFUNC(fctiwz);
528c2ecf20Sopenharmony_ciFLOATFUNC(frsp);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ciFLOATFUNC(fcmpo);
558c2ecf20Sopenharmony_ciFLOATFUNC(fcmpu);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciFLOATFUNC(mcrfs);
588c2ecf20Sopenharmony_ciFLOATFUNC(mffs);
598c2ecf20Sopenharmony_ciFLOATFUNC(mtfsb0);
608c2ecf20Sopenharmony_ciFLOATFUNC(mtfsb1);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciFLOATFUNC(lfd);
638c2ecf20Sopenharmony_ciFLOATFUNC(lfs);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciFLOATFUNC(stfd);
668c2ecf20Sopenharmony_ciFLOATFUNC(stfs);
678c2ecf20Sopenharmony_ciFLOATFUNC(stfiwx);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciFLOATFUNC(fabs);
708c2ecf20Sopenharmony_ciFLOATFUNC(fmr);
718c2ecf20Sopenharmony_ciFLOATFUNC(fnabs);
728c2ecf20Sopenharmony_ciFLOATFUNC(fneg);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* Optional */
758c2ecf20Sopenharmony_ciFLOATFUNC(fres);
768c2ecf20Sopenharmony_ciFLOATFUNC(frsqrte);
778c2ecf20Sopenharmony_ciFLOATFUNC(fsel);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define OP31		0x1f		/*   31 */
818c2ecf20Sopenharmony_ci#define LFS		0x30		/*   48 */
828c2ecf20Sopenharmony_ci#define LFSU		0x31		/*   49 */
838c2ecf20Sopenharmony_ci#define LFD		0x32		/*   50 */
848c2ecf20Sopenharmony_ci#define LFDU		0x33		/*   51 */
858c2ecf20Sopenharmony_ci#define STFS		0x34		/*   52 */
868c2ecf20Sopenharmony_ci#define STFSU		0x35		/*   53 */
878c2ecf20Sopenharmony_ci#define STFD		0x36		/*   54 */
888c2ecf20Sopenharmony_ci#define STFDU		0x37		/*   55 */
898c2ecf20Sopenharmony_ci#define OP59		0x3b		/*   59 */
908c2ecf20Sopenharmony_ci#define OP63		0x3f		/*   63 */
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* Opcode 31: */
938c2ecf20Sopenharmony_ci/* X-Form: */
948c2ecf20Sopenharmony_ci#define LFSX		0x217		/*  535 */
958c2ecf20Sopenharmony_ci#define LFSUX		0x237		/*  567 */
968c2ecf20Sopenharmony_ci#define LFDX		0x257		/*  599 */
978c2ecf20Sopenharmony_ci#define LFDUX		0x277		/*  631 */
988c2ecf20Sopenharmony_ci#define STFSX		0x297		/*  663 */
998c2ecf20Sopenharmony_ci#define STFSUX		0x2b7		/*  695 */
1008c2ecf20Sopenharmony_ci#define STFDX		0x2d7		/*  727 */
1018c2ecf20Sopenharmony_ci#define STFDUX		0x2f7		/*  759 */
1028c2ecf20Sopenharmony_ci#define STFIWX		0x3d7		/*  983 */
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* Opcode 59: */
1058c2ecf20Sopenharmony_ci/* A-Form: */
1068c2ecf20Sopenharmony_ci#define FDIVS		0x012		/*   18 */
1078c2ecf20Sopenharmony_ci#define FSUBS		0x014		/*   20 */
1088c2ecf20Sopenharmony_ci#define FADDS		0x015		/*   21 */
1098c2ecf20Sopenharmony_ci#define FSQRTS		0x016		/*   22 */
1108c2ecf20Sopenharmony_ci#define FRES		0x018		/*   24 */
1118c2ecf20Sopenharmony_ci#define FMULS		0x019		/*   25 */
1128c2ecf20Sopenharmony_ci#define FRSQRTES	0x01a		/*   26 */
1138c2ecf20Sopenharmony_ci#define FMSUBS		0x01c		/*   28 */
1148c2ecf20Sopenharmony_ci#define FMADDS		0x01d		/*   29 */
1158c2ecf20Sopenharmony_ci#define FNMSUBS		0x01e		/*   30 */
1168c2ecf20Sopenharmony_ci#define FNMADDS		0x01f		/*   31 */
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* Opcode 63: */
1198c2ecf20Sopenharmony_ci/* A-Form: */
1208c2ecf20Sopenharmony_ci#define FDIV		0x012		/*   18 */
1218c2ecf20Sopenharmony_ci#define FSUB		0x014		/*   20 */
1228c2ecf20Sopenharmony_ci#define FADD		0x015		/*   21 */
1238c2ecf20Sopenharmony_ci#define FSQRT		0x016		/*   22 */
1248c2ecf20Sopenharmony_ci#define FSEL		0x017		/*   23 */
1258c2ecf20Sopenharmony_ci#define FRE		0x018		/*   24 */
1268c2ecf20Sopenharmony_ci#define FMUL		0x019		/*   25 */
1278c2ecf20Sopenharmony_ci#define FRSQRTE		0x01a		/*   26 */
1288c2ecf20Sopenharmony_ci#define FMSUB		0x01c		/*   28 */
1298c2ecf20Sopenharmony_ci#define FMADD		0x01d		/*   29 */
1308c2ecf20Sopenharmony_ci#define FNMSUB		0x01e		/*   30 */
1318c2ecf20Sopenharmony_ci#define FNMADD		0x01f		/*   31 */
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/* X-Form: */
1348c2ecf20Sopenharmony_ci#define FCMPU		0x000		/*    0	*/
1358c2ecf20Sopenharmony_ci#define FRSP		0x00c		/*   12 */
1368c2ecf20Sopenharmony_ci#define FCTIW		0x00e		/*   14 */
1378c2ecf20Sopenharmony_ci#define FCTIWZ		0x00f		/*   15 */
1388c2ecf20Sopenharmony_ci#define FCMPO		0x020		/*   32 */
1398c2ecf20Sopenharmony_ci#define MTFSB1		0x026		/*   38 */
1408c2ecf20Sopenharmony_ci#define FNEG		0x028		/*   40 */
1418c2ecf20Sopenharmony_ci#define MCRFS		0x040		/*   64 */
1428c2ecf20Sopenharmony_ci#define MTFSB0		0x046		/*   70 */
1438c2ecf20Sopenharmony_ci#define FMR		0x048		/*   72 */
1448c2ecf20Sopenharmony_ci#define MTFSFI		0x086		/*  134 */
1458c2ecf20Sopenharmony_ci#define FNABS		0x088		/*  136 */
1468c2ecf20Sopenharmony_ci#define FABS		0x108		/*  264 */
1478c2ecf20Sopenharmony_ci#define MFFS		0x247		/*  583 */
1488c2ecf20Sopenharmony_ci#define MTFSF		0x2c7		/*  711 */
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#define AB	2
1528c2ecf20Sopenharmony_ci#define AC	3
1538c2ecf20Sopenharmony_ci#define ABC	4
1548c2ecf20Sopenharmony_ci#define D	5
1558c2ecf20Sopenharmony_ci#define DU	6
1568c2ecf20Sopenharmony_ci#define X	7
1578c2ecf20Sopenharmony_ci#define XA	8
1588c2ecf20Sopenharmony_ci#define XB	9
1598c2ecf20Sopenharmony_ci#define XCR	11
1608c2ecf20Sopenharmony_ci#define XCRB	12
1618c2ecf20Sopenharmony_ci#define XCRI	13
1628c2ecf20Sopenharmony_ci#define XCRL	16
1638c2ecf20Sopenharmony_ci#define XE	14
1648c2ecf20Sopenharmony_ci#define XEU	15
1658c2ecf20Sopenharmony_ci#define XFLB	10
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic int
1688c2ecf20Sopenharmony_cirecord_exception(struct pt_regs *regs, int eflag)
1698c2ecf20Sopenharmony_ci{
1708c2ecf20Sopenharmony_ci	u32 fpscr;
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	fpscr = __FPU_FPSCR;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	if (eflag) {
1758c2ecf20Sopenharmony_ci		fpscr |= FPSCR_FX;
1768c2ecf20Sopenharmony_ci		if (eflag & EFLAG_OVERFLOW)
1778c2ecf20Sopenharmony_ci			fpscr |= FPSCR_OX;
1788c2ecf20Sopenharmony_ci		if (eflag & EFLAG_UNDERFLOW)
1798c2ecf20Sopenharmony_ci			fpscr |= FPSCR_UX;
1808c2ecf20Sopenharmony_ci		if (eflag & EFLAG_DIVZERO)
1818c2ecf20Sopenharmony_ci			fpscr |= FPSCR_ZX;
1828c2ecf20Sopenharmony_ci		if (eflag & EFLAG_INEXACT)
1838c2ecf20Sopenharmony_ci			fpscr |= FPSCR_XX;
1848c2ecf20Sopenharmony_ci		if (eflag & EFLAG_INVALID)
1858c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VX;
1868c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXSNAN)
1878c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXSNAN;
1888c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXISI)
1898c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXISI;
1908c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXIDI)
1918c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXIDI;
1928c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXZDZ)
1938c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXZDZ;
1948c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXIMZ)
1958c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXIMZ;
1968c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXVC)
1978c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXVC;
1988c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXSOFT)
1998c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXSOFT;
2008c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXSQRT)
2018c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXSQRT;
2028c2ecf20Sopenharmony_ci		if (eflag & EFLAG_VXCVI)
2038c2ecf20Sopenharmony_ci			fpscr |= FPSCR_VXCVI;
2048c2ecf20Sopenharmony_ci	}
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci//	fpscr &= ~(FPSCR_VX);
2078c2ecf20Sopenharmony_ci	if (fpscr & (FPSCR_VXSNAN | FPSCR_VXISI | FPSCR_VXIDI |
2088c2ecf20Sopenharmony_ci		     FPSCR_VXZDZ | FPSCR_VXIMZ | FPSCR_VXVC |
2098c2ecf20Sopenharmony_ci		     FPSCR_VXSOFT | FPSCR_VXSQRT | FPSCR_VXCVI))
2108c2ecf20Sopenharmony_ci		fpscr |= FPSCR_VX;
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	fpscr &= ~(FPSCR_FEX);
2138c2ecf20Sopenharmony_ci	if (((fpscr & FPSCR_VX) && (fpscr & FPSCR_VE)) ||
2148c2ecf20Sopenharmony_ci	    ((fpscr & FPSCR_OX) && (fpscr & FPSCR_OE)) ||
2158c2ecf20Sopenharmony_ci	    ((fpscr & FPSCR_UX) && (fpscr & FPSCR_UE)) ||
2168c2ecf20Sopenharmony_ci	    ((fpscr & FPSCR_ZX) && (fpscr & FPSCR_ZE)) ||
2178c2ecf20Sopenharmony_ci	    ((fpscr & FPSCR_XX) && (fpscr & FPSCR_XE)))
2188c2ecf20Sopenharmony_ci		fpscr |= FPSCR_FEX;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	__FPU_FPSCR = fpscr;
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	return (fpscr & FPSCR_FEX) ? 1 : 0;
2238c2ecf20Sopenharmony_ci}
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ciint
2268c2ecf20Sopenharmony_cido_mathemu(struct pt_regs *regs)
2278c2ecf20Sopenharmony_ci{
2288c2ecf20Sopenharmony_ci	void *op0 = 0, *op1 = 0, *op2 = 0, *op3 = 0;
2298c2ecf20Sopenharmony_ci	unsigned long pc = regs->nip;
2308c2ecf20Sopenharmony_ci	signed short sdisp;
2318c2ecf20Sopenharmony_ci	u32 insn = 0;
2328c2ecf20Sopenharmony_ci	int idx = 0;
2338c2ecf20Sopenharmony_ci	int (*func)(void *, void *, void *, void *);
2348c2ecf20Sopenharmony_ci	int type = 0;
2358c2ecf20Sopenharmony_ci	int eflag, trap;
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	if (get_user(insn, (u32 *)pc))
2388c2ecf20Sopenharmony_ci		return -EFAULT;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	switch (insn >> 26) {
2418c2ecf20Sopenharmony_ci	case LFS:	func = lfs;	type = D;	break;
2428c2ecf20Sopenharmony_ci	case LFSU:	func = lfs;	type = DU;	break;
2438c2ecf20Sopenharmony_ci	case LFD:	func = lfd;	type = D;	break;
2448c2ecf20Sopenharmony_ci	case LFDU:	func = lfd;	type = DU;	break;
2458c2ecf20Sopenharmony_ci	case STFS:	func = stfs;	type = D;	break;
2468c2ecf20Sopenharmony_ci	case STFSU:	func = stfs;	type = DU;	break;
2478c2ecf20Sopenharmony_ci	case STFD:	func = stfd;	type = D;	break;
2488c2ecf20Sopenharmony_ci	case STFDU:	func = stfd;	type = DU;	break;
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	case OP31:
2518c2ecf20Sopenharmony_ci		switch ((insn >> 1) & 0x3ff) {
2528c2ecf20Sopenharmony_ci		case LFSX:	func = lfs;	type = XE;	break;
2538c2ecf20Sopenharmony_ci		case LFSUX:	func = lfs;	type = XEU;	break;
2548c2ecf20Sopenharmony_ci		case LFDX:	func = lfd;	type = XE;	break;
2558c2ecf20Sopenharmony_ci		case LFDUX:	func = lfd;	type = XEU;	break;
2568c2ecf20Sopenharmony_ci		case STFSX:	func = stfs;	type = XE;	break;
2578c2ecf20Sopenharmony_ci		case STFSUX:	func = stfs;	type = XEU;	break;
2588c2ecf20Sopenharmony_ci		case STFDX:	func = stfd;	type = XE;	break;
2598c2ecf20Sopenharmony_ci		case STFDUX:	func = stfd;	type = XEU;	break;
2608c2ecf20Sopenharmony_ci		case STFIWX:	func = stfiwx;	type = XE;	break;
2618c2ecf20Sopenharmony_ci		default:
2628c2ecf20Sopenharmony_ci			goto illegal;
2638c2ecf20Sopenharmony_ci		}
2648c2ecf20Sopenharmony_ci		break;
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	case OP59:
2678c2ecf20Sopenharmony_ci		switch ((insn >> 1) & 0x1f) {
2688c2ecf20Sopenharmony_ci		case FDIVS:	func = fdivs;	type = AB;	break;
2698c2ecf20Sopenharmony_ci		case FSUBS:	func = fsubs;	type = AB;	break;
2708c2ecf20Sopenharmony_ci		case FADDS:	func = fadds;	type = AB;	break;
2718c2ecf20Sopenharmony_ci		case FSQRTS:	func = fsqrts;	type = XB;	break;
2728c2ecf20Sopenharmony_ci		case FRES:	func = fres;	type = XB;	break;
2738c2ecf20Sopenharmony_ci		case FMULS:	func = fmuls;	type = AC;	break;
2748c2ecf20Sopenharmony_ci		case FRSQRTES:	func = frsqrtes;type = XB;	break;
2758c2ecf20Sopenharmony_ci		case FMSUBS:	func = fmsubs;	type = ABC;	break;
2768c2ecf20Sopenharmony_ci		case FMADDS:	func = fmadds;	type = ABC;	break;
2778c2ecf20Sopenharmony_ci		case FNMSUBS:	func = fnmsubs;	type = ABC;	break;
2788c2ecf20Sopenharmony_ci		case FNMADDS:	func = fnmadds;	type = ABC;	break;
2798c2ecf20Sopenharmony_ci		default:
2808c2ecf20Sopenharmony_ci			goto illegal;
2818c2ecf20Sopenharmony_ci		}
2828c2ecf20Sopenharmony_ci		break;
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci	case OP63:
2858c2ecf20Sopenharmony_ci		if (insn & 0x20) {
2868c2ecf20Sopenharmony_ci			switch ((insn >> 1) & 0x1f) {
2878c2ecf20Sopenharmony_ci			case FDIV:	func = fdiv;	type = AB;	break;
2888c2ecf20Sopenharmony_ci			case FSUB:	func = fsub;	type = AB;	break;
2898c2ecf20Sopenharmony_ci			case FADD:	func = fadd;	type = AB;	break;
2908c2ecf20Sopenharmony_ci			case FSQRT:	func = fsqrt;	type = XB;	break;
2918c2ecf20Sopenharmony_ci			case FRE:	func = fre;	type = XB;	break;
2928c2ecf20Sopenharmony_ci			case FSEL:	func = fsel;	type = ABC;	break;
2938c2ecf20Sopenharmony_ci			case FMUL:	func = fmul;	type = AC;	break;
2948c2ecf20Sopenharmony_ci			case FRSQRTE:	func = frsqrte;	type = XB;	break;
2958c2ecf20Sopenharmony_ci			case FMSUB:	func = fmsub;	type = ABC;	break;
2968c2ecf20Sopenharmony_ci			case FMADD:	func = fmadd;	type = ABC;	break;
2978c2ecf20Sopenharmony_ci			case FNMSUB:	func = fnmsub;	type = ABC;	break;
2988c2ecf20Sopenharmony_ci			case FNMADD:	func = fnmadd;	type = ABC;	break;
2998c2ecf20Sopenharmony_ci			default:
3008c2ecf20Sopenharmony_ci				goto illegal;
3018c2ecf20Sopenharmony_ci			}
3028c2ecf20Sopenharmony_ci			break;
3038c2ecf20Sopenharmony_ci		}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci		switch ((insn >> 1) & 0x3ff) {
3068c2ecf20Sopenharmony_ci		case FCMPU:	func = fcmpu;	type = XCR;	break;
3078c2ecf20Sopenharmony_ci		case FRSP:	func = frsp;	type = XB;	break;
3088c2ecf20Sopenharmony_ci		case FCTIW:	func = fctiw;	type = XB;	break;
3098c2ecf20Sopenharmony_ci		case FCTIWZ:	func = fctiwz;	type = XB;	break;
3108c2ecf20Sopenharmony_ci		case FCMPO:	func = fcmpo;	type = XCR;	break;
3118c2ecf20Sopenharmony_ci		case MTFSB1:	func = mtfsb1;	type = XCRB;	break;
3128c2ecf20Sopenharmony_ci		case FNEG:	func = fneg;	type = XB;	break;
3138c2ecf20Sopenharmony_ci		case MCRFS:	func = mcrfs;	type = XCRL;	break;
3148c2ecf20Sopenharmony_ci		case MTFSB0:	func = mtfsb0;	type = XCRB;	break;
3158c2ecf20Sopenharmony_ci		case FMR:	func = fmr;	type = XB;	break;
3168c2ecf20Sopenharmony_ci		case MTFSFI:	func = mtfsfi;	type = XCRI;	break;
3178c2ecf20Sopenharmony_ci		case FNABS:	func = fnabs;	type = XB;	break;
3188c2ecf20Sopenharmony_ci		case FABS:	func = fabs;	type = XB;	break;
3198c2ecf20Sopenharmony_ci		case MFFS:	func = mffs;	type = X;	break;
3208c2ecf20Sopenharmony_ci		case MTFSF:	func = mtfsf;	type = XFLB;	break;
3218c2ecf20Sopenharmony_ci		default:
3228c2ecf20Sopenharmony_ci			goto illegal;
3238c2ecf20Sopenharmony_ci		}
3248c2ecf20Sopenharmony_ci		break;
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	default:
3278c2ecf20Sopenharmony_ci		goto illegal;
3288c2ecf20Sopenharmony_ci	}
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	switch (type) {
3318c2ecf20Sopenharmony_ci	case AB:
3328c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3338c2ecf20Sopenharmony_ci		op1 = (void *)&current->thread.TS_FPR((insn >> 16) & 0x1f);
3348c2ecf20Sopenharmony_ci		op2 = (void *)&current->thread.TS_FPR((insn >> 11) & 0x1f);
3358c2ecf20Sopenharmony_ci		break;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	case AC:
3388c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3398c2ecf20Sopenharmony_ci		op1 = (void *)&current->thread.TS_FPR((insn >> 16) & 0x1f);
3408c2ecf20Sopenharmony_ci		op2 = (void *)&current->thread.TS_FPR((insn >>  6) & 0x1f);
3418c2ecf20Sopenharmony_ci		break;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	case ABC:
3448c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3458c2ecf20Sopenharmony_ci		op1 = (void *)&current->thread.TS_FPR((insn >> 16) & 0x1f);
3468c2ecf20Sopenharmony_ci		op2 = (void *)&current->thread.TS_FPR((insn >> 11) & 0x1f);
3478c2ecf20Sopenharmony_ci		op3 = (void *)&current->thread.TS_FPR((insn >>  6) & 0x1f);
3488c2ecf20Sopenharmony_ci		break;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	case D:
3518c2ecf20Sopenharmony_ci		idx = (insn >> 16) & 0x1f;
3528c2ecf20Sopenharmony_ci		sdisp = (insn & 0xffff);
3538c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3548c2ecf20Sopenharmony_ci		op1 = (void *)((idx ? regs->gpr[idx] : 0) + sdisp);
3558c2ecf20Sopenharmony_ci		break;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	case DU:
3588c2ecf20Sopenharmony_ci		idx = (insn >> 16) & 0x1f;
3598c2ecf20Sopenharmony_ci		if (!idx)
3608c2ecf20Sopenharmony_ci			goto illegal;
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci		sdisp = (insn & 0xffff);
3638c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3648c2ecf20Sopenharmony_ci		op1 = (void *)(regs->gpr[idx] + sdisp);
3658c2ecf20Sopenharmony_ci		break;
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	case X:
3688c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3698c2ecf20Sopenharmony_ci		break;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	case XA:
3728c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3738c2ecf20Sopenharmony_ci		op1 = (void *)&current->thread.TS_FPR((insn >> 16) & 0x1f);
3748c2ecf20Sopenharmony_ci		break;
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	case XB:
3778c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3788c2ecf20Sopenharmony_ci		op1 = (void *)&current->thread.TS_FPR((insn >> 11) & 0x1f);
3798c2ecf20Sopenharmony_ci		break;
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	case XE:
3828c2ecf20Sopenharmony_ci		idx = (insn >> 16) & 0x1f;
3838c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3848c2ecf20Sopenharmony_ci		op1 = (void *)((idx ? regs->gpr[idx] : 0)
3858c2ecf20Sopenharmony_ci				+ regs->gpr[(insn >> 11) & 0x1f]);
3868c2ecf20Sopenharmony_ci		break;
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	case XEU:
3898c2ecf20Sopenharmony_ci		idx = (insn >> 16) & 0x1f;
3908c2ecf20Sopenharmony_ci		if (!idx)
3918c2ecf20Sopenharmony_ci			goto illegal;
3928c2ecf20Sopenharmony_ci		op0 = (void *)&current->thread.TS_FPR((insn >> 21) & 0x1f);
3938c2ecf20Sopenharmony_ci		op1 = (void *)(regs->gpr[idx]
3948c2ecf20Sopenharmony_ci				+ regs->gpr[(insn >> 11) & 0x1f]);
3958c2ecf20Sopenharmony_ci		break;
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	case XCR:
3988c2ecf20Sopenharmony_ci		op0 = (void *)&regs->ccr;
3998c2ecf20Sopenharmony_ci		op1 = (void *)((insn >> 23) & 0x7);
4008c2ecf20Sopenharmony_ci		op2 = (void *)&current->thread.TS_FPR((insn >> 16) & 0x1f);
4018c2ecf20Sopenharmony_ci		op3 = (void *)&current->thread.TS_FPR((insn >> 11) & 0x1f);
4028c2ecf20Sopenharmony_ci		break;
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	case XCRL:
4058c2ecf20Sopenharmony_ci		op0 = (void *)&regs->ccr;
4068c2ecf20Sopenharmony_ci		op1 = (void *)((insn >> 23) & 0x7);
4078c2ecf20Sopenharmony_ci		op2 = (void *)((insn >> 18) & 0x7);
4088c2ecf20Sopenharmony_ci		break;
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	case XCRB:
4118c2ecf20Sopenharmony_ci		op0 = (void *)((insn >> 21) & 0x1f);
4128c2ecf20Sopenharmony_ci		break;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	case XCRI:
4158c2ecf20Sopenharmony_ci		op0 = (void *)((insn >> 23) & 0x7);
4168c2ecf20Sopenharmony_ci		op1 = (void *)((insn >> 12) & 0xf);
4178c2ecf20Sopenharmony_ci		break;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	case XFLB:
4208c2ecf20Sopenharmony_ci		op0 = (void *)((insn >> 17) & 0xff);
4218c2ecf20Sopenharmony_ci		op1 = (void *)&current->thread.TS_FPR((insn >> 11) & 0x1f);
4228c2ecf20Sopenharmony_ci		break;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	default:
4258c2ecf20Sopenharmony_ci		goto illegal;
4268c2ecf20Sopenharmony_ci	}
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	/*
4298c2ecf20Sopenharmony_ci	 * If we support a HW FPU, we need to ensure the FP state
4308c2ecf20Sopenharmony_ci	 * is flushed into the thread_struct before attempting
4318c2ecf20Sopenharmony_ci	 * emulation
4328c2ecf20Sopenharmony_ci	 */
4338c2ecf20Sopenharmony_ci	flush_fp_to_thread(current);
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	eflag = func(op0, op1, op2, op3);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	if (insn & 1) {
4388c2ecf20Sopenharmony_ci		regs->ccr &= ~(0x0f000000);
4398c2ecf20Sopenharmony_ci		regs->ccr |= (__FPU_FPSCR >> 4) & 0x0f000000;
4408c2ecf20Sopenharmony_ci	}
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	trap = record_exception(regs, eflag);
4438c2ecf20Sopenharmony_ci	if (trap)
4448c2ecf20Sopenharmony_ci		return 1;
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	switch (type) {
4478c2ecf20Sopenharmony_ci	case DU:
4488c2ecf20Sopenharmony_ci	case XEU:
4498c2ecf20Sopenharmony_ci		regs->gpr[idx] = (unsigned long)op1;
4508c2ecf20Sopenharmony_ci		break;
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	default:
4538c2ecf20Sopenharmony_ci		break;
4548c2ecf20Sopenharmony_ci	}
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	regs->nip += 4;
4578c2ecf20Sopenharmony_ci	return 0;
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ciillegal:
4608c2ecf20Sopenharmony_ci	return -ENOSYS;
4618c2ecf20Sopenharmony_ci}
462