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 MY_symbol_leading_char '\0'
37 #define MY(OP) CAT(mipsbsd_,OP)
44 #define SET_ARCH_MACH(ABFD, EXEC) \
45 MY(set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
46 MY(choose_reloc_size)(ABFD);
47 void MY(set_arch_mach) PARAMS ((bfd *abfd, int machtype));
48 static void MY(choose_reloc_size) PARAMS ((bfd *abfd));
50 #define MY_write_object_contents MY(write_object_contents)
51 static boolean MY(write_object_contents) PARAMS ((bfd *abfd));
53 #define MY_reloc_howto_type_lookup MY(reloc_howto_type_lookup)
54 #define MY_canonicalize_reloc MY(canonicalize_reloc)
56 #define MY_backend_data &MY(backend_data)
59 #include "aout-target.h"
62 MY(set_arch_mach) (abfd, machtype)
66 enum bfd_architecture arch;
69 /* Determine the architecture and machine type of the object file. */
83 arch = bfd_arch_obscure;
87 bfd_set_arch_mach(abfd, arch, machine);
90 /* Determine the size of a relocation entry, based on the architecture */
92 MY(choose_reloc_size) (abfd)
95 switch (bfd_get_arch(abfd)) {
99 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
102 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
107 /* Write an object file in BSD a.out format.
108 Section contents have already been written. We write the
109 file header, symbols, and relocation. */
112 MY(write_object_contents) (abfd)
115 struct external_exec exec_bytes;
116 struct internal_exec *execp = exec_hdr (abfd);
118 /* Magic number, maestro, please! */
119 switch (bfd_get_arch(abfd)) {
121 switch (bfd_get_mach(abfd)) {
123 N_SET_MACHTYPE(*execp, M_68010);
127 N_SET_MACHTYPE(*execp, M_68020);
132 N_SET_MACHTYPE(*execp, M_SPARC);
135 N_SET_MACHTYPE(*execp, M_386);
138 N_SET_MACHTYPE(*execp, M_29K);
141 switch (bfd_get_mach(abfd)) {
144 N_SET_MACHTYPE(*execp, M_MIPS2);
147 N_SET_MACHTYPE(*execp, M_MIPS1);
152 N_SET_MACHTYPE(*execp, M_UNKNOWN);
155 MY(choose_reloc_size)(abfd);
157 WRITE_HEADERS(abfd, execp);
163 * MIPS relocation types.
165 #define MIPS_RELOC_32 0
166 #define MIPS_RELOC_JMP 1
167 #define MIPS_RELOC_WDISP16 2
168 #define MIPS_RELOC_HI16 3
169 #define MIPS_RELOC_HI16_S 4
170 #define MIPS_RELOC_LO16 5
173 * This is only called when performing a BFD_RELOC_HI16_S relocation.
174 * We need to see if bit 15 is set in the result. If it is, we add
175 * 0x10000 and continue normally. This will compensate for the sign extension
176 * when the low bits are added at run time.
178 bfd_reloc_status_type
179 mips_fix_hi16_s (abfd,reloc_entry,symbol,data,input_section,output_bfd)
181 arelent *reloc_entry;
182 struct symbol_cache_entry *symbol;
184 asection *input_section;
189 /* If this is a partial relocation, just continue. */
190 if (output_bfd != (bfd *)NULL)
191 return bfd_reloc_continue;
194 * Work out which section the relocation is targetted at and the
195 * initial relocation command value.
197 if (symbol->section == &bfd_com_section)
200 relocation = symbol->value;
202 relocation += symbol->section->output_section->vma;
203 relocation += symbol->section->output_offset;
204 relocation += reloc_entry->addend;
206 if (relocation & 0x8000)
207 reloc_entry->addend += 0x10000;
209 return bfd_reloc_continue;
212 static reloc_howto_type mips_howto_table_ext[] = {
213 MIPS_RELOC_32, 0, 2, 32, false, 0, true, true, 0,
214 "32", false, 0, 0xffffffff, false,
215 MIPS_RELOC_JMP, 2, 2, 26, false, 0, false, true, 0,
216 "MIPS_JMP", false, 0, 0x03ffffff, false,
217 MIPS_RELOC_WDISP16, 2, 1, 16, true, 0, false, true, 0,
218 "WDISP16", false, 0, 0x0000ffff, false,
219 MIPS_RELOC_HI16, 16, 1, 16, false, 0, false, true, 0,
220 "HI16", false, 0, 0x0000ffff, false,
221 MIPS_RELOC_HI16_S, 16, 1, 16, false, 0, false, true, mips_fix_hi16_s,
222 "HI16_S", false, 0, 0x0000ffff, false,
223 MIPS_RELOC_LO16, 0, 1, 16, false, 0, false, true, 0,
224 "LO16", false, 0, 0x0000ffff, false,
227 static reloc_howto_type *
228 MY(reloc_howto_type_lookup) (abfd, code)
230 bfd_reloc_code_real_type code;
232 extern reloc_howto_type NAME(aout,ext_howto_table)[];
234 if (bfd_get_arch (abfd) != bfd_arch_mips)
240 return (&mips_howto_table_ext[MIPS_RELOC_32]);
241 case BFD_RELOC_MIPS_JMP:
242 return (&mips_howto_table_ext[MIPS_RELOC_JMP]);
243 case BFD_RELOC_16_PCREL_S2:
244 return (&mips_howto_table_ext[MIPS_RELOC_WDISP16]);
246 return (&mips_howto_table_ext[MIPS_RELOC_HI16]);
247 case BFD_RELOC_HI16_S:
248 return (&mips_howto_table_ext[MIPS_RELOC_HI16_S]);
250 return (&mips_howto_table_ext[MIPS_RELOC_LO16]);
257 * This is just like the standard aoutx.h version but we need to do our
258 * own mapping of external reloc type values to howto entries.
261 MY(canonicalize_reloc)(abfd, section, relptr, symbols)
267 arelent *tblptr = section->relocation;
268 unsigned int count, c;
269 extern reloc_howto_type NAME(aout,ext_howto_table)[];
271 /* If we have already read in the relocation table, return the values. */
272 if (section->flags & SEC_CONSTRUCTOR) {
273 arelent_chain *chain = section->constructor_chain;
275 for (count = 0; count < section->reloc_count; count++) {
276 *relptr++ = &chain->relent;
280 return section->reloc_count;
282 if (tblptr && section->reloc_count) {
283 for (count = 0; count++ < section->reloc_count;)
284 *relptr++ = tblptr++;
286 return section->reloc_count;
289 if (!NAME(aout,slurp_reloc_table)(abfd, section, symbols))
291 tblptr = section->relocation;
295 /* fix up howto entries */
296 for (count = 0; count++ < section->reloc_count;)
298 c = tblptr->howto - NAME(aout,ext_howto_table);
299 tblptr->howto = &mips_howto_table_ext[c];
301 *relptr++ = tblptr++;
304 return section->reloc_count;
307 static CONST struct aout_backend_data MY(backend_data) = {
308 0, /* zmagic contiguous */
309 1, /* text incl header */
310 PAGE_SIZE, /* text vma */
312 0, /* text size includes exec header */
315 bfd_target aout_mips_little_vec =
317 "aout-mips-little", /* name */
318 bfd_target_aout_flavour,
319 false, /* target byte order (little) */
320 false, /* target headers byte order (little) */
321 (HAS_RELOC | EXEC_P | /* object flags */
322 HAS_LINENO | HAS_DEBUG |
323 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
324 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
325 MY_symbol_leading_char,
326 ' ', /* ar_pad_char */
327 15, /* ar_max_namelen */
328 1, /* minimum alignment */
329 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
330 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
331 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
332 bfd_generic_archive_p, MY_core_file_p},
333 {bfd_false, MY_mkobject, /* bfd_set_format */
334 _bfd_generic_mkarchive, bfd_false},
335 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
336 _bfd_write_archive_contents, bfd_false},
338 MY_core_file_failing_command,
339 MY_core_file_failing_signal,
340 MY_core_file_matches_executable_p,
342 MY_slurp_extended_name_table,
345 MY_close_and_cleanup,
346 MY_set_section_contents,
347 MY_get_section_contents,
349 MY_get_symtab_upper_bound,
351 MY_get_reloc_upper_bound,
352 MY_canonicalize_reloc,
353 MY_make_empty_symbol,
357 MY_openr_next_archived_file,
358 MY_find_nearest_line,
359 MY_generic_stat_arch_elt,
361 MY_bfd_debug_info_start,
362 MY_bfd_debug_info_end,
363 MY_bfd_debug_info_accumulate,
364 bfd_generic_get_relocated_section_contents,
365 bfd_generic_relax_section,
366 bfd_generic_seclet_link,
367 MY_reloc_howto_type_lookup,
368 MY_make_debug_symbol,
369 (PTR) MY_backend_data,
372 bfd_target aout_mips_big_vec =
374 "aout-mips-big", /* name */
375 bfd_target_aout_flavour,
376 true, /* target byte order (big) */
377 true, /* target headers byte order (big) */
378 (HAS_RELOC | EXEC_P | /* object flags */
379 HAS_LINENO | HAS_DEBUG |
380 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
381 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
382 MY_symbol_leading_char,
383 ' ', /* ar_pad_char */
384 15, /* ar_max_namelen */
385 1, /* minimum alignment */
386 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
387 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
388 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
389 bfd_generic_archive_p, MY_core_file_p},
390 {bfd_false, MY_mkobject, /* bfd_set_format */
391 _bfd_generic_mkarchive, bfd_false},
392 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
393 _bfd_write_archive_contents, bfd_false},
395 MY_core_file_failing_command,
396 MY_core_file_failing_signal,
397 MY_core_file_matches_executable_p,
399 MY_slurp_extended_name_table,
402 MY_close_and_cleanup,
403 MY_set_section_contents,
404 MY_get_section_contents,
406 MY_get_symtab_upper_bound,
408 MY_get_reloc_upper_bound,
409 MY_canonicalize_reloc,
410 MY_make_empty_symbol,
414 MY_openr_next_archived_file,
415 MY_find_nearest_line,
416 MY_generic_stat_arch_elt,
418 MY_bfd_debug_info_start,
419 MY_bfd_debug_info_end,
420 MY_bfd_debug_info_accumulate,
421 bfd_generic_get_relocated_section_contents,
422 bfd_generic_relax_section,
423 bfd_generic_seclet_link,
424 MY_reloc_howto_type_lookup,
425 MY_make_debug_symbol,
426 (PTR) MY_backend_data,