Revisions from Jeff Law to HPPA-directives section.
[deliverable/binutils-gdb.git] / bfd / coffswap.h
CommitLineData
075caafd 1/* Generic COFF swapping routines, for BFD.
fbb61b50 2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
075caafd
ILT
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21/* This file contains routines used to swap COFF data. It is a header
22 file because the details of swapping depend on the details of the
23 structures used by each COFF implementation. This is included by
24 coffcode.h, as well as by the ECOFF backend.
25
26 Any file which uses this must first include "coff/internal.h" and
27 "coff/CPU.h". The functions will then be correct for that CPU. */
28
29#define PUTWORD bfd_h_put_32
30#define PUTHALF bfd_h_put_16
31#define PUTBYTE bfd_h_put_8
32
33#ifndef GET_FCN_LNNOPTR
34#define GET_FCN_LNNOPTR(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
35#endif
36
37#ifndef GET_FCN_ENDNDX
38#define GET_FCN_ENDNDX(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
39#endif
40
41#ifndef PUT_FCN_LNNOPTR
42#define PUT_FCN_LNNOPTR(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
43#endif
44#ifndef PUT_FCN_ENDNDX
45#define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
46#endif
47#ifndef GET_LNSZ_LNNO
48#define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
49#endif
50#ifndef GET_LNSZ_SIZE
51#define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
52#endif
53#ifndef PUT_LNSZ_LNNO
54#define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
55#endif
56#ifndef PUT_LNSZ_SIZE
57#define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
58#endif
59#ifndef GET_SCN_SCNLEN
60#define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
61#endif
62#ifndef GET_SCN_NRELOC
63#define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
64#endif
65#ifndef GET_SCN_NLINNO
66#define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
67#endif
68#ifndef PUT_SCN_SCNLEN
69#define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
70#endif
71#ifndef PUT_SCN_NRELOC
72#define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
73#endif
74#ifndef PUT_SCN_NLINNO
75#define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
76#endif
77#ifndef GET_LINENO_LNNO
78#define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
79#endif
80#ifndef PUT_LINENO_LNNO
81#define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
82#endif
83
fbb61b50
SC
84/* The f_symptr field in the filehdr is sometimes 64 bits. */
85#ifndef GET_FILEHDR_SYMPTR
86#define GET_FILEHDR_SYMPTR bfd_h_get_32
87#endif
88#ifndef PUT_FILEHDR_SYMPTR
89#define PUT_FILEHDR_SYMPTR bfd_h_put_32
90#endif
91
92/* Some fields in the aouthdr are sometimes 64 bits. */
93#ifndef GET_AOUTHDR_TSIZE
94#define GET_AOUTHDR_TSIZE bfd_h_get_32
95#endif
96#ifndef PUT_AOUTHDR_TSIZE
97#define PUT_AOUTHDR_TSIZE bfd_h_put_32
98#endif
99#ifndef GET_AOUTHDR_DSIZE
100#define GET_AOUTHDR_DSIZE bfd_h_get_32
101#endif
102#ifndef PUT_AOUTHDR_DSIZE
103#define PUT_AOUTHDR_DSIZE bfd_h_put_32
104#endif
105#ifndef GET_AOUTHDR_BSIZE
106#define GET_AOUTHDR_BSIZE bfd_h_get_32
107#endif
108#ifndef PUT_AOUTHDR_BSIZE
109#define PUT_AOUTHDR_BSIZE bfd_h_put_32
110#endif
111#ifndef GET_AOUTHDR_ENTRY
112#define GET_AOUTHDR_ENTRY bfd_h_get_32
113#endif
114#ifndef PUT_AOUTHDR_ENTRY
115#define PUT_AOUTHDR_ENTRY bfd_h_put_32
116#endif
117#ifndef GET_AOUTHDR_TEXT_START
118#define GET_AOUTHDR_TEXT_START bfd_h_get_32
119#endif
120#ifndef PUT_AOUTHDR_TEXT_START
121#define PUT_AOUTHDR_TEXT_START bfd_h_put_32
122#endif
123#ifndef GET_AOUTHDR_DATA_START
124#define GET_AOUTHDR_DATA_START bfd_h_get_32
125#endif
126#ifndef PUT_AOUTHDR_DATA_START
127#define PUT_AOUTHDR_DATA_START bfd_h_put_32
128#endif
129
130/* Some fields in the scnhdr are sometimes 64 bits. */
131#ifndef GET_SCNHDR_PADDR
132#define GET_SCNHDR_PADDR bfd_h_get_32
133#endif
134#ifndef PUT_SCNHDR_PADDR
135#define PUT_SCNHDR_PADDR bfd_h_put_32
136#endif
137#ifndef GET_SCNHDR_VADDR
138#define GET_SCNHDR_VADDR bfd_h_get_32
139#endif
140#ifndef PUT_SCNHDR_VADDR
141#define PUT_SCNHDR_VADDR bfd_h_put_32
142#endif
143#ifndef GET_SCNHDR_SIZE
144#define GET_SCNHDR_SIZE bfd_h_get_32
145#endif
146#ifndef PUT_SCNHDR_SIZE
147#define PUT_SCNHDR_SIZE bfd_h_put_32
148#endif
149#ifndef GET_SCNHDR_SCNPTR
150#define GET_SCNHDR_SCNPTR bfd_h_get_32
151#endif
152#ifndef PUT_SCNHDR_SCNPTR
153#define PUT_SCNHDR_SCNPTR bfd_h_put_32
154#endif
155#ifndef GET_SCNHDR_RELPTR
156#define GET_SCNHDR_RELPTR bfd_h_get_32
157#endif
158#ifndef PUT_SCNHDR_RELPTR
159#define PUT_SCNHDR_RELPTR bfd_h_put_32
160#endif
161#ifndef GET_SCNHDR_LNNOPTR
162#define GET_SCNHDR_LNNOPTR bfd_h_get_32
163#endif
164#ifndef PUT_SCNHDR_LNNOPTR
165#define PUT_SCNHDR_LNNOPTR bfd_h_put_32
166#endif
167
168#ifndef NO_COFF_RELOCS
169
075caafd
ILT
170static void
171DEFUN(bfd_swap_reloc_in,(abfd, reloc_src, reloc_dst),
172 bfd *abfd AND
173 RELOC *reloc_src AND
174 struct internal_reloc *reloc_dst)
175{
176 reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
fbb61b50 177 reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
075caafd
ILT
178
179#ifdef RS6000COFF_C
180 reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
181 reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
182#else
183 reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
184#endif
185
186#ifdef SWAP_IN_RELOC_OFFSET
187 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
188 (bfd_byte *) reloc_src->r_offset);
189#endif
190}
191
192
193static unsigned int
194DEFUN(coff_swap_reloc_out,(abfd, src, dst),
195 bfd *abfd AND
196 PTR src AND
197 PTR dst)
198{
199 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
200 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
201 bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
202 bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
203 bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
204 reloc_dst->r_type);
205
206#ifdef SWAP_OUT_RELOC_OFFSET
207 SWAP_OUT_RELOC_OFFSET(abfd,
208 reloc_src->r_offset,
209 (bfd_byte *) reloc_dst->r_offset);
210#endif
211#ifdef SWAP_OUT_RELOC_EXTRA
212 SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
213#endif
214
215 return sizeof(struct external_reloc);
216}
217
fbb61b50
SC
218#endif /* NO_COFF_RELOCS */
219
075caafd
ILT
220static void
221DEFUN(coff_swap_filehdr_in,(abfd, src, dst),
222 bfd *abfd AND
223 PTR src AND
224 PTR dst)
225{
226 FILHDR *filehdr_src = (FILHDR *) src;
227 struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
228 filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
229 filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
230 filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
fbb61b50
SC
231 filehdr_dst->f_symptr =
232 GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
075caafd
ILT
233 filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
234 filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
235 filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
236}
237
238static unsigned int
239DEFUN(coff_swap_filehdr_out,(abfd, in, out),
240 bfd *abfd AND
241 PTR in AND
242 PTR out)
243{
244 struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
245 FILHDR *filehdr_out = (FILHDR *)out;
246 bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
247 bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
248 bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
fbb61b50
SC
249 PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
250 (bfd_byte *) filehdr_out->f_symptr);
075caafd
ILT
251 bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
252 bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
253 bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
254 return sizeof(FILHDR);
255}
256
257
258#ifndef NO_COFF_SYMBOLS
259
260static void
261DEFUN(coff_swap_sym_in,(abfd, ext1, in1),
262 bfd *abfd AND
263 PTR ext1 AND
264 PTR in1)
265{
266 SYMENT *ext = (SYMENT *)ext1;
267 struct internal_syment *in = (struct internal_syment *)in1;
268
269 if( ext->e.e_name[0] == 0) {
270 in->_n._n_n._n_zeroes = 0;
271 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
272 }
273 else {
274#if SYMNMLEN != E_SYMNMLEN
275 -> Error, we need to cope with truncating or extending SYMNMLEN!;
276#else
277 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
278#endif
279 }
280 in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
281 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
282 if (sizeof(ext->e_type) == 2){
283 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
284 }
285 else {
286 in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
287 }
288 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
289 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
290}
291
292static unsigned int
293DEFUN(coff_swap_sym_out,(abfd, inp, extp),
294 bfd *abfd AND
295 PTR inp AND
296 PTR extp)
297{
298 struct internal_syment *in = (struct internal_syment *)inp;
299 SYMENT *ext =(SYMENT *)extp;
300 if(in->_n._n_name[0] == 0) {
301 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
302 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
303 }
304 else {
305#if SYMNMLEN != E_SYMNMLEN
306 -> Error, we need to cope with truncating or extending SYMNMLEN!;
307#else
308 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
309#endif
310 }
311 bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
312 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
313 if (sizeof(ext->e_type) == 2)
314 {
315 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
316 }
317 else
318 {
319 bfd_h_put_32(abfd, in->n_type , (bfd_byte *) ext->e_type);
320 }
321 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
322 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
323 return sizeof(SYMENT);
324}
325
326static void
327DEFUN(coff_swap_aux_in,(abfd, ext1, type, class, in1),
328 bfd *abfd AND
329 PTR ext1 AND
330 int type AND
331 int class AND
332 PTR in1)
333{
334 AUXENT *ext = (AUXENT *)ext1;
335 union internal_auxent *in = (union internal_auxent *)in1;
336
337 switch (class) {
338 case C_FILE:
339 if (ext->x_file.x_fname[0] == 0) {
340 in->x_file.x_n.x_zeroes = 0;
341 in->x_file.x_n.x_offset =
342 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
343 } else {
344#if FILNMLEN != E_FILNMLEN
345 -> Error, we need to cope with truncating or extending FILNMLEN!;
346#else
347 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
348#endif
349 }
350 break;
351
352 /* RS/6000 "csect" auxents */
353#ifdef RS6000COFF_C
354 case C_EXT:
355 case C_HIDEXT:
356 in->x_csect.x_scnlen = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_scnlen);
357 in->x_csect.x_parmhash = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_parmhash);
358 in->x_csect.x_snhash = bfd_h_get_16 (abfd, (bfd_byte *) ext->x_csect.x_snhash);
359 /* We don't have to hack bitfields in x_smtyp because it's defined by
360 shifts-and-ands, which are equivalent on all byte orders. */
361 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, (bfd_byte *) ext->x_csect.x_smtyp);
362 in->x_csect.x_smclas = bfd_h_get_8 (abfd, (bfd_byte *) ext->x_csect.x_smclas);
363 in->x_csect.x_stab = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_stab);
364 in->x_csect.x_snstab = bfd_h_get_16 (abfd, (bfd_byte *) ext->x_csect.x_snstab);
365 break;
366#endif
367
368 case C_STAT:
369#ifdef C_LEAFSTAT
370 case C_LEAFSTAT:
371#endif
372 case C_HIDDEN:
373 if (type == T_NULL) {
374 in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
375 in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
376 in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
377 break;
378 }
379 default:
380 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
381#ifndef NO_TVNDX
382 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
383#endif
384
385 if (ISARY(type)) {
386#if DIMNUM != E_DIMNUM
387 -> Error, we need to cope with truncating or extending DIMNUM!;
388#else
389 in->x_sym.x_fcnary.x_ary.x_dimen[0] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
390 in->x_sym.x_fcnary.x_ary.x_dimen[1] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
391 in->x_sym.x_fcnary.x_ary.x_dimen[2] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
392 in->x_sym.x_fcnary.x_ary.x_dimen[3] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
393#endif
394 }
395 if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
396 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR(abfd, ext);
397 in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX(abfd, ext);
398 }
399
400 if (ISFCN(type)) {
401 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
402 }
403 else {
404 in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
405 in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
406 }
407 }
408}
409
410static unsigned int
411DEFUN(coff_swap_aux_out,(abfd, inp, type, class, extp),
412 bfd *abfd AND
413 PTR inp AND
414 int type AND
415 int class AND
416 PTR extp)
417{
418 union internal_auxent *in = (union internal_auxent *)inp;
419 AUXENT *ext = (AUXENT *)extp;
420
421 memset((PTR)ext, 0, AUXESZ);
422 switch (class) {
423 case C_FILE:
424 if (in->x_file.x_fname[0] == 0) {
425 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
426 PUTWORD(abfd,
427 in->x_file.x_n.x_offset,
428 (bfd_byte *) ext->x_file.x_n.x_offset);
429 }
430 else {
431#if FILNMLEN != E_FILNMLEN
432 -> Error, we need to cope with truncating or extending FILNMLEN!;
433#else
434 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
435#endif
436 }
437 break;
438
439#ifdef RS6000COFF_C
440 /* RS/6000 "csect" auxents */
441 case C_EXT:
442 case C_HIDEXT:
443 PUTWORD (abfd, in->x_csect.x_scnlen, ext->x_csect.x_scnlen);
444 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
445 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
446 /* We don't have to hack bitfields in x_smtyp because it's defined by
447 shifts-and-ands, which are equivalent on all byte orders. */
448 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
449 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
450 PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
451 PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
452 break;
453#endif
454
455 case C_STAT:
456#ifdef C_LEAFSTAT
457 case C_LEAFSTAT:
458#endif
459 case C_HIDDEN:
460 if (type == T_NULL) {
461 PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
462 PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
463 PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
464 break;
465 }
466 default:
467 PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
468#ifndef NO_TVNDX
469 bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
470#endif
471
472 if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
473 PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
474 PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
475 }
476
477 if (ISFCN(type)) {
478 PUTWORD(abfd, in->x_sym.x_misc.x_fsize, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
479 }
480 else {
481 if (ISARY(type)) {
482#if DIMNUM != E_DIMNUM
483 -> Error, we need to cope with truncating or extending DIMNUM!;
484#else
485 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
486 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
487 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
488 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
489#endif
490 }
491 PUT_LNSZ_LNNO(abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
492 PUT_LNSZ_SIZE(abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
493 }
494 }
495return sizeof(AUXENT);
496}
497
498#endif /* NO_COFF_SYMBOLS */
499
500#ifndef NO_COFF_LINENOS
501
502static void
503DEFUN(coff_swap_lineno_in,(abfd, ext1, in1),
504 bfd *abfd AND
505 PTR ext1 AND
506 PTR in1)
507{
508 LINENO *ext = (LINENO *)ext1;
509 struct internal_lineno *in = (struct internal_lineno *)in1;
510
511 in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
512 in->l_lnno = GET_LINENO_LNNO(abfd, ext);
513}
514
515static unsigned int
516DEFUN(coff_swap_lineno_out,(abfd, inp, outp),
517 bfd *abfd AND
518 PTR inp AND
519 PTR outp)
520{
521 struct internal_lineno *in = (struct internal_lineno *)inp;
522 struct external_lineno *ext = (struct external_lineno *)outp;
523 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
524 ext->l_addr.l_symndx);
525
526 PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
527 return sizeof(struct external_lineno);
528}
529
530#endif /* NO_COFF_LINENOS */
531
532
533static void
534DEFUN(coff_swap_aouthdr_in,(abfd, aouthdr_ext1, aouthdr_int1),
535 bfd *abfd AND
536 PTR aouthdr_ext1 AND
537 PTR aouthdr_int1)
538{
539 AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
540 struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
541
542 aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
543 aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
fbb61b50
SC
544 aouthdr_int->tsize =
545 GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
546 aouthdr_int->dsize =
547 GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
548 aouthdr_int->bsize =
549 GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
550 aouthdr_int->entry =
551 GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
552 aouthdr_int->text_start =
553 GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
554 aouthdr_int->data_start =
555 GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
556
075caafd
ILT
557#ifdef I960
558 aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
559#endif
560
561#ifdef RS6000COFF_C
562 aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
563 aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
564 aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
565 aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
566 aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
567 aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
568 aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
569 aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
570 aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
571 aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
572 aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
573#endif
fbb61b50
SC
574
575#ifdef MIPSECOFF
576 aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
577 aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
578 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
579 aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
580 aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
581 aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
582 aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
583#endif
584
585#ifdef ALPHAECOFF
586 aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
587 aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
588 aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
589 aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
590#endif
075caafd
ILT
591}
592
593static unsigned int
594DEFUN(coff_swap_aouthdr_out,(abfd, in, out),
595 bfd *abfd AND
596 PTR in AND
597 PTR out)
598{
599 struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
600 AOUTHDR *aouthdr_out = (AOUTHDR *)out;
fbb61b50 601
075caafd
ILT
602 bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
603 bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
fbb61b50
SC
604 PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
605 PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
606 PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
607 PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
608 PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
609 (bfd_byte *) aouthdr_out->text_start);
610 PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
611 (bfd_byte *) aouthdr_out->data_start);
075caafd
ILT
612#ifdef I960
613 bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
614#endif
fbb61b50
SC
615
616#ifdef MIPSECOFF
617 bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
618 bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
619 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
620 bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
621 bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
622 bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
623 bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
624#endif
625
626#ifdef ALPHAECOFF
627 bfd_h_put_32(abfd, 0, (bfd_byte *) aouthdr_out->padding);
628 bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
629 bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
630 bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
631 bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
632#endif
633
075caafd
ILT
634 return sizeof(AOUTHDR);
635}
636
637static void
638DEFUN(coff_swap_scnhdr_in,(abfd, ext, in),
639 bfd *abfd AND
640 PTR ext AND
641 PTR in)
642{
643 SCNHDR *scnhdr_ext = (SCNHDR *) ext;
644 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
075caafd 645
fbb61b50
SC
646 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
647 scnhdr_int->s_vaddr =
648 GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
649 scnhdr_int->s_paddr =
650 GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
651 scnhdr_int->s_size =
652 GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
653
654 scnhdr_int->s_scnptr =
655 GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
656 scnhdr_int->s_relptr =
657 GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
658 scnhdr_int->s_lnnoptr =
659 GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
075caafd
ILT
660 scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
661#if defined(M88)
662 scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
663 scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
664#else
665 scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
666 scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
667#endif
668#ifdef I960
669 scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
670#endif
671}
672
673static unsigned int
674DEFUN(coff_swap_scnhdr_out,(abfd, in, out),
675 bfd *abfd AND
676 PTR in AND
677 PTR out)
678{
679 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
680 SCNHDR *scnhdr_ext = (SCNHDR *)out;
fbb61b50 681
075caafd 682 memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
fbb61b50
SC
683 PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
684 (bfd_byte *) scnhdr_ext->s_vaddr);
685 PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
686 (bfd_byte *) scnhdr_ext->s_paddr);
687 PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
688 (bfd_byte *) scnhdr_ext->s_size);
689 PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
690 (bfd_byte *) scnhdr_ext->s_scnptr);
691 PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
692 (bfd_byte *) scnhdr_ext->s_relptr);
693 PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
694 (bfd_byte *) scnhdr_ext->s_lnnoptr);
075caafd
ILT
695 PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
696#if defined(M88)
697 PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
698 PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
699#else
700 PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
701 PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
702#endif
703
704#if defined(I960)
705 PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
706#endif
707 return sizeof(SCNHDR);
708}
This page took 0.085516 seconds and 4 git commands to generate.