xref: /onnv-gate/usr/src/uts/sparc/fpu/iu_simulator.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /* Integer Unit simulator for Sparc FPU simulator. */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #include <sys/fpu/fpu_simulator.h>
32*0Sstevel@tonic-gate #include <sys/fpu/globals.h>
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <sys/regset.h>
35*0Sstevel@tonic-gate #include <sys/privregs.h>
36*0Sstevel@tonic-gate #include <sys/vis_simulator.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate  * fbcc_sim() also handles V9 fbpcc, and ignores the prediction bit.
40*0Sstevel@tonic-gate  */
41*0Sstevel@tonic-gate static enum ftt_type
fbcc_sim(fp_inst_type pinst,struct regs * pregs,kfpu_t * pfpu)42*0Sstevel@tonic-gate fbcc_sim(
43*0Sstevel@tonic-gate 	fp_inst_type    pinst,	/* FPU instruction to simulate. */
44*0Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
45*0Sstevel@tonic-gate 	kfpu_t		*pfpu)	/* Pointer to FPU register block. */
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate {
48*0Sstevel@tonic-gate 	fsr_type	fsr;
49*0Sstevel@tonic-gate 	int fbpcc = 0;
50*0Sstevel@tonic-gate 	union {
51*0Sstevel@tonic-gate 		fp_inst_type	fi;
52*0Sstevel@tonic-gate 		int32_t		i;	/* for sign_ext(disp22) */
53*0Sstevel@tonic-gate 	} fp;
54*0Sstevel@tonic-gate 	enum fcc_type	fcc;
55*0Sstevel@tonic-gate 	enum icc_type {
56*0Sstevel@tonic-gate 		fbn, fbne, fblg, fbul, fbl, fbug, fbg, fbu,
57*0Sstevel@tonic-gate 		fba, fbe, fbue, fbge, fbuge, fble, fbule, fbo
58*0Sstevel@tonic-gate 	} icc;
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate 	uint_t	annul, takeit;
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate 	if (((pinst.op3 >> 3) & 0xf) == 5)
63*0Sstevel@tonic-gate 		fbpcc = 1;
64*0Sstevel@tonic-gate 	fsr.ll = pfpu->fpu_fsr;
65*0Sstevel@tonic-gate 	if (fbpcc) {
66*0Sstevel@tonic-gate 		uint_t nfcc = (pinst.op3 >> 1) & 0x3;
67*0Sstevel@tonic-gate 		switch (nfcc) {
68*0Sstevel@tonic-gate 			case fcc_0:
69*0Sstevel@tonic-gate 				fcc = fsr.fcc0;
70*0Sstevel@tonic-gate 				break;
71*0Sstevel@tonic-gate 			case fcc_1:
72*0Sstevel@tonic-gate 				fcc = fsr.fcc1;
73*0Sstevel@tonic-gate 				break;
74*0Sstevel@tonic-gate 			case fcc_2:
75*0Sstevel@tonic-gate 				fcc = fsr.fcc2;
76*0Sstevel@tonic-gate 				break;
77*0Sstevel@tonic-gate 			case fcc_3:
78*0Sstevel@tonic-gate 				fcc = fsr.fcc3;
79*0Sstevel@tonic-gate 				break;
80*0Sstevel@tonic-gate 			}
81*0Sstevel@tonic-gate 	} else {
82*0Sstevel@tonic-gate 		fcc = fsr.fcc0;
83*0Sstevel@tonic-gate 	}
84*0Sstevel@tonic-gate 	icc = (enum icc_type) (pinst.rd & 0xf);
85*0Sstevel@tonic-gate 	annul = pinst.rd & 0x10;
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 	switch (icc) {
88*0Sstevel@tonic-gate 	case fbn:
89*0Sstevel@tonic-gate 		takeit = 0;
90*0Sstevel@tonic-gate 		break;
91*0Sstevel@tonic-gate 	case fbl:
92*0Sstevel@tonic-gate 		takeit = fcc == fcc_less;
93*0Sstevel@tonic-gate 		break;
94*0Sstevel@tonic-gate 	case fbg:
95*0Sstevel@tonic-gate 		takeit = fcc == fcc_greater;
96*0Sstevel@tonic-gate 		break;
97*0Sstevel@tonic-gate 	case fbu:
98*0Sstevel@tonic-gate 		takeit = fcc == fcc_unordered;
99*0Sstevel@tonic-gate 		break;
100*0Sstevel@tonic-gate 	case fbe:
101*0Sstevel@tonic-gate 		takeit = fcc == fcc_equal;
102*0Sstevel@tonic-gate 		break;
103*0Sstevel@tonic-gate 	case fblg:
104*0Sstevel@tonic-gate 		takeit = (fcc == fcc_less) || (fcc == fcc_greater);
105*0Sstevel@tonic-gate 		break;
106*0Sstevel@tonic-gate 	case fbul:
107*0Sstevel@tonic-gate 		takeit = (fcc == fcc_unordered) || (fcc == fcc_less);
108*0Sstevel@tonic-gate 		break;
109*0Sstevel@tonic-gate 	case fbug:
110*0Sstevel@tonic-gate 		takeit = (fcc == fcc_unordered) || (fcc == fcc_greater);
111*0Sstevel@tonic-gate 		break;
112*0Sstevel@tonic-gate 	case fbue:
113*0Sstevel@tonic-gate 		takeit = (fcc == fcc_unordered) || (fcc == fcc_equal);
114*0Sstevel@tonic-gate 		break;
115*0Sstevel@tonic-gate 	case fbge:
116*0Sstevel@tonic-gate 		takeit = (fcc == fcc_greater) || (fcc == fcc_equal);
117*0Sstevel@tonic-gate 		break;
118*0Sstevel@tonic-gate 	case fble:
119*0Sstevel@tonic-gate 		takeit = (fcc == fcc_less) || (fcc == fcc_equal);
120*0Sstevel@tonic-gate 		break;
121*0Sstevel@tonic-gate 	case fbne:
122*0Sstevel@tonic-gate 		takeit = fcc != fcc_equal;
123*0Sstevel@tonic-gate 		break;
124*0Sstevel@tonic-gate 	case fbuge:
125*0Sstevel@tonic-gate 		takeit = fcc != fcc_less;
126*0Sstevel@tonic-gate 		break;
127*0Sstevel@tonic-gate 	case fbule:
128*0Sstevel@tonic-gate 		takeit = fcc != fcc_greater;
129*0Sstevel@tonic-gate 		break;
130*0Sstevel@tonic-gate 	case fbo:
131*0Sstevel@tonic-gate 		takeit = fcc != fcc_unordered;
132*0Sstevel@tonic-gate 		break;
133*0Sstevel@tonic-gate 	case fba:
134*0Sstevel@tonic-gate 		takeit = 1;
135*0Sstevel@tonic-gate 		break;
136*0Sstevel@tonic-gate 	}
137*0Sstevel@tonic-gate 	if (takeit) {		/* Branch taken. */
138*0Sstevel@tonic-gate 		uintptr_t	tpc;
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate 		fp.fi = pinst;
141*0Sstevel@tonic-gate 		tpc = pregs->r_pc;
142*0Sstevel@tonic-gate 		if (annul && (icc == fba)) {	/* fba,a is wierd */
143*0Sstevel@tonic-gate 			if (fbpcc) {
144*0Sstevel@tonic-gate 				pregs->r_pc = tpc +
145*0Sstevel@tonic-gate 					(int)((fp.i << 13) >> 11);
146*0Sstevel@tonic-gate 			} else {
147*0Sstevel@tonic-gate 				pregs->r_pc = tpc +
148*0Sstevel@tonic-gate 					(int)((fp.i << 10) >> 8);
149*0Sstevel@tonic-gate 			}
150*0Sstevel@tonic-gate 			pregs->r_npc = pregs->r_pc + 4;
151*0Sstevel@tonic-gate 		} else {
152*0Sstevel@tonic-gate 			pregs->r_pc = pregs->r_npc;
153*0Sstevel@tonic-gate 			if (fbpcc) {
154*0Sstevel@tonic-gate 				pregs->r_npc = tpc +
155*0Sstevel@tonic-gate 					(int)((fp.i << 13) >> 11);
156*0Sstevel@tonic-gate 			} else {
157*0Sstevel@tonic-gate 				pregs->r_npc = tpc +
158*0Sstevel@tonic-gate 					(int)((fp.i << 10) >> 8);
159*0Sstevel@tonic-gate 			}
160*0Sstevel@tonic-gate 		}
161*0Sstevel@tonic-gate 	} else {		/* Branch not taken. */
162*0Sstevel@tonic-gate 		if (annul) {	/* Annul next instruction. */
163*0Sstevel@tonic-gate 			pregs->r_pc = pregs->r_npc + 4;
164*0Sstevel@tonic-gate 			pregs->r_npc += 8;
165*0Sstevel@tonic-gate 		} else {	/* Execute next instruction. */
166*0Sstevel@tonic-gate 			pregs->r_pc = pregs->r_npc;
167*0Sstevel@tonic-gate 			pregs->r_npc += 4;
168*0Sstevel@tonic-gate 		}
169*0Sstevel@tonic-gate 	}
170*0Sstevel@tonic-gate 	return (ftt_none);
171*0Sstevel@tonic-gate }
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate /* PUBLIC FUNCTIONS */
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate enum ftt_type
_fp_iu_simulator(fp_simd_type * pfpsd,fp_inst_type pinst,struct regs * pregs,void * prw,kfpu_t * pfpu)176*0Sstevel@tonic-gate _fp_iu_simulator(
177*0Sstevel@tonic-gate 	fp_simd_type	*pfpsd,	/* FPU simulator data. */
178*0Sstevel@tonic-gate 	fp_inst_type	pinst,	/* FPU instruction to simulate. */
179*0Sstevel@tonic-gate 	struct regs	*pregs,	/* Pointer to PCB image of registers. */
180*0Sstevel@tonic-gate 	void		*prw,	/* Pointer to locals and ins. */
181*0Sstevel@tonic-gate 	kfpu_t		*pfpu)	/* Pointer to FPU register block. */
182*0Sstevel@tonic-gate {
183*0Sstevel@tonic-gate 	switch (pinst.hibits) {
184*0Sstevel@tonic-gate 	case 0:				/* fbcc and V9 fbpcc */
185*0Sstevel@tonic-gate 		return (fbcc_sim(pinst, pregs, pfpu));
186*0Sstevel@tonic-gate 	case 2:
187*0Sstevel@tonic-gate 		switch (pinst.op3) {
188*0Sstevel@tonic-gate 		case 0x28:
189*0Sstevel@tonic-gate 			if (pinst.rs1 == 0x13)
190*0Sstevel@tonic-gate 				return (vis_rdgsr(pfpsd, pinst, pregs,
191*0Sstevel@tonic-gate 					prw, pfpu));
192*0Sstevel@tonic-gate 			else
193*0Sstevel@tonic-gate 				return (ftt_unimplemented);
194*0Sstevel@tonic-gate 		case 0x30:
195*0Sstevel@tonic-gate 			if (pinst.rd == 0x13)
196*0Sstevel@tonic-gate 				return (vis_wrgsr(pfpsd, pinst, pregs,
197*0Sstevel@tonic-gate 					prw, pfpu));
198*0Sstevel@tonic-gate 			else
199*0Sstevel@tonic-gate 				return (ftt_unimplemented);
200*0Sstevel@tonic-gate 		case 0x2C:
201*0Sstevel@tonic-gate 			return (movcc(pfpsd, pinst, pregs, prw, pfpu));
202*0Sstevel@tonic-gate 		default:
203*0Sstevel@tonic-gate 			return (ftt_unimplemented);
204*0Sstevel@tonic-gate 	}
205*0Sstevel@tonic-gate 	case 3:
206*0Sstevel@tonic-gate 		return (fldst(pfpsd, pinst, pregs, prw));
207*0Sstevel@tonic-gate 	default:
208*0Sstevel@tonic-gate 		return (ftt_unimplemented);
209*0Sstevel@tonic-gate 	}
210*0Sstevel@tonic-gate }
211