]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/i387-tdep.c
import gdb-1999-09-21
[thirdparty/binutils-gdb.git] / gdb / i387-tdep.c
CommitLineData
c906108c
SS
1/* Intel 387 floating point stuff.
2 Copyright (C) 1988, 1989, 1991, 1998 Free Software Foundation, Inc.
3
c5aa993b 4 This file is part of GDB.
c906108c 5
c5aa993b
JM
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
c906108c 10
c5aa993b
JM
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
c906108c 15
c5aa993b
JM
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
c906108c
SS
20
21#include "defs.h"
22#include "frame.h"
23#include "inferior.h"
24#include "language.h"
d4f3574e 25#include "value.h"
c906108c
SS
26#include "gdbcore.h"
27#include "floatformat.h"
28
29void i387_to_double PARAMS ((char *, char *));
c906108c
SS
30void double_to_i387 PARAMS ((char *, char *));
31
d4f3574e
SS
32static void print_387_control_bits PARAMS ((unsigned int control));
33static void print_387_status_bits PARAMS ((unsigned int status));
34
c906108c
SS
35/* FIXME: Eliminate these routines when we have the time to change all
36 the callers. */
37
38void
39i387_to_double (from, to)
40 char *from;
41 char *to;
42{
c5aa993b 43 floatformat_to_double (&floatformat_i387_ext, from, (double *) to);
c906108c
SS
44}
45
46void
47double_to_i387 (from, to)
48 char *from;
49 char *to;
50{
c5aa993b 51 floatformat_from_double (&floatformat_i387_ext, (double *) from, to);
c906108c
SS
52}
53
d4f3574e
SS
54static void
55print_387_control_bits (control)
c906108c
SS
56 unsigned int control;
57{
c5aa993b 58 switch ((control >> 8) & 3)
c906108c 59 {
c5aa993b 60 case 0:
d4f3574e 61 puts_unfiltered (" 24 bit; ");
c5aa993b
JM
62 break;
63 case 1:
d4f3574e 64 puts_unfiltered (" (bad); ");
c5aa993b
JM
65 break;
66 case 2:
d4f3574e 67 puts_unfiltered (" 53 bit; ");
c5aa993b
JM
68 break;
69 case 3:
d4f3574e 70 puts_unfiltered (" 64 bit; ");
c5aa993b 71 break;
c906108c 72 }
c5aa993b 73 switch ((control >> 10) & 3)
c906108c 74 {
c5aa993b 75 case 0:
d4f3574e 76 puts_unfiltered ("NEAR; ");
c5aa993b
JM
77 break;
78 case 1:
d4f3574e 79 puts_unfiltered ("DOWN; ");
c5aa993b
JM
80 break;
81 case 2:
d4f3574e 82 puts_unfiltered ("UP; ");
c5aa993b
JM
83 break;
84 case 3:
d4f3574e 85 puts_unfiltered ("CHOP; ");
c5aa993b 86 break;
c906108c 87 }
c5aa993b 88 if (control & 0x3f)
c906108c 89 {
d4f3574e 90 puts_unfiltered ("mask");
c5aa993b 91 if (control & 0x0001)
d4f3574e 92 puts_unfiltered (" INVAL");
c5aa993b 93 if (control & 0x0002)
d4f3574e 94 puts_unfiltered (" DENOR");
c5aa993b 95 if (control & 0x0004)
d4f3574e 96 puts_unfiltered (" DIVZ");
c5aa993b 97 if (control & 0x0008)
d4f3574e 98 puts_unfiltered (" OVERF");
c5aa993b 99 if (control & 0x0010)
d4f3574e 100 puts_unfiltered (" UNDER");
c5aa993b 101 if (control & 0x0020)
d4f3574e
SS
102 puts_unfiltered (" LOS");
103 puts_unfiltered (";");
c906108c 104 }
cff3e48b 105
c5aa993b 106 if (control & 0xe080)
d4f3574e 107 warning ("\nreserved bits on: %s",
c5aa993b 108 local_hex_string (control & 0xe080));
c906108c
SS
109}
110
111void
d4f3574e
SS
112print_387_control_word (control)
113 unsigned int control;
114{
115 printf_filtered ("control %s:", local_hex_string(control & 0xffff));
116 print_387_control_bits (control);
117 puts_unfiltered ("\n");
118}
119
120static void
121print_387_status_bits (status)
c906108c
SS
122 unsigned int status;
123{
d4f3574e 124 printf_unfiltered (" flags %d%d%d%d; ",
c5aa993b
JM
125 (status & 0x4000) != 0,
126 (status & 0x0400) != 0,
127 (status & 0x0200) != 0,
128 (status & 0x0100) != 0);
d4f3574e
SS
129 printf_unfiltered ("top %d; ", (status >> 11) & 7);
130 if (status & 0xff)
131 {
132 puts_unfiltered ("excep");
133 if (status & 0x0001) puts_unfiltered (" INVAL");
134 if (status & 0x0002) puts_unfiltered (" DENOR");
135 if (status & 0x0004) puts_unfiltered (" DIVZ");
136 if (status & 0x0008) puts_unfiltered (" OVERF");
137 if (status & 0x0010) puts_unfiltered (" UNDER");
138 if (status & 0x0020) puts_unfiltered (" LOS");
139 if (status & 0x0040) puts_unfiltered (" STACK");
140 }
141}
142
143void
144print_387_status_word (status)
145 unsigned int status;
146{
147 printf_filtered ("status %s:", local_hex_string (status & 0xffff));
148 print_387_status_bits (status);
149 puts_unfiltered ("\n");
150}
151
d4f3574e
SS
152#ifdef LD_I387
153int
154i387_extract_floating (PTR addr, int len, DOUBLEST *dretptr)
155{
156 if (len == TARGET_LONG_DOUBLE_BIT / 8)
157 {
158 if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
159 {
160 DOUBLEST retval;
161
162 memcpy (dretptr, addr, sizeof (retval));
163 }
164 else
165 floatformat_to_doublest (TARGET_LONG_DOUBLE_FORMAT, addr, dretptr);
166
167 return 1;
168 }
169 else
170 return 0;
171}
172
173int
174i387_store_floating (PTR addr, int len, DOUBLEST val)
175{
176 if (len == TARGET_LONG_DOUBLE_BIT / 8)
177 {
178 /* This `if' may be totally stupid. I just put it in here to be
179 absolutely sure I'm preserving the semantics of the code I'm
180 frobbing, while I try to maintain portability boundaries; I
181 don't actually know exactly what it's doing. -JimB, May 1999 */
182 if (HOST_LONG_DOUBLE_FORMAT == TARGET_LONG_DOUBLE_FORMAT)
183 memcpy (addr, &val, sizeof (val));
184 else
185 floatformat_from_doublest (TARGET_LONG_DOUBLE_FORMAT, &val, addr);
186
187 return 1;
188 }
189 else
190 return 0;
c906108c 191}
d4f3574e 192#endif /* LD_I387 */