fpu_emu.c revision 1.3.6.2 1 1.3.6.2 thorpej /* $NetBSD: fpu_emu.c,v 1.3.6.2 2002/12/11 06:11:37 thorpej Exp $ */
2 1.3.6.2 thorpej
3 1.3.6.2 thorpej /*
4 1.3.6.2 thorpej * Copyright 2001 Wasabi Systems, Inc.
5 1.3.6.2 thorpej * All rights reserved.
6 1.3.6.2 thorpej *
7 1.3.6.2 thorpej * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 1.3.6.2 thorpej *
9 1.3.6.2 thorpej * Redistribution and use in source and binary forms, with or without
10 1.3.6.2 thorpej * modification, are permitted provided that the following conditions
11 1.3.6.2 thorpej * are met:
12 1.3.6.2 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.3.6.2 thorpej * notice, this list of conditions and the following disclaimer.
14 1.3.6.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.6.2 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.3.6.2 thorpej * documentation and/or other materials provided with the distribution.
17 1.3.6.2 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.3.6.2 thorpej * must display the following acknowledgement:
19 1.3.6.2 thorpej * This product includes software developed for the NetBSD Project by
20 1.3.6.2 thorpej * Wasabi Systems, Inc.
21 1.3.6.2 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.3.6.2 thorpej * or promote products derived from this software without specific prior
23 1.3.6.2 thorpej * written permission.
24 1.3.6.2 thorpej *
25 1.3.6.2 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.3.6.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.3.6.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.3.6.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.3.6.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.3.6.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.3.6.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.3.6.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.3.6.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.3.6.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.3.6.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.3.6.2 thorpej */
37 1.3.6.2 thorpej
38 1.3.6.2 thorpej /*
39 1.3.6.2 thorpej * Copyright (c) 1992, 1993
40 1.3.6.2 thorpej * The Regents of the University of California. All rights reserved.
41 1.3.6.2 thorpej *
42 1.3.6.2 thorpej * This software was developed by the Computer Systems Engineering group
43 1.3.6.2 thorpej * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
44 1.3.6.2 thorpej * contributed to Berkeley.
45 1.3.6.2 thorpej *
46 1.3.6.2 thorpej * All advertising materials mentioning features or use of this software
47 1.3.6.2 thorpej * must display the following acknowledgement:
48 1.3.6.2 thorpej * This product includes software developed by the University of
49 1.3.6.2 thorpej * California, Lawrence Berkeley Laboratory.
50 1.3.6.2 thorpej *
51 1.3.6.2 thorpej * Redistribution and use in source and binary forms, with or without
52 1.3.6.2 thorpej * modification, are permitted provided that the following conditions
53 1.3.6.2 thorpej * are met:
54 1.3.6.2 thorpej * 1. Redistributions of source code must retain the above copyright
55 1.3.6.2 thorpej * notice, this list of conditions and the following disclaimer.
56 1.3.6.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
57 1.3.6.2 thorpej * notice, this list of conditions and the following disclaimer in the
58 1.3.6.2 thorpej * documentation and/or other materials provided with the distribution.
59 1.3.6.2 thorpej * 3. All advertising materials mentioning features or use of this software
60 1.3.6.2 thorpej * must display the following acknowledgement:
61 1.3.6.2 thorpej * This product includes software developed by the University of
62 1.3.6.2 thorpej * California, Berkeley and its contributors.
63 1.3.6.2 thorpej * 4. Neither the name of the University nor the names of its contributors
64 1.3.6.2 thorpej * may be used to endorse or promote products derived from this software
65 1.3.6.2 thorpej * without specific prior written permission.
66 1.3.6.2 thorpej *
67 1.3.6.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
68 1.3.6.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 1.3.6.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70 1.3.6.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
71 1.3.6.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72 1.3.6.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73 1.3.6.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74 1.3.6.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75 1.3.6.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76 1.3.6.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77 1.3.6.2 thorpej * SUCH DAMAGE.
78 1.3.6.2 thorpej *
79 1.3.6.2 thorpej * @(#)fpu.c 8.1 (Berkeley) 6/11/93
80 1.3.6.2 thorpej */
81 1.3.6.2 thorpej
82 1.3.6.2 thorpej #include "opt_ddb.h"
83 1.3.6.2 thorpej
84 1.3.6.2 thorpej #include <sys/param.h>
85 1.3.6.2 thorpej #include <sys/proc.h>
86 1.3.6.2 thorpej #include <sys/signal.h>
87 1.3.6.2 thorpej #include <sys/systm.h>
88 1.3.6.2 thorpej #include <sys/syslog.h>
89 1.3.6.2 thorpej #include <sys/signalvar.h>
90 1.3.6.2 thorpej #include <sys/device.h> /* for evcnt */
91 1.3.6.2 thorpej
92 1.3.6.2 thorpej #include <powerpc/instr.h>
93 1.3.6.2 thorpej #include <machine/reg.h>
94 1.3.6.2 thorpej #include <machine/fpu.h>
95 1.3.6.2 thorpej
96 1.3.6.2 thorpej #include <powerpc/fpu/fpu_emu.h>
97 1.3.6.2 thorpej #include <powerpc/fpu/fpu_extern.h>
98 1.3.6.2 thorpej
99 1.3.6.2 thorpej #define FPU_EMU_EVCNT_DECL(name) \
100 1.3.6.2 thorpej static struct evcnt fpu_emu_ev_##name = \
101 1.3.6.2 thorpej EVCNT_INITIALIZER(EVCNT_TYPE_TRAP, NULL, "fpemu", #name); \
102 1.3.6.2 thorpej EVCNT_ATTACH_STATIC(fpu_emu_ev_##name)
103 1.3.6.2 thorpej
104 1.3.6.2 thorpej #define FPU_EMU_EVCNT_INCR(name) \
105 1.3.6.2 thorpej fpu_emu_ev_##name.ev_count++
106 1.3.6.2 thorpej
107 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(stfiwx);
108 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fpstore);
109 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fpload);
110 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fcmpu);
111 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(frsp);
112 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fctiw);
113 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fcmpo);
114 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(mtfsb1);
115 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fnegabs);
116 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(mcrfs);
117 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(mtfsb0);
118 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fmr);
119 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(mtfsfi);
120 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fnabs);
121 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fabs);
122 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(mffs);
123 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(mtfsf);
124 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fctid);
125 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fcfid);
126 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fdiv);
127 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fsub);
128 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fadd);
129 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fsqrt);
130 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fsel);
131 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fpres);
132 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fmul);
133 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(frsqrte);
134 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fmulsub);
135 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fmuladd);
136 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fnmsub);
137 1.3.6.2 thorpej FPU_EMU_EVCNT_DECL(fnmadd);
138 1.3.6.2 thorpej
139 1.3.6.2 thorpej /* FPSR exception masks */
140 1.3.6.2 thorpej #define FPSR_EX_MSK (FPSCR_VX|FPSCR_OX|FPSCR_UX|FPSCR_ZX| \
141 1.3.6.2 thorpej FPSCR_XX|FPSCR_VXSNAN|FPSCR_VXISI|FPSCR_VXIDI| \
142 1.3.6.2 thorpej FPSCR_VXZDZ|FPSCR_VXIMZ|FPSCR_VXVC|FPSCR_VXSOFT|\
143 1.3.6.2 thorpej FPSCR_VXSQRT|FPSCR_VXCVI)
144 1.3.6.2 thorpej #define FPSR_EX (FPSCR_VE|FPSCR_OE|FPSCR_UE|FPSCR_ZE|FPSCR_XE)
145 1.3.6.2 thorpej #define FPSR_EXOP (FPSR_EX_MSK&(~FPSR_EX))
146 1.3.6.2 thorpej
147 1.3.6.2 thorpej
148 1.3.6.2 thorpej int fpe_debug = 0;
149 1.3.6.2 thorpej
150 1.3.6.2 thorpej #ifdef DDB
151 1.3.6.2 thorpej extern vaddr_t opc_disasm(vaddr_t loc, int opcode);
152 1.3.6.2 thorpej #endif
153 1.3.6.2 thorpej
154 1.3.6.2 thorpej #ifdef DEBUG
155 1.3.6.2 thorpej /*
156 1.3.6.2 thorpej * Dump a `fpn' structure.
157 1.3.6.2 thorpej */
158 1.3.6.2 thorpej void
159 1.3.6.2 thorpej fpu_dumpfpn(struct fpn *fp)
160 1.3.6.2 thorpej {
161 1.3.6.2 thorpej static char *class[] = {
162 1.3.6.2 thorpej "SNAN", "QNAN", "ZERO", "NUM", "INF"
163 1.3.6.2 thorpej };
164 1.3.6.2 thorpej
165 1.3.6.2 thorpej printf("%s %c.%x %x %x %xE%d", class[fp->fp_class + 2],
166 1.3.6.2 thorpej fp->fp_sign ? '-' : ' ',
167 1.3.6.2 thorpej fp->fp_mant[0], fp->fp_mant[1],
168 1.3.6.2 thorpej fp->fp_mant[2], fp->fp_mant[3],
169 1.3.6.2 thorpej fp->fp_exp);
170 1.3.6.2 thorpej }
171 1.3.6.2 thorpej #endif
172 1.3.6.2 thorpej
173 1.3.6.2 thorpej /*
174 1.3.6.2 thorpej * fpu_execute returns the following error numbers (0 = no error):
175 1.3.6.2 thorpej */
176 1.3.6.2 thorpej #define FPE 1 /* take a floating point exception */
177 1.3.6.2 thorpej #define NOTFPU 2 /* not an FPU instruction */
178 1.3.6.2 thorpej #define FAULT 3
179 1.3.6.2 thorpej
180 1.3.6.2 thorpej
181 1.3.6.2 thorpej /*
182 1.3.6.2 thorpej * Emulate a floating-point instruction.
183 1.3.6.2 thorpej * Return zero for success, else signal number.
184 1.3.6.2 thorpej * (Typically: zero, SIGFPE, SIGILL, SIGSEGV)
185 1.3.6.2 thorpej */
186 1.3.6.2 thorpej int
187 1.3.6.2 thorpej fpu_emulate(struct trapframe *frame, struct fpreg *fpf)
188 1.3.6.2 thorpej {
189 1.3.6.2 thorpej static union instr insn;
190 1.3.6.2 thorpej static struct fpemu fe;
191 1.3.6.2 thorpej static int lastill = 0;
192 1.3.6.2 thorpej int sig;
193 1.3.6.2 thorpej
194 1.3.6.2 thorpej /* initialize insn.is_datasize to tell it is *not* initialized */
195 1.3.6.2 thorpej fe.fe_fpstate = fpf;
196 1.3.6.2 thorpej fe.fe_cx = 0;
197 1.3.6.2 thorpej
198 1.3.6.2 thorpej /* always set this (to avoid a warning) */
199 1.3.6.2 thorpej
200 1.3.6.2 thorpej if (copyin((void *) (frame->srr0), &insn.i_int, sizeof (insn.i_int))) {
201 1.3.6.2 thorpej #ifdef DEBUG
202 1.3.6.2 thorpej printf("fpu_emulate: fault reading opcode\n");
203 1.3.6.2 thorpej #endif
204 1.3.6.2 thorpej return SIGSEGV;
205 1.3.6.2 thorpej }
206 1.3.6.2 thorpej
207 1.3.6.2 thorpej DPRINTF(FPE_EX, ("fpu_emulate: emulating insn %x at %p\n",
208 1.3.6.2 thorpej insn.i_int, (void *)frame->srr0));
209 1.3.6.2 thorpej
210 1.3.6.2 thorpej
211 1.3.6.2 thorpej if ((insn.i_any.i_opcd == OPC_TWI) ||
212 1.3.6.2 thorpej ((insn.i_any.i_opcd == OPC_integer_31) &&
213 1.3.6.2 thorpej (insn.i_x.i_xo == OPC31_TW))) {
214 1.3.6.2 thorpej /* Check for the two trap insns. */
215 1.3.6.2 thorpej DPRINTF(FPE_EX, ("fpu_emulate: SIGTRAP\n"));
216 1.3.6.2 thorpej return (SIGTRAP);
217 1.3.6.2 thorpej }
218 1.3.6.2 thorpej sig = 0;
219 1.3.6.2 thorpej switch (fpu_execute(frame, &fe, &insn)) {
220 1.3.6.2 thorpej case 0:
221 1.3.6.2 thorpej DPRINTF(FPE_EX, ("fpu_emulate: success\n"));
222 1.3.6.2 thorpej frame->srr0 += 4;
223 1.3.6.2 thorpej break;
224 1.3.6.2 thorpej
225 1.3.6.2 thorpej case FPE:
226 1.3.6.2 thorpej DPRINTF(FPE_EX, ("fpu_emulate: SIGFPE\n"));
227 1.3.6.2 thorpej sig = SIGFPE;
228 1.3.6.2 thorpej break;
229 1.3.6.2 thorpej
230 1.3.6.2 thorpej case FAULT:
231 1.3.6.2 thorpej DPRINTF(FPE_EX, ("fpu_emulate: SIGSEGV\n"));
232 1.3.6.2 thorpej sig = SIGSEGV;
233 1.3.6.2 thorpej break;
234 1.3.6.2 thorpej
235 1.3.6.2 thorpej case NOTFPU:
236 1.3.6.2 thorpej default:
237 1.3.6.2 thorpej DPRINTF(FPE_EX, ("fpu_emulate: SIGILL\n"));
238 1.3.6.2 thorpej #ifdef DEBUG
239 1.3.6.2 thorpej if (fpe_debug & FPE_EX) {
240 1.3.6.2 thorpej printf("fpu_emulate: illegal insn %x at %p:",
241 1.3.6.2 thorpej insn.i_int, (void *) (frame->srr0));
242 1.3.6.2 thorpej opc_disasm((vaddr_t)(frame->srr0), insn.i_int);
243 1.3.6.2 thorpej }
244 1.3.6.2 thorpej #endif
245 1.3.6.2 thorpej /*
246 1.3.6.2 thorpej * XXXX retry an illegal insn once due to cache issues.
247 1.3.6.2 thorpej */
248 1.3.6.2 thorpej if (lastill == frame->srr0) {
249 1.3.6.2 thorpej sig = SIGILL;
250 1.3.6.2 thorpej #ifdef DEBUG
251 1.3.6.2 thorpej if (fpe_debug & FPE_EX)
252 1.3.6.2 thorpej Debugger();
253 1.3.6.2 thorpej #endif
254 1.3.6.2 thorpej }
255 1.3.6.2 thorpej lastill = frame->srr0;
256 1.3.6.2 thorpej break;
257 1.3.6.2 thorpej }
258 1.3.6.2 thorpej
259 1.3.6.2 thorpej return (sig);
260 1.3.6.2 thorpej }
261 1.3.6.2 thorpej
262 1.3.6.2 thorpej /*
263 1.3.6.2 thorpej * Execute an FPU instruction (one that runs entirely in the FPU; not
264 1.3.6.2 thorpej * FBfcc or STF, for instance). On return, fe->fe_fs->fs_fsr will be
265 1.3.6.2 thorpej * modified to reflect the setting the hardware would have left.
266 1.3.6.2 thorpej *
267 1.3.6.2 thorpej * Note that we do not catch all illegal opcodes, so you can, for instance,
268 1.3.6.2 thorpej * multiply two integers this way.
269 1.3.6.2 thorpej */
270 1.3.6.2 thorpej int
271 1.3.6.2 thorpej fpu_execute(struct trapframe *tf, struct fpemu *fe, union instr *insn)
272 1.3.6.2 thorpej {
273 1.3.6.2 thorpej struct fpn *fp;
274 1.3.6.2 thorpej union instr instr = *insn;
275 1.3.6.2 thorpej int *a;
276 1.3.6.2 thorpej vaddr_t addr;
277 1.3.6.2 thorpej int ra, rb, rc, rt, type, mask, fsr, cx, bf, setcr, cond;
278 1.3.6.2 thorpej struct fpreg *fs;
279 1.3.6.2 thorpej
280 1.3.6.2 thorpej /* Setup work. */
281 1.3.6.2 thorpej fp = NULL;
282 1.3.6.2 thorpej fs = fe->fe_fpstate;
283 1.3.6.2 thorpej fe->fe_fpscr = ((int *)&fs->fpscr)[1];
284 1.3.6.2 thorpej
285 1.3.6.2 thorpej /*
286 1.3.6.2 thorpej * On PowerPC all floating point values are stored in registers
287 1.3.6.2 thorpej * as doubles, even when used for single precision operations.
288 1.3.6.2 thorpej */
289 1.3.6.2 thorpej type = FTYPE_DBL;
290 1.3.6.2 thorpej cond = instr.i_any.i_rc;
291 1.3.6.2 thorpej setcr = 0;
292 1.3.6.2 thorpej
293 1.3.6.2 thorpej #if defined(DDB) && defined(DEBUG)
294 1.3.6.2 thorpej if (fpe_debug & FPE_EX) {
295 1.3.6.2 thorpej vaddr_t loc = tf->srr0;
296 1.3.6.2 thorpej
297 1.3.6.2 thorpej printf("Trying to emulate: %p ", (void *)loc);
298 1.3.6.2 thorpej opc_disasm(loc, instr.i_int);
299 1.3.6.2 thorpej }
300 1.3.6.2 thorpej #endif
301 1.3.6.2 thorpej
302 1.3.6.2 thorpej /*
303 1.3.6.2 thorpej * `Decode' and execute instruction.
304 1.3.6.2 thorpej */
305 1.3.6.2 thorpej
306 1.3.6.2 thorpej if ((instr.i_any.i_opcd >= OPC_LFS && instr.i_any.i_opcd <= OPC_STFDU) ||
307 1.3.6.2 thorpej instr.i_any.i_opcd == OPC_integer_31) {
308 1.3.6.2 thorpej /*
309 1.3.6.2 thorpej * Handle load/store insns:
310 1.3.6.2 thorpej *
311 1.3.6.2 thorpej * Convert to/from single if needed, calculate addr,
312 1.3.6.2 thorpej * and update index reg if needed.
313 1.3.6.2 thorpej */
314 1.3.6.2 thorpej double buf;
315 1.3.6.2 thorpej size_t size = sizeof(float);
316 1.3.6.2 thorpej int store, update;
317 1.3.6.2 thorpej
318 1.3.6.2 thorpej cond = 0; /* ld/st never set condition codes */
319 1.3.6.2 thorpej
320 1.3.6.2 thorpej
321 1.3.6.2 thorpej if (instr.i_any.i_opcd == OPC_integer_31) {
322 1.3.6.2 thorpej if (instr.i_x.i_xo == OPC31_STFIWX) {
323 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(stfiwx);
324 1.3.6.2 thorpej
325 1.3.6.2 thorpej /* Store as integer */
326 1.3.6.2 thorpej ra = instr.i_x.i_ra;
327 1.3.6.2 thorpej rb = instr.i_x.i_rb;
328 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("reg %d has %x reg %d has %x\n",
329 1.3.6.2 thorpej ra, tf->fixreg[ra], rb, tf->fixreg[rb]));
330 1.3.6.2 thorpej
331 1.3.6.2 thorpej addr = tf->fixreg[rb];
332 1.3.6.2 thorpej if (ra != 0)
333 1.3.6.2 thorpej addr += tf->fixreg[ra];
334 1.3.6.2 thorpej rt = instr.i_x.i_rt;
335 1.3.6.2 thorpej a = (int *)&fs->fpreg[rt];
336 1.3.6.2 thorpej DPRINTF(FPE_INSN,
337 1.3.6.2 thorpej ("fpu_execute: Store INT %x at %p\n",
338 1.3.6.2 thorpej a[1], (void *)addr));
339 1.3.6.2 thorpej if (copyout(&a[1], (void *)addr, sizeof(int)))
340 1.3.6.2 thorpej return (FAULT);
341 1.3.6.2 thorpej return (0);
342 1.3.6.2 thorpej }
343 1.3.6.2 thorpej
344 1.3.6.2 thorpej if ((instr.i_x.i_xo & OPC31_FPMASK) != OPC31_FPOP)
345 1.3.6.2 thorpej /* Not an indexed FP load/store op */
346 1.3.6.2 thorpej return (NOTFPU);
347 1.3.6.2 thorpej
348 1.3.6.2 thorpej store = (instr.i_x.i_xo & 0x80);
349 1.3.6.2 thorpej if (instr.i_x.i_xo & 0x40)
350 1.3.6.2 thorpej size = sizeof(double);
351 1.3.6.2 thorpej else
352 1.3.6.2 thorpej type = FTYPE_SNG;
353 1.3.6.2 thorpej update = (instr.i_x.i_xo & 0x20);
354 1.3.6.2 thorpej
355 1.3.6.2 thorpej /* calculate EA of load/store */
356 1.3.6.2 thorpej ra = instr.i_x.i_ra;
357 1.3.6.2 thorpej rb = instr.i_x.i_rb;
358 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("reg %d has %x reg %d has %x\n",
359 1.3.6.2 thorpej ra, tf->fixreg[ra], rb, tf->fixreg[rb]));
360 1.3.6.2 thorpej addr = tf->fixreg[rb];
361 1.3.6.2 thorpej if (ra != 0)
362 1.3.6.2 thorpej addr += tf->fixreg[ra];
363 1.3.6.2 thorpej rt = instr.i_x.i_rt;
364 1.3.6.2 thorpej } else {
365 1.3.6.2 thorpej store = instr.i_d.i_opcd & 0x4;
366 1.3.6.2 thorpej if (instr.i_d.i_opcd & 0x2)
367 1.3.6.2 thorpej size = sizeof(double);
368 1.3.6.2 thorpej else
369 1.3.6.2 thorpej type = FTYPE_SNG;
370 1.3.6.2 thorpej update = instr.i_d.i_opcd & 0x1;
371 1.3.6.2 thorpej
372 1.3.6.2 thorpej /* calculate EA of load/store */
373 1.3.6.2 thorpej ra = instr.i_d.i_ra;
374 1.3.6.2 thorpej addr = instr.i_d.i_d;
375 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("reg %d has %x displ %lx\n",
376 1.3.6.2 thorpej ra, tf->fixreg[ra], addr));
377 1.3.6.2 thorpej if (ra != 0)
378 1.3.6.2 thorpej addr += tf->fixreg[ra];
379 1.3.6.2 thorpej rt = instr.i_d.i_rt;
380 1.3.6.2 thorpej }
381 1.3.6.2 thorpej
382 1.3.6.2 thorpej if (update && ra == 0)
383 1.3.6.2 thorpej return (NOTFPU);
384 1.3.6.2 thorpej
385 1.3.6.2 thorpej if (store) {
386 1.3.6.2 thorpej /* Store */
387 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fpstore);
388 1.3.6.2 thorpej if (type != FTYPE_DBL) {
389 1.3.6.2 thorpej DPRINTF(FPE_INSN,
390 1.3.6.2 thorpej ("fpu_execute: Store SNG at %p\n",
391 1.3.6.2 thorpej (void *)addr));
392 1.3.6.2 thorpej fpu_explode(fe, fp = &fe->fe_f1, FTYPE_DBL, rt);
393 1.3.6.2 thorpej fpu_implode(fe, fp, type, (void *)&buf);
394 1.3.6.2 thorpej if (copyout(&buf, (void *)addr, size))
395 1.3.6.2 thorpej return (FAULT);
396 1.3.6.2 thorpej } else {
397 1.3.6.2 thorpej DPRINTF(FPE_INSN,
398 1.3.6.2 thorpej ("fpu_execute: Store DBL at %p\n",
399 1.3.6.2 thorpej (void *)addr));
400 1.3.6.2 thorpej if (copyout(&fs->fpreg[rt], (void *)addr, size))
401 1.3.6.2 thorpej return (FAULT);
402 1.3.6.2 thorpej }
403 1.3.6.2 thorpej } else {
404 1.3.6.2 thorpej /* Load */
405 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fpload);
406 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: Load from %p\n",
407 1.3.6.2 thorpej (void *)addr));
408 1.3.6.2 thorpej if (copyin((const void *)addr, &fs->fpreg[rt], size))
409 1.3.6.2 thorpej return (FAULT);
410 1.3.6.2 thorpej if (type != FTYPE_DBL) {
411 1.3.6.2 thorpej fpu_explode(fe, fp = &fe->fe_f1, type, rt);
412 1.3.6.2 thorpej fpu_implode(fe, fp, FTYPE_DBL,
413 1.3.6.2 thorpej (u_int *)&fs->fpreg[rt]);
414 1.3.6.2 thorpej }
415 1.3.6.2 thorpej }
416 1.3.6.2 thorpej if (update)
417 1.3.6.2 thorpej tf->fixreg[ra] = addr;
418 1.3.6.2 thorpej /* Complete. */
419 1.3.6.2 thorpej return (0);
420 1.3.6.2 thorpej #ifdef notyet
421 1.3.6.2 thorpej } else if (instr.i_any.i_opcd == OPC_load_st_62) {
422 1.3.6.2 thorpej /* These are 64-bit extenstions */
423 1.3.6.2 thorpej return (NOTFPU);
424 1.3.6.2 thorpej #endif
425 1.3.6.2 thorpej } else if (instr.i_any.i_opcd == OPC_sp_fp_59 ||
426 1.3.6.2 thorpej instr.i_any.i_opcd == OPC_dp_fp_63) {
427 1.3.6.2 thorpej
428 1.3.6.2 thorpej
429 1.3.6.2 thorpej if (instr.i_any.i_opcd == OPC_dp_fp_63 &&
430 1.3.6.2 thorpej !(instr.i_a.i_xo & OPC63M_MASK)) {
431 1.3.6.2 thorpej /* Format X */
432 1.3.6.2 thorpej rt = instr.i_x.i_rt;
433 1.3.6.2 thorpej ra = instr.i_x.i_ra;
434 1.3.6.2 thorpej rb = instr.i_x.i_rb;
435 1.3.6.2 thorpej
436 1.3.6.2 thorpej
437 1.3.6.2 thorpej /* One of the special opcodes.... */
438 1.3.6.2 thorpej switch (instr.i_x.i_xo) {
439 1.3.6.2 thorpej case OPC63_FCMPU:
440 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fcmpu);
441 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FCMPU\n"));
442 1.3.6.2 thorpej rt >>= 2;
443 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
444 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
445 1.3.6.2 thorpej fpu_compare(fe, 0);
446 1.3.6.2 thorpej /* Make sure we do the condition regs. */
447 1.3.6.2 thorpej cond = 0;
448 1.3.6.2 thorpej /* N.B.: i_rs is already left shifted by two. */
449 1.3.6.2 thorpej bf = instr.i_x.i_rs & 0xfc;
450 1.3.6.2 thorpej setcr = 1;
451 1.3.6.2 thorpej break;
452 1.3.6.2 thorpej
453 1.3.6.2 thorpej case OPC63_FRSP:
454 1.3.6.2 thorpej /*
455 1.3.6.2 thorpej * Convert to single:
456 1.3.6.2 thorpej *
457 1.3.6.2 thorpej * PowerPC uses this to round a double
458 1.3.6.2 thorpej * precision value to single precision,
459 1.3.6.2 thorpej * but values in registers are always
460 1.3.6.2 thorpej * stored in double precision format.
461 1.3.6.2 thorpej */
462 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(frsp);
463 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FRSP\n"));
464 1.3.6.2 thorpej fpu_explode(fe, fp = &fe->fe_f1, FTYPE_DBL, rb);
465 1.3.6.2 thorpej fpu_implode(fe, fp, FTYPE_SNG,
466 1.3.6.2 thorpej (u_int *)&fs->fpreg[rt]);
467 1.3.6.2 thorpej fpu_explode(fe, fp = &fe->fe_f1, FTYPE_SNG, rt);
468 1.3.6.2 thorpej type = FTYPE_DBL;
469 1.3.6.2 thorpej break;
470 1.3.6.2 thorpej case OPC63_FCTIW:
471 1.3.6.2 thorpej case OPC63_FCTIWZ:
472 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fctiw);
473 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FCTIW\n"));
474 1.3.6.2 thorpej fpu_explode(fe, fp = &fe->fe_f1, type, rb);
475 1.3.6.2 thorpej type = FTYPE_INT;
476 1.3.6.2 thorpej break;
477 1.3.6.2 thorpej case OPC63_FCMPO:
478 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fcmpo);
479 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FCMPO\n"));
480 1.3.6.2 thorpej rt >>= 2;
481 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
482 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
483 1.3.6.2 thorpej fpu_compare(fe, 1);
484 1.3.6.2 thorpej /* Make sure we do the condition regs. */
485 1.3.6.2 thorpej cond = 0;
486 1.3.6.2 thorpej /* N.B.: i_rs is already left shifted by two. */
487 1.3.6.2 thorpej bf = instr.i_x.i_rs & 0xfc;
488 1.3.6.2 thorpej setcr = 1;
489 1.3.6.2 thorpej break;
490 1.3.6.2 thorpej case OPC63_MTFSB1:
491 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(mtfsb1);
492 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: MTFSB1\n"));
493 1.3.6.2 thorpej fe->fe_fpscr |=
494 1.3.6.2 thorpej (~(FPSCR_VX|FPSR_EX) & (1<<(31-rt)));
495 1.3.6.2 thorpej break;
496 1.3.6.2 thorpej case OPC63_FNEG:
497 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fnegabs);
498 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FNEGABS\n"));
499 1.3.6.2 thorpej memcpy(&fs->fpreg[rt], &fs->fpreg[rb],
500 1.3.6.2 thorpej sizeof(double));
501 1.3.6.2 thorpej a = (int *)&fs->fpreg[rt];
502 1.3.6.2 thorpej *a ^= (1 << 31);
503 1.3.6.2 thorpej break;
504 1.3.6.2 thorpej case OPC63_MCRFS:
505 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(mcrfs);
506 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: MCRFS\n"));
507 1.3.6.2 thorpej cond = 0;
508 1.3.6.2 thorpej rt &= 0x1c;
509 1.3.6.2 thorpej ra &= 0x1c;
510 1.3.6.2 thorpej /* Extract the bits we want */
511 1.3.6.2 thorpej mask = (fe->fe_fpscr >> (28 - ra)) & 0xf;
512 1.3.6.2 thorpej /* Clear the bits we copied. */
513 1.3.6.2 thorpej fe->fe_cx =
514 1.3.6.2 thorpej (FPSR_EX_MSK | (0xf << (28 - ra)));
515 1.3.6.2 thorpej fe->fe_fpscr &= fe->fe_cx;
516 1.3.6.2 thorpej /* Now shove them in the right part of cr */
517 1.3.6.2 thorpej tf->cr &= ~(0xf << (28 - rt));
518 1.3.6.2 thorpej tf->cr |= (mask << (28 - rt));
519 1.3.6.2 thorpej break;
520 1.3.6.2 thorpej case OPC63_MTFSB0:
521 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(mtfsb0);
522 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: MTFSB0\n"));
523 1.3.6.2 thorpej fe->fe_fpscr &=
524 1.3.6.2 thorpej ((FPSCR_VX|FPSR_EX) & ~(1<<(31-rt)));
525 1.3.6.2 thorpej break;
526 1.3.6.2 thorpej case OPC63_FMR:
527 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fmr);
528 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FMR\n"));
529 1.3.6.2 thorpej memcpy(&fs->fpreg[rt], &fs->fpreg[rb],
530 1.3.6.2 thorpej sizeof(double));
531 1.3.6.2 thorpej break;
532 1.3.6.2 thorpej case OPC63_MTFSFI:
533 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(mtfsfi);
534 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: MTFSFI\n"));
535 1.3.6.2 thorpej rb >>= 1;
536 1.3.6.2 thorpej rt &= 0x1c; /* Already left-shifted 4 */
537 1.3.6.2 thorpej fe->fe_cx = rb << (28 - rt);
538 1.3.6.2 thorpej mask = 0xf<<(28 - rt);
539 1.3.6.2 thorpej fe->fe_fpscr = (fe->fe_fpscr & ~mask) |
540 1.3.6.2 thorpej fe->fe_cx;
541 1.3.6.2 thorpej /* XXX weird stuff about OX, FX, FEX, and VX should be handled */
542 1.3.6.2 thorpej break;
543 1.3.6.2 thorpej case OPC63_FNABS:
544 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fnabs);
545 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FABS\n"));
546 1.3.6.2 thorpej memcpy(&fs->fpreg[rt], &fs->fpreg[rb],
547 1.3.6.2 thorpej sizeof(double));
548 1.3.6.2 thorpej a = (int *)&fs->fpreg[rt];
549 1.3.6.2 thorpej *a |= (1 << 31);
550 1.3.6.2 thorpej break;
551 1.3.6.2 thorpej case OPC63_FABS:
552 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fabs);
553 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FABS\n"));
554 1.3.6.2 thorpej memcpy(&fs->fpreg[rt], &fs->fpreg[rb],
555 1.3.6.2 thorpej sizeof(double));
556 1.3.6.2 thorpej a = (int *)&fs->fpreg[rt];
557 1.3.6.2 thorpej *a &= ~(1 << 31);
558 1.3.6.2 thorpej break;
559 1.3.6.2 thorpej case OPC63_MFFS:
560 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(mffs);
561 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: MFFS\n"));
562 1.3.6.2 thorpej memcpy(&fs->fpreg[rt], &fs->fpscr,
563 1.3.6.2 thorpej sizeof(fs->fpscr));
564 1.3.6.2 thorpej break;
565 1.3.6.2 thorpej case OPC63_MTFSF:
566 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(mtfsf);
567 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: MTFSF\n"));
568 1.3.6.2 thorpej if ((rt = instr.i_xfl.i_flm) == -1)
569 1.3.6.2 thorpej mask = -1;
570 1.3.6.2 thorpej else {
571 1.3.6.2 thorpej mask = 0;
572 1.3.6.2 thorpej /* Convert 1 bit -> 4 bits */
573 1.3.6.2 thorpej for (ra = 0; ra < 8; ra ++)
574 1.3.6.2 thorpej if (rt & (1<<ra))
575 1.3.6.2 thorpej mask |= (0xf<<(4*ra));
576 1.3.6.2 thorpej }
577 1.3.6.2 thorpej a = (int *)&fs->fpreg[rt];
578 1.3.6.2 thorpej fe->fe_cx = mask & a[1];
579 1.3.6.2 thorpej fe->fe_fpscr = (fe->fe_fpscr&~mask) |
580 1.3.6.2 thorpej (fe->fe_cx);
581 1.3.6.2 thorpej /* XXX weird stuff about OX, FX, FEX, and VX should be handled */
582 1.3.6.2 thorpej break;
583 1.3.6.2 thorpej case OPC63_FCTID:
584 1.3.6.2 thorpej case OPC63_FCTIDZ:
585 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fctid);
586 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FCTID\n"));
587 1.3.6.2 thorpej fpu_explode(fe, fp = &fe->fe_f1, type, rb);
588 1.3.6.2 thorpej type = FTYPE_LNG;
589 1.3.6.2 thorpej break;
590 1.3.6.2 thorpej case OPC63_FCFID:
591 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fcfid);
592 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FCFID\n"));
593 1.3.6.2 thorpej type = FTYPE_LNG;
594 1.3.6.2 thorpej fpu_explode(fe, fp = &fe->fe_f1, type, rb);
595 1.3.6.2 thorpej type = FTYPE_DBL;
596 1.3.6.2 thorpej break;
597 1.3.6.2 thorpej default:
598 1.3.6.2 thorpej return (NOTFPU);
599 1.3.6.2 thorpej break;
600 1.3.6.2 thorpej }
601 1.3.6.2 thorpej } else {
602 1.3.6.2 thorpej /* Format A */
603 1.3.6.2 thorpej rt = instr.i_a.i_frt;
604 1.3.6.2 thorpej ra = instr.i_a.i_fra;
605 1.3.6.2 thorpej rb = instr.i_a.i_frb;
606 1.3.6.2 thorpej rc = instr.i_a.i_frc;
607 1.3.6.2 thorpej
608 1.3.6.2 thorpej type = FTYPE_SNG;
609 1.3.6.2 thorpej if (instr.i_any.i_opcd & 0x4)
610 1.3.6.2 thorpej type = FTYPE_DBL;
611 1.3.6.2 thorpej switch ((unsigned int)instr.i_a.i_xo) {
612 1.3.6.2 thorpej case OPC59_FDIVS:
613 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fdiv);
614 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FDIV\n"));
615 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
616 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
617 1.3.6.2 thorpej fp = fpu_div(fe);
618 1.3.6.2 thorpej break;
619 1.3.6.2 thorpej case OPC59_FSUBS:
620 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fsub);
621 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FSUB\n"));
622 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
623 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
624 1.3.6.2 thorpej fp = fpu_sub(fe);
625 1.3.6.2 thorpej break;
626 1.3.6.2 thorpej case OPC59_FADDS:
627 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fadd);
628 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FADD\n"));
629 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
630 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
631 1.3.6.2 thorpej fp = fpu_add(fe);
632 1.3.6.2 thorpej break;
633 1.3.6.2 thorpej case OPC59_FSQRTS:
634 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fsqrt);
635 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FSQRT\n"));
636 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, rb);
637 1.3.6.2 thorpej fp = fpu_sqrt(fe);
638 1.3.6.2 thorpej break;
639 1.3.6.2 thorpej case OPC63M_FSEL:
640 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fsel);
641 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FSEL\n"));
642 1.3.6.2 thorpej a = (int *)&fe->fe_fpstate->fpreg[ra];
643 1.3.6.2 thorpej if ((*a & 0x80000000) && (*a & 0x7fffffff))
644 1.3.6.2 thorpej /* fra < 0 */
645 1.3.6.2 thorpej rc = rb;
646 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("f%d => f%d\n", rc, rt));
647 1.3.6.2 thorpej memcpy(&fs->fpreg[rt], &fs->fpreg[rc],
648 1.3.6.2 thorpej sizeof(double));
649 1.3.6.2 thorpej break;
650 1.3.6.2 thorpej case OPC59_FRES:
651 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fpres);
652 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FPRES\n"));
653 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, rb);
654 1.3.6.2 thorpej fp = fpu_sqrt(fe);
655 1.3.6.2 thorpej /* now we've gotta overwrite the dest reg */
656 1.3.6.2 thorpej *((int *)&fe->fe_fpstate->fpreg[rt]) = 1;
657 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, FTYPE_INT, rt);
658 1.3.6.2 thorpej fpu_div(fe);
659 1.3.6.2 thorpej break;
660 1.3.6.2 thorpej case OPC59_FMULS:
661 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fmul);
662 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FMUL\n"));
663 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
664 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rc);
665 1.3.6.2 thorpej fp = fpu_mul(fe);
666 1.3.6.2 thorpej break;
667 1.3.6.2 thorpej case OPC63M_FRSQRTE:
668 1.3.6.2 thorpej /* Reciprocal sqrt() estimate */
669 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(frsqrte);
670 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FRSQRTE\n"));
671 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, rb);
672 1.3.6.2 thorpej fe->fe_f2 = *fp;
673 1.3.6.2 thorpej /* now we've gotta overwrite the dest reg */
674 1.3.6.2 thorpej *((int *)&fe->fe_fpstate->fpreg[rt]) = 1;
675 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, FTYPE_INT, rt);
676 1.3.6.2 thorpej fpu_div(fe);
677 1.3.6.2 thorpej break;
678 1.3.6.2 thorpej case OPC59_FMSUBS:
679 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fmulsub);
680 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FMULSUB\n"));
681 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
682 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rc);
683 1.3.6.2 thorpej fp = fpu_mul(fe);
684 1.3.6.2 thorpej fe->fe_f1 = *fp;
685 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
686 1.3.6.2 thorpej fp = fpu_sub(fe);
687 1.3.6.2 thorpej break;
688 1.3.6.2 thorpej case OPC59_FMADDS:
689 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fmuladd);
690 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FMULADD\n"));
691 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
692 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rc);
693 1.3.6.2 thorpej fp = fpu_mul(fe);
694 1.3.6.2 thorpej fe->fe_f1 = *fp;
695 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
696 1.3.6.2 thorpej fp = fpu_add(fe);
697 1.3.6.2 thorpej break;
698 1.3.6.2 thorpej case OPC59_FNMSUBS:
699 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fnmsub);
700 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FNMSUB\n"));
701 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
702 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rc);
703 1.3.6.2 thorpej fp = fpu_mul(fe);
704 1.3.6.2 thorpej fe->fe_f1 = *fp;
705 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
706 1.3.6.2 thorpej fp = fpu_sub(fe);
707 1.3.6.2 thorpej /* Negate */
708 1.3.6.2 thorpej fp->fp_sign ^= 1;
709 1.3.6.2 thorpej break;
710 1.3.6.2 thorpej case OPC59_FNMADDS:
711 1.3.6.2 thorpej FPU_EMU_EVCNT_INCR(fnmadd);
712 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: FNMADD\n"));
713 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f1, type, ra);
714 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rc);
715 1.3.6.2 thorpej fp = fpu_mul(fe);
716 1.3.6.2 thorpej fe->fe_f1 = *fp;
717 1.3.6.2 thorpej fpu_explode(fe, &fe->fe_f2, type, rb);
718 1.3.6.2 thorpej fp = fpu_add(fe);
719 1.3.6.2 thorpej /* Negate */
720 1.3.6.2 thorpej fp->fp_sign ^= 1;
721 1.3.6.2 thorpej break;
722 1.3.6.2 thorpej default:
723 1.3.6.2 thorpej return (NOTFPU);
724 1.3.6.2 thorpej break;
725 1.3.6.2 thorpej }
726 1.3.6.2 thorpej }
727 1.3.6.2 thorpej } else {
728 1.3.6.2 thorpej return (NOTFPU);
729 1.3.6.2 thorpej }
730 1.3.6.2 thorpej
731 1.3.6.2 thorpej /*
732 1.3.6.2 thorpej * ALU operation is complete. Collapse the result and then check
733 1.3.6.2 thorpej * for exceptions. If we got any, and they are enabled, do not
734 1.3.6.2 thorpej * alter the destination register, just stop with an exception.
735 1.3.6.2 thorpej * Otherwise set new current exceptions and accrue.
736 1.3.6.2 thorpej */
737 1.3.6.2 thorpej if (fp)
738 1.3.6.2 thorpej fpu_implode(fe, fp, type, (u_int *)&fs->fpreg[rt]);
739 1.3.6.2 thorpej cx = fe->fe_cx;
740 1.3.6.2 thorpej fsr = fe->fe_fpscr;
741 1.3.6.2 thorpej if (cx != 0) {
742 1.3.6.2 thorpej fsr &= ~FPSCR_FX;
743 1.3.6.2 thorpej if ((cx^fsr)&FPSR_EX_MSK)
744 1.3.6.2 thorpej fsr |= FPSCR_FX;
745 1.3.6.2 thorpej mask = fsr & FPSR_EX;
746 1.3.6.2 thorpej mask <<= (25-3);
747 1.3.6.2 thorpej if (cx & mask)
748 1.3.6.2 thorpej fsr |= FPSCR_FEX;
749 1.3.6.2 thorpej if (cx & FPSCR_FPRF) {
750 1.3.6.2 thorpej /* Need to replace CC */
751 1.3.6.2 thorpej fsr &= ~FPSCR_FPRF;
752 1.3.6.2 thorpej }
753 1.3.6.2 thorpej if (cx & (FPSR_EXOP))
754 1.3.6.2 thorpej fsr |= FPSCR_VX;
755 1.3.6.2 thorpej fsr |= cx;
756 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: cx %x, fsr %x\n", cx, fsr));
757 1.3.6.2 thorpej }
758 1.3.6.2 thorpej
759 1.3.6.2 thorpej if (cond) {
760 1.3.6.2 thorpej cond = fsr & 0xf0000000;
761 1.3.6.2 thorpej /* Isolate condition codes */
762 1.3.6.2 thorpej cond >>= 28;
763 1.3.6.2 thorpej /* Move fpu condition codes to cr[1] */
764 1.3.6.2 thorpej tf->cr &= (0x0f000000);
765 1.3.6.2 thorpej tf->cr |= (cond<<24);
766 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: cr[1] <= %x\n", cond));
767 1.3.6.2 thorpej }
768 1.3.6.2 thorpej
769 1.3.6.2 thorpej if (setcr) {
770 1.3.6.2 thorpej cond = fsr & FPSCR_FPCC;
771 1.3.6.2 thorpej /* Isolate condition codes */
772 1.3.6.2 thorpej cond <<= 16;
773 1.3.6.2 thorpej /* Move fpu condition codes to cr[1] */
774 1.3.6.2 thorpej tf->cr &= ~(0xf0000000>>bf);
775 1.3.6.2 thorpej tf->cr |= (cond>>bf);
776 1.3.6.2 thorpej DPRINTF(FPE_INSN, ("fpu_execute: cr[%d] (cr=%x) <= %x\n", bf/4, tf->cr, cond));
777 1.3.6.2 thorpej }
778 1.3.6.2 thorpej
779 1.3.6.2 thorpej ((int *)&fs->fpscr)[1] = fsr;
780 1.3.6.2 thorpej if (fsr & FPSCR_FEX)
781 1.3.6.2 thorpej return(FPE);
782 1.3.6.2 thorpej return (0); /* success */
783 1.3.6.2 thorpej }
784