aboutsummaryrefslogtreecommitdiff
path: root/bfd/coffswap.c
blob: b1f74517eeb4c5cfa9a922cd2335c2e8060b10a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* Byte-swapping routines for COFF files */

/* Copyright (C) 1990, 1991 Free Software Foundation, Inc.

This file is part of BFD, the Binary File Diddler.

BFD is free software; you can redistribute it and/or modify it under the
   terms of the GNU General Public License as published by the Free Software
   Foundation; either version 1, or (at your option) any later version.

BFD is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   details.

You should have received a copy of the GNU General Public License along with
   BFD; see the file COPYING.  If not, write to the Free Software Foundation,
   675 Mass Ave, Cambridge, MA 02139, USA.
*/

/* Most of this hacked by Steve Chamberlain, steve@cygnus.com */
#if 0
#include <ansidecl.h>
#include "intel-coff.h"
#include "bfd.h"
#include "libcoff.h"		/* to allow easier abstraction-breaking */

#define sp(x) bfd_h_put_x(abfd, x, &x)

/* All the generic swapping routines:

FIXME
   These routines cater for the sizes and alignments and offsets of
   all the contained fields. Because of this, the fields can change
   size, so these should be phased out to use the ones specific to the
   file format.
 */

void 
DEFUN(bfd_coff_swap_name,(abfd, ptr),
      bfd            *abfd AND
      long           *ptr)
{
    if (ptr[0] == 0) {
	/* There is an index which needs to be swapped */
	bfd_h_put_x(abfd, ptr[1], (ptr + 1));
    }
    else {
	/* This is a string .. leave it alone */
    }
}

void 
DEFUN(bfd_coff_swap_sym,(abfd, se),
      bfd            *abfd AND
      struct internal_syment      *se)
{
    bfd_coff_swap_name(abfd, (long*)(se->n_name));
    bfd_h_put_x(abfd, se->n_value, &se->n_value);
    bfd_h_put_x(abfd, se->n_scnum, &se->n_scnum);
    bfd_h_put_x(abfd, se->n_type, &se->n_type);
    bfd_h_put_x(abfd, se->n_sclass, &se->n_sclass);
    bfd_h_put_x(abfd, se->n_numaux, &se->n_numaux);
}

void
DEFUN(bfd_coff_swap_aux,(abfd, au, type, class),
      bfd            *abfd AND
      struct internal_auxent    *au AND
      int             type AND
      int             class)
{
    switch (class) {
    case C_FILE:
	bfd_coff_swap_name(abfd, (long *)(&au->x_file.x_n));
	break;
    case C_STAT:
#ifdef C_LEAFSTAT
    case C_LEAFSTAT:
#endif
    case C_HIDDEN:
	if (type == T_NULL) {
	    sp(au->x_scn.x_scnlen);
	    sp(au->x_scn.x_nreloc);
	    sp(au->x_scn.x_nlinno);
	    break;
	}
    default:
	sp(au->x_sym.x_tagndx);
	sp(au->x_sym.x_tvndx);

	if (ISARY(type) || class == C_BLOCK) {
	    sp(au->x_sym.x_fcnary.x_ary.x_dimen[0]);
	    sp(au->x_sym.x_fcnary.x_ary.x_dimen[1]);
	    sp(au->x_sym.x_fcnary.x_ary.x_dimen[2]);
	    sp(au->x_sym.x_fcnary.x_ary.x_dimen[3]);
	}
	else {
	    sp(au->x_sym.x_fcnary.x_fcn.x_lnnoptr);
	    sp(au->x_sym.x_fcnary.x_fcn.x_endndx);
	}
	if (ISFCN(type)) {
	    sp(au->x_sym.x_misc.x_fsize);
	}
	else {
	    sp(au->x_sym.x_misc.x_lnsz.x_lnno);
	    sp(au->x_sym.x_misc.x_lnsz.x_size);
	}
    }
}

void
DEFUN(bfd_coff_swap_lineno,(abfd, lineno),
      bfd            *abfd AND
      struct internal_lineno      *lineno)
{
    sp(lineno->l_addr.l_symndx);
    sp(lineno->l_lnno);
}



#endif