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