xref: /titanic_52/usr/src/uts/sun4/os/visinstr.c (revision bfb7f3826f3b1e9073c9312c466df5591fcf7e1c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*bfb7f382Skalai  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /* VIS floating point instruction simulator for Sparc FPU simulator. */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <sys/fpu/fpusystm.h>
347c478bd9Sstevel@tonic-gate #include <sys/fpu/fpu_simulator.h>
357c478bd9Sstevel@tonic-gate #include <sys/vis_simulator.h>
367c478bd9Sstevel@tonic-gate #include <sys/fpu/globals.h>
377c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
387c478bd9Sstevel@tonic-gate #include <sys/sun4asi.h>
397c478bd9Sstevel@tonic-gate #include <sys/machasi.h>
407c478bd9Sstevel@tonic-gate #include <sys/debug.h>
417c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h>
427c478bd9Sstevel@tonic-gate #include <sys/systm.h>
437c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	FPU_REG_FIELD uint32_reg	/* Coordinate with FPU_REGS_TYPE. */
467c478bd9Sstevel@tonic-gate #define	FPU_DREG_FIELD uint64_reg	/* Coordinate with FPU_DREGS_TYPE. */
477c478bd9Sstevel@tonic-gate #define	FPU_FSR_FIELD uint64_reg	/* Coordinate with V9_FPU_FSR_TYPE. */
487c478bd9Sstevel@tonic-gate 
49*bfb7f382Skalai extern	uint_t	get_subcc_ccr(uint64_t, uint64_t);
50*bfb7f382Skalai 
517c478bd9Sstevel@tonic-gate static enum ftt_type vis_array(fp_simd_type *, vis_inst_type, struct regs *,
527c478bd9Sstevel@tonic-gate 				void *);
537c478bd9Sstevel@tonic-gate static enum ftt_type vis_alignaddr(fp_simd_type *, vis_inst_type,
547c478bd9Sstevel@tonic-gate 				struct regs *, void *, kfpu_t *);
557c478bd9Sstevel@tonic-gate static enum ftt_type vis_edge(fp_simd_type *, vis_inst_type, struct regs *,
567c478bd9Sstevel@tonic-gate 				void *);
577c478bd9Sstevel@tonic-gate static enum ftt_type vis_faligndata(fp_simd_type *, fp_inst_type,
587c478bd9Sstevel@tonic-gate 				kfpu_t *);
597c478bd9Sstevel@tonic-gate static enum ftt_type vis_bmask(fp_simd_type *, vis_inst_type, struct regs *,
607c478bd9Sstevel@tonic-gate 				void *, kfpu_t *);
617c478bd9Sstevel@tonic-gate static enum ftt_type vis_bshuffle(fp_simd_type *, fp_inst_type,
627c478bd9Sstevel@tonic-gate 				kfpu_t *);
637c478bd9Sstevel@tonic-gate static enum ftt_type vis_siam(fp_simd_type *, vis_inst_type, kfpu_t *);
647c478bd9Sstevel@tonic-gate static enum ftt_type vis_fcmp(fp_simd_type *, vis_inst_type, struct regs *,
657c478bd9Sstevel@tonic-gate 				void *);
667c478bd9Sstevel@tonic-gate static enum ftt_type vis_fmul(fp_simd_type *, vis_inst_type);
677c478bd9Sstevel@tonic-gate static enum ftt_type vis_fpixel(fp_simd_type *, vis_inst_type, kfpu_t *);
687c478bd9Sstevel@tonic-gate static enum ftt_type vis_fpaddsub(fp_simd_type *, vis_inst_type);
697c478bd9Sstevel@tonic-gate static enum ftt_type vis_pdist(fp_simd_type *, fp_inst_type);
707c478bd9Sstevel@tonic-gate static enum ftt_type vis_prtl_fst(fp_simd_type *, vis_inst_type, struct regs *,
717c478bd9Sstevel@tonic-gate 				void *, uint_t);
727c478bd9Sstevel@tonic-gate static enum ftt_type vis_short_fls(fp_simd_type *, vis_inst_type,
737c478bd9Sstevel@tonic-gate 				struct regs *, void *, uint_t);
747c478bd9Sstevel@tonic-gate static enum ftt_type vis_blk_fldst(fp_simd_type *, vis_inst_type,
757c478bd9Sstevel@tonic-gate 				struct regs *, void *, uint_t);
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Simulator for VIS instructions with op3 == 0x36 that get fp_disabled
797c478bd9Sstevel@tonic-gate  * traps.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate enum ftt_type
827c478bd9Sstevel@tonic-gate vis_fpu_simulator(
837c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
847c478bd9Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
857c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
867c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
877c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
907c478bd9Sstevel@tonic-gate 	uint_t	us1, us2, usr;
917c478bd9Sstevel@tonic-gate 	uint64_t lus1, lus2, lusr;
927c478bd9Sstevel@tonic-gate 	enum ftt_type ftt = ftt_none;
937c478bd9Sstevel@tonic-gate 	union {
947c478bd9Sstevel@tonic-gate 		vis_inst_type	inst;
957c478bd9Sstevel@tonic-gate 		fp_inst_type	pinst;
967c478bd9Sstevel@tonic-gate 	} f;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	ASSERT(USERMODE(pregs->r_tstate));
997c478bd9Sstevel@tonic-gate 	nrs1 = pinst.rs1;
1007c478bd9Sstevel@tonic-gate 	nrs2 = pinst.rs2;
1017c478bd9Sstevel@tonic-gate 	nrd = pinst.rd;
1027c478bd9Sstevel@tonic-gate 	f.pinst = pinst;
1037c478bd9Sstevel@tonic-gate 	if ((f.inst.opf & 1) == 0) {		/* double precision */
1047c478bd9Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 		/* fix register encoding */
1057c478bd9Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
1067c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
1077c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
1087c478bd9Sstevel@tonic-gate 		if ((nrd & 1) == 1)
1097c478bd9Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	switch (f.inst.opf) {
1137c478bd9Sstevel@tonic-gate 		/* these instr's do not use fp regs */
1147c478bd9Sstevel@tonic-gate 	case edge8:
1157c478bd9Sstevel@tonic-gate 	case edge8l:
1167c478bd9Sstevel@tonic-gate 	case edge8n:
1177c478bd9Sstevel@tonic-gate 	case edge8ln:
1187c478bd9Sstevel@tonic-gate 	case edge16:
1197c478bd9Sstevel@tonic-gate 	case edge16l:
1207c478bd9Sstevel@tonic-gate 	case edge16n:
1217c478bd9Sstevel@tonic-gate 	case edge16ln:
1227c478bd9Sstevel@tonic-gate 	case edge32:
1237c478bd9Sstevel@tonic-gate 	case edge32l:
1247c478bd9Sstevel@tonic-gate 	case edge32n:
1257c478bd9Sstevel@tonic-gate 	case edge32ln:
1267c478bd9Sstevel@tonic-gate 		ftt = vis_edge(pfpsd, f.inst, pregs, prw);
1277c478bd9Sstevel@tonic-gate 		break;
1287c478bd9Sstevel@tonic-gate 	case array8:
1297c478bd9Sstevel@tonic-gate 	case array16:
1307c478bd9Sstevel@tonic-gate 	case array32:
1317c478bd9Sstevel@tonic-gate 		ftt = vis_array(pfpsd, f.inst, pregs, prw);
1327c478bd9Sstevel@tonic-gate 		break;
1337c478bd9Sstevel@tonic-gate 	case alignaddr:
1347c478bd9Sstevel@tonic-gate 	case alignaddrl:
1357c478bd9Sstevel@tonic-gate 		ftt = vis_alignaddr(pfpsd, f.inst, pregs, prw, fp);
1367c478bd9Sstevel@tonic-gate 		break;
1377c478bd9Sstevel@tonic-gate 	case bmask:
1387c478bd9Sstevel@tonic-gate 		ftt = vis_bmask(pfpsd, f.inst, pregs, prw, fp);
1397c478bd9Sstevel@tonic-gate 		break;
1407c478bd9Sstevel@tonic-gate 	case fcmple16:
1417c478bd9Sstevel@tonic-gate 	case fcmpne16:
1427c478bd9Sstevel@tonic-gate 	case fcmpgt16:
1437c478bd9Sstevel@tonic-gate 	case fcmpeq16:
1447c478bd9Sstevel@tonic-gate 	case fcmple32:
1457c478bd9Sstevel@tonic-gate 	case fcmpne32:
1467c478bd9Sstevel@tonic-gate 	case fcmpgt32:
1477c478bd9Sstevel@tonic-gate 	case fcmpeq32:
1487c478bd9Sstevel@tonic-gate 		ftt = vis_fcmp(pfpsd, f.inst, pregs, prw);
1497c478bd9Sstevel@tonic-gate 		break;
1507c478bd9Sstevel@tonic-gate 	case fmul8x16:
1517c478bd9Sstevel@tonic-gate 	case fmul8x16au:
1527c478bd9Sstevel@tonic-gate 	case fmul8x16al:
1537c478bd9Sstevel@tonic-gate 	case fmul8sux16:
1547c478bd9Sstevel@tonic-gate 	case fmul8ulx16:
1557c478bd9Sstevel@tonic-gate 	case fmuld8sux16:
1567c478bd9Sstevel@tonic-gate 	case fmuld8ulx16:
1577c478bd9Sstevel@tonic-gate 		ftt = vis_fmul(pfpsd, f.inst);
1587c478bd9Sstevel@tonic-gate 		break;
1597c478bd9Sstevel@tonic-gate 	case fpack16:
1607c478bd9Sstevel@tonic-gate 	case fpack32:
1617c478bd9Sstevel@tonic-gate 	case fpackfix:
1627c478bd9Sstevel@tonic-gate 	case fexpand:
1637c478bd9Sstevel@tonic-gate 	case fpmerge:
1647c478bd9Sstevel@tonic-gate 		ftt = vis_fpixel(pfpsd, f.inst, fp);
1657c478bd9Sstevel@tonic-gate 		break;
1667c478bd9Sstevel@tonic-gate 	case pdist:
1677c478bd9Sstevel@tonic-gate 		ftt = vis_pdist(pfpsd, pinst);
1687c478bd9Sstevel@tonic-gate 		break;
1697c478bd9Sstevel@tonic-gate 	case faligndata:
1707c478bd9Sstevel@tonic-gate 		ftt = vis_faligndata(pfpsd, pinst, fp);
1717c478bd9Sstevel@tonic-gate 		break;
1727c478bd9Sstevel@tonic-gate 	case bshuffle:
1737c478bd9Sstevel@tonic-gate 		ftt = vis_bshuffle(pfpsd, pinst, fp);
1747c478bd9Sstevel@tonic-gate 		break;
1757c478bd9Sstevel@tonic-gate 	case fpadd16:
1767c478bd9Sstevel@tonic-gate 	case fpadd16s:
1777c478bd9Sstevel@tonic-gate 	case fpadd32:
1787c478bd9Sstevel@tonic-gate 	case fpadd32s:
1797c478bd9Sstevel@tonic-gate 	case fpsub16:
1807c478bd9Sstevel@tonic-gate 	case fpsub16s:
1817c478bd9Sstevel@tonic-gate 	case fpsub32:
1827c478bd9Sstevel@tonic-gate 	case fpsub32s:
1837c478bd9Sstevel@tonic-gate 		ftt = vis_fpaddsub(pfpsd, f.inst);
1847c478bd9Sstevel@tonic-gate 		break;
1857c478bd9Sstevel@tonic-gate 	case fzero:
1867c478bd9Sstevel@tonic-gate 		lusr = 0;
1877c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
1887c478bd9Sstevel@tonic-gate 		break;
1897c478bd9Sstevel@tonic-gate 	case fzeros:
1907c478bd9Sstevel@tonic-gate 		usr = 0;
1917c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
1927c478bd9Sstevel@tonic-gate 		break;
1937c478bd9Sstevel@tonic-gate 	case fnor:
1947c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
1957c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
1967c478bd9Sstevel@tonic-gate 		lusr = ~(lus1 | lus2);
1977c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
1987c478bd9Sstevel@tonic-gate 		break;
1997c478bd9Sstevel@tonic-gate 	case fnors:
2007c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2017c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2027c478bd9Sstevel@tonic-gate 		usr = ~(us1 | us2);
2037c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2047c478bd9Sstevel@tonic-gate 		break;
2057c478bd9Sstevel@tonic-gate 	case fandnot2:
2067c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2077c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2087c478bd9Sstevel@tonic-gate 		lusr = (lus1 & ~lus2);
2097c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2107c478bd9Sstevel@tonic-gate 		break;
2117c478bd9Sstevel@tonic-gate 	case fandnot2s:
2127c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2137c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2147c478bd9Sstevel@tonic-gate 		usr = (us1 & ~us2);
2157c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2167c478bd9Sstevel@tonic-gate 		break;
2177c478bd9Sstevel@tonic-gate 	case fnot2:
2187c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2197c478bd9Sstevel@tonic-gate 		lusr = ~lus2;
2207c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2217c478bd9Sstevel@tonic-gate 		break;
2227c478bd9Sstevel@tonic-gate 	case fnot2s:
2237c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2247c478bd9Sstevel@tonic-gate 		usr = ~us2;
2257c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2267c478bd9Sstevel@tonic-gate 		break;
2277c478bd9Sstevel@tonic-gate 	case fandnot1:
2287c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2297c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2307c478bd9Sstevel@tonic-gate 		lusr = (~lus1 & lus2);
2317c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2327c478bd9Sstevel@tonic-gate 		break;
2337c478bd9Sstevel@tonic-gate 	case fandnot1s:
2347c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2357c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2367c478bd9Sstevel@tonic-gate 		usr = (~us1 & us2);
2377c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2387c478bd9Sstevel@tonic-gate 		break;
2397c478bd9Sstevel@tonic-gate 	case fnot1:
2407c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2417c478bd9Sstevel@tonic-gate 		lusr = ~lus1;
2427c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2437c478bd9Sstevel@tonic-gate 		break;
2447c478bd9Sstevel@tonic-gate 	case fnot1s:
2457c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2467c478bd9Sstevel@tonic-gate 		usr = ~us1;
2477c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2487c478bd9Sstevel@tonic-gate 		break;
2497c478bd9Sstevel@tonic-gate 	case fxor:
2507c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2517c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2527c478bd9Sstevel@tonic-gate 		lusr = (lus1 ^ lus2);
2537c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2547c478bd9Sstevel@tonic-gate 		break;
2557c478bd9Sstevel@tonic-gate 	case fxors:
2567c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2577c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2587c478bd9Sstevel@tonic-gate 		usr = (us1 ^ us2);
2597c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2607c478bd9Sstevel@tonic-gate 		break;
2617c478bd9Sstevel@tonic-gate 	case fnand:
2627c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2637c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2647c478bd9Sstevel@tonic-gate 		lusr = ~(lus1 & lus2);
2657c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2667c478bd9Sstevel@tonic-gate 		break;
2677c478bd9Sstevel@tonic-gate 	case fnands:
2687c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2697c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2707c478bd9Sstevel@tonic-gate 		usr = ~(us1 & us2);
2717c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2727c478bd9Sstevel@tonic-gate 		break;
2737c478bd9Sstevel@tonic-gate 	case fand:
2747c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2757c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2767c478bd9Sstevel@tonic-gate 		lusr = (lus1 & lus2);
2777c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2787c478bd9Sstevel@tonic-gate 		break;
2797c478bd9Sstevel@tonic-gate 	case fands:
2807c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2817c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2827c478bd9Sstevel@tonic-gate 		usr = (us1 & us2);
2837c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2847c478bd9Sstevel@tonic-gate 		break;
2857c478bd9Sstevel@tonic-gate 	case fxnor:
2867c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
2877c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
2887c478bd9Sstevel@tonic-gate 		lusr = ~(lus1 ^ lus2);
2897c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
2907c478bd9Sstevel@tonic-gate 		break;
2917c478bd9Sstevel@tonic-gate 	case fxnors:
2927c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
2937c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
2947c478bd9Sstevel@tonic-gate 		usr = ~(us1 ^ us2);
2957c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
2967c478bd9Sstevel@tonic-gate 		break;
2977c478bd9Sstevel@tonic-gate 	case fsrc1:
2987c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lusr, nrs1);
2997c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3007c478bd9Sstevel@tonic-gate 		break;
3017c478bd9Sstevel@tonic-gate 	case fsrc1s:
3027c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &usr, nrs1);
3037c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3047c478bd9Sstevel@tonic-gate 		break;
3057c478bd9Sstevel@tonic-gate 	case fornot2:
3067c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3077c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3087c478bd9Sstevel@tonic-gate 		lusr = (lus1 | ~lus2);
3097c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3107c478bd9Sstevel@tonic-gate 		break;
3117c478bd9Sstevel@tonic-gate 	case fornot2s:
3127c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
3137c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
3147c478bd9Sstevel@tonic-gate 		usr = (us1 | ~us2);
3157c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3167c478bd9Sstevel@tonic-gate 		break;
3177c478bd9Sstevel@tonic-gate 	case fsrc2:
3187c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lusr, nrs2);
3197c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3207c478bd9Sstevel@tonic-gate 		break;
3217c478bd9Sstevel@tonic-gate 	case fsrc2s:
3227c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &usr, nrs2);
3237c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3247c478bd9Sstevel@tonic-gate 		break;
3257c478bd9Sstevel@tonic-gate 	case fornot1:
3267c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3277c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3287c478bd9Sstevel@tonic-gate 		lusr = (~lus1 | lus2);
3297c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3307c478bd9Sstevel@tonic-gate 		break;
3317c478bd9Sstevel@tonic-gate 	case fornot1s:
3327c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
3337c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
3347c478bd9Sstevel@tonic-gate 		usr = (~us1 | us2);
3357c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3367c478bd9Sstevel@tonic-gate 		break;
3377c478bd9Sstevel@tonic-gate 	case for_op:
3387c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus1, nrs1);
3397c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lus2, nrs2);
3407c478bd9Sstevel@tonic-gate 		lusr = (lus1 | lus2);
3417c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3427c478bd9Sstevel@tonic-gate 		break;
3437c478bd9Sstevel@tonic-gate 	case fors_op:
3447c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us1, nrs1);
3457c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &us2, nrs2);
3467c478bd9Sstevel@tonic-gate 		usr = (us1 | us2);
3477c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3487c478bd9Sstevel@tonic-gate 		break;
3497c478bd9Sstevel@tonic-gate 	case fone:
3507c478bd9Sstevel@tonic-gate 		lusr = 0xffffffffffffffff;
3517c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lusr, nrd);
3527c478bd9Sstevel@tonic-gate 		break;
3537c478bd9Sstevel@tonic-gate 	case fones:
3547c478bd9Sstevel@tonic-gate 		usr = 0xffffffffUL;
3557c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &usr, nrd);
3567c478bd9Sstevel@tonic-gate 		break;
3577c478bd9Sstevel@tonic-gate 	case siam:
3587c478bd9Sstevel@tonic-gate 		ftt = vis_siam(pfpsd, f.inst, fp);
3597c478bd9Sstevel@tonic-gate 		break;
3607c478bd9Sstevel@tonic-gate 	default:
3617c478bd9Sstevel@tonic-gate 		return (ftt_unimplemented);
3627c478bd9Sstevel@tonic-gate 	}
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
3657c478bd9Sstevel@tonic-gate 	pregs->r_npc += 4;
3667c478bd9Sstevel@tonic-gate 	return (ftt);
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate  * Simulator for edge instructions
3717c478bd9Sstevel@tonic-gate  */
3727c478bd9Sstevel@tonic-gate static enum ftt_type
3737c478bd9Sstevel@tonic-gate vis_edge(
3747c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
3757c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
3767c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
3777c478bd9Sstevel@tonic-gate 	void		*prw)	/* Pointer to locals and ins. */
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate {
3807c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
3817c478bd9Sstevel@tonic-gate 	enum ftt_type ftt;
3827c478bd9Sstevel@tonic-gate 	uint64_t addrl, addrr, mask;
3837c478bd9Sstevel@tonic-gate 	uint64_t ah61l, ah61r;		/* Higher 61 bits of address */
3847c478bd9Sstevel@tonic-gate 	int al3l, al3r;			/* Lower 3 bits of address */
3857c478bd9Sstevel@tonic-gate 	int am32;			/* Whether PSTATE.AM == 1 */
386*bfb7f382Skalai 	uint_t	ccr;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
3897c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
3907c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &addrl);
3937c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
3947c478bd9Sstevel@tonic-gate 		return (ftt);
3957c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &addrr);
3967c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
3977c478bd9Sstevel@tonic-gate 		return (ftt);
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	/* Get PSTATE.AM to determine 32-bit vs 64-bit addressing */
4005892374fSdf157793 	am32 =  pregs->r_tstate & TSTATE_AM;
4017c478bd9Sstevel@tonic-gate 	if (am32 == 1) {
4025892374fSdf157793 		ah61l = addrl & 0xffffffff8;
4035892374fSdf157793 		ah61r = addrr & 0xffffffff8;
4047c478bd9Sstevel@tonic-gate 	} else {
4057c478bd9Sstevel@tonic-gate 		ah61l = addrl & ~0x7;
4067c478bd9Sstevel@tonic-gate 		ah61r = addrr & ~0x7;
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	switch (inst.opf) {
4117c478bd9Sstevel@tonic-gate 	case edge8:
4127c478bd9Sstevel@tonic-gate 	case edge8n:
4137c478bd9Sstevel@tonic-gate 	case edge8l:
4147c478bd9Sstevel@tonic-gate 	case edge8ln:
4157c478bd9Sstevel@tonic-gate 		al3l = addrl & 0x7;
4167c478bd9Sstevel@tonic-gate 		switch (inst.opf) {
4177c478bd9Sstevel@tonic-gate 		case edge8:
4187c478bd9Sstevel@tonic-gate 		case edge8n:
4197c478bd9Sstevel@tonic-gate 			if (inst.opf == edge8) {
4207c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8);
4217c478bd9Sstevel@tonic-gate 			} else {
4227c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8n);
4237c478bd9Sstevel@tonic-gate 			}
4245892374fSdf157793 			mask = 0xff >> al3l;
4257c478bd9Sstevel@tonic-gate 			if (ah61l == ah61r) {
4267c478bd9Sstevel@tonic-gate 				al3r = addrr & 0x7;
4275892374fSdf157793 				mask &= (0xff << (0x7 - al3r)) & 0xff;
4287c478bd9Sstevel@tonic-gate 			}
4297c478bd9Sstevel@tonic-gate 			break;
4307c478bd9Sstevel@tonic-gate 		case edge8l:
4317c478bd9Sstevel@tonic-gate 		case edge8ln:
4327c478bd9Sstevel@tonic-gate 			if (inst.opf == edge8l) {
4337c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8l);
4347c478bd9Sstevel@tonic-gate 			} else {
4357c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge8ln);
4367c478bd9Sstevel@tonic-gate 			}
4375892374fSdf157793 			mask = (0xff << al3l) & 0xff;
4387c478bd9Sstevel@tonic-gate 			if (ah61l == ah61r) {
4397c478bd9Sstevel@tonic-gate 				al3r = addrr & 0x7;
4405892374fSdf157793 				mask &= 0xff >> (0x7 - al3r);
4417c478bd9Sstevel@tonic-gate 			}
4427c478bd9Sstevel@tonic-gate 			break;
4437c478bd9Sstevel@tonic-gate 		}
4447c478bd9Sstevel@tonic-gate 		break;
4457c478bd9Sstevel@tonic-gate 	case edge16:
4467c478bd9Sstevel@tonic-gate 	case edge16l:
4477c478bd9Sstevel@tonic-gate 	case edge16n:
4487c478bd9Sstevel@tonic-gate 	case edge16ln:
4497c478bd9Sstevel@tonic-gate 		al3l = addrl & 0x6;
4505892374fSdf157793 		al3l >>= 0x1;
4517c478bd9Sstevel@tonic-gate 		switch (inst.opf) {
4527c478bd9Sstevel@tonic-gate 		case edge16:
4537c478bd9Sstevel@tonic-gate 		case edge16n:
4547c478bd9Sstevel@tonic-gate 			if (inst.opf == edge16) {
4557c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16);
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 			} else {
4587c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16n);
4597c478bd9Sstevel@tonic-gate 			}
4605892374fSdf157793 			mask = 0xf >> al3l;
4617c478bd9Sstevel@tonic-gate 			if (ah61l == ah61r) {
4627c478bd9Sstevel@tonic-gate 				al3r = addrr & 0x6;
4635892374fSdf157793 				al3r >>= 0x1;
4645892374fSdf157793 				mask &= (0xf << (0x3 - al3r)) & 0xf;
4657c478bd9Sstevel@tonic-gate 			}
4667c478bd9Sstevel@tonic-gate 			break;
4677c478bd9Sstevel@tonic-gate 		case edge16l:
4687c478bd9Sstevel@tonic-gate 		case edge16ln:
4697c478bd9Sstevel@tonic-gate 			if (inst.opf == edge16l) {
4707c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16l);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 			} else {
4737c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge16ln);
4747c478bd9Sstevel@tonic-gate 			}
4755892374fSdf157793 
4765892374fSdf157793 			mask = (0xf << al3l) & 0xf;
4777c478bd9Sstevel@tonic-gate 			if (ah61l == ah61r) {
4787c478bd9Sstevel@tonic-gate 				al3r = addrr & 0x6;
4795892374fSdf157793 				al3r >>= 0x1;
4805892374fSdf157793 				mask &= 0xf >> (0x3 - al3r);
4817c478bd9Sstevel@tonic-gate 			}
4827c478bd9Sstevel@tonic-gate 			break;
4837c478bd9Sstevel@tonic-gate 		}
4847c478bd9Sstevel@tonic-gate 		break;
4857c478bd9Sstevel@tonic-gate 	case edge32:
4867c478bd9Sstevel@tonic-gate 	case edge32l:
4877c478bd9Sstevel@tonic-gate 	case edge32n:
4887c478bd9Sstevel@tonic-gate 	case edge32ln:
4897c478bd9Sstevel@tonic-gate 		al3l = addrl & 0x4;
4905892374fSdf157793 		al3l >>= 0x2;
4915892374fSdf157793 
4927c478bd9Sstevel@tonic-gate 		switch (inst.opf) {
4937c478bd9Sstevel@tonic-gate 		case edge32:
4947c478bd9Sstevel@tonic-gate 		case edge32n:
4957c478bd9Sstevel@tonic-gate 			if (inst.opf == edge32) {
4967c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32);
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 			} else {
4997c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32n);
5007c478bd9Sstevel@tonic-gate 			}
5015892374fSdf157793 			mask = 0x3 >> al3l;
5027c478bd9Sstevel@tonic-gate 			if (ah61l == ah61r) {
5037c478bd9Sstevel@tonic-gate 				al3r = addrr & 0x4;
5045892374fSdf157793 				al3r >>= 0x2;
5055892374fSdf157793 				mask &= (0x3 << (0x1 - al3r)) & 0x3;
5067c478bd9Sstevel@tonic-gate 			}
5077c478bd9Sstevel@tonic-gate 			break;
5087c478bd9Sstevel@tonic-gate 		case edge32l:
5097c478bd9Sstevel@tonic-gate 		case edge32ln:
5107c478bd9Sstevel@tonic-gate 			if (inst.opf == edge32l) {
5117c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32l);
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 			} else {
5147c478bd9Sstevel@tonic-gate 				VISINFO_KSTAT(vis_edge32ln);
5157c478bd9Sstevel@tonic-gate 			}
5165892374fSdf157793 			mask = (0x3 << al3l) & 0x3;
5177c478bd9Sstevel@tonic-gate 			if (ah61l == ah61r) {
5187c478bd9Sstevel@tonic-gate 				al3r = addrr & 0x4;
5195892374fSdf157793 				al3r >>= 0x2;
5205892374fSdf157793 				mask &= 0x3 >> (0x1 - al3r);
5217c478bd9Sstevel@tonic-gate 			}
5227c478bd9Sstevel@tonic-gate 			break;
5237c478bd9Sstevel@tonic-gate 		}
5247c478bd9Sstevel@tonic-gate 		break;
5257c478bd9Sstevel@tonic-gate 	}
5265892374fSdf157793 
5277c478bd9Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &mask);
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	switch (inst.opf) {
5307c478bd9Sstevel@tonic-gate 	case edge8:
5317c478bd9Sstevel@tonic-gate 	case edge8l:
5327c478bd9Sstevel@tonic-gate 	case edge16:
5337c478bd9Sstevel@tonic-gate 	case edge16l:
5347c478bd9Sstevel@tonic-gate 	case edge32:
5357c478bd9Sstevel@tonic-gate 	case edge32l:
5367c478bd9Sstevel@tonic-gate 
537*bfb7f382Skalai 		/* Update flags per SUBcc outcome */
538*bfb7f382Skalai 		pregs->r_tstate &= ~((uint64_t)TSTATE_CCR_MASK
539*bfb7f382Skalai 					<< TSTATE_CCR_SHIFT);
540*bfb7f382Skalai 		ccr = get_subcc_ccr(addrl, addrr);  /* get subcc cond. codes */
541*bfb7f382Skalai 		pregs->r_tstate |= ((uint64_t)ccr << TSTATE_CCR_SHIFT);
542*bfb7f382Skalai 
5437c478bd9Sstevel@tonic-gate 		break;
5447c478bd9Sstevel@tonic-gate 	}
5457c478bd9Sstevel@tonic-gate 	return (ftt);
5467c478bd9Sstevel@tonic-gate }
547*bfb7f382Skalai 
5487c478bd9Sstevel@tonic-gate /*
5497c478bd9Sstevel@tonic-gate  * Simulator for three dimentional array addressing instructions.
5507c478bd9Sstevel@tonic-gate  */
5517c478bd9Sstevel@tonic-gate static enum ftt_type
5527c478bd9Sstevel@tonic-gate vis_array(
5537c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
5547c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
5557c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
5567c478bd9Sstevel@tonic-gate 	void		*prw)	/* Pointer to locals and ins. */
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate {
5597c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
5607c478bd9Sstevel@tonic-gate 	enum ftt_type ftt;
5617c478bd9Sstevel@tonic-gate 	uint64_t laddr, bsize, baddr;
5627c478bd9Sstevel@tonic-gate 	uint64_t nbit;
5637c478bd9Sstevel@tonic-gate 	int oy, oz;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
5667c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
5677c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &laddr);
5707c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
5717c478bd9Sstevel@tonic-gate 		return (ftt);
5727c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &bsize);
5737c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
5747c478bd9Sstevel@tonic-gate 		return (ftt);
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	if (bsize > 5) {
5777c478bd9Sstevel@tonic-gate 		bsize = 5;
5787c478bd9Sstevel@tonic-gate 	}
5797c478bd9Sstevel@tonic-gate 	nbit = (1 << bsize) - 1;	/* Number of bits for XY<6+n-1:6> */
5807c478bd9Sstevel@tonic-gate 	oy = 17 + bsize;		/* Offset of Y<6+n-1:6> */
5817c478bd9Sstevel@tonic-gate 	oz = 17 + 2 * bsize;		/* Offset of Z<8:5> */
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	baddr = 0;
5847c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (11 -  0)) & (0x03 <<  0);	/* X_integer<1:0> */
5857c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (33 -  2)) & (0x03 <<  2);	/* Y_integer<1:0> */
5867c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (55 -  4)) & (0x01 <<  4);	/* Z_integer<0>   */
5877c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (13 -  5)) & (0x0f <<  5);	/* X_integer<5:2> */
5887c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (35 -  9)) & (0x0f <<  9);	/* Y_integer<5:2> */
5897c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (56 - 13)) & (0x0f << 13);	/* Z_integer<4:1> */
5907c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (17 - 17)) & (nbit << 17);	/* X_integer<6+n-1:6> */
5917c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (39 - oy)) & (nbit << oy);	/* Y_integer<6+n-1:6> */
5927c478bd9Sstevel@tonic-gate 	baddr |= (laddr >> (60 - oz)) & (0x0f << oz);	/* Z_integer<8:5> */
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	switch (inst.opf) {
5957c478bd9Sstevel@tonic-gate 	case array8:
5967c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_array8);
5977c478bd9Sstevel@tonic-gate 		break;
5987c478bd9Sstevel@tonic-gate 	case array16:
5997c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_array16);
6007c478bd9Sstevel@tonic-gate 		baddr <<= 1;
6017c478bd9Sstevel@tonic-gate 		break;
6027c478bd9Sstevel@tonic-gate 	case array32:
6037c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_array32);
6047c478bd9Sstevel@tonic-gate 		baddr <<= 2;
6057c478bd9Sstevel@tonic-gate 		break;
6067c478bd9Sstevel@tonic-gate 	}
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &baddr);
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate 	return (ftt);
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate /*
6147c478bd9Sstevel@tonic-gate  * Simulator for alignaddr and alignaddrl instructions.
6157c478bd9Sstevel@tonic-gate  */
6167c478bd9Sstevel@tonic-gate static enum ftt_type
6177c478bd9Sstevel@tonic-gate vis_alignaddr(
6187c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
6197c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
6207c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
6217c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
6227c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
6237c478bd9Sstevel@tonic-gate {
6247c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
6257c478bd9Sstevel@tonic-gate 	enum ftt_type ftt;
6267c478bd9Sstevel@tonic-gate 	uint64_t ea, tea, g, r;
6277c478bd9Sstevel@tonic-gate 	short s;
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
6307c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
6317c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
6347c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
6357c478bd9Sstevel@tonic-gate 		return (ftt);
6367c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
6377c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
6387c478bd9Sstevel@tonic-gate 		return (ftt);
6397c478bd9Sstevel@tonic-gate 	ea += tea;
6407c478bd9Sstevel@tonic-gate 	r = ea & ~0x7;	/* zero least 3 significant bits */
6417c478bd9Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &r);
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 
6445892374fSdf157793 	g = pfpsd->fp_current_read_gsr(fp);
6457c478bd9Sstevel@tonic-gate 	g &= ~(GSR_ALIGN_MASK);		/* zero the align offset */
6467c478bd9Sstevel@tonic-gate 	r = ea & 0x7;
6477c478bd9Sstevel@tonic-gate 	if (inst.opf == alignaddrl) {
6487c478bd9Sstevel@tonic-gate 		s = (short)(~r);	/* 2's complement for alignaddrl */
6497c478bd9Sstevel@tonic-gate 		if (s < 0)
6507c478bd9Sstevel@tonic-gate 			r = (uint64_t)((s + 1) & 0x7);
6517c478bd9Sstevel@tonic-gate 		else
6527c478bd9Sstevel@tonic-gate 			r = (uint64_t)(s & 0x7);
6537c478bd9Sstevel@tonic-gate 	}
6547c478bd9Sstevel@tonic-gate 	g |= (r << GSR_ALIGN_SHIFT) & GSR_ALIGN_MASK;
6555892374fSdf157793 	pfpsd->fp_current_write_gsr(g, fp);
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	return (ftt);
6587c478bd9Sstevel@tonic-gate }
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate /*
6617c478bd9Sstevel@tonic-gate  * Simulator for bmask instruction.
6627c478bd9Sstevel@tonic-gate  */
6637c478bd9Sstevel@tonic-gate static enum ftt_type
6647c478bd9Sstevel@tonic-gate vis_bmask(
6657c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
6667c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
6677c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
6687c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
6697c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
6707c478bd9Sstevel@tonic-gate {
6717c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
6727c478bd9Sstevel@tonic-gate 	enum ftt_type ftt;
6737c478bd9Sstevel@tonic-gate 	uint64_t ea, tea, g;
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate 	VISINFO_KSTAT(vis_bmask);
6767c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
6777c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
6787c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
6817c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
6827c478bd9Sstevel@tonic-gate 		return (ftt);
6837c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
6847c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
6857c478bd9Sstevel@tonic-gate 		return (ftt);
6867c478bd9Sstevel@tonic-gate 	ea += tea;
6877c478bd9Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &ea);
6887c478bd9Sstevel@tonic-gate 
6895892374fSdf157793 	g = pfpsd->fp_current_read_gsr(fp);
6907c478bd9Sstevel@tonic-gate 	g &= ~(GSR_MASK_MASK);		/* zero the mask offset */
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	/* Put the least significant 32 bits of ea in GSR.mask */
6937c478bd9Sstevel@tonic-gate 	g |= (ea << GSR_MASK_SHIFT) & GSR_MASK_MASK;
6945892374fSdf157793 	pfpsd->fp_current_write_gsr(g, fp);
6957c478bd9Sstevel@tonic-gate 	return (ftt);
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate /*
6997c478bd9Sstevel@tonic-gate  * Simulator for fp[add|sub]* instruction.
7007c478bd9Sstevel@tonic-gate  */
7017c478bd9Sstevel@tonic-gate static enum ftt_type
7027c478bd9Sstevel@tonic-gate vis_fpaddsub(
7037c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
7047c478bd9Sstevel@tonic-gate 	vis_inst_type	inst)	/* FPU instruction to simulate. */
7057c478bd9Sstevel@tonic-gate {
7067c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
7077c478bd9Sstevel@tonic-gate 	union {
7087c478bd9Sstevel@tonic-gate 		uint64_t	ll;
7097c478bd9Sstevel@tonic-gate 		uint32_t	i[2];
7107c478bd9Sstevel@tonic-gate 		uint16_t	s[4];
7117c478bd9Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
7127c478bd9Sstevel@tonic-gate 	union {
7137c478bd9Sstevel@tonic-gate 		uint32_t	i;
7147c478bd9Sstevel@tonic-gate 		uint16_t	s[2];
7157c478bd9Sstevel@tonic-gate 	} krs1, krs2, krd;
7167c478bd9Sstevel@tonic-gate 	int i;
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
7197c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
7207c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
7217c478bd9Sstevel@tonic-gate 	if ((inst.opf & 1) == 0) {	/* double precision */
7227c478bd9Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
7237c478bd9Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
7247c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
7257c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
7267c478bd9Sstevel@tonic-gate 		if ((nrd & 1) == 1)
7277c478bd9Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
7287c478bd9Sstevel@tonic-gate 	}
7297c478bd9Sstevel@tonic-gate 	switch (inst.opf) {
7307c478bd9Sstevel@tonic-gate 	case fpadd16:
7317c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7327c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7337c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
7347c478bd9Sstevel@tonic-gate 			lrd.s[i] = lrs1.s[i] + lrs2.s[i];
7357c478bd9Sstevel@tonic-gate 		}
7367c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7377c478bd9Sstevel@tonic-gate 		break;
7387c478bd9Sstevel@tonic-gate 	case fpadd16s:
7397c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7407c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7417c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7427c478bd9Sstevel@tonic-gate 			krd.s[i] = krs1.s[i] + krs2.s[i];
7437c478bd9Sstevel@tonic-gate 		}
7447c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7457c478bd9Sstevel@tonic-gate 		break;
7467c478bd9Sstevel@tonic-gate 	case fpadd32:
7477c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7487c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7497c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7507c478bd9Sstevel@tonic-gate 			lrd.i[i] = lrs1.i[i] + lrs2.i[i];
7517c478bd9Sstevel@tonic-gate 		}
7527c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7537c478bd9Sstevel@tonic-gate 		break;
7547c478bd9Sstevel@tonic-gate 	case fpadd32s:
7557c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7567c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7577c478bd9Sstevel@tonic-gate 		krd.i = krs1.i + krs2.i;
7587c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7597c478bd9Sstevel@tonic-gate 		break;
7607c478bd9Sstevel@tonic-gate 	case fpsub16:
7617c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7627c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7637c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
7647c478bd9Sstevel@tonic-gate 			lrd.s[i] = lrs1.s[i] - lrs2.s[i];
7657c478bd9Sstevel@tonic-gate 		}
7667c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7677c478bd9Sstevel@tonic-gate 		break;
7687c478bd9Sstevel@tonic-gate 	case fpsub16s:
7697c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7707c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7717c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7727c478bd9Sstevel@tonic-gate 			krd.s[i] = krs1.s[i] - krs2.s[i];
7737c478bd9Sstevel@tonic-gate 		}
7747c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7757c478bd9Sstevel@tonic-gate 		break;
7767c478bd9Sstevel@tonic-gate 	case fpsub32:
7777c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
7787c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
7797c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
7807c478bd9Sstevel@tonic-gate 			lrd.i[i] = lrs1.i[i] - lrs2.i[i];
7817c478bd9Sstevel@tonic-gate 		}
7827c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
7837c478bd9Sstevel@tonic-gate 		break;
7847c478bd9Sstevel@tonic-gate 	case fpsub32s:
7857c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
7867c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
7877c478bd9Sstevel@tonic-gate 		krd.i = krs1.i - krs2.i;
7887c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
7897c478bd9Sstevel@tonic-gate 		break;
7907c478bd9Sstevel@tonic-gate 	}
7917c478bd9Sstevel@tonic-gate 	return (ftt_none);
7927c478bd9Sstevel@tonic-gate }
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate /*
7957c478bd9Sstevel@tonic-gate  * Simulator for fcmp* instruction.
7967c478bd9Sstevel@tonic-gate  */
7977c478bd9Sstevel@tonic-gate static enum ftt_type
7987c478bd9Sstevel@tonic-gate vis_fcmp(
7997c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
8007c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
8017c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
8027c478bd9Sstevel@tonic-gate 	void		*prw)	/* Pointer to locals and ins. */
8037c478bd9Sstevel@tonic-gate {
8047c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
8057c478bd9Sstevel@tonic-gate 	union {
8067c478bd9Sstevel@tonic-gate 		uint64_t	ll;
8077c478bd9Sstevel@tonic-gate 		uint32_t	i[2];
8087c478bd9Sstevel@tonic-gate 		uint16_t	s[4];
8097c478bd9Sstevel@tonic-gate 	} krs1, krs2, krd;
8107c478bd9Sstevel@tonic-gate 	enum ftt_type ftt;
8117c478bd9Sstevel@tonic-gate 	short sr1, sr2;
8127c478bd9Sstevel@tonic-gate 	int i, ir1, ir2;
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
8157c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
8167c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
8177c478bd9Sstevel@tonic-gate 	krd.ll = 0;
8187c478bd9Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 	/* fix register encoding */
8197c478bd9Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
8207c478bd9Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
8217c478bd9Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &krs1.ll, nrs1);
8247c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &krs2.ll, nrs2);
8257c478bd9Sstevel@tonic-gate 	switch (inst.opf) {
8267c478bd9Sstevel@tonic-gate 	case fcmple16:
8277c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmple16);
8287c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8297c478bd9Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8307c478bd9Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8317c478bd9Sstevel@tonic-gate 			if (sr1 <= sr2)
8327c478bd9Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8337c478bd9Sstevel@tonic-gate 		}
8347c478bd9Sstevel@tonic-gate 		break;
8357c478bd9Sstevel@tonic-gate 	case fcmpne16:
8367c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpne16);
8377c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8387c478bd9Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8397c478bd9Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8407c478bd9Sstevel@tonic-gate 			if (sr1 != sr2)
8417c478bd9Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8427c478bd9Sstevel@tonic-gate 		}
8437c478bd9Sstevel@tonic-gate 		break;
8447c478bd9Sstevel@tonic-gate 	case fcmpgt16:
8457c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpgt16);
8467c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8477c478bd9Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8487c478bd9Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8497c478bd9Sstevel@tonic-gate 			if (sr1 > sr2)
8507c478bd9Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8517c478bd9Sstevel@tonic-gate 		}
8527c478bd9Sstevel@tonic-gate 		break;
8537c478bd9Sstevel@tonic-gate 	case fcmpeq16:
8547c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpeq16);
8557c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
8567c478bd9Sstevel@tonic-gate 			sr1 = (short)krs1.s[i];
8577c478bd9Sstevel@tonic-gate 			sr2 = (short)krs2.s[i];
8587c478bd9Sstevel@tonic-gate 			if (sr1 == sr2)
8597c478bd9Sstevel@tonic-gate 				krd.ll += (0x8 >> i);
8607c478bd9Sstevel@tonic-gate 		}
8617c478bd9Sstevel@tonic-gate 		break;
8627c478bd9Sstevel@tonic-gate 	case fcmple32:
8637c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmple32);
8647c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8657c478bd9Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8667c478bd9Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8677c478bd9Sstevel@tonic-gate 			if (ir1 <= ir2)
8687c478bd9Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8697c478bd9Sstevel@tonic-gate 		}
8707c478bd9Sstevel@tonic-gate 		break;
8717c478bd9Sstevel@tonic-gate 	case fcmpne32:
8727c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpne32);
8737c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8747c478bd9Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8757c478bd9Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8767c478bd9Sstevel@tonic-gate 			if (ir1 != ir2)
8777c478bd9Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8787c478bd9Sstevel@tonic-gate 		}
8797c478bd9Sstevel@tonic-gate 		break;
8807c478bd9Sstevel@tonic-gate 	case fcmpgt32:
8817c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpgt32);
8827c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8837c478bd9Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8847c478bd9Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8857c478bd9Sstevel@tonic-gate 			if (ir1 > ir2)
8867c478bd9Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8877c478bd9Sstevel@tonic-gate 		}
8887c478bd9Sstevel@tonic-gate 		break;
8897c478bd9Sstevel@tonic-gate 	case fcmpeq32:
8907c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fcmpeq32);
8917c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
8927c478bd9Sstevel@tonic-gate 			ir1 = (int)krs1.i[i];
8937c478bd9Sstevel@tonic-gate 			ir2 = (int)krs2.i[i];
8947c478bd9Sstevel@tonic-gate 			if (ir1 == ir2)
8957c478bd9Sstevel@tonic-gate 				krd.ll += (0x2 >> i);
8967c478bd9Sstevel@tonic-gate 		}
8977c478bd9Sstevel@tonic-gate 		break;
8987c478bd9Sstevel@tonic-gate 	}
8997c478bd9Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &krd.ll);
9007c478bd9Sstevel@tonic-gate 	return (ftt);
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate /*
9047c478bd9Sstevel@tonic-gate  * Simulator for fmul* instruction.
9057c478bd9Sstevel@tonic-gate  */
9067c478bd9Sstevel@tonic-gate static enum ftt_type
9077c478bd9Sstevel@tonic-gate vis_fmul(
9087c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
9097c478bd9Sstevel@tonic-gate 	vis_inst_type	inst)	/* FPU instruction to simulate. */
9107c478bd9Sstevel@tonic-gate {
9117c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
9127c478bd9Sstevel@tonic-gate 	union {
9137c478bd9Sstevel@tonic-gate 		uint64_t	ll;
9147c478bd9Sstevel@tonic-gate 		uint32_t	i[2];
9157c478bd9Sstevel@tonic-gate 		uint16_t	s[4];
9167c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
9177c478bd9Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
9187c478bd9Sstevel@tonic-gate 	union {
9197c478bd9Sstevel@tonic-gate 		uint32_t	i;
9207c478bd9Sstevel@tonic-gate 		uint16_t	s[2];
9217c478bd9Sstevel@tonic-gate 		uint8_t		c[4];
9227c478bd9Sstevel@tonic-gate 	} krs1, krs2, kres;
9237c478bd9Sstevel@tonic-gate 	short s1, s2, sres;
9247c478bd9Sstevel@tonic-gate 	ushort_t us1;
9257c478bd9Sstevel@tonic-gate 	char c1;
9267c478bd9Sstevel@tonic-gate 	int i;
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
9297c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
9307c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
9317c478bd9Sstevel@tonic-gate 	if ((inst.opf & 1) == 0) {	/* double precision */
9327c478bd9Sstevel@tonic-gate 		if ((nrd & 1) == 1) 	/* fix register encoding */
9337c478bd9Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
9347c478bd9Sstevel@tonic-gate 	}
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate 	switch (inst.opf) {
9377c478bd9Sstevel@tonic-gate 	case fmul8x16:
9387c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8x16);
9397c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9407c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
9417c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
9427c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
9437c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9447c478bd9Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[i];
9457c478bd9Sstevel@tonic-gate 			s2 = (short)lrs2.s[i];
9467c478bd9Sstevel@tonic-gate 			kres.i = us1 * s2;
9477c478bd9Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9487c478bd9Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9497c478bd9Sstevel@tonic-gate 				sres++;
9507c478bd9Sstevel@tonic-gate 			lrd.s[i] = sres;
9517c478bd9Sstevel@tonic-gate 		}
9527c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9537c478bd9Sstevel@tonic-gate 		break;
9547c478bd9Sstevel@tonic-gate 	case fmul8x16au:
9557c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8x16au);
9567c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9577c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
9587c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9597c478bd9Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[i];
9607c478bd9Sstevel@tonic-gate 			s2 = (short)krs2.s[0];
9617c478bd9Sstevel@tonic-gate 			kres.i = us1 * s2;
9627c478bd9Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9637c478bd9Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9647c478bd9Sstevel@tonic-gate 				sres++;
9657c478bd9Sstevel@tonic-gate 			lrd.s[i] = sres;
9667c478bd9Sstevel@tonic-gate 		}
9677c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9687c478bd9Sstevel@tonic-gate 		break;
9697c478bd9Sstevel@tonic-gate 	case fmul8x16al:
9707c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8x16al);
9717c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
9727c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
9737c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9747c478bd9Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[i];
9757c478bd9Sstevel@tonic-gate 			s2 = (short)krs2.s[1];
9767c478bd9Sstevel@tonic-gate 			kres.i = us1 * s2;
9777c478bd9Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9787c478bd9Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9797c478bd9Sstevel@tonic-gate 				sres++;
9807c478bd9Sstevel@tonic-gate 			lrd.s[i] = sres;
9817c478bd9Sstevel@tonic-gate 		}
9827c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
9837c478bd9Sstevel@tonic-gate 		break;
9847c478bd9Sstevel@tonic-gate 	case fmul8sux16:
9857c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8sux16);
9867c478bd9Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
9877c478bd9Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
9887c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
9897c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
9907c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
9917c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
9927c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
9937c478bd9Sstevel@tonic-gate 			c1 = lrs1.c[(i*2)];
9947c478bd9Sstevel@tonic-gate 			s1 = (short)c1;		/* keeps the sign alive */
9957c478bd9Sstevel@tonic-gate 			s2 = (short)lrs2.s[i];
9967c478bd9Sstevel@tonic-gate 			kres.i = s1 * s2;
9977c478bd9Sstevel@tonic-gate 			sres = (short)((kres.c[1] << 8) | kres.c[2]);
9987c478bd9Sstevel@tonic-gate 			if (kres.c[3] >= 0x80)
9997c478bd9Sstevel@tonic-gate 				sres++;
10007c478bd9Sstevel@tonic-gate 			if (sres < 0)
10017c478bd9Sstevel@tonic-gate 				lrd.s[i] = (sres & 0xFFFF);
10027c478bd9Sstevel@tonic-gate 			else
10037c478bd9Sstevel@tonic-gate 				lrd.s[i] = sres;
10047c478bd9Sstevel@tonic-gate 		}
10057c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10067c478bd9Sstevel@tonic-gate 		break;
10077c478bd9Sstevel@tonic-gate 	case fmul8ulx16:
10087c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmul8ulx16);
10097c478bd9Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
10107c478bd9Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
10117c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
10127c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
10137c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
10147c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
10157c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
10167c478bd9Sstevel@tonic-gate 			us1 = (ushort_t)lrs1.c[(i*2)+1];
10177c478bd9Sstevel@tonic-gate 			s2 = (short)lrs2.s[i];
10187c478bd9Sstevel@tonic-gate 			kres.i = us1 * s2;
10197c478bd9Sstevel@tonic-gate 			sres = (short)kres.s[0];
10207c478bd9Sstevel@tonic-gate 			if (kres.s[1] >= 0x8000)
10217c478bd9Sstevel@tonic-gate 				sres++;
10227c478bd9Sstevel@tonic-gate 			lrd.s[i] = sres;
10237c478bd9Sstevel@tonic-gate 		}
10247c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10257c478bd9Sstevel@tonic-gate 		break;
10267c478bd9Sstevel@tonic-gate 	case fmuld8sux16:
10277c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmuld8sux16);
10287c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
10297c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
10307c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
10317c478bd9Sstevel@tonic-gate 			c1 = krs1.c[(i*2)];
10327c478bd9Sstevel@tonic-gate 			s1 = (short)c1;		/* keeps the sign alive */
10337c478bd9Sstevel@tonic-gate 			s2 = (short)krs2.s[i];
10347c478bd9Sstevel@tonic-gate 			kres.i = s1 * s2;
10357c478bd9Sstevel@tonic-gate 			lrd.i[i] = kres.i << 8;
10367c478bd9Sstevel@tonic-gate 		}
10377c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10387c478bd9Sstevel@tonic-gate 		break;
10397c478bd9Sstevel@tonic-gate 	case fmuld8ulx16:
10407c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fmuld8ulx16);
10417c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
10427c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
10437c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
10447c478bd9Sstevel@tonic-gate 			us1 = (ushort_t)krs1.c[(i*2)+1];
10457c478bd9Sstevel@tonic-gate 			s2 = (short)krs2.s[i];
10467c478bd9Sstevel@tonic-gate 			lrd.i[i] = us1 * s2;
10477c478bd9Sstevel@tonic-gate 		}
10487c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
10497c478bd9Sstevel@tonic-gate 		break;
10507c478bd9Sstevel@tonic-gate 	}
10517c478bd9Sstevel@tonic-gate 	return (ftt_none);
10527c478bd9Sstevel@tonic-gate }
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate /*
10557c478bd9Sstevel@tonic-gate  * Simulator for fpixel formatting instructions.
10567c478bd9Sstevel@tonic-gate  */
10577c478bd9Sstevel@tonic-gate static enum ftt_type
10587c478bd9Sstevel@tonic-gate vis_fpixel(
10597c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
10607c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
10617c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
10627c478bd9Sstevel@tonic-gate {
10637c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
10647c478bd9Sstevel@tonic-gate 	int	i, j, k, sf;
10657c478bd9Sstevel@tonic-gate 	union {
10667c478bd9Sstevel@tonic-gate 		uint64_t	ll;
10677c478bd9Sstevel@tonic-gate 		uint32_t	i[2];
10687c478bd9Sstevel@tonic-gate 		uint16_t	s[4];
10697c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
10707c478bd9Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
10717c478bd9Sstevel@tonic-gate 	union {
10727c478bd9Sstevel@tonic-gate 		uint32_t	i;
10737c478bd9Sstevel@tonic-gate 		uint16_t	s[2];
10747c478bd9Sstevel@tonic-gate 		uint8_t		c[4];
10757c478bd9Sstevel@tonic-gate 	} krs1, krs2, krd;
10767c478bd9Sstevel@tonic-gate 	uint64_t r;
10777c478bd9Sstevel@tonic-gate 	int64_t l, m;
10787c478bd9Sstevel@tonic-gate 	short s;
10797c478bd9Sstevel@tonic-gate 	uchar_t uc;
10807c478bd9Sstevel@tonic-gate 
10817c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
10827c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
10837c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
10847c478bd9Sstevel@tonic-gate 	if ((inst.opf != fpack16) && (inst.opf != fpackfix)) {
10857c478bd9Sstevel@tonic-gate 		if ((nrd & 1) == 1) 	/* fix register encoding */
10867c478bd9Sstevel@tonic-gate 			nrd = (nrd & 0x1e) | 0x20;
10877c478bd9Sstevel@tonic-gate 	}
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate 	switch (inst.opf) {
10907c478bd9Sstevel@tonic-gate 	case fpack16:
10917c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpack16);
10927c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1) 	/* fix register encoding */
10937c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
10947c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
10955892374fSdf157793 		r = pfpsd->fp_current_read_gsr(fp);
10967c478bd9Sstevel@tonic-gate 		/* fpack16 ignores GSR.scale msb */
10977c478bd9Sstevel@tonic-gate 		sf = (int)(GSR_SCALE(r) & 0xf);
10987c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
10997c478bd9Sstevel@tonic-gate 			s = (short)lrs2.s[i];	/* preserve the sign */
11007c478bd9Sstevel@tonic-gate 			j = ((int)s << sf);
11017c478bd9Sstevel@tonic-gate 			k = j >> 7;
11027c478bd9Sstevel@tonic-gate 			if (k < 0) {
11037c478bd9Sstevel@tonic-gate 				uc = 0;
11047c478bd9Sstevel@tonic-gate 			} else if (k > 255) {
11057c478bd9Sstevel@tonic-gate 				uc = 255;
11067c478bd9Sstevel@tonic-gate 			} else {
11077c478bd9Sstevel@tonic-gate 				uc = (uchar_t)k;
11087c478bd9Sstevel@tonic-gate 			}
11097c478bd9Sstevel@tonic-gate 			krd.c[i] = uc;
11107c478bd9Sstevel@tonic-gate 		}
11117c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
11127c478bd9Sstevel@tonic-gate 		break;
11137c478bd9Sstevel@tonic-gate 	case fpack32:
11147c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpack32);
11157c478bd9Sstevel@tonic-gate 		if ((nrs1 & 1) == 1) 	/* fix register encoding */
11167c478bd9Sstevel@tonic-gate 			nrs1 = (nrs1 & 0x1e) | 0x20;
11177c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
11187c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
11197c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
11207c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
11217c478bd9Sstevel@tonic-gate 
11225892374fSdf157793 		r = pfpsd->fp_current_read_gsr(fp);
11237c478bd9Sstevel@tonic-gate 		sf = (int)GSR_SCALE(r);
11247c478bd9Sstevel@tonic-gate 		lrd.ll = lrs1.ll << 8;
11257c478bd9Sstevel@tonic-gate 		for (i = 0, k = 3; i <= 1; i++, k += 4) {
11267c478bd9Sstevel@tonic-gate 			j = (int)lrs2.i[i];	/* preserve the sign */
11277c478bd9Sstevel@tonic-gate 			l = ((int64_t)j << sf);
11287c478bd9Sstevel@tonic-gate 			m = l >> 23;
11297c478bd9Sstevel@tonic-gate 			if (m < 0) {
11307c478bd9Sstevel@tonic-gate 				uc = 0;
11317c478bd9Sstevel@tonic-gate 			} else if (m > 255) {
11327c478bd9Sstevel@tonic-gate 				uc = 255;
11337c478bd9Sstevel@tonic-gate 			} else {
11347c478bd9Sstevel@tonic-gate 				uc = (uchar_t)m;
11357c478bd9Sstevel@tonic-gate 			}
11367c478bd9Sstevel@tonic-gate 			lrd.c[k] = uc;
11377c478bd9Sstevel@tonic-gate 		}
11387c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11397c478bd9Sstevel@tonic-gate 		break;
11407c478bd9Sstevel@tonic-gate 	case fpackfix:
11417c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpackfix);
11427c478bd9Sstevel@tonic-gate 		if ((nrs2 & 1) == 1)
11437c478bd9Sstevel@tonic-gate 			nrs2 = (nrs2 & 0x1e) | 0x20;
11447c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
11457c478bd9Sstevel@tonic-gate 
11465892374fSdf157793 		r = pfpsd->fp_current_read_gsr(fp);
11477c478bd9Sstevel@tonic-gate 		sf = (int)GSR_SCALE(r);
11487c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 1; i++) {
11497c478bd9Sstevel@tonic-gate 			j = (int)lrs2.i[i];	/* preserve the sign */
11507c478bd9Sstevel@tonic-gate 			l = ((int64_t)j << sf);
11517c478bd9Sstevel@tonic-gate 			m = l >> 16;
11527c478bd9Sstevel@tonic-gate 			if (m < -32768) {
11537c478bd9Sstevel@tonic-gate 				s = -32768;
11547c478bd9Sstevel@tonic-gate 			} else if (m > 32767) {
11557c478bd9Sstevel@tonic-gate 				s = 32767;
11567c478bd9Sstevel@tonic-gate 			} else {
11577c478bd9Sstevel@tonic-gate 				s = (short)m;
11587c478bd9Sstevel@tonic-gate 			}
11597c478bd9Sstevel@tonic-gate 			krd.s[i] = s;
11607c478bd9Sstevel@tonic-gate 		}
11617c478bd9Sstevel@tonic-gate 		_fp_pack_word(pfpsd, &krd.i, nrd);
11627c478bd9Sstevel@tonic-gate 		break;
11637c478bd9Sstevel@tonic-gate 	case fexpand:
11647c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fexpand);
11657c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
11667c478bd9Sstevel@tonic-gate 		for (i = 0; i <= 3; i++) {
11677c478bd9Sstevel@tonic-gate 			uc = krs2.c[i];
11687c478bd9Sstevel@tonic-gate 			lrd.s[i] = (ushort_t)(uc << 4);
11697c478bd9Sstevel@tonic-gate 		}
11707c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11717c478bd9Sstevel@tonic-gate 		break;
11727c478bd9Sstevel@tonic-gate 	case fpmerge:
11737c478bd9Sstevel@tonic-gate 		VISINFO_KSTAT(vis_fpmerge);
11747c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs1.i, nrs1);
11757c478bd9Sstevel@tonic-gate 		_fp_unpack_word(pfpsd, &krs2.i, nrs2);
11767c478bd9Sstevel@tonic-gate 		for (i = 0, j = 0; i <= 3; i++, j += 2) {
11777c478bd9Sstevel@tonic-gate 			lrd.c[j] = krs1.c[i];
11787c478bd9Sstevel@tonic-gate 			lrd.c[j+1] = krs2.c[i];
11797c478bd9Sstevel@tonic-gate 		}
11807c478bd9Sstevel@tonic-gate 		_fp_pack_extword(pfpsd, &lrd.ll, nrd);
11817c478bd9Sstevel@tonic-gate 		break;
11827c478bd9Sstevel@tonic-gate 	}
11837c478bd9Sstevel@tonic-gate 	return (ftt_none);
11847c478bd9Sstevel@tonic-gate }
11857c478bd9Sstevel@tonic-gate 
11867c478bd9Sstevel@tonic-gate /*
11877c478bd9Sstevel@tonic-gate  * Simulator for pdist instruction.
11887c478bd9Sstevel@tonic-gate  */
11897c478bd9Sstevel@tonic-gate enum ftt_type
11907c478bd9Sstevel@tonic-gate vis_pdist(
11917c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
11927c478bd9Sstevel@tonic-gate 	fp_inst_type	pinst)	/* FPU instruction to simulate. */
11937c478bd9Sstevel@tonic-gate {
11947c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
11957c478bd9Sstevel@tonic-gate 	int	i;
11967c478bd9Sstevel@tonic-gate 	short	s;
11977c478bd9Sstevel@tonic-gate 	union {
11987c478bd9Sstevel@tonic-gate 		uint64_t	ll;
11997c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
12007c478bd9Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
12017c478bd9Sstevel@tonic-gate 
12027c478bd9Sstevel@tonic-gate 	nrs1 = pinst.rs1;
12037c478bd9Sstevel@tonic-gate 	nrs2 = pinst.rs2;
12047c478bd9Sstevel@tonic-gate 	nrd = pinst.rd;
12057c478bd9Sstevel@tonic-gate 	VISINFO_KSTAT(vis_pdist);
12067c478bd9Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12077c478bd9Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
12087c478bd9Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
12097c478bd9Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
12107c478bd9Sstevel@tonic-gate 	if ((nrd & 1) == 1)
12117c478bd9Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
12147c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
12157c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrd.ll, nrd);
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate 	for (i = 0; i <= 7; i++) {
12187c478bd9Sstevel@tonic-gate 		s = (short)(lrs1.c[i] - lrs2.c[i]);
12197c478bd9Sstevel@tonic-gate 		if (s < 0)
12207c478bd9Sstevel@tonic-gate 			s = ~s + 1;
12217c478bd9Sstevel@tonic-gate 		lrd.ll += s;
12227c478bd9Sstevel@tonic-gate 	}
12237c478bd9Sstevel@tonic-gate 
12247c478bd9Sstevel@tonic-gate 	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
12257c478bd9Sstevel@tonic-gate 	return (ftt_none);
12267c478bd9Sstevel@tonic-gate }
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate /*
12297c478bd9Sstevel@tonic-gate  * Simulator for faligndata instruction.
12307c478bd9Sstevel@tonic-gate  */
12317c478bd9Sstevel@tonic-gate static enum ftt_type
12327c478bd9Sstevel@tonic-gate vis_faligndata(
12337c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
12347c478bd9Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
12357c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
12367c478bd9Sstevel@tonic-gate {
12377c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
12387c478bd9Sstevel@tonic-gate 	int	i, j, k, ao;
12397c478bd9Sstevel@tonic-gate 	union {
12407c478bd9Sstevel@tonic-gate 		uint64_t	ll;
12417c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
12427c478bd9Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
12437c478bd9Sstevel@tonic-gate 	uint64_t r;
12447c478bd9Sstevel@tonic-gate 
12457c478bd9Sstevel@tonic-gate 	nrs1 = pinst.rs1;
12467c478bd9Sstevel@tonic-gate 	nrs2 = pinst.rs2;
12477c478bd9Sstevel@tonic-gate 	nrd = pinst.rd;
12487c478bd9Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12497c478bd9Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
12507c478bd9Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
12517c478bd9Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
12527c478bd9Sstevel@tonic-gate 	if ((nrd & 1) == 1)
12537c478bd9Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
12547c478bd9Sstevel@tonic-gate 
12557c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
12567c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
12577c478bd9Sstevel@tonic-gate 
12585892374fSdf157793 	r = pfpsd->fp_current_read_gsr(fp);
12597c478bd9Sstevel@tonic-gate 	ao = (int)GSR_ALIGN(r);
12607c478bd9Sstevel@tonic-gate 
12617c478bd9Sstevel@tonic-gate 	for (i = 0, j = ao, k = 0; i <= 7; i++)
12627c478bd9Sstevel@tonic-gate 		if (j <= 7) {
12637c478bd9Sstevel@tonic-gate 			lrd.c[i] = lrs1.c[j++];
12647c478bd9Sstevel@tonic-gate 		} else {
12657c478bd9Sstevel@tonic-gate 			lrd.c[i] = lrs2.c[k++];
12667c478bd9Sstevel@tonic-gate 		}
12677c478bd9Sstevel@tonic-gate 	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate 	return (ftt_none);
12707c478bd9Sstevel@tonic-gate }
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate /*
12737c478bd9Sstevel@tonic-gate  * Simulator for bshuffle instruction.
12747c478bd9Sstevel@tonic-gate  */
12757c478bd9Sstevel@tonic-gate static enum ftt_type
12767c478bd9Sstevel@tonic-gate vis_bshuffle(
12777c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
12787c478bd9Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
12797c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
12807c478bd9Sstevel@tonic-gate {
12817c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
12827c478bd9Sstevel@tonic-gate 	int	i, j, ao;
12837c478bd9Sstevel@tonic-gate 	union {
12847c478bd9Sstevel@tonic-gate 		uint64_t	ll;
12857c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
12867c478bd9Sstevel@tonic-gate 	} lrs1, lrs2, lrd;
12877c478bd9Sstevel@tonic-gate 	uint64_t r;
12887c478bd9Sstevel@tonic-gate 
12897c478bd9Sstevel@tonic-gate 	VISINFO_KSTAT(vis_bshuffle);
12907c478bd9Sstevel@tonic-gate 	nrs1 = pinst.rs1;
12917c478bd9Sstevel@tonic-gate 	nrs2 = pinst.rs2;
12927c478bd9Sstevel@tonic-gate 	nrd = pinst.rd;
12937c478bd9Sstevel@tonic-gate 	if ((nrs1 & 1) == 1) 		/* fix register encoding */
12947c478bd9Sstevel@tonic-gate 		nrs1 = (nrs1 & 0x1e) | 0x20;
12957c478bd9Sstevel@tonic-gate 	if ((nrs2 & 1) == 1)
12967c478bd9Sstevel@tonic-gate 		nrs2 = (nrs2 & 0x1e) | 0x20;
12977c478bd9Sstevel@tonic-gate 	if ((nrd & 1) == 1)
12987c478bd9Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
12997c478bd9Sstevel@tonic-gate 
13007c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs1.ll, nrs1);
13017c478bd9Sstevel@tonic-gate 	_fp_unpack_extword(pfpsd, &lrs2.ll, nrs2);
13027c478bd9Sstevel@tonic-gate 
13035892374fSdf157793 	r = pfpsd->fp_current_read_gsr(fp);
13047c478bd9Sstevel@tonic-gate 	ao = (int)GSR_MASK(r);
13057c478bd9Sstevel@tonic-gate 
13067c478bd9Sstevel@tonic-gate 	/*
13077c478bd9Sstevel@tonic-gate 	 * BSHUFFLE Destination Byte Selection
13087c478bd9Sstevel@tonic-gate 	 * rd Byte	Source
13097c478bd9Sstevel@tonic-gate 	 * 0		rs byte[GSR.mask<31..28>]
13107c478bd9Sstevel@tonic-gate 	 * 1		rs byte[GSR.mask<27..24>]
13117c478bd9Sstevel@tonic-gate 	 * 2		rs byte[GSR.mask<23..20>]
13127c478bd9Sstevel@tonic-gate 	 * 3		rs byte[GSR.mask<19..16>]
13137c478bd9Sstevel@tonic-gate 	 * 4		rs byte[GSR.mask<15..12>]
13147c478bd9Sstevel@tonic-gate 	 * 5		rs byte[GSR.mask<11..8>]
13157c478bd9Sstevel@tonic-gate 	 * 6		rs byte[GSR.mask<7..4>]
13167c478bd9Sstevel@tonic-gate 	 * 7		rs byte[GSR.mask<3..0>]
13177c478bd9Sstevel@tonic-gate 	 * P.S. rs1 is the upper half and rs2 is the lower half
13187c478bd9Sstevel@tonic-gate 	 * Bytes in the source value are numbered from most to
13197c478bd9Sstevel@tonic-gate 	 * least significant
13207c478bd9Sstevel@tonic-gate 	 */
13217c478bd9Sstevel@tonic-gate 	for (i = 7; i >= 0; i--, ao = (ao >> 4)) {
13227c478bd9Sstevel@tonic-gate 		j = ao & 0xf;		/* get byte number */
13237c478bd9Sstevel@tonic-gate 		if (j < 8) {
13247c478bd9Sstevel@tonic-gate 			lrd.c[i] = lrs1.c[j];
13257c478bd9Sstevel@tonic-gate 		} else {
13267c478bd9Sstevel@tonic-gate 			lrd.c[i] = lrs2.c[j - 8];
13277c478bd9Sstevel@tonic-gate 		}
13287c478bd9Sstevel@tonic-gate 	}
13297c478bd9Sstevel@tonic-gate 	_fp_pack_extword(pfpsd, &lrd.ll, nrd);
13307c478bd9Sstevel@tonic-gate 
13317c478bd9Sstevel@tonic-gate 	return (ftt_none);
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate 
13347c478bd9Sstevel@tonic-gate /*
13357c478bd9Sstevel@tonic-gate  * Simulator for siam instruction.
13367c478bd9Sstevel@tonic-gate  */
13377c478bd9Sstevel@tonic-gate static enum ftt_type
13387c478bd9Sstevel@tonic-gate vis_siam(
13397c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
13407c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* FPU instruction to simulate. */
13417c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
13427c478bd9Sstevel@tonic-gate {
13437c478bd9Sstevel@tonic-gate 	uint_t	nrs2;			/* Register number fields. */
13447c478bd9Sstevel@tonic-gate 	uint64_t g, r;
13457c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
13467c478bd9Sstevel@tonic-gate 
13475892374fSdf157793 	g = pfpsd->fp_current_read_gsr(fp);
13487c478bd9Sstevel@tonic-gate 	g &= ~(GSR_IM_IRND_MASK);	/* zero the IM and IRND fields */
13497c478bd9Sstevel@tonic-gate 	r = nrs2 & 0x7;			/* get mode(3 bit) */
13507c478bd9Sstevel@tonic-gate 	g |= (r << GSR_IRND_SHIFT);
13515892374fSdf157793 	pfpsd->fp_current_write_gsr(g, fp);
13527c478bd9Sstevel@tonic-gate 	return (ftt_none);
13537c478bd9Sstevel@tonic-gate }
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate /*
13567c478bd9Sstevel@tonic-gate  * Simulator for VIS loads and stores between floating-point unit and memory.
13577c478bd9Sstevel@tonic-gate  */
13587c478bd9Sstevel@tonic-gate enum ftt_type
13597c478bd9Sstevel@tonic-gate vis_fldst(
13607c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
13617c478bd9Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
13627c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
13637c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
13647c478bd9Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
13657c478bd9Sstevel@tonic-gate {
13667c478bd9Sstevel@tonic-gate 	union {
13677c478bd9Sstevel@tonic-gate 		vis_inst_type	inst;
13687c478bd9Sstevel@tonic-gate 		fp_inst_type	pinst;
13697c478bd9Sstevel@tonic-gate 	} i;
13707c478bd9Sstevel@tonic-gate 
13717c478bd9Sstevel@tonic-gate 	ASSERT(USERMODE(pregs->r_tstate));
13727c478bd9Sstevel@tonic-gate 	i.pinst = pinst;
13737c478bd9Sstevel@tonic-gate 	switch (asi) {
13747c478bd9Sstevel@tonic-gate 		case ASI_PST8_P:
13757c478bd9Sstevel@tonic-gate 		case ASI_PST8_S:
13767c478bd9Sstevel@tonic-gate 		case ASI_PST16_P:
13777c478bd9Sstevel@tonic-gate 		case ASI_PST16_S:
13787c478bd9Sstevel@tonic-gate 		case ASI_PST32_P:
13797c478bd9Sstevel@tonic-gate 		case ASI_PST32_S:
13807c478bd9Sstevel@tonic-gate 		case ASI_PST8_PL:
13817c478bd9Sstevel@tonic-gate 		case ASI_PST8_SL:
13827c478bd9Sstevel@tonic-gate 		case ASI_PST16_PL:
13837c478bd9Sstevel@tonic-gate 		case ASI_PST16_SL:
13847c478bd9Sstevel@tonic-gate 		case ASI_PST32_PL:
13857c478bd9Sstevel@tonic-gate 		case ASI_PST32_SL:
13867c478bd9Sstevel@tonic-gate 			return (vis_prtl_fst(pfpsd, i.inst, pregs,
13877c478bd9Sstevel@tonic-gate 				prw, asi));
13887c478bd9Sstevel@tonic-gate 		case ASI_FL8_P:
13897c478bd9Sstevel@tonic-gate 		case ASI_FL8_S:
13907c478bd9Sstevel@tonic-gate 		case ASI_FL8_PL:
13917c478bd9Sstevel@tonic-gate 		case ASI_FL8_SL:
13927c478bd9Sstevel@tonic-gate 		case ASI_FL16_P:
13937c478bd9Sstevel@tonic-gate 		case ASI_FL16_S:
13947c478bd9Sstevel@tonic-gate 		case ASI_FL16_PL:
13957c478bd9Sstevel@tonic-gate 		case ASI_FL16_SL:
13967c478bd9Sstevel@tonic-gate 			return (vis_short_fls(pfpsd, i.inst, pregs,
13977c478bd9Sstevel@tonic-gate 				prw, asi));
13987c478bd9Sstevel@tonic-gate 		case ASI_BLK_AIUP:
13997c478bd9Sstevel@tonic-gate 		case ASI_BLK_AIUS:
14007c478bd9Sstevel@tonic-gate 		case ASI_BLK_AIUPL:
14017c478bd9Sstevel@tonic-gate 		case ASI_BLK_AIUSL:
14027c478bd9Sstevel@tonic-gate 		case ASI_BLK_P:
14037c478bd9Sstevel@tonic-gate 		case ASI_BLK_S:
14047c478bd9Sstevel@tonic-gate 		case ASI_BLK_PL:
14057c478bd9Sstevel@tonic-gate 		case ASI_BLK_SL:
14067c478bd9Sstevel@tonic-gate 		case ASI_BLK_COMMIT_P:
14077c478bd9Sstevel@tonic-gate 		case ASI_BLK_COMMIT_S:
14087c478bd9Sstevel@tonic-gate 			return (vis_blk_fldst(pfpsd, i.inst, pregs,
14097c478bd9Sstevel@tonic-gate 				prw, asi));
14107c478bd9Sstevel@tonic-gate 		default:
14117c478bd9Sstevel@tonic-gate 			return (ftt_unimplemented);
14127c478bd9Sstevel@tonic-gate 	}
14137c478bd9Sstevel@tonic-gate }
14147c478bd9Sstevel@tonic-gate 
14157c478bd9Sstevel@tonic-gate /*
14167c478bd9Sstevel@tonic-gate  * Simulator for partial stores between floating-point unit and memory.
14177c478bd9Sstevel@tonic-gate  */
14187c478bd9Sstevel@tonic-gate static enum ftt_type
14197c478bd9Sstevel@tonic-gate vis_prtl_fst(
14207c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
14217c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* ISE instruction to simulate. */
14227c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
14237c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
14247c478bd9Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
14257c478bd9Sstevel@tonic-gate {
14267c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
14277c478bd9Sstevel@tonic-gate 	uint_t	opf, msk;
14287c478bd9Sstevel@tonic-gate 	int	h, i, j;
14297c478bd9Sstevel@tonic-gate 	uint64_t ea, tmsk;
14307c478bd9Sstevel@tonic-gate 	union {
14317c478bd9Sstevel@tonic-gate 		freg_type	f;
14327c478bd9Sstevel@tonic-gate 		uint64_t	ll;
14337c478bd9Sstevel@tonic-gate 		uint32_t	i[2];
14347c478bd9Sstevel@tonic-gate 		uint16_t	s[4];
14357c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
14367c478bd9Sstevel@tonic-gate 	} k, l, res;
14377c478bd9Sstevel@tonic-gate 	enum ftt_type   ftt;
14387c478bd9Sstevel@tonic-gate 
14397c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
14407c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
14417c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
14427c478bd9Sstevel@tonic-gate 	if ((nrd & 1) == 1) 		/* fix register encoding */
14437c478bd9Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
14447c478bd9Sstevel@tonic-gate 	opf = inst.opf;
14457c478bd9Sstevel@tonic-gate 	res.ll = 0;
14467c478bd9Sstevel@tonic-gate 	if ((opf & 0x100) == 0) {	/* effective address = rs1  */
14477c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
14487c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
14497c478bd9Sstevel@tonic-gate 			return (ftt);
14507c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tmsk);
14517c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
14527c478bd9Sstevel@tonic-gate 			return (ftt);
14537c478bd9Sstevel@tonic-gate 		msk = (uint_t)tmsk;
14547c478bd9Sstevel@tonic-gate 	} else {
14557c478bd9Sstevel@tonic-gate 		pfpsd->fp_trapaddr = (caddr_t)pregs->r_pc;
14567c478bd9Sstevel@tonic-gate 		return (ftt_unimplemented);
14577c478bd9Sstevel@tonic-gate 	}
14587c478bd9Sstevel@tonic-gate 
14597c478bd9Sstevel@tonic-gate 	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
14607c478bd9Sstevel@tonic-gate 	if ((ea & 0x3) != 0)
14617c478bd9Sstevel@tonic-gate 		return (ftt_alignment);	/* Require 32 bit-alignment. */
14627c478bd9Sstevel@tonic-gate 
14637c478bd9Sstevel@tonic-gate 	switch (asi) {
14647c478bd9Sstevel@tonic-gate 	case ASI_PST8_P:
14657c478bd9Sstevel@tonic-gate 	case ASI_PST8_S:
14667c478bd9Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14677c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
14687c478bd9Sstevel@tonic-gate 			return (ftt);
14697c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
14707c478bd9Sstevel@tonic-gate 		for (i = 0, j = 0x80; i <= 7; i++, j >>= 1) {
14717c478bd9Sstevel@tonic-gate 			if ((msk & j) == j)
14727c478bd9Sstevel@tonic-gate 				res.c[i] = k.c[i];
14737c478bd9Sstevel@tonic-gate 			else
14747c478bd9Sstevel@tonic-gate 				res.c[i] = l.c[i];
14757c478bd9Sstevel@tonic-gate 		}
14767c478bd9Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
14777c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
14787c478bd9Sstevel@tonic-gate 			return (ftt);
14797c478bd9Sstevel@tonic-gate 		break;
14807c478bd9Sstevel@tonic-gate 	case ASI_PST8_PL:	/* little-endian */
14817c478bd9Sstevel@tonic-gate 	case ASI_PST8_SL:
14827c478bd9Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14837c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
14847c478bd9Sstevel@tonic-gate 			return (ftt);
14857c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
14867c478bd9Sstevel@tonic-gate 		for (h = 7, i = 0, j = 0x80; i <= 7; h--, i++, j >>= 1) {
14877c478bd9Sstevel@tonic-gate 			if ((msk & j) == j)
14887c478bd9Sstevel@tonic-gate 				res.c[h] = k.c[i];
14897c478bd9Sstevel@tonic-gate 			else
14907c478bd9Sstevel@tonic-gate 				res.c[h] = l.c[i];
14917c478bd9Sstevel@tonic-gate 		}
14927c478bd9Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
14937c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
14947c478bd9Sstevel@tonic-gate 			return (ftt);
14957c478bd9Sstevel@tonic-gate 		break;
14967c478bd9Sstevel@tonic-gate 	case ASI_PST16_P:
14977c478bd9Sstevel@tonic-gate 	case ASI_PST16_S:
14987c478bd9Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
14997c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15007c478bd9Sstevel@tonic-gate 			return (ftt);
15017c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15027c478bd9Sstevel@tonic-gate 		for (i = 0, j = 0x8; i <= 3; i++, j >>= 1) {
15037c478bd9Sstevel@tonic-gate 			if ((msk & j) == j)
15047c478bd9Sstevel@tonic-gate 				res.s[i] = k.s[i];
15057c478bd9Sstevel@tonic-gate 			else
15067c478bd9Sstevel@tonic-gate 				res.s[i] = l.s[i];
15077c478bd9Sstevel@tonic-gate 		}
15087c478bd9Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15097c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15107c478bd9Sstevel@tonic-gate 			return (ftt);
15117c478bd9Sstevel@tonic-gate 		break;
15127c478bd9Sstevel@tonic-gate 	case ASI_PST16_PL:
15137c478bd9Sstevel@tonic-gate 	case ASI_PST16_SL:
15147c478bd9Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15157c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15167c478bd9Sstevel@tonic-gate 			return (ftt);
15177c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15187c478bd9Sstevel@tonic-gate 		for (h = 7, i = 0, j = 0x8; i <= 6; h -= 2, i += 2, j >>= 1) {
15197c478bd9Sstevel@tonic-gate 			if ((msk & j) == j) {
15207c478bd9Sstevel@tonic-gate 				res.c[h] = k.c[i];
15217c478bd9Sstevel@tonic-gate 				res.c[h-1] = k.c[i+1];
15227c478bd9Sstevel@tonic-gate 			} else {
15237c478bd9Sstevel@tonic-gate 				res.c[h] = l.c[i];
15247c478bd9Sstevel@tonic-gate 				res.c[h-1] = l.c[i+1];
15257c478bd9Sstevel@tonic-gate 			}
15267c478bd9Sstevel@tonic-gate 		}
15277c478bd9Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15287c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15297c478bd9Sstevel@tonic-gate 			return (ftt);
15307c478bd9Sstevel@tonic-gate 		break;
15317c478bd9Sstevel@tonic-gate 	case ASI_PST32_P:
15327c478bd9Sstevel@tonic-gate 	case ASI_PST32_S:
15337c478bd9Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15347c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15357c478bd9Sstevel@tonic-gate 			return (ftt);
15367c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15377c478bd9Sstevel@tonic-gate 		for (i = 0, j = 0x2; i <= 1; i++, j >>= 1) {
15387c478bd9Sstevel@tonic-gate 			if ((msk & j) == j)
15397c478bd9Sstevel@tonic-gate 				res.i[i] = k.i[i];
15407c478bd9Sstevel@tonic-gate 			else
15417c478bd9Sstevel@tonic-gate 				res.i[i] = l.i[i];
15427c478bd9Sstevel@tonic-gate 		}
15437c478bd9Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15447c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15457c478bd9Sstevel@tonic-gate 			return (ftt);
15467c478bd9Sstevel@tonic-gate 		break;
15477c478bd9Sstevel@tonic-gate 	case ASI_PST32_PL:
15487c478bd9Sstevel@tonic-gate 	case ASI_PST32_SL:
15497c478bd9Sstevel@tonic-gate 		ftt = _fp_read_extword((uint64_t *)ea, &l.ll, pfpsd);
15507c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15517c478bd9Sstevel@tonic-gate 			return (ftt);
15527c478bd9Sstevel@tonic-gate 		_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
15537c478bd9Sstevel@tonic-gate 		for (h = 7, i = 0, j = 0x2; i <= 4; h -= 4, i += 4, j >>= 1) {
15547c478bd9Sstevel@tonic-gate 			if ((msk & j) == j) {
15557c478bd9Sstevel@tonic-gate 				res.c[h] = k.c[i];
15567c478bd9Sstevel@tonic-gate 				res.c[h-1] = k.c[i+1];
15577c478bd9Sstevel@tonic-gate 				res.c[h-2] = k.c[i+2];
15587c478bd9Sstevel@tonic-gate 				res.c[h-3] = k.c[i+3];
15597c478bd9Sstevel@tonic-gate 			} else {
15607c478bd9Sstevel@tonic-gate 				res.c[h] = l.c[i];
15617c478bd9Sstevel@tonic-gate 				res.c[h-1] = l.c[i+1];
15627c478bd9Sstevel@tonic-gate 				res.c[h-2] = l.c[i+2];
15637c478bd9Sstevel@tonic-gate 				res.c[h-3] = l.c[i+3];
15647c478bd9Sstevel@tonic-gate 			}
15657c478bd9Sstevel@tonic-gate 		}
15667c478bd9Sstevel@tonic-gate 		ftt = _fp_write_extword((uint64_t *)ea, res.ll, pfpsd);
15677c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
15687c478bd9Sstevel@tonic-gate 			return (ftt);
15697c478bd9Sstevel@tonic-gate 		break;
15707c478bd9Sstevel@tonic-gate 	}
15717c478bd9Sstevel@tonic-gate 
15727c478bd9Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
15737c478bd9Sstevel@tonic-gate 	pregs->r_npc += 4;
15747c478bd9Sstevel@tonic-gate 	return (ftt_none);
15757c478bd9Sstevel@tonic-gate }
15767c478bd9Sstevel@tonic-gate 
15777c478bd9Sstevel@tonic-gate /*
15787c478bd9Sstevel@tonic-gate  * Simulator for short load/stores between floating-point unit and memory.
15797c478bd9Sstevel@tonic-gate  */
15807c478bd9Sstevel@tonic-gate static enum ftt_type
15817c478bd9Sstevel@tonic-gate vis_short_fls(
15827c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
15837c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* ISE instruction to simulate. */
15847c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
15857c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
15867c478bd9Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
15877c478bd9Sstevel@tonic-gate {
15887c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
15897c478bd9Sstevel@tonic-gate 	uint_t	opf;
15907c478bd9Sstevel@tonic-gate 	uint64_t ea, tea;
15917c478bd9Sstevel@tonic-gate 	union {
15927c478bd9Sstevel@tonic-gate 		freg_type	f;
15937c478bd9Sstevel@tonic-gate 		uint64_t	ll;
15947c478bd9Sstevel@tonic-gate 		uint32_t	i[2];
15957c478bd9Sstevel@tonic-gate 		uint16_t	s[4];
15967c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
15977c478bd9Sstevel@tonic-gate 	} k;
15987c478bd9Sstevel@tonic-gate 	union {
15997c478bd9Sstevel@tonic-gate 		vis_inst_type	inst;
16007c478bd9Sstevel@tonic-gate 		int		i;
16017c478bd9Sstevel@tonic-gate 	} fp;
16027c478bd9Sstevel@tonic-gate 	enum ftt_type   ftt = ftt_none;
16037c478bd9Sstevel@tonic-gate 	ushort_t us;
16047c478bd9Sstevel@tonic-gate 	uchar_t uc;
16057c478bd9Sstevel@tonic-gate 
16067c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
16077c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
16087c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
16097c478bd9Sstevel@tonic-gate 	if ((nrd & 1) == 1) 		/* fix register encoding */
16107c478bd9Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
16117c478bd9Sstevel@tonic-gate 	opf = inst.opf;
16127c478bd9Sstevel@tonic-gate 	fp.inst = inst;
16137c478bd9Sstevel@tonic-gate 	if ((opf & 0x100) == 0) { /* effective address = rs1 + rs2 */
16147c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
16157c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
16167c478bd9Sstevel@tonic-gate 			return (ftt);
16177c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
16187c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
16197c478bd9Sstevel@tonic-gate 			return (ftt);
16207c478bd9Sstevel@tonic-gate 		ea += tea;
16217c478bd9Sstevel@tonic-gate 	} else {	/* effective address = rs1 + imm13 */
16227c478bd9Sstevel@tonic-gate 		fp.inst = inst;
16237c478bd9Sstevel@tonic-gate 		ea = (fp.i << 19) >> 19;	/* Extract simm13 field. */
16247c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &tea);
16257c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
16267c478bd9Sstevel@tonic-gate 			return (ftt);
16277c478bd9Sstevel@tonic-gate 		ea += tea;
16287c478bd9Sstevel@tonic-gate 	}
16297c478bd9Sstevel@tonic-gate 	if (get_udatamodel() == DATAMODEL_ILP32)
16307c478bd9Sstevel@tonic-gate 		ea = (uint64_t)(caddr32_t)ea;
16317c478bd9Sstevel@tonic-gate 
16327c478bd9Sstevel@tonic-gate 	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
16337c478bd9Sstevel@tonic-gate 	switch (asi) {
16347c478bd9Sstevel@tonic-gate 	case ASI_FL8_P:
16357c478bd9Sstevel@tonic-gate 	case ASI_FL8_S:
16367c478bd9Sstevel@tonic-gate 	case ASI_FL8_PL:		/* little-endian */
16377c478bd9Sstevel@tonic-gate 	case ASI_FL8_SL:
16387c478bd9Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* load byte */
16397c478bd9Sstevel@tonic-gate 			if (fuword8((void *)ea, &uc) == -1)
16407c478bd9Sstevel@tonic-gate 				return (ftt_fault);
16417c478bd9Sstevel@tonic-gate 			k.ll = 0;
16427c478bd9Sstevel@tonic-gate 			k.c[7] = uc;
16437c478bd9Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16447c478bd9Sstevel@tonic-gate 		} else {			/* store byte */
16457c478bd9Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16467c478bd9Sstevel@tonic-gate 			uc = k.c[7];
16477c478bd9Sstevel@tonic-gate 			if (subyte((caddr_t)ea, uc) == -1)
16487c478bd9Sstevel@tonic-gate 				return (ftt_fault);
16497c478bd9Sstevel@tonic-gate 		}
16507c478bd9Sstevel@tonic-gate 		break;
16517c478bd9Sstevel@tonic-gate 	case ASI_FL16_P:
16527c478bd9Sstevel@tonic-gate 	case ASI_FL16_S:
16537c478bd9Sstevel@tonic-gate 		if ((ea & 1) == 1)
16547c478bd9Sstevel@tonic-gate 			return (ftt_alignment);
16557c478bd9Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* load short */
16567c478bd9Sstevel@tonic-gate 			if (fuword16((void *)ea, &us) == -1)
16577c478bd9Sstevel@tonic-gate 				return (ftt_fault);
16587c478bd9Sstevel@tonic-gate 			k.ll = 0;
16597c478bd9Sstevel@tonic-gate 			k.s[3] = us;
16607c478bd9Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16617c478bd9Sstevel@tonic-gate 		} else {			/* store short */
16627c478bd9Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16637c478bd9Sstevel@tonic-gate 			us = k.s[3];
16647c478bd9Sstevel@tonic-gate 			if (suword16((caddr_t)ea, us) == -1)
16657c478bd9Sstevel@tonic-gate 				return (ftt_fault);
16667c478bd9Sstevel@tonic-gate 		}
16677c478bd9Sstevel@tonic-gate 		break;
16687c478bd9Sstevel@tonic-gate 	case ASI_FL16_PL:		/* little-endian */
16697c478bd9Sstevel@tonic-gate 	case ASI_FL16_SL:
16707c478bd9Sstevel@tonic-gate 		if ((ea & 1) == 1)
16717c478bd9Sstevel@tonic-gate 			return (ftt_alignment);
16727c478bd9Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* load short */
16737c478bd9Sstevel@tonic-gate 			if (fuword16((void *)ea, &us) == -1)
16747c478bd9Sstevel@tonic-gate 				return (ftt_fault);
16757c478bd9Sstevel@tonic-gate 			k.ll = 0;
16767c478bd9Sstevel@tonic-gate 			k.c[6] = (uchar_t)us;
16777c478bd9Sstevel@tonic-gate 			k.c[7] = (uchar_t)((us & 0xff00) >> 8);
16787c478bd9Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16797c478bd9Sstevel@tonic-gate 		} else {			/* store short */
16807c478bd9Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
16817c478bd9Sstevel@tonic-gate 			uc = k.c[7];
16827c478bd9Sstevel@tonic-gate 			us = (ushort_t)((uc << 8) | k.c[6]);
16837c478bd9Sstevel@tonic-gate 			if (suword16((void *)ea, us) == -1)
16847c478bd9Sstevel@tonic-gate 				return (ftt_fault);
16857c478bd9Sstevel@tonic-gate 		}
16867c478bd9Sstevel@tonic-gate 		break;
16877c478bd9Sstevel@tonic-gate 	}
16887c478bd9Sstevel@tonic-gate 
16897c478bd9Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
16907c478bd9Sstevel@tonic-gate 	pregs->r_npc += 4;
16917c478bd9Sstevel@tonic-gate 	return (ftt_none);
16927c478bd9Sstevel@tonic-gate }
16937c478bd9Sstevel@tonic-gate 
16947c478bd9Sstevel@tonic-gate /*
16957c478bd9Sstevel@tonic-gate  * Simulator for block loads and stores between floating-point unit and memory.
16967c478bd9Sstevel@tonic-gate  * XXX - OK, so it is really gross to flush the whole Ecache for a block commit
16977c478bd9Sstevel@tonic-gate  *	 store - but the circumstances under which this code actually gets
16987c478bd9Sstevel@tonic-gate  *	 used in real life are so obscure that you can live with it!
16997c478bd9Sstevel@tonic-gate  */
17007c478bd9Sstevel@tonic-gate static enum ftt_type
17017c478bd9Sstevel@tonic-gate vis_blk_fldst(
17027c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
17037c478bd9Sstevel@tonic-gate 	vis_inst_type	inst,	/* ISE instruction to simulate. */
17047c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
17057c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
17067c478bd9Sstevel@tonic-gate 	uint_t		asi)	/* asi to emulate! */
17077c478bd9Sstevel@tonic-gate {
17087c478bd9Sstevel@tonic-gate 	uint_t	nrs1, nrs2, nrd;	/* Register number fields. */
17097c478bd9Sstevel@tonic-gate 	uint_t	opf, h, i, j;
17107c478bd9Sstevel@tonic-gate 	uint64_t ea, tea;
17117c478bd9Sstevel@tonic-gate 	union {
17127c478bd9Sstevel@tonic-gate 		freg_type	f;
17137c478bd9Sstevel@tonic-gate 		uint64_t	ll;
17147c478bd9Sstevel@tonic-gate 		uint8_t		c[8];
17157c478bd9Sstevel@tonic-gate 	} k, l;
17167c478bd9Sstevel@tonic-gate 	union {
17177c478bd9Sstevel@tonic-gate 		vis_inst_type	inst;
17187c478bd9Sstevel@tonic-gate 		int32_t		i;
17197c478bd9Sstevel@tonic-gate 	} fp;
17207c478bd9Sstevel@tonic-gate 	enum ftt_type   ftt;
17217c478bd9Sstevel@tonic-gate 	boolean_t little_endian = B_FALSE;
17227c478bd9Sstevel@tonic-gate 
17237c478bd9Sstevel@tonic-gate 	nrs1 = inst.rs1;
17247c478bd9Sstevel@tonic-gate 	nrs2 = inst.rs2;
17257c478bd9Sstevel@tonic-gate 	nrd = inst.rd;
17267c478bd9Sstevel@tonic-gate 	if ((nrd & 1) == 1) 		/* fix register encoding */
17277c478bd9Sstevel@tonic-gate 		nrd = (nrd & 0x1e) | 0x20;
17287c478bd9Sstevel@tonic-gate 
17297c478bd9Sstevel@tonic-gate 	/* ensure register is 8-double precision aligned */
17307c478bd9Sstevel@tonic-gate 	if ((nrd & 0xf) != 0)
17317c478bd9Sstevel@tonic-gate 		return (ftt_unimplemented);
17327c478bd9Sstevel@tonic-gate 
17337c478bd9Sstevel@tonic-gate 	opf = inst.opf;
17347c478bd9Sstevel@tonic-gate 	if ((opf & 0x100) == 0) { 	/* effective address = rs1 + rs2 */
17357c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &ea);
17367c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
17377c478bd9Sstevel@tonic-gate 			return (ftt);
17387c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &tea);
17397c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
17407c478bd9Sstevel@tonic-gate 			return (ftt);
17417c478bd9Sstevel@tonic-gate 		ea += tea;
17427c478bd9Sstevel@tonic-gate 	} else {			/* effective address = rs1 + imm13 */
17437c478bd9Sstevel@tonic-gate 		fp.inst = inst;
17447c478bd9Sstevel@tonic-gate 		ea = (fp.i << 19) >> 19;	/* Extract simm13 field. */
17457c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs1, pregs, prw, &tea);
17467c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
17477c478bd9Sstevel@tonic-gate 			return (ftt);
17487c478bd9Sstevel@tonic-gate 		ea += tea;
17497c478bd9Sstevel@tonic-gate 	}
17507c478bd9Sstevel@tonic-gate 	if ((ea & 0x3F) != 0)		/* Require 64 byte-alignment. */
17517c478bd9Sstevel@tonic-gate 		return (ftt_alignment);
17527c478bd9Sstevel@tonic-gate 
17537c478bd9Sstevel@tonic-gate 	pfpsd->fp_trapaddr = (caddr_t)ea; /* setup bad addr in case we trap */
17547c478bd9Sstevel@tonic-gate 	switch (asi) {
17557c478bd9Sstevel@tonic-gate 	case ASI_BLK_AIUPL:
17567c478bd9Sstevel@tonic-gate 	case ASI_BLK_AIUSL:
17577c478bd9Sstevel@tonic-gate 	case ASI_BLK_PL:
17587c478bd9Sstevel@tonic-gate 	case ASI_BLK_SL:
17597c478bd9Sstevel@tonic-gate 		little_endian = B_TRUE;
17607c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
17617c478bd9Sstevel@tonic-gate 	case ASI_BLK_AIUP:
17627c478bd9Sstevel@tonic-gate 	case ASI_BLK_AIUS:
17637c478bd9Sstevel@tonic-gate 	case ASI_BLK_P:
17647c478bd9Sstevel@tonic-gate 	case ASI_BLK_S:
17657c478bd9Sstevel@tonic-gate 	case ASI_BLK_COMMIT_P:
17667c478bd9Sstevel@tonic-gate 	case ASI_BLK_COMMIT_S:
17677c478bd9Sstevel@tonic-gate 		if ((inst.op3 & 7) == 3) {	/* lddf */
17687c478bd9Sstevel@tonic-gate 		    for (i = 0; i < 8; i++, ea += 8, nrd += 2) {
17697c478bd9Sstevel@tonic-gate 			ftt = _fp_read_extword((uint64_t *)ea, &k.ll, pfpsd);
17707c478bd9Sstevel@tonic-gate 			if (ftt != ftt_none)
17717c478bd9Sstevel@tonic-gate 				return (ftt);
17727c478bd9Sstevel@tonic-gate 			if (little_endian) {
17737c478bd9Sstevel@tonic-gate 				for (j = 0, h = 7; j < 8; j++, h--)
17747c478bd9Sstevel@tonic-gate 					l.c[h] = k.c[j];
17757c478bd9Sstevel@tonic-gate 				k.ll = l.ll;
17767c478bd9Sstevel@tonic-gate 			}
17777c478bd9Sstevel@tonic-gate 			_fp_pack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
17787c478bd9Sstevel@tonic-gate 		    }
17797c478bd9Sstevel@tonic-gate 		} else {			/* stdf */
17807c478bd9Sstevel@tonic-gate 		    for (i = 0; i < 8; i++, ea += 8, nrd += 2) {
17817c478bd9Sstevel@tonic-gate 			_fp_unpack_extword(pfpsd, &k.f.FPU_DREG_FIELD, nrd);
17827c478bd9Sstevel@tonic-gate 			if (little_endian) {
17837c478bd9Sstevel@tonic-gate 				for (j = 0, h = 7; j < 8; j++, h--)
17847c478bd9Sstevel@tonic-gate 					l.c[h] = k.c[j];
17857c478bd9Sstevel@tonic-gate 				k.ll = l.ll;
17867c478bd9Sstevel@tonic-gate 			}
17877c478bd9Sstevel@tonic-gate 			ftt = _fp_write_extword((uint64_t *)ea, k.ll, pfpsd);
17887c478bd9Sstevel@tonic-gate 			if (ftt != ftt_none)
17897c478bd9Sstevel@tonic-gate 				return (ftt);
17907c478bd9Sstevel@tonic-gate 		    }
17917c478bd9Sstevel@tonic-gate 		}
17927c478bd9Sstevel@tonic-gate 		if ((asi == ASI_BLK_COMMIT_P) || (asi == ASI_BLK_COMMIT_S))
17937c478bd9Sstevel@tonic-gate 			cpu_flush_ecache();
17947c478bd9Sstevel@tonic-gate 		break;
17957c478bd9Sstevel@tonic-gate 	default:
17967c478bd9Sstevel@tonic-gate 		/* addr of unimp inst */
17977c478bd9Sstevel@tonic-gate 		pfpsd->fp_trapaddr = (caddr_t)pregs->r_pc;
17987c478bd9Sstevel@tonic-gate 		return (ftt_unimplemented);
17997c478bd9Sstevel@tonic-gate 	}
18007c478bd9Sstevel@tonic-gate 
18017c478bd9Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18027c478bd9Sstevel@tonic-gate 	pregs->r_npc += 4;
18037c478bd9Sstevel@tonic-gate 	return (ftt_none);
18047c478bd9Sstevel@tonic-gate }
18057c478bd9Sstevel@tonic-gate 
18067c478bd9Sstevel@tonic-gate /*
18077c478bd9Sstevel@tonic-gate  * Simulator for rd %gsr instruction.
18087c478bd9Sstevel@tonic-gate  */
18097c478bd9Sstevel@tonic-gate enum ftt_type
18107c478bd9Sstevel@tonic-gate vis_rdgsr(
18117c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
18127c478bd9Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
18137c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
18147c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
18157c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
18167c478bd9Sstevel@tonic-gate {
18177c478bd9Sstevel@tonic-gate 	uint_t nrd;
18187c478bd9Sstevel@tonic-gate 	uint64_t r;
18197c478bd9Sstevel@tonic-gate 	enum ftt_type ftt = ftt_none;
18207c478bd9Sstevel@tonic-gate 
18217c478bd9Sstevel@tonic-gate 	nrd = pinst.rd;
18227c478bd9Sstevel@tonic-gate 
18235892374fSdf157793 	r = pfpsd->fp_current_read_gsr(fp);
18247c478bd9Sstevel@tonic-gate 	ftt = write_iureg(pfpsd, nrd, pregs, prw, &r);
18257c478bd9Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18267c478bd9Sstevel@tonic-gate 	pregs->r_npc += 4;
18277c478bd9Sstevel@tonic-gate 	return (ftt);
18287c478bd9Sstevel@tonic-gate }
18297c478bd9Sstevel@tonic-gate 
18307c478bd9Sstevel@tonic-gate /*
18317c478bd9Sstevel@tonic-gate  * Simulator for wr %gsr instruction.
18327c478bd9Sstevel@tonic-gate  */
18337c478bd9Sstevel@tonic-gate enum ftt_type
18347c478bd9Sstevel@tonic-gate vis_wrgsr(
18357c478bd9Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
18367c478bd9Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
18377c478bd9Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
18387c478bd9Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
18397c478bd9Sstevel@tonic-gate 	kfpu_t		*fp)	/* Need to fp to access gsr reg */
18407c478bd9Sstevel@tonic-gate {
18417c478bd9Sstevel@tonic-gate 	uint_t nrs1;
18427c478bd9Sstevel@tonic-gate 	uint64_t r, r1, r2;
18437c478bd9Sstevel@tonic-gate 	enum ftt_type ftt = ftt_none;
18447c478bd9Sstevel@tonic-gate 
18457c478bd9Sstevel@tonic-gate 	nrs1 = pinst.rs1;
18467c478bd9Sstevel@tonic-gate 	ftt = read_iureg(pfpsd, nrs1, pregs, prw, &r1);
18477c478bd9Sstevel@tonic-gate 	if (ftt != ftt_none)
18487c478bd9Sstevel@tonic-gate 		return (ftt);
18497c478bd9Sstevel@tonic-gate 	if (pinst.ibit == 0) {	/* copy the value in r[rs2] */
18507c478bd9Sstevel@tonic-gate 		uint_t nrs2;
18517c478bd9Sstevel@tonic-gate 
18527c478bd9Sstevel@tonic-gate 		nrs2 = pinst.rs2;
18537c478bd9Sstevel@tonic-gate 		ftt = read_iureg(pfpsd, nrs2, pregs, prw, &r2);
18547c478bd9Sstevel@tonic-gate 		if (ftt != ftt_none)
18557c478bd9Sstevel@tonic-gate 			return (ftt);
18567c478bd9Sstevel@tonic-gate 	} else {	/* use sign_ext(simm13) */
18577c478bd9Sstevel@tonic-gate 		union {
18587c478bd9Sstevel@tonic-gate 			fp_inst_type	inst;
18597c478bd9Sstevel@tonic-gate 			uint32_t	i;
18607c478bd9Sstevel@tonic-gate 		} fp;
18617c478bd9Sstevel@tonic-gate 
18627c478bd9Sstevel@tonic-gate 		fp.inst = pinst;		/* Extract simm13 field */
18637c478bd9Sstevel@tonic-gate 		r2 = (fp.i << 19) >> 19;
18647c478bd9Sstevel@tonic-gate 	}
18657c478bd9Sstevel@tonic-gate 	r = r1 ^ r2;
18665892374fSdf157793 	pfpsd->fp_current_write_gsr(r, fp);
18677c478bd9Sstevel@tonic-gate 	pregs->r_pc = pregs->r_npc;	/* Do not retry emulated instruction. */
18687c478bd9Sstevel@tonic-gate 	pregs->r_npc += 4;
18697c478bd9Sstevel@tonic-gate 	return (ftt);
18707c478bd9Sstevel@tonic-gate }
18717c478bd9Sstevel@tonic-gate 
18727c478bd9Sstevel@tonic-gate /*
18737c478bd9Sstevel@tonic-gate  * This is the loadable module wrapper.
18747c478bd9Sstevel@tonic-gate  */
18757c478bd9Sstevel@tonic-gate #include <sys/errno.h>
18767c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
18777c478bd9Sstevel@tonic-gate 
18787c478bd9Sstevel@tonic-gate /*
18797c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
18807c478bd9Sstevel@tonic-gate  */
18817c478bd9Sstevel@tonic-gate extern struct mod_ops mod_miscops;
18827c478bd9Sstevel@tonic-gate 
18837c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = {
18847c478bd9Sstevel@tonic-gate 	&mod_miscops,
18857c478bd9Sstevel@tonic-gate 	"vis fp simulation",
18867c478bd9Sstevel@tonic-gate };
18877c478bd9Sstevel@tonic-gate 
18887c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
18897c478bd9Sstevel@tonic-gate 	MODREV_1, (void *)&modlmisc, NULL
18907c478bd9Sstevel@tonic-gate };
18917c478bd9Sstevel@tonic-gate 
18927c478bd9Sstevel@tonic-gate int
18937c478bd9Sstevel@tonic-gate _init(void)
18947c478bd9Sstevel@tonic-gate {
18957c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
18967c478bd9Sstevel@tonic-gate }
18977c478bd9Sstevel@tonic-gate 
18987c478bd9Sstevel@tonic-gate int
18997c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
19007c478bd9Sstevel@tonic-gate {
19017c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
19027c478bd9Sstevel@tonic-gate }
1903