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