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