1169695Skan/* IEEE floating point support declarations, for GDB, the GNU Debugger.
2169695Skan   Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005
3169695Skan   Free Software Foundation, Inc.
4169695Skan
5169695SkanThis file is part of GDB.
6169695Skan
7169695SkanThis program is free software; you can redistribute it and/or modify
8169695Skanit under the terms of the GNU General Public License as published by
9169695Skanthe Free Software Foundation; either version 2 of the License, or
10169695Skan(at your option) any later version.
11169695Skan
12169695SkanThis program is distributed in the hope that it will be useful,
13169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
14169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15169695SkanGNU General Public License for more details.
16169695Skan
17169695SkanYou should have received a copy of the GNU General Public License
18169695Skanalong with this program; if not, write to the Free Software
19169695SkanFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20169695Skan
21169695Skan#if !defined (FLOATFORMAT_H)
22169695Skan#define FLOATFORMAT_H 1
23169695Skan
24169695Skan#include "ansidecl.h"
25169695Skan
26169695Skan/* A floatformat consists of a sign bit, an exponent and a mantissa.  Once the
27169695Skan   bytes are concatenated according to the byteorder flag, then each of those
28169695Skan   fields is contiguous.  We number the bits with 0 being the most significant
29169695Skan   (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field
30169695Skan   contains with the *_start and *_len fields.  */
31169695Skan
32169695Skan/* What is the order of the bytes?  */
33169695Skan
34169695Skanenum floatformat_byteorders {
35169695Skan  /* Standard little endian byte order.
36169695Skan     EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
37169695Skan  floatformat_little,
38169695Skan
39169695Skan  /* Standard big endian byte order.
40169695Skan     EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */
41169695Skan  floatformat_big,
42169695Skan
43169695Skan  /* Little endian byte order but big endian word order.
44169695Skan     EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */
45169695Skan  floatformat_littlebyte_bigword,
46169695Skan
47169695Skan  /* VAX byte order.  Little endian byte order with 16-bit words.  The
48169695Skan     following example is an illustration of the byte order only; VAX
49169695Skan     doesn't have a fully IEEE compliant floating-point format.
50169695Skan     EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */
51169695Skan  floatformat_vax
52169695Skan};
53169695Skan
54169695Skanenum floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no };
55169695Skan
56169695Skanstruct floatformat
57169695Skan{
58169695Skan  enum floatformat_byteorders byteorder;
59169695Skan  unsigned int totalsize;	/* Total size of number in bits */
60169695Skan
61169695Skan  /* Sign bit is always one bit long.  1 means negative, 0 means positive.  */
62169695Skan  unsigned int sign_start;
63169695Skan
64169695Skan  unsigned int exp_start;
65169695Skan  unsigned int exp_len;
66169695Skan  /* Bias added to a "true" exponent to form the biased exponent.  It
67169695Skan     is intentionally signed as, otherwize, -exp_bias can turn into a
68169695Skan     very large number (e.g., given the exp_bias of 0x3fff and a 64
69169695Skan     bit long, the equation (long)(1 - exp_bias) evaluates to
70169695Skan     4294950914) instead of -16382).  */
71169695Skan  int exp_bias;
72169695Skan  /* Exponent value which indicates NaN.  This is the actual value stored in
73169695Skan     the float, not adjusted by the exp_bias.  This usually consists of all
74169695Skan     one bits.  */
75169695Skan  unsigned int exp_nan;
76169695Skan
77169695Skan  unsigned int man_start;
78169695Skan  unsigned int man_len;
79169695Skan
80169695Skan  /* Is the integer bit explicit or implicit?  */
81169695Skan  enum floatformat_intbit intbit;
82169695Skan
83169695Skan  /* Internal name for debugging. */
84169695Skan  const char *name;
85169695Skan
86169695Skan  /* Validator method.  */
87169695Skan  int (*is_valid) (const struct floatformat *fmt, const void *from);
88169695Skan};
89169695Skan
90169695Skan/* floatformats for IEEE single and double, big and little endian.  */
91169695Skan
92169695Skanextern const struct floatformat floatformat_ieee_single_big;
93169695Skanextern const struct floatformat floatformat_ieee_single_little;
94169695Skanextern const struct floatformat floatformat_ieee_double_big;
95169695Skanextern const struct floatformat floatformat_ieee_double_little;
96169695Skan
97169695Skan/* floatformat for ARM IEEE double, little endian bytes and big endian words */
98169695Skan
99169695Skanextern const struct floatformat floatformat_ieee_double_littlebyte_bigword;
100169695Skan
101169695Skan/* floatformats for VAX.  */
102169695Skan
103169695Skanextern const struct floatformat floatformat_vax_f;
104169695Skanextern const struct floatformat floatformat_vax_d;
105169695Skanextern const struct floatformat floatformat_vax_g;
106169695Skan
107169695Skan/* floatformats for various extendeds.  */
108169695Skan
109169695Skanextern const struct floatformat floatformat_i387_ext;
110169695Skanextern const struct floatformat floatformat_m68881_ext;
111169695Skanextern const struct floatformat floatformat_i960_ext;
112169695Skanextern const struct floatformat floatformat_m88110_ext;
113169695Skanextern const struct floatformat floatformat_m88110_harris_ext;
114169695Skanextern const struct floatformat floatformat_arm_ext_big;
115169695Skanextern const struct floatformat floatformat_arm_ext_littlebyte_bigword;
116169695Skan/* IA-64 Floating Point register spilt into memory.  */
117169695Skanextern const struct floatformat floatformat_ia64_spill_big;
118169695Skanextern const struct floatformat floatformat_ia64_spill_little;
119169695Skanextern const struct floatformat floatformat_ia64_quad_big;
120169695Skanextern const struct floatformat floatformat_ia64_quad_little;
121169695Skan
122169695Skan/* Convert from FMT to a double.
123169695Skan   FROM is the address of the extended float.
124169695Skan   Store the double in *TO.  */
125169695Skan
126169695Skanextern void
127169695Skanfloatformat_to_double (const struct floatformat *, const void *, double *);
128169695Skan
129169695Skan/* The converse: convert the double *FROM to FMT
130169695Skan   and store where TO points.  */
131169695Skan
132169695Skanextern void
133169695Skanfloatformat_from_double (const struct floatformat *, const double *, void *);
134169695Skan
135169695Skan/* Return non-zero iff the data at FROM is a valid number in format FMT.  */
136169695Skan
137169695Skanextern int
138169695Skanfloatformat_is_valid (const struct floatformat *fmt, const void *from);
139169695Skan
140169695Skan#endif	/* defined (FLOATFORMAT_H) */
141