Home | History | Annotate | Line # | Download | only in bfd
ecoffswap.h revision 1.1
      1  1.1  christos /* Generic ECOFF swapping routines, for BFD.
      2  1.1  christos    Copyright 1992, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2004, 2005,
      3  1.1  christos    2007  Free Software Foundation, Inc.
      4  1.1  christos    Written by Cygnus Support.
      5  1.1  christos 
      6  1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      7  1.1  christos 
      8  1.1  christos    This program is free software; you can redistribute it and/or modify
      9  1.1  christos    it under the terms of the GNU General Public License as published by
     10  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     11  1.1  christos    (at your option) any later version.
     12  1.1  christos 
     13  1.1  christos    This program is distributed in the hope that it will be useful,
     14  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  1.1  christos    GNU General Public License for more details.
     17  1.1  christos 
     18  1.1  christos    You should have received a copy of the GNU General Public License
     19  1.1  christos    along with this program; if not, write to the Free Software
     20  1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     21  1.1  christos    MA 02110-1301, USA.  */
     22  1.1  christos 
     23  1.1  christos 
     24  1.1  christos /* NOTE: This is a header file, but it contains executable routines.
     25  1.1  christos    This is done this way because these routines are substantially
     26  1.1  christos    similar, but are not identical, for all ECOFF targets.
     27  1.1  christos 
     28  1.1  christos    These are routines to swap the ECOFF symbolic information in and
     29  1.1  christos    out.  The routines are defined statically.  You can set breakpoints
     30  1.1  christos    on them in gdb by naming the including source file; e.g.,
     31  1.1  christos    'coff-mips.c':ecoff_swap_hdr_in.
     32  1.1  christos 
     33  1.1  christos    Before including this header file, one of ECOFF_32, ECOFF_64,
     34  1.1  christos    ECOFF_SIGNED_32 or ECOFF_SIGNED_64 must be defined.  These are
     35  1.1  christos    checked when swapping information that depends upon the target
     36  1.1  christos    size.  This code works for 32 bit and 64 bit ECOFF, but may need to
     37  1.1  christos    be generalized in the future.
     38  1.1  christos 
     39  1.1  christos    Some header file which defines the external forms of these
     40  1.1  christos    structures must also be included before including this header file.
     41  1.1  christos    Currently this is either coff/mips.h or coff/alpha.h.
     42  1.1  christos 
     43  1.1  christos    If the symbol TEST is defined when this file is compiled, a
     44  1.1  christos    comparison is made to ensure that, in fact, the output is
     45  1.1  christos    bit-for-bit the same as the input.  Of course, this symbol should
     46  1.1  christos    only be defined when deliberately testing the code on a machine
     47  1.1  christos    with the proper byte sex and such.  */
     48  1.1  christos 
     49  1.1  christos #ifdef ECOFF_32
     50  1.1  christos #define ECOFF_GET_OFF H_GET_32
     51  1.1  christos #define ECOFF_PUT_OFF H_PUT_32
     52  1.1  christos #endif
     53  1.1  christos #ifdef ECOFF_64
     54  1.1  christos #define ECOFF_GET_OFF H_GET_64
     55  1.1  christos #define ECOFF_PUT_OFF H_PUT_64
     56  1.1  christos #endif
     57  1.1  christos #ifdef ECOFF_SIGNED_32
     58  1.1  christos #define ECOFF_GET_OFF H_GET_S32
     59  1.1  christos #define ECOFF_PUT_OFF H_PUT_S32
     60  1.1  christos #endif
     61  1.1  christos #ifdef ECOFF_SIGNED_64
     62  1.1  christos #define ECOFF_GET_OFF H_GET_S64
     63  1.1  christos #define ECOFF_PUT_OFF H_PUT_S64
     64  1.1  christos #endif
     65  1.1  christos 
     66  1.1  christos /* ECOFF auxiliary information swapping routines.  These are the same
     67  1.1  christos    for all ECOFF targets, so they are defined in ecofflink.c.  */
     68  1.1  christos 
     69  1.1  christos extern void _bfd_ecoff_swap_tir_in
     70  1.1  christos   (int, const struct tir_ext *, TIR *);
     71  1.1  christos extern void _bfd_ecoff_swap_tir_out
     72  1.1  christos   (int, const TIR *, struct tir_ext *);
     73  1.1  christos extern void _bfd_ecoff_swap_rndx_in
     74  1.1  christos   (int, const struct rndx_ext *, RNDXR *);
     75  1.1  christos extern void _bfd_ecoff_swap_rndx_out
     76  1.1  christos   (int, const RNDXR *, struct rndx_ext *);
     77  1.1  christos 
     78  1.1  christos /* Prototypes for functions defined in this file.  */
     79  1.1  christos 
     80  1.1  christos static void ecoff_swap_hdr_in (bfd *, void *, HDRR *);
     81  1.1  christos static void ecoff_swap_hdr_out (bfd *, const HDRR *, void *);
     82  1.1  christos static void ecoff_swap_fdr_in (bfd *, void *, FDR *);
     83  1.1  christos static void ecoff_swap_fdr_out (bfd *, const FDR *, void *);
     84  1.1  christos static void ecoff_swap_pdr_in (bfd *, void *, PDR *);
     85  1.1  christos static void ecoff_swap_pdr_out (bfd *, const PDR *, void *);
     86  1.1  christos static void ecoff_swap_sym_in (bfd *, void *, SYMR *);
     87  1.1  christos static void ecoff_swap_sym_out (bfd *, const SYMR *, void *);
     88  1.1  christos static void ecoff_swap_ext_in (bfd *, void *, EXTR *);
     89  1.1  christos static void ecoff_swap_ext_out (bfd *, const EXTR *, void *);
     90  1.1  christos static void ecoff_swap_rfd_in (bfd *, void *, RFDT *);
     91  1.1  christos static void ecoff_swap_rfd_out (bfd *, const RFDT *, void *);
     92  1.1  christos static void ecoff_swap_opt_in (bfd *, void *, OPTR *);
     93  1.1  christos static void ecoff_swap_opt_out (bfd *, const OPTR *, void *);
     94  1.1  christos static void ecoff_swap_dnr_in (bfd *, void *, DNR *);
     95  1.1  christos static void ecoff_swap_dnr_out (bfd *, const DNR *, void *);
     96  1.1  christos 
     97  1.1  christos /* Swap in the symbolic header.  */
     98  1.1  christos 
     99  1.1  christos static void
    100  1.1  christos ecoff_swap_hdr_in (bfd *abfd, void * ext_copy, HDRR *intern)
    101  1.1  christos {
    102  1.1  christos   struct hdr_ext ext[1];
    103  1.1  christos 
    104  1.1  christos   *ext = *(struct hdr_ext *) ext_copy;
    105  1.1  christos 
    106  1.1  christos   intern->magic         = H_GET_S16     (abfd, ext->h_magic);
    107  1.1  christos   intern->vstamp        = H_GET_S16     (abfd, ext->h_vstamp);
    108  1.1  christos   intern->ilineMax      = H_GET_32      (abfd, ext->h_ilineMax);
    109  1.1  christos   intern->cbLine        = ECOFF_GET_OFF (abfd, ext->h_cbLine);
    110  1.1  christos   intern->cbLineOffset  = ECOFF_GET_OFF (abfd, ext->h_cbLineOffset);
    111  1.1  christos   intern->idnMax        = H_GET_32      (abfd, ext->h_idnMax);
    112  1.1  christos   intern->cbDnOffset    = ECOFF_GET_OFF (abfd, ext->h_cbDnOffset);
    113  1.1  christos   intern->ipdMax        = H_GET_32      (abfd, ext->h_ipdMax);
    114  1.1  christos   intern->cbPdOffset    = ECOFF_GET_OFF (abfd, ext->h_cbPdOffset);
    115  1.1  christos   intern->isymMax       = H_GET_32      (abfd, ext->h_isymMax);
    116  1.1  christos   intern->cbSymOffset   = ECOFF_GET_OFF (abfd, ext->h_cbSymOffset);
    117  1.1  christos   intern->ioptMax       = H_GET_32      (abfd, ext->h_ioptMax);
    118  1.1  christos   intern->cbOptOffset   = ECOFF_GET_OFF (abfd, ext->h_cbOptOffset);
    119  1.1  christos   intern->iauxMax       = H_GET_32      (abfd, ext->h_iauxMax);
    120  1.1  christos   intern->cbAuxOffset   = ECOFF_GET_OFF (abfd, ext->h_cbAuxOffset);
    121  1.1  christos   intern->issMax        = H_GET_32      (abfd, ext->h_issMax);
    122  1.1  christos   intern->cbSsOffset    = ECOFF_GET_OFF (abfd, ext->h_cbSsOffset);
    123  1.1  christos   intern->issExtMax     = H_GET_32      (abfd, ext->h_issExtMax);
    124  1.1  christos   intern->cbSsExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsExtOffset);
    125  1.1  christos   intern->ifdMax        = H_GET_32      (abfd, ext->h_ifdMax);
    126  1.1  christos   intern->cbFdOffset    = ECOFF_GET_OFF (abfd, ext->h_cbFdOffset);
    127  1.1  christos   intern->crfd          = H_GET_32      (abfd, ext->h_crfd);
    128  1.1  christos   intern->cbRfdOffset   = ECOFF_GET_OFF (abfd, ext->h_cbRfdOffset);
    129  1.1  christos   intern->iextMax       = H_GET_32      (abfd, ext->h_iextMax);
    130  1.1  christos   intern->cbExtOffset   = ECOFF_GET_OFF (abfd, ext->h_cbExtOffset);
    131  1.1  christos 
    132  1.1  christos #ifdef TEST
    133  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    134  1.1  christos     abort ();
    135  1.1  christos #endif
    136  1.1  christos }
    137  1.1  christos 
    138  1.1  christos /* Swap out the symbolic header.  */
    139  1.1  christos 
    140  1.1  christos static void
    141  1.1  christos ecoff_swap_hdr_out (bfd *abfd, const HDRR *intern_copy, void * ext_ptr)
    142  1.1  christos {
    143  1.1  christos   struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
    144  1.1  christos   HDRR intern[1];
    145  1.1  christos 
    146  1.1  christos   *intern = *intern_copy;
    147  1.1  christos 
    148  1.1  christos   H_PUT_S16     (abfd, intern->magic,         ext->h_magic);
    149  1.1  christos   H_PUT_S16     (abfd, intern->vstamp,        ext->h_vstamp);
    150  1.1  christos   H_PUT_32      (abfd, intern->ilineMax,      ext->h_ilineMax);
    151  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbLine,        ext->h_cbLine);
    152  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbLineOffset,  ext->h_cbLineOffset);
    153  1.1  christos   H_PUT_32      (abfd, intern->idnMax,        ext->h_idnMax);
    154  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbDnOffset,    ext->h_cbDnOffset);
    155  1.1  christos   H_PUT_32      (abfd, intern->ipdMax,        ext->h_ipdMax);
    156  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbPdOffset,    ext->h_cbPdOffset);
    157  1.1  christos   H_PUT_32      (abfd, intern->isymMax,       ext->h_isymMax);
    158  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbSymOffset,   ext->h_cbSymOffset);
    159  1.1  christos   H_PUT_32      (abfd, intern->ioptMax,       ext->h_ioptMax);
    160  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbOptOffset,   ext->h_cbOptOffset);
    161  1.1  christos   H_PUT_32      (abfd, intern->iauxMax,       ext->h_iauxMax);
    162  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbAuxOffset,   ext->h_cbAuxOffset);
    163  1.1  christos   H_PUT_32      (abfd, intern->issMax,        ext->h_issMax);
    164  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbSsOffset,    ext->h_cbSsOffset);
    165  1.1  christos   H_PUT_32      (abfd, intern->issExtMax,     ext->h_issExtMax);
    166  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbSsExtOffset, ext->h_cbSsExtOffset);
    167  1.1  christos   H_PUT_32      (abfd, intern->ifdMax,        ext->h_ifdMax);
    168  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbFdOffset,    ext->h_cbFdOffset);
    169  1.1  christos   H_PUT_32      (abfd, intern->crfd,          ext->h_crfd);
    170  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbRfdOffset,   ext->h_cbRfdOffset);
    171  1.1  christos   H_PUT_32      (abfd, intern->iextMax,       ext->h_iextMax);
    172  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbExtOffset,   ext->h_cbExtOffset);
    173  1.1  christos 
    174  1.1  christos #ifdef TEST
    175  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    176  1.1  christos     abort ();
    177  1.1  christos #endif
    178  1.1  christos }
    179  1.1  christos 
    180  1.1  christos /* Swap in the file descriptor record.  */
    181  1.1  christos 
    182  1.1  christos static void
    183  1.1  christos ecoff_swap_fdr_in (bfd *abfd, void * ext_copy, FDR *intern)
    184  1.1  christos {
    185  1.1  christos   struct fdr_ext ext[1];
    186  1.1  christos 
    187  1.1  christos   *ext = *(struct fdr_ext *) ext_copy;
    188  1.1  christos 
    189  1.1  christos   intern->adr           = ECOFF_GET_OFF (abfd, ext->f_adr);
    190  1.1  christos   intern->rss           = H_GET_32 (abfd, ext->f_rss);
    191  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    192  1.1  christos   if (intern->rss == (signed long) 0xffffffff)
    193  1.1  christos     intern->rss = -1;
    194  1.1  christos #endif
    195  1.1  christos   intern->issBase       = H_GET_32 (abfd, ext->f_issBase);
    196  1.1  christos   intern->cbSs          = ECOFF_GET_OFF (abfd, ext->f_cbSs);
    197  1.1  christos   intern->isymBase      = H_GET_32 (abfd, ext->f_isymBase);
    198  1.1  christos   intern->csym          = H_GET_32 (abfd, ext->f_csym);
    199  1.1  christos   intern->ilineBase     = H_GET_32 (abfd, ext->f_ilineBase);
    200  1.1  christos   intern->cline         = H_GET_32 (abfd, ext->f_cline);
    201  1.1  christos   intern->ioptBase      = H_GET_32 (abfd, ext->f_ioptBase);
    202  1.1  christos   intern->copt          = H_GET_32 (abfd, ext->f_copt);
    203  1.1  christos #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    204  1.1  christos   intern->ipdFirst      = H_GET_16 (abfd, ext->f_ipdFirst);
    205  1.1  christos   intern->cpd           = H_GET_16 (abfd, ext->f_cpd);
    206  1.1  christos #endif
    207  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    208  1.1  christos   intern->ipdFirst      = H_GET_32 (abfd, ext->f_ipdFirst);
    209  1.1  christos   intern->cpd           = H_GET_32 (abfd, ext->f_cpd);
    210  1.1  christos #endif
    211  1.1  christos   intern->iauxBase      = H_GET_32 (abfd, ext->f_iauxBase);
    212  1.1  christos   intern->caux          = H_GET_32 (abfd, ext->f_caux);
    213  1.1  christos   intern->rfdBase       = H_GET_32 (abfd, ext->f_rfdBase);
    214  1.1  christos   intern->crfd          = H_GET_32 (abfd, ext->f_crfd);
    215  1.1  christos 
    216  1.1  christos   /* Now the fun stuff...  */
    217  1.1  christos   if (bfd_header_big_endian (abfd))
    218  1.1  christos     {
    219  1.1  christos       intern->lang       = ((ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
    220  1.1  christos 			    >> FDR_BITS1_LANG_SH_BIG);
    221  1.1  christos       intern->fMerge     = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
    222  1.1  christos       intern->fReadin    = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
    223  1.1  christos       intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
    224  1.1  christos       intern->glevel     = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
    225  1.1  christos 			    >> FDR_BITS2_GLEVEL_SH_BIG);
    226  1.1  christos     }
    227  1.1  christos   else
    228  1.1  christos     {
    229  1.1  christos       intern->lang       = ((ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
    230  1.1  christos 			    >> FDR_BITS1_LANG_SH_LITTLE);
    231  1.1  christos       intern->fMerge     = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
    232  1.1  christos       intern->fReadin    = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
    233  1.1  christos       intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
    234  1.1  christos       intern->glevel     = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
    235  1.1  christos 			    >> FDR_BITS2_GLEVEL_SH_LITTLE);
    236  1.1  christos     }
    237  1.1  christos   intern->reserved = 0;
    238  1.1  christos 
    239  1.1  christos   intern->cbLineOffset  = ECOFF_GET_OFF (abfd, ext->f_cbLineOffset);
    240  1.1  christos   intern->cbLine        = ECOFF_GET_OFF (abfd, ext->f_cbLine);
    241  1.1  christos 
    242  1.1  christos #ifdef TEST
    243  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    244  1.1  christos     abort ();
    245  1.1  christos #endif
    246  1.1  christos }
    247  1.1  christos 
    248  1.1  christos /* Swap out the file descriptor record.  */
    249  1.1  christos 
    250  1.1  christos static void
    251  1.1  christos ecoff_swap_fdr_out (bfd *abfd, const FDR *intern_copy, void * ext_ptr)
    252  1.1  christos {
    253  1.1  christos   struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
    254  1.1  christos   FDR intern[1];
    255  1.1  christos 
    256  1.1  christos   /* Make it reasonable to do in-place.  */
    257  1.1  christos   *intern = *intern_copy;
    258  1.1  christos 
    259  1.1  christos   ECOFF_PUT_OFF (abfd, intern->adr,       ext->f_adr);
    260  1.1  christos   H_PUT_32      (abfd, intern->rss,       ext->f_rss);
    261  1.1  christos   H_PUT_32      (abfd, intern->issBase,   ext->f_issBase);
    262  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbSs,      ext->f_cbSs);
    263  1.1  christos   H_PUT_32      (abfd, intern->isymBase,  ext->f_isymBase);
    264  1.1  christos   H_PUT_32      (abfd, intern->csym,      ext->f_csym);
    265  1.1  christos   H_PUT_32      (abfd, intern->ilineBase, ext->f_ilineBase);
    266  1.1  christos   H_PUT_32      (abfd, intern->cline,     ext->f_cline);
    267  1.1  christos   H_PUT_32      (abfd, intern->ioptBase,  ext->f_ioptBase);
    268  1.1  christos   H_PUT_32      (abfd, intern->copt,      ext->f_copt);
    269  1.1  christos #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    270  1.1  christos   H_PUT_16      (abfd, intern->ipdFirst,  ext->f_ipdFirst);
    271  1.1  christos   H_PUT_16      (abfd, intern->cpd,       ext->f_cpd);
    272  1.1  christos #endif
    273  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    274  1.1  christos   H_PUT_32      (abfd, intern->ipdFirst,  ext->f_ipdFirst);
    275  1.1  christos   H_PUT_32      (abfd, intern->cpd,       ext->f_cpd);
    276  1.1  christos #endif
    277  1.1  christos   H_PUT_32      (abfd, intern->iauxBase,  ext->f_iauxBase);
    278  1.1  christos   H_PUT_32      (abfd, intern->caux,      ext->f_caux);
    279  1.1  christos   H_PUT_32      (abfd, intern->rfdBase,   ext->f_rfdBase);
    280  1.1  christos   H_PUT_32      (abfd, intern->crfd,      ext->f_crfd);
    281  1.1  christos 
    282  1.1  christos   /* Now the fun stuff...  */
    283  1.1  christos   if (bfd_header_big_endian (abfd))
    284  1.1  christos     {
    285  1.1  christos       ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
    286  1.1  christos 			  & FDR_BITS1_LANG_BIG)
    287  1.1  christos 			 | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
    288  1.1  christos 			 | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
    289  1.1  christos 			 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
    290  1.1  christos       ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
    291  1.1  christos 			 & FDR_BITS2_GLEVEL_BIG);
    292  1.1  christos       ext->f_bits2[1] = 0;
    293  1.1  christos       ext->f_bits2[2] = 0;
    294  1.1  christos     }
    295  1.1  christos   else
    296  1.1  christos     {
    297  1.1  christos       ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
    298  1.1  christos 			  & FDR_BITS1_LANG_LITTLE)
    299  1.1  christos 			 | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
    300  1.1  christos 			 | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
    301  1.1  christos 			 | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
    302  1.1  christos       ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
    303  1.1  christos 			 & FDR_BITS2_GLEVEL_LITTLE);
    304  1.1  christos       ext->f_bits2[1] = 0;
    305  1.1  christos       ext->f_bits2[2] = 0;
    306  1.1  christos     }
    307  1.1  christos 
    308  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->f_cbLineOffset);
    309  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbLine, ext->f_cbLine);
    310  1.1  christos 
    311  1.1  christos #ifdef TEST
    312  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    313  1.1  christos     abort ();
    314  1.1  christos #endif
    315  1.1  christos }
    316  1.1  christos 
    317  1.1  christos /* Swap in the procedure descriptor record.  */
    318  1.1  christos 
    319  1.1  christos static void
    320  1.1  christos ecoff_swap_pdr_in (bfd *abfd, void * ext_copy, PDR *intern)
    321  1.1  christos {
    322  1.1  christos   struct pdr_ext ext[1];
    323  1.1  christos 
    324  1.1  christos   *ext = *(struct pdr_ext *) ext_copy;
    325  1.1  christos 
    326  1.1  christos   memset ((void *) intern, 0, sizeof (*intern));
    327  1.1  christos 
    328  1.1  christos   intern->adr           = ECOFF_GET_OFF (abfd, ext->p_adr);
    329  1.1  christos   intern->isym          = H_GET_32 (abfd, ext->p_isym);
    330  1.1  christos   intern->iline         = H_GET_32 (abfd, ext->p_iline);
    331  1.1  christos   intern->regmask       = H_GET_32 (abfd, ext->p_regmask);
    332  1.1  christos   intern->regoffset     = H_GET_S32 (abfd, ext->p_regoffset);
    333  1.1  christos   intern->iopt          = H_GET_S32 (abfd, ext->p_iopt);
    334  1.1  christos   intern->fregmask      = H_GET_32 (abfd, ext->p_fregmask);
    335  1.1  christos   intern->fregoffset    = H_GET_S32 (abfd, ext->p_fregoffset);
    336  1.1  christos   intern->frameoffset   = H_GET_S32 (abfd, ext->p_frameoffset);
    337  1.1  christos   intern->framereg      = H_GET_16 (abfd, ext->p_framereg);
    338  1.1  christos   intern->pcreg         = H_GET_16 (abfd, ext->p_pcreg);
    339  1.1  christos   intern->lnLow         = H_GET_32 (abfd, ext->p_lnLow);
    340  1.1  christos   intern->lnHigh        = H_GET_32 (abfd, ext->p_lnHigh);
    341  1.1  christos   intern->cbLineOffset  = ECOFF_GET_OFF (abfd, ext->p_cbLineOffset);
    342  1.1  christos 
    343  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    344  1.1  christos   if (intern->isym == (signed long) 0xffffffff)
    345  1.1  christos     intern->isym = -1;
    346  1.1  christos   if (intern->iline == (signed long) 0xffffffff)
    347  1.1  christos     intern->iline = -1;
    348  1.1  christos 
    349  1.1  christos   intern->gp_prologue = H_GET_8 (abfd, ext->p_gp_prologue);
    350  1.1  christos   if (bfd_header_big_endian (abfd))
    351  1.1  christos     {
    352  1.1  christos       intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
    353  1.1  christos       intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
    354  1.1  christos       intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
    355  1.1  christos       intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
    356  1.1  christos 			   << PDR_BITS1_RESERVED_SH_LEFT_BIG)
    357  1.1  christos 			  | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
    358  1.1  christos 			     >> PDR_BITS2_RESERVED_SH_BIG));
    359  1.1  christos     }
    360  1.1  christos   else
    361  1.1  christos     {
    362  1.1  christos       intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
    363  1.1  christos       intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
    364  1.1  christos       intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
    365  1.1  christos       intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
    366  1.1  christos 			   >> PDR_BITS1_RESERVED_SH_LITTLE)
    367  1.1  christos 			  | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
    368  1.1  christos 			     << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
    369  1.1  christos     }
    370  1.1  christos   intern->localoff = H_GET_8 (abfd, ext->p_localoff);
    371  1.1  christos #endif
    372  1.1  christos 
    373  1.1  christos #ifdef TEST
    374  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    375  1.1  christos     abort ();
    376  1.1  christos #endif
    377  1.1  christos }
    378  1.1  christos 
    379  1.1  christos /* Swap out the procedure descriptor record.  */
    380  1.1  christos 
    381  1.1  christos static void
    382  1.1  christos ecoff_swap_pdr_out (bfd *abfd, const PDR *intern_copy, void * ext_ptr)
    383  1.1  christos {
    384  1.1  christos   struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
    385  1.1  christos   PDR intern[1];
    386  1.1  christos 
    387  1.1  christos   /* Make it reasonable to do in-place.  */
    388  1.1  christos   *intern = *intern_copy;
    389  1.1  christos 
    390  1.1  christos   ECOFF_PUT_OFF (abfd, intern->adr,          ext->p_adr);
    391  1.1  christos   H_PUT_32      (abfd, intern->isym,         ext->p_isym);
    392  1.1  christos   H_PUT_32      (abfd, intern->iline,        ext->p_iline);
    393  1.1  christos   H_PUT_32      (abfd, intern->regmask,      ext->p_regmask);
    394  1.1  christos   H_PUT_32      (abfd, intern->regoffset,    ext->p_regoffset);
    395  1.1  christos   H_PUT_32      (abfd, intern->iopt,         ext->p_iopt);
    396  1.1  christos   H_PUT_32      (abfd, intern->fregmask,     ext->p_fregmask);
    397  1.1  christos   H_PUT_32      (abfd, intern->fregoffset,   ext->p_fregoffset);
    398  1.1  christos   H_PUT_32      (abfd, intern->frameoffset,  ext->p_frameoffset);
    399  1.1  christos   H_PUT_16      (abfd, intern->framereg,     ext->p_framereg);
    400  1.1  christos   H_PUT_16      (abfd, intern->pcreg,        ext->p_pcreg);
    401  1.1  christos   H_PUT_32      (abfd, intern->lnLow,        ext->p_lnLow);
    402  1.1  christos   H_PUT_32      (abfd, intern->lnHigh,       ext->p_lnHigh);
    403  1.1  christos   ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->p_cbLineOffset);
    404  1.1  christos 
    405  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    406  1.1  christos   H_PUT_8       (abfd, intern->gp_prologue,  ext->p_gp_prologue);
    407  1.1  christos 
    408  1.1  christos   if (bfd_header_big_endian (abfd))
    409  1.1  christos     {
    410  1.1  christos       ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
    411  1.1  christos 			 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
    412  1.1  christos 			 | (intern->prof ? PDR_BITS1_PROF_BIG : 0)
    413  1.1  christos 			 | ((intern->reserved
    414  1.1  christos 			     >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
    415  1.1  christos 			    & PDR_BITS1_RESERVED_BIG));
    416  1.1  christos       ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
    417  1.1  christos 			 & PDR_BITS2_RESERVED_BIG);
    418  1.1  christos     }
    419  1.1  christos   else
    420  1.1  christos     {
    421  1.1  christos       ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
    422  1.1  christos 			 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
    423  1.1  christos 			 | (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
    424  1.1  christos 			 | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
    425  1.1  christos 			    & PDR_BITS1_RESERVED_LITTLE));
    426  1.1  christos       ext->p_bits2[0] = ((intern->reserved >>
    427  1.1  christos 			  PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
    428  1.1  christos 			 & PDR_BITS2_RESERVED_LITTLE);
    429  1.1  christos     }
    430  1.1  christos   H_PUT_8 (abfd, intern->localoff, ext->p_localoff);
    431  1.1  christos #endif
    432  1.1  christos 
    433  1.1  christos #ifdef TEST
    434  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    435  1.1  christos     abort ();
    436  1.1  christos #endif
    437  1.1  christos }
    438  1.1  christos 
    439  1.1  christos /* Swap in a symbol record.  */
    440  1.1  christos 
    441  1.1  christos static void
    442  1.1  christos ecoff_swap_sym_in (bfd *abfd, void * ext_copy, SYMR *intern)
    443  1.1  christos {
    444  1.1  christos   struct sym_ext ext[1];
    445  1.1  christos 
    446  1.1  christos   *ext = *(struct sym_ext *) ext_copy;
    447  1.1  christos 
    448  1.1  christos   intern->iss           = H_GET_32 (abfd, ext->s_iss);
    449  1.1  christos   intern->value         = ECOFF_GET_OFF (abfd, ext->s_value);
    450  1.1  christos 
    451  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    452  1.1  christos   if (intern->iss == (signed long) 0xffffffff)
    453  1.1  christos     intern->iss = -1;
    454  1.1  christos #endif
    455  1.1  christos 
    456  1.1  christos   /* Now the fun stuff...  */
    457  1.1  christos   if (bfd_header_big_endian (abfd))
    458  1.1  christos     {
    459  1.1  christos       intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
    460  1.1  christos 					     >> SYM_BITS1_ST_SH_BIG;
    461  1.1  christos       intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
    462  1.1  christos 					     << SYM_BITS1_SC_SH_LEFT_BIG)
    463  1.1  christos 			  | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
    464  1.1  christos 					     >> SYM_BITS2_SC_SH_BIG);
    465  1.1  christos       intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
    466  1.1  christos       intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
    467  1.1  christos 					     << SYM_BITS2_INDEX_SH_LEFT_BIG)
    468  1.1  christos 			  | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
    469  1.1  christos 			  | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
    470  1.1  christos     }
    471  1.1  christos   else
    472  1.1  christos     {
    473  1.1  christos       intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
    474  1.1  christos 					     >> SYM_BITS1_ST_SH_LITTLE;
    475  1.1  christos       intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
    476  1.1  christos 					     >> SYM_BITS1_SC_SH_LITTLE)
    477  1.1  christos 			  | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
    478  1.1  christos 					     << SYM_BITS2_SC_SH_LEFT_LITTLE);
    479  1.1  christos       intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
    480  1.1  christos       intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
    481  1.1  christos 					     >> SYM_BITS2_INDEX_SH_LITTLE)
    482  1.1  christos 			  | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
    483  1.1  christos 			  | ((unsigned int) ext->s_bits4[0]
    484  1.1  christos 			     << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
    485  1.1  christos     }
    486  1.1  christos 
    487  1.1  christos #ifdef TEST
    488  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    489  1.1  christos     abort ();
    490  1.1  christos #endif
    491  1.1  christos }
    492  1.1  christos 
    493  1.1  christos /* Swap out a symbol record.  */
    494  1.1  christos 
    495  1.1  christos static void
    496  1.1  christos ecoff_swap_sym_out (bfd *abfd, const SYMR *intern_copy, void * ext_ptr)
    497  1.1  christos {
    498  1.1  christos   struct sym_ext *ext = (struct sym_ext *) ext_ptr;
    499  1.1  christos   SYMR intern[1];
    500  1.1  christos 
    501  1.1  christos   /* Make it reasonable to do in-place.  */
    502  1.1  christos   *intern = *intern_copy;
    503  1.1  christos 
    504  1.1  christos   H_PUT_32 (abfd, intern->iss, ext->s_iss);
    505  1.1  christos   ECOFF_PUT_OFF (abfd, intern->value, ext->s_value);
    506  1.1  christos 
    507  1.1  christos   /* Now the fun stuff...  */
    508  1.1  christos   if (bfd_header_big_endian (abfd))
    509  1.1  christos     {
    510  1.1  christos       ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
    511  1.1  christos 			  & SYM_BITS1_ST_BIG)
    512  1.1  christos 			 | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
    513  1.1  christos 			    & SYM_BITS1_SC_BIG));
    514  1.1  christos       ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
    515  1.1  christos 			  & SYM_BITS2_SC_BIG)
    516  1.1  christos 			 | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
    517  1.1  christos 			 | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
    518  1.1  christos 			    & SYM_BITS2_INDEX_BIG));
    519  1.1  christos       ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
    520  1.1  christos       ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
    521  1.1  christos     }
    522  1.1  christos   else
    523  1.1  christos     {
    524  1.1  christos       ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
    525  1.1  christos 			  & SYM_BITS1_ST_LITTLE)
    526  1.1  christos 			 | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
    527  1.1  christos 			    & SYM_BITS1_SC_LITTLE));
    528  1.1  christos       ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
    529  1.1  christos 			  & SYM_BITS2_SC_LITTLE)
    530  1.1  christos 			 | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
    531  1.1  christos 			 | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
    532  1.1  christos 			    & SYM_BITS2_INDEX_LITTLE));
    533  1.1  christos       ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
    534  1.1  christos       ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
    535  1.1  christos     }
    536  1.1  christos 
    537  1.1  christos #ifdef TEST
    538  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    539  1.1  christos     abort ();
    540  1.1  christos #endif
    541  1.1  christos }
    542  1.1  christos 
    543  1.1  christos /* Swap in an external symbol record.  */
    544  1.1  christos 
    545  1.1  christos static void
    546  1.1  christos ecoff_swap_ext_in (bfd *abfd, void * ext_copy, EXTR *intern)
    547  1.1  christos {
    548  1.1  christos   struct ext_ext ext[1];
    549  1.1  christos 
    550  1.1  christos   *ext = *(struct ext_ext *) ext_copy;
    551  1.1  christos 
    552  1.1  christos   /* Now the fun stuff...  */
    553  1.1  christos   if (bfd_header_big_endian (abfd))
    554  1.1  christos     {
    555  1.1  christos       intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
    556  1.1  christos       intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
    557  1.1  christos       intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
    558  1.1  christos     }
    559  1.1  christos   else
    560  1.1  christos     {
    561  1.1  christos       intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
    562  1.1  christos       intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
    563  1.1  christos       intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
    564  1.1  christos     }
    565  1.1  christos   intern->reserved = 0;
    566  1.1  christos 
    567  1.1  christos #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    568  1.1  christos   intern->ifd = H_GET_S16 (abfd, ext->es_ifd);
    569  1.1  christos #endif
    570  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    571  1.1  christos   intern->ifd = H_GET_S32 (abfd, ext->es_ifd);
    572  1.1  christos #endif
    573  1.1  christos 
    574  1.1  christos   ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
    575  1.1  christos 
    576  1.1  christos #ifdef TEST
    577  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    578  1.1  christos     abort ();
    579  1.1  christos #endif
    580  1.1  christos }
    581  1.1  christos 
    582  1.1  christos /* Swap out an external symbol record.  */
    583  1.1  christos 
    584  1.1  christos static void
    585  1.1  christos ecoff_swap_ext_out (bfd *abfd, const EXTR *intern_copy, void * ext_ptr)
    586  1.1  christos {
    587  1.1  christos   struct ext_ext *ext = (struct ext_ext *) ext_ptr;
    588  1.1  christos   EXTR intern[1];
    589  1.1  christos 
    590  1.1  christos   /* Make it reasonable to do in-place.  */
    591  1.1  christos   *intern = *intern_copy;
    592  1.1  christos 
    593  1.1  christos   /* Now the fun stuff...  */
    594  1.1  christos   if (bfd_header_big_endian (abfd))
    595  1.1  christos     {
    596  1.1  christos       ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
    597  1.1  christos 			  | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
    598  1.1  christos 			  | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
    599  1.1  christos       ext->es_bits2[0] = 0;
    600  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    601  1.1  christos       ext->es_bits2[1] = 0;
    602  1.1  christos       ext->es_bits2[2] = 0;
    603  1.1  christos #endif
    604  1.1  christos     }
    605  1.1  christos   else
    606  1.1  christos     {
    607  1.1  christos       ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
    608  1.1  christos 			  | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
    609  1.1  christos 			  | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
    610  1.1  christos       ext->es_bits2[0] = 0;
    611  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    612  1.1  christos       ext->es_bits2[1] = 0;
    613  1.1  christos       ext->es_bits2[2] = 0;
    614  1.1  christos #endif
    615  1.1  christos     }
    616  1.1  christos 
    617  1.1  christos #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
    618  1.1  christos   H_PUT_S16 (abfd, intern->ifd, ext->es_ifd);
    619  1.1  christos #endif
    620  1.1  christos #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
    621  1.1  christos   H_PUT_S32 (abfd, intern->ifd, ext->es_ifd);
    622  1.1  christos #endif
    623  1.1  christos 
    624  1.1  christos   ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
    625  1.1  christos 
    626  1.1  christos #ifdef TEST
    627  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    628  1.1  christos     abort ();
    629  1.1  christos #endif
    630  1.1  christos }
    631  1.1  christos 
    632  1.1  christos /* Swap in a relative file descriptor.  */
    633  1.1  christos 
    634  1.1  christos static void
    635  1.1  christos ecoff_swap_rfd_in (bfd *abfd, void * ext_ptr, RFDT *intern)
    636  1.1  christos {
    637  1.1  christos   struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
    638  1.1  christos 
    639  1.1  christos   *intern = H_GET_32 (abfd, ext->rfd);
    640  1.1  christos 
    641  1.1  christos #ifdef TEST
    642  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    643  1.1  christos     abort ();
    644  1.1  christos #endif
    645  1.1  christos }
    646  1.1  christos 
    647  1.1  christos /* Swap out a relative file descriptor.  */
    648  1.1  christos 
    649  1.1  christos static void
    650  1.1  christos ecoff_swap_rfd_out (bfd *abfd, const RFDT *intern, void * ext_ptr)
    651  1.1  christos {
    652  1.1  christos   struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
    653  1.1  christos 
    654  1.1  christos   H_PUT_32 (abfd, *intern, ext->rfd);
    655  1.1  christos 
    656  1.1  christos #ifdef TEST
    657  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    658  1.1  christos     abort ();
    659  1.1  christos #endif
    660  1.1  christos }
    661  1.1  christos 
    662  1.1  christos /* Swap in an optimization symbol.  */
    663  1.1  christos 
    664  1.1  christos static void
    665  1.1  christos ecoff_swap_opt_in (bfd *abfd, void * ext_copy, OPTR * intern)
    666  1.1  christos {
    667  1.1  christos   struct opt_ext ext[1];
    668  1.1  christos 
    669  1.1  christos   *ext = *(struct opt_ext *) ext_copy;
    670  1.1  christos 
    671  1.1  christos   if (bfd_header_big_endian (abfd))
    672  1.1  christos     {
    673  1.1  christos       intern->ot = ext->o_bits1[0];
    674  1.1  christos       intern->value = (((unsigned int) ext->o_bits2[0]
    675  1.1  christos 			<< OPT_BITS2_VALUE_SH_LEFT_BIG)
    676  1.1  christos 		       | ((unsigned int) ext->o_bits3[0]
    677  1.1  christos 			  << OPT_BITS2_VALUE_SH_LEFT_BIG)
    678  1.1  christos 		       | ((unsigned int) ext->o_bits4[0]
    679  1.1  christos 			  << OPT_BITS2_VALUE_SH_LEFT_BIG));
    680  1.1  christos     }
    681  1.1  christos   else
    682  1.1  christos     {
    683  1.1  christos       intern->ot = ext->o_bits1[0];
    684  1.1  christos       intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
    685  1.1  christos 		       | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
    686  1.1  christos 		       | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
    687  1.1  christos     }
    688  1.1  christos 
    689  1.1  christos   _bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
    690  1.1  christos 			   &ext->o_rndx, &intern->rndx);
    691  1.1  christos 
    692  1.1  christos   intern->offset = H_GET_32 (abfd, ext->o_offset);
    693  1.1  christos 
    694  1.1  christos #ifdef TEST
    695  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    696  1.1  christos     abort ();
    697  1.1  christos #endif
    698  1.1  christos }
    699  1.1  christos 
    700  1.1  christos /* Swap out an optimization symbol.  */
    701  1.1  christos 
    702  1.1  christos static void
    703  1.1  christos ecoff_swap_opt_out (bfd *abfd, const OPTR *intern_copy, void * ext_ptr)
    704  1.1  christos {
    705  1.1  christos   struct opt_ext *ext = (struct opt_ext *) ext_ptr;
    706  1.1  christos   OPTR intern[1];
    707  1.1  christos 
    708  1.1  christos   /* Make it reasonable to do in-place.  */
    709  1.1  christos   *intern = *intern_copy;
    710  1.1  christos 
    711  1.1  christos   if (bfd_header_big_endian (abfd))
    712  1.1  christos     {
    713  1.1  christos       ext->o_bits1[0] = intern->ot;
    714  1.1  christos       ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
    715  1.1  christos       ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
    716  1.1  christos       ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
    717  1.1  christos     }
    718  1.1  christos   else
    719  1.1  christos     {
    720  1.1  christos       ext->o_bits1[0] = intern->ot;
    721  1.1  christos       ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
    722  1.1  christos       ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
    723  1.1  christos       ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
    724  1.1  christos     }
    725  1.1  christos 
    726  1.1  christos   _bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
    727  1.1  christos 			    &intern->rndx, &ext->o_rndx);
    728  1.1  christos 
    729  1.1  christos   H_PUT_32 (abfd, intern->value, ext->o_offset);
    730  1.1  christos 
    731  1.1  christos #ifdef TEST
    732  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    733  1.1  christos     abort ();
    734  1.1  christos #endif
    735  1.1  christos }
    736  1.1  christos 
    737  1.1  christos /* Swap in a dense number.  */
    738  1.1  christos 
    739  1.1  christos static void
    740  1.1  christos ecoff_swap_dnr_in (bfd *abfd, void * ext_copy, DNR *intern)
    741  1.1  christos {
    742  1.1  christos   struct dnr_ext ext[1];
    743  1.1  christos 
    744  1.1  christos   *ext = *(struct dnr_ext *) ext_copy;
    745  1.1  christos 
    746  1.1  christos   intern->rfd = H_GET_32 (abfd, ext->d_rfd);
    747  1.1  christos   intern->index = H_GET_32 (abfd, ext->d_index);
    748  1.1  christos 
    749  1.1  christos #ifdef TEST
    750  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    751  1.1  christos     abort ();
    752  1.1  christos #endif
    753  1.1  christos }
    754  1.1  christos 
    755  1.1  christos /* Swap out a dense number.  */
    756  1.1  christos 
    757  1.1  christos static void
    758  1.1  christos ecoff_swap_dnr_out (bfd *abfd, const DNR *intern_copy, void * ext_ptr)
    759  1.1  christos {
    760  1.1  christos   struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
    761  1.1  christos   DNR intern[1];
    762  1.1  christos 
    763  1.1  christos   /* Make it reasonable to do in-place.  */
    764  1.1  christos   *intern = *intern_copy;
    765  1.1  christos 
    766  1.1  christos   H_PUT_32 (abfd, intern->rfd, ext->d_rfd);
    767  1.1  christos   H_PUT_32 (abfd, intern->index, ext->d_index);
    768  1.1  christos 
    769  1.1  christos #ifdef TEST
    770  1.1  christos   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
    771  1.1  christos     abort ();
    772  1.1  christos #endif
    773  1.1  christos }
    774