4397c9c2302642dfdb0e00b2f54041c50128ef60
[deliverable/binutils-gdb.git] / gdb / ecoff.c
1 /* Byte swap a symbol table in MIPS' format (Third-Eye).
2 Copyright 1992 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <stdio.h>
21 #include "defs.h"
22 #include "bfd.h"
23 #define LANGUAGE_C /* Wierd MIPS crap */
24 #include "sym.h" /* MIPS symbols */
25 #include "symconst.h" /* MIPS symbols */
26 #include "coff/ecoff-ext.h" /* ECOFF external struct defns */
27
28 void
29 ecoff_swap_hdr_in (abfd, ext_copy, intern)
30 bfd *abfd;
31 struct hdr_ext *ext_copy;
32 HDRR *intern;
33 {
34 struct hdr_ext ext[1];
35
36 *ext = *ext_copy;
37
38 intern->magic = bfd_h_get_16 (abfd, (bfd_byte *)ext->h_magic);
39 intern->vstamp = bfd_h_get_16 (abfd, (bfd_byte *)ext->h_vstamp);
40 intern->ilineMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax);
41 intern->cbLine = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbLine);
42 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbLineOffset);
43 intern->idnMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax);
44 intern->cbDnOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbDnOffset);
45 intern->ipdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax);
46 intern->cbPdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbPdOffset);
47 intern->isymMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax);
48 intern->cbSymOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSymOffset);
49 intern->ioptMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax);
50 intern->cbOptOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbOptOffset);
51 intern->iauxMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax);
52 intern->cbAuxOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbAuxOffset);
53 intern->issMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax);
54 intern->cbSsOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSsOffset);
55 intern->issExtMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax);
56 intern->cbSsExtOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbSsExtOffset);
57 intern->ifdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax);
58 intern->cbFdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbFdOffset);
59 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd);
60 intern->cbRfdOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbRfdOffset);
61 intern->iextMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax);
62 intern->cbExtOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_cbExtOffset);
63
64 #ifdef TEST
65 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
66 abort();
67 #endif
68 }
69
70 /* Swap in the file descriptor record. */
71
72 void
73 ecoff_swap_fdr_in (abfd, ext_copy, intern)
74 bfd *abfd;
75 struct fdr_ext *ext_copy;
76 FDR *intern;
77 {
78 struct fdr_ext ext[1];
79
80 *ext = *ext_copy; /* Make it reasonable to do in-place. */
81
82 intern->adr = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_adr);
83 intern->rss = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
84 intern->issBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase);
85 intern->cbSs = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbSs);
86 intern->isymBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase);
87 intern->csym = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym);
88 intern->ilineBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase);
89 intern->cline = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
90 intern->ioptBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
91 intern->copt = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
92 intern->ipdFirst = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
93 intern->cpd = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
94 intern->iauxBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase);
95 intern->caux = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux);
96 intern->rfdBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase);
97 intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd);
98
99 /* now the fun stuff... */
100 if (abfd->xvec->header_byteorder_big_p != false) {
101 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
102 >> FDR_BITS1_LANG_SH_BIG;
103 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
104 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
105 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
106 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
107 >> FDR_BITS2_GLEVEL_SH_BIG;
108 /* intern->reserved we ignore. */
109 } else {
110 intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
111 >> FDR_BITS1_LANG_SH_LITTLE;
112 intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
113 intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
114 intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
115 intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
116 >> FDR_BITS2_GLEVEL_SH_LITTLE;
117 /* intern->reserved we ignore. */
118 }
119
120 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbLineOffset);
121 intern->cbLine = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cbLine);
122
123 #ifdef TEST
124 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
125 abort();
126 #endif
127 }
128
129
130
131 /* Swap in the procedure descriptor record. */
132
133 void
134 ecoff_swap_pdr_in (abfd, ext_copy, intern)
135 bfd *abfd;
136 struct pdr_ext *ext_copy;
137 PDR *intern;
138 {
139 struct pdr_ext ext[1];
140
141 *ext = *ext_copy; /* Make it reasonable to do in-place. */
142
143 intern->adr = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_adr);
144 intern->isym = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
145 intern->iline = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
146 intern->regmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
147 intern->regoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regoffset);
148 intern->iopt = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iopt);
149 intern->fregmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
150 intern->fregoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregoffset);
151 intern->frameoffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_frameoffset);
152 intern->framereg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
153 intern->pcreg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
154 intern->lnLow = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
155 intern->lnHigh = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
156 intern->cbLineOffset = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_cbLineOffset);
157
158 #ifdef TEST
159 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
160 abort();
161 #endif
162 }
163
164
165 /* Swap in a symbol record. */
166
167 void
168 ecoff_swap_sym_in (abfd, ext_copy, intern)
169 bfd *abfd;
170 struct sym_ext *ext_copy;
171 SYMR *intern;
172 {
173 struct sym_ext ext[1];
174
175 *ext = *ext_copy; /* Make it reasonable to do in-place. */
176
177 intern->iss = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss);
178 intern->value = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_value);
179
180 /* now the fun stuff... */
181 if (abfd->xvec->header_byteorder_big_p != false) {
182 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
183 >> SYM_BITS1_ST_SH_BIG;
184 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
185 << SYM_BITS1_SC_SH_LEFT_BIG)
186 | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
187 >> SYM_BITS2_SC_SH_BIG);
188 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
189 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
190 << SYM_BITS2_INDEX_SH_LEFT_BIG)
191 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
192 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
193 } else {
194 intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
195 >> SYM_BITS1_ST_SH_LITTLE;
196 intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
197 >> SYM_BITS1_SC_SH_LITTLE)
198 | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
199 << SYM_BITS2_SC_SH_LEFT_LITTLE);
200 intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
201 intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
202 >> SYM_BITS2_INDEX_SH_LITTLE)
203 | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
204 | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
205 }
206
207 #ifdef TEST
208 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
209 abort();
210 #endif
211 }
212
213
214 /* Swap in an external symbol record. */
215
216 void
217 ecoff_swap_ext_in (abfd, ext_copy, intern)
218 bfd *abfd;
219 struct ext_ext *ext_copy;
220 EXTR *intern;
221 {
222 struct ext_ext ext[1];
223
224 *ext = *ext_copy; /* Make it reasonable to do in-place. */
225
226 /* now the fun stuff... */
227 if (abfd->xvec->header_byteorder_big_p != false) {
228 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
229 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
230 } else {
231 intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
232 intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
233 }
234
235 intern->ifd = bfd_h_get_16 (abfd, (bfd_byte *)ext->es_ifd);
236 ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
237
238 #ifdef TEST
239 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
240 abort();
241 #endif
242 }
243
244 /* Swap in a type information record.
245 BIGEND says whether AUX symbols are big-endian or little-endian; this
246 info comes from the file header record (fh-fBigendian). */
247
248 void
249 ecoff_swap_tir_in (bigend, ext_copy, intern)
250 int bigend;
251 struct tir_ext *ext_copy;
252 TIR *intern;
253 {
254 struct tir_ext ext[1];
255
256 *ext = *ext_copy; /* Make it reasonable to do in-place. */
257
258 /* now the fun stuff... */
259 if (bigend) {
260 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
261 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
262 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_BIG)
263 >> TIR_BITS1_BT_SH_BIG;
264 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_BIG)
265 >> TIR_BITS_TQ4_SH_BIG;
266 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_BIG)
267 >> TIR_BITS_TQ5_SH_BIG;
268 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_BIG)
269 >> TIR_BITS_TQ0_SH_BIG;
270 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_BIG)
271 >> TIR_BITS_TQ1_SH_BIG;
272 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_BIG)
273 >> TIR_BITS_TQ2_SH_BIG;
274 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_BIG)
275 >> TIR_BITS_TQ3_SH_BIG;
276 } else {
277 intern->fBitfield = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_LITTLE);
278 intern->continued = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_LITTLE);
279 intern->bt = (ext->t_bits1[0] & TIR_BITS1_BT_LITTLE)
280 >> TIR_BITS1_BT_SH_LITTLE;
281 intern->tq4 = (ext->t_tq45[0] & TIR_BITS_TQ4_LITTLE)
282 >> TIR_BITS_TQ4_SH_LITTLE;
283 intern->tq5 = (ext->t_tq45[0] & TIR_BITS_TQ5_LITTLE)
284 >> TIR_BITS_TQ5_SH_LITTLE;
285 intern->tq0 = (ext->t_tq01[0] & TIR_BITS_TQ0_LITTLE)
286 >> TIR_BITS_TQ0_SH_LITTLE;
287 intern->tq1 = (ext->t_tq01[0] & TIR_BITS_TQ1_LITTLE)
288 >> TIR_BITS_TQ1_SH_LITTLE;
289 intern->tq2 = (ext->t_tq23[0] & TIR_BITS_TQ2_LITTLE)
290 >> TIR_BITS_TQ2_SH_LITTLE;
291 intern->tq3 = (ext->t_tq23[0] & TIR_BITS_TQ3_LITTLE)
292 >> TIR_BITS_TQ3_SH_LITTLE;
293 }
294
295 #ifdef TEST
296 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
297 abort();
298 #endif
299 }
300
301 /* Swap in a relative symbol record. BIGEND says whether it is in
302 big-endian or little-endian format.*/
303
304 void
305 ecoff_swap_rndx_in (bigend, ext_copy, intern)
306 int bigend;
307 struct rndx_ext *ext_copy;
308 RNDXR *intern;
309 {
310 struct rndx_ext ext[1];
311
312 *ext = *ext_copy; /* Make it reasonable to do in-place. */
313
314 /* now the fun stuff... */
315 if (bigend) {
316 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
317 | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
318 >> RNDX_BITS1_RFD_SH_BIG);
319 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_BIG)
320 << RNDX_BITS1_INDEX_SH_LEFT_BIG)
321 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG)
322 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG);
323 } else {
324 intern->rfd = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE)
325 | ((ext->r_bits[1] & RNDX_BITS1_RFD_LITTLE)
326 << RNDX_BITS1_RFD_SH_LEFT_LITTLE);
327 intern->index = ((ext->r_bits[1] & RNDX_BITS1_INDEX_LITTLE)
328 >> RNDX_BITS1_INDEX_SH_LITTLE)
329 | (ext->r_bits[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE)
330 | (ext->r_bits[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE);
331 }
332
333 #ifdef TEST
334 if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
335 abort();
336 #endif
337 }
This page took 0.037031 seconds and 4 git commands to generate.