Back to index

cell-binutils  2.17cvs20070401
ecoffswap.h
Go to the documentation of this file.
00001 /* Generic ECOFF swapping routines, for BFD.
00002    Copyright 1992, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2004, 2005
00003    Free Software Foundation, Inc.
00004    Written by Cygnus Support.
00005 
00006    This file is part of BFD, the Binary File Descriptor library.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00021 
00022 /* NOTE: This is a header file, but it contains executable routines.
00023    This is done this way because these routines are substantially
00024    similar, but are not identical, for all ECOFF targets.
00025 
00026    These are routines to swap the ECOFF symbolic information in and
00027    out.  The routines are defined statically.  You can set breakpoints
00028    on them in gdb by naming the including source file; e.g.,
00029    'coff-mips.c':ecoff_swap_hdr_in.
00030 
00031    Before including this header file, one of ECOFF_32, ECOFF_64,
00032    ECOFF_SIGNED_32 or ECOFF_SIGNED_64 must be defined.  These are
00033    checked when swapping information that depends upon the target
00034    size.  This code works for 32 bit and 64 bit ECOFF, but may need to
00035    be generalized in the future.
00036 
00037    Some header file which defines the external forms of these
00038    structures must also be included before including this header file.
00039    Currently this is either coff/mips.h or coff/alpha.h.
00040 
00041    If the symbol TEST is defined when this file is compiled, a
00042    comparison is made to ensure that, in fact, the output is
00043    bit-for-bit the same as the input.  Of course, this symbol should
00044    only be defined when deliberately testing the code on a machine
00045    with the proper byte sex and such.  */
00046 
00047 #ifdef ECOFF_32
00048 #define ECOFF_GET_OFF H_GET_32
00049 #define ECOFF_PUT_OFF H_PUT_32
00050 #endif
00051 #ifdef ECOFF_64
00052 #define ECOFF_GET_OFF H_GET_64
00053 #define ECOFF_PUT_OFF H_PUT_64
00054 #endif
00055 #ifdef ECOFF_SIGNED_32
00056 #define ECOFF_GET_OFF H_GET_S32
00057 #define ECOFF_PUT_OFF H_PUT_S32
00058 #endif
00059 #ifdef ECOFF_SIGNED_64
00060 #define ECOFF_GET_OFF H_GET_S64
00061 #define ECOFF_PUT_OFF H_PUT_S64
00062 #endif
00063 
00064 /* ECOFF auxiliary information swapping routines.  These are the same
00065    for all ECOFF targets, so they are defined in ecofflink.c.  */
00066 
00067 extern void _bfd_ecoff_swap_tir_in
00068   (int, const struct tir_ext *, TIR *);
00069 extern void _bfd_ecoff_swap_tir_out
00070   (int, const TIR *, struct tir_ext *);
00071 extern void _bfd_ecoff_swap_rndx_in
00072   (int, const struct rndx_ext *, RNDXR *);
00073 extern void _bfd_ecoff_swap_rndx_out
00074   (int, const RNDXR *, struct rndx_ext *);
00075 
00076 /* Prototypes for functions defined in this file.  */
00077 
00078 static void ecoff_swap_hdr_in (bfd *, void *, HDRR *);
00079 static void ecoff_swap_hdr_out (bfd *, const HDRR *, void *);
00080 static void ecoff_swap_fdr_in (bfd *, void *, FDR *);
00081 static void ecoff_swap_fdr_out (bfd *, const FDR *, void *);
00082 static void ecoff_swap_pdr_in (bfd *, void *, PDR *);
00083 static void ecoff_swap_pdr_out (bfd *, const PDR *, void *);
00084 static void ecoff_swap_sym_in (bfd *, void *, SYMR *);
00085 static void ecoff_swap_sym_out (bfd *, const SYMR *, void *);
00086 static void ecoff_swap_ext_in (bfd *, void *, EXTR *);
00087 static void ecoff_swap_ext_out (bfd *, const EXTR *, void *);
00088 static void ecoff_swap_rfd_in (bfd *, void *, RFDT *);
00089 static void ecoff_swap_rfd_out (bfd *, const RFDT *, void *);
00090 static void ecoff_swap_opt_in (bfd *, void *, OPTR *);
00091 static void ecoff_swap_opt_out (bfd *, const OPTR *, void *);
00092 static void ecoff_swap_dnr_in (bfd *, void *, DNR *);
00093 static void ecoff_swap_dnr_out (bfd *, const DNR *, void *);
00094 
00095 /* Swap in the symbolic header.  */
00096 
00097 static void
00098 ecoff_swap_hdr_in (bfd *abfd, void * ext_copy, HDRR *intern)
00099 {
00100   struct hdr_ext ext[1];
00101 
00102   *ext = *(struct hdr_ext *) ext_copy;
00103 
00104   intern->magic         = H_GET_S16     (abfd, ext->h_magic);
00105   intern->vstamp        = H_GET_S16     (abfd, ext->h_vstamp);
00106   intern->ilineMax      = H_GET_32      (abfd, ext->h_ilineMax);
00107   intern->cbLine        = ECOFF_GET_OFF (abfd, ext->h_cbLine);
00108   intern->cbLineOffset  = ECOFF_GET_OFF (abfd, ext->h_cbLineOffset);
00109   intern->idnMax        = H_GET_32      (abfd, ext->h_idnMax);
00110   intern->cbDnOffset    = ECOFF_GET_OFF (abfd, ext->h_cbDnOffset);
00111   intern->ipdMax        = H_GET_32      (abfd, ext->h_ipdMax);
00112   intern->cbPdOffset    = ECOFF_GET_OFF (abfd, ext->h_cbPdOffset);
00113   intern->isymMax       = H_GET_32      (abfd, ext->h_isymMax);
00114   intern->cbSymOffset   = ECOFF_GET_OFF (abfd, ext->h_cbSymOffset);
00115   intern->ioptMax       = H_GET_32      (abfd, ext->h_ioptMax);
00116   intern->cbOptOffset   = ECOFF_GET_OFF (abfd, ext->h_cbOptOffset);
00117   intern->iauxMax       = H_GET_32      (abfd, ext->h_iauxMax);
00118   intern->cbAuxOffset   = ECOFF_GET_OFF (abfd, ext->h_cbAuxOffset);
00119   intern->issMax        = H_GET_32      (abfd, ext->h_issMax);
00120   intern->cbSsOffset    = ECOFF_GET_OFF (abfd, ext->h_cbSsOffset);
00121   intern->issExtMax     = H_GET_32      (abfd, ext->h_issExtMax);
00122   intern->cbSsExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsExtOffset);
00123   intern->ifdMax        = H_GET_32      (abfd, ext->h_ifdMax);
00124   intern->cbFdOffset    = ECOFF_GET_OFF (abfd, ext->h_cbFdOffset);
00125   intern->crfd          = H_GET_32      (abfd, ext->h_crfd);
00126   intern->cbRfdOffset   = ECOFF_GET_OFF (abfd, ext->h_cbRfdOffset);
00127   intern->iextMax       = H_GET_32      (abfd, ext->h_iextMax);
00128   intern->cbExtOffset   = ECOFF_GET_OFF (abfd, ext->h_cbExtOffset);
00129 
00130 #ifdef TEST
00131   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00132     abort ();
00133 #endif
00134 }
00135 
00136 /* Swap out the symbolic header.  */
00137 
00138 static void
00139 ecoff_swap_hdr_out (bfd *abfd, const HDRR *intern_copy, void * ext_ptr)
00140 {
00141   struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
00142   HDRR intern[1];
00143 
00144   *intern = *intern_copy;
00145 
00146   H_PUT_S16     (abfd, intern->magic,         ext->h_magic);
00147   H_PUT_S16     (abfd, intern->vstamp,        ext->h_vstamp);
00148   H_PUT_32      (abfd, intern->ilineMax,      ext->h_ilineMax);
00149   ECOFF_PUT_OFF (abfd, intern->cbLine,        ext->h_cbLine);
00150   ECOFF_PUT_OFF (abfd, intern->cbLineOffset,  ext->h_cbLineOffset);
00151   H_PUT_32      (abfd, intern->idnMax,        ext->h_idnMax);
00152   ECOFF_PUT_OFF (abfd, intern->cbDnOffset,    ext->h_cbDnOffset);
00153   H_PUT_32      (abfd, intern->ipdMax,        ext->h_ipdMax);
00154   ECOFF_PUT_OFF (abfd, intern->cbPdOffset,    ext->h_cbPdOffset);
00155   H_PUT_32      (abfd, intern->isymMax,       ext->h_isymMax);
00156   ECOFF_PUT_OFF (abfd, intern->cbSymOffset,   ext->h_cbSymOffset);
00157   H_PUT_32      (abfd, intern->ioptMax,       ext->h_ioptMax);
00158   ECOFF_PUT_OFF (abfd, intern->cbOptOffset,   ext->h_cbOptOffset);
00159   H_PUT_32      (abfd, intern->iauxMax,       ext->h_iauxMax);
00160   ECOFF_PUT_OFF (abfd, intern->cbAuxOffset,   ext->h_cbAuxOffset);
00161   H_PUT_32      (abfd, intern->issMax,        ext->h_issMax);
00162   ECOFF_PUT_OFF (abfd, intern->cbSsOffset,    ext->h_cbSsOffset);
00163   H_PUT_32      (abfd, intern->issExtMax,     ext->h_issExtMax);
00164   ECOFF_PUT_OFF (abfd, intern->cbSsExtOffset, ext->h_cbSsExtOffset);
00165   H_PUT_32      (abfd, intern->ifdMax,        ext->h_ifdMax);
00166   ECOFF_PUT_OFF (abfd, intern->cbFdOffset,    ext->h_cbFdOffset);
00167   H_PUT_32      (abfd, intern->crfd,          ext->h_crfd);
00168   ECOFF_PUT_OFF (abfd, intern->cbRfdOffset,   ext->h_cbRfdOffset);
00169   H_PUT_32      (abfd, intern->iextMax,       ext->h_iextMax);
00170   ECOFF_PUT_OFF (abfd, intern->cbExtOffset,   ext->h_cbExtOffset);
00171 
00172 #ifdef TEST
00173   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00174     abort ();
00175 #endif
00176 }
00177 
00178 /* Swap in the file descriptor record.  */
00179 
00180 static void
00181 ecoff_swap_fdr_in (bfd *abfd, void * ext_copy, FDR *intern)
00182 {
00183   struct fdr_ext ext[1];
00184 
00185   *ext = *(struct fdr_ext *) ext_copy;
00186 
00187   intern->adr           = ECOFF_GET_OFF (abfd, ext->f_adr);
00188   intern->rss           = H_GET_32 (abfd, ext->f_rss);
00189 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00190   if (intern->rss == (signed long) 0xffffffff)
00191     intern->rss = -1;
00192 #endif
00193   intern->issBase       = H_GET_32 (abfd, ext->f_issBase);
00194   intern->cbSs          = ECOFF_GET_OFF (abfd, ext->f_cbSs);
00195   intern->isymBase      = H_GET_32 (abfd, ext->f_isymBase);
00196   intern->csym          = H_GET_32 (abfd, ext->f_csym);
00197   intern->ilineBase     = H_GET_32 (abfd, ext->f_ilineBase);
00198   intern->cline         = H_GET_32 (abfd, ext->f_cline);
00199   intern->ioptBase      = H_GET_32 (abfd, ext->f_ioptBase);
00200   intern->copt          = H_GET_32 (abfd, ext->f_copt);
00201 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
00202   intern->ipdFirst      = H_GET_16 (abfd, ext->f_ipdFirst);
00203   intern->cpd           = H_GET_16 (abfd, ext->f_cpd);
00204 #endif
00205 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00206   intern->ipdFirst      = H_GET_32 (abfd, ext->f_ipdFirst);
00207   intern->cpd           = H_GET_32 (abfd, ext->f_cpd);
00208 #endif
00209   intern->iauxBase      = H_GET_32 (abfd, ext->f_iauxBase);
00210   intern->caux          = H_GET_32 (abfd, ext->f_caux);
00211   intern->rfdBase       = H_GET_32 (abfd, ext->f_rfdBase);
00212   intern->crfd          = H_GET_32 (abfd, ext->f_crfd);
00213 
00214   /* Now the fun stuff...  */
00215   if (bfd_header_big_endian (abfd))
00216     {
00217       intern->lang       = ((ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
00218                          >> FDR_BITS1_LANG_SH_BIG);
00219       intern->fMerge     = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
00220       intern->fReadin    = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
00221       intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
00222       intern->glevel     = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
00223                          >> FDR_BITS2_GLEVEL_SH_BIG);
00224     }
00225   else
00226     {
00227       intern->lang       = ((ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
00228                          >> FDR_BITS1_LANG_SH_LITTLE);
00229       intern->fMerge     = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
00230       intern->fReadin    = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
00231       intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
00232       intern->glevel     = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
00233                          >> FDR_BITS2_GLEVEL_SH_LITTLE);
00234     }
00235   intern->reserved = 0;
00236 
00237   intern->cbLineOffset  = ECOFF_GET_OFF (abfd, ext->f_cbLineOffset);
00238   intern->cbLine        = ECOFF_GET_OFF (abfd, ext->f_cbLine);
00239 
00240 #ifdef TEST
00241   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00242     abort ();
00243 #endif
00244 }
00245 
00246 /* Swap out the file descriptor record.  */
00247 
00248 static void
00249 ecoff_swap_fdr_out (bfd *abfd, const FDR *intern_copy, void * ext_ptr)
00250 {
00251   struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
00252   FDR intern[1];
00253 
00254   /* Make it reasonable to do in-place.  */
00255   *intern = *intern_copy;
00256 
00257   ECOFF_PUT_OFF (abfd, intern->adr,       ext->f_adr);
00258   H_PUT_32      (abfd, intern->rss,       ext->f_rss);
00259   H_PUT_32      (abfd, intern->issBase,   ext->f_issBase);
00260   ECOFF_PUT_OFF (abfd, intern->cbSs,      ext->f_cbSs);
00261   H_PUT_32      (abfd, intern->isymBase,  ext->f_isymBase);
00262   H_PUT_32      (abfd, intern->csym,      ext->f_csym);
00263   H_PUT_32      (abfd, intern->ilineBase, ext->f_ilineBase);
00264   H_PUT_32      (abfd, intern->cline,     ext->f_cline);
00265   H_PUT_32      (abfd, intern->ioptBase,  ext->f_ioptBase);
00266   H_PUT_32      (abfd, intern->copt,      ext->f_copt);
00267 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
00268   H_PUT_16      (abfd, intern->ipdFirst,  ext->f_ipdFirst);
00269   H_PUT_16      (abfd, intern->cpd,       ext->f_cpd);
00270 #endif
00271 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00272   H_PUT_32      (abfd, intern->ipdFirst,  ext->f_ipdFirst);
00273   H_PUT_32      (abfd, intern->cpd,       ext->f_cpd);
00274 #endif
00275   H_PUT_32      (abfd, intern->iauxBase,  ext->f_iauxBase);
00276   H_PUT_32      (abfd, intern->caux,      ext->f_caux);
00277   H_PUT_32      (abfd, intern->rfdBase,   ext->f_rfdBase);
00278   H_PUT_32      (abfd, intern->crfd,      ext->f_crfd);
00279 
00280   /* Now the fun stuff...  */
00281   if (bfd_header_big_endian (abfd))
00282     {
00283       ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
00284                        & FDR_BITS1_LANG_BIG)
00285                       | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
00286                       | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
00287                       | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
00288       ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
00289                       & FDR_BITS2_GLEVEL_BIG);
00290       ext->f_bits2[1] = 0;
00291       ext->f_bits2[2] = 0;
00292     }
00293   else
00294     {
00295       ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
00296                        & FDR_BITS1_LANG_LITTLE)
00297                       | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
00298                       | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
00299                       | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
00300       ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
00301                       & FDR_BITS2_GLEVEL_LITTLE);
00302       ext->f_bits2[1] = 0;
00303       ext->f_bits2[2] = 0;
00304     }
00305 
00306   ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->f_cbLineOffset);
00307   ECOFF_PUT_OFF (abfd, intern->cbLine, ext->f_cbLine);
00308 
00309 #ifdef TEST
00310   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00311     abort ();
00312 #endif
00313 }
00314 
00315 /* Swap in the procedure descriptor record.  */
00316 
00317 static void
00318 ecoff_swap_pdr_in (bfd *abfd, void * ext_copy, PDR *intern)
00319 {
00320   struct pdr_ext ext[1];
00321 
00322   *ext = *(struct pdr_ext *) ext_copy;
00323 
00324   memset ((void *) intern, 0, sizeof (*intern));
00325 
00326   intern->adr           = ECOFF_GET_OFF (abfd, ext->p_adr);
00327   intern->isym          = H_GET_32 (abfd, ext->p_isym);
00328   intern->iline         = H_GET_32 (abfd, ext->p_iline);
00329   intern->regmask       = H_GET_32 (abfd, ext->p_regmask);
00330   intern->regoffset     = H_GET_S32 (abfd, ext->p_regoffset);
00331   intern->iopt          = H_GET_S32 (abfd, ext->p_iopt);
00332   intern->fregmask      = H_GET_32 (abfd, ext->p_fregmask);
00333   intern->fregoffset    = H_GET_S32 (abfd, ext->p_fregoffset);
00334   intern->frameoffset   = H_GET_S32 (abfd, ext->p_frameoffset);
00335   intern->framereg      = H_GET_16 (abfd, ext->p_framereg);
00336   intern->pcreg         = H_GET_16 (abfd, ext->p_pcreg);
00337   intern->lnLow         = H_GET_32 (abfd, ext->p_lnLow);
00338   intern->lnHigh        = H_GET_32 (abfd, ext->p_lnHigh);
00339   intern->cbLineOffset  = ECOFF_GET_OFF (abfd, ext->p_cbLineOffset);
00340 
00341 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00342   if (intern->isym == (signed long) 0xffffffff)
00343     intern->isym = -1;
00344   if (intern->iline == (signed long) 0xffffffff)
00345     intern->iline = -1;
00346 
00347   intern->gp_prologue = H_GET_8 (abfd, ext->p_gp_prologue);
00348   if (bfd_header_big_endian (abfd))
00349     {
00350       intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
00351       intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
00352       intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
00353       intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
00354                         << PDR_BITS1_RESERVED_SH_LEFT_BIG)
00355                        | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
00356                           >> PDR_BITS2_RESERVED_SH_BIG));
00357     }
00358   else
00359     {
00360       intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
00361       intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
00362       intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
00363       intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
00364                         >> PDR_BITS1_RESERVED_SH_LITTLE)
00365                        | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
00366                           << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
00367     }
00368   intern->localoff = H_GET_8 (abfd, ext->p_localoff);
00369 #endif
00370 
00371 #ifdef TEST
00372   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00373     abort ();
00374 #endif
00375 }
00376 
00377 /* Swap out the procedure descriptor record.  */
00378 
00379 static void
00380 ecoff_swap_pdr_out (bfd *abfd, const PDR *intern_copy, void * ext_ptr)
00381 {
00382   struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
00383   PDR intern[1];
00384 
00385   /* Make it reasonable to do in-place.  */
00386   *intern = *intern_copy;
00387 
00388   ECOFF_PUT_OFF (abfd, intern->adr,          ext->p_adr);
00389   H_PUT_32      (abfd, intern->isym,         ext->p_isym);
00390   H_PUT_32      (abfd, intern->iline,        ext->p_iline);
00391   H_PUT_32      (abfd, intern->regmask,      ext->p_regmask);
00392   H_PUT_32      (abfd, intern->regoffset,    ext->p_regoffset);
00393   H_PUT_32      (abfd, intern->iopt,         ext->p_iopt);
00394   H_PUT_32      (abfd, intern->fregmask,     ext->p_fregmask);
00395   H_PUT_32      (abfd, intern->fregoffset,   ext->p_fregoffset);
00396   H_PUT_32      (abfd, intern->frameoffset,  ext->p_frameoffset);
00397   H_PUT_16      (abfd, intern->framereg,     ext->p_framereg);
00398   H_PUT_16      (abfd, intern->pcreg,        ext->p_pcreg);
00399   H_PUT_32      (abfd, intern->lnLow,        ext->p_lnLow);
00400   H_PUT_32      (abfd, intern->lnHigh,       ext->p_lnHigh);
00401   ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->p_cbLineOffset);
00402 
00403 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00404   H_PUT_8       (abfd, intern->gp_prologue,  ext->p_gp_prologue);
00405 
00406   if (bfd_header_big_endian (abfd))
00407     {
00408       ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
00409                       | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
00410                       | (intern->prof ? PDR_BITS1_PROF_BIG : 0)
00411                       | ((intern->reserved
00412                           >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
00413                          & PDR_BITS1_RESERVED_BIG));
00414       ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
00415                       & PDR_BITS2_RESERVED_BIG);
00416     }
00417   else
00418     {
00419       ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
00420                       | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
00421                       | (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
00422                       | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
00423                          & PDR_BITS1_RESERVED_LITTLE));
00424       ext->p_bits2[0] = ((intern->reserved >>
00425                        PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
00426                       & PDR_BITS2_RESERVED_LITTLE);
00427     }
00428   H_PUT_8 (abfd, intern->localoff, ext->p_localoff);
00429 #endif
00430 
00431 #ifdef TEST
00432   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00433     abort ();
00434 #endif
00435 }
00436 
00437 /* Swap in a symbol record.  */
00438 
00439 static void
00440 ecoff_swap_sym_in (bfd *abfd, void * ext_copy, SYMR *intern)
00441 {
00442   struct sym_ext ext[1];
00443 
00444   *ext = *(struct sym_ext *) ext_copy;
00445 
00446   intern->iss           = H_GET_32 (abfd, ext->s_iss);
00447   intern->value         = ECOFF_GET_OFF (abfd, ext->s_value);
00448 
00449 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00450   if (intern->iss == (signed long) 0xffffffff)
00451     intern->iss = -1;
00452 #endif  
00453 
00454   /* Now the fun stuff...  */
00455   if (bfd_header_big_endian (abfd))
00456     {
00457       intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
00458                                         >> SYM_BITS1_ST_SH_BIG;
00459       intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
00460                                         << SYM_BITS1_SC_SH_LEFT_BIG)
00461                        | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
00462                                         >> SYM_BITS2_SC_SH_BIG);
00463       intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
00464       intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
00465                                         << SYM_BITS2_INDEX_SH_LEFT_BIG)
00466                        | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
00467                        | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
00468     }
00469   else
00470     {
00471       intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
00472                                         >> SYM_BITS1_ST_SH_LITTLE;
00473       intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
00474                                         >> SYM_BITS1_SC_SH_LITTLE)
00475                        | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
00476                                         << SYM_BITS2_SC_SH_LEFT_LITTLE);
00477       intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
00478       intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
00479                                         >> SYM_BITS2_INDEX_SH_LITTLE)
00480                        | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
00481                        | ((unsigned int) ext->s_bits4[0]
00482                           << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
00483     }
00484 
00485 #ifdef TEST
00486   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00487     abort ();
00488 #endif
00489 }
00490 
00491 /* Swap out a symbol record.  */
00492 
00493 static void
00494 ecoff_swap_sym_out (bfd *abfd, const SYMR *intern_copy, void * ext_ptr)
00495 {
00496   struct sym_ext *ext = (struct sym_ext *) ext_ptr;
00497   SYMR intern[1];
00498 
00499   /* Make it reasonable to do in-place.  */
00500   *intern = *intern_copy;
00501 
00502   H_PUT_32 (abfd, intern->iss, ext->s_iss);
00503   ECOFF_PUT_OFF (abfd, intern->value, ext->s_value);
00504 
00505   /* Now the fun stuff...  */
00506   if (bfd_header_big_endian (abfd))
00507     {
00508       ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
00509                        & SYM_BITS1_ST_BIG)
00510                       | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
00511                          & SYM_BITS1_SC_BIG));
00512       ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
00513                        & SYM_BITS2_SC_BIG)
00514                       | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
00515                       | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
00516                          & SYM_BITS2_INDEX_BIG));
00517       ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
00518       ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
00519     }
00520   else
00521     {
00522       ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
00523                        & SYM_BITS1_ST_LITTLE)
00524                       | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
00525                          & SYM_BITS1_SC_LITTLE));
00526       ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
00527                        & SYM_BITS2_SC_LITTLE)
00528                       | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
00529                       | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
00530                          & SYM_BITS2_INDEX_LITTLE));
00531       ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
00532       ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
00533     }
00534 
00535 #ifdef TEST
00536   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00537     abort ();
00538 #endif
00539 }
00540 
00541 /* Swap in an external symbol record.  */
00542 
00543 static void
00544 ecoff_swap_ext_in (bfd *abfd, void * ext_copy, EXTR *intern)
00545 {
00546   struct ext_ext ext[1];
00547 
00548   *ext = *(struct ext_ext *) ext_copy;
00549 
00550   /* Now the fun stuff...  */
00551   if (bfd_header_big_endian (abfd))
00552     {
00553       intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
00554       intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
00555       intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
00556     }
00557   else
00558     {
00559       intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
00560       intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
00561       intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
00562     }
00563   intern->reserved = 0;
00564 
00565 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
00566   intern->ifd = H_GET_S16 (abfd, ext->es_ifd);
00567 #endif
00568 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00569   intern->ifd = H_GET_S32 (abfd, ext->es_ifd);
00570 #endif
00571 
00572   ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
00573 
00574 #ifdef TEST
00575   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00576     abort ();
00577 #endif
00578 }
00579 
00580 /* Swap out an external symbol record.  */
00581 
00582 static void
00583 ecoff_swap_ext_out (bfd *abfd, const EXTR *intern_copy, void * ext_ptr)
00584 {
00585   struct ext_ext *ext = (struct ext_ext *) ext_ptr;
00586   EXTR intern[1];
00587 
00588   /* Make it reasonable to do in-place.  */
00589   *intern = *intern_copy;
00590 
00591   /* Now the fun stuff...  */
00592   if (bfd_header_big_endian (abfd))
00593     {
00594       ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
00595                        | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
00596                        | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
00597       ext->es_bits2[0] = 0;
00598 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00599       ext->es_bits2[1] = 0;
00600       ext->es_bits2[2] = 0;
00601 #endif
00602     }
00603   else
00604     {
00605       ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
00606                        | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
00607                        | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
00608       ext->es_bits2[0] = 0;
00609 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00610       ext->es_bits2[1] = 0;
00611       ext->es_bits2[2] = 0;
00612 #endif
00613     }
00614 
00615 #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
00616   H_PUT_S16 (abfd, intern->ifd, ext->es_ifd);
00617 #endif
00618 #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
00619   H_PUT_S32 (abfd, intern->ifd, ext->es_ifd);
00620 #endif
00621 
00622   ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
00623 
00624 #ifdef TEST
00625   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00626     abort ();
00627 #endif
00628 }
00629 
00630 /* Swap in a relative file descriptor.  */
00631 
00632 static void
00633 ecoff_swap_rfd_in (bfd *abfd, void * ext_ptr, RFDT *intern)
00634 {
00635   struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
00636 
00637   *intern = H_GET_32 (abfd, ext->rfd);
00638 
00639 #ifdef TEST
00640   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00641     abort ();
00642 #endif
00643 }
00644 
00645 /* Swap out a relative file descriptor.  */
00646 
00647 static void
00648 ecoff_swap_rfd_out (bfd *abfd, const RFDT *intern, void * ext_ptr)
00649 {
00650   struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
00651 
00652   H_PUT_32 (abfd, *intern, ext->rfd);
00653 
00654 #ifdef TEST
00655   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00656     abort ();
00657 #endif
00658 }
00659 
00660 /* Swap in an optimization symbol.  */
00661 
00662 static void
00663 ecoff_swap_opt_in (bfd *abfd, void * ext_copy, OPTR * intern)
00664 {
00665   struct opt_ext ext[1];
00666 
00667   *ext = *(struct opt_ext *) ext_copy;
00668 
00669   if (bfd_header_big_endian (abfd))
00670     {
00671       intern->ot = ext->o_bits1[0];
00672       intern->value = (((unsigned int) ext->o_bits2[0]
00673                      << OPT_BITS2_VALUE_SH_LEFT_BIG)
00674                      | ((unsigned int) ext->o_bits3[0]
00675                        << OPT_BITS2_VALUE_SH_LEFT_BIG)
00676                      | ((unsigned int) ext->o_bits4[0]
00677                        << OPT_BITS2_VALUE_SH_LEFT_BIG));
00678     }
00679   else
00680     {
00681       intern->ot = ext->o_bits1[0];
00682       intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
00683                      | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
00684                      | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
00685     }
00686 
00687   _bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
00688                         &ext->o_rndx, &intern->rndx);
00689 
00690   intern->offset = H_GET_32 (abfd, ext->o_offset);
00691 
00692 #ifdef TEST
00693   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00694     abort ();
00695 #endif
00696 }
00697 
00698 /* Swap out an optimization symbol.  */
00699 
00700 static void
00701 ecoff_swap_opt_out (bfd *abfd, const OPTR *intern_copy, void * ext_ptr)
00702 {
00703   struct opt_ext *ext = (struct opt_ext *) ext_ptr;
00704   OPTR intern[1];
00705 
00706   /* Make it reasonable to do in-place.  */
00707   *intern = *intern_copy;
00708 
00709   if (bfd_header_big_endian (abfd))
00710     {
00711       ext->o_bits1[0] = intern->ot;
00712       ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
00713       ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
00714       ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
00715     }
00716   else
00717     {
00718       ext->o_bits1[0] = intern->ot;
00719       ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
00720       ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
00721       ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
00722     }
00723 
00724   _bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
00725                          &intern->rndx, &ext->o_rndx);
00726 
00727   H_PUT_32 (abfd, intern->value, ext->o_offset);
00728 
00729 #ifdef TEST
00730   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00731     abort ();
00732 #endif
00733 }
00734 
00735 /* Swap in a dense number.  */
00736 
00737 static void
00738 ecoff_swap_dnr_in (bfd *abfd, void * ext_copy, DNR *intern)
00739 {
00740   struct dnr_ext ext[1];
00741 
00742   *ext = *(struct dnr_ext *) ext_copy;
00743 
00744   intern->rfd = H_GET_32 (abfd, ext->d_rfd);
00745   intern->index = H_GET_32 (abfd, ext->d_index);
00746 
00747 #ifdef TEST
00748   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00749     abort ();
00750 #endif
00751 }
00752 
00753 /* Swap out a dense number.  */
00754 
00755 static void
00756 ecoff_swap_dnr_out (bfd *abfd, const DNR *intern_copy, void * ext_ptr)
00757 {
00758   struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
00759   DNR intern[1];
00760 
00761   /* Make it reasonable to do in-place.  */
00762   *intern = *intern_copy;
00763 
00764   H_PUT_32 (abfd, intern->rfd, ext->d_rfd);
00765   H_PUT_32 (abfd, intern->index, ext->d_index);
00766 
00767 #ifdef TEST
00768   if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
00769     abort ();
00770 #endif
00771 }