Home | History | Annotate | Line # | Download | only in fpe
fpu_fstore.c revision 1.6
      1 /*	$NetBSD: fpu_fstore.c,v 1.6 1997/07/19 22:28:49 is Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Ken Nakata
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #include <sys/types.h>
     29 #include <sys/signal.h>
     30 #include <sys/systm.h>
     31 #include <machine/frame.h>
     32 
     33 #include "fpu_emulate.h"
     34 
     35 /*
     36  * type 0: fmove mem/fpr->fpr
     37  * In this function, we know
     38  *	(opcode & 0x01c0) == 0
     39  *	(word1 & 0xe000) == 0x6000
     40  */
     41 int
     42 fpu_emul_fstore(fe, insn)
     43      struct fpemu *fe;
     44      struct instruction *insn;
     45 {
     46     struct frame *frame = fe->fe_frame;
     47     u_int *fpregs = fe->fe_fpframe->fpf_regs;
     48     int word1, sig;
     49     int regnum;
     50     int format;
     51     u_int buf[3];
     52 
     53     if (fpu_debug_level & DL_FSTORE) {
     54 	printf("  fpu_emul_fstore: frame at %p fpframe at %p\n",
     55 	       frame, fe->fe_fpframe);
     56     }
     57 
     58     word1 = insn->is_word1;
     59     format = (word1 >> 10) & 7;
     60     regnum = (word1 >> 7) & 7;
     61 
     62     insn->is_advance = 4;
     63 
     64     if (format == FTYPE_DBL) {
     65 	insn->is_datasize = 8;
     66     } else if (format == FTYPE_SNG || format == FTYPE_LNG) {
     67 	insn->is_datasize = 4;
     68     } else if (format == FTYPE_WRD) {
     69 	insn->is_datasize = 2;
     70 	format = FTYPE_LNG;
     71     } else if (format == FTYPE_BYT) {
     72 	insn->is_datasize = 1;
     73 	format = FTYPE_LNG;
     74     } else if (format == FTYPE_EXT) {
     75 	insn->is_datasize = 12;
     76     } else {
     77 	/* invalid or unsupported operand format */
     78 	if (fpu_debug_level & DL_FSTORE) {
     79 	    printf("  fpu_emul_fstore: invalid format %d\n", format);
     80 	}
     81 	sig = SIGFPE;
     82     }
     83     if (fpu_debug_level & DL_FSTORE) {
     84 	printf("  fpu_emul_fstore: format %d, size %d\n",
     85 	       format, insn->is_datasize);
     86     }
     87 
     88     fe->fe_fpsr &= ~FPSR_EXCP;
     89 
     90     /* Get effective address. (modreg=opcode&077) */
     91     sig = fpu_decode_ea(frame, insn, &insn->is_ea0, insn->is_opcode);
     92     if (sig) {
     93 	if (fpu_debug_level & DL_FSTORE) {
     94 	    printf("  fpu_emul_fstore: failed in decode_ea sig=%d\n", sig);
     95 	}
     96 	return sig;
     97     }
     98 
     99     if (insn->is_datasize > 4 && insn->is_ea0.ea_flags == EA_DIRECT) {
    100 	/* trying to store dbl or ext into a data register */
    101 #ifdef DEBUG
    102 	printf("  fpu_fstore: attempted to store dbl/ext to reg\n");
    103 #endif
    104 	return SIGILL;
    105     }
    106 
    107     if (fpu_debug_level & DL_OPERANDS)
    108 	printf("  fpu_emul_fstore: saving FP%d (%08x,%08x,%08x)\n",
    109 	       regnum, fpregs[regnum * 3], fpregs[regnum * 3 + 1],
    110 	       fpregs[regnum * 3 + 2]);
    111     fpu_explode(fe, &fe->fe_f3, FTYPE_EXT, &fpregs[regnum * 3]);
    112     if (fpu_debug_level & DL_VALUES) {
    113 	static char *class_name[] = { "SNAN", "QNAN", "ZERO", "NUM", "INF" };
    114 	printf("  fpu_emul_fstore: fpn (%s,%c,%d,%08x,%08x,%08x,%08x)\n",
    115 	       class_name[fe->fe_f3.fp_class + 2],
    116 	       fe->fe_f3.fp_sign ? '-' : '+', fe->fe_f3.fp_exp,
    117 	       fe->fe_f3.fp_mant[0], fe->fe_f3.fp_mant[1],
    118 	       fe->fe_f3.fp_mant[2], fe->fe_f3.fp_mant[3]);
    119     }
    120     fpu_implode(fe, &fe->fe_f3, format, buf);
    121 
    122     fpu_store_ea(frame, insn, &insn->is_ea0, (char *)buf);
    123     if (fpu_debug_level & DL_RESULT)
    124 	printf("  fpu_emul_fstore: %08x,%08x,%08x size %d\n",
    125 	       buf[0], buf[1], buf[2], insn->is_datasize);
    126 
    127     return 0;
    128 }
    129