List the known things that are currently sanitized away. (Sanitize
[deliverable/binutils-gdb.git] / bfd / aout-mipsbsd.c
CommitLineData
796dc40d
PB
1<<<<<<< 1.3 is dead >>>>>>>
2#define BYTES_IN_WORD 4
3#define ARCH 32
4/* #define ENTRY_CAN_BE_ZERO */
5#define N_HEADER_IN_TEXT(x) 1
6#define N_SHARED_LIB(x) 0
7#define N_TXTADDR(x) \
8 (N_MAGIC(x) != ZMAGIC ? (x).a_entry : /* object file or NMAGIC */\
9 TEXT_START_ADDR + EXEC_BYTES_SIZE /* no padding */\
10 )
11#define N_DATADDR(x) (N_TXTADDR(x)+N_TXTSIZE(x))
12#define TEXT_START_ADDR 4096
13#define PAGE_SIZE 4096
14#define SEGMENT_SIZE PAGE_SIZE
15#define DEFAULT_ARCH bfd_arch_mips
16#define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \
17 || (mtype) == M_MIPS1 || (mtype) == M_MIPS2)
18#define MY_symbol_leading_char '\0'
19
20#define MY(OP) CAT(mipsbsd_,OP)
21
22#include "bfd.h"
23#include "sysdep.h"
24#include "libbfd.h"
25#include "libaout.h"
26
27#define SET_ARCH_MACH(ABFD, EXEC) \
28 MY(set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
29 MY(choose_reloc_size)(ABFD);
30void MY(set_arch_mach) PARAMS ((bfd *abfd, int machtype));
31static void MY(choose_reloc_size) PARAMS ((bfd *abfd));
32
33#define MY_write_object_contents MY(write_object_contents)
34static boolean MY(write_object_contents) PARAMS ((bfd *abfd));
35
36#define MY_reloc_howto_type_lookup MY(reloc_howto_type_lookup)
37#define MY_canonicalize_reloc MY(canonicalize_reloc)
38
39#define MY_backend_data &MY(backend_data)
40#define MY_BFD_TARGET
41
42#include "aout-target.h"
43
44/*
45 * These really should be common to all BSD systems.
46 * Also, to reduce space, should ifdef the individual cases if MINIMIZE=1.
47 */
48void
49MY(set_arch_mach) (abfd, machtype)
50 bfd *abfd;
51 int machtype;
52{
53 enum bfd_architecture arch;
54 long machine;
55
56 /* Determine the architecture and machine type of the object file. */
57 switch (machtype) {
58
59 case M_68010:
60 case M_HP200:
61 arch = bfd_arch_m68k;
62 machine = 68010;
63 break;
64
65 case M_68020:
66 case M_HP300:
67 arch = bfd_arch_m68k;
68 machine = 68020;
69 break;
70
71 case M_SPARC:
72 arch = bfd_arch_sparc;
73 machine = 0;
74 break;
75
76 case M_386:
77 arch = bfd_arch_i386;
78 machine = 0;
79 break;
80
81 case M_29K:
82 arch = bfd_arch_a29k;
83 machine = 0;
84 break;
85
86 case M_HPUX:
87 arch = bfd_arch_m68k;
88 machine = 0;
89 break;
90
91 case M_MIPS1:
92 arch = bfd_arch_mips;
93 machine = 3000;
94 break;
95
96 case M_MIPS2:
97 arch = bfd_arch_mips;
98 machine = 4000;
99 break;
100
101 default:
102 arch = bfd_arch_obscure;
103 machine = 0;
104 break;
105 }
106 bfd_set_arch_mach(abfd, arch, machine);
107}
108
109/* Determine the size of a relocation entry, based on the architecture */
110static void
111MY(choose_reloc_size) (abfd)
112 bfd *abfd;
113{
114 switch (bfd_get_arch(abfd)) {
115 case bfd_arch_sparc:
116 case bfd_arch_a29k:
117 case bfd_arch_mips:
118 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
119 break;
120 default:
121 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
122 break;
123 }
124}
125
126/* Write an object file in BSD a.out format.
127 Section contents have already been written. We write the
128 file header, symbols, and relocation. */
129
130static boolean
131MY(write_object_contents) (abfd)
132 bfd *abfd;
133{
134 struct external_exec exec_bytes;
135 struct internal_exec *execp = exec_hdr (abfd);
136
137 /* Magic number, maestro, please! */
138 switch (bfd_get_arch(abfd)) {
139 case bfd_arch_m68k:
140 switch (bfd_get_mach(abfd)) {
141 case 68010:
142 N_SET_MACHTYPE(*execp, M_68010);
143 break;
144 default:
145 case 68020:
146 N_SET_MACHTYPE(*execp, M_68020);
147 break;
148 }
149 break;
150 case bfd_arch_sparc:
151 N_SET_MACHTYPE(*execp, M_SPARC);
152 break;
153 case bfd_arch_i386:
154 N_SET_MACHTYPE(*execp, M_386);
155 break;
156 case bfd_arch_a29k:
157 N_SET_MACHTYPE(*execp, M_29K);
158 break;
159 case bfd_arch_mips:
160 switch (bfd_get_mach(abfd)) {
161 case 4000:
162 case 6000:
163 N_SET_MACHTYPE(*execp, M_MIPS2);
164 break;
165 default:
166 N_SET_MACHTYPE(*execp, M_MIPS1);
167 break;
168 }
169 break;
170 default:
171 N_SET_MACHTYPE(*execp, M_UNKNOWN);
172 }
173
174 MY(choose_reloc_size)(abfd);
175
176 WRITE_HEADERS(abfd, execp);
177
178 return true;
179}
180
181/*
182 * MIPS relocation types.
183 */
184#define MIPS_RELOC_32 0
185#define MIPS_RELOC_JMP 1
186#define MIPS_RELOC_WDISP16 2
187#define MIPS_RELOC_HI16 3
188#define MIPS_RELOC_HI16_S 4
189#define MIPS_RELOC_LO16 5
190
191/*
192 * This is only called when performing a BFD_RELOC_HI16_S relocation.
193 * We need to see if bit 15 is set in the result. If it is, we add
194 * 0x10000 and continue normally. This will compensate for the sign extension
195 * when the low bits are added at run time.
196 */
197bfd_reloc_status_type
198mips_fix_hi16_s (abfd,reloc_entry,symbol,data,input_section,output_bfd)
199 bfd *abfd;
200 arelent *reloc_entry;
201 struct symbol_cache_entry *symbol;
202 PTR data;
203 asection *input_section;
204 bfd *output_bfd;
205{
206 bfd_vma relocation;
207
208 /* If this is a partial relocation, just continue. */
209 if (output_bfd != (bfd *)NULL)
210 return bfd_reloc_continue;
211
212 /*
213 * Work out which section the relocation is targetted at and the
214 * initial relocation command value.
215 */
216 if (symbol->section == &bfd_com_section)
217 relocation = 0;
218 else
219 relocation = symbol->value;
220
221 relocation += symbol->section->output_section->vma;
222 relocation += symbol->section->output_offset;
223 relocation += reloc_entry->addend;
224
225 if (relocation & 0x8000)
226 reloc_entry->addend += 0x10000;
227
228 return bfd_reloc_continue;
229}
230
231static reloc_howto_type mips_howto_table_ext[] = {
232 MIPS_RELOC_32, 0, 2, 32, false, 0, true, true, 0,
233 "32", false, 0, 0xffffffff, false,
234 MIPS_RELOC_JMP, 2, 2, 26, false, 0, false, true, 0,
235 "MIPS_JMP", false, 0, 0x03ffffff, false,
236 MIPS_RELOC_WDISP16, 2, 1, 16, true, 0, false, true, 0,
237 "WDISP16", false, 0, 0x0000ffff, false,
238 MIPS_RELOC_HI16, 16, 1, 16, false, 0, false, true, 0,
239 "HI16", false, 0, 0x0000ffff, false,
240 MIPS_RELOC_HI16_S, 16, 1, 16, false, 0, false, true, mips_fix_hi16_s,
241 "HI16_S", false, 0, 0x0000ffff, false,
242 MIPS_RELOC_LO16, 0, 1, 16, false, 0, false, true, 0,
243 "LO16", false, 0, 0x0000ffff, false,
244};
245
246static reloc_howto_type *
247MY(reloc_howto_type_lookup) (abfd, code)
248 bfd *abfd;
249 bfd_reloc_code_real_type code;
250{
251 extern reloc_howto_type NAME(aout,ext_howto_table)[];
252
253 switch (bfd_get_arch (abfd))
254 {
255 case bfd_arch_sparc:
256 switch (code)
257 {
258 default:
259 return 0;
260#define IDX(i,j) case i: return &NAME(aout,ext_howto_table)[j]
261 IDX (BFD_RELOC_CTOR, 2);
262 IDX (BFD_RELOC_32, 2);
263 IDX (BFD_RELOC_HI22, 8);
264 IDX (BFD_RELOC_LO10, 11);
265 IDX (BFD_RELOC_32_PCREL_S2, 6);
266 }
267 case bfd_arch_mips:
268 switch (code)
269 {
270 case BFD_RELOC_32:
271 return (&mips_howto_table_ext[MIPS_RELOC_32]);
272 case BFD_RELOC_MIPS_JMP:
273 return (&mips_howto_table_ext[MIPS_RELOC_JMP]);
274 case BFD_RELOC_16_PCREL_S2:
275 return (&mips_howto_table_ext[MIPS_RELOC_WDISP16]);
276 case BFD_RELOC_HI16:
277 return (&mips_howto_table_ext[MIPS_RELOC_HI16]);
278 case BFD_RELOC_HI16_S:
279 return (&mips_howto_table_ext[MIPS_RELOC_HI16_S]);
280 case BFD_RELOC_LO16:
281 return (&mips_howto_table_ext[MIPS_RELOC_LO16]);
282 default:
283 return 0;
284 }
285 default:
286 return 0;
287 }
288}
289
290/*
291 * This is just like the standard aoutx.h version but we need to do our
292 * own mapping of external reloc type values to howto entries.
293 */
294unsigned int
295MY(canonicalize_reloc)(abfd, section, relptr, symbols)
296 bfd *abfd;
297 sec_ptr section;
298 arelent **relptr;
299 asymbol **symbols;
300{
301 arelent *tblptr = section->relocation;
302 unsigned int count, c;
303 extern reloc_howto_type NAME(aout,ext_howto_table)[];
304
305 /* If we have already read in the relocation table, return the values. */
306 if (section->flags & SEC_CONSTRUCTOR) {
307 arelent_chain *chain = section->constructor_chain;
308
309 for (count = 0; count < section->reloc_count; count++) {
310 *relptr++ = &chain->relent;
311 chain = chain->next;
312 }
313 *relptr = 0;
314 return section->reloc_count;
315 }
316 if (tblptr && section->reloc_count) {
317 for (count = 0; count++ < section->reloc_count;)
318 *relptr++ = tblptr++;
319 *relptr = 0;
320 return section->reloc_count;
321 }
322
323 if (!NAME(aout,slurp_reloc_table)(abfd, section, symbols))
324 return 0;
325 tblptr = section->relocation;
326 if (!tblptr)
327 return 0;
328
329 /* fix up howto entries */
330 for (count = 0; count++ < section->reloc_count;)
331 {
332 c = tblptr->howto - NAME(aout,ext_howto_table);
333 tblptr->howto = &mips_howto_table_ext[c];
334
335 *relptr++ = tblptr++;
336 }
337 *relptr = 0;
338 return section->reloc_count;
339}
340
341static CONST struct aout_backend_data MY(backend_data) = {
342 0, /* zmagic contiguous */
343 1, /* text incl header */
344 PAGE_SIZE, /* text vma */
345 MY_set_sizes,
346 0, /* text size includes exec header */
347};
348
349bfd_target aout_mips_little_vec =
350{
351 "aout-mips-little", /* name */
352 bfd_target_aout_flavour,
353 false, /* target byte order (little) */
354 false, /* target headers byte order (little) */
355 (HAS_RELOC | EXEC_P | /* object flags */
356 HAS_LINENO | HAS_DEBUG |
357 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
358 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
359 MY_symbol_leading_char,
360 ' ', /* ar_pad_char */
361 15, /* ar_max_namelen */
362 1, /* minimum alignment */
363 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
364 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
365 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
366 bfd_generic_archive_p, MY_core_file_p},
367 {bfd_false, MY_mkobject, /* bfd_set_format */
368 _bfd_generic_mkarchive, bfd_false},
369 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
370 _bfd_write_archive_contents, bfd_false},
371
372 MY_core_file_failing_command,
373 MY_core_file_failing_signal,
374 MY_core_file_matches_executable_p,
375 MY_slurp_armap,
376 MY_slurp_extended_name_table,
377 MY_truncate_arname,
378 MY_write_armap,
379 MY_close_and_cleanup,
380 MY_set_section_contents,
381 MY_get_section_contents,
382 MY_new_section_hook,
383 MY_get_symtab_upper_bound,
384 MY_get_symtab,
385 MY_get_reloc_upper_bound,
386 MY_canonicalize_reloc,
387 MY_make_empty_symbol,
388 MY_print_symbol,
389 MY_get_lineno,
390 MY_set_arch_mach,
391 MY_openr_next_archived_file,
392 MY_find_nearest_line,
393 MY_generic_stat_arch_elt,
394 MY_sizeof_headers,
395 MY_bfd_debug_info_start,
396 MY_bfd_debug_info_end,
397 MY_bfd_debug_info_accumulate,
398 bfd_generic_get_relocated_section_contents,
399 bfd_generic_relax_section,
400 bfd_generic_seclet_link,
401 MY_reloc_howto_type_lookup,
402 MY_make_debug_symbol,
403 (PTR) MY_backend_data,
404};
405
406bfd_target aout_mips_big_vec =
407{
408 "aout-mips-big", /* name */
409 bfd_target_aout_flavour,
410 true, /* target byte order (big) */
411 true, /* target headers byte order (big) */
412 (HAS_RELOC | EXEC_P | /* object flags */
413 HAS_LINENO | HAS_DEBUG |
414 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
415 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
416 MY_symbol_leading_char,
417 ' ', /* ar_pad_char */
418 15, /* ar_max_namelen */
419 1, /* minimum alignment */
420 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
421 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
422 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
423 bfd_generic_archive_p, MY_core_file_p},
424 {bfd_false, MY_mkobject, /* bfd_set_format */
425 _bfd_generic_mkarchive, bfd_false},
426 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
427 _bfd_write_archive_contents, bfd_false},
428
429 MY_core_file_failing_command,
430 MY_core_file_failing_signal,
431 MY_core_file_matches_executable_p,
432 MY_slurp_armap,
433 MY_slurp_extended_name_table,
434 MY_truncate_arname,
435 MY_write_armap,
436 MY_close_and_cleanup,
437 MY_set_section_contents,
438 MY_get_section_contents,
439 MY_new_section_hook,
440 MY_get_symtab_upper_bound,
441 MY_get_symtab,
442 MY_get_reloc_upper_bound,
443 MY_canonicalize_reloc,
444 MY_make_empty_symbol,
445 MY_print_symbol,
446 MY_get_lineno,
447 MY_set_arch_mach,
448 MY_openr_next_archived_file,
449 MY_find_nearest_line,
450 MY_generic_stat_arch_elt,
451 MY_sizeof_headers,
452 MY_bfd_debug_info_start,
453 MY_bfd_debug_info_end,
454 MY_bfd_debug_info_accumulate,
455 bfd_generic_get_relocated_section_contents,
456 bfd_generic_relax_section,
457 bfd_generic_seclet_link,
458 MY_reloc_howto_type_lookup,
459 MY_make_debug_symbol,
460 (PTR) MY_backend_data,
461};
This page took 0.039531 seconds and 4 git commands to generate.