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