ecoffswap.h revision 77298
133965Sjdp/* Generic ECOFF swapping routines, for BFD.
277298Sobrien   Copyright 1992, 1993, 1994, 1995, 1996, 2000 Free Software Foundation, Inc.
333965Sjdp   Written by Cygnus Support.
433965Sjdp
533965SjdpThis file is part of BFD, the Binary File Descriptor library.
633965Sjdp
733965SjdpThis program is free software; you can redistribute it and/or modify
833965Sjdpit under the terms of the GNU General Public License as published by
933965Sjdpthe Free Software Foundation; either version 2 of the License, or
1033965Sjdp(at your option) any later version.
1133965Sjdp
1233965SjdpThis program is distributed in the hope that it will be useful,
1333965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1433965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1533965SjdpGNU General Public License for more details.
1633965Sjdp
1733965SjdpYou should have received a copy of the GNU General Public License
1833965Sjdpalong with this program; if not, write to the Free Software
1933965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2033965Sjdp
2133965Sjdp/* NOTE: This is a header file, but it contains executable routines.
2233965Sjdp   This is done this way because these routines are substantially
2333965Sjdp   similar, but are not identical, for all ECOFF targets.
2433965Sjdp
2533965Sjdp   These are routines to swap the ECOFF symbolic information in and
2633965Sjdp   out.  The routines are defined statically.  You can set breakpoints
2733965Sjdp   on them in gdb by naming the including source file; e.g.,
2833965Sjdp   'coff-mips.c':ecoff_swap_hdr_in.
2933965Sjdp
3077298Sobrien   Before including this header file, one of ECOFF_32, ECOFF_64,
3177298Sobrien   ECOFF_SIGNED_32 or ECOFF_SIGNED_64 must be defined.  These are
3277298Sobrien   checked when swapping information that depends upon the target
3377298Sobrien   size.  This code works for 32 bit and 64 bit ECOFF, but may need to
3477298Sobrien   be generalized in the future.
3533965Sjdp
3633965Sjdp   Some header file which defines the external forms of these
3733965Sjdp   structures must also be included before including this header file.
3833965Sjdp   Currently this is either coff/mips.h or coff/alpha.h.
3933965Sjdp
4033965Sjdp   If the symbol TEST is defined when this file is compiled, a
4133965Sjdp   comparison is made to ensure that, in fact, the output is
4233965Sjdp   bit-for-bit the same as the input.  Of course, this symbol should
4333965Sjdp   only be defined when deliberately testing the code on a machine
4433965Sjdp   with the proper byte sex and such.  */
4533965Sjdp
4633965Sjdp#ifdef ECOFF_32
4733965Sjdp#define ecoff_get_off bfd_h_get_32
4833965Sjdp#define ecoff_put_off bfd_h_put_32
4933965Sjdp#endif
5033965Sjdp#ifdef ECOFF_64
5133965Sjdp#define ecoff_get_off bfd_h_get_64
5233965Sjdp#define ecoff_put_off bfd_h_put_64
5333965Sjdp#endif
5477298Sobrien#ifdef ECOFF_SIGNED_32
5577298Sobrien#define ecoff_get_off bfd_h_get_signed_32
5677298Sobrien#define ecoff_put_off bfd_h_put_signed_32
5777298Sobrien#endif
5877298Sobrien#ifdef ECOFF_SIGNED_64
5977298Sobrien#define ecoff_get_off bfd_h_get_signed_64
6077298Sobrien#define ecoff_put_off bfd_h_put_signed_64
6177298Sobrien#endif
6233965Sjdp
6333965Sjdp/* ECOFF auxiliary information swapping routines.  These are the same
6433965Sjdp   for all ECOFF targets, so they are defined in ecofflink.c.  */
6533965Sjdp
6633965Sjdpextern void _bfd_ecoff_swap_tir_in
6733965Sjdp  PARAMS ((int, const struct tir_ext *, TIR *));
6833965Sjdpextern void _bfd_ecoff_swap_tir_out
6933965Sjdp  PARAMS ((int, const TIR *, struct tir_ext *));
7033965Sjdpextern void _bfd_ecoff_swap_rndx_in
7133965Sjdp  PARAMS ((int, const struct rndx_ext *, RNDXR *));
7233965Sjdpextern void _bfd_ecoff_swap_rndx_out
7333965Sjdp  PARAMS ((int, const RNDXR *, struct rndx_ext *));
7433965Sjdp
7533965Sjdp/* Prototypes for functions defined in this file.  */
7633965Sjdp
7733965Sjdpstatic void ecoff_swap_hdr_in PARAMS ((bfd *, PTR, HDRR *));
7833965Sjdpstatic void ecoff_swap_hdr_out PARAMS ((bfd *, const HDRR *, PTR));
7933965Sjdpstatic void ecoff_swap_fdr_in PARAMS ((bfd *, PTR, FDR *));
8033965Sjdpstatic void ecoff_swap_fdr_out PARAMS ((bfd *, const FDR *, PTR));
8133965Sjdpstatic void ecoff_swap_pdr_in PARAMS ((bfd *, PTR, PDR *));
8233965Sjdpstatic void ecoff_swap_pdr_out PARAMS ((bfd *, const PDR *, PTR));
8333965Sjdpstatic void ecoff_swap_sym_in PARAMS ((bfd *, PTR, SYMR *));
8433965Sjdpstatic void ecoff_swap_sym_out PARAMS ((bfd *, const SYMR *, PTR));
8533965Sjdpstatic void ecoff_swap_ext_in PARAMS ((bfd *, PTR, EXTR *));
8633965Sjdpstatic void ecoff_swap_ext_out PARAMS ((bfd *, const EXTR *, PTR));
8733965Sjdpstatic void ecoff_swap_rfd_in PARAMS ((bfd *, PTR, RFDT *));
8833965Sjdpstatic void ecoff_swap_rfd_out PARAMS ((bfd *, const RFDT *, PTR));
8933965Sjdpstatic void ecoff_swap_opt_in PARAMS ((bfd *, PTR, OPTR *));
9033965Sjdpstatic void ecoff_swap_opt_out PARAMS ((bfd *, const OPTR *, PTR));
9133965Sjdpstatic void ecoff_swap_dnr_in PARAMS ((bfd *, PTR, DNR *));
9233965Sjdpstatic void ecoff_swap_dnr_out PARAMS ((bfd *, const DNR *, PTR));
9333965Sjdp
9433965Sjdp/* Swap in the symbolic header.  */
9533965Sjdp
9633965Sjdpstatic void
9733965Sjdpecoff_swap_hdr_in (abfd, ext_copy, intern)
9833965Sjdp     bfd *abfd;
9933965Sjdp     PTR ext_copy;
10033965Sjdp     HDRR *intern;
10133965Sjdp{
10233965Sjdp  struct hdr_ext ext[1];
10333965Sjdp
10433965Sjdp  *ext = *(struct hdr_ext *) ext_copy;
10533965Sjdp
10633965Sjdp  intern->magic         = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_magic);
10733965Sjdp  intern->vstamp        = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_vstamp);
10833965Sjdp  intern->ilineMax      = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax);
10933965Sjdp  intern->cbLine        = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLine);
11033965Sjdp  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLineOffset);
11133965Sjdp  intern->idnMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax);
11233965Sjdp  intern->cbDnOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbDnOffset);
11333965Sjdp  intern->ipdMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax);
11433965Sjdp  intern->cbPdOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbPdOffset);
11533965Sjdp  intern->isymMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax);
11633965Sjdp  intern->cbSymOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSymOffset);
11733965Sjdp  intern->ioptMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax);
11833965Sjdp  intern->cbOptOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbOptOffset);
11933965Sjdp  intern->iauxMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax);
12033965Sjdp  intern->cbAuxOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbAuxOffset);
12133965Sjdp  intern->issMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax);
12233965Sjdp  intern->cbSsOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsOffset);
12333965Sjdp  intern->issExtMax     = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax);
12433965Sjdp  intern->cbSsExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsExtOffset);
12533965Sjdp  intern->ifdMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax);
12633965Sjdp  intern->cbFdOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbFdOffset);
12733965Sjdp  intern->crfd          = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd);
12833965Sjdp  intern->cbRfdOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbRfdOffset);
12933965Sjdp  intern->iextMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax);
13033965Sjdp  intern->cbExtOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbExtOffset);
13133965Sjdp
13233965Sjdp#ifdef TEST
13333965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
13477298Sobrien    abort ();
13533965Sjdp#endif
13633965Sjdp}
13733965Sjdp
13833965Sjdp/* Swap out the symbolic header.  */
13933965Sjdp
14033965Sjdpstatic void
14133965Sjdpecoff_swap_hdr_out (abfd, intern_copy, ext_ptr)
14233965Sjdp     bfd *abfd;
14333965Sjdp     const HDRR *intern_copy;
14433965Sjdp     PTR ext_ptr;
14533965Sjdp{
14633965Sjdp  struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
14733965Sjdp  HDRR intern[1];
14833965Sjdp
14933965Sjdp  *intern = *intern_copy;
15033965Sjdp
15133965Sjdp  bfd_h_put_signed_16 (abfd, intern->magic, (bfd_byte *)ext->h_magic);
15233965Sjdp  bfd_h_put_signed_16 (abfd, intern->vstamp, (bfd_byte *)ext->h_vstamp);
15333965Sjdp  bfd_h_put_32 (abfd, intern->ilineMax, (bfd_byte *)ext->h_ilineMax);
15433965Sjdp  ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->h_cbLine);
15533965Sjdp  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->h_cbLineOffset);
15633965Sjdp  bfd_h_put_32 (abfd, intern->idnMax, (bfd_byte *)ext->h_idnMax);
15733965Sjdp  ecoff_put_off (abfd, intern->cbDnOffset, (bfd_byte *)ext->h_cbDnOffset);
15833965Sjdp  bfd_h_put_32 (abfd, intern->ipdMax, (bfd_byte *)ext->h_ipdMax);
15933965Sjdp  ecoff_put_off (abfd, intern->cbPdOffset, (bfd_byte *)ext->h_cbPdOffset);
16033965Sjdp  bfd_h_put_32 (abfd, intern->isymMax, (bfd_byte *)ext->h_isymMax);
16133965Sjdp  ecoff_put_off (abfd, intern->cbSymOffset, (bfd_byte *)ext->h_cbSymOffset);
16233965Sjdp  bfd_h_put_32 (abfd, intern->ioptMax, (bfd_byte *)ext->h_ioptMax);
16333965Sjdp  ecoff_put_off (abfd, intern->cbOptOffset, (bfd_byte *)ext->h_cbOptOffset);
16433965Sjdp  bfd_h_put_32 (abfd, intern->iauxMax, (bfd_byte *)ext->h_iauxMax);
16533965Sjdp  ecoff_put_off (abfd, intern->cbAuxOffset, (bfd_byte *)ext->h_cbAuxOffset);
16633965Sjdp  bfd_h_put_32 (abfd, intern->issMax, (bfd_byte *)ext->h_issMax);
16733965Sjdp  ecoff_put_off (abfd, intern->cbSsOffset, (bfd_byte *)ext->h_cbSsOffset);
16833965Sjdp  bfd_h_put_32 (abfd, intern->issExtMax, (bfd_byte *)ext->h_issExtMax);
16933965Sjdp  ecoff_put_off (abfd, intern->cbSsExtOffset, (bfd_byte *)ext->h_cbSsExtOffset);
17033965Sjdp  bfd_h_put_32 (abfd, intern->ifdMax, (bfd_byte *)ext->h_ifdMax);
17133965Sjdp  ecoff_put_off (abfd, intern->cbFdOffset, (bfd_byte *)ext->h_cbFdOffset);
17233965Sjdp  bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->h_crfd);
17333965Sjdp  ecoff_put_off (abfd, intern->cbRfdOffset, (bfd_byte *)ext->h_cbRfdOffset);
17433965Sjdp  bfd_h_put_32 (abfd, intern->iextMax, (bfd_byte *)ext->h_iextMax);
17533965Sjdp  ecoff_put_off (abfd, intern->cbExtOffset, (bfd_byte *)ext->h_cbExtOffset);
17633965Sjdp
17733965Sjdp#ifdef TEST
17833965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
17977298Sobrien    abort ();
18033965Sjdp#endif
18133965Sjdp}
18233965Sjdp
18333965Sjdp/* Swap in the file descriptor record.  */
18433965Sjdp
18533965Sjdpstatic void
18633965Sjdpecoff_swap_fdr_in (abfd, ext_copy, intern)
18733965Sjdp     bfd *abfd;
18833965Sjdp     PTR ext_copy;
18933965Sjdp     FDR *intern;
19033965Sjdp{
19133965Sjdp  struct fdr_ext ext[1];
19233965Sjdp
19333965Sjdp  *ext = *(struct fdr_ext *) ext_copy;
19477298Sobrien
19533965Sjdp  intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->f_adr);
19633965Sjdp  intern->rss           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
19777298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
19833965Sjdp  if (intern->rss == 0xffffffff)
19933965Sjdp    intern->rss = -1;
20033965Sjdp#endif
20133965Sjdp  intern->issBase       = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase);
20233965Sjdp  intern->cbSs          = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbSs);
20333965Sjdp  intern->isymBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase);
20433965Sjdp  intern->csym          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym);
20533965Sjdp  intern->ilineBase     = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase);
20633965Sjdp  intern->cline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
20733965Sjdp  intern->ioptBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
20833965Sjdp  intern->copt          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
20977298Sobrien#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
21033965Sjdp  intern->ipdFirst      = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
21133965Sjdp  intern->cpd           = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
21233965Sjdp#endif
21377298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
21433965Sjdp  intern->ipdFirst      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ipdFirst);
21533965Sjdp  intern->cpd           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cpd);
21633965Sjdp#endif
21733965Sjdp  intern->iauxBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase);
21833965Sjdp  intern->caux          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux);
21933965Sjdp  intern->rfdBase       = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase);
22033965Sjdp  intern->crfd          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd);
22133965Sjdp
22277298Sobrien  /* now the fun stuff...  */
22333965Sjdp  if (bfd_header_big_endian (abfd)) {
22433965Sjdp    intern->lang        = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
22533965Sjdp					>> FDR_BITS1_LANG_SH_BIG;
22633965Sjdp    intern->fMerge      = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
22733965Sjdp    intern->fReadin     = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
22833965Sjdp    intern->fBigendian  = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
22933965Sjdp    intern->glevel      = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
23033965Sjdp					>> FDR_BITS2_GLEVEL_SH_BIG;
23133965Sjdp  } else {
23233965Sjdp    intern->lang        = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
23333965Sjdp					>> FDR_BITS1_LANG_SH_LITTLE;
23433965Sjdp    intern->fMerge      = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
23533965Sjdp    intern->fReadin     = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
23633965Sjdp    intern->fBigendian  = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
23733965Sjdp    intern->glevel      = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
23833965Sjdp					>> FDR_BITS2_GLEVEL_SH_LITTLE;
23933965Sjdp  }
24033965Sjdp  intern->reserved = 0;
24133965Sjdp
24233965Sjdp  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLineOffset);
24333965Sjdp  intern->cbLine        = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLine);
24433965Sjdp
24533965Sjdp#ifdef TEST
24633965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
24777298Sobrien    abort ();
24833965Sjdp#endif
24933965Sjdp}
25033965Sjdp
25133965Sjdp/* Swap out the file descriptor record.  */
25233965Sjdp
25333965Sjdpstatic void
25433965Sjdpecoff_swap_fdr_out (abfd, intern_copy, ext_ptr)
25533965Sjdp     bfd *abfd;
25633965Sjdp     const FDR *intern_copy;
25733965Sjdp     PTR ext_ptr;
25833965Sjdp{
25933965Sjdp  struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
26033965Sjdp  FDR intern[1];
26133965Sjdp
26233965Sjdp  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
26377298Sobrien
26433965Sjdp  ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->f_adr);
26533965Sjdp  bfd_h_put_32 (abfd, intern->rss, (bfd_byte *)ext->f_rss);
26633965Sjdp  bfd_h_put_32 (abfd, intern->issBase, (bfd_byte *)ext->f_issBase);
26733965Sjdp  ecoff_put_off (abfd, intern->cbSs, (bfd_byte *)ext->f_cbSs);
26833965Sjdp  bfd_h_put_32 (abfd, intern->isymBase, (bfd_byte *)ext->f_isymBase);
26933965Sjdp  bfd_h_put_32 (abfd, intern->csym, (bfd_byte *)ext->f_csym);
27033965Sjdp  bfd_h_put_32 (abfd, intern->ilineBase, (bfd_byte *)ext->f_ilineBase);
27133965Sjdp  bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline);
27233965Sjdp  bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase);
27333965Sjdp  bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt);
27477298Sobrien#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
27533965Sjdp  bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
27633965Sjdp  bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
27733965Sjdp#endif
27877298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
27933965Sjdp  bfd_h_put_32 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
28033965Sjdp  bfd_h_put_32 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
28133965Sjdp#endif
28233965Sjdp  bfd_h_put_32 (abfd, intern->iauxBase, (bfd_byte *)ext->f_iauxBase);
28333965Sjdp  bfd_h_put_32 (abfd, intern->caux, (bfd_byte *)ext->f_caux);
28433965Sjdp  bfd_h_put_32 (abfd, intern->rfdBase, (bfd_byte *)ext->f_rfdBase);
28533965Sjdp  bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->f_crfd);
28633965Sjdp
28777298Sobrien  /* now the fun stuff...  */
28833965Sjdp  if (bfd_header_big_endian (abfd)) {
28933965Sjdp    ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
29033965Sjdp			& FDR_BITS1_LANG_BIG)
29133965Sjdp		       | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
29233965Sjdp		       | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
29333965Sjdp		       | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
29433965Sjdp    ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
29533965Sjdp		       & FDR_BITS2_GLEVEL_BIG);
29633965Sjdp    ext->f_bits2[1] = 0;
29733965Sjdp    ext->f_bits2[2] = 0;
29833965Sjdp  } else {
29933965Sjdp    ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
30033965Sjdp			& FDR_BITS1_LANG_LITTLE)
30133965Sjdp		       | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
30233965Sjdp		       | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
30333965Sjdp		       | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
30433965Sjdp    ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
30533965Sjdp		       & FDR_BITS2_GLEVEL_LITTLE);
30633965Sjdp    ext->f_bits2[1] = 0;
30733965Sjdp    ext->f_bits2[2] = 0;
30833965Sjdp  }
30933965Sjdp
31033965Sjdp  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->f_cbLineOffset);
31133965Sjdp  ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->f_cbLine);
31233965Sjdp
31333965Sjdp#ifdef TEST
31433965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
31577298Sobrien    abort ();
31633965Sjdp#endif
31733965Sjdp}
31833965Sjdp
31933965Sjdp#ifndef MPW_C
32033965Sjdp
32133965Sjdp/* Swap in the procedure descriptor record.  */
32233965Sjdp
32333965Sjdpstatic void
32433965Sjdpecoff_swap_pdr_in (abfd, ext_copy, intern)
32533965Sjdp     bfd *abfd;
32633965Sjdp     PTR ext_copy;
32733965Sjdp     PDR *intern;
32833965Sjdp{
32933965Sjdp  struct pdr_ext ext[1];
33033965Sjdp
33133965Sjdp  *ext = *(struct pdr_ext *) ext_copy;
33233965Sjdp
33333965Sjdp  memset ((PTR) intern, 0, sizeof (*intern));
33433965Sjdp
33533965Sjdp  intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr);
33633965Sjdp  intern->isym          = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
33733965Sjdp  intern->iline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
33833965Sjdp  intern->regmask       = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
33933965Sjdp  intern->regoffset     = bfd_h_get_signed_32 (abfd,
34033965Sjdp					       (bfd_byte *)ext->p_regoffset);
34133965Sjdp  intern->iopt          = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->p_iopt);
34233965Sjdp  intern->fregmask      = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
34333965Sjdp  intern->fregoffset    = bfd_h_get_signed_32 (abfd,
34433965Sjdp					       (bfd_byte *)ext->p_fregoffset);
34533965Sjdp  intern->frameoffset   = bfd_h_get_signed_32 (abfd,
34633965Sjdp					       (bfd_byte *)ext->p_frameoffset);
34733965Sjdp  intern->framereg      = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
34833965Sjdp  intern->pcreg         = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
34933965Sjdp  intern->lnLow         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
35033965Sjdp  intern->lnHigh        = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
35133965Sjdp  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
35233965Sjdp
35377298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
35433965Sjdp  intern->gp_prologue = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_gp_prologue);
35533965Sjdp  if (bfd_header_big_endian (abfd))
35633965Sjdp    {
35733965Sjdp      intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
35833965Sjdp      intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
35933965Sjdp      intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
36033965Sjdp      intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
36133965Sjdp			   << PDR_BITS1_RESERVED_SH_LEFT_BIG)
36233965Sjdp			  | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
36333965Sjdp			     >> PDR_BITS2_RESERVED_SH_BIG));
36433965Sjdp    }
36533965Sjdp  else
36633965Sjdp    {
36733965Sjdp      intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
36833965Sjdp      intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
36933965Sjdp      intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
37033965Sjdp      intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
37133965Sjdp			   >> PDR_BITS1_RESERVED_SH_LITTLE)
37233965Sjdp			  | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
37333965Sjdp			     << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
37433965Sjdp    }
37533965Sjdp  intern->localoff = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_localoff);
37677298Sobrien#endif
37733965Sjdp
37833965Sjdp#ifdef TEST
37933965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
38077298Sobrien    abort ();
38133965Sjdp#endif
38233965Sjdp}
38333965Sjdp
38433965Sjdp/* Swap out the procedure descriptor record.  */
38533965Sjdp
38633965Sjdpstatic void
38733965Sjdpecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
38833965Sjdp     bfd *abfd;
38933965Sjdp     const PDR *intern_copy;
39033965Sjdp     PTR ext_ptr;
39133965Sjdp{
39233965Sjdp  struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
39333965Sjdp  PDR intern[1];
39433965Sjdp
39533965Sjdp  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
39677298Sobrien
39733965Sjdp  ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr);
39833965Sjdp  bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
39933965Sjdp  bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
40033965Sjdp  bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
40133965Sjdp  bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
40233965Sjdp  bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
40333965Sjdp  bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
40433965Sjdp  bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
40533965Sjdp  bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
40633965Sjdp  bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
40733965Sjdp  bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
40833965Sjdp  bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
40933965Sjdp  bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
41033965Sjdp  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
41133965Sjdp
41277298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
41333965Sjdp  bfd_h_put_8 (abfd, intern->gp_prologue, (bfd_byte *) ext->p_gp_prologue);
41433965Sjdp  if (bfd_header_big_endian (abfd))
41533965Sjdp    {
41633965Sjdp      ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
41733965Sjdp			 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
41833965Sjdp			 | (intern->prof ? PDR_BITS1_PROF_BIG : 0)
41933965Sjdp			 | ((intern->reserved
42033965Sjdp			     >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
42133965Sjdp			    & PDR_BITS1_RESERVED_BIG));
42233965Sjdp      ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
42333965Sjdp			 & PDR_BITS2_RESERVED_BIG);
42433965Sjdp    }
42533965Sjdp  else
42633965Sjdp    {
42733965Sjdp      ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
42833965Sjdp			 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
42933965Sjdp			 | (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
43033965Sjdp			 | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
43133965Sjdp			    & PDR_BITS1_RESERVED_LITTLE));
43233965Sjdp      ext->p_bits2[0] = ((intern->reserved >>
43333965Sjdp			  PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
43433965Sjdp			 & PDR_BITS2_RESERVED_LITTLE);
43533965Sjdp    }
43633965Sjdp  bfd_h_put_8 (abfd, intern->localoff, (bfd_byte *) ext->p_localoff);
43777298Sobrien#endif
43833965Sjdp
43933965Sjdp#ifdef TEST
44033965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
44177298Sobrien    abort ();
44233965Sjdp#endif
44333965Sjdp}
44433965Sjdp
44533965Sjdp#else /* MPW_C */
44633965Sjdp/* Same routines, but with ECOFF_64 code removed, so ^&%$#&! MPW C doesn't
44777298Sobrien   corrupt itself and then freak out.  */
44833965Sjdp/* Swap in the procedure descriptor record.  */
44933965Sjdp
45033965Sjdpstatic void
45133965Sjdpecoff_swap_pdr_in (abfd, ext_copy, intern)
45233965Sjdp     bfd *abfd;
45333965Sjdp     PTR ext_copy;
45433965Sjdp     PDR *intern;
45533965Sjdp{
45633965Sjdp  struct pdr_ext ext[1];
45733965Sjdp
45833965Sjdp  *ext = *(struct pdr_ext *) ext_copy;
45977298Sobrien
46033965Sjdp  intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr);
46133965Sjdp  intern->isym          = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
46233965Sjdp  intern->iline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
46333965Sjdp  intern->regmask       = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
46433965Sjdp  intern->regoffset     = bfd_h_get_signed_32 (abfd,
46533965Sjdp					       (bfd_byte *)ext->p_regoffset);
46633965Sjdp  intern->iopt          = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->p_iopt);
46733965Sjdp  intern->fregmask      = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
46833965Sjdp  intern->fregoffset    = bfd_h_get_signed_32 (abfd,
46933965Sjdp					       (bfd_byte *)ext->p_fregoffset);
47033965Sjdp  intern->frameoffset   = bfd_h_get_signed_32 (abfd,
47133965Sjdp					       (bfd_byte *)ext->p_frameoffset);
47233965Sjdp  intern->framereg      = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
47333965Sjdp  intern->pcreg         = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
47433965Sjdp  intern->lnLow         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
47533965Sjdp  intern->lnHigh        = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
47633965Sjdp  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
47733965Sjdp
47833965Sjdp#ifdef TEST
47933965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
48077298Sobrien    abort ();
48133965Sjdp#endif
48233965Sjdp}
48333965Sjdp
48433965Sjdp/* Swap out the procedure descriptor record.  */
48533965Sjdp
48633965Sjdpstatic void
48733965Sjdpecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
48833965Sjdp     bfd *abfd;
48933965Sjdp     const PDR *intern_copy;
49033965Sjdp     PTR ext_ptr;
49133965Sjdp{
49233965Sjdp  struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
49333965Sjdp  PDR intern[1];
49433965Sjdp
49533965Sjdp  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
49677298Sobrien
49733965Sjdp  ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr);
49833965Sjdp  bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
49933965Sjdp  bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
50033965Sjdp  bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
50133965Sjdp  bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
50233965Sjdp  bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
50333965Sjdp  bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
50433965Sjdp  bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
50533965Sjdp  bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
50633965Sjdp  bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
50733965Sjdp  bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
50833965Sjdp  bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
50933965Sjdp  bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
51033965Sjdp  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
51133965Sjdp
51233965Sjdp#ifdef TEST
51333965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
51477298Sobrien    abort ();
51533965Sjdp#endif
51633965Sjdp}
51733965Sjdp#endif /* MPW_C */
51833965Sjdp
51933965Sjdp/* Swap in a symbol record.  */
52033965Sjdp
52133965Sjdpstatic void
52233965Sjdpecoff_swap_sym_in (abfd, ext_copy, intern)
52333965Sjdp     bfd *abfd;
52433965Sjdp     PTR ext_copy;
52533965Sjdp     SYMR *intern;
52633965Sjdp{
52733965Sjdp  struct sym_ext ext[1];
52833965Sjdp
52933965Sjdp  *ext = *(struct sym_ext *) ext_copy;
53077298Sobrien
53133965Sjdp  intern->iss           = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss);
53233965Sjdp  intern->value         = ecoff_get_off (abfd, (bfd_byte *)ext->s_value);
53333965Sjdp
53477298Sobrien  /* now the fun stuff...  */
53533965Sjdp  if (bfd_header_big_endian (abfd)) {
53633965Sjdp    intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
53733965Sjdp					   >> SYM_BITS1_ST_SH_BIG;
53833965Sjdp    intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
53933965Sjdp					   << SYM_BITS1_SC_SH_LEFT_BIG)
54033965Sjdp			| ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
54133965Sjdp					   >> SYM_BITS2_SC_SH_BIG);
54233965Sjdp    intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
54333965Sjdp    intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
54433965Sjdp					   << SYM_BITS2_INDEX_SH_LEFT_BIG)
54533965Sjdp			| (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
54633965Sjdp			| (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
54733965Sjdp  } else {
54833965Sjdp    intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
54933965Sjdp					   >> SYM_BITS1_ST_SH_LITTLE;
55033965Sjdp    intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
55133965Sjdp					   >> SYM_BITS1_SC_SH_LITTLE)
55233965Sjdp			| ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
55333965Sjdp					   << SYM_BITS2_SC_SH_LEFT_LITTLE);
55433965Sjdp    intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
55533965Sjdp    intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
55633965Sjdp					   >> SYM_BITS2_INDEX_SH_LITTLE)
55733965Sjdp			| (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
55833965Sjdp			| ((unsigned int) ext->s_bits4[0]
55933965Sjdp			   << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
56033965Sjdp  }
56133965Sjdp
56233965Sjdp#ifdef TEST
56333965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
56477298Sobrien    abort ();
56533965Sjdp#endif
56633965Sjdp}
56733965Sjdp
56833965Sjdp/* Swap out a symbol record.  */
56933965Sjdp
57033965Sjdpstatic void
57133965Sjdpecoff_swap_sym_out (abfd, intern_copy, ext_ptr)
57233965Sjdp     bfd *abfd;
57333965Sjdp     const SYMR *intern_copy;
57433965Sjdp     PTR ext_ptr;
57533965Sjdp{
57633965Sjdp  struct sym_ext *ext = (struct sym_ext *) ext_ptr;
57733965Sjdp  SYMR intern[1];
57833965Sjdp
57933965Sjdp  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
58077298Sobrien
58133965Sjdp  bfd_h_put_32 (abfd, intern->iss, (bfd_byte *)ext->s_iss);
58233965Sjdp  ecoff_put_off (abfd, intern->value, (bfd_byte *)ext->s_value);
58333965Sjdp
58477298Sobrien  /* now the fun stuff...  */
58533965Sjdp  if (bfd_header_big_endian (abfd)) {
58633965Sjdp    ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
58733965Sjdp			& SYM_BITS1_ST_BIG)
58833965Sjdp		       | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
58933965Sjdp			  & SYM_BITS1_SC_BIG));
59033965Sjdp    ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
59133965Sjdp			& SYM_BITS2_SC_BIG)
59233965Sjdp		       | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
59333965Sjdp		       | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
59433965Sjdp			  & SYM_BITS2_INDEX_BIG));
59533965Sjdp    ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
59633965Sjdp    ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
59733965Sjdp  } else {
59833965Sjdp    ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
59933965Sjdp			& SYM_BITS1_ST_LITTLE)
60033965Sjdp		       | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
60133965Sjdp			  & SYM_BITS1_SC_LITTLE));
60233965Sjdp    ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
60333965Sjdp			& SYM_BITS2_SC_LITTLE)
60433965Sjdp		       | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
60533965Sjdp		       | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
60633965Sjdp			  & SYM_BITS2_INDEX_LITTLE));
60733965Sjdp    ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
60833965Sjdp    ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
60933965Sjdp  }
61033965Sjdp
61133965Sjdp#ifdef TEST
61233965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
61377298Sobrien    abort ();
61433965Sjdp#endif
61533965Sjdp}
61633965Sjdp
61733965Sjdp/* Swap in an external symbol record.  */
61833965Sjdp
61933965Sjdpstatic void
62033965Sjdpecoff_swap_ext_in (abfd, ext_copy, intern)
62133965Sjdp     bfd *abfd;
62233965Sjdp     PTR ext_copy;
62333965Sjdp     EXTR *intern;
62433965Sjdp{
62533965Sjdp  struct ext_ext ext[1];
62633965Sjdp
62733965Sjdp  *ext = *(struct ext_ext *) ext_copy;
62877298Sobrien
62977298Sobrien  /* now the fun stuff...  */
63033965Sjdp  if (bfd_header_big_endian (abfd)) {
63133965Sjdp    intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
63233965Sjdp    intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
63333965Sjdp    intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
63433965Sjdp  } else {
63533965Sjdp    intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
63633965Sjdp    intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
63733965Sjdp    intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
63833965Sjdp  }
63933965Sjdp  intern->reserved = 0;
64033965Sjdp
64177298Sobrien#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
64233965Sjdp  intern->ifd           = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->es_ifd);
64333965Sjdp#endif
64477298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
64533965Sjdp  intern->ifd           = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->es_ifd);
64633965Sjdp#endif
64733965Sjdp
64833965Sjdp  ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
64933965Sjdp
65033965Sjdp#ifdef TEST
65133965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
65277298Sobrien    abort ();
65333965Sjdp#endif
65433965Sjdp}
65533965Sjdp
65633965Sjdp/* Swap out an external symbol record.  */
65733965Sjdp
65833965Sjdpstatic void
65933965Sjdpecoff_swap_ext_out (abfd, intern_copy, ext_ptr)
66033965Sjdp     bfd *abfd;
66133965Sjdp     const EXTR *intern_copy;
66233965Sjdp     PTR ext_ptr;
66333965Sjdp{
66433965Sjdp  struct ext_ext *ext = (struct ext_ext *) ext_ptr;
66533965Sjdp  EXTR intern[1];
66633965Sjdp
66733965Sjdp  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
66877298Sobrien
66977298Sobrien  /* now the fun stuff...  */
67033965Sjdp  if (bfd_header_big_endian (abfd)) {
67133965Sjdp    ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
67233965Sjdp			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
67333965Sjdp			| (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
67433965Sjdp    ext->es_bits2[0] = 0;
67577298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
67633965Sjdp    ext->es_bits2[1] = 0;
67733965Sjdp    ext->es_bits2[2] = 0;
67833965Sjdp#endif
67933965Sjdp  } else {
68033965Sjdp    ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
68133965Sjdp			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
68233965Sjdp			| (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
68333965Sjdp    ext->es_bits2[0] = 0;
68477298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
68533965Sjdp    ext->es_bits2[1] = 0;
68633965Sjdp    ext->es_bits2[2] = 0;
68733965Sjdp#endif
68833965Sjdp  }
68933965Sjdp
69077298Sobrien#if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
69133965Sjdp  bfd_h_put_signed_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
69233965Sjdp#endif
69377298Sobrien#if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
69433965Sjdp  bfd_h_put_signed_32 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
69533965Sjdp#endif
69633965Sjdp
69733965Sjdp  ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
69833965Sjdp
69933965Sjdp#ifdef TEST
70033965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
70177298Sobrien    abort ();
70233965Sjdp#endif
70333965Sjdp}
70433965Sjdp
70533965Sjdp/* Swap in a relative file descriptor.  */
70633965Sjdp
70733965Sjdpstatic void
70833965Sjdpecoff_swap_rfd_in (abfd, ext_ptr, intern)
70933965Sjdp     bfd *abfd;
71033965Sjdp     PTR ext_ptr;
71133965Sjdp     RFDT *intern;
71233965Sjdp{
71333965Sjdp  struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
71433965Sjdp
71533965Sjdp  *intern = bfd_h_get_32 (abfd, (bfd_byte *)ext->rfd);
71633965Sjdp
71733965Sjdp#ifdef TEST
71833965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
71977298Sobrien    abort ();
72033965Sjdp#endif
72133965Sjdp}
72233965Sjdp
72333965Sjdp/* Swap out a relative file descriptor.  */
72433965Sjdp
72533965Sjdpstatic void
72633965Sjdpecoff_swap_rfd_out (abfd, intern, ext_ptr)
72733965Sjdp     bfd *abfd;
72833965Sjdp     const RFDT *intern;
72933965Sjdp     PTR ext_ptr;
73033965Sjdp{
73133965Sjdp  struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
73233965Sjdp
73333965Sjdp  bfd_h_put_32 (abfd, *intern, (bfd_byte *)ext->rfd);
73433965Sjdp
73533965Sjdp#ifdef TEST
73633965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
73777298Sobrien    abort ();
73833965Sjdp#endif
73933965Sjdp}
74033965Sjdp
74133965Sjdp/* Swap in an optimization symbol.  */
74233965Sjdp
74333965Sjdpstatic void
74433965Sjdpecoff_swap_opt_in (abfd, ext_copy, intern)
74533965Sjdp     bfd *abfd;
74633965Sjdp     PTR ext_copy;
74733965Sjdp     OPTR *intern;
74833965Sjdp{
74933965Sjdp  struct opt_ext ext[1];
75033965Sjdp
75133965Sjdp  *ext = *(struct opt_ext *) ext_copy;
75233965Sjdp
75333965Sjdp  if (bfd_header_big_endian (abfd))
75433965Sjdp    {
75533965Sjdp      intern->ot = ext->o_bits1[0];
75633965Sjdp      intern->value = (((unsigned int) ext->o_bits2[0]
75733965Sjdp			<< OPT_BITS2_VALUE_SH_LEFT_BIG)
75833965Sjdp		       | ((unsigned int) ext->o_bits3[0]
75933965Sjdp			  << OPT_BITS2_VALUE_SH_LEFT_BIG)
76033965Sjdp		       | ((unsigned int) ext->o_bits4[0]
76133965Sjdp			  << OPT_BITS2_VALUE_SH_LEFT_BIG));
76233965Sjdp    }
76333965Sjdp  else
76433965Sjdp    {
76533965Sjdp      intern->ot = ext->o_bits1[0];
76633965Sjdp      intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
76733965Sjdp		       | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
76833965Sjdp		       | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
76933965Sjdp    }
77033965Sjdp
77133965Sjdp  _bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
77233965Sjdp			   &ext->o_rndx, &intern->rndx);
77333965Sjdp
77433965Sjdp  intern->offset = bfd_h_get_32 (abfd, (bfd_byte *) ext->o_offset);
77533965Sjdp
77633965Sjdp#ifdef TEST
77733965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
77877298Sobrien    abort ();
77933965Sjdp#endif
78033965Sjdp}
78133965Sjdp
78233965Sjdp/* Swap out an optimization symbol.  */
78333965Sjdp
78433965Sjdpstatic void
78533965Sjdpecoff_swap_opt_out (abfd, intern_copy, ext_ptr)
78633965Sjdp     bfd *abfd;
78733965Sjdp     const OPTR *intern_copy;
78833965Sjdp     PTR ext_ptr;
78933965Sjdp{
79033965Sjdp  struct opt_ext *ext = (struct opt_ext *) ext_ptr;
79133965Sjdp  OPTR intern[1];
79233965Sjdp
79333965Sjdp  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
79433965Sjdp
79533965Sjdp  if (bfd_header_big_endian (abfd))
79633965Sjdp    {
79733965Sjdp      ext->o_bits1[0] = intern->ot;
79833965Sjdp      ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
79933965Sjdp      ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
80033965Sjdp      ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
80133965Sjdp    }
80233965Sjdp  else
80333965Sjdp    {
80433965Sjdp      ext->o_bits1[0] = intern->ot;
80533965Sjdp      ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
80633965Sjdp      ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
80733965Sjdp      ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
80833965Sjdp    }
80933965Sjdp
81033965Sjdp  _bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
81133965Sjdp			    &intern->rndx, &ext->o_rndx);
81233965Sjdp
81333965Sjdp  bfd_h_put_32 (abfd, intern->value, (bfd_byte *) ext->o_offset);
81433965Sjdp
81533965Sjdp#ifdef TEST
81633965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
81777298Sobrien    abort ();
81833965Sjdp#endif
81933965Sjdp}
82033965Sjdp
82133965Sjdp/* Swap in a dense number.  */
82233965Sjdp
82333965Sjdpstatic void
82433965Sjdpecoff_swap_dnr_in (abfd, ext_copy, intern)
82533965Sjdp     bfd *abfd;
82633965Sjdp     PTR ext_copy;
82733965Sjdp     DNR *intern;
82833965Sjdp{
82933965Sjdp  struct dnr_ext ext[1];
83033965Sjdp
83133965Sjdp  *ext = *(struct dnr_ext *) ext_copy;
83233965Sjdp
83333965Sjdp  intern->rfd = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_rfd);
83433965Sjdp  intern->index = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_index);
83533965Sjdp
83633965Sjdp#ifdef TEST
83733965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
83877298Sobrien    abort ();
83933965Sjdp#endif
84033965Sjdp}
84133965Sjdp
84233965Sjdp/* Swap out a dense number.  */
84333965Sjdp
84433965Sjdpstatic void
84533965Sjdpecoff_swap_dnr_out (abfd, intern_copy, ext_ptr)
84633965Sjdp     bfd *abfd;
84733965Sjdp     const DNR *intern_copy;
84833965Sjdp     PTR ext_ptr;
84933965Sjdp{
85033965Sjdp  struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
85133965Sjdp  DNR intern[1];
85233965Sjdp
85333965Sjdp  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
85433965Sjdp
85533965Sjdp  bfd_h_put_32 (abfd, intern->rfd, (bfd_byte *) ext->d_rfd);
85633965Sjdp  bfd_h_put_32 (abfd, intern->index, (bfd_byte *) ext->d_index);
85733965Sjdp
85833965Sjdp#ifdef TEST
85933965Sjdp  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
86077298Sobrien    abort ();
86133965Sjdp#endif
86233965Sjdp}
863