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