1 #define BYTES_IN_WORD 4
3 /* #define ENTRY_CAN_BE_ZERO */
4 #define N_HEADER_IN_TEXT(x) 1
5 #define N_SHARED_LIB(x) 0
7 (N_MAGIC(x) != ZMAGIC ? (x).a_entry : /* object file or NMAGIC */\
8 TEXT_START_ADDR + EXEC_BYTES_SIZE /* no padding */\
10 #define N_DATADDR(x) (N_TXTADDR(x)+N_TXTSIZE(x))
11 #define TEXT_START_ADDR 4096
12 #define PAGE_SIZE 4096
13 #define SEGMENT_SIZE PAGE_SIZE
14 #define DEFAULT_ARCH bfd_arch_mips
15 #define MY_symbol_leading_char '\0'
17 #define MY(OP) CAT(mipsbsd_,OP)
24 #define SET_ARCH_MACH(ABFD, EXEC) \
25 MY(set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
26 MY(choose_reloc_size)(ABFD);
27 void MY(set_arch_mach
) PARAMS ((bfd
*abfd
, int machtype
));
28 static void MY(choose_reloc_size
) PARAMS ((bfd
*abfd
));
30 #define MY_write_object_contents MY(write_object_contents)
31 static boolean
MY(write_object_contents
) PARAMS ((bfd
*abfd
));
33 #define MY_reloc_howto_type_lookup MY(reloc_howto_type_lookup)
34 #define MY_canonicalize_reloc MY(canonicalize_reloc)
36 #define MY_backend_data &MY(backend_data)
39 #include "aout-target.h"
42 * These really should be common to all BSD systems.
43 * Also, to reduce space, should ifdef the individual cases if MINIMIZE=1.
46 MY(set_arch_mach
) (abfd
, machtype
)
50 enum bfd_architecture arch
;
53 /* Determine the architecture and machine type of the object file. */
69 arch
= bfd_arch_sparc
;
99 arch
= bfd_arch_obscure
;
103 bfd_set_arch_mach(abfd
, arch
, machine
);
106 /* Determine the size of a relocation entry, based on the architecture */
108 MY(choose_reloc_size
) (abfd
)
111 switch (bfd_get_arch(abfd
)) {
115 obj_reloc_entry_size (abfd
) = RELOC_EXT_SIZE
;
118 obj_reloc_entry_size (abfd
) = RELOC_STD_SIZE
;
123 /* Write an object file in BSD a.out format.
124 Section contents have already been written. We write the
125 file header, symbols, and relocation. */
128 MY(write_object_contents
) (abfd
)
131 struct external_exec exec_bytes
;
132 struct internal_exec
*execp
= exec_hdr (abfd
);
134 /* Magic number, maestro, please! */
135 switch (bfd_get_arch(abfd
)) {
137 switch (bfd_get_mach(abfd
)) {
139 N_SET_MACHTYPE(*execp
, M_68010
);
143 N_SET_MACHTYPE(*execp
, M_68020
);
148 N_SET_MACHTYPE(*execp
, M_SPARC
);
151 N_SET_MACHTYPE(*execp
, M_386
);
154 N_SET_MACHTYPE(*execp
, M_29K
);
157 switch (bfd_get_mach(abfd
)) {
160 N_SET_MACHTYPE(*execp
, M_MIPS2
);
163 N_SET_MACHTYPE(*execp
, M_MIPS1
);
168 N_SET_MACHTYPE(*execp
, M_UNKNOWN
);
171 MY(choose_reloc_size
)(abfd
);
173 WRITE_HEADERS(abfd
, execp
);
179 * MIPS relocation types.
181 #define MIPS_RELOC_32 0
182 #define MIPS_RELOC_JMP 1
183 #define MIPS_RELOC_WDISP16 2
184 #define MIPS_RELOC_HI16 3
185 #define MIPS_RELOC_HI16_S 4
186 #define MIPS_RELOC_LO16 5
189 * This is only called when performing a BFD_RELOC_HI16_S relocation.
190 * We need to see if bit 15 is set in the result. If it is, we add
191 * 0x10000 and continue normally. This will compensate for the sign extension
192 * when the low bits are added at run time.
194 bfd_reloc_status_type
195 mips_fix_hi16_s (abfd
,reloc_entry
,symbol
,data
,input_section
,output_bfd
)
197 arelent
*reloc_entry
;
198 struct symbol_cache_entry
*symbol
;
200 asection
*input_section
;
205 /* If this is a partial relocation, just continue. */
206 if (output_bfd
!= (bfd
*)NULL
)
207 return bfd_reloc_continue
;
210 * Work out which section the relocation is targetted at and the
211 * initial relocation command value.
213 if (symbol
->section
== &bfd_com_section
)
216 relocation
= symbol
->value
;
218 relocation
+= symbol
->section
->output_section
->vma
;
219 relocation
+= symbol
->section
->output_offset
;
220 relocation
+= reloc_entry
->addend
;
222 if (relocation
& 0x8000)
223 reloc_entry
->addend
+= 0x10000;
225 return bfd_reloc_continue
;
228 static reloc_howto_type mips_howto_table_ext
[] = {
229 MIPS_RELOC_32
, 0, 2, 32, false, 0, true, true, 0,
230 "32", false, 0, 0xffffffff, false,
231 MIPS_RELOC_JMP
, 2, 2, 26, false, 0, false, true, 0,
232 "MIPS_JMP", false, 0, 0x03ffffff, false,
233 MIPS_RELOC_WDISP16
, 2, 1, 16, true, 0, false, true, 0,
234 "WDISP16", false, 0, 0x0000ffff, false,
235 MIPS_RELOC_HI16
, 16, 1, 16, false, 0, false, true, 0,
236 "HI16", false, 0, 0x0000ffff, false,
237 MIPS_RELOC_HI16_S
, 16, 1, 16, false, 0, false, true, mips_fix_hi16_s
,
238 "HI16_S", false, 0, 0x0000ffff, false,
239 MIPS_RELOC_LO16
, 0, 1, 16, false, 0, false, true, 0,
240 "LO16", false, 0, 0x0000ffff, false,
243 static reloc_howto_type
*
244 MY(reloc_howto_type_lookup
) (abfd
, code
)
246 bfd_reloc_code_real_type code
;
248 extern reloc_howto_type
NAME(aout
,ext_howto_table
)[];
250 switch (bfd_get_arch (abfd
))
257 #define IDX(i,j) case i: return &NAME(aout,ext_howto_table)[j]
258 IDX (BFD_RELOC_CTOR
, 2);
259 IDX (BFD_RELOC_32
, 2);
260 IDX (BFD_RELOC_HI22
, 8);
261 IDX (BFD_RELOC_LO10
, 11);
262 IDX (BFD_RELOC_32_PCREL_S2
, 6);
268 return (&mips_howto_table_ext
[MIPS_RELOC_32
]);
269 case BFD_RELOC_MIPS_JMP
:
270 return (&mips_howto_table_ext
[MIPS_RELOC_JMP
]);
271 case BFD_RELOC_16_PCREL_S2
:
272 return (&mips_howto_table_ext
[MIPS_RELOC_WDISP16
]);
274 return (&mips_howto_table_ext
[MIPS_RELOC_HI16
]);
275 case BFD_RELOC_HI16_S
:
276 return (&mips_howto_table_ext
[MIPS_RELOC_HI16_S
]);
278 return (&mips_howto_table_ext
[MIPS_RELOC_LO16
]);
288 * This is just like the standard aoutx.h version but we need to do our
289 * own mapping of external reloc type values to howto entries.
292 MY(canonicalize_reloc
)(abfd
, section
, relptr
, symbols
)
298 arelent
*tblptr
= section
->relocation
;
299 unsigned int count
, c
;
300 extern reloc_howto_type
NAME(aout
,ext_howto_table
)[];
302 /* If we have already read in the relocation table, return the values. */
303 if (section
->flags
& SEC_CONSTRUCTOR
) {
304 arelent_chain
*chain
= section
->constructor_chain
;
306 for (count
= 0; count
< section
->reloc_count
; count
++) {
307 *relptr
++ = &chain
->relent
;
311 return section
->reloc_count
;
313 if (tblptr
&& section
->reloc_count
) {
314 for (count
= 0; count
++ < section
->reloc_count
;)
315 *relptr
++ = tblptr
++;
317 return section
->reloc_count
;
320 if (!NAME(aout
,slurp_reloc_table
)(abfd
, section
, symbols
))
322 tblptr
= section
->relocation
;
326 /* fix up howto entries */
327 for (count
= 0; count
++ < section
->reloc_count
;)
329 c
= tblptr
->howto
- NAME(aout
,ext_howto_table
);
330 tblptr
->howto
= &mips_howto_table_ext
[c
];
332 *relptr
++ = tblptr
++;
335 return section
->reloc_count
;
338 static CONST
struct aout_backend_data
MY(backend_data
) = {
339 0, /* zmagic contiguous */
340 1, /* text incl header */
341 PAGE_SIZE
, /* text vma */
343 0, /* text size includes exec header */
346 bfd_target aout_mips_little_vec
=
348 "aout-mips-little", /* name */
349 bfd_target_aout_flavour
,
350 false, /* target byte order (little) */
351 false, /* target headers byte order (little) */
352 (HAS_RELOC
| EXEC_P
| /* object flags */
353 HAS_LINENO
| HAS_DEBUG
|
354 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
355 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
356 MY_symbol_leading_char
,
357 ' ', /* ar_pad_char */
358 15, /* ar_max_namelen */
359 1, /* minimum alignment */
360 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* data */
361 _do_getl64
, _do_putl64
, _do_getl32
, _do_putl32
, _do_getl16
, _do_putl16
, /* hdrs */
362 {_bfd_dummy_target
, MY_object_p
, /* bfd_check_format */
363 bfd_generic_archive_p
, MY_core_file_p
},
364 {bfd_false
, MY_mkobject
, /* bfd_set_format */
365 _bfd_generic_mkarchive
, bfd_false
},
366 {bfd_false
, MY_write_object_contents
, /* bfd_write_contents */
367 _bfd_write_archive_contents
, bfd_false
},
369 MY_core_file_failing_command
,
370 MY_core_file_failing_signal
,
371 MY_core_file_matches_executable_p
,
373 MY_slurp_extended_name_table
,
376 MY_close_and_cleanup
,
377 MY_set_section_contents
,
378 MY_get_section_contents
,
380 MY_get_symtab_upper_bound
,
382 MY_get_reloc_upper_bound
,
383 MY_canonicalize_reloc
,
384 MY_make_empty_symbol
,
388 MY_openr_next_archived_file
,
389 MY_find_nearest_line
,
390 MY_generic_stat_arch_elt
,
392 MY_bfd_debug_info_start
,
393 MY_bfd_debug_info_end
,
394 MY_bfd_debug_info_accumulate
,
395 bfd_generic_get_relocated_section_contents
,
396 bfd_generic_relax_section
,
397 bfd_generic_seclet_link
,
398 MY_reloc_howto_type_lookup
,
399 MY_make_debug_symbol
,
400 (PTR
) MY_backend_data
,
403 bfd_target aout_mips_big_vec
=
405 "aout-mips-big", /* name */
406 bfd_target_aout_flavour
,
407 true, /* target byte order (big) */
408 true, /* target headers byte order (big) */
409 (HAS_RELOC
| EXEC_P
| /* object flags */
410 HAS_LINENO
| HAS_DEBUG
|
411 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
412 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
413 MY_symbol_leading_char
,
414 ' ', /* ar_pad_char */
415 15, /* ar_max_namelen */
416 1, /* minimum alignment */
417 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* data */
418 _do_getb64
, _do_putb64
, _do_getb32
, _do_putb32
, _do_getb16
, _do_putb16
, /* hdrs */
419 {_bfd_dummy_target
, MY_object_p
, /* bfd_check_format */
420 bfd_generic_archive_p
, MY_core_file_p
},
421 {bfd_false
, MY_mkobject
, /* bfd_set_format */
422 _bfd_generic_mkarchive
, bfd_false
},
423 {bfd_false
, MY_write_object_contents
, /* bfd_write_contents */
424 _bfd_write_archive_contents
, bfd_false
},
426 MY_core_file_failing_command
,
427 MY_core_file_failing_signal
,
428 MY_core_file_matches_executable_p
,
430 MY_slurp_extended_name_table
,
433 MY_close_and_cleanup
,
434 MY_set_section_contents
,
435 MY_get_section_contents
,
437 MY_get_symtab_upper_bound
,
439 MY_get_reloc_upper_bound
,
440 MY_canonicalize_reloc
,
441 MY_make_empty_symbol
,
445 MY_openr_next_archived_file
,
446 MY_find_nearest_line
,
447 MY_generic_stat_arch_elt
,
449 MY_bfd_debug_info_start
,
450 MY_bfd_debug_info_end
,
451 MY_bfd_debug_info_accumulate
,
452 bfd_generic_get_relocated_section_contents
,
453 bfd_generic_relax_section
,
454 bfd_generic_seclet_link
,
455 MY_reloc_howto_type_lookup
,
456 MY_make_debug_symbol
,
457 (PTR
) MY_backend_data
,