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