home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / bfd / ecoffswap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-04  |  26.7 KB  |  747 lines

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