1 /* BFD backend for MIPS BSD (a.out) binaries.
2 Copyright (C) 1993 Free Software Foundation, Inc.
3 Written by Ralph Campbell.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define BYTES_IN_WORD 4
23 /* #define ENTRY_CAN_BE_ZERO */
24 #define N_HEADER_IN_TEXT(x) 1
25 #define N_SHARED_LIB(x) 0
26 #define N_TXTADDR(x) \
27 (N_MAGIC(x) != ZMAGIC ? (x).a_entry : /* object file or NMAGIC */\
28 TEXT_START_ADDR + EXEC_BYTES_SIZE /* no padding */\
30 #define N_DATADDR(x) (N_TXTADDR(x)+N_TXTSIZE(x))
31 #define TEXT_START_ADDR 4096
32 #define PAGE_SIZE 4096
33 #define SEGMENT_SIZE PAGE_SIZE
34 #define DEFAULT_ARCH bfd_arch_mips
35 #define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \
36 || (mtype) == M_MIPS1 || (mtype) == M_MIPS2)
37 #define MY_symbol_leading_char '\0'
39 #define MY(OP) CAT(mipsbsd_,OP)
46 #define SET_ARCH_MACH(ABFD, EXEC) \
47 MY(set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
48 MY(choose_reloc_size)(ABFD);
49 void MY(set_arch_mach
) PARAMS ((bfd
*abfd
, int machtype
));
50 static void MY(choose_reloc_size
) PARAMS ((bfd
*abfd
));
52 #define MY_write_object_contents MY(write_object_contents)
53 static boolean
MY(write_object_contents
) PARAMS ((bfd
*abfd
));
55 #define MY_reloc_howto_type_lookup MY(reloc_howto_type_lookup)
56 #define MY_canonicalize_reloc MY(canonicalize_reloc)
58 #define MY_backend_data &MY(backend_data)
61 #include "aout-target.h"
64 MY(set_arch_mach
) (abfd
, machtype
)
68 enum bfd_architecture arch
;
71 /* Determine the architecture and machine type of the object file. */
85 arch
= bfd_arch_obscure
;
89 bfd_set_arch_mach(abfd
, arch
, machine
);
92 /* Determine the size of a relocation entry, based on the architecture */
94 MY(choose_reloc_size
) (abfd
)
97 switch (bfd_get_arch(abfd
)) {
101 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
104 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
109 /* Write an object file in BSD a.out format.
110 Section contents have already been written. We write the
111 file header, symbols, and relocation. */
114 MY(write_object_contents
) (abfd
)
117 struct external_exec exec_bytes
;
118 struct internal_exec
*execp
= exec_hdr (abfd
);
120 /* Magic number, maestro, please! */
121 switch (bfd_get_arch(abfd
)) {
123 switch (bfd_get_mach(abfd
)) {
125 N_SET_MACHTYPE(*execp
, M_68010
);
129 N_SET_MACHTYPE(*execp
, M_68020
);
134 N_SET_MACHTYPE(*execp
, M_SPARC
);
137 N_SET_MACHTYPE(*execp
, M_386
);
140 N_SET_MACHTYPE(*execp
, M_29K
);
143 switch (bfd_get_mach(abfd
)) {
146 N_SET_MACHTYPE(*execp
, M_MIPS2
);
149 N_SET_MACHTYPE(*execp
, M_MIPS1
);
154 N_SET_MACHTYPE(*execp
, M_UNKNOWN
);
157 MY(choose_reloc_size
)(abfd
);
159 WRITE_HEADERS(abfd
, execp
);
165 * MIPS relocation types.
167 #define MIPS_RELOC_32 0
168 #define MIPS_RELOC_JMP 1
169 #define MIPS_RELOC_WDISP16 2
170 #define MIPS_RELOC_HI16 3
171 #define MIPS_RELOC_HI16_S 4
172 #define MIPS_RELOC_LO16 5
175 * This is only called when performing a BFD_RELOC_HI16_S relocation.
176 * We need to see if bit 15 is set in the result. If it is, we add
177 * 0x10000 and continue normally. This will compensate for the sign extension
178 * when the low bits are added at run time.
180 bfd_reloc_status_type
181 mips_fix_hi16_s (abfd
,reloc_entry
,symbol
,data
,input_section
,output_bfd
)
183 arelent
*reloc_entry
;
184 struct symbol_cache_entry
*symbol
;
186 asection
*input_section
;
191 /* If this is a partial relocation, just continue. */
192 if (output_bfd
!= (bfd
*)NULL
)
193 return bfd_reloc_continue
;
196 * Work out which section the relocation is targetted at and the
197 * initial relocation command value.
199 if (symbol
->section
== &bfd_com_section
)
202 relocation
= symbol
->value
;
204 relocation
+= symbol
->section
->output_section
->vma
;
205 relocation
+= symbol
->section
->output_offset
;
206 relocation
+= reloc_entry
->addend
;
208 if (relocation
& 0x8000)
209 reloc_entry
->addend
+= 0x10000;
211 return bfd_reloc_continue
;
214 static reloc_howto_type mips_howto_table_ext
[] = {
215 {MIPS_RELOC_32
, 0, 2, 32, false, 0, true, true, 0,
216 "32", false, 0, 0xffffffff, false},
217 {MIPS_RELOC_JMP
, 2, 2, 26, false, 0, false, true, 0,
218 "MIPS_JMP", false, 0, 0x03ffffff, false},
219 {MIPS_RELOC_WDISP16
, 2, 1, 16, true, 0, false, true, 0,
220 "WDISP16", false, 0, 0x0000ffff, false},
221 {MIPS_RELOC_HI16
, 16, 1, 16, false, 0, false, true, 0,
222 "HI16", false, 0, 0x0000ffff, false},
223 {MIPS_RELOC_HI16_S
, 16, 1, 16, false, 0, false, true, mips_fix_hi16_s
,
224 "HI16_S", false, 0, 0x0000ffff, false},
225 {MIPS_RELOC_LO16
, 0, 1, 16, false, 0, false, true, 0,
226 "LO16", false, 0, 0x0000ffff, false},
229 static reloc_howto_type
*
230 MY(reloc_howto_type_lookup
) (abfd
, code
)
232 bfd_reloc_code_real_type code
;
235 if (bfd_get_arch (abfd
) != bfd_arch_mips
)
241 return (&mips_howto_table_ext
[MIPS_RELOC_32
]);
242 case BFD_RELOC_MIPS_JMP
:
243 return (&mips_howto_table_ext
[MIPS_RELOC_JMP
]);
244 case BFD_RELOC_16_PCREL_S2
:
245 return (&mips_howto_table_ext
[MIPS_RELOC_WDISP16
]);
247 return (&mips_howto_table_ext
[MIPS_RELOC_HI16
]);
248 case BFD_RELOC_HI16_S
:
249 return (&mips_howto_table_ext
[MIPS_RELOC_HI16_S
]);
251 return (&mips_howto_table_ext
[MIPS_RELOC_LO16
]);
258 * This is just like the standard aoutx.h version but we need to do our
259 * own mapping of external reloc type values to howto entries.
262 MY(canonicalize_reloc
)(abfd
, section
, relptr
, symbols
)
268 arelent
*tblptr
= section
->relocation
;
269 unsigned int count
, c
;
270 extern reloc_howto_type
NAME(aout
,ext_howto_table
)[];
272 /* If we have already read in the relocation table, return the values. */
273 if (section
->flags
& SEC_CONSTRUCTOR
) {
274 arelent_chain
*chain
= section
->constructor_chain
;
276 for (count
= 0; count
< section
->reloc_count
; count
++) {
277 *relptr
++ = &chain
->relent
;
281 return section
->reloc_count
;
283 if (tblptr
&& section
->reloc_count
) {
284 for (count
= 0; count
++ < section
->reloc_count
;)
285 *relptr
++ = tblptr
++;
287 return section
->reloc_count
;
290 if (!NAME(aout
,slurp_reloc_table
)(abfd
, section
, symbols
))
292 tblptr
= section
->relocation
;
296 /* fix up howto entries */
297 for (count
= 0; count
++ < section
->reloc_count
;)
299 c
= tblptr
->howto
- NAME(aout
,ext_howto_table
);
300 tblptr
->howto
= &mips_howto_table_ext
[c
];
302 *relptr
++ = tblptr
++;
305 return section
->reloc_count
;
308 static CONST
struct aout_backend_data
MY(backend_data
) = {
309 0, /* zmagic contiguous */
310 1, /* text incl header */
311 PAGE_SIZE
, /* text vma */
313 0, /* text size includes exec header */
316 bfd_target aout_mips_little_vec
=
318 "aout-mips-little", /* name */
319 bfd_target_aout_flavour
,
320 false, /* target byte order (little) */
321 false, /* target headers byte order (little) */
322 (HAS_RELOC
| EXEC_P
| /* object flags */
323 HAS_LINENO
| HAS_DEBUG
|
324 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
325 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
326 MY_symbol_leading_char
,
327 ' ', /* ar_pad_char */
328 15, /* ar_max_namelen */
329 1, /* minimum alignment */
330 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* data */
331 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* hdrs */
332 {_bfd_dummy_target
, MY_object_p
, /* bfd_check_format */
333 bfd_generic_archive_p
, MY_core_file_p
},
334 {bfd_false
, MY_mkobject
, /* bfd_set_format */
335 _bfd_generic_mkarchive
, bfd_false
},
336 {bfd_false
, MY_write_object_contents
, /* bfd_write_contents */
337 _bfd_write_archive_contents
, bfd_false
},
339 MY_core_file_failing_command
,
340 MY_core_file_failing_signal
,
341 MY_core_file_matches_executable_p
,
343 MY_slurp_extended_name_table
,
346 MY_close_and_cleanup
,
347 MY_set_section_contents
,
348 MY_get_section_contents
,
350 MY_get_symtab_upper_bound
,
352 MY_get_reloc_upper_bound
,
353 MY_canonicalize_reloc
,
354 MY_make_empty_symbol
,
358 MY_openr_next_archived_file
,
359 MY_find_nearest_line
,
360 MY_generic_stat_arch_elt
,
362 MY_bfd_debug_info_start
,
363 MY_bfd_debug_info_end
,
364 MY_bfd_debug_info_accumulate
,
365 bfd_generic_get_relocated_section_contents
,
366 bfd_generic_relax_section
,
367 bfd_generic_seclet_link
,
368 MY_reloc_howto_type_lookup
,
369 MY_make_debug_symbol
,
370 (PTR
) MY_backend_data
,
373 bfd_target aout_mips_big_vec
=
375 "aout-mips-big", /* name */
376 bfd_target_aout_flavour
,
377 true, /* target byte order (big) */
378 true, /* target headers byte order (big) */
379 (HAS_RELOC
| EXEC_P
| /* object flags */
380 HAS_LINENO
| HAS_DEBUG
|
381 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
382 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
383 MY_symbol_leading_char
,
384 ' ', /* ar_pad_char */
385 15, /* ar_max_namelen */
386 1, /* minimum alignment */
387 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* data */
388 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* hdrs */
389 {_bfd_dummy_target
, MY_object_p
, /* bfd_check_format */
390 bfd_generic_archive_p
, MY_core_file_p
},
391 {bfd_false
, MY_mkobject
, /* bfd_set_format */
392 _bfd_generic_mkarchive
, bfd_false
},
393 {bfd_false
, MY_write_object_contents
, /* bfd_write_contents */
394 _bfd_write_archive_contents
, bfd_false
},
396 MY_core_file_failing_command
,
397 MY_core_file_failing_signal
,
398 MY_core_file_matches_executable_p
,
400 MY_slurp_extended_name_table
,
403 MY_close_and_cleanup
,
404 MY_set_section_contents
,
405 MY_get_section_contents
,
407 MY_get_symtab_upper_bound
,
409 MY_get_reloc_upper_bound
,
410 MY_canonicalize_reloc
,
411 MY_make_empty_symbol
,
415 MY_openr_next_archived_file
,
416 MY_find_nearest_line
,
417 MY_generic_stat_arch_elt
,
419 MY_bfd_debug_info_start
,
420 MY_bfd_debug_info_end
,
421 MY_bfd_debug_info_accumulate
,
422 bfd_generic_get_relocated_section_contents
,
423 bfd_generic_relax_section
,
424 bfd_generic_seclet_link
,
425 MY_reloc_howto_type_lookup
,
426 MY_make_debug_symbol
,
427 (PTR
) MY_backend_data
,