1130812Smarcel/* IEEE floating point support declarations, for GDB, the GNU Debugger.
2130812Smarcel   Copyright 1991, 1994, 1995, 1997, 2000, 2003 Free Software Foundation, Inc.
3130812Smarcel
4130812SmarcelThis file is part of GDB.
5130812Smarcel
6130812SmarcelThis program is free software; you can redistribute it and/or modify
7130812Smarcelit under the terms of the GNU General Public License as published by
8130812Smarcelthe Free Software Foundation; either version 2 of the License, or
9130812Smarcel(at your option) any later version.
10130812Smarcel
11130812SmarcelThis program is distributed in the hope that it will be useful,
12130812Smarcelbut WITHOUT ANY WARRANTY; without even the implied warranty of
13130812SmarcelMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14130812SmarcelGNU General Public License for more details.
15130812Smarcel
16130812SmarcelYou should have received a copy of the GNU General Public License
17130812Smarcelalong with this program; if not, write to the Free Software
18130812SmarcelFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19130812Smarcel
20130812Smarcel#if !defined (FLOATFORMAT_H)
21130812Smarcel#define FLOATFORMAT_H 1
22130812Smarcel
23130812Smarcel#include "ansidecl.h"
24130812Smarcel
25130812Smarcel/* A floatformat consists of a sign bit, an exponent and a mantissa.  Once the
26130812Smarcel   bytes are concatenated according to the byteorder flag, then each of those
27130812Smarcel   fields is contiguous.  We number the bits with 0 being the most significant
28130812Smarcel   (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field
29130812Smarcel   contains with the *_start and *_len fields.  */
30130812Smarcel
31130812Smarcel/* What is the order of the bytes. */
32130812Smarcel
33130812Smarcelenum floatformat_byteorders {
34130812Smarcel
35130812Smarcel  /* Standard little endian byte order.
36130812Smarcel     EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
37130812Smarcel
38130812Smarcel  floatformat_little,
39130812Smarcel
40130812Smarcel  /* Standard big endian byte order.
41130812Smarcel     EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */
42130812Smarcel
43130812Smarcel  floatformat_big,
44130812Smarcel
45130812Smarcel  /* Little endian byte order but big endian word order.
46130812Smarcel     EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */
47130812Smarcel
48130812Smarcel  floatformat_littlebyte_bigword
49130812Smarcel
50130812Smarcel};
51130812Smarcel
52130812Smarcelenum floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no };
53130812Smarcel
54130812Smarcelstruct floatformat
55130812Smarcel{
56130812Smarcel  enum floatformat_byteorders byteorder;
57130812Smarcel  unsigned int totalsize;	/* Total size of number in bits */
58130812Smarcel
59130812Smarcel  /* Sign bit is always one bit long.  1 means negative, 0 means positive.  */
60130812Smarcel  unsigned int sign_start;
61130812Smarcel
62130812Smarcel  unsigned int exp_start;
63130812Smarcel  unsigned int exp_len;
64130812Smarcel  /* Bias added to a "true" exponent to form the biased exponent.  It
65130812Smarcel     is intentionally signed as, otherwize, -exp_bias can turn into a
66130812Smarcel     very large number (e.g., given the exp_bias of 0x3fff and a 64
67130812Smarcel     bit long, the equation (long)(1 - exp_bias) evaluates to
68130812Smarcel     4294950914) instead of -16382).  */
69130812Smarcel  int exp_bias;
70130812Smarcel  /* Exponent value which indicates NaN.  This is the actual value stored in
71130812Smarcel     the float, not adjusted by the exp_bias.  This usually consists of all
72130812Smarcel     one bits.  */
73130812Smarcel  unsigned int exp_nan;
74130812Smarcel
75130812Smarcel  unsigned int man_start;
76130812Smarcel  unsigned int man_len;
77130812Smarcel
78130812Smarcel  /* Is the integer bit explicit or implicit?  */
79130812Smarcel  enum floatformat_intbit intbit;
80130812Smarcel
81130812Smarcel  /* Internal name for debugging. */
82130812Smarcel  const char *name;
83130812Smarcel
84130812Smarcel  /* Validator method.  */
85130812Smarcel  int (*is_valid) PARAMS ((const struct floatformat *fmt, const char *from));
86130812Smarcel};
87130812Smarcel
88130812Smarcel/* floatformats for IEEE single and double, big and little endian.  */
89130812Smarcel
90130812Smarcelextern const struct floatformat floatformat_ieee_single_big;
91130812Smarcelextern const struct floatformat floatformat_ieee_single_little;
92130812Smarcelextern const struct floatformat floatformat_ieee_double_big;
93130812Smarcelextern const struct floatformat floatformat_ieee_double_little;
94130812Smarcel
95130812Smarcel/* floatformat for ARM IEEE double, little endian bytes and big endian words */
96130812Smarcel
97130812Smarcelextern const struct floatformat floatformat_ieee_double_littlebyte_bigword;
98130812Smarcel
99130812Smarcel/* floatformats for various extendeds.  */
100130812Smarcel
101130812Smarcelextern const struct floatformat floatformat_i387_ext;
102130812Smarcelextern const struct floatformat floatformat_m68881_ext;
103130812Smarcelextern const struct floatformat floatformat_i960_ext;
104130812Smarcelextern const struct floatformat floatformat_m88110_ext;
105130812Smarcelextern const struct floatformat floatformat_m88110_harris_ext;
106130812Smarcelextern const struct floatformat floatformat_arm_ext_big;
107130812Smarcelextern const struct floatformat floatformat_arm_ext_littlebyte_bigword;
108130812Smarcel/* IA-64 Floating Point register spilt into memory.  */
109130812Smarcelextern const struct floatformat floatformat_ia64_spill_big;
110130812Smarcelextern const struct floatformat floatformat_ia64_spill_little;
111130812Smarcelextern const struct floatformat floatformat_ia64_quad_big;
112130812Smarcelextern const struct floatformat floatformat_ia64_quad_little;
113130812Smarcel
114130812Smarcel/* Convert from FMT to a double.
115130812Smarcel   FROM is the address of the extended float.
116130812Smarcel   Store the double in *TO.  */
117130812Smarcel
118130812Smarcelextern void
119130812Smarcelfloatformat_to_double PARAMS ((const struct floatformat *, const char *, double *));
120130812Smarcel
121130812Smarcel/* The converse: convert the double *FROM to FMT
122130812Smarcel   and store where TO points.  */
123130812Smarcel
124130812Smarcelextern void
125130812Smarcelfloatformat_from_double PARAMS ((const struct floatformat *,
126130812Smarcel				 const double *, char *));
127130812Smarcel
128130812Smarcel/* Return non-zero iff the data at FROM is a valid number in format FMT.  */
129130812Smarcel
130130812Smarcelextern int
131130812Smarcelfloatformat_is_valid PARAMS ((const struct floatformat *fmt, const char *from));
132130812Smarcel
133130812Smarcel#endif	/* defined (FLOATFORMAT_H) */
134