1 /* Byte swap a symbol table in MIPS' format (Third-Eye).
2 Copyright 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
22 #define LANGUAGE_C /* Wierd MIPS crap */
23 #include "sym.h" /* MIPS symbols */
24 #include "symconst.h" /* MIPS symbols */
25 #include "coff/ecoff-ext.h" /* ECOFF external struct defns */
28 ecoff_swap_hdr_in (abfd
, ext_copy
, intern
)
30 struct hdr_ext
*ext_copy
;
33 struct hdr_ext ext
[1];
37 intern
->magic
= bfd_h_get_16 (abfd
, (bfd_byte
*)ext
->h_magic
);
38 intern
->vstamp
= bfd_h_get_16 (abfd
, (bfd_byte
*)ext
->h_vstamp
);
39 intern
->ilineMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_ilineMax
);
40 intern
->cbLine
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbLine
);
41 intern
->cbLineOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbLineOffset
);
42 intern
->idnMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_idnMax
);
43 intern
->cbDnOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbDnOffset
);
44 intern
->ipdMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_ipdMax
);
45 intern
->cbPdOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbPdOffset
);
46 intern
->isymMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_isymMax
);
47 intern
->cbSymOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbSymOffset
);
48 intern
->ioptMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_ioptMax
);
49 intern
->cbOptOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbOptOffset
);
50 intern
->iauxMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_iauxMax
);
51 intern
->cbAuxOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbAuxOffset
);
52 intern
->issMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_issMax
);
53 intern
->cbSsOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbSsOffset
);
54 intern
->issExtMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_issExtMax
);
55 intern
->cbSsExtOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbSsExtOffset
);
56 intern
->ifdMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_ifdMax
);
57 intern
->cbFdOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbFdOffset
);
58 intern
->crfd
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_crfd
);
59 intern
->cbRfdOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbRfdOffset
);
60 intern
->iextMax
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_iextMax
);
61 intern
->cbExtOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->h_cbExtOffset
);
64 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
69 /* Swap in the file descriptor record. */
72 ecoff_swap_fdr_in (abfd
, ext_copy
, intern
)
74 struct fdr_ext
*ext_copy
;
77 struct fdr_ext ext
[1];
79 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
81 intern
->adr
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_adr
);
82 intern
->rss
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_rss
);
83 intern
->issBase
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_issBase
);
84 intern
->cbSs
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_cbSs
);
85 intern
->isymBase
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_isymBase
);
86 intern
->csym
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_csym
);
87 intern
->ilineBase
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_ilineBase
);
88 intern
->cline
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_cline
);
89 intern
->ioptBase
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_ioptBase
);
90 intern
->copt
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_copt
);
91 intern
->ipdFirst
= bfd_h_get_16 (abfd
, (bfd_byte
*)ext
->f_ipdFirst
);
92 intern
->cpd
= bfd_h_get_16 (abfd
, (bfd_byte
*)ext
->f_cpd
);
93 intern
->iauxBase
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_iauxBase
);
94 intern
->caux
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_caux
);
95 intern
->rfdBase
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_rfdBase
);
96 intern
->crfd
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_crfd
);
98 /* now the fun stuff... */
99 if (abfd
->xvec
->header_byteorder_big_p
!= false) {
100 intern
->lang
= (ext
->f_bits1
[0] & FDR_BITS1_LANG_BIG
)
101 >> FDR_BITS1_LANG_SH_BIG
;
102 intern
->fMerge
= 0 != (ext
->f_bits1
[0] & FDR_BITS1_FMERGE_BIG
);
103 intern
->fReadin
= 0 != (ext
->f_bits1
[0] & FDR_BITS1_FREADIN_BIG
);
104 intern
->fBigendian
= 0 != (ext
->f_bits1
[0] & FDR_BITS1_FBIGENDIAN_BIG
);
105 intern
->glevel
= (ext
->f_bits2
[0] & FDR_BITS2_GLEVEL_BIG
)
106 >> FDR_BITS2_GLEVEL_SH_BIG
;
107 /* intern->reserved we ignore. */
109 intern
->lang
= (ext
->f_bits1
[0] & FDR_BITS1_LANG_LITTLE
)
110 >> FDR_BITS1_LANG_SH_LITTLE
;
111 intern
->fMerge
= 0 != (ext
->f_bits1
[0] & FDR_BITS1_FMERGE_LITTLE
);
112 intern
->fReadin
= 0 != (ext
->f_bits1
[0] & FDR_BITS1_FREADIN_LITTLE
);
113 intern
->fBigendian
= 0 != (ext
->f_bits1
[0] & FDR_BITS1_FBIGENDIAN_LITTLE
);
114 intern
->glevel
= (ext
->f_bits2
[0] & FDR_BITS2_GLEVEL_LITTLE
)
115 >> FDR_BITS2_GLEVEL_SH_LITTLE
;
116 /* intern->reserved we ignore. */
119 intern
->cbLineOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_cbLineOffset
);
120 intern
->cbLine
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->f_cbLine
);
123 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
130 /* Swap in the procedure descriptor record. */
133 ecoff_swap_pdr_in (abfd
, ext_copy
, intern
)
135 struct pdr_ext
*ext_copy
;
138 struct pdr_ext ext
[1];
140 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
142 intern
->adr
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_adr
);
143 intern
->isym
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_isym
);
144 intern
->iline
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_iline
);
145 intern
->regmask
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_regmask
);
146 intern
->regoffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_regoffset
);
147 intern
->iopt
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_iopt
);
148 intern
->fregmask
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_fregmask
);
149 intern
->fregoffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_fregoffset
);
150 intern
->frameoffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_frameoffset
);
151 intern
->framereg
= bfd_h_get_16 (abfd
, (bfd_byte
*)ext
->p_framereg
);
152 intern
->pcreg
= bfd_h_get_16 (abfd
, (bfd_byte
*)ext
->p_pcreg
);
153 intern
->lnLow
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_lnLow
);
154 intern
->lnHigh
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_lnHigh
);
155 intern
->cbLineOffset
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->p_cbLineOffset
);
158 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
164 /* Swap in a symbol record. */
167 ecoff_swap_sym_in (abfd
, ext_copy
, intern
)
169 struct sym_ext
*ext_copy
;
172 struct sym_ext ext
[1];
174 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
176 intern
->iss
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->s_iss
);
177 intern
->value
= bfd_h_get_32 (abfd
, (bfd_byte
*)ext
->s_value
);
179 /* now the fun stuff... */
180 if (abfd
->xvec
->header_byteorder_big_p
!= false) {
181 intern
->st
= (ext
->s_bits1
[0] & SYM_BITS1_ST_BIG
)
182 >> SYM_BITS1_ST_SH_BIG
;
183 intern
->sc
= ((ext
->s_bits1
[0] & SYM_BITS1_SC_BIG
)
184 << SYM_BITS1_SC_SH_LEFT_BIG
)
185 | ((ext
->s_bits2
[0] & SYM_BITS2_SC_BIG
)
186 >> SYM_BITS2_SC_SH_BIG
);
187 intern
->reserved
= 0 != (ext
->s_bits2
[0] & SYM_BITS2_RESERVED_BIG
);
188 intern
->index
= ((ext
->s_bits2
[0] & SYM_BITS2_INDEX_BIG
)
189 << SYM_BITS2_INDEX_SH_LEFT_BIG
)
190 | (ext
->s_bits3
[0] << SYM_BITS3_INDEX_SH_LEFT_BIG
)
191 | (ext
->s_bits4
[0] << SYM_BITS4_INDEX_SH_LEFT_BIG
);
193 intern
->st
= (ext
->s_bits1
[0] & SYM_BITS1_ST_LITTLE
)
194 >> SYM_BITS1_ST_SH_LITTLE
;
195 intern
->sc
= ((ext
->s_bits1
[0] & SYM_BITS1_SC_LITTLE
)
196 >> SYM_BITS1_SC_SH_LITTLE
)
197 | ((ext
->s_bits2
[0] & SYM_BITS2_SC_LITTLE
)
198 << SYM_BITS2_SC_SH_LEFT_LITTLE
);
199 intern
->reserved
= 0 != (ext
->s_bits2
[0] & SYM_BITS2_RESERVED_LITTLE
);
200 intern
->index
= ((ext
->s_bits2
[0] & SYM_BITS2_INDEX_LITTLE
)
201 >> SYM_BITS2_INDEX_SH_LITTLE
)
202 | (ext
->s_bits3
[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE
)
203 | (ext
->s_bits4
[0] << SYM_BITS4_INDEX_SH_LEFT_LITTLE
);
207 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
213 /* Swap in an external symbol record. */
216 ecoff_swap_ext_in (abfd
, ext_copy
, intern
)
218 struct ext_ext
*ext_copy
;
221 struct ext_ext ext
[1];
223 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
225 /* now the fun stuff... */
226 if (abfd
->xvec
->header_byteorder_big_p
!= false) {
227 intern
->jmptbl
= 0 != (ext
->es_bits1
[0] & EXT_BITS1_JMPTBL_BIG
);
228 intern
->cobol_main
= 0 != (ext
->es_bits1
[0] & EXT_BITS1_COBOL_MAIN_BIG
);
230 intern
->jmptbl
= 0 != (ext
->es_bits1
[0] & EXT_BITS1_JMPTBL_LITTLE
);
231 intern
->cobol_main
= 0 != (ext
->es_bits1
[0] & EXT_BITS1_COBOL_MAIN_LITTLE
);
234 intern
->ifd
= bfd_h_get_16 (abfd
, (bfd_byte
*)ext
->es_ifd
);
235 ecoff_swap_sym_in (abfd
, &ext
->es_asym
, &intern
->asym
);
238 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
243 /* Swap in a type information record.
244 BIGEND says whether AUX symbols are big-endian or little-endian; this
245 info comes from the file header record (fh-fBigendian). */
248 ecoff_swap_tir_in (bigend
, ext_copy
, intern
)
250 struct tir_ext
*ext_copy
;
253 struct tir_ext ext
[1];
255 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
257 /* now the fun stuff... */
259 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_BIG
);
260 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_BIG
);
261 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_BIG
)
262 >> TIR_BITS1_BT_SH_BIG
;
263 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_BIG
)
264 >> TIR_BITS_TQ4_SH_BIG
;
265 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_BIG
)
266 >> TIR_BITS_TQ5_SH_BIG
;
267 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_BIG
)
268 >> TIR_BITS_TQ0_SH_BIG
;
269 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_BIG
)
270 >> TIR_BITS_TQ1_SH_BIG
;
271 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_BIG
)
272 >> TIR_BITS_TQ2_SH_BIG
;
273 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_BIG
)
274 >> TIR_BITS_TQ3_SH_BIG
;
276 intern
->fBitfield
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_FBITFIELD_LITTLE
);
277 intern
->continued
= 0 != (ext
->t_bits1
[0] & TIR_BITS1_CONTINUED_LITTLE
);
278 intern
->bt
= (ext
->t_bits1
[0] & TIR_BITS1_BT_LITTLE
)
279 >> TIR_BITS1_BT_SH_LITTLE
;
280 intern
->tq4
= (ext
->t_tq45
[0] & TIR_BITS_TQ4_LITTLE
)
281 >> TIR_BITS_TQ4_SH_LITTLE
;
282 intern
->tq5
= (ext
->t_tq45
[0] & TIR_BITS_TQ5_LITTLE
)
283 >> TIR_BITS_TQ5_SH_LITTLE
;
284 intern
->tq0
= (ext
->t_tq01
[0] & TIR_BITS_TQ0_LITTLE
)
285 >> TIR_BITS_TQ0_SH_LITTLE
;
286 intern
->tq1
= (ext
->t_tq01
[0] & TIR_BITS_TQ1_LITTLE
)
287 >> TIR_BITS_TQ1_SH_LITTLE
;
288 intern
->tq2
= (ext
->t_tq23
[0] & TIR_BITS_TQ2_LITTLE
)
289 >> TIR_BITS_TQ2_SH_LITTLE
;
290 intern
->tq3
= (ext
->t_tq23
[0] & TIR_BITS_TQ3_LITTLE
)
291 >> TIR_BITS_TQ3_SH_LITTLE
;
295 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)
300 /* Swap in a relative symbol record. BIGEND says whether it is in
301 big-endian or little-endian format.*/
304 ecoff_swap_rndx_in (bigend
, ext_copy
, intern
)
306 struct rndx_ext
*ext_copy
;
309 struct rndx_ext ext
[1];
311 *ext
= *ext_copy
; /* Make it reasonable to do in-place. */
313 /* now the fun stuff... */
315 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_BIG
)
316 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_BIG
)
317 >> RNDX_BITS1_RFD_SH_BIG
);
318 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_BIG
)
319 << RNDX_BITS1_INDEX_SH_LEFT_BIG
)
320 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_BIG
)
321 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_BIG
);
323 intern
->rfd
= (ext
->r_bits
[0] << RNDX_BITS0_RFD_SH_LEFT_LITTLE
)
324 | ((ext
->r_bits
[1] & RNDX_BITS1_RFD_LITTLE
)
325 << RNDX_BITS1_RFD_SH_LEFT_LITTLE
);
326 intern
->index
= ((ext
->r_bits
[1] & RNDX_BITS1_INDEX_LITTLE
)
327 >> RNDX_BITS1_INDEX_SH_LITTLE
)
328 | (ext
->r_bits
[2] << RNDX_BITS2_INDEX_SH_LEFT_LITTLE
)
329 | (ext
->r_bits
[3] << RNDX_BITS3_INDEX_SH_LEFT_LITTLE
);
333 if (memcmp ((char *)ext
, (char *)intern
, sizeof (*intern
)) != 0)