fpu.c revision 1.20 1 /* $NetBSD: fpu.c,v 1.20 2003/08/07 16:29:36 agc Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)fpu.c 8.1 (Berkeley) 6/11/93
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.20 2003/08/07 16:29:36 agc Exp $");
45
46 #include <sys/param.h>
47 #include <sys/proc.h>
48 #include <sys/signal.h>
49 #include <sys/systm.h>
50 #include <sys/syslog.h>
51 #include <sys/signalvar.h>
52
53 #include <machine/instr.h>
54 #include <machine/reg.h>
55
56 #include <sparc/fpu/fpu_emu.h>
57 #include <sparc/fpu/fpu_extern.h>
58
59 int fpe_debug = 0;
60
61 #ifdef DEBUG
62 /*
63 * Dump a `fpn' structure.
64 */
65 void
66 fpu_dumpfpn(struct fpn *fp)
67 {
68 static char *class[] = {
69 "SNAN", "QNAN", "ZERO", "NUM", "INF"
70 };
71
72 printf("%s %c.%x %x %x %xE%d", class[fp->fp_class + 2],
73 fp->fp_sign ? '-' : ' ',
74 fp->fp_mant[0], fp->fp_mant[1],
75 fp->fp_mant[2], fp->fp_mant[3],
76 fp->fp_exp);
77 }
78 #endif
79
80 /*
81 * fpu_execute returns the following error numbers (0 = no error):
82 */
83 #define FPE 1 /* take a floating point exception */
84 #define NOTFPU 2 /* not an FPU instruction */
85
86 /*
87 * Translate current exceptions into `first' exception. The
88 * bits go the wrong way for ffs() (0x10 is most important, etc).
89 * There are only 5, so do it the obvious way.
90 */
91 #define X1(x) x
92 #define X2(x) x,x
93 #define X4(x) x,x,x,x
94 #define X8(x) X4(x),X4(x)
95 #define X16(x) X8(x),X8(x)
96
97 static char cx_to_trapx[] = {
98 X1(FSR_NX),
99 X2(FSR_DZ),
100 X4(FSR_UF),
101 X8(FSR_OF),
102 X16(FSR_NV)
103 };
104 static u_char fpu_codes[] = {
105 X1(FPE_FLTINEX_TRAP),
106 X2(FPE_FLTDIV_TRAP),
107 X4(FPE_FLTUND_TRAP),
108 X8(FPE_FLTOVF_TRAP),
109 X16(FPE_FLTOPERR_TRAP)
110 };
111
112 /*
113 * The FPU gave us an exception. Clean up the mess. Note that the
114 * fp queue can only have FPops in it, never load/store FP registers
115 * nor FBfcc instructions. Experiments with `crashme' prove that
116 * unknown FPops do enter the queue, however.
117 */
118 void
119 fpu_cleanup(l, fs)
120 register struct lwp *l;
121 #ifndef SUN4U
122 register struct fpstate *fs;
123 #else /* SUN4U */
124 register struct fpstate64 *fs;
125 #endif /* SUN4U */
126 {
127 register int i, fsr = fs->fs_fsr, error;
128 struct proc *p = l->l_proc;
129 union instr instr;
130 struct fpemu fe;
131
132 switch ((fsr >> FSR_FTT_SHIFT) & FSR_FTT_MASK) {
133
134 case FSR_TT_NONE:
135 panic("fpu_cleanup: No fault"); /* ??? */
136 break;
137
138 case FSR_TT_IEEE:
139 DPRINTF(FPE_INSN, ("fpu_cleanup: FSR_TT_IEEE\n"));
140 /* XXX missing trap address! */
141 if ((i = fsr & FSR_CX) == 0)
142 panic("fpu ieee trap, but no exception");
143 KERNEL_PROC_LOCK(l);
144 trapsignal(l, SIGFPE, fpu_codes[i - 1]);
145 KERNEL_PROC_UNLOCK(l);
146 break; /* XXX should return, but queue remains */
147
148 case FSR_TT_UNFIN:
149 DPRINTF(FPE_INSN, ("fpu_cleanup: FSR_TT_UNFIN\n"));
150 #ifdef SUN4U
151 if (fs->fs_qsize == 0) {
152 printf("fpu_cleanup: unfinished fpop");
153 /* The book sez reexecute or emulate. */
154 return;
155 }
156 break;
157
158 #endif /* SUN4U */
159 case FSR_TT_UNIMP:
160 DPRINTF(FPE_INSN, ("fpu_cleanup: FSR_TT_UNIMP\n"));
161 if (fs->fs_qsize == 0)
162 panic("fpu_cleanup: unimplemented fpop");
163 break;
164
165 case FSR_TT_SEQ:
166 panic("fpu sequence error");
167 /* NOTREACHED */
168
169 case FSR_TT_HWERR:
170 DPRINTF(FPE_INSN, ("fpu_cleanup: FSR_TT_HWERR\n"));
171 log(LOG_ERR, "fpu hardware error (%s[%d])\n",
172 p->p_comm, p->p_pid);
173 uprintf("%s[%d]: fpu hardware error\n", p->p_comm, p->p_pid);
174 KERNEL_PROC_LOCK(l);
175 trapsignal(l, SIGFPE, -1); /* ??? */
176 KERNEL_PROC_UNLOCK(l);
177 goto out;
178
179 default:
180 printf("fsr=0x%x\n", fsr);
181 panic("fpu error");
182 }
183
184 /* emulate the instructions left in the queue */
185 fe.fe_fpstate = fs;
186 for (i = 0; i < fs->fs_qsize; i++) {
187 instr.i_int = fs->fs_queue[i].fq_instr;
188 if (instr.i_any.i_op != IOP_reg ||
189 (instr.i_op3.i_op3 != IOP3_FPop1 &&
190 instr.i_op3.i_op3 != IOP3_FPop2))
191 panic("bogus fpu queue");
192 error = fpu_execute(&fe, instr);
193 if (error == 0)
194 continue;
195
196 KERNEL_PROC_LOCK(l);
197 switch (error) {
198 case FPE:
199 trapsignal(l, SIGFPE,
200 fpu_codes[(fs->fs_fsr & FSR_CX) - 1]);
201 break;
202
203 case NOTFPU:
204 #ifdef SUN4U
205 #ifdef DEBUG
206 printf("fpu_cleanup: not an FPU error -- sending SIGILL\n");
207 #endif
208 #endif /* SUN4U */
209 trapsignal(l, SIGILL, 0); /* ??? code? */
210 break;
211
212 default:
213 panic("fpu_cleanup 3");
214 /* NOTREACHED */
215 }
216 KERNEL_PROC_UNLOCK(l);
217 /* XXX should stop here, but queue remains */
218 }
219 out:
220 fs->fs_qsize = 0;
221 }
222
223 #ifdef notyet
224 /*
225 * If we have no FPU at all (are there any machines like this out
226 * there!?) we have to emulate each instruction, and we need a pointer
227 * to the trapframe so that we can step over them and do FBfcc's.
228 * We know the `queue' is empty, though; we just want to emulate
229 * the instruction at tf->tf_pc.
230 */
231 fpu_emulate(l, tf, fs)
232 struct lwp *l;
233 register struct trapframe *tf;
234 #ifndef SUN4U
235 register struct fpstate *fs;
236 #else /* SUN4U */
237 register struct fpstate64 *fs;
238 #endif /* SUN4U */
239 {
240
241 do {
242 fetch instr from pc
243 decode
244 if (integer instr) {
245 /*
246 * We do this here, rather than earlier, to avoid
247 * losing even more badly than usual.
248 */
249 if (l->l_addr->u_pcb.pcb_uw) {
250 write_user_windows();
251 if (rwindow_save(l))
252 sigexit(l, SIGILL);
253 }
254 if (loadstore) {
255 do_it;
256 pc = npc, npc += 4
257 } else if (fbfcc) {
258 do_annul_stuff;
259 } else
260 return;
261 } else if (fpu instr) {
262 fe.fe_fsr = fs->fs_fsr &= ~FSR_CX;
263 error = fpu_execute(&fe, fs, instr);
264 switch (error) {
265 etc;
266 }
267 } else
268 return;
269 if (want to reschedule)
270 return;
271 } while (error == 0);
272 }
273 #endif
274
275 /*
276 * Execute an FPU instruction (one that runs entirely in the FPU; not
277 * FBfcc or STF, for instance). On return, fe->fe_fs->fs_fsr will be
278 * modified to reflect the setting the hardware would have left.
279 *
280 * Note that we do not catch all illegal opcodes, so you can, for instance,
281 * multiply two integers this way.
282 */
283 int
284 fpu_execute(fe, instr)
285 register struct fpemu *fe;
286 union instr instr;
287 {
288 register struct fpn *fp;
289 #ifndef SUN4U
290 register int opf, rs1, rs2, rd, type, mask, fsr, cx;
291 register struct fpstate *fs;
292 #else /* SUN4U */
293 register int opf, rs1, rs2, rd, type, mask, fsr, cx, i, cond;
294 register struct fpstate64 *fs;
295 #endif /* SUN4U */
296 u_int space[4];
297
298 /*
299 * `Decode' and execute instruction. Start with no exceptions.
300 * The type of any i_opf opcode is in the bottom two bits, so we
301 * squish them out here.
302 */
303 opf = instr.i_opf.i_opf;
304 /*
305 * The low two bits of the opf field for floating point insns usually
306 * correspond to the operation width:
307 *
308 * 0: Invalid
309 * 1: Single precision float
310 * 2: Double precision float
311 * 3: Quad precision float
312 *
313 * The exceptions are the integer to float conversion instructions.
314 *
315 * For double and quad precision, the low bit if the rs or rd field
316 * is actually the high bit of the register number.
317 */
318
319 type = opf & 3;
320 mask = 0x3 >> (3 - type);
321
322 rs1 = instr.i_opf.i_rs1;
323 rs1 = (rs1 & ~mask) | ((rs1 & mask & 0x1) << 5);
324 rs2 = instr.i_opf.i_rs2;
325 rs2 = (rs2 & ~mask) | ((rs2 & mask & 0x1) << 5);
326 rd = instr.i_opf.i_rd;
327 rd = (rd & ~mask) | ((rd & mask & 0x1) << 5);
328 #ifdef DIAGNOSTIC
329 if ((rs1 | rs2 | rd) & mask)
330 /* This may be an FPU insn but it is illegal. */
331 return (NOTFPU);
332 #endif
333 fs = fe->fe_fpstate;
334 fe->fe_fsr = fs->fs_fsr & ~FSR_CX;
335 fe->fe_cx = 0;
336 #ifdef SUN4U
337 /*
338 * Check to see if we're dealing with a fancy cmove and handle
339 * it first.
340 */
341 if (instr.i_op3.i_op3 == IOP3_FPop2 && (opf&0xff0) != (FCMP&0xff0)) {
342 switch (opf >>= 2) {
343 case FMVFC0 >> 2:
344 DPRINTF(FPE_INSN, ("fpu_execute: FMVFC0\n"));
345 cond = (fs->fs_fsr>>FSR_FCC_SHIFT)&FSR_FCC_MASK;
346 if (instr.i_fmovcc.i_cond != cond) return(0); /* success */
347 rs1 = fs->fs_regs[rs2];
348 goto mov;
349 case FMVFC1 >> 2:
350 DPRINTF(FPE_INSN, ("fpu_execute: FMVFC1\n"));
351 cond = (fs->fs_fsr>>FSR_FCC1_SHIFT)&FSR_FCC_MASK;
352 if (instr.i_fmovcc.i_cond != cond) return(0); /* success */
353 rs1 = fs->fs_regs[rs2];
354 goto mov;
355 case FMVFC2 >> 2:
356 DPRINTF(FPE_INSN, ("fpu_execute: FMVFC2\n"));
357 cond = (fs->fs_fsr>>FSR_FCC2_SHIFT)&FSR_FCC_MASK;
358 if (instr.i_fmovcc.i_cond != cond) return(0); /* success */
359 rs1 = fs->fs_regs[rs2];
360 goto mov;
361 case FMVFC3 >> 2:
362 DPRINTF(FPE_INSN, ("fpu_execute: FMVFC3\n"));
363 cond = (fs->fs_fsr>>FSR_FCC3_SHIFT)&FSR_FCC_MASK;
364 if (instr.i_fmovcc.i_cond != cond) return(0); /* success */
365 rs1 = fs->fs_regs[rs2];
366 goto mov;
367 case FMVIC >> 2:
368 /* Presume we're curlwp */
369 DPRINTF(FPE_INSN, ("fpu_execute: FMVIC\n"));
370 cond = (curlwp->l_md.md_tf->tf_tstate>>TSTATE_CCR_SHIFT)&PSR_ICC;
371 if (instr.i_fmovcc.i_cond != cond) return(0); /* success */
372 rs1 = fs->fs_regs[rs2];
373 goto mov;
374 case FMVXC >> 2:
375 /* Presume we're curlwp */
376 DPRINTF(FPE_INSN, ("fpu_execute: FMVXC\n"));
377 cond = (curlwp->l_md.md_tf->tf_tstate>>(TSTATE_CCR_SHIFT+XCC_SHIFT))&PSR_ICC;
378 if (instr.i_fmovcc.i_cond != cond) return(0); /* success */
379 rs1 = fs->fs_regs[rs2];
380 goto mov;
381 case FMVRZ >> 2:
382 /* Presume we're curlwp */
383 DPRINTF(FPE_INSN, ("fpu_execute: FMVRZ\n"));
384 rs1 = instr.i_fmovr.i_rs1;
385 if (rs1 != 0 && (int64_t)curlwp->l_md.md_tf->tf_global[rs1] != 0)
386 return (0); /* success */
387 rs1 = fs->fs_regs[rs2];
388 goto mov;
389 case FMVRLEZ >> 2:
390 /* Presume we're curlwp */
391 DPRINTF(FPE_INSN, ("fpu_execute: FMVRLEZ\n"));
392 rs1 = instr.i_fmovr.i_rs1;
393 if (rs1 != 0 && (int64_t)curlwp->l_md.md_tf->tf_global[rs1] > 0)
394 return (0); /* success */
395 rs1 = fs->fs_regs[rs2];
396 goto mov;
397 case FMVRLZ >> 2:
398 /* Presume we're curlwp */
399 DPRINTF(FPE_INSN, ("fpu_execute: FMVRLZ\n"));
400 rs1 = instr.i_fmovr.i_rs1;
401 if (rs1 == 0 || (int64_t)curlwp->l_md.md_tf->tf_global[rs1] >= 0)
402 return (0); /* success */
403 rs1 = fs->fs_regs[rs2];
404 goto mov;
405 case FMVRNZ >> 2:
406 /* Presume we're curlwp */
407 DPRINTF(FPE_INSN, ("fpu_execute: FMVRNZ\n"));
408 rs1 = instr.i_fmovr.i_rs1;
409 if (rs1 == 0 || (int64_t)curlwp->l_md.md_tf->tf_global[rs1] == 0)
410 return (0); /* success */
411 rs1 = fs->fs_regs[rs2];
412 goto mov;
413 case FMVRGZ >> 2:
414 /* Presume we're curlwp */
415 DPRINTF(FPE_INSN, ("fpu_execute: FMVRGZ\n"));
416 rs1 = instr.i_fmovr.i_rs1;
417 if (rs1 == 0 || (int64_t)curlwp->l_md.md_tf->tf_global[rs1] <= 0)
418 return (0); /* success */
419 rs1 = fs->fs_regs[rs2];
420 goto mov;
421 case FMVRGEZ >> 2:
422 /* Presume we're curlwp */
423 DPRINTF(FPE_INSN, ("fpu_execute: FMVRGEZ\n"));
424 rs1 = instr.i_fmovr.i_rs1;
425 if (rs1 != 0 && (int64_t)curlwp->l_md.md_tf->tf_global[rs1] < 0)
426 return (0); /* success */
427 rs1 = fs->fs_regs[rs2];
428 goto mov;
429 default:
430 DPRINTF(FPE_INSN,
431 ("fpu_execute: unknown v9 FP inst %x opf %x\n",
432 instr.i_int, opf));
433 return (NOTFPU);
434 }
435 }
436 #endif /* SUN4U */
437 switch (opf >>= 2) {
438
439 default:
440 DPRINTF(FPE_INSN,
441 ("fpu_execute: unknown basic FP inst %x opf %x\n",
442 instr.i_int, opf));
443 return (NOTFPU);
444
445 case FMOV >> 2: /* these should all be pretty obvious */
446 DPRINTF(FPE_INSN, ("fpu_execute: FMOV\n"));
447 rs1 = fs->fs_regs[rs2];
448 goto mov;
449
450 case FNEG >> 2:
451 DPRINTF(FPE_INSN, ("fpu_execute: FNEG\n"));
452 rs1 = fs->fs_regs[rs2] ^ (1 << 31);
453 goto mov;
454
455 case FABS >> 2:
456 DPRINTF(FPE_INSN, ("fpu_execute: FABS\n"));
457 rs1 = fs->fs_regs[rs2] & ~(1 << 31);
458 mov:
459 #ifndef SUN4U
460 fs->fs_regs[rd] = rs1;
461 #else /* SUN4U */
462 i = 1<<(type-1);
463 fs->fs_regs[rd++] = rs1;
464 while (--i > 0)
465 fs->fs_regs[rd++] = fs->fs_regs[++rs2];
466 #endif /* SUN4U */
467 fs->fs_fsr = fe->fe_fsr;
468 return (0); /* success */
469
470 case FSQRT >> 2:
471 DPRINTF(FPE_INSN, ("fpu_execute: FSQRT\n"));
472 fpu_explode(fe, &fe->fe_f1, type, rs2);
473 fp = fpu_sqrt(fe);
474 break;
475
476 case FADD >> 2:
477 DPRINTF(FPE_INSN, ("fpu_execute: FADD\n"));
478 fpu_explode(fe, &fe->fe_f1, type, rs1);
479 fpu_explode(fe, &fe->fe_f2, type, rs2);
480 fp = fpu_add(fe);
481 break;
482
483 case FSUB >> 2:
484 DPRINTF(FPE_INSN, ("fpu_execute: FSUB\n"));
485 fpu_explode(fe, &fe->fe_f1, type, rs1);
486 fpu_explode(fe, &fe->fe_f2, type, rs2);
487 fp = fpu_sub(fe);
488 break;
489
490 case FMUL >> 2:
491 DPRINTF(FPE_INSN, ("fpu_execute: FMUL\n"));
492 fpu_explode(fe, &fe->fe_f1, type, rs1);
493 fpu_explode(fe, &fe->fe_f2, type, rs2);
494 fp = fpu_mul(fe);
495 break;
496
497 case FDIV >> 2:
498 DPRINTF(FPE_INSN, ("fpu_execute: FDIV\n"));
499 fpu_explode(fe, &fe->fe_f1, type, rs1);
500 fpu_explode(fe, &fe->fe_f2, type, rs2);
501 fp = fpu_div(fe);
502 break;
503
504 case FCMP >> 2:
505 DPRINTF(FPE_INSN, ("fpu_execute: FCMP\n"));
506 fpu_explode(fe, &fe->fe_f1, type, rs1);
507 fpu_explode(fe, &fe->fe_f2, type, rs2);
508 fpu_compare(fe, 0);
509 goto cmpdone;
510
511 case FCMPE >> 2:
512 DPRINTF(FPE_INSN, ("fpu_execute: FCMPE\n"));
513 fpu_explode(fe, &fe->fe_f1, type, rs1);
514 fpu_explode(fe, &fe->fe_f2, type, rs2);
515 fpu_compare(fe, 1);
516 cmpdone:
517 /*
518 * The only possible exception here is NV; catch it
519 * early and get out, as there is no result register.
520 */
521 cx = fe->fe_cx;
522 fsr = fe->fe_fsr | (cx << FSR_CX_SHIFT);
523 if (cx != 0) {
524 if (fsr & (FSR_NV << FSR_TEM_SHIFT)) {
525 fs->fs_fsr = (fsr & ~FSR_FTT) |
526 (FSR_TT_IEEE << FSR_FTT_SHIFT);
527 return (FPE);
528 }
529 fsr |= FSR_NV << FSR_AX_SHIFT;
530 }
531 fs->fs_fsr = fsr;
532 return (0);
533
534 case FSMULD >> 2:
535 case FDMULX >> 2:
536 DPRINTF(FPE_INSN, ("fpu_execute: FSMULx\n"));
537 if (type == FTYPE_EXT)
538 return (NOTFPU);
539 fpu_explode(fe, &fe->fe_f1, type, rs1);
540 fpu_explode(fe, &fe->fe_f2, type, rs2);
541 type++; /* single to double, or double to quad */
542 fp = fpu_mul(fe);
543 break;
544
545 #ifdef SUN4U
546 case FXTOS >> 2:
547 case FXTOD >> 2:
548 case FXTOQ >> 2:
549 DPRINTF(FPE_INSN, ("fpu_execute: FXTOx\n"));
550 type = FTYPE_LNG;
551 fpu_explode(fe, fp = &fe->fe_f1, type, rs2);
552 type = opf & 3; /* sneaky; depends on instruction encoding */
553 break;
554
555 case FTOX >> 2:
556 DPRINTF(FPE_INSN, ("fpu_execute: FTOX\n"));
557 fpu_explode(fe, fp = &fe->fe_f1, type, rs2);
558 type = FTYPE_LNG;
559 /* Recalculate destination register */
560 rd = instr.i_opf.i_rd;
561 break;
562
563 #endif /* SUN4U */
564 case FTOI >> 2:
565 DPRINTF(FPE_INSN, ("fpu_execute: FTOI\n"));
566 fpu_explode(fe, fp = &fe->fe_f1, type, rs2);
567 type = FTYPE_INT;
568 /* Recalculate destination register */
569 rd = instr.i_opf.i_rd;
570 break;
571
572 case FTOS >> 2:
573 case FTOD >> 2:
574 case FTOQ >> 2:
575 DPRINTF(FPE_INSN, ("fpu_execute: FTOx\n"));
576 fpu_explode(fe, fp = &fe->fe_f1, type, rs2);
577 /* Recalculate rd with correct type info. */
578 type = opf & 3; /* sneaky; depends on instruction encoding */
579 mask = 0x3 >> (3 - type);
580 rd = instr.i_opf.i_rd;
581 rd = (rd & ~mask) | ((rd & mask & 0x1) << 5);
582 break;
583 }
584
585 /*
586 * ALU operation is complete. Collapse the result and then check
587 * for exceptions. If we got any, and they are enabled, do not
588 * alter the destination register, just stop with an exception.
589 * Otherwise set new current exceptions and accrue.
590 */
591 fpu_implode(fe, fp, type, space);
592 cx = fe->fe_cx;
593 fsr = fe->fe_fsr;
594 if (cx != 0) {
595 mask = (fsr >> FSR_TEM_SHIFT) & FSR_TEM_MASK;
596 if (cx & mask) {
597 /* not accrued??? */
598 fs->fs_fsr = (fsr & ~FSR_FTT) |
599 (FSR_TT_IEEE << FSR_FTT_SHIFT) |
600 (cx_to_trapx[(cx & mask) - 1] << FSR_CX_SHIFT);
601 return (FPE);
602 }
603 fsr |= (cx << FSR_CX_SHIFT) | (cx << FSR_AX_SHIFT);
604 }
605 fs->fs_fsr = fsr;
606 DPRINTF(FPE_REG, ("-> %c%d\n", (type == FTYPE_LNG) ? 'x' :
607 ((type == FTYPE_INT) ? 'i' :
608 ((type == FTYPE_SNG) ? 's' :
609 ((type == FTYPE_DBL) ? 'd' :
610 ((type == FTYPE_EXT) ? 'q' : '?')))),
611 rd));
612 fs->fs_regs[rd] = space[0];
613 if (type >= FTYPE_DBL || type == FTYPE_LNG) {
614 fs->fs_regs[rd + 1] = space[1];
615 if (type > FTYPE_DBL) {
616 fs->fs_regs[rd + 2] = space[2];
617 fs->fs_regs[rd + 3] = space[3];
618 }
619 }
620 return (0); /* success */
621 }
622