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