libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

convert_numeric.h (5903B)


      1 /* IEEE floating point support declarations, for GDB, the GNU Debugger.
      2    Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005
      3    Free Software Foundation, Inc.
      4 
      5 This file is part of GDB.
      6 
      7 This program is free software; you can redistribute it and/or modify
      8 it under the terms of the GNU General Public License as published by
      9 the Free Software Foundation; either version 2 of the License, or
     10 (at your option) any later version.
     11 
     12 This program is distributed in the hope that it will be useful,
     13 but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 GNU General Public License for more details.
     16 
     17 You should have received a copy of the GNU General Public License
     18 along with this program; if not, write to the Free Software
     19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
     20 
     21 #if ! defined (FLOATFORMAT_H)
     22 #define FLOATFORMAT_H 1
     23 
     24 /*#include "ansidecl.h"*/
     25 
     26 /* A floatformat consists of a sign bit, an exponent and a mantissa.  Once the
     27    bytes are concatenated according to the byteorder flag, then each of those
     28    fields is contiguous.  We number the bits with 0 being the most significant
     29    (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field
     30    contains with the *_start and *_len fields.  */
     31 
     32 /* What is the order of the bytes?  */
     33 
     34 enum EXTRACTOR_floatformat_byteorders
     35 {
     36   /* Standard little endian byte order.
     37      EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
     38   floatformat_little,
     39 
     40   /* Standard big endian byte order.
     41      EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */
     42   floatformat_big,
     43 
     44   /* Little endian byte order but big endian word order.
     45      EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */
     46   floatformat_littlebyte_bigword,
     47 
     48   /* VAX byte order.  Little endian byte order with 16-bit words.  The
     49      following example is an illustration of the byte order only; VAX
     50      doesn't have a fully IEEE compliant floating-point format.
     51      EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */
     52   floatformat_vax
     53 };
     54 
     55 enum EXTRACTOR_floatformat_intbit { floatformat_intbit_yes,
     56                                     floatformat_intbit_no };
     57 
     58 struct EXTRACTOR_floatformat
     59 {
     60   enum EXTRACTOR_floatformat_byteorders byteorder;
     61   unsigned int totalsize; /* Total size of number in bits */
     62 
     63   /* Sign bit is always one bit long.  1 means negative, 0 means positive.  */
     64   unsigned int sign_start;
     65 
     66   unsigned int exp_start;
     67   unsigned int exp_len;
     68   /* Bias added to a "true" exponent to form the biased exponent.  It
     69      is intentionally signed as, otherwize, -exp_bias can turn into a
     70      very large number (e.g., given the exp_bias of 0x3fff and a 64
     71      bit long, the equation (long)(1 - exp_bias) evaluates to
     72      4294950914) instead of -16382).  */
     73   int exp_bias;
     74   /* Exponent value which indicates NaN.  This is the actual value stored in
     75      the float, not adjusted by the exp_bias.  This usually consists of all
     76      one bits.  */
     77   unsigned int exp_nan;
     78 
     79   unsigned int man_start;
     80   unsigned int man_len;
     81 
     82   /* Is the integer bit explicit or implicit?  */
     83   enum EXTRACTOR_floatformat_intbit intbit;
     84 
     85   /* Internal name for debugging. */
     86   const char *name;
     87 
     88   /* Validator method.  */
     89   int (*is_valid) (const struct EXTRACTOR_floatformat *fmt, const void *from);
     90 };
     91 
     92 /* floatformats for IEEE single and double, big and little endian.  */
     93 
     94 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big;
     95 extern const struct EXTRACTOR_floatformat
     96   EXTRACTOR_floatformat_ieee_single_little;
     97 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big;
     98 extern const struct EXTRACTOR_floatformat
     99   EXTRACTOR_floatformat_ieee_double_little;
    100 
    101 /* floatformat for ARM IEEE double, little endian bytes and big endian words */
    102 
    103 extern const struct EXTRACTOR_floatformat
    104   EXTRACTOR_floatformat_ieee_double_littlebyte_bigword;
    105 
    106 /* floatformats for VAX.  */
    107 
    108 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f;
    109 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d;
    110 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g;
    111 
    112 /* floatformats for various extendeds.  */
    113 
    114 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext;
    115 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext;
    116 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext;
    117 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext;
    118 extern const struct EXTRACTOR_floatformat
    119   EXTRACTOR_floatformat_m88110_harris_ext;
    120 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big;
    121 extern const struct EXTRACTOR_floatformat
    122   EXTRACTOR_floatformat_arm_ext_littlebyte_bigword;
    123 /* IA-64 Floating Point register spilt into memory.  */
    124 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big;
    125 extern const struct EXTRACTOR_floatformat
    126   EXTRACTOR_floatformat_ia64_spill_little;
    127 extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big;
    128 extern const struct EXTRACTOR_floatformat
    129   EXTRACTOR_floatformat_ia64_quad_little;
    130 
    131 /* Convert from FMT to a double.
    132    FROM is the address of the extended float.
    133    Store the double in *TO.  */
    134 
    135 extern void
    136 EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *,
    137                                         const void *, double *);
    138 
    139 /* The converse: convert the double *FROM to FMT
    140    and store where TO points.  */
    141 
    142 extern void
    143 EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *,
    144                                           const double *, void *);
    145 
    146 /* Return non-zero iff the data at FROM is a valid number in format FMT.  */
    147 
    148 extern int
    149 EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt,
    150                                        const void *from);
    151 
    152 #endif  /* defined (FLOATFORMAT_H) */