1 /* $NetBSD: fpu_fstore.c,v 1.10 2007/03/09 16:23:01 tsutsui Exp $ */
4 * Copyright (c) 1995 Ken Nakata
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: fpu_fstore.c,v 1.10 2007/03/09 16:23:01 tsutsui Exp $");
31 #include <sys/types.h>
32 #include <sys/signal.h>
33 #include <sys/systm.h>
34 #include <machine/frame.h>
36 #include "fpu_emulate.h"
39 * type 0: fmove mem/fpr->fpr
40 * In this function, we know
41 * (opcode & 0x01c0) == 0
42 * (word1 & 0xe000) == 0x6000
45 fpu_emul_fstore(struct fpemu
*fe
, struct instruction
*insn
)
47 struct frame
*frame
= fe
->fe_frame
;
48 u_int
*fpregs
= fe
->fe_fpframe
->fpf_regs
;
55 printf(" fpu_emul_fstore: frame at %p fpframe at %p\n",
56 frame
, fe
->fe_fpframe
);
59 word1
= insn
->is_word1
;
60 format
= (word1
>> 10) & 7;
61 regnum
= (word1
>> 7) & 7;
65 if (format
== FTYPE_DBL
) {
66 insn
->is_datasize
= 8;
67 } else if (format
== FTYPE_SNG
|| format
== FTYPE_LNG
) {
68 insn
->is_datasize
= 4;
69 } else if (format
== FTYPE_WRD
) {
70 insn
->is_datasize
= 2;
72 } else if (format
== FTYPE_BYT
) {
73 insn
->is_datasize
= 1;
75 } else if (format
== FTYPE_EXT
) {
76 insn
->is_datasize
= 12;
78 /* invalid or unsupported operand format */
80 printf(" fpu_emul_fstore: invalid format %d\n", format
);
85 printf(" fpu_emul_fstore: format %d, size %d\n",
86 format
, insn
->is_datasize
);
89 fe
->fe_fpsr
&= ~FPSR_EXCP
;
91 /* Get effective address. (modreg=opcode&077) */
92 sig
= fpu_decode_ea(frame
, insn
, &insn
->is_ea
, insn
->is_opcode
);
95 printf(" fpu_emul_fstore: failed in decode_ea sig=%d\n", sig
);
100 if (insn
->is_datasize
> 4 && insn
->is_ea
.ea_flags
== EA_DIRECT
) {
101 /* trying to store dbl or ext into a data register */
103 printf(" fpu_fstore: attempted to store dbl/ext to reg\n");
109 printf(" fpu_emul_fstore: saving FP%d (%08x,%08x,%08x)\n",
110 regnum
, fpregs
[regnum
* 3], fpregs
[regnum
* 3 + 1],
111 fpregs
[regnum
* 3 + 2]);
113 fpu_explode(fe
, &fe
->fe_f3
, FTYPE_EXT
, &fpregs
[regnum
* 3]);
116 static const char *class_name
[] =
117 { "SNAN", "QNAN", "ZERO", "NUM", "INF" };
118 printf(" fpu_emul_fstore: fpn (%s,%c,%d,%08x,%08x,%08x)\n",
119 class_name
[fe
->fe_f3
.fp_class
+ 2],
120 fe
->fe_f3
.fp_sign
? '-' : '+', fe
->fe_f3
.fp_exp
,
121 fe
->fe_f3
.fp_mant
[0], fe
->fe_f3
.fp_mant
[1],
122 fe
->fe_f3
.fp_mant
[2]);
125 fpu_implode(fe
, &fe
->fe_f3
, format
, buf
);
127 fpu_store_ea(frame
, insn
, &insn
->is_ea
, (char *)buf
);
129 printf(" fpu_emul_fstore: %08x,%08x,%08x size %d\n",
130 buf
[0], buf
[1], buf
[2], insn
->is_datasize
);