xref: /onnv-gate/usr/src/uts/sun4/os/visinstr.c (revision 2227)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2227Sjfrank  * Common Development and Distribution License (the "License").
6*2227Sjfrank  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
221246Skalai  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /* VIS floating point instruction simulator for Sparc FPU simulator. */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/systm.h>
320Sstevel@tonic-gate #include <sys/fpu/fpusystm.h>
330Sstevel@tonic-gate #include <sys/fpu/fpu_simulator.h>
340Sstevel@tonic-gate #include <sys/vis_simulator.h>
350Sstevel@tonic-gate #include <sys/fpu/globals.h>
360Sstevel@tonic-gate #include <sys/privregs.h>
370Sstevel@tonic-gate #include <sys/sun4asi.h>
380Sstevel@tonic-gate #include <sys/machasi.h>
390Sstevel@tonic-gate #include <sys/debug.h>
400Sstevel@tonic-gate #include <sys/cpu_module.h>
410Sstevel@tonic-gate #include <sys/systm.h>
420Sstevel@tonic-gate #include <sys/machsystm.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	FPU_REG_FIELD uint32_reg	/* Coordinate with FPU_REGS_TYPE. */
450Sstevel@tonic-gate #define	FPU_DREG_FIELD uint64_reg	/* Coordinate with FPU_DREGS_TYPE. */
460Sstevel@tonic-gate #define	FPU_FSR_FIELD uint64_reg	/* Coordinate with V9_FPU_FSR_TYPE. */
470Sstevel@tonic-gate 
481246Skalai extern	uint_t	get_subcc_ccr(uint64_t, uint64_t);
491246Skalai 
500Sstevel@tonic-gate static enum ftt_type vis_array(fp_simd_type *, vis_inst_type, struct regs *,
510Sstevel@tonic-gate 				void *);
520Sstevel@tonic-gate static enum ftt_type vis_alignaddr(fp_simd_type *, vis_inst_type,
530Sstevel@tonic-gate 				struct regs *, void *, kfpu_t *);
540Sstevel@tonic-gate static enum ftt_type vis_edge(fp_simd_type *, vis_inst_type, struct regs *,
550Sstevel@tonic-gate 				void *);
560Sstevel@tonic-gate static enum ftt_type vis_faligndata(fp_simd_type *, fp_inst_type,
570Sstevel@tonic-gate 				kfpu_t *);
580Sstevel@tonic-gate static enum ftt_type vis_bmask(fp_simd_type *, vis_inst_type, struct regs *,
590Sstevel@tonic-gate 				void *, kfpu_t *);
600Sstevel@tonic-gate static enum ftt_type vis_bshuffle(fp_simd_type *, fp_inst_type,
610Sstevel@tonic-gate 				kfpu_t *);
620Sstevel@tonic-gate static enum ftt_type vis_siam(fp_simd_type *, vis_inst_type, kfpu_t *);
630Sstevel@tonic-gate static enum ftt_type vis_fcmp(fp_simd_type *, vis_inst_type, struct regs *,
640Sstevel@tonic-gate 				void *);
650Sstevel@tonic-gate static enum ftt_type vis_fmul(fp_simd_type *, vis_inst_type);
660Sstevel@tonic-gate static enum ftt_type vis_fpixel(fp_simd_type *, vis_inst_type, kfpu_t *);
670Sstevel@tonic-gate static enum ftt_type vis_fpaddsub(fp_simd_type *, vis_inst_type);
680Sstevel@tonic-gate static enum ftt_type vis_pdist(fp_simd_type *, fp_inst_type);
690Sstevel@tonic-gate static enum ftt_type vis_prtl_fst(fp_simd_type *, vis_inst_type, struct regs *,
700Sstevel@tonic-gate 				void *, uint_t);
710Sstevel@tonic-gate static enum ftt_type vis_short_fls(fp_simd_type *, vis_inst_type,
720Sstevel@tonic-gate 				struct regs *, void *, uint_t);
730Sstevel@tonic-gate static enum ftt_type vis_blk_fldst(fp_simd_type *, vis_inst_type,
740Sstevel@tonic-gate 				struct regs *, void *, uint_t);
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * Simulator for VIS instructions with op3 == 0x36 that get fp_disabled
780Sstevel@tonic-gate  * traps.
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate enum ftt_type
810Sstevel@tonic-gate vis_fpu_simulator(
820Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
830Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
840Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
850Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
860Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
890Sstevel@tonic-gate 	uint_t	us1, us2, usr;
900Sstevel@tonic-gate 	uint64_t lus1, lus2, lusr;
910Sstevel@tonic-gate 	enum ftt_type ftt = ftt_none;
920Sstevel@tonic-gate 	union {
930Sstevel@tonic-gate 		vis_inst_type	inst;
940Sstevel@tonic-gate 		fp_inst_type	pinst;
950Sstevel@tonic-gate 	} f;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	ASSERT(USERMODE(pregs->r_tstate));
980Sstevel@tonic-gate 	nrs1 = pinst.rs1;
990Sstevel@tonic-gate 	nrs2 = pinst.rs2;
1000Sstevel@tonic-gate 	nrd = pinst.rd;
1010Sstevel@tonic-gate 	f.pinst = pinst;
1020Sstevel@tonic-gate 	if ((f.inst.opf & 1) == 0) {		/* double precision */
1030Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 		/* fix register encoding */
1040Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
1050Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
1060Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
1070Sstevel@tonic-gate 		if ((nrd & 1) == 1)
1080Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
1090Sstevel@tonic-gate 	}
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	switch (f.inst.opf) {
1120Sstevel@tonic-gate 		/* these instr's do not use fp regs */
1130Sstevel@tonic-gate 	case edge8:
1140Sstevel@tonic-gate 	case edge8l:
1150Sstevel@tonic-gate 	case edge8n:
1160Sstevel@tonic-gate 	case edge8ln:
1170Sstevel@tonic-gate 	case edge16:
1180Sstevel@tonic-gate 	case edge16l:
1190Sstevel@tonic-gate 	case edge16n:
1200Sstevel@tonic-gate 	case edge16ln:
1210Sstevel@tonic-gate 	case edge32:
1220Sstevel@tonic-gate 	case edge32l:
1230Sstevel@tonic-gate 	case edge32n:
1240Sstevel@tonic-gate 	case edge32ln:
1250Sstevel@tonic-gate 		ftt = vis_edge(pfpsd, f.inst, pregs, prw);
1260Sstevel@tonic-gate 		break;
1270Sstevel@tonic-gate 	case array8:
1280Sstevel@tonic-gate 	case array16:
1290Sstevel@tonic-gate 	case array32:
1300Sstevel@tonic-gate 		ftt = vis_array(pfpsd, f.inst, pregs, prw);
1310Sstevel@tonic-gate 		break;
1320Sstevel@tonic-gate 	case alignaddr:
1330Sstevel@tonic-gate 	case alignaddrl:
1340Sstevel@tonic-gate 		ftt = vis_alignaddr(pfpsd, f.inst, pregs, prw, fp);
1350Sstevel@tonic-gate 		break;
1360Sstevel@tonic-gate 	case bmask:
1370Sstevel@tonic-gate 		ftt = vis_bmask(pfpsd, f.inst, pregs, prw, fp);
1380Sstevel@tonic-gate 		break;
1390Sstevel@tonic-gate 	case fcmple16:
1400Sstevel@tonic-gate 	case fcmpne16:
1410Sstevel@tonic-gate 	case fcmpgt16:
1420Sstevel@tonic-gate 	case fcmpeq16:
1430Sstevel@tonic-gate 	case fcmple32:
1440Sstevel@tonic-gate 	case fcmpne32:
1450Sstevel@tonic-gate 	case fcmpgt32:
1460Sstevel@tonic-gate 	case fcmpeq32:
1470Sstevel@tonic-gate 		ftt = vis_fcmp(pfpsd, f.inst, pregs, prw);
1480Sstevel@tonic-gate 		break;
1490Sstevel@tonic-gate 	case fmul8x16:
1500Sstevel@tonic-gate 	case fmul8x16au:
1510Sstevel@tonic-gate 	case fmul8x16al:
1520Sstevel@tonic-gate 	case fmul8sux16:
1530Sstevel@tonic-gate 	case fmul8ulx16:
1540Sstevel@tonic-gate 	case fmuld8sux16:
1550Sstevel@tonic-gate 	case fmuld8ulx16:
1560Sstevel@tonic-gate 		ftt = vis_fmul(pfpsd, f.inst);
1570Sstevel@tonic-gate 		break;
1580Sstevel@tonic-gate 	case fpack16:
1590Sstevel@tonic-gate 	case fpack32:
1600Sstevel@tonic-gate 	case fpackfix:
1610Sstevel@tonic-gate 	case fexpand:
1620Sstevel@tonic-gate 	case fpmerge:
1630Sstevel@tonic-gate 		ftt = vis_fpixel(pfpsd, f.inst, fp);
1640Sstevel@tonic-gate 		break;
1650Sstevel@tonic-gate 	case pdist:
1660Sstevel@tonic-gate 		ftt = vis_pdist(pfpsd, pinst);
1670Sstevel@tonic-gate 		break;
1680Sstevel@tonic-gate 	case faligndata:
1690Sstevel@tonic-gate 		ftt = vis_faligndata(pfpsd, pinst, fp);
1700Sstevel@tonic-gate 		break;
1710Sstevel@tonic-gate 	case bshuffle:
1720Sstevel@tonic-gate 		ftt = vis_bshuffle(pfpsd, pinst, fp);
1730Sstevel@tonic-gate 		break;
1740Sstevel@tonic-gate 	case fpadd16:
1750Sstevel@tonic-gate 	case fpadd16s:
1760Sstevel@tonic-gate 	case fpadd32:
1770Sstevel@tonic-gate 	case fpadd32s:
1780Sstevel@tonic-gate 	case fpsub16:
1790Sstevel@tonic-gate 	case fpsub16s:
1800Sstevel@tonic-gate 	case fpsub32:
1810Sstevel@tonic-gate 	case fpsub32s:
1820Sstevel@tonic-gate 		ftt = vis_fpaddsub(pfpsd, f.inst);
1830Sstevel@tonic-gate 		break;
1840Sstevel@tonic-gate 	case fzero:
1850Sstevel@tonic-gate 		lusr = 0;
1860Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
1870Sstevel@tonic-gate 		break;
1880Sstevel@tonic-gate 	case fzeros:
1890Sstevel@tonic-gate 		usr = 0;
1900Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
1910Sstevel@tonic-gate 		break;
1920Sstevel@tonic-gate 	case fnor:
1930Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
1940Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
1950Sstevel@tonic-gate 		lusr = ~(lus1 | lus2);
1960Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
1970Sstevel@tonic-gate 		break;
1980Sstevel@tonic-gate 	case fnors:
1990Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2000Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2010Sstevel@tonic-gate 		usr = ~(us1 | us2);
2020Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2030Sstevel@tonic-gate 		break;
2040Sstevel@tonic-gate 	case fandnot2:
2050Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2060Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2070Sstevel@tonic-gate 		lusr = (lus1 & ~lus2);
2080Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2090Sstevel@tonic-gate 		break;
2100Sstevel@tonic-gate 	case fandnot2s:
2110Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2120Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2130Sstevel@tonic-gate 		usr = (us1 & ~us2);
2140Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2150Sstevel@tonic-gate 		break;
2160Sstevel@tonic-gate 	case fnot2:
2170Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2180Sstevel@tonic-gate 		lusr = ~lus2;
2190Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2200Sstevel@tonic-gate 		break;
2210Sstevel@tonic-gate 	case fnot2s:
2220Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2230Sstevel@tonic-gate 		usr = ~us2;
2240Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2250Sstevel@tonic-gate 		break;
2260Sstevel@tonic-gate 	case fandnot1:
2270Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2280Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2290Sstevel@tonic-gate 		lusr = (~lus1 & lus2);
2300Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2310Sstevel@tonic-gate 		break;
2320Sstevel@tonic-gate 	case fandnot1s:
2330Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2340Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2350Sstevel@tonic-gate 		usr = (~us1 & us2);
2360Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2370Sstevel@tonic-gate 		break;
2380Sstevel@tonic-gate 	case fnot1:
2390Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2400Sstevel@tonic-gate 		lusr = ~lus1;
2410Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2420Sstevel@tonic-gate 		break;
2430Sstevel@tonic-gate 	case fnot1s:
2440Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2450Sstevel@tonic-gate 		usr = ~us1;
2460Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2470Sstevel@tonic-gate 		break;
2480Sstevel@tonic-gate 	case fxor:
2490Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2500Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2510Sstevel@tonic-gate 		lusr = (lus1 ^ lus2);
2520Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2530Sstevel@tonic-gate 		break;
2540Sstevel@tonic-gate 	case fxors:
2550Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2560Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2570Sstevel@tonic-gate 		usr = (us1 ^ us2);
2580Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2590Sstevel@tonic-gate 		break;
2600Sstevel@tonic-gate 	case fnand:
2610Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2620Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2630Sstevel@tonic-gate 		lusr = ~(lus1 & lus2);
2640Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2650Sstevel@tonic-gate 		break;
2660Sstevel@tonic-gate 	case fnands:
2670Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2680Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2690Sstevel@tonic-gate 		usr = ~(us1 & us2);
2700Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2710Sstevel@tonic-gate 		break;
2720Sstevel@tonic-gate 	case fand:
2730Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2740Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2750Sstevel@tonic-gate 		lusr = (lus1 & lus2);
2760Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2770Sstevel@tonic-gate 		break;
2780Sstevel@tonic-gate 	case fands:
2790Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2800Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2810Sstevel@tonic-gate 		usr = (us1 & us2);
2820Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2830Sstevel@tonic-gate 		break;
2840Sstevel@tonic-gate 	case fxnor:
2850Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2860Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2870Sstevel@tonic-gate 		lusr = ~(lus1 ^ lus2);
2880Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2890Sstevel@tonic-gate 		break;
2900Sstevel@tonic-gate 	case fxnors:
2910Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2920Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2930Sstevel@tonic-gate 		usr = ~(us1 ^ us2);
2940Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2950Sstevel@tonic-gate 		break;
2960Sstevel@tonic-gate 	case fsrc1:
2970Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lusr, nrs1);
2980Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2990Sstevel@tonic-gate 		break;
3000Sstevel@tonic-gate 	case fsrc1s:
3010Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &usr, nrs1);
3020Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3030Sstevel@tonic-gate 		break;
3040Sstevel@tonic-gate 	case fornot2:
3050Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3060Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3070Sstevel@tonic-gate 		lusr = (lus1 | ~lus2);
3080Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3090Sstevel@tonic-gate 		break;
3100Sstevel@tonic-gate 	case fornot2s:
3110Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
3120Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
3130Sstevel@tonic-gate 		usr = (us1 | ~us2);
3140Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3150Sstevel@tonic-gate 		break;
3160Sstevel@tonic-gate 	case fsrc2:
3170Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lusr, nrs2);
3180Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3190Sstevel@tonic-gate 		break;
3200Sstevel@tonic-gate 	case fsrc2s:
3210Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &usr, nrs2);
3220Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3230Sstevel@tonic-gate 		break;
3240Sstevel@tonic-gate 	case fornot1:
3250Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3260Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3270Sstevel@tonic-gate 		lusr = (~lus1 | lus2);
3280Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3290Sstevel@tonic-gate 		break;
3300Sstevel@tonic-gate 	case fornot1s:
3310Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
3320Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
3330Sstevel@tonic-gate 		usr = (~us1 | us2);
3340Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3350Sstevel@tonic-gate 		break;
3360Sstevel@tonic-gate 	case for_op:
3370Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3380Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3390Sstevel@tonic-gate 		lusr = (lus1 | lus2);
3400Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3410Sstevel@tonic-gate 		break;
3420Sstevel@tonic-gate 	case fors_op:
3430Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
3440Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
3450Sstevel@tonic-gate 		usr = (us1 | us2);
3460Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3470Sstevel@tonic-gate 		break;
3480Sstevel@tonic-gate 	case fone:
3490Sstevel@tonic-gate 		lusr = 0xffffffffffffffff;
3500Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3510Sstevel@tonic-gate 		break;
3520Sstevel@tonic-gate 	case fones:
3530Sstevel@tonic-gate 		usr = 0xffffffffUL;
3540Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3550Sstevel@tonic-gate 		break;
3560Sstevel@tonic-gate 	case siam:
3570Sstevel@tonic-gate 		ftt = vis_siam(pfpsd, f.inst, fp);
3580Sstevel@tonic-gate 		break;
3590Sstevel@tonic-gate 	default:
3600Sstevel@tonic-gate 		return (ftt_unimplemented);
3610Sstevel@tonic-gate 	}
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
3640Sstevel@tonic-gate 	pregs->r_npc += 4;
3650Sstevel@tonic-gate 	return (ftt);
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate /*
3690Sstevel@tonic-gate  * Simulator for edge instructions
3700Sstevel@tonic-gate  */
3710Sstevel@tonic-gate static enum ftt_type
3720Sstevel@tonic-gate vis_edge(
3730Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
3740Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
3750Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
3760Sstevel@tonic-gate 	void		*prw)	/* Pointer to locals and ins. */
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate {
3790Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
3800Sstevel@tonic-gate 	enum ftt_type ftt;
3810Sstevel@tonic-gate 	uint64_t addrl, addrr, mask;
3820Sstevel@tonic-gate 	uint64_t ah61l, ah61r;		/* Higher 61 bits of address */
3830Sstevel@tonic-gate 	int al3l, al3r;			/* Lower 3 bits of address */
3840Sstevel@tonic-gate 	int am32;			/* Whether PSTATE.AM == 1 */
3851246Skalai 	uint_t	ccr;
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate 	nrs1 = inst.rs1;
3880Sstevel@tonic-gate 	nrs2 = inst.rs2;
3890Sstevel@tonic-gate 	nrd = inst.rd;
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &addrl);
3920Sstevel@tonic-gate 	if (ftt != ftt_none)
3930Sstevel@tonic-gate 		return (ftt);
3940Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &addrr);
3950Sstevel@tonic-gate 	if (ftt != ftt_none)
3960Sstevel@tonic-gate 		return (ftt);
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	/* Get PSTATE.AM to determine 32-bit vs 64-bit addressing */
3997Sdf157793 	am32 =  pregs->r_tstate & TSTATE_AM;
4000Sstevel@tonic-gate 	if (am32 == 1) {
4017Sdf157793 		ah61l = addrl & 0xffffffff8;
4027Sdf157793 		ah61r = addrr & 0xffffffff8;
4030Sstevel@tonic-gate 	} else {
4040Sstevel@tonic-gate 		ah61l = addrl & ~0x7;
4050Sstevel@tonic-gate 		ah61r = addrr & ~0x7;
4060Sstevel@tonic-gate 	}
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate 	switch (inst.opf) {
4100Sstevel@tonic-gate 	case edge8:
4110Sstevel@tonic-gate 	case edge8n:
4120Sstevel@tonic-gate 	case edge8l:
4130Sstevel@tonic-gate 	case edge8ln:
4140Sstevel@tonic-gate 		al3l = addrl & 0x7;
4150Sstevel@tonic-gate 		switch (inst.opf) {
4160Sstevel@tonic-gate 		case edge8:
4170Sstevel@tonic-gate 		case edge8n:
4180Sstevel@tonic-gate 			if (inst.opf == edge8) {
4190Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8);
4200Sstevel@tonic-gate 			} else {
4210Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8n);
4220Sstevel@tonic-gate 			}
4237Sdf157793 			mask = 0xff >> al3l;
4240Sstevel@tonic-gate 			if (ah61l == ah61r) {
4250Sstevel@tonic-gate 				al3r = addrr & 0x7;
4267Sdf157793 				mask &= (0xff << (0x7 - al3r)) & 0xff;
4270Sstevel@tonic-gate 			}
4280Sstevel@tonic-gate 			break;
4290Sstevel@tonic-gate 		case edge8l:
4300Sstevel@tonic-gate 		case edge8ln:
4310Sstevel@tonic-gate 			if (inst.opf == edge8l) {
4320Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8l);
4330Sstevel@tonic-gate 			} else {
4340Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8ln);
4350Sstevel@tonic-gate 			}
4367Sdf157793 			mask = (0xff << al3l) & 0xff;
4370Sstevel@tonic-gate 			if (ah61l == ah61r) {
4380Sstevel@tonic-gate 				al3r = addrr & 0x7;
4397Sdf157793 				mask &= 0xff >> (0x7 - al3r);
4400Sstevel@tonic-gate 			}
4410Sstevel@tonic-gate 			break;
4420Sstevel@tonic-gate 		}
4430Sstevel@tonic-gate 		break;
4440Sstevel@tonic-gate 	case edge16:
4450Sstevel@tonic-gate 	case edge16l:
4460Sstevel@tonic-gate 	case edge16n:
4470Sstevel@tonic-gate 	case edge16ln:
4480Sstevel@tonic-gate 		al3l = addrl & 0x6;
4497Sdf157793 		al3l >>= 0x1;
4500Sstevel@tonic-gate 		switch (inst.opf) {
4510Sstevel@tonic-gate 		case edge16:
4520Sstevel@tonic-gate 		case edge16n:
4530Sstevel@tonic-gate 			if (inst.opf == edge16) {
4540Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16);
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate 			} else {
4570Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16n);
4580Sstevel@tonic-gate 			}
4597Sdf157793 			mask = 0xf >> al3l;
4600Sstevel@tonic-gate 			if (ah61l == ah61r) {
4610Sstevel@tonic-gate 				al3r = addrr & 0x6;
4627Sdf157793 				al3r >>= 0x1;
4637Sdf157793 				mask &= (0xf << (0x3 - al3r)) & 0xf;
4640Sstevel@tonic-gate 			}
4650Sstevel@tonic-gate 			break;
4660Sstevel@tonic-gate 		case edge16l:
4670Sstevel@tonic-gate 		case edge16ln:
4680Sstevel@tonic-gate 			if (inst.opf == edge16l) {
4690Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16l);
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate 			} else {
4720Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16ln);
4730Sstevel@tonic-gate 			}
4747Sdf157793 
4757Sdf157793 			mask = (0xf << al3l) & 0xf;
4760Sstevel@tonic-gate 			if (ah61l == ah61r) {
4770Sstevel@tonic-gate 				al3r = addrr & 0x6;
4787Sdf157793 				al3r >>= 0x1;
4797Sdf157793 				mask &= 0xf >> (0x3 - al3r);
4800Sstevel@tonic-gate 			}
4810Sstevel@tonic-gate 			break;
4820Sstevel@tonic-gate 		}
4830Sstevel@tonic-gate 		break;
4840Sstevel@tonic-gate 	case edge32:
4850Sstevel@tonic-gate 	case edge32l:
4860Sstevel@tonic-gate 	case edge32n:
4870Sstevel@tonic-gate 	case edge32ln:
4880Sstevel@tonic-gate 		al3l = addrl & 0x4;
4897Sdf157793 		al3l >>= 0x2;
4907Sdf157793 
4910Sstevel@tonic-gate 		switch (inst.opf) {
4920Sstevel@tonic-gate 		case edge32:
4930Sstevel@tonic-gate 		case edge32n:
4940Sstevel@tonic-gate 			if (inst.opf == edge32) {
4950Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32);
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 			} else {
4980Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32n);
4990Sstevel@tonic-gate 			}
5007Sdf157793 			mask = 0x3 >> al3l;
5010Sstevel@tonic-gate 			if (ah61l == ah61r) {
5020Sstevel@tonic-gate 				al3r = addrr & 0x4;
5037Sdf157793 				al3r >>= 0x2;
5047Sdf157793 				mask &= (0x3 << (0x1 - al3r)) & 0x3;
5050Sstevel@tonic-gate 			}
5060Sstevel@tonic-gate 			break;
5070Sstevel@tonic-gate 		case edge32l:
5080Sstevel@tonic-gate 		case edge32ln:
5090Sstevel@tonic-gate 			if (inst.opf == edge32l) {
5100Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32l);
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate 			} else {
5130Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32ln);
5140Sstevel@tonic-gate 			}
5157Sdf157793 			mask = (0x3 << al3l) & 0x3;
5160Sstevel@tonic-gate 			if (ah61l == ah61r) {
5170Sstevel@tonic-gate 				al3r = addrr & 0x4;
5187Sdf157793 				al3r >>= 0x2;
5197Sdf157793 				mask &= 0x3 >> (0x1 - al3r);
5200Sstevel@tonic-gate 			}
5210Sstevel@tonic-gate 			break;
5220Sstevel@tonic-gate 		}
5230Sstevel@tonic-gate 		break;
5240Sstevel@tonic-gate 	}
5257Sdf157793 
5260Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &mask);
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate 	switch (inst.opf) {
5290Sstevel@tonic-gate 	case edge8:
5300Sstevel@tonic-gate 	case edge8l:
5310Sstevel@tonic-gate 	case edge16:
5320Sstevel@tonic-gate 	case edge16l:
5330Sstevel@tonic-gate 	case edge32:
5340Sstevel@tonic-gate 	case edge32l:
5350Sstevel@tonic-gate 
5361246Skalai 		/* Update flags per SUBcc outcome */
5371246Skalai 		pregs->r_tstate &= ~((uint64_t)TSTATE_CCR_MASK
5381246Skalai 					<< TSTATE_CCR_SHIFT);
5391246Skalai 		ccr = get_subcc_ccr(addrl, addrr);  /* get subcc cond. codes */
5401246Skalai 		pregs->r_tstate |= ((uint64_t)ccr << TSTATE_CCR_SHIFT);
5411246Skalai 
5420Sstevel@tonic-gate 		break;
5430Sstevel@tonic-gate 	}
5440Sstevel@tonic-gate 	return (ftt);
5451246Skalai }
5461246Skalai 
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate  * Simulator for three dimentional array addressing instructions.
5490Sstevel@tonic-gate  */
5500Sstevel@tonic-gate static enum ftt_type
5510Sstevel@tonic-gate vis_array(
5520Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
5530Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
5540Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
5550Sstevel@tonic-gate 	void		*prw)	/* Pointer to locals and ins. */
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate {
5580Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
5590Sstevel@tonic-gate 	enum ftt_type ftt;
5600Sstevel@tonic-gate 	uint64_t laddr, bsize, baddr;
5610Sstevel@tonic-gate 	uint64_t nbit;
5620Sstevel@tonic-gate 	int oy, oz;
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 	nrs1 = inst.rs1;
5650Sstevel@tonic-gate 	nrs2 = inst.rs2;
5660Sstevel@tonic-gate 	nrd = inst.rd;
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &laddr);
5690Sstevel@tonic-gate 	if (ftt != ftt_none)
5700Sstevel@tonic-gate 		return (ftt);
5710Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &bsize);
5720Sstevel@tonic-gate 	if (ftt != ftt_none)
5730Sstevel@tonic-gate 		return (ftt);
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate 	if (bsize > 5) {
5760Sstevel@tonic-gate 		bsize = 5;
5770Sstevel@tonic-gate 	}
5780Sstevel@tonic-gate 	nbit = (1 << bsize) - 1;	/* Number of bits for XY<6+n-1:6> */
5790Sstevel@tonic-gate 	oy = 17 + bsize;		/* Offset of Y<6+n-1:6> */
5800Sstevel@tonic-gate 	oz = 17 + 2 * bsize;		/* Offset of Z<8:5> */
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate 	baddr = 0;
5830Sstevel@tonic-gate 	baddr |= (laddr >> (11 -  0)) & (0x03 <<  0);	/* X_integer<1:0> */
5840Sstevel@tonic-gate 	baddr |= (laddr >> (33 -  2)) & (0x03 <<  2);	/* Y_integer<1:0> */
5850Sstevel@tonic-gate 	baddr |= (laddr >> (55 -  4)) & (0x01 <<  4);	/* Z_integer<0>   */
5860Sstevel@tonic-gate 	baddr |= (laddr >> (13 -  5)) & (0x0f <<  5);	/* X_integer<5:2> */
5870Sstevel@tonic-gate 	baddr |= (laddr >> (35 -  9)) & (0x0f <<  9);	/* Y_integer<5:2> */
5880Sstevel@tonic-gate 	baddr |= (laddr >> (56 - 13)) & (0x0f << 13);	/* Z_integer<4:1> */
5890Sstevel@tonic-gate 	baddr |= (laddr >> (17 - 17)) & (nbit << 17);	/* X_integer<6+n-1:6> */
5900Sstevel@tonic-gate 	baddr |= (laddr >> (39 - oy)) & (nbit << oy);	/* Y_integer<6+n-1:6> */
5910Sstevel@tonic-gate 	baddr |= (laddr >> (60 - oz)) & (0x0f << oz);	/* Z_integer<8:5> */
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 	switch (inst.opf) {
5940Sstevel@tonic-gate 	case array8:
5950Sstevel@tonic-gate 		VISINFO_KSTAT(vis_array8);
5960Sstevel@tonic-gate 		break;
5970Sstevel@tonic-gate 	case array16:
5980Sstevel@tonic-gate 		VISINFO_KSTAT(vis_array16);
5990Sstevel@tonic-gate 		baddr <<= 1;
6000Sstevel@tonic-gate 		break;
6010Sstevel@tonic-gate 	case array32:
6020Sstevel@tonic-gate 		VISINFO_KSTAT(vis_array32);
6030Sstevel@tonic-gate 		baddr <<= 2;
6040Sstevel@tonic-gate 		break;
6050Sstevel@tonic-gate 	}
6060Sstevel@tonic-gate 
6070Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &baddr);
6080Sstevel@tonic-gate 
6090Sstevel@tonic-gate 	return (ftt);
6100Sstevel@tonic-gate }
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate /*
6130Sstevel@tonic-gate  * Simulator for alignaddr and alignaddrl instructions.
6140Sstevel@tonic-gate  */
6150Sstevel@tonic-gate static enum ftt_type
6160Sstevel@tonic-gate vis_alignaddr(
6170Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
6180Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
6190Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
6200Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
6210Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
6220Sstevel@tonic-gate {
6230Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
6240Sstevel@tonic-gate 	enum ftt_type ftt;
6250Sstevel@tonic-gate 	uint64_t ea, tea, g, r;
6260Sstevel@tonic-gate 	short s;
6270Sstevel@tonic-gate 
6280Sstevel@tonic-gate 	nrs1 = inst.rs1;
6290Sstevel@tonic-gate 	nrs2 = inst.rs2;
6300Sstevel@tonic-gate 	nrd = inst.rd;
6310Sstevel@tonic-gate 
6320Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
6330Sstevel@tonic-gate 	if (ftt != ftt_none)
6340Sstevel@tonic-gate 		return (ftt);
6350Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
6360Sstevel@tonic-gate 	if (ftt != ftt_none)
6370Sstevel@tonic-gate 		return (ftt);
6380Sstevel@tonic-gate 	ea += tea;
6390Sstevel@tonic-gate 	r = ea & ~0x7;	/* zero least 3 significant bits */
6400Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &r);
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate 
6437Sdf157793 	g = pfpsd->fp_current_read_gsr(fp);
6440Sstevel@tonic-gate 	g &= ~(GSR_ALIGN_MASK);		/* zero the align offset */
6450Sstevel@tonic-gate 	r = ea & 0x7;
6460Sstevel@tonic-gate 	if (inst.opf == alignaddrl) {
6470Sstevel@tonic-gate 		s = (short)(~r);	/* 2's complement for alignaddrl */
6480Sstevel@tonic-gate 		if (s < 0)
6490Sstevel@tonic-gate 			r = (uint64_t)((s + 1) & 0x7);
6500Sstevel@tonic-gate 		else
6510Sstevel@tonic-gate 			r = (uint64_t)(s & 0x7);
6520Sstevel@tonic-gate 	}
6530Sstevel@tonic-gate 	g |= (r << GSR_ALIGN_SHIFT) & GSR_ALIGN_MASK;
6547Sdf157793 	pfpsd->fp_current_write_gsr(g, fp);
6550Sstevel@tonic-gate 
6560Sstevel@tonic-gate 	return (ftt);
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate /*
6600Sstevel@tonic-gate  * Simulator for bmask instruction.
6610Sstevel@tonic-gate  */
6620Sstevel@tonic-gate static enum ftt_type
6630Sstevel@tonic-gate vis_bmask(
6640Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
6650Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
6660Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
6670Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
6680Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
6690Sstevel@tonic-gate {
6700Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
6710Sstevel@tonic-gate 	enum ftt_type ftt;
6720Sstevel@tonic-gate 	uint64_t ea, tea, g;
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate 	VISINFO_KSTAT(vis_bmask);
6750Sstevel@tonic-gate 	nrs1 = inst.rs1;
6760Sstevel@tonic-gate 	nrs2 = inst.rs2;
6770Sstevel@tonic-gate 	nrd = inst.rd;
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
6800Sstevel@tonic-gate 	if (ftt != ftt_none)
6810Sstevel@tonic-gate 		return (ftt);
6820Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
6830Sstevel@tonic-gate 	if (ftt != ftt_none)
6840Sstevel@tonic-gate 		return (ftt);
6850Sstevel@tonic-gate 	ea += tea;
6860Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &ea);
6870Sstevel@tonic-gate 
6887Sdf157793 	g = pfpsd->fp_current_read_gsr(fp);
6890Sstevel@tonic-gate 	g &= ~(GSR_MASK_MASK);		/* zero the mask offset */
6900Sstevel@tonic-gate 
6910Sstevel@tonic-gate 	/* Put the least significant 32 bits of ea in GSR.mask */
6920Sstevel@tonic-gate 	g |= (ea << GSR_MASK_SHIFT) & GSR_MASK_MASK;
6937Sdf157793 	pfpsd->fp_current_write_gsr(g, fp);
6940Sstevel@tonic-gate 	return (ftt);
6950Sstevel@tonic-gate }
6960Sstevel@tonic-gate 
6970Sstevel@tonic-gate /*
6980Sstevel@tonic-gate  * Simulator for fp[add|sub]* instruction.
6990Sstevel@tonic-gate  */
7000Sstevel@tonic-gate static enum ftt_type
7010Sstevel@tonic-gate vis_fpaddsub(
7020Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
7030Sstevel@tonic-gate 	vis_inst_type	inst)	/* FPU instruction to simulate. */
7040Sstevel@tonic-gate {
7050Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
7060Sstevel@tonic-gate 	union {
7070Sstevel@tonic-gate 		uint64_t	ll;
7080Sstevel@tonic-gate 		uint32_t	i[2];
7090Sstevel@tonic-gate 		uint16_t	s[4];
7100Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
7110Sstevel@tonic-gate 	union {
7120Sstevel@tonic-gate 		uint32_t	i;
7130Sstevel@tonic-gate 		uint16_t	s[2];
7140Sstevel@tonic-gate 	} krs1, krs2, krd;
7150Sstevel@tonic-gate 	int i;
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate 	nrs1 = inst.rs1;
7180Sstevel@tonic-gate 	nrs2 = inst.rs2;
7190Sstevel@tonic-gate 	nrd = inst.rd;
7200Sstevel@tonic-gate 	if ((inst.opf & 1) == 0) {	/* double precision */
7210Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
7220Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
7230Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
7240Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
7250Sstevel@tonic-gate 		if ((nrd & 1) == 1)
7260Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
7270Sstevel@tonic-gate 	}
7280Sstevel@tonic-gate 	switch (inst.opf) {
7290Sstevel@tonic-gate 	case fpadd16:
7300Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7310Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7320Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
7330Sstevel@tonic-gate 			lrd.s[i] = lrs1.s[i] + lrs2.s[i];
7340Sstevel@tonic-gate 		}
7350Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7360Sstevel@tonic-gate 		break;
7370Sstevel@tonic-gate 	case fpadd16s:
7380Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7390Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7400Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7410Sstevel@tonic-gate 			krd.s[i] = krs1.s[i] + krs2.s[i];
7420Sstevel@tonic-gate 		}
7430Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7440Sstevel@tonic-gate 		break;
7450Sstevel@tonic-gate 	case fpadd32:
7460Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7470Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7480Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7490Sstevel@tonic-gate 			lrd.i[i] = lrs1.i[i] + lrs2.i[i];
7500Sstevel@tonic-gate 		}
7510Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7520Sstevel@tonic-gate 		break;
7530Sstevel@tonic-gate 	case fpadd32s:
7540Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7550Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7560Sstevel@tonic-gate 		krd.i = krs1.i + krs2.i;
7570Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7580Sstevel@tonic-gate 		break;
7590Sstevel@tonic-gate 	case fpsub16:
7600Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7610Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7620Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
7630Sstevel@tonic-gate 			lrd.s[i] = lrs1.s[i] - lrs2.s[i];
7640Sstevel@tonic-gate 		}
7650Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7660Sstevel@tonic-gate 		break;
7670Sstevel@tonic-gate 	case fpsub16s:
7680Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7690Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7700Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7710Sstevel@tonic-gate 			krd.s[i] = krs1.s[i] - krs2.s[i];
7720Sstevel@tonic-gate 		}
7730Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7740Sstevel@tonic-gate 		break;
7750Sstevel@tonic-gate 	case fpsub32:
7760Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7770Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7780Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7790Sstevel@tonic-gate 			lrd.i[i] = lrs1.i[i] - lrs2.i[i];
7800Sstevel@tonic-gate 		}
7810Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7820Sstevel@tonic-gate 		break;
7830Sstevel@tonic-gate 	case fpsub32s:
7840Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7850Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7860Sstevel@tonic-gate 		krd.i = krs1.i - krs2.i;
7870Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7880Sstevel@tonic-gate 		break;
7890Sstevel@tonic-gate 	}
7900Sstevel@tonic-gate 	return (ftt_none);
7910Sstevel@tonic-gate }
7920Sstevel@tonic-gate 
7930Sstevel@tonic-gate /*
7940Sstevel@tonic-gate  * Simulator for fcmp* instruction.
7950Sstevel@tonic-gate  */
7960Sstevel@tonic-gate static enum ftt_type
7970Sstevel@tonic-gate vis_fcmp(
7980Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
7990Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
8000Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
8010Sstevel@tonic-gate 	void		*prw)	/* Pointer to locals and ins. */
8020Sstevel@tonic-gate {
8030Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
8040Sstevel@tonic-gate 	union {
8050Sstevel@tonic-gate 		uint64_t	ll;
8060Sstevel@tonic-gate 		uint32_t	i[2];
8070Sstevel@tonic-gate 		uint16_t	s[4];
8080Sstevel@tonic-gate 	} krs1, krs2, krd;
8090Sstevel@tonic-gate 	enum ftt_type ftt;
8100Sstevel@tonic-gate 	short sr1, sr2;
8110Sstevel@tonic-gate 	int i, ir1, ir2;
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate 	nrs1 = inst.rs1;
8140Sstevel@tonic-gate 	nrs2 = inst.rs2;
8150Sstevel@tonic-gate 	nrd = inst.rd;
8160Sstevel@tonic-gate 	krd.ll = 0;
8170Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 	/* fix register encoding */
8180Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
8190Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
8200Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
8210Sstevel@tonic-gate 
8220Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &krs1.ll, nrs1);
8230Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &krs2.ll, nrs2);
8240Sstevel@tonic-gate 	switch (inst.opf) {
8250Sstevel@tonic-gate 	case fcmple16:
8260Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmple16);
8270Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8280Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8290Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8300Sstevel@tonic-gate 			if (sr1 <= sr2)
8310Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8320Sstevel@tonic-gate 		}
8330Sstevel@tonic-gate 		break;
8340Sstevel@tonic-gate 	case fcmpne16:
8350Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpne16);
8360Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8370Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8380Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8390Sstevel@tonic-gate 			if (sr1 != sr2)
8400Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8410Sstevel@tonic-gate 		}
8420Sstevel@tonic-gate 		break;
8430Sstevel@tonic-gate 	case fcmpgt16:
8440Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpgt16);
8450Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8460Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8470Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8480Sstevel@tonic-gate 			if (sr1 > sr2)
8490Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8500Sstevel@tonic-gate 		}
8510Sstevel@tonic-gate 		break;
8520Sstevel@tonic-gate 	case fcmpeq16:
8530Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpeq16);
8540Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8550Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8560Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8570Sstevel@tonic-gate 			if (sr1 == sr2)
8580Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8590Sstevel@tonic-gate 		}
8600Sstevel@tonic-gate 		break;
8610Sstevel@tonic-gate 	case fcmple32:
8620Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmple32);
8630Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8640Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8650Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8660Sstevel@tonic-gate 			if (ir1 <= ir2)
8670Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8680Sstevel@tonic-gate 		}
8690Sstevel@tonic-gate 		break;
8700Sstevel@tonic-gate 	case fcmpne32:
8710Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpne32);
8720Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8730Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8740Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8750Sstevel@tonic-gate 			if (ir1 != ir2)
8760Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8770Sstevel@tonic-gate 		}
8780Sstevel@tonic-gate 		break;
8790Sstevel@tonic-gate 	case fcmpgt32:
8800Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpgt32);
8810Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8820Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8830Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8840Sstevel@tonic-gate 			if (ir1 > ir2)
8850Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8860Sstevel@tonic-gate 		}
8870Sstevel@tonic-gate 		break;
8880Sstevel@tonic-gate 	case fcmpeq32:
8890Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpeq32);
8900Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8910Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8920Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8930Sstevel@tonic-gate 			if (ir1 == ir2)
8940Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8950Sstevel@tonic-gate 		}
8960Sstevel@tonic-gate 		break;
8970Sstevel@tonic-gate 	}
8980Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &krd.ll);
8990Sstevel@tonic-gate 	return (ftt);
9000Sstevel@tonic-gate }
9010Sstevel@tonic-gate 
9020Sstevel@tonic-gate /*
9030Sstevel@tonic-gate  * Simulator for fmul* instruction.
9040Sstevel@tonic-gate  */
9050Sstevel@tonic-gate static enum ftt_type
9060Sstevel@tonic-gate vis_fmul(
9070Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
9080Sstevel@tonic-gate 	vis_inst_type	inst)	/* FPU instruction to simulate. */
9090Sstevel@tonic-gate {
9100Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
9110Sstevel@tonic-gate 	union {
9120Sstevel@tonic-gate 		uint64_t	ll;
9130Sstevel@tonic-gate 		uint32_t	i[2];
9140Sstevel@tonic-gate 		uint16_t	s[4];
9150Sstevel@tonic-gate 		uint8_t		c[8];
9160Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
9170Sstevel@tonic-gate 	union {
9180Sstevel@tonic-gate 		uint32_t	i;
9190Sstevel@tonic-gate 		uint16_t	s[2];
9200Sstevel@tonic-gate 		uint8_t		c[4];
9210Sstevel@tonic-gate 	} krs1, krs2, kres;
9220Sstevel@tonic-gate 	short s1, s2, sres;
9230Sstevel@tonic-gate 	ushort_t us1;
9240Sstevel@tonic-gate 	char c1;
9250Sstevel@tonic-gate 	int i;
9260Sstevel@tonic-gate 
9270Sstevel@tonic-gate 	nrs1 = inst.rs1;
9280Sstevel@tonic-gate 	nrs2 = inst.rs2;
9290Sstevel@tonic-gate 	nrd = inst.rd;
9300Sstevel@tonic-gate 	if ((inst.opf & 1) == 0) {	/* double precision */
9310Sstevel@tonic-gate 		if ((nrd & 1) == 1) 	/* fix register encoding */
9320Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
9330Sstevel@tonic-gate 	}
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate 	switch (inst.opf) {
9360Sstevel@tonic-gate 	case fmul8x16:
9370Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8x16);
9380Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9390Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
9400Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
9410Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
9420Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9430Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[i];
9440Sstevel@tonic-gate 			s2 = (short)lrs2.s[i];
9450Sstevel@tonic-gate 			kres.i = us1 * s2;
9460Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9470Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9480Sstevel@tonic-gate 				sres++;
9490Sstevel@tonic-gate 			lrd.s[i] = sres;
9500Sstevel@tonic-gate 		}
9510Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9520Sstevel@tonic-gate 		break;
9530Sstevel@tonic-gate 	case fmul8x16au:
9540Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8x16au);
9550Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9560Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
9570Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9580Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[i];
9590Sstevel@tonic-gate 			s2 = (short)krs2.s[0];
9600Sstevel@tonic-gate 			kres.i = us1 * s2;
9610Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9620Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9630Sstevel@tonic-gate 				sres++;
9640Sstevel@tonic-gate 			lrd.s[i] = sres;
9650Sstevel@tonic-gate 		}
9660Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9670Sstevel@tonic-gate 		break;
9680Sstevel@tonic-gate 	case fmul8x16al:
9690Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8x16al);
9700Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9710Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
9720Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9730Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[i];
9740Sstevel@tonic-gate 			s2 = (short)krs2.s[1];
9750Sstevel@tonic-gate 			kres.i = us1 * s2;
9760Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9770Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9780Sstevel@tonic-gate 				sres++;
9790Sstevel@tonic-gate 			lrd.s[i] = sres;
9800Sstevel@tonic-gate 		}
9810Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9820Sstevel@tonic-gate 		break;
9830Sstevel@tonic-gate 	case fmul8sux16:
9840Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8sux16);
9850Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
9860Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
9870Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
9880Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
9890Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
9900Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
9910Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9920Sstevel@tonic-gate 			c1 = lrs1.c[(i*2)];
9930Sstevel@tonic-gate 			s1 = (short)c1;		/* keeps the sign alive */
9940Sstevel@tonic-gate 			s2 = (short)lrs2.s[i];
9950Sstevel@tonic-gate 			kres.i = s1 * s2;
9960Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9970Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9980Sstevel@tonic-gate 				sres++;
9990Sstevel@tonic-gate 			if (sres < 0)
10000Sstevel@tonic-gate 				lrd.s[i] = (sres & 0xFFFF);
10010Sstevel@tonic-gate 			else
10020Sstevel@tonic-gate 				lrd.s[i] = sres;
10030Sstevel@tonic-gate 		}
10040Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10050Sstevel@tonic-gate 		break;
10060Sstevel@tonic-gate 	case fmul8ulx16:
10070Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8ulx16);
10080Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
10090Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
10100Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
10110Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
10120Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
10130Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
10140Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
10150Sstevel@tonic-gate 			us1 = (ushort_t)lrs1.c[(i*2)+1];
10160Sstevel@tonic-gate 			s2 = (short)lrs2.s[i];
10170Sstevel@tonic-gate 			kres.i = us1 * s2;
10180Sstevel@tonic-gate 			sres = (short)kres.s[0];
10190Sstevel@tonic-gate 			if (kres.s[1] >= 0x8000)
10200Sstevel@tonic-gate 				sres++;
10210Sstevel@tonic-gate 			lrd.s[i] = sres;
10220Sstevel@tonic-gate 		}
10230Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10240Sstevel@tonic-gate 		break;
10250Sstevel@tonic-gate 	case fmuld8sux16:
10260Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmuld8sux16);
10270Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
10280Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
10290Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
10300Sstevel@tonic-gate 			c1 = krs1.c[(i*2)];
10310Sstevel@tonic-gate 			s1 = (short)c1;		/* keeps the sign alive */
10320Sstevel@tonic-gate 			s2 = (short)krs2.s[i];
10330Sstevel@tonic-gate 			kres.i = s1 * s2;
10340Sstevel@tonic-gate 			lrd.i[i] = kres.i << 8;
10350Sstevel@tonic-gate 		}
10360Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10370Sstevel@tonic-gate 		break;
10380Sstevel@tonic-gate 	case fmuld8ulx16:
10390Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmuld8ulx16);
10400Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
10410Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
10420Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
10430Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[(i*2)+1];
10440Sstevel@tonic-gate 			s2 = (short)krs2.s[i];
10450Sstevel@tonic-gate 			lrd.i[i] = us1 * s2;
10460Sstevel@tonic-gate 		}
10470Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10480Sstevel@tonic-gate 		break;
10490Sstevel@tonic-gate 	}
10500Sstevel@tonic-gate 	return (ftt_none);
10510Sstevel@tonic-gate }
10520Sstevel@tonic-gate 
10530Sstevel@tonic-gate /*
10540Sstevel@tonic-gate  * Simulator for fpixel formatting instructions.
10550Sstevel@tonic-gate  */
10560Sstevel@tonic-gate static enum ftt_type
10570Sstevel@tonic-gate vis_fpixel(
10580Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
10590Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
10600Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
10610Sstevel@tonic-gate {
10620Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
10630Sstevel@tonic-gate 	int	i, j, k, sf;
10640Sstevel@tonic-gate 	union {
10650Sstevel@tonic-gate 		uint64_t	ll;
10660Sstevel@tonic-gate 		uint32_t	i[2];
10670Sstevel@tonic-gate 		uint16_t	s[4];
10680Sstevel@tonic-gate 		uint8_t		c[8];
10690Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
10700Sstevel@tonic-gate 	union {
10710Sstevel@tonic-gate 		uint32_t	i;
10720Sstevel@tonic-gate 		uint16_t	s[2];
10730Sstevel@tonic-gate 		uint8_t		c[4];
10740Sstevel@tonic-gate 	} krs1, krs2, krd;
10750Sstevel@tonic-gate 	uint64_t r;
10760Sstevel@tonic-gate 	int64_t l, m;
10770Sstevel@tonic-gate 	short s;
10780Sstevel@tonic-gate 	uchar_t uc;
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate 	nrs1 = inst.rs1;
10810Sstevel@tonic-gate 	nrs2 = inst.rs2;
10820Sstevel@tonic-gate 	nrd = inst.rd;
10830Sstevel@tonic-gate 	if ((inst.opf != fpack16) && (inst.opf != fpackfix)) {
10840Sstevel@tonic-gate 		if ((nrd & 1) == 1) 	/* fix register encoding */
10850Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
10860Sstevel@tonic-gate 	}
10870Sstevel@tonic-gate 
10880Sstevel@tonic-gate 	switch (inst.opf) {
10890Sstevel@tonic-gate 	case fpack16:
10900Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpack16);
10910Sstevel@tonic-gate 		if ((nrs2 & 1) == 1) 	/* fix register encoding */
10920Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
10930Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
10947Sdf157793 		r = pfpsd->fp_current_read_gsr(fp);
10950Sstevel@tonic-gate 		/* fpack16 ignores GSR.scale msb */
10960Sstevel@tonic-gate 		sf = (int)(GSR_SCALE(r) & 0xf);
10970Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
10980Sstevel@tonic-gate 			s = (short)lrs2.s[i];	/* preserve the sign */
10990Sstevel@tonic-gate 			j = ((int)s << sf);
11000Sstevel@tonic-gate 			k = j >> 7;
11010Sstevel@tonic-gate 			if (k < 0) {
11020Sstevel@tonic-gate 				uc = 0;
11030Sstevel@tonic-gate 			} else if (k > 255) {
11040Sstevel@tonic-gate 				uc = 255;
11050Sstevel@tonic-gate 			} else {
11060Sstevel@tonic-gate 				uc = (uchar_t)k;
11070Sstevel@tonic-gate 			}
11080Sstevel@tonic-gate 			krd.c[i] = uc;
11090Sstevel@tonic-gate 		}
11100Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
11110Sstevel@tonic-gate 		break;
11120Sstevel@tonic-gate 	case fpack32:
11130Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpack32);
11140Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
11150Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
11160Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
11170Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
11180Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
11190Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
11200Sstevel@tonic-gate 
11217Sdf157793 		r = pfpsd->fp_current_read_gsr(fp);
11220Sstevel@tonic-gate 		sf = (int)GSR_SCALE(r);
11230Sstevel@tonic-gate 		lrd.ll = lrs1.ll << 8;
11240Sstevel@tonic-gate 		for (i = 0, k = 3; i <= 1; i++, k += 4) {
11250Sstevel@tonic-gate 			j = (int)lrs2.i[i];	/* preserve the sign */
11260Sstevel@tonic-gate 			l = ((int64_t)j << sf);
11270Sstevel@tonic-gate 			m = l >> 23;
11280Sstevel@tonic-gate 			if (m < 0) {
11290Sstevel@tonic-gate 				uc = 0;
11300Sstevel@tonic-gate 			} else if (m > 255) {
11310Sstevel@tonic-gate 				uc = 255;
11320Sstevel@tonic-gate 			} else {
11330Sstevel@tonic-gate 				uc = (uchar_t)m;
11340Sstevel@tonic-gate 			}
11350Sstevel@tonic-gate 			lrd.c[k] = uc;
11360Sstevel@tonic-gate 		}
11370Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11380Sstevel@tonic-gate 		break;
11390Sstevel@tonic-gate 	case fpackfix:
11400Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpackfix);
11410Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
11420Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
11430Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
11440Sstevel@tonic-gate 
11457Sdf157793 		r = pfpsd->fp_current_read_gsr(fp);
11460Sstevel@tonic-gate 		sf = (int)GSR_SCALE(r);
11470Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
11480Sstevel@tonic-gate 			j = (int)lrs2.i[i];	/* preserve the sign */
11490Sstevel@tonic-gate 			l = ((int64_t)j << sf);
11500Sstevel@tonic-gate 			m = l >> 16;
11510Sstevel@tonic-gate 			if (m < -32768) {
11520Sstevel@tonic-gate 				s = -32768;
11530Sstevel@tonic-gate 			} else if (m > 32767) {
11540Sstevel@tonic-gate 				s = 32767;
11550Sstevel@tonic-gate 			} else {
11560Sstevel@tonic-gate 				s = (short)m;
11570Sstevel@tonic-gate 			}
11580Sstevel@tonic-gate 			krd.s[i] = s;
11590Sstevel@tonic-gate 		}
11600Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
11610Sstevel@tonic-gate 		break;
11620Sstevel@tonic-gate 	case fexpand:
11630Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fexpand);
11640Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
11650Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
11660Sstevel@tonic-gate 			uc = krs2.c[i];
11670Sstevel@tonic-gate 			lrd.s[i] = (ushort_t)(uc << 4);
11680Sstevel@tonic-gate 		}
11690Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11700Sstevel@tonic-gate 		break;
11710Sstevel@tonic-gate 	case fpmerge:
11720Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpmerge);
11730Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
11740Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
11750Sstevel@tonic-gate 		for (i = 0, j = 0; i <= 3; i++, j += 2) {
11760Sstevel@tonic-gate 			lrd.c[j] = krs1.c[i];
11770Sstevel@tonic-gate 			lrd.c[j+1] = krs2.c[i];
11780Sstevel@tonic-gate 		}
11790Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11800Sstevel@tonic-gate 		break;
11810Sstevel@tonic-gate 	}
11820Sstevel@tonic-gate 	return (ftt_none);
11830Sstevel@tonic-gate }
11840Sstevel@tonic-gate 
11850Sstevel@tonic-gate /*
11860Sstevel@tonic-gate  * Simulator for pdist instruction.
11870Sstevel@tonic-gate  */
11880Sstevel@tonic-gate enum ftt_type
11890Sstevel@tonic-gate vis_pdist(
11900Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
11910Sstevel@tonic-gate 	fp_inst_type	pinst)	/* FPU instruction to simulate. */
11920Sstevel@tonic-gate {
11930Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
11940Sstevel@tonic-gate 	int	i;
11950Sstevel@tonic-gate 	short	s;
11960Sstevel@tonic-gate 	union {
11970Sstevel@tonic-gate 		uint64_t	ll;
11980Sstevel@tonic-gate 		uint8_t		c[8];
11990Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
12000Sstevel@tonic-gate 
12010Sstevel@tonic-gate 	nrs1 = pinst.rs1;
12020Sstevel@tonic-gate 	nrs2 = pinst.rs2;
12030Sstevel@tonic-gate 	nrd = pinst.rd;
12040Sstevel@tonic-gate 	VISINFO_KSTAT(vis_pdist);
12050Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12060Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
12070Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
12080Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
12090Sstevel@tonic-gate 	if ((nrd & 1) == 1)
12100Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
12110Sstevel@tonic-gate 
12120Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
12130Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
12140Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrd.ll, nrd);
12150Sstevel@tonic-gate 
12160Sstevel@tonic-gate 	for (i = 0; i <= 7; i++) {
12170Sstevel@tonic-gate 		s = (short)(lrs1.c[i] - lrs2.c[i]);
12180Sstevel@tonic-gate 		if (s < 0)
12190Sstevel@tonic-gate 			s = ~s + 1;
12200Sstevel@tonic-gate 		lrd.ll += s;
12210Sstevel@tonic-gate 	}
12220Sstevel@tonic-gate 
12230Sstevel@tonic-gate 	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
12240Sstevel@tonic-gate 	return (ftt_none);
12250Sstevel@tonic-gate }
12260Sstevel@tonic-gate 
12270Sstevel@tonic-gate /*
12280Sstevel@tonic-gate  * Simulator for faligndata instruction.
12290Sstevel@tonic-gate  */
12300Sstevel@tonic-gate static enum ftt_type
12310Sstevel@tonic-gate vis_faligndata(
12320Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
12330Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
12340Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
12350Sstevel@tonic-gate {
12360Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
12370Sstevel@tonic-gate 	int	i, j, k, ao;
12380Sstevel@tonic-gate 	union {
12390Sstevel@tonic-gate 		uint64_t	ll;
12400Sstevel@tonic-gate 		uint8_t		c[8];
12410Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
12420Sstevel@tonic-gate 	uint64_t r;
12430Sstevel@tonic-gate 
12440Sstevel@tonic-gate 	nrs1 = pinst.rs1;
12450Sstevel@tonic-gate 	nrs2 = pinst.rs2;
12460Sstevel@tonic-gate 	nrd = pinst.rd;
12470Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12480Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
12490Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
12500Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
12510Sstevel@tonic-gate 	if ((nrd & 1) == 1)
12520Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
12530Sstevel@tonic-gate 
12540Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
12550Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
12560Sstevel@tonic-gate 
12577Sdf157793 	r = pfpsd->fp_current_read_gsr(fp);
12580Sstevel@tonic-gate 	ao = (int)GSR_ALIGN(r);
12590Sstevel@tonic-gate 
12600Sstevel@tonic-gate 	for (i = 0, j = ao, k = 0; i <= 7; i++)
12610Sstevel@tonic-gate 		if (j <= 7) {
12620Sstevel@tonic-gate 			lrd.c[i] = lrs1.c[j++];
12630Sstevel@tonic-gate 		} else {
12640Sstevel@tonic-gate 			lrd.c[i] = lrs2.c[k++];
12650Sstevel@tonic-gate 		}
12660Sstevel@tonic-gate 	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
12670Sstevel@tonic-gate 
12680Sstevel@tonic-gate 	return (ftt_none);
12690Sstevel@tonic-gate }
12700Sstevel@tonic-gate 
12710Sstevel@tonic-gate /*
12720Sstevel@tonic-gate  * Simulator for bshuffle instruction.
12730Sstevel@tonic-gate  */
12740Sstevel@tonic-gate static enum ftt_type
12750Sstevel@tonic-gate vis_bshuffle(
12760Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
12770Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
12780Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
12790Sstevel@tonic-gate {
12800Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
12810Sstevel@tonic-gate 	int	i, j, ao;
12820Sstevel@tonic-gate 	union {
12830Sstevel@tonic-gate 		uint64_t	ll;
12840Sstevel@tonic-gate 		uint8_t		c[8];
12850Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
12860Sstevel@tonic-gate 	uint64_t r;
12870Sstevel@tonic-gate 
12880Sstevel@tonic-gate 	VISINFO_KSTAT(vis_bshuffle);
12890Sstevel@tonic-gate 	nrs1 = pinst.rs1;
12900Sstevel@tonic-gate 	nrs2 = pinst.rs2;
12910Sstevel@tonic-gate 	nrd = pinst.rd;
12920Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12930Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
12940Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
12950Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
12960Sstevel@tonic-gate 	if ((nrd & 1) == 1)
12970Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
12980Sstevel@tonic-gate 
12990Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
13000Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
13010Sstevel@tonic-gate 
13027Sdf157793 	r = pfpsd->fp_current_read_gsr(fp);
13030Sstevel@tonic-gate 	ao = (int)GSR_MASK(r);
13040Sstevel@tonic-gate 
13050Sstevel@tonic-gate 	/*
13060Sstevel@tonic-gate 	 * BSHUFFLE Destination Byte Selection
13070Sstevel@tonic-gate 	 * rd Byte	Source
13080Sstevel@tonic-gate 	 * 0		rs byte[GSR.mask<31..28>]
13090Sstevel@tonic-gate 	 * 1		rs byte[GSR.mask<27..24>]
13100Sstevel@tonic-gate 	 * 2		rs byte[GSR.mask<23..20>]
13110Sstevel@tonic-gate 	 * 3		rs byte[GSR.mask<19..16>]
13120Sstevel@tonic-gate 	 * 4		rs byte[GSR.mask<15..12>]
13130Sstevel@tonic-gate 	 * 5		rs byte[GSR.mask<11..8>]
13140Sstevel@tonic-gate 	 * 6		rs byte[GSR.mask<7..4>]
13150Sstevel@tonic-gate 	 * 7		rs byte[GSR.mask<3..0>]
13160Sstevel@tonic-gate 	 * P.S. rs1 is the upper half and rs2 is the lower half
13170Sstevel@tonic-gate 	 * Bytes in the source value are numbered from most to
13180Sstevel@tonic-gate 	 * least significant
13190Sstevel@tonic-gate 	 */
13200Sstevel@tonic-gate 	for (i = 7; i >= 0; i--, ao = (ao >> 4)) {
13210Sstevel@tonic-gate 		j = ao & 0xf;		/* get byte number */
13220Sstevel@tonic-gate 		if (j < 8) {
13230Sstevel@tonic-gate 			lrd.c[i] = lrs1.c[j];
13240Sstevel@tonic-gate 		} else {
13250Sstevel@tonic-gate 			lrd.c[i] = lrs2.c[j - 8];
13260Sstevel@tonic-gate 		}
13270Sstevel@tonic-gate 	}
13280Sstevel@tonic-gate 	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
13290Sstevel@tonic-gate 
13300Sstevel@tonic-gate 	return (ftt_none);
13310Sstevel@tonic-gate }
13320Sstevel@tonic-gate 
13330Sstevel@tonic-gate /*
13340Sstevel@tonic-gate  * Simulator for siam instruction.
13350Sstevel@tonic-gate  */
13360Sstevel@tonic-gate static enum ftt_type
13370Sstevel@tonic-gate vis_siam(
13380Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
13390Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
13400Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
13410Sstevel@tonic-gate {
13420Sstevel@tonic-gate 	uint_t	nrs2;			/* Register number fields. */
13430Sstevel@tonic-gate 	uint64_t g, r;
13440Sstevel@tonic-gate 	nrs2 = inst.rs2;
13450Sstevel@tonic-gate 
13467Sdf157793 	g = pfpsd->fp_current_read_gsr(fp);
13470Sstevel@tonic-gate 	g &= ~(GSR_IM_IRND_MASK);	/* zero the IM and IRND fields */
13480Sstevel@tonic-gate 	r = nrs2 & 0x7;			/* get mode(3 bit) */
13490Sstevel@tonic-gate 	g |= (r << GSR_IRND_SHIFT);
13507Sdf157793 	pfpsd->fp_current_write_gsr(g, fp);
13510Sstevel@tonic-gate 	return (ftt_none);
13520Sstevel@tonic-gate }
13530Sstevel@tonic-gate 
13540Sstevel@tonic-gate /*
13550Sstevel@tonic-gate  * Simulator for VIS loads and stores between floating-point unit and memory.
13560Sstevel@tonic-gate  */
13570Sstevel@tonic-gate enum ftt_type
13580Sstevel@tonic-gate vis_fldst(
13590Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
13600Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
13610Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
13620Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
13630Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
13640Sstevel@tonic-gate {
13650Sstevel@tonic-gate 	union {
13660Sstevel@tonic-gate 		vis_inst_type	inst;
13670Sstevel@tonic-gate 		fp_inst_type	pinst;
13680Sstevel@tonic-gate 	} i;
13690Sstevel@tonic-gate 
13700Sstevel@tonic-gate 	ASSERT(USERMODE(pregs->r_tstate));
13710Sstevel@tonic-gate 	i.pinst = pinst;
13720Sstevel@tonic-gate 	switch (asi) {
13730Sstevel@tonic-gate 		case ASI_PST8_P:
13740Sstevel@tonic-gate 		case ASI_PST8_S:
13750Sstevel@tonic-gate 		case ASI_PST16_P:
13760Sstevel@tonic-gate 		case ASI_PST16_S:
13770Sstevel@tonic-gate 		case ASI_PST32_P:
13780Sstevel@tonic-gate 		case ASI_PST32_S:
13790Sstevel@tonic-gate 		case ASI_PST8_PL:
13800Sstevel@tonic-gate 		case ASI_PST8_SL:
13810Sstevel@tonic-gate 		case ASI_PST16_PL:
13820Sstevel@tonic-gate 		case ASI_PST16_SL:
13830Sstevel@tonic-gate 		case ASI_PST32_PL:
13840Sstevel@tonic-gate 		case ASI_PST32_SL:
13850Sstevel@tonic-gate 			return (vis_prtl_fst(pfpsd, i.inst, pregs,
13860Sstevel@tonic-gate 				prw, asi));
13870Sstevel@tonic-gate 		case ASI_FL8_P:
13880Sstevel@tonic-gate 		case ASI_FL8_S:
13890Sstevel@tonic-gate 		case ASI_FL8_PL:
13900Sstevel@tonic-gate 		case ASI_FL8_SL:
13910Sstevel@tonic-gate 		case ASI_FL16_P:
13920Sstevel@tonic-gate 		case ASI_FL16_S:
13930Sstevel@tonic-gate 		case ASI_FL16_PL:
13940Sstevel@tonic-gate 		case ASI_FL16_SL:
13950Sstevel@tonic-gate 			return (vis_short_fls(pfpsd, i.inst, pregs,
13960Sstevel@tonic-gate 				prw, asi));
13970Sstevel@tonic-gate 		case ASI_BLK_AIUP:
13980Sstevel@tonic-gate 		case ASI_BLK_AIUS:
13990Sstevel@tonic-gate 		case ASI_BLK_AIUPL:
14000Sstevel@tonic-gate 		case ASI_BLK_AIUSL:
14010Sstevel@tonic-gate 		case ASI_BLK_P:
14020Sstevel@tonic-gate 		case ASI_BLK_S:
14030Sstevel@tonic-gate 		case ASI_BLK_PL:
14040Sstevel@tonic-gate 		case ASI_BLK_SL:
14050Sstevel@tonic-gate 		case ASI_BLK_COMMIT_P:
14060Sstevel@tonic-gate 		case ASI_BLK_COMMIT_S:
14070Sstevel@tonic-gate 			return (vis_blk_fldst(pfpsd, i.inst, pregs,
14080Sstevel@tonic-gate 				prw, asi));
14090Sstevel@tonic-gate 		default:
14100Sstevel@tonic-gate 			return (ftt_unimplemented);
14110Sstevel@tonic-gate 	}
14120Sstevel@tonic-gate }
14130Sstevel@tonic-gate 
14140Sstevel@tonic-gate /*
14150Sstevel@tonic-gate  * Simulator for partial stores between floating-point unit and memory.
14160Sstevel@tonic-gate  */
14170Sstevel@tonic-gate static enum ftt_type
14180Sstevel@tonic-gate vis_prtl_fst(
14190Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
14200Sstevel@tonic-gate 	vis_inst_type	inst,	/* ISE instruction to simulate. */
14210Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
14220Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
14230Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
14240Sstevel@tonic-gate {
14250Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
14260Sstevel@tonic-gate 	uint_t	opf, msk;
14270Sstevel@tonic-gate 	int	h, i, j;
14280Sstevel@tonic-gate 	uint64_t ea, tmsk;
14290Sstevel@tonic-gate 	union {
14300Sstevel@tonic-gate 		freg_type	f;
14310Sstevel@tonic-gate 		uint64_t	ll;
14320Sstevel@tonic-gate 		uint32_t	i[2];
14330Sstevel@tonic-gate 		uint16_t	s[4];
14340Sstevel@tonic-gate 		uint8_t		c[8];
14350Sstevel@tonic-gate 	} k, l, res;
14360Sstevel@tonic-gate 	enum ftt_type   ftt;
14370Sstevel@tonic-gate 
14380Sstevel@tonic-gate 	nrs1 = inst.rs1;
14390Sstevel@tonic-gate 	nrs2 = inst.rs2;
14400Sstevel@tonic-gate 	nrd = inst.rd;
14410Sstevel@tonic-gate 	if ((nrd & 1) == 1) 		/* fix register encoding */
14420Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
14430Sstevel@tonic-gate 	opf = inst.opf;
14440Sstevel@tonic-gate 	res.ll = 0;
14450Sstevel@tonic-gate 	if ((opf & 0x100) == 0) {	/* effective address = rs1  */
14460Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
14470Sstevel@tonic-gate 		if (ftt != ftt_none)
14480Sstevel@tonic-gate 			return (ftt);
14490Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tmsk);
14500Sstevel@tonic-gate 		if (ftt != ftt_none)
14510Sstevel@tonic-gate 			return (ftt);
14520Sstevel@tonic-gate 		msk = (uint_t)tmsk;
14530Sstevel@tonic-gate 	} else {
14540Sstevel@tonic-gate 		pfpsd->fp_trapaddr = (caddr_t)pregs->r_pc;
14550Sstevel@tonic-gate 		return (ftt_unimplemented);
14560Sstevel@tonic-gate 	}
14570Sstevel@tonic-gate 
14580Sstevel@tonic-gate 	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
14590Sstevel@tonic-gate 	if ((ea & 0x3) != 0)
14600Sstevel@tonic-gate 		return (ftt_alignment);	/* Require 32 bit-alignment. */
14610Sstevel@tonic-gate 
14620Sstevel@tonic-gate 	switch (asi) {
14630Sstevel@tonic-gate 	case ASI_PST8_P:
14640Sstevel@tonic-gate 	case ASI_PST8_S:
14650Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14660Sstevel@tonic-gate 		if (ftt != ftt_none)
14670Sstevel@tonic-gate 			return (ftt);
14680Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
14690Sstevel@tonic-gate 		for (i = 0, j = 0x80; i <= 7; i++, j >>= 1) {
14700Sstevel@tonic-gate 			if ((msk & j) == j)
14710Sstevel@tonic-gate 				res.c[i] = k.c[i];
14720Sstevel@tonic-gate 			else
14730Sstevel@tonic-gate 				res.c[i] = l.c[i];
14740Sstevel@tonic-gate 		}
14750Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
14760Sstevel@tonic-gate 		if (ftt != ftt_none)
14770Sstevel@tonic-gate 			return (ftt);
14780Sstevel@tonic-gate 		break;
14790Sstevel@tonic-gate 	case ASI_PST8_PL:	/* little-endian */
14800Sstevel@tonic-gate 	case ASI_PST8_SL:
14810Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14820Sstevel@tonic-gate 		if (ftt != ftt_none)
14830Sstevel@tonic-gate 			return (ftt);
14840Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
1485*2227Sjfrank 		for (h = 7, i = 0, j = 1; i <= 7; h--, i++, j <<= 1) {
14860Sstevel@tonic-gate 			if ((msk & j) == j)
1487*2227Sjfrank 				res.c[i] = k.c[h];
14880Sstevel@tonic-gate 			else
1489*2227Sjfrank 				res.c[i] = l.c[i];
14900Sstevel@tonic-gate 		}
14910Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
14920Sstevel@tonic-gate 		if (ftt != ftt_none)
14930Sstevel@tonic-gate 			return (ftt);
14940Sstevel@tonic-gate 		break;
14950Sstevel@tonic-gate 	case ASI_PST16_P:
14960Sstevel@tonic-gate 	case ASI_PST16_S:
14970Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14980Sstevel@tonic-gate 		if (ftt != ftt_none)
14990Sstevel@tonic-gate 			return (ftt);
15000Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15010Sstevel@tonic-gate 		for (i = 0, j = 0x8; i <= 3; i++, j >>= 1) {
15020Sstevel@tonic-gate 			if ((msk & j) == j)
15030Sstevel@tonic-gate 				res.s[i] = k.s[i];
15040Sstevel@tonic-gate 			else
15050Sstevel@tonic-gate 				res.s[i] = l.s[i];
15060Sstevel@tonic-gate 		}
15070Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15080Sstevel@tonic-gate 		if (ftt != ftt_none)
15090Sstevel@tonic-gate 			return (ftt);
15100Sstevel@tonic-gate 		break;
15110Sstevel@tonic-gate 	case ASI_PST16_PL:
15120Sstevel@tonic-gate 	case ASI_PST16_SL:
15130Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15140Sstevel@tonic-gate 		if (ftt != ftt_none)
15150Sstevel@tonic-gate 			return (ftt);
15160Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
1517*2227Sjfrank 		for (h = 7, i = 0, j = 1; i <= 6; h -= 2, i += 2, j <<= 1) {
15180Sstevel@tonic-gate 			if ((msk & j) == j) {
1519*2227Sjfrank 				res.c[i] = k.c[h];
1520*2227Sjfrank 				res.c[i+1] = k.c[h-1];
15210Sstevel@tonic-gate 			} else {
1522*2227Sjfrank 				res.c[i] = l.c[i];
1523*2227Sjfrank 				res.c[i+1] = l.c[i+1];
15240Sstevel@tonic-gate 			}
15250Sstevel@tonic-gate 		}
15260Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15270Sstevel@tonic-gate 		if (ftt != ftt_none)
15280Sstevel@tonic-gate 			return (ftt);
15290Sstevel@tonic-gate 		break;
15300Sstevel@tonic-gate 	case ASI_PST32_P:
15310Sstevel@tonic-gate 	case ASI_PST32_S:
15320Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15330Sstevel@tonic-gate 		if (ftt != ftt_none)
15340Sstevel@tonic-gate 			return (ftt);
15350Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15360Sstevel@tonic-gate 		for (i = 0, j = 0x2; i <= 1; i++, j >>= 1) {
15370Sstevel@tonic-gate 			if ((msk & j) == j)
15380Sstevel@tonic-gate 				res.i[i] = k.i[i];
15390Sstevel@tonic-gate 			else
15400Sstevel@tonic-gate 				res.i[i] = l.i[i];
15410Sstevel@tonic-gate 		}
15420Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15430Sstevel@tonic-gate 		if (ftt != ftt_none)
15440Sstevel@tonic-gate 			return (ftt);
15450Sstevel@tonic-gate 		break;
15460Sstevel@tonic-gate 	case ASI_PST32_PL:
15470Sstevel@tonic-gate 	case ASI_PST32_SL:
15480Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15490Sstevel@tonic-gate 		if (ftt != ftt_none)
15500Sstevel@tonic-gate 			return (ftt);
15510Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
1552*2227Sjfrank 		for (h = 7, i = 0, j = 1; i <= 4; h -= 4, i += 4, j <<= 1) {
15530Sstevel@tonic-gate 			if ((msk & j) == j) {
1554*2227Sjfrank 				res.c[i] = k.c[h];
1555*2227Sjfrank 				res.c[i+1] = k.c[h-1];
1556*2227Sjfrank 				res.c[i+2] = k.c[h-2];
1557*2227Sjfrank 				res.c[i+3] = k.c[h-3];
15580Sstevel@tonic-gate 			} else {
1559*2227Sjfrank 				res.c[i] = l.c[i];
1560*2227Sjfrank 				res.c[i+1] = l.c[i+1];
1561*2227Sjfrank 				res.c[i+2] = l.c[i+2];
1562*2227Sjfrank 				res.c[i+3] = l.c[i+3];
15630Sstevel@tonic-gate 			}
15640Sstevel@tonic-gate 		}
15650Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15660Sstevel@tonic-gate 		if (ftt != ftt_none)
15670Sstevel@tonic-gate 			return (ftt);
15680Sstevel@tonic-gate 		break;
15690Sstevel@tonic-gate 	}
15700Sstevel@tonic-gate 
15710Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
15720Sstevel@tonic-gate 	pregs->r_npc += 4;
15730Sstevel@tonic-gate 	return (ftt_none);
15740Sstevel@tonic-gate }
15750Sstevel@tonic-gate 
15760Sstevel@tonic-gate /*
15770Sstevel@tonic-gate  * Simulator for short load/stores between floating-point unit and memory.
15780Sstevel@tonic-gate  */
15790Sstevel@tonic-gate static enum ftt_type
15800Sstevel@tonic-gate vis_short_fls(
15810Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
15820Sstevel@tonic-gate 	vis_inst_type	inst,	/* ISE instruction to simulate. */
15830Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
15840Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
15850Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
15860Sstevel@tonic-gate {
15870Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
15880Sstevel@tonic-gate 	uint_t	opf;
15890Sstevel@tonic-gate 	uint64_t ea, tea;
15900Sstevel@tonic-gate 	union {
15910Sstevel@tonic-gate 		freg_type	f;
15920Sstevel@tonic-gate 		uint64_t	ll;
15930Sstevel@tonic-gate 		uint32_t	i[2];
15940Sstevel@tonic-gate 		uint16_t	s[4];
15950Sstevel@tonic-gate 		uint8_t		c[8];
15960Sstevel@tonic-gate 	} k;
15970Sstevel@tonic-gate 	union {
15980Sstevel@tonic-gate 		vis_inst_type	inst;
15990Sstevel@tonic-gate 		int		i;
16000Sstevel@tonic-gate 	} fp;
16010Sstevel@tonic-gate 	enum ftt_type   ftt = ftt_none;
16020Sstevel@tonic-gate 	ushort_t us;
16030Sstevel@tonic-gate 	uchar_t uc;
16040Sstevel@tonic-gate 
16050Sstevel@tonic-gate 	nrs1 = inst.rs1;
16060Sstevel@tonic-gate 	nrs2 = inst.rs2;
16070Sstevel@tonic-gate 	nrd = inst.rd;
16080Sstevel@tonic-gate 	if ((nrd & 1) == 1) 		/* fix register encoding */
16090Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
16100Sstevel@tonic-gate 	opf = inst.opf;
16110Sstevel@tonic-gate 	fp.inst = inst;
16120Sstevel@tonic-gate 	if ((opf & 0x100) == 0) { /* effective address = rs1 + rs2 */
16130Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
16140Sstevel@tonic-gate 		if (ftt != ftt_none)
16150Sstevel@tonic-gate 			return (ftt);
16160Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
16170Sstevel@tonic-gate 		if (ftt != ftt_none)
16180Sstevel@tonic-gate 			return (ftt);
16190Sstevel@tonic-gate 		ea += tea;
16200Sstevel@tonic-gate 	} else {	/* effective address = rs1 + imm13 */
16210Sstevel@tonic-gate 		fp.inst = inst;
16220Sstevel@tonic-gate 		ea = (fp.i << 19) >> 19;	/* Extract simm13 field. */
16230Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &tea);
16240Sstevel@tonic-gate 		if (ftt != ftt_none)
16250Sstevel@tonic-gate 			return (ftt);
16260Sstevel@tonic-gate 		ea += tea;
16270Sstevel@tonic-gate 	}
16280Sstevel@tonic-gate 	if (get_udatamodel() == DATAMODEL_ILP32)
16290Sstevel@tonic-gate 		ea = (uint64_t)(caddr32_t)ea;
16300Sstevel@tonic-gate 
16310Sstevel@tonic-gate 	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
16320Sstevel@tonic-gate 	switch (asi) {
16330Sstevel@tonic-gate 	case ASI_FL8_P:
16340Sstevel@tonic-gate 	case ASI_FL8_S:
16350Sstevel@tonic-gate 	case ASI_FL8_PL:		/* little-endian */
16360Sstevel@tonic-gate 	case ASI_FL8_SL:
16370Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* load byte */
16380Sstevel@tonic-gate 			if (fuword8((void *)ea, &uc) == -1)
16390Sstevel@tonic-gate 				return (ftt_fault);
16400Sstevel@tonic-gate 			k.ll = 0;
16410Sstevel@tonic-gate 			k.c[7] = uc;
16420Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16430Sstevel@tonic-gate 		} else {			/* store byte */
16440Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16450Sstevel@tonic-gate 			uc = k.c[7];
16460Sstevel@tonic-gate 			if (subyte((caddr_t)ea, uc) == -1)
16470Sstevel@tonic-gate 				return (ftt_fault);
16480Sstevel@tonic-gate 		}
16490Sstevel@tonic-gate 		break;
16500Sstevel@tonic-gate 	case ASI_FL16_P:
16510Sstevel@tonic-gate 	case ASI_FL16_S:
16520Sstevel@tonic-gate 		if ((ea & 1) == 1)
16530Sstevel@tonic-gate 			return (ftt_alignment);
16540Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* load short */
16550Sstevel@tonic-gate 			if (fuword16((void *)ea, &us) == -1)
16560Sstevel@tonic-gate 				return (ftt_fault);
16570Sstevel@tonic-gate 			k.ll = 0;
16580Sstevel@tonic-gate 			k.s[3] = us;
16590Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16600Sstevel@tonic-gate 		} else {			/* store short */
16610Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16620Sstevel@tonic-gate 			us = k.s[3];
16630Sstevel@tonic-gate 			if (suword16((caddr_t)ea, us) == -1)
16640Sstevel@tonic-gate 				return (ftt_fault);
16650Sstevel@tonic-gate 		}
16660Sstevel@tonic-gate 		break;
16670Sstevel@tonic-gate 	case ASI_FL16_PL:		/* little-endian */
16680Sstevel@tonic-gate 	case ASI_FL16_SL:
16690Sstevel@tonic-gate 		if ((ea & 1) == 1)
16700Sstevel@tonic-gate 			return (ftt_alignment);
16710Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* load short */
16720Sstevel@tonic-gate 			if (fuword16((void *)ea, &us) == -1)
16730Sstevel@tonic-gate 				return (ftt_fault);
16740Sstevel@tonic-gate 			k.ll = 0;
16750Sstevel@tonic-gate 			k.c[6] = (uchar_t)us;
16760Sstevel@tonic-gate 			k.c[7] = (uchar_t)((us & 0xff00) >> 8);
16770Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16780Sstevel@tonic-gate 		} else {			/* store short */
16790Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16800Sstevel@tonic-gate 			uc = k.c[7];
16810Sstevel@tonic-gate 			us = (ushort_t)((uc << 8) | k.c[6]);
16820Sstevel@tonic-gate 			if (suword16((void *)ea, us) == -1)
16830Sstevel@tonic-gate 				return (ftt_fault);
16840Sstevel@tonic-gate 		}
16850Sstevel@tonic-gate 		break;
16860Sstevel@tonic-gate 	}
16870Sstevel@tonic-gate 
16880Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
16890Sstevel@tonic-gate 	pregs->r_npc += 4;
16900Sstevel@tonic-gate 	return (ftt_none);
16910Sstevel@tonic-gate }
16920Sstevel@tonic-gate 
16930Sstevel@tonic-gate /*
16940Sstevel@tonic-gate  * Simulator for block loads and stores between floating-point unit and memory.
16950Sstevel@tonic-gate  * XXX - OK, so it is really gross to flush the whole Ecache for a block commit
16960Sstevel@tonic-gate  *	 store - but the circumstances under which this code actually gets
16970Sstevel@tonic-gate  *	 used in real life are so obscure that you can live with it!
16980Sstevel@tonic-gate  */
16990Sstevel@tonic-gate static enum ftt_type
17000Sstevel@tonic-gate vis_blk_fldst(
17010Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
17020Sstevel@tonic-gate 	vis_inst_type	inst,	/* ISE instruction to simulate. */
17030Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
17040Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
17050Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
17060Sstevel@tonic-gate {
17070Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
17080Sstevel@tonic-gate 	uint_t	opf, h, i, j;
17090Sstevel@tonic-gate 	uint64_t ea, tea;
17100Sstevel@tonic-gate 	union {
17110Sstevel@tonic-gate 		freg_type	f;
17120Sstevel@tonic-gate 		uint64_t	ll;
17130Sstevel@tonic-gate 		uint8_t		c[8];
17140Sstevel@tonic-gate 	} k, l;
17150Sstevel@tonic-gate 	union {
17160Sstevel@tonic-gate 		vis_inst_type	inst;
17170Sstevel@tonic-gate 		int32_t		i;
17180Sstevel@tonic-gate 	} fp;
17190Sstevel@tonic-gate 	enum ftt_type   ftt;
17200Sstevel@tonic-gate 	boolean_t little_endian = B_FALSE;
17210Sstevel@tonic-gate 
17220Sstevel@tonic-gate 	nrs1 = inst.rs1;
17230Sstevel@tonic-gate 	nrs2 = inst.rs2;
17240Sstevel@tonic-gate 	nrd = inst.rd;
17250Sstevel@tonic-gate 	if ((nrd & 1) == 1) 		/* fix register encoding */
17260Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
17270Sstevel@tonic-gate 
17280Sstevel@tonic-gate 	/* ensure register is 8-double precision aligned */
17290Sstevel@tonic-gate 	if ((nrd & 0xf) != 0)
17300Sstevel@tonic-gate 		return (ftt_unimplemented);
17310Sstevel@tonic-gate 
17320Sstevel@tonic-gate 	opf = inst.opf;
17330Sstevel@tonic-gate 	if ((opf & 0x100) == 0) { 	/* effective address = rs1 + rs2 */
17340Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
17350Sstevel@tonic-gate 		if (ftt != ftt_none)
17360Sstevel@tonic-gate 			return (ftt);
17370Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
17380Sstevel@tonic-gate 		if (ftt != ftt_none)
17390Sstevel@tonic-gate 			return (ftt);
17400Sstevel@tonic-gate 		ea += tea;
17410Sstevel@tonic-gate 	} else {			/* effective address = rs1 + imm13 */
17420Sstevel@tonic-gate 		fp.inst = inst;
17430Sstevel@tonic-gate 		ea = (fp.i << 19) >> 19;	/* Extract simm13 field. */
17440Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &tea);
17450Sstevel@tonic-gate 		if (ftt != ftt_none)
17460Sstevel@tonic-gate 			return (ftt);
17470Sstevel@tonic-gate 		ea += tea;
17480Sstevel@tonic-gate 	}
17490Sstevel@tonic-gate 	if ((ea & 0x3F) != 0)		/* Require 64 byte-alignment. */
17500Sstevel@tonic-gate 		return (ftt_alignment);
17510Sstevel@tonic-gate 
17520Sstevel@tonic-gate 	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
17530Sstevel@tonic-gate 	switch (asi) {
17540Sstevel@tonic-gate 	case ASI_BLK_AIUPL:
17550Sstevel@tonic-gate 	case ASI_BLK_AIUSL:
17560Sstevel@tonic-gate 	case ASI_BLK_PL:
17570Sstevel@tonic-gate 	case ASI_BLK_SL:
17580Sstevel@tonic-gate 		little_endian = B_TRUE;
17590Sstevel@tonic-gate 		/* FALLTHROUGH */
17600Sstevel@tonic-gate 	case ASI_BLK_AIUP:
17610Sstevel@tonic-gate 	case ASI_BLK_AIUS:
17620Sstevel@tonic-gate 	case ASI_BLK_P:
17630Sstevel@tonic-gate 	case ASI_BLK_S:
17640Sstevel@tonic-gate 	case ASI_BLK_COMMIT_P:
17650Sstevel@tonic-gate 	case ASI_BLK_COMMIT_S:
17660Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* lddf */
17670Sstevel@tonic-gate 		    for (i = 0; i < 8; i++, ea += 8, nrd += 2) {
17680Sstevel@tonic-gate 			ftt = _fp_read_extword((uint64_t *)ea, &k.ll, pfpsd);
17690Sstevel@tonic-gate 			if (ftt != ftt_none)
17700Sstevel@tonic-gate 				return (ftt);
17710Sstevel@tonic-gate 			if (little_endian) {
17720Sstevel@tonic-gate 				for (j = 0, h = 7; j < 8; j++, h--)
17730Sstevel@tonic-gate 					l.c[h] = k.c[j];
17740Sstevel@tonic-gate 				k.ll = l.ll;
17750Sstevel@tonic-gate 			}
17760Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
17770Sstevel@tonic-gate 		    }
17780Sstevel@tonic-gate 		} else {			/* stdf */
17790Sstevel@tonic-gate 		    for (i = 0; i < 8; i++, ea += 8, nrd += 2) {
17800Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
17810Sstevel@tonic-gate 			if (little_endian) {
17820Sstevel@tonic-gate 				for (j = 0, h = 7; j < 8; j++, h--)
17830Sstevel@tonic-gate 					l.c[h] = k.c[j];
17840Sstevel@tonic-gate 				k.ll = l.ll;
17850Sstevel@tonic-gate 			}
17860Sstevel@tonic-gate 			ftt = _fp_write_extword((uint64_t *)ea, k.ll, pfpsd);
17870Sstevel@tonic-gate 			if (ftt != ftt_none)
17880Sstevel@tonic-gate 				return (ftt);
17890Sstevel@tonic-gate 		    }
17900Sstevel@tonic-gate 		}
17910Sstevel@tonic-gate 		if ((asi == ASI_BLK_COMMIT_P) || (asi == ASI_BLK_COMMIT_S))
17920Sstevel@tonic-gate 			cpu_flush_ecache();
17930Sstevel@tonic-gate 		break;
17940Sstevel@tonic-gate 	default:
17950Sstevel@tonic-gate 		/* addr of unimp inst */
17960Sstevel@tonic-gate 		pfpsd->fp_trapaddr = (caddr_t)pregs->r_pc;
17970Sstevel@tonic-gate 		return (ftt_unimplemented);
17980Sstevel@tonic-gate 	}
17990Sstevel@tonic-gate 
18000Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18010Sstevel@tonic-gate 	pregs->r_npc += 4;
18020Sstevel@tonic-gate 	return (ftt_none);
18030Sstevel@tonic-gate }
18040Sstevel@tonic-gate 
18050Sstevel@tonic-gate /*
18060Sstevel@tonic-gate  * Simulator for rd %gsr instruction.
18070Sstevel@tonic-gate  */
18080Sstevel@tonic-gate enum ftt_type
18090Sstevel@tonic-gate vis_rdgsr(
18100Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
18110Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
18120Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
18130Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
18140Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
18150Sstevel@tonic-gate {
18160Sstevel@tonic-gate 	uint_t nrd;
18170Sstevel@tonic-gate 	uint64_t r;
18180Sstevel@tonic-gate 	enum ftt_type ftt = ftt_none;
18190Sstevel@tonic-gate 
18200Sstevel@tonic-gate 	nrd = pinst.rd;
18210Sstevel@tonic-gate 
18227Sdf157793 	r = pfpsd->fp_current_read_gsr(fp);
18230Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &r);
18240Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18250Sstevel@tonic-gate 	pregs->r_npc += 4;
18260Sstevel@tonic-gate 	return (ftt);
18270Sstevel@tonic-gate }
18280Sstevel@tonic-gate 
18290Sstevel@tonic-gate /*
18300Sstevel@tonic-gate  * Simulator for wr %gsr instruction.
18310Sstevel@tonic-gate  */
18320Sstevel@tonic-gate enum ftt_type
18330Sstevel@tonic-gate vis_wrgsr(
18340Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
18350Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
18360Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
18370Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
18380Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
18390Sstevel@tonic-gate {
18400Sstevel@tonic-gate 	uint_t nrs1;
18410Sstevel@tonic-gate 	uint64_t r, r1, r2;
18420Sstevel@tonic-gate 	enum ftt_type ftt = ftt_none;
18430Sstevel@tonic-gate 
18440Sstevel@tonic-gate 	nrs1 = pinst.rs1;
18450Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &r1);
18460Sstevel@tonic-gate 	if (ftt != ftt_none)
18470Sstevel@tonic-gate 		return (ftt);
18480Sstevel@tonic-gate 	if (pinst.ibit == 0) {	/* copy the value in r[rs2] */
18490Sstevel@tonic-gate 		uint_t nrs2;
18500Sstevel@tonic-gate 
18510Sstevel@tonic-gate 		nrs2 = pinst.rs2;
18520Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &r2);
18530Sstevel@tonic-gate 		if (ftt != ftt_none)
18540Sstevel@tonic-gate 			return (ftt);
18550Sstevel@tonic-gate 	} else {	/* use sign_ext(simm13) */
18560Sstevel@tonic-gate 		union {
18570Sstevel@tonic-gate 			fp_inst_type	inst;
18580Sstevel@tonic-gate 			uint32_t	i;
18590Sstevel@tonic-gate 		} fp;
18600Sstevel@tonic-gate 
18610Sstevel@tonic-gate 		fp.inst = pinst;		/* Extract simm13 field */
18620Sstevel@tonic-gate 		r2 = (fp.i << 19) >> 19;
18630Sstevel@tonic-gate 	}
18640Sstevel@tonic-gate 	r = r1 ^ r2;
18657Sdf157793 	pfpsd->fp_current_write_gsr(r, fp);
18660Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18670Sstevel@tonic-gate 	pregs->r_npc += 4;
18680Sstevel@tonic-gate 	return (ftt);
18690Sstevel@tonic-gate }
18700Sstevel@tonic-gate 
18710Sstevel@tonic-gate /*
18720Sstevel@tonic-gate  * This is the loadable module wrapper.
18730Sstevel@tonic-gate  */
18740Sstevel@tonic-gate #include <sys/errno.h>
18750Sstevel@tonic-gate #include <sys/modctl.h>
18760Sstevel@tonic-gate 
18770Sstevel@tonic-gate /*
18780Sstevel@tonic-gate  * Module linkage information for the kernel.
18790Sstevel@tonic-gate  */
18800Sstevel@tonic-gate extern struct mod_ops mod_miscops;
18810Sstevel@tonic-gate 
18820Sstevel@tonic-gate static struct modlmisc modlmisc = {
18830Sstevel@tonic-gate 	&mod_miscops,
18840Sstevel@tonic-gate 	"vis fp simulation",
18850Sstevel@tonic-gate };
18860Sstevel@tonic-gate 
18870Sstevel@tonic-gate static struct modlinkage modlinkage = {
18880Sstevel@tonic-gate 	MODREV_1, (void *)&modlmisc, NULL
18890Sstevel@tonic-gate };
18900Sstevel@tonic-gate 
18910Sstevel@tonic-gate int
18920Sstevel@tonic-gate _init(void)
18930Sstevel@tonic-gate {
18940Sstevel@tonic-gate 	return (mod_install(&modlinkage));
18950Sstevel@tonic-gate }
18960Sstevel@tonic-gate 
18970Sstevel@tonic-gate int
18980Sstevel@tonic-gate _info(struct modinfo *modinfop)
18990Sstevel@tonic-gate {
19000Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
19010Sstevel@tonic-gate }
1902