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 / coffswap.h < prev    next >
C/C++ Source or Header  |  1994-02-03  |  26KB  |  719 lines

  1. /* Generic COFF swapping routines, for BFD.
  2.    Copyright 1990, 1991, 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. /* This file contains routines used to swap COFF data.  It is a header
  22.    file because the details of swapping depend on the details of the
  23.    structures used by each COFF implementation.  This is included by
  24.    coffcode.h, as well as by the ECOFF backend.
  25.  
  26.    Any file which uses this must first include "coff/internal.h" and
  27.    "coff/CPU.h".  The functions will then be correct for that CPU.  */
  28.  
  29. #define PUTWORD bfd_h_put_32
  30. #define PUTHALF bfd_h_put_16
  31. #define    PUTBYTE bfd_h_put_8
  32.  
  33. #ifndef GET_FCN_LNNOPTR
  34. #define GET_FCN_LNNOPTR(abfd, ext)  bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
  35. #endif
  36.  
  37. #ifndef GET_FCN_ENDNDX
  38. #define GET_FCN_ENDNDX(abfd, ext)  bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
  39. #endif
  40.  
  41. #ifndef PUT_FCN_LNNOPTR
  42. #define PUT_FCN_LNNOPTR(abfd, in, ext)  PUTWORD(abfd,  in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
  43. #endif
  44. #ifndef PUT_FCN_ENDNDX
  45. #define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
  46. #endif
  47. #ifndef GET_LNSZ_LNNO
  48. #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
  49. #endif
  50. #ifndef GET_LNSZ_SIZE
  51. #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
  52. #endif
  53. #ifndef PUT_LNSZ_LNNO
  54. #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
  55. #endif
  56. #ifndef PUT_LNSZ_SIZE
  57. #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
  58. #endif
  59. #ifndef GET_SCN_SCNLEN
  60. #define GET_SCN_SCNLEN(abfd,  ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
  61. #endif
  62. #ifndef GET_SCN_NRELOC
  63. #define GET_SCN_NRELOC(abfd,  ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
  64. #endif
  65. #ifndef GET_SCN_NLINNO
  66. #define GET_SCN_NLINNO(abfd, ext)  bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
  67. #endif
  68. #ifndef PUT_SCN_SCNLEN
  69. #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
  70. #endif
  71. #ifndef PUT_SCN_NRELOC
  72. #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
  73. #endif
  74. #ifndef PUT_SCN_NLINNO
  75. #define PUT_SCN_NLINNO(abfd,in, ext)  bfd_h_put_16(abfd,in, (bfd_byte  *) ext->x_scn.x_nlinno)
  76. #endif
  77. #ifndef GET_LINENO_LNNO
  78. #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
  79. #endif
  80. #ifndef PUT_LINENO_LNNO
  81. #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val,  (bfd_byte *) (ext->l_lnno));
  82. #endif
  83.  
  84. /* The f_symptr field in the filehdr is sometimes 64 bits.  */
  85. #ifndef GET_FILEHDR_SYMPTR
  86. #define GET_FILEHDR_SYMPTR bfd_h_get_32
  87. #endif
  88. #ifndef PUT_FILEHDR_SYMPTR
  89. #define PUT_FILEHDR_SYMPTR bfd_h_put_32
  90. #endif
  91.  
  92. /* Some fields in the aouthdr are sometimes 64 bits.  */
  93. #ifndef GET_AOUTHDR_TSIZE
  94. #define GET_AOUTHDR_TSIZE bfd_h_get_32
  95. #endif
  96. #ifndef PUT_AOUTHDR_TSIZE
  97. #define PUT_AOUTHDR_TSIZE bfd_h_put_32
  98. #endif
  99. #ifndef GET_AOUTHDR_DSIZE
  100. #define GET_AOUTHDR_DSIZE bfd_h_get_32
  101. #endif
  102. #ifndef PUT_AOUTHDR_DSIZE
  103. #define PUT_AOUTHDR_DSIZE bfd_h_put_32
  104. #endif
  105. #ifndef GET_AOUTHDR_BSIZE
  106. #define GET_AOUTHDR_BSIZE bfd_h_get_32
  107. #endif
  108. #ifndef PUT_AOUTHDR_BSIZE
  109. #define PUT_AOUTHDR_BSIZE bfd_h_put_32
  110. #endif
  111. #ifndef GET_AOUTHDR_ENTRY
  112. #define GET_AOUTHDR_ENTRY bfd_h_get_32
  113. #endif
  114. #ifndef PUT_AOUTHDR_ENTRY
  115. #define PUT_AOUTHDR_ENTRY bfd_h_put_32
  116. #endif
  117. #ifndef GET_AOUTHDR_TEXT_START
  118. #define GET_AOUTHDR_TEXT_START bfd_h_get_32
  119. #endif
  120. #ifndef PUT_AOUTHDR_TEXT_START
  121. #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
  122. #endif
  123. #ifndef GET_AOUTHDR_DATA_START
  124. #define GET_AOUTHDR_DATA_START bfd_h_get_32
  125. #endif
  126. #ifndef PUT_AOUTHDR_DATA_START
  127. #define PUT_AOUTHDR_DATA_START bfd_h_put_32
  128. #endif
  129.  
  130. /* Some fields in the scnhdr are sometimes 64 bits.  */
  131. #ifndef GET_SCNHDR_PADDR
  132. #define GET_SCNHDR_PADDR bfd_h_get_32
  133. #endif
  134. #ifndef PUT_SCNHDR_PADDR
  135. #define PUT_SCNHDR_PADDR bfd_h_put_32
  136. #endif
  137. #ifndef GET_SCNHDR_VADDR
  138. #define GET_SCNHDR_VADDR bfd_h_get_32
  139. #endif
  140. #ifndef PUT_SCNHDR_VADDR
  141. #define PUT_SCNHDR_VADDR bfd_h_put_32
  142. #endif
  143. #ifndef GET_SCNHDR_SIZE
  144. #define GET_SCNHDR_SIZE bfd_h_get_32
  145. #endif
  146. #ifndef PUT_SCNHDR_SIZE
  147. #define PUT_SCNHDR_SIZE bfd_h_put_32
  148. #endif
  149. #ifndef GET_SCNHDR_SCNPTR
  150. #define GET_SCNHDR_SCNPTR bfd_h_get_32
  151. #endif
  152. #ifndef PUT_SCNHDR_SCNPTR
  153. #define PUT_SCNHDR_SCNPTR bfd_h_put_32
  154. #endif
  155. #ifndef GET_SCNHDR_RELPTR
  156. #define GET_SCNHDR_RELPTR bfd_h_get_32
  157. #endif
  158. #ifndef PUT_SCNHDR_RELPTR
  159. #define PUT_SCNHDR_RELPTR bfd_h_put_32
  160. #endif
  161. #ifndef GET_SCNHDR_LNNOPTR
  162. #define GET_SCNHDR_LNNOPTR bfd_h_get_32
  163. #endif
  164. #ifndef PUT_SCNHDR_LNNOPTR
  165. #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
  166. #endif
  167.  
  168. #ifndef NO_COFF_RELOCS
  169.  
  170. static void
  171. DEFUN(bfd_swap_reloc_in,(abfd, reloc_src, reloc_dst),
  172.       bfd            *abfd AND
  173.       RELOC *reloc_src AND
  174.       struct internal_reloc *reloc_dst)
  175. {
  176.   reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
  177.   reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
  178.  
  179. #ifdef RS6000COFF_C
  180.   reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
  181.   reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
  182. #else
  183.   reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
  184. #endif
  185.  
  186. #ifdef SWAP_IN_RELOC_OFFSET
  187.   reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
  188.                          (bfd_byte *) reloc_src->r_offset);
  189. #endif
  190. }
  191.  
  192.  
  193. static unsigned int
  194. DEFUN(coff_swap_reloc_out,(abfd, src, dst),
  195.       bfd       *abfd AND
  196.       PTR    src AND
  197.       PTR    dst)
  198. {
  199.   struct internal_reloc *reloc_src = (struct internal_reloc *)src;
  200.   struct external_reloc *reloc_dst = (struct external_reloc *)dst;
  201.   bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
  202.   bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
  203.   bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
  204.            reloc_dst->r_type);
  205.  
  206. #ifdef SWAP_OUT_RELOC_OFFSET
  207.   SWAP_OUT_RELOC_OFFSET(abfd,
  208.             reloc_src->r_offset,
  209.             (bfd_byte *) reloc_dst->r_offset);
  210. #endif
  211. #ifdef SWAP_OUT_RELOC_EXTRA
  212.   SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
  213. #endif
  214.  
  215.   return sizeof(struct external_reloc);
  216. }
  217.  
  218. #endif /* NO_COFF_RELOCS */
  219.  
  220. static void
  221. DEFUN(coff_swap_filehdr_in,(abfd, src, dst),
  222.       bfd            *abfd AND
  223.       PTR         src AND
  224.       PTR         dst)
  225. {
  226.   FILHDR *filehdr_src = (FILHDR *) src;
  227.   struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
  228.   filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
  229.   filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
  230.   filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
  231.   filehdr_dst->f_symptr =
  232.     GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
  233.   filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
  234.   filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
  235.   filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
  236. }
  237.  
  238. static  unsigned int
  239. DEFUN(coff_swap_filehdr_out,(abfd, in, out),
  240.       bfd       *abfd AND
  241.       PTR    in AND
  242.       PTR    out)
  243. {
  244.   struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
  245.   FILHDR *filehdr_out = (FILHDR *)out;
  246.   bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
  247.   bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
  248.   bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
  249.   PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
  250.               (bfd_byte *) filehdr_out->f_symptr);
  251.   bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
  252.   bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
  253.   bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
  254.   return sizeof(FILHDR);
  255. }
  256.  
  257.  
  258. #ifndef NO_COFF_SYMBOLS
  259.  
  260. static void
  261. DEFUN(coff_swap_sym_in,(abfd, ext1, in1),
  262.       bfd            *abfd AND
  263.       PTR ext1 AND
  264.       PTR in1)
  265. {
  266.   SYMENT *ext = (SYMENT *)ext1;
  267.   struct internal_syment      *in = (struct internal_syment *)in1;
  268.  
  269.   if( ext->e.e_name[0] == 0) {
  270.     in->_n._n_n._n_zeroes = 0;
  271.     in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
  272.   }
  273.   else {
  274. #if SYMNMLEN != E_SYMNMLEN
  275.    -> Error, we need to cope with truncating or extending SYMNMLEN!;
  276. #else
  277.     memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
  278. #endif
  279.   }
  280.   in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
  281.   in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
  282.   if (sizeof(ext->e_type) == 2){
  283.     in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
  284.   }
  285.   else {
  286.     in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
  287.   }
  288.   in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
  289.   in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
  290. }
  291.  
  292. static unsigned int
  293. DEFUN(coff_swap_sym_out,(abfd, inp, extp),
  294.       bfd       *abfd AND
  295.       PTR    inp AND
  296.       PTR    extp)
  297. {
  298.   struct internal_syment *in = (struct internal_syment *)inp;
  299.   SYMENT *ext =(SYMENT *)extp;
  300.   if(in->_n._n_name[0] == 0) {
  301.     bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
  302.     bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *)  ext->e.e.e_offset);
  303.   }
  304.   else {
  305. #if SYMNMLEN != E_SYMNMLEN
  306.     -> Error, we need to cope with truncating or extending SYMNMLEN!;
  307. #else
  308.     memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
  309. #endif
  310.   }
  311.   bfd_h_put_32(abfd,  in->n_value , (bfd_byte *) ext->e_value);
  312.   bfd_h_put_16(abfd,  in->n_scnum , (bfd_byte *) ext->e_scnum);
  313.   if (sizeof(ext->e_type) == 2)
  314.       {
  315.     bfd_h_put_16(abfd,  in->n_type , (bfd_byte *) ext->e_type);
  316.       }
  317.   else
  318.       {
  319.     bfd_h_put_32(abfd,  in->n_type , (bfd_byte *) ext->e_type);
  320.       }
  321.   bfd_h_put_8(abfd,  in->n_sclass , ext->e_sclass);
  322.   bfd_h_put_8(abfd,  in->n_numaux , ext->e_numaux);
  323.   return sizeof(SYMENT);
  324. }
  325.  
  326. static void
  327. DEFUN(coff_swap_aux_in,(abfd, ext1, type, class, in1),
  328.       bfd            *abfd AND
  329.       PTR           ext1 AND
  330.       int             type AND
  331.       int             class AND
  332.       PTR           in1)
  333. {
  334.   AUXENT    *ext = (AUXENT *)ext1;
  335.   union internal_auxent *in = (union internal_auxent *)in1;
  336.  
  337.   switch (class) {
  338.     case C_FILE:
  339.       if (ext->x_file.x_fname[0] == 0) {
  340.       in->x_file.x_n.x_zeroes = 0;
  341.       in->x_file.x_n.x_offset = 
  342.        bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
  343.     } else {
  344. #if FILNMLEN != E_FILNMLEN
  345.         -> Error, we need to cope with truncating or extending FILNMLEN!;
  346. #else
  347.         memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
  348. #endif
  349.       }
  350.       break;
  351.  
  352.       /* RS/6000 "csect" auxents */
  353. #ifdef RS6000COFF_C
  354.     case C_EXT:
  355.     case C_HIDEXT:
  356.       in->x_csect.x_scnlen   = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_scnlen);
  357.       in->x_csect.x_parmhash = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_parmhash);
  358.       in->x_csect.x_snhash   = bfd_h_get_16 (abfd, (bfd_byte *) ext->x_csect.x_snhash);
  359.       /* We don't have to hack bitfields in x_smtyp because it's defined by
  360.      shifts-and-ands, which are equivalent on all byte orders.  */
  361.       in->x_csect.x_smtyp    = bfd_h_get_8  (abfd, (bfd_byte *) ext->x_csect.x_smtyp);
  362.       in->x_csect.x_smclas   = bfd_h_get_8  (abfd, (bfd_byte *) ext->x_csect.x_smclas);
  363.       in->x_csect.x_stab     = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_stab);
  364.       in->x_csect.x_snstab   = bfd_h_get_16 (abfd, (bfd_byte *) ext->x_csect.x_snstab);
  365.       break;
  366. #endif
  367.  
  368.     case C_STAT:
  369. #ifdef C_LEAFSTAT
  370.     case C_LEAFSTAT:
  371. #endif
  372.     case C_HIDDEN:
  373.       if (type == T_NULL) {
  374.       in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
  375.       in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
  376.       in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
  377.       break;
  378.     }
  379.     default:
  380.       in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
  381. #ifndef NO_TVNDX
  382.       in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
  383. #endif
  384.  
  385.       if (ISARY(type)) {
  386. #if DIMNUM != E_DIMNUM
  387.       -> Error, we need to cope with truncating or extending DIMNUM!;
  388. #else
  389.       in->x_sym.x_fcnary.x_ary.x_dimen[0] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
  390.       in->x_sym.x_fcnary.x_ary.x_dimen[1] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
  391.       in->x_sym.x_fcnary.x_ary.x_dimen[2] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
  392.       in->x_sym.x_fcnary.x_ary.x_dimen[3] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
  393. #endif
  394.     }
  395.       if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
  396.     in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR(abfd, ext);
  397.     in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX(abfd, ext);
  398.       }
  399.  
  400.       if (ISFCN(type)) {
  401.       in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
  402.     }
  403.       else {
  404.       in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
  405.       in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
  406.     }
  407.     }
  408. }
  409.  
  410. static unsigned int
  411. DEFUN(coff_swap_aux_out,(abfd, inp, type, class, extp),
  412.   bfd   *abfd AND
  413.   PTR     inp AND
  414.   int   type AND
  415.   int   class AND
  416.   PTR    extp)
  417. {
  418.   union internal_auxent *in = (union internal_auxent *)inp;
  419.   AUXENT *ext = (AUXENT *)extp;
  420.  
  421.   memset((PTR)ext, 0, AUXESZ);
  422.   switch (class) {
  423.   case C_FILE:
  424.     if (in->x_file.x_fname[0] == 0) {
  425.       PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
  426.       PUTWORD(abfd,
  427.           in->x_file.x_n.x_offset,
  428.           (bfd_byte *) ext->x_file.x_n.x_offset);
  429.     }
  430.     else {
  431. #if FILNMLEN != E_FILNMLEN
  432.       -> Error, we need to cope with truncating or extending FILNMLEN!;
  433. #else
  434.       memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
  435. #endif
  436.     }
  437.     break;
  438.  
  439. #ifdef RS6000COFF_C
  440.   /* RS/6000 "csect" auxents */
  441.   case C_EXT:
  442.   case C_HIDEXT:
  443.     PUTWORD (abfd, in->x_csect.x_scnlen,    ext->x_csect.x_scnlen);
  444.     PUTWORD (abfd, in->x_csect.x_parmhash,    ext->x_csect.x_parmhash);
  445.     PUTHALF (abfd, in->x_csect.x_snhash,    ext->x_csect.x_snhash);
  446.     /* We don't have to hack bitfields in x_smtyp because it's defined by
  447.        shifts-and-ands, which are equivalent on all byte orders.  */
  448.     PUTBYTE (abfd, in->x_csect.x_smtyp,        ext->x_csect.x_smtyp);
  449.     PUTBYTE (abfd, in->x_csect.x_smclas,    ext->x_csect.x_smclas);
  450.     PUTWORD (abfd, in->x_csect.x_stab,        ext->x_csect.x_stab);
  451.     PUTHALF (abfd, in->x_csect.x_snstab,    ext->x_csect.x_snstab);
  452.     break;
  453. #endif
  454.  
  455.   case C_STAT:
  456. #ifdef C_LEAFSTAT
  457.   case C_LEAFSTAT:
  458. #endif
  459.   case C_HIDDEN:
  460.     if (type == T_NULL) {
  461.       PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
  462.       PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
  463.       PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
  464.       break;
  465.     }
  466.   default:
  467.     PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
  468. #ifndef NO_TVNDX
  469.     bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
  470. #endif
  471.  
  472.     if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
  473.       PUT_FCN_LNNOPTR(abfd,  in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
  474.       PUT_FCN_ENDNDX(abfd,  in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
  475.     }
  476.  
  477.     if (ISFCN(type)) {
  478.       PUTWORD(abfd, in->x_sym.x_misc.x_fsize, (bfd_byte *)  ext->x_sym.x_misc.x_fsize);
  479.     }
  480.     else {
  481.       if (ISARY(type)) {
  482. #if DIMNUM != E_DIMNUM
  483.     -> Error, we need to cope with truncating or extending DIMNUM!;
  484. #else
  485.     bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
  486.     bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
  487.     bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
  488.     bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
  489. #endif
  490.       }
  491.       PUT_LNSZ_LNNO(abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
  492.       PUT_LNSZ_SIZE(abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
  493.     }
  494.   }
  495. return sizeof(AUXENT);
  496. }
  497.  
  498. #endif /* NO_COFF_SYMBOLS */
  499.  
  500. #ifndef NO_COFF_LINENOS
  501.  
  502. static void
  503. DEFUN(coff_swap_lineno_in,(abfd, ext1, in1),
  504.       bfd            *abfd AND
  505.       PTR ext1 AND
  506.       PTR in1)
  507. {
  508.   LINENO *ext = (LINENO *)ext1;
  509.   struct internal_lineno      *in = (struct internal_lineno *)in1;
  510.  
  511.   in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
  512.   in->l_lnno = GET_LINENO_LNNO(abfd, ext);
  513. }
  514.  
  515. static unsigned int
  516. DEFUN(coff_swap_lineno_out,(abfd, inp, outp),
  517.       bfd       *abfd AND
  518.       PTR    inp AND
  519.       PTR    outp)
  520. {
  521.   struct internal_lineno *in = (struct internal_lineno *)inp;
  522.   struct external_lineno *ext = (struct external_lineno *)outp;
  523.   PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
  524.       ext->l_addr.l_symndx);
  525.  
  526.   PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
  527.   return sizeof(struct external_lineno);
  528. }
  529.  
  530. #endif /* NO_COFF_LINENOS */
  531.  
  532.  
  533. static void
  534. DEFUN(coff_swap_aouthdr_in,(abfd, aouthdr_ext1, aouthdr_int1),
  535.       bfd            *abfd AND
  536.       PTR aouthdr_ext1 AND
  537.       PTR aouthdr_int1)
  538. {
  539.   AOUTHDR        *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
  540.   struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
  541.  
  542.   aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
  543.   aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
  544.   aouthdr_int->tsize =
  545.     GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
  546.   aouthdr_int->dsize =
  547.     GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
  548.   aouthdr_int->bsize =
  549.     GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
  550.   aouthdr_int->entry =
  551.     GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
  552.   aouthdr_int->text_start =
  553.     GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
  554.   aouthdr_int->data_start =
  555.     GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
  556.  
  557. #ifdef I960
  558.   aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
  559. #endif
  560.  
  561. #ifdef APOLLO_M68
  562.   bfd_h_put_32(abfd, aouthdr_int->o_inlib, (bfd_byte *) aouthdr_ext->o_inlib);
  563.   bfd_h_put_32(abfd, aouthdr_int->o_sri, (bfd_byte *) aouthdr_ext->o_sri);
  564.   bfd_h_put_32(abfd, aouthdr_int->vid[0], (bfd_byte *) aouthdr_ext->vid);
  565.   bfd_h_put_32(abfd, aouthdr_int->vid[1], (bfd_byte *) aouthdr_ext->vid + 4);
  566. #endif
  567.  
  568.  
  569. #ifdef RS6000COFF_C
  570.   aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
  571.   aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
  572.   aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
  573.   aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
  574.   aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
  575.   aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
  576.   aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
  577.   aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
  578.   aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
  579.   aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
  580.   aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
  581. #endif
  582.  
  583. #ifdef MIPSECOFF
  584.   aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
  585.   aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
  586.   aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
  587.   aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
  588.   aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
  589.   aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
  590.   aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
  591. #endif
  592.  
  593. #ifdef ALPHAECOFF
  594.   aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
  595.   aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
  596.   aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
  597.   aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
  598. #endif
  599. }
  600.  
  601. static unsigned int
  602. DEFUN(coff_swap_aouthdr_out,(abfd, in, out),
  603.       bfd       *abfd AND
  604.       PTR    in AND
  605.       PTR    out)
  606. {
  607.   struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
  608.   AOUTHDR *aouthdr_out = (AOUTHDR *)out;
  609.  
  610.   bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
  611.   bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
  612.   PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
  613.   PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
  614.   PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
  615.   PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
  616.   PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
  617.               (bfd_byte *) aouthdr_out->text_start);
  618.   PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
  619.               (bfd_byte *) aouthdr_out->data_start);
  620. #ifdef I960
  621.   bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
  622. #endif
  623.  
  624. #ifdef MIPSECOFF
  625.   bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
  626.   bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
  627.   bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
  628.   bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
  629.   bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
  630.   bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
  631.   bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
  632. #endif
  633.  
  634. #ifdef ALPHAECOFF
  635.   /* FIXME: What does bldrev mean?  */
  636.   bfd_h_put_16(abfd, (bfd_vma) 2, (bfd_byte *) aouthdr_out->bldrev);
  637.   bfd_h_put_16(abfd, (bfd_vma) 0, (bfd_byte *) aouthdr_out->padding);
  638.   bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
  639.   bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
  640.   bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
  641.   bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
  642. #endif
  643.  
  644.   return sizeof(AOUTHDR);
  645. }
  646.  
  647. static void
  648. DEFUN(coff_swap_scnhdr_in,(abfd, ext, in),
  649.       bfd            *abfd AND
  650.       PTR         ext AND
  651.       PTR         in)
  652. {
  653.   SCNHDR *scnhdr_ext = (SCNHDR *) ext;
  654.   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
  655.  
  656.   memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
  657.   scnhdr_int->s_vaddr =
  658.     GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
  659.   scnhdr_int->s_paddr =
  660.     GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
  661.   scnhdr_int->s_size =
  662.     GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
  663.  
  664.   scnhdr_int->s_scnptr =
  665.     GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
  666.   scnhdr_int->s_relptr =
  667.     GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
  668.   scnhdr_int->s_lnnoptr =
  669.     GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
  670.   scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
  671. #if defined(M88)
  672.   scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
  673.   scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
  674. #else
  675.   scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
  676.   scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
  677. #endif
  678. #ifdef I960
  679.   scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
  680. #endif
  681. }
  682.  
  683. static unsigned int
  684. DEFUN(coff_swap_scnhdr_out,(abfd, in, out),
  685.       bfd       *abfd AND
  686.       PTR    in AND
  687.       PTR    out)
  688. {
  689.   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
  690.   SCNHDR *scnhdr_ext = (SCNHDR *)out;
  691.  
  692.   memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
  693.   PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
  694.             (bfd_byte *) scnhdr_ext->s_vaddr);
  695.   PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
  696.             (bfd_byte *) scnhdr_ext->s_paddr);
  697.   PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
  698.            (bfd_byte *) scnhdr_ext->s_size);
  699.   PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
  700.              (bfd_byte *) scnhdr_ext->s_scnptr);
  701.   PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
  702.              (bfd_byte *) scnhdr_ext->s_relptr);
  703.   PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
  704.               (bfd_byte *) scnhdr_ext->s_lnnoptr);
  705.   PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
  706. #if defined(M88)
  707.   PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
  708.   PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
  709. #else
  710.   PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
  711.   PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
  712. #endif
  713.  
  714. #if defined(I960)
  715.   PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
  716. #endif
  717.   return sizeof(SCNHDR);
  718. }
  719.