home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / bfd / coffswap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-13  |  25.0 KB  |  742 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. bfd_swap_reloc_in (abfd, reloc_src, reloc_dst)
  172.      bfd            *abfd;
  173.      RELOC *reloc_src;
  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. coff_swap_reloc_out (abfd, src, dst)
  195.      bfd       *abfd;
  196.      PTR    src;
  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.  
  204. #ifdef RS6000COFF_C
  205.   bfd_h_put_8 (abfd, reloc_src->r_type, (bfd_byte *) reloc_dst->r_type);
  206.   bfd_h_put_8 (abfd, reloc_src->r_size, (bfd_byte *) reloc_dst->r_size);
  207. #else
  208.   bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
  209.            reloc_dst->r_type);
  210. #endif
  211.  
  212. #ifdef SWAP_OUT_RELOC_OFFSET
  213.   SWAP_OUT_RELOC_OFFSET(abfd,
  214.             reloc_src->r_offset,
  215.             (bfd_byte *) reloc_dst->r_offset);
  216. #endif
  217. #ifdef SWAP_OUT_RELOC_EXTRA
  218.   SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
  219. #endif
  220.  
  221.   return sizeof(struct external_reloc);
  222. }
  223.  
  224. #endif /* NO_COFF_RELOCS */
  225.  
  226. static void
  227. coff_swap_filehdr_in (abfd, src, dst)
  228.      bfd            *abfd;
  229.      PTR         src;
  230.      PTR         dst;
  231. {
  232.   FILHDR *filehdr_src = (FILHDR *) src;
  233.   struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
  234.   filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
  235.   filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
  236.   filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
  237.   filehdr_dst->f_symptr =
  238.     GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
  239.   filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
  240.   filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
  241.   filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
  242. }
  243.  
  244. static  unsigned int
  245. coff_swap_filehdr_out (abfd, in, out)
  246.      bfd       *abfd;
  247.      PTR    in;
  248.      PTR    out;
  249. {
  250.   struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
  251.   FILHDR *filehdr_out = (FILHDR *)out;
  252.   bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
  253.   bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
  254.   bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
  255.   PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
  256.               (bfd_byte *) filehdr_out->f_symptr);
  257.   bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
  258.   bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
  259.   bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
  260.   return sizeof(FILHDR);
  261. }
  262.  
  263.  
  264. #ifndef NO_COFF_SYMBOLS
  265.  
  266. static void
  267. coff_swap_sym_in (abfd, ext1, in1)
  268.      bfd            *abfd;
  269.      PTR ext1;
  270.      PTR in1;
  271. {
  272.   SYMENT *ext = (SYMENT *)ext1;
  273.   struct internal_syment      *in = (struct internal_syment *)in1;
  274.  
  275.   if( ext->e.e_name[0] == 0) {
  276.     in->_n._n_n._n_zeroes = 0;
  277.     in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
  278.   }
  279.   else {
  280. #if SYMNMLEN != E_SYMNMLEN
  281.    -> Error, we need to cope with truncating or extending SYMNMLEN!;
  282. #else
  283.     memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
  284. #endif
  285.   }
  286.   in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
  287.   in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
  288.   if (sizeof(ext->e_type) == 2){
  289.     in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
  290.   }
  291.   else {
  292.     in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
  293.   }
  294.   in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
  295.   in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
  296. }
  297.  
  298. static unsigned int
  299. coff_swap_sym_out (abfd, inp, extp)
  300.      bfd       *abfd;
  301.      PTR    inp;
  302.      PTR    extp;
  303. {
  304.   struct internal_syment *in = (struct internal_syment *)inp;
  305.   SYMENT *ext =(SYMENT *)extp;
  306.   if(in->_n._n_name[0] == 0) {
  307.     bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
  308.     bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *)  ext->e.e.e_offset);
  309.   }
  310.   else {
  311. #if SYMNMLEN != E_SYMNMLEN
  312.     -> Error, we need to cope with truncating or extending SYMNMLEN!;
  313. #else
  314.     memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
  315. #endif
  316.   }
  317.   bfd_h_put_32(abfd,  in->n_value , (bfd_byte *) ext->e_value);
  318.   bfd_h_put_16(abfd,  in->n_scnum , (bfd_byte *) ext->e_scnum);
  319.   if (sizeof(ext->e_type) == 2)
  320.       {
  321.     bfd_h_put_16(abfd,  in->n_type , (bfd_byte *) ext->e_type);
  322.       }
  323.   else
  324.       {
  325.     bfd_h_put_32(abfd,  in->n_type , (bfd_byte *) ext->e_type);
  326.       }
  327.   bfd_h_put_8(abfd,  in->n_sclass , ext->e_sclass);
  328.   bfd_h_put_8(abfd,  in->n_numaux , ext->e_numaux);
  329.   return sizeof(SYMENT);
  330. }
  331.  
  332. static void
  333. coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
  334.      bfd            *abfd;
  335.      PTR           ext1;
  336.      int             type;
  337.      int             class;
  338.      int          indx;
  339.      int          numaux;
  340.      PTR           in1;
  341. {
  342.   AUXENT    *ext = (AUXENT *)ext1;
  343.   union internal_auxent *in = (union internal_auxent *)in1;
  344.  
  345.   switch (class) {
  346.     case C_FILE:
  347.       if (ext->x_file.x_fname[0] == 0) {
  348.       in->x_file.x_n.x_zeroes = 0;
  349.       in->x_file.x_n.x_offset = 
  350.        bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
  351.     } else {
  352. #if FILNMLEN != E_FILNMLEN
  353.         -> Error, we need to cope with truncating or extending FILNMLEN!;
  354. #else
  355.         memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
  356. #endif
  357.       }
  358.       return;
  359.  
  360.       /* RS/6000 "csect" auxents */
  361. #ifdef RS6000COFF_C
  362.     case C_EXT:
  363.     case C_HIDEXT:
  364.       if (indx + 1 == numaux)
  365.     {
  366.       in->x_csect.x_scnlen.l = bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
  367.       in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
  368.                          ext->x_csect.x_parmhash);
  369.       in->x_csect.x_snhash   = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
  370.       /* We don't have to hack bitfields in x_smtyp because it's
  371.          defined by shifts-and-ands, which are equivalent on all
  372.          byte orders.  */
  373.       in->x_csect.x_smtyp    = bfd_h_get_8  (abfd, ext->x_csect.x_smtyp);
  374.       in->x_csect.x_smclas   = bfd_h_get_8  (abfd, ext->x_csect.x_smclas);
  375.       in->x_csect.x_stab     = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
  376.       in->x_csect.x_snstab   = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
  377.       return;
  378.     }
  379.       break;
  380. #endif
  381.  
  382.     case C_STAT:
  383. #ifdef C_LEAFSTAT
  384.     case C_LEAFSTAT:
  385. #endif
  386.     case C_HIDDEN:
  387.       if (type == T_NULL) {
  388.       in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
  389.       in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
  390.       in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
  391.       return;
  392.     }
  393.       break;
  394.     }
  395.  
  396.   in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
  397. #ifndef NO_TVNDX
  398.   in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
  399. #endif
  400.  
  401.   if (ISARY(type)) {
  402. #if DIMNUM != E_DIMNUM
  403.     -> Error, we need to cope with truncating or extending DIMNUM!;
  404. #else
  405.     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]);
  406.     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]);
  407.     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]);
  408.     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]);
  409. #endif
  410.   }
  411.   if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
  412.     in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR(abfd, ext);
  413.     in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX(abfd, ext);
  414.   }
  415.  
  416.   if (ISFCN(type)) {
  417.     in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
  418.   }
  419.   else {
  420.     in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
  421.     in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
  422.   }
  423. }
  424.  
  425. static unsigned int
  426. coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
  427.      bfd   *abfd;
  428.      PTR     inp;
  429.      int   type;
  430.      int   class;
  431.      int   indx;
  432.      int   numaux;
  433.      PTR    extp;
  434. {
  435.   union internal_auxent *in = (union internal_auxent *)inp;
  436.   AUXENT *ext = (AUXENT *)extp;
  437.  
  438.   memset((PTR)ext, 0, AUXESZ);
  439.   switch (class) {
  440.   case C_FILE:
  441.     if (in->x_file.x_fname[0] == 0) {
  442.       PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
  443.       PUTWORD(abfd,
  444.           in->x_file.x_n.x_offset,
  445.           (bfd_byte *) ext->x_file.x_n.x_offset);
  446.     }
  447.     else {
  448. #if FILNMLEN != E_FILNMLEN
  449.       -> Error, we need to cope with truncating or extending FILNMLEN!;
  450. #else
  451.       memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
  452. #endif
  453.     }
  454.     return sizeof (AUXENT);
  455.  
  456. #ifdef RS6000COFF_C
  457.   /* RS/6000 "csect" auxents */
  458.   case C_EXT:
  459.   case C_HIDEXT:
  460.     if (indx + 1 == numaux)
  461.       {
  462.     PUTWORD (abfd, in->x_csect.x_scnlen.l,    ext->x_csect.x_scnlen);
  463.     PUTWORD (abfd, in->x_csect.x_parmhash,    ext->x_csect.x_parmhash);
  464.     PUTHALF (abfd, in->x_csect.x_snhash,    ext->x_csect.x_snhash);
  465.     /* We don't have to hack bitfields in x_smtyp because it's
  466.        defined by shifts-and-ands, which are equivalent on all
  467.        byte orders.  */
  468.     PUTBYTE (abfd, in->x_csect.x_smtyp,    ext->x_csect.x_smtyp);
  469.     PUTBYTE (abfd, in->x_csect.x_smclas,    ext->x_csect.x_smclas);
  470.     PUTWORD (abfd, in->x_csect.x_stab,    ext->x_csect.x_stab);
  471.     PUTHALF (abfd, in->x_csect.x_snstab,    ext->x_csect.x_snstab);
  472.     return sizeof (AUXENT);
  473.       }
  474.     break;
  475. #endif
  476.  
  477.   case C_STAT:
  478. #ifdef C_LEAFSTAT
  479.   case C_LEAFSTAT:
  480. #endif
  481.   case C_HIDDEN:
  482.     if (type == T_NULL) {
  483.       PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
  484.       PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
  485.       PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
  486.       return sizeof (AUXENT);
  487.     }
  488.     break;
  489.   }
  490.  
  491.   PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
  492. #ifndef NO_TVNDX
  493.   bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
  494. #endif
  495.  
  496.   if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
  497.     PUT_FCN_LNNOPTR(abfd,  in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
  498.     PUT_FCN_ENDNDX(abfd,  in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
  499.   }
  500.  
  501.   if (ISFCN(type)) {
  502.     PUTWORD(abfd, in->x_sym.x_misc.x_fsize, (bfd_byte *)  ext->x_sym.x_misc.x_fsize);
  503.   }
  504.   else {
  505.     if (ISARY(type)) {
  506. #if DIMNUM != E_DIMNUM
  507.       -> Error, we need to cope with truncating or extending DIMNUM!;
  508. #else
  509.       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]);
  510.       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]);
  511.       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]);
  512.       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]);
  513. #endif
  514.     }
  515.     PUT_LNSZ_LNNO(abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
  516.     PUT_LNSZ_SIZE(abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
  517.   }
  518.   return sizeof(AUXENT);
  519. }
  520.  
  521. #endif /* NO_COFF_SYMBOLS */
  522.  
  523. #ifndef NO_COFF_LINENOS
  524.  
  525. static void
  526. coff_swap_lineno_in (abfd, ext1, in1)
  527.      bfd            *abfd;
  528.      PTR ext1;
  529.      PTR in1;
  530. {
  531.   LINENO *ext = (LINENO *)ext1;
  532.   struct internal_lineno      *in = (struct internal_lineno *)in1;
  533.  
  534.   in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
  535.   in->l_lnno = GET_LINENO_LNNO(abfd, ext);
  536. }
  537.  
  538. static unsigned int
  539. coff_swap_lineno_out (abfd, inp, outp)
  540.      bfd       *abfd;
  541.      PTR    inp;
  542.      PTR    outp;
  543. {
  544.   struct internal_lineno *in = (struct internal_lineno *)inp;
  545.   struct external_lineno *ext = (struct external_lineno *)outp;
  546.   PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
  547.       ext->l_addr.l_symndx);
  548.  
  549.   PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
  550.   return sizeof(struct external_lineno);
  551. }
  552.  
  553. #endif /* NO_COFF_LINENOS */
  554.  
  555.  
  556. static void
  557. coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
  558.      bfd            *abfd;
  559.      PTR aouthdr_ext1;
  560.      PTR aouthdr_int1;
  561. {
  562.   AOUTHDR        *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
  563.   struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
  564.  
  565.   aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
  566.   aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
  567.   aouthdr_int->tsize =
  568.     GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
  569.   aouthdr_int->dsize =
  570.     GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
  571.   aouthdr_int->bsize =
  572.     GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
  573.   aouthdr_int->entry =
  574.     GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
  575.   aouthdr_int->text_start =
  576.     GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
  577.   aouthdr_int->data_start =
  578.     GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
  579.  
  580. #ifdef I960
  581.   aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
  582. #endif
  583.  
  584. #ifdef APOLLO_M68
  585.   bfd_h_put_32(abfd, aouthdr_int->o_inlib, (bfd_byte *) aouthdr_ext->o_inlib);
  586.   bfd_h_put_32(abfd, aouthdr_int->o_sri, (bfd_byte *) aouthdr_ext->o_sri);
  587.   bfd_h_put_32(abfd, aouthdr_int->vid[0], (bfd_byte *) aouthdr_ext->vid);
  588.   bfd_h_put_32(abfd, aouthdr_int->vid[1], (bfd_byte *) aouthdr_ext->vid + 4);
  589. #endif
  590.  
  591.  
  592. #ifdef RS6000COFF_C
  593.   aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
  594.   aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
  595.   aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
  596.   aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
  597.   aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
  598.   aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
  599.   aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
  600.   aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
  601.   aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
  602.   aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
  603.   aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
  604. #endif
  605.  
  606. #ifdef MIPSECOFF
  607.   aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
  608.   aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
  609.   aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
  610.   aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
  611.   aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
  612.   aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
  613.   aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
  614. #endif
  615.  
  616. #ifdef ALPHAECOFF
  617.   aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
  618.   aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
  619.   aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
  620.   aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
  621. #endif
  622. }
  623.  
  624. static unsigned int
  625. coff_swap_aouthdr_out (abfd, in, out)
  626.      bfd       *abfd;
  627.      PTR    in;
  628.      PTR    out;
  629. {
  630.   struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
  631.   AOUTHDR *aouthdr_out = (AOUTHDR *)out;
  632.  
  633.   bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
  634.   bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
  635.   PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
  636.   PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
  637.   PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
  638.   PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
  639.   PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
  640.               (bfd_byte *) aouthdr_out->text_start);
  641.   PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
  642.               (bfd_byte *) aouthdr_out->data_start);
  643. #ifdef I960
  644.   bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
  645. #endif
  646.  
  647. #ifdef MIPSECOFF
  648.   bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
  649.   bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
  650.   bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
  651.   bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
  652.   bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
  653.   bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
  654.   bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
  655. #endif
  656.  
  657. #ifdef ALPHAECOFF
  658.   /* FIXME: What does bldrev mean?  */
  659.   bfd_h_put_16(abfd, (bfd_vma) 2, (bfd_byte *) aouthdr_out->bldrev);
  660.   bfd_h_put_16(abfd, (bfd_vma) 0, (bfd_byte *) aouthdr_out->padding);
  661.   bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
  662.   bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
  663.   bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
  664.   bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
  665. #endif
  666.  
  667.   return sizeof(AOUTHDR);
  668. }
  669.  
  670. static void
  671. coff_swap_scnhdr_in (abfd, ext, in)
  672.      bfd            *abfd;
  673.      PTR         ext;
  674.      PTR         in;
  675. {
  676.   SCNHDR *scnhdr_ext = (SCNHDR *) ext;
  677.   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
  678.  
  679.   memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
  680.   scnhdr_int->s_vaddr =
  681.     GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
  682.   scnhdr_int->s_paddr =
  683.     GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
  684.   scnhdr_int->s_size =
  685.     GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
  686.  
  687.   scnhdr_int->s_scnptr =
  688.     GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
  689.   scnhdr_int->s_relptr =
  690.     GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
  691.   scnhdr_int->s_lnnoptr =
  692.     GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
  693.   scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
  694. #if defined(M88)
  695.   scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
  696.   scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
  697. #else
  698.   scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
  699.   scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
  700. #endif
  701. #ifdef I960
  702.   scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
  703. #endif
  704. }
  705.  
  706. static unsigned int
  707. coff_swap_scnhdr_out (abfd, in, out)
  708.      bfd       *abfd;
  709.      PTR    in;
  710.      PTR    out;
  711. {
  712.   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
  713.   SCNHDR *scnhdr_ext = (SCNHDR *)out;
  714.  
  715.   memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
  716.   PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
  717.             (bfd_byte *) scnhdr_ext->s_vaddr);
  718.   PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
  719.             (bfd_byte *) scnhdr_ext->s_paddr);
  720.   PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
  721.            (bfd_byte *) scnhdr_ext->s_size);
  722.   PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
  723.              (bfd_byte *) scnhdr_ext->s_scnptr);
  724.   PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
  725.              (bfd_byte *) scnhdr_ext->s_relptr);
  726.   PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
  727.               (bfd_byte *) scnhdr_ext->s_lnnoptr);
  728.   PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
  729. #if defined(M88)
  730.   PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
  731.   PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
  732. #else
  733.   PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
  734.   PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
  735. #endif
  736.  
  737. #if defined(I960)
  738.   PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
  739. #endif
  740.   return sizeof(SCNHDR);
  741. }
  742.