ecoffswap.h revision 33965
1/* Generic ECOFF swapping routines, for BFD.
2   Copyright 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
3   Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21/* NOTE: This is a header file, but it contains executable routines.
22   This is done this way because these routines are substantially
23   similar, but are not identical, for all ECOFF targets.
24
25   These are routines to swap the ECOFF symbolic information in and
26   out.  The routines are defined statically.  You can set breakpoints
27   on them in gdb by naming the including source file; e.g.,
28   'coff-mips.c':ecoff_swap_hdr_in.
29
30   Before including this header file, one of ECOFF_32 or ECOFF_64 must
31   be defined.  These are checked when swapping information that
32   depends upon the target size.  This code works for 32 bit and 64
33   bit ECOFF, but may need to be generalized in the future.
34
35   Some header file which defines the external forms of these
36   structures must also be included before including this header file.
37   Currently this is either coff/mips.h or coff/alpha.h.
38
39   If the symbol TEST is defined when this file is compiled, a
40   comparison is made to ensure that, in fact, the output is
41   bit-for-bit the same as the input.  Of course, this symbol should
42   only be defined when deliberately testing the code on a machine
43   with the proper byte sex and such.  */
44
45#ifdef ECOFF_32
46#define ecoff_get_off bfd_h_get_32
47#define ecoff_put_off bfd_h_put_32
48#endif
49#ifdef ECOFF_64
50#define ecoff_get_off bfd_h_get_64
51#define ecoff_put_off bfd_h_put_64
52#endif
53
54/* ECOFF auxiliary information swapping routines.  These are the same
55   for all ECOFF targets, so they are defined in ecofflink.c.  */
56
57extern void _bfd_ecoff_swap_tir_in
58  PARAMS ((int, const struct tir_ext *, TIR *));
59extern void _bfd_ecoff_swap_tir_out
60  PARAMS ((int, const TIR *, struct tir_ext *));
61extern void _bfd_ecoff_swap_rndx_in
62  PARAMS ((int, const struct rndx_ext *, RNDXR *));
63extern void _bfd_ecoff_swap_rndx_out
64  PARAMS ((int, const RNDXR *, struct rndx_ext *));
65
66/* Prototypes for functions defined in this file.  */
67
68static void ecoff_swap_hdr_in PARAMS ((bfd *, PTR, HDRR *));
69static void ecoff_swap_hdr_out PARAMS ((bfd *, const HDRR *, PTR));
70static void ecoff_swap_fdr_in PARAMS ((bfd *, PTR, FDR *));
71static void ecoff_swap_fdr_out PARAMS ((bfd *, const FDR *, PTR));
72static void ecoff_swap_pdr_in PARAMS ((bfd *, PTR, PDR *));
73static void ecoff_swap_pdr_out PARAMS ((bfd *, const PDR *, PTR));
74static void ecoff_swap_sym_in PARAMS ((bfd *, PTR, SYMR *));
75static void ecoff_swap_sym_out PARAMS ((bfd *, const SYMR *, PTR));
76static void ecoff_swap_ext_in PARAMS ((bfd *, PTR, EXTR *));
77static void ecoff_swap_ext_out PARAMS ((bfd *, const EXTR *, PTR));
78static void ecoff_swap_rfd_in PARAMS ((bfd *, PTR, RFDT *));
79static void ecoff_swap_rfd_out PARAMS ((bfd *, const RFDT *, PTR));
80static void ecoff_swap_opt_in PARAMS ((bfd *, PTR, OPTR *));
81static void ecoff_swap_opt_out PARAMS ((bfd *, const OPTR *, PTR));
82static void ecoff_swap_dnr_in PARAMS ((bfd *, PTR, DNR *));
83static void ecoff_swap_dnr_out PARAMS ((bfd *, const DNR *, PTR));
84
85/* Swap in the symbolic header.  */
86
87static void
88ecoff_swap_hdr_in (abfd, ext_copy, intern)
89     bfd *abfd;
90     PTR ext_copy;
91     HDRR *intern;
92{
93  struct hdr_ext ext[1];
94
95  *ext = *(struct hdr_ext *) ext_copy;
96
97  intern->magic         = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_magic);
98  intern->vstamp        = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_vstamp);
99  intern->ilineMax      = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax);
100  intern->cbLine        = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLine);
101  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLineOffset);
102  intern->idnMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax);
103  intern->cbDnOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbDnOffset);
104  intern->ipdMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax);
105  intern->cbPdOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbPdOffset);
106  intern->isymMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax);
107  intern->cbSymOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSymOffset);
108  intern->ioptMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax);
109  intern->cbOptOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbOptOffset);
110  intern->iauxMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax);
111  intern->cbAuxOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbAuxOffset);
112  intern->issMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax);
113  intern->cbSsOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsOffset);
114  intern->issExtMax     = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax);
115  intern->cbSsExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsExtOffset);
116  intern->ifdMax        = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax);
117  intern->cbFdOffset    = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbFdOffset);
118  intern->crfd          = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd);
119  intern->cbRfdOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbRfdOffset);
120  intern->iextMax       = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax);
121  intern->cbExtOffset   = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbExtOffset);
122
123#ifdef TEST
124  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
125    abort();
126#endif
127}
128
129/* Swap out the symbolic header.  */
130
131static void
132ecoff_swap_hdr_out (abfd, intern_copy, ext_ptr)
133     bfd *abfd;
134     const HDRR *intern_copy;
135     PTR ext_ptr;
136{
137  struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
138  HDRR intern[1];
139
140  *intern = *intern_copy;
141
142  bfd_h_put_signed_16 (abfd, intern->magic, (bfd_byte *)ext->h_magic);
143  bfd_h_put_signed_16 (abfd, intern->vstamp, (bfd_byte *)ext->h_vstamp);
144  bfd_h_put_32 (abfd, intern->ilineMax, (bfd_byte *)ext->h_ilineMax);
145  ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->h_cbLine);
146  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->h_cbLineOffset);
147  bfd_h_put_32 (abfd, intern->idnMax, (bfd_byte *)ext->h_idnMax);
148  ecoff_put_off (abfd, intern->cbDnOffset, (bfd_byte *)ext->h_cbDnOffset);
149  bfd_h_put_32 (abfd, intern->ipdMax, (bfd_byte *)ext->h_ipdMax);
150  ecoff_put_off (abfd, intern->cbPdOffset, (bfd_byte *)ext->h_cbPdOffset);
151  bfd_h_put_32 (abfd, intern->isymMax, (bfd_byte *)ext->h_isymMax);
152  ecoff_put_off (abfd, intern->cbSymOffset, (bfd_byte *)ext->h_cbSymOffset);
153  bfd_h_put_32 (abfd, intern->ioptMax, (bfd_byte *)ext->h_ioptMax);
154  ecoff_put_off (abfd, intern->cbOptOffset, (bfd_byte *)ext->h_cbOptOffset);
155  bfd_h_put_32 (abfd, intern->iauxMax, (bfd_byte *)ext->h_iauxMax);
156  ecoff_put_off (abfd, intern->cbAuxOffset, (bfd_byte *)ext->h_cbAuxOffset);
157  bfd_h_put_32 (abfd, intern->issMax, (bfd_byte *)ext->h_issMax);
158  ecoff_put_off (abfd, intern->cbSsOffset, (bfd_byte *)ext->h_cbSsOffset);
159  bfd_h_put_32 (abfd, intern->issExtMax, (bfd_byte *)ext->h_issExtMax);
160  ecoff_put_off (abfd, intern->cbSsExtOffset, (bfd_byte *)ext->h_cbSsExtOffset);
161  bfd_h_put_32 (abfd, intern->ifdMax, (bfd_byte *)ext->h_ifdMax);
162  ecoff_put_off (abfd, intern->cbFdOffset, (bfd_byte *)ext->h_cbFdOffset);
163  bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->h_crfd);
164  ecoff_put_off (abfd, intern->cbRfdOffset, (bfd_byte *)ext->h_cbRfdOffset);
165  bfd_h_put_32 (abfd, intern->iextMax, (bfd_byte *)ext->h_iextMax);
166  ecoff_put_off (abfd, intern->cbExtOffset, (bfd_byte *)ext->h_cbExtOffset);
167
168#ifdef TEST
169  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
170    abort();
171#endif
172}
173
174/* Swap in the file descriptor record.  */
175
176static void
177ecoff_swap_fdr_in (abfd, ext_copy, intern)
178     bfd *abfd;
179     PTR ext_copy;
180     FDR *intern;
181{
182  struct fdr_ext ext[1];
183
184  *ext = *(struct fdr_ext *) ext_copy;
185
186  intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->f_adr);
187  intern->rss           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
188#ifdef ECOFF_64
189  if (intern->rss == 0xffffffff)
190    intern->rss = -1;
191#endif
192  intern->issBase       = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase);
193  intern->cbSs          = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbSs);
194  intern->isymBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase);
195  intern->csym          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym);
196  intern->ilineBase     = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase);
197  intern->cline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
198  intern->ioptBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
199  intern->copt          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
200#ifdef ECOFF_32
201  intern->ipdFirst      = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
202  intern->cpd           = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
203#endif
204#ifdef ECOFF_64
205  intern->ipdFirst      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ipdFirst);
206  intern->cpd           = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cpd);
207#endif
208  intern->iauxBase      = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase);
209  intern->caux          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux);
210  intern->rfdBase       = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase);
211  intern->crfd          = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd);
212
213  /* now the fun stuff... */
214  if (bfd_header_big_endian (abfd)) {
215    intern->lang        = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
216					>> FDR_BITS1_LANG_SH_BIG;
217    intern->fMerge      = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
218    intern->fReadin     = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
219    intern->fBigendian  = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
220    intern->glevel      = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
221					>> FDR_BITS2_GLEVEL_SH_BIG;
222  } else {
223    intern->lang        = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
224					>> FDR_BITS1_LANG_SH_LITTLE;
225    intern->fMerge      = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
226    intern->fReadin     = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
227    intern->fBigendian  = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
228    intern->glevel      = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
229					>> FDR_BITS2_GLEVEL_SH_LITTLE;
230  }
231  intern->reserved = 0;
232
233  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLineOffset);
234  intern->cbLine        = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLine);
235
236#ifdef TEST
237  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
238    abort();
239#endif
240}
241
242/* Swap out the file descriptor record.  */
243
244static void
245ecoff_swap_fdr_out (abfd, intern_copy, ext_ptr)
246     bfd *abfd;
247     const FDR *intern_copy;
248     PTR ext_ptr;
249{
250  struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
251  FDR intern[1];
252
253  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
254
255  ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->f_adr);
256  bfd_h_put_32 (abfd, intern->rss, (bfd_byte *)ext->f_rss);
257  bfd_h_put_32 (abfd, intern->issBase, (bfd_byte *)ext->f_issBase);
258  ecoff_put_off (abfd, intern->cbSs, (bfd_byte *)ext->f_cbSs);
259  bfd_h_put_32 (abfd, intern->isymBase, (bfd_byte *)ext->f_isymBase);
260  bfd_h_put_32 (abfd, intern->csym, (bfd_byte *)ext->f_csym);
261  bfd_h_put_32 (abfd, intern->ilineBase, (bfd_byte *)ext->f_ilineBase);
262  bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline);
263  bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase);
264  bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt);
265#ifdef ECOFF_32
266  bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
267  bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
268#endif
269#ifdef ECOFF_64
270  bfd_h_put_32 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
271  bfd_h_put_32 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
272#endif
273  bfd_h_put_32 (abfd, intern->iauxBase, (bfd_byte *)ext->f_iauxBase);
274  bfd_h_put_32 (abfd, intern->caux, (bfd_byte *)ext->f_caux);
275  bfd_h_put_32 (abfd, intern->rfdBase, (bfd_byte *)ext->f_rfdBase);
276  bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->f_crfd);
277
278  /* now the fun stuff... */
279  if (bfd_header_big_endian (abfd)) {
280    ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
281			& FDR_BITS1_LANG_BIG)
282		       | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
283		       | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
284		       | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
285    ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
286		       & FDR_BITS2_GLEVEL_BIG);
287    ext->f_bits2[1] = 0;
288    ext->f_bits2[2] = 0;
289  } else {
290    ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
291			& FDR_BITS1_LANG_LITTLE)
292		       | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
293		       | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
294		       | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
295    ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
296		       & FDR_BITS2_GLEVEL_LITTLE);
297    ext->f_bits2[1] = 0;
298    ext->f_bits2[2] = 0;
299  }
300
301  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->f_cbLineOffset);
302  ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->f_cbLine);
303
304#ifdef TEST
305  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
306    abort();
307#endif
308}
309
310#ifndef MPW_C
311
312/* Swap in the procedure descriptor record.  */
313
314static void
315ecoff_swap_pdr_in (abfd, ext_copy, intern)
316     bfd *abfd;
317     PTR ext_copy;
318     PDR *intern;
319{
320  struct pdr_ext ext[1];
321
322  *ext = *(struct pdr_ext *) ext_copy;
323
324  memset ((PTR) intern, 0, sizeof (*intern));
325
326  intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr);
327  intern->isym          = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
328  intern->iline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
329  intern->regmask       = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
330  intern->regoffset     = bfd_h_get_signed_32 (abfd,
331					       (bfd_byte *)ext->p_regoffset);
332  intern->iopt          = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->p_iopt);
333  intern->fregmask      = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
334  intern->fregoffset    = bfd_h_get_signed_32 (abfd,
335					       (bfd_byte *)ext->p_fregoffset);
336  intern->frameoffset   = bfd_h_get_signed_32 (abfd,
337					       (bfd_byte *)ext->p_frameoffset);
338  intern->framereg      = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
339  intern->pcreg         = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
340  intern->lnLow         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
341  intern->lnHigh        = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
342  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
343
344#ifdef ECOFF_64
345  intern->gp_prologue = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_gp_prologue);
346  if (bfd_header_big_endian (abfd))
347    {
348      intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
349      intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
350      intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
351      intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
352			   << PDR_BITS1_RESERVED_SH_LEFT_BIG)
353			  | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
354			     >> PDR_BITS2_RESERVED_SH_BIG));
355    }
356  else
357    {
358      intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
359      intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
360      intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
361      intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
362			   >> PDR_BITS1_RESERVED_SH_LITTLE)
363			  | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
364			     << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
365    }
366  intern->localoff = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_localoff);
367#endif
368
369#ifdef TEST
370  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
371    abort();
372#endif
373}
374
375/* Swap out the procedure descriptor record.  */
376
377static void
378ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
379     bfd *abfd;
380     const PDR *intern_copy;
381     PTR ext_ptr;
382{
383  struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
384  PDR intern[1];
385
386  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
387
388  ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr);
389  bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
390  bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
391  bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
392  bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
393  bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
394  bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
395  bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
396  bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
397  bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
398  bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
399  bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
400  bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
401  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
402
403#ifdef ECOFF_64
404  bfd_h_put_8 (abfd, intern->gp_prologue, (bfd_byte *) ext->p_gp_prologue);
405  if (bfd_header_big_endian (abfd))
406    {
407      ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
408			 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
409			 | (intern->prof ? PDR_BITS1_PROF_BIG : 0)
410			 | ((intern->reserved
411			     >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
412			    & PDR_BITS1_RESERVED_BIG));
413      ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
414			 & PDR_BITS2_RESERVED_BIG);
415    }
416  else
417    {
418      ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
419			 | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
420			 | (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
421			 | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
422			    & PDR_BITS1_RESERVED_LITTLE));
423      ext->p_bits2[0] = ((intern->reserved >>
424			  PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
425			 & PDR_BITS2_RESERVED_LITTLE);
426    }
427  bfd_h_put_8 (abfd, intern->localoff, (bfd_byte *) ext->p_localoff);
428#endif
429
430#ifdef TEST
431  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
432    abort();
433#endif
434}
435
436#else /* MPW_C */
437/* Same routines, but with ECOFF_64 code removed, so ^&%$#&! MPW C doesn't
438   corrupt itself and then freak out. */
439/* Swap in the procedure descriptor record.  */
440
441static void
442ecoff_swap_pdr_in (abfd, ext_copy, intern)
443     bfd *abfd;
444     PTR ext_copy;
445     PDR *intern;
446{
447  struct pdr_ext ext[1];
448
449  *ext = *(struct pdr_ext *) ext_copy;
450
451  intern->adr           = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr);
452  intern->isym          = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
453  intern->iline         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
454  intern->regmask       = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
455  intern->regoffset     = bfd_h_get_signed_32 (abfd,
456					       (bfd_byte *)ext->p_regoffset);
457  intern->iopt          = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->p_iopt);
458  intern->fregmask      = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
459  intern->fregoffset    = bfd_h_get_signed_32 (abfd,
460					       (bfd_byte *)ext->p_fregoffset);
461  intern->frameoffset   = bfd_h_get_signed_32 (abfd,
462					       (bfd_byte *)ext->p_frameoffset);
463  intern->framereg      = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
464  intern->pcreg         = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
465  intern->lnLow         = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
466  intern->lnHigh        = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
467  intern->cbLineOffset  = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
468
469#ifdef TEST
470  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
471    abort();
472#endif
473}
474
475/* Swap out the procedure descriptor record.  */
476
477static void
478ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
479     bfd *abfd;
480     const PDR *intern_copy;
481     PTR ext_ptr;
482{
483  struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
484  PDR intern[1];
485
486  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
487
488  ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr);
489  bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
490  bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
491  bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
492  bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
493  bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
494  bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
495  bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
496  bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
497  bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
498  bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
499  bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
500  bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
501  ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
502
503#ifdef TEST
504  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
505    abort();
506#endif
507}
508#endif /* MPW_C */
509
510/* Swap in a symbol record.  */
511
512static void
513ecoff_swap_sym_in (abfd, ext_copy, intern)
514     bfd *abfd;
515     PTR ext_copy;
516     SYMR *intern;
517{
518  struct sym_ext ext[1];
519
520  *ext = *(struct sym_ext *) ext_copy;
521
522  intern->iss           = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss);
523  intern->value         = ecoff_get_off (abfd, (bfd_byte *)ext->s_value);
524
525  /* now the fun stuff... */
526  if (bfd_header_big_endian (abfd)) {
527    intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
528					   >> SYM_BITS1_ST_SH_BIG;
529    intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
530					   << SYM_BITS1_SC_SH_LEFT_BIG)
531			| ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
532					   >> SYM_BITS2_SC_SH_BIG);
533    intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
534    intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
535					   << SYM_BITS2_INDEX_SH_LEFT_BIG)
536			| (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
537			| (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
538  } else {
539    intern->st          =  (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
540					   >> SYM_BITS1_ST_SH_LITTLE;
541    intern->sc          = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
542					   >> SYM_BITS1_SC_SH_LITTLE)
543			| ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
544					   << SYM_BITS2_SC_SH_LEFT_LITTLE);
545    intern->reserved    = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
546    intern->index       = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
547					   >> SYM_BITS2_INDEX_SH_LITTLE)
548			| (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
549			| ((unsigned int) ext->s_bits4[0]
550			   << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
551  }
552
553#ifdef TEST
554  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
555    abort();
556#endif
557}
558
559/* Swap out a symbol record.  */
560
561static void
562ecoff_swap_sym_out (abfd, intern_copy, ext_ptr)
563     bfd *abfd;
564     const SYMR *intern_copy;
565     PTR ext_ptr;
566{
567  struct sym_ext *ext = (struct sym_ext *) ext_ptr;
568  SYMR intern[1];
569
570  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
571
572  bfd_h_put_32 (abfd, intern->iss, (bfd_byte *)ext->s_iss);
573  ecoff_put_off (abfd, intern->value, (bfd_byte *)ext->s_value);
574
575  /* now the fun stuff... */
576  if (bfd_header_big_endian (abfd)) {
577    ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
578			& SYM_BITS1_ST_BIG)
579		       | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
580			  & SYM_BITS1_SC_BIG));
581    ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
582			& SYM_BITS2_SC_BIG)
583		       | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
584		       | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
585			  & SYM_BITS2_INDEX_BIG));
586    ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
587    ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
588  } else {
589    ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
590			& SYM_BITS1_ST_LITTLE)
591		       | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
592			  & SYM_BITS1_SC_LITTLE));
593    ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
594			& SYM_BITS2_SC_LITTLE)
595		       | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
596		       | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
597			  & SYM_BITS2_INDEX_LITTLE));
598    ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
599    ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
600  }
601
602#ifdef TEST
603  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
604    abort();
605#endif
606}
607
608/* Swap in an external symbol record.  */
609
610static void
611ecoff_swap_ext_in (abfd, ext_copy, intern)
612     bfd *abfd;
613     PTR ext_copy;
614     EXTR *intern;
615{
616  struct ext_ext ext[1];
617
618  *ext = *(struct ext_ext *) ext_copy;
619
620  /* now the fun stuff... */
621  if (bfd_header_big_endian (abfd)) {
622    intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
623    intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
624    intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
625  } else {
626    intern->jmptbl      = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
627    intern->cobol_main  = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
628    intern->weakext     = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
629  }
630  intern->reserved = 0;
631
632#ifdef ECOFF_32
633  intern->ifd           = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->es_ifd);
634#endif
635#ifdef ECOFF_64
636  intern->ifd           = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->es_ifd);
637#endif
638
639  ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
640
641#ifdef TEST
642  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
643    abort();
644#endif
645}
646
647/* Swap out an external symbol record.  */
648
649static void
650ecoff_swap_ext_out (abfd, intern_copy, ext_ptr)
651     bfd *abfd;
652     const EXTR *intern_copy;
653     PTR ext_ptr;
654{
655  struct ext_ext *ext = (struct ext_ext *) ext_ptr;
656  EXTR intern[1];
657
658  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
659
660  /* now the fun stuff... */
661  if (bfd_header_big_endian (abfd)) {
662    ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
663			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
664			| (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
665    ext->es_bits2[0] = 0;
666#ifdef ECOFF_64
667    ext->es_bits2[1] = 0;
668    ext->es_bits2[2] = 0;
669#endif
670  } else {
671    ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
672			| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
673			| (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
674    ext->es_bits2[0] = 0;
675#ifdef ECOFF_64
676    ext->es_bits2[1] = 0;
677    ext->es_bits2[2] = 0;
678#endif
679  }
680
681#ifdef ECOFF_32
682  bfd_h_put_signed_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
683#endif
684#ifdef ECOFF_64
685  bfd_h_put_signed_32 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
686#endif
687
688  ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
689
690#ifdef TEST
691  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
692    abort();
693#endif
694}
695
696/* Swap in a relative file descriptor.  */
697
698static void
699ecoff_swap_rfd_in (abfd, ext_ptr, intern)
700     bfd *abfd;
701     PTR ext_ptr;
702     RFDT *intern;
703{
704  struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
705
706  *intern = bfd_h_get_32 (abfd, (bfd_byte *)ext->rfd);
707
708#ifdef TEST
709  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
710    abort();
711#endif
712}
713
714/* Swap out a relative file descriptor.  */
715
716static void
717ecoff_swap_rfd_out (abfd, intern, ext_ptr)
718     bfd *abfd;
719     const RFDT *intern;
720     PTR ext_ptr;
721{
722  struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
723
724  bfd_h_put_32 (abfd, *intern, (bfd_byte *)ext->rfd);
725
726#ifdef TEST
727  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
728    abort();
729#endif
730}
731
732/* Swap in an optimization symbol.  */
733
734static void
735ecoff_swap_opt_in (abfd, ext_copy, intern)
736     bfd *abfd;
737     PTR ext_copy;
738     OPTR *intern;
739{
740  struct opt_ext ext[1];
741
742  *ext = *(struct opt_ext *) ext_copy;
743
744  if (bfd_header_big_endian (abfd))
745    {
746      intern->ot = ext->o_bits1[0];
747      intern->value = (((unsigned int) ext->o_bits2[0]
748			<< OPT_BITS2_VALUE_SH_LEFT_BIG)
749		       | ((unsigned int) ext->o_bits3[0]
750			  << OPT_BITS2_VALUE_SH_LEFT_BIG)
751		       | ((unsigned int) ext->o_bits4[0]
752			  << OPT_BITS2_VALUE_SH_LEFT_BIG));
753    }
754  else
755    {
756      intern->ot = ext->o_bits1[0];
757      intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
758		       | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
759		       | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
760    }
761
762  _bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
763			   &ext->o_rndx, &intern->rndx);
764
765  intern->offset = bfd_h_get_32 (abfd, (bfd_byte *) ext->o_offset);
766
767#ifdef TEST
768  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
769    abort();
770#endif
771}
772
773/* Swap out an optimization symbol.  */
774
775static void
776ecoff_swap_opt_out (abfd, intern_copy, ext_ptr)
777     bfd *abfd;
778     const OPTR *intern_copy;
779     PTR ext_ptr;
780{
781  struct opt_ext *ext = (struct opt_ext *) ext_ptr;
782  OPTR intern[1];
783
784  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
785
786  if (bfd_header_big_endian (abfd))
787    {
788      ext->o_bits1[0] = intern->ot;
789      ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
790      ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
791      ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
792    }
793  else
794    {
795      ext->o_bits1[0] = intern->ot;
796      ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
797      ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
798      ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
799    }
800
801  _bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
802			    &intern->rndx, &ext->o_rndx);
803
804  bfd_h_put_32 (abfd, intern->value, (bfd_byte *) ext->o_offset);
805
806#ifdef TEST
807  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
808    abort();
809#endif
810}
811
812/* Swap in a dense number.  */
813
814static void
815ecoff_swap_dnr_in (abfd, ext_copy, intern)
816     bfd *abfd;
817     PTR ext_copy;
818     DNR *intern;
819{
820  struct dnr_ext ext[1];
821
822  *ext = *(struct dnr_ext *) ext_copy;
823
824  intern->rfd = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_rfd);
825  intern->index = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_index);
826
827#ifdef TEST
828  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
829    abort();
830#endif
831}
832
833/* Swap out a dense number.  */
834
835static void
836ecoff_swap_dnr_out (abfd, intern_copy, ext_ptr)
837     bfd *abfd;
838     const DNR *intern_copy;
839     PTR ext_ptr;
840{
841  struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
842  DNR intern[1];
843
844  *intern = *intern_copy;	/* Make it reasonable to do in-place.  */
845
846  bfd_h_put_32 (abfd, intern->rfd, (bfd_byte *) ext->d_rfd);
847  bfd_h_put_32 (abfd, intern->index, (bfd_byte *) ext->d_index);
848
849#ifdef TEST
850  if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
851    abort();
852#endif
853}
854