Minor stylistic cleanup; eliminated more contractions, eliminated
[deliverable/binutils-gdb.git] / bfd / aout-mipsbsd.c
1 #define BYTES_IN_WORD 4
2 #define ARCH 32
3 /* #define ENTRY_CAN_BE_ZERO */
4 #define N_HEADER_IN_TEXT(x) 1
5 #define N_SHARED_LIB(x) 0
6 #define N_TXTADDR(x) \
7 (N_MAGIC(x) != ZMAGIC ? (x).a_entry : /* object file or NMAGIC */\
8 TEXT_START_ADDR + EXEC_BYTES_SIZE /* no padding */\
9 )
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'
16
17 #define MY(OP) CAT(mipsbsd_,OP)
18
19 #include "bfd.h"
20 #include "sysdep.h"
21 #include "libbfd.h"
22 #include "libaout.h"
23
24 #define SET_ARCH_MACH(ABFD, EXEC) \
25 MY(set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
26 MY(choose_reloc_size)(ABFD);
27 void DEFUN(MY(set_arch_mach), (abfd, machtype),
28 bfd *abfd AND int machtype);
29 static void DEFUN(MY(choose_reloc_size),(abfd),bfd *abfd);
30
31 #define MY_write_object_contents MY(write_object_contents)
32 static boolean DEFUN(MY(write_object_contents), (abfd), bfd *abfd);
33
34 #define MY_reloc_howto_type_lookup MY(reloc_howto_type_lookup)
35 #define MY_canonicalize_reloc MY(canonicalize_reloc)
36
37 #define MY_backend_data &MY(backend_data)
38 #define MY_BFD_TARGET
39
40 #include "aout-target.h"
41
42 /*
43 * These really should be common to all BSD systems.
44 * Also, to reduce space, should ifdef the individual cases if MINIMIZE=1.
45 */
46 void
47 DEFUN(MY(set_arch_mach), (abfd, machtype),
48 bfd *abfd AND int machtype)
49 {
50 enum bfd_architecture arch;
51 long machine;
52
53 /* Determine the architecture and machine type of the object file. */
54 switch (machtype) {
55
56 case M_68010:
57 case M_HP200:
58 arch = bfd_arch_m68k;
59 machine = 68010;
60 break;
61
62 case M_68020:
63 case M_HP300:
64 arch = bfd_arch_m68k;
65 machine = 68020;
66 break;
67
68 case M_SPARC:
69 arch = bfd_arch_sparc;
70 machine = 0;
71 break;
72
73 case M_386:
74 arch = bfd_arch_i386;
75 machine = 0;
76 break;
77
78 case M_29K:
79 arch = bfd_arch_a29k;
80 machine = 0;
81 break;
82
83 case M_HPUX:
84 arch = bfd_arch_m68k;
85 machine = 0;
86 break;
87
88 case M_MIPS1:
89 arch = bfd_arch_mips;
90 machine = 3000;
91 break;
92
93 case M_MIPS2:
94 arch = bfd_arch_mips;
95 machine = 4000;
96 break;
97
98 default:
99 arch = bfd_arch_obscure;
100 machine = 0;
101 break;
102 }
103 bfd_set_arch_mach(abfd, arch, machine);
104 }
105
106 /* Determine the size of a relocation entry, based on the architecture */
107 static void
108 DEFUN(MY(choose_reloc_size),(abfd),
109 bfd *abfd)
110 {
111 switch (bfd_get_arch(abfd)) {
112 case bfd_arch_sparc:
113 case bfd_arch_a29k:
114 case bfd_arch_mips:
115 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
116 break;
117 default:
118 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
119 break;
120 }
121 }
122
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. */
126
127 static boolean
128 DEFUN(MY(write_object_contents), (abfd),
129 bfd *abfd)
130 {
131 struct external_exec exec_bytes;
132 struct internal_exec *execp = exec_hdr (abfd);
133
134 /* Magic number, maestro, please! */
135 switch (bfd_get_arch(abfd)) {
136 case bfd_arch_m68k:
137 switch (bfd_get_mach(abfd)) {
138 case 68010:
139 N_SET_MACHTYPE(*execp, M_68010);
140 break;
141 default:
142 case 68020:
143 N_SET_MACHTYPE(*execp, M_68020);
144 break;
145 }
146 break;
147 case bfd_arch_sparc:
148 N_SET_MACHTYPE(*execp, M_SPARC);
149 break;
150 case bfd_arch_i386:
151 N_SET_MACHTYPE(*execp, M_386);
152 break;
153 case bfd_arch_a29k:
154 N_SET_MACHTYPE(*execp, M_29K);
155 break;
156 case bfd_arch_mips:
157 switch (bfd_get_mach(abfd)) {
158 case 4000:
159 case 6000:
160 N_SET_MACHTYPE(*execp, M_MIPS2);
161 break;
162 default:
163 N_SET_MACHTYPE(*execp, M_MIPS1);
164 break;
165 }
166 break;
167 default:
168 N_SET_MACHTYPE(*execp, M_UNKNOWN);
169 }
170
171 MY(choose_reloc_size)(abfd);
172
173 WRITE_HEADERS(abfd, execp);
174
175 return true;
176 }
177
178 /*
179 * MIPS relocation types.
180 */
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
187
188 /*
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.
193 */
194 bfd_reloc_status_type
195 DEFUN(mips_fix_hi16_s, (abfd,reloc_entry,symbol,data,input_section,output_bfd),
196 bfd *abfd AND
197 arelent *reloc_entry AND
198 struct symbol_cache_entry *symbol AND
199 PTR data AND
200 asection *input_section AND
201 bfd *output_bfd)
202 {
203 bfd_vma relocation;
204
205 /* If this is a partial relocation, just continue. */
206 if (output_bfd != (bfd *)NULL)
207 return bfd_reloc_continue;
208
209 /*
210 * Work out which section the relocation is targetted at and the
211 * initial relocation command value.
212 */
213 if (symbol->section == &bfd_com_section)
214 relocation = 0;
215 else
216 relocation = symbol->value;
217
218 relocation += symbol->section->output_section->vma;
219 relocation += symbol->section->output_offset;
220 relocation += reloc_entry->addend;
221
222 if (relocation & 0x8000)
223 reloc_entry->addend += 0x10000;
224
225 return bfd_reloc_continue;
226 }
227
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,
241 };
242
243 static reloc_howto_type *
244 MY(reloc_howto_type_lookup) (abfd, code)
245 bfd *abfd;
246 bfd_reloc_code_real_type code;
247 {
248 extern reloc_howto_type NAME(aout,ext_howto_table)[];
249
250 switch (bfd_get_arch (abfd))
251 {
252 case bfd_arch_sparc:
253 switch (code)
254 {
255 default:
256 return 0;
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);
263 }
264 case bfd_arch_mips:
265 switch (code)
266 {
267 case BFD_RELOC_32:
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]);
273 case BFD_RELOC_HI16:
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]);
277 case BFD_RELOC_LO16:
278 return (&mips_howto_table_ext[MIPS_RELOC_LO16]);
279 default:
280 return 0;
281 }
282 default:
283 return 0;
284 }
285 }
286
287 /*
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.
290 */
291 unsigned int
292 MY(canonicalize_reloc)(abfd, section, relptr, symbols)
293 bfd *abfd;
294 sec_ptr section;
295 arelent **relptr;
296 asymbol **symbols;
297 {
298 arelent *tblptr = section->relocation;
299 unsigned int count, c;
300 extern reloc_howto_type NAME(aout,ext_howto_table)[];
301
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;
305
306 for (count = 0; count < section->reloc_count; count++) {
307 *relptr++ = &chain->relent;
308 chain = chain->next;
309 }
310 *relptr = 0;
311 return section->reloc_count;
312 }
313 if (tblptr && section->reloc_count) {
314 for (count = 0; count++ < section->reloc_count;)
315 *relptr++ = tblptr++;
316 *relptr = 0;
317 return section->reloc_count;
318 }
319
320 if (!NAME(aout,slurp_reloc_table)(abfd, section, symbols))
321 return 0;
322 tblptr = section->relocation;
323 if (!tblptr)
324 return 0;
325
326 /* fix up howto entries */
327 for (count = 0; count++ < section->reloc_count;)
328 {
329 c = tblptr->howto - NAME(aout,ext_howto_table);
330 tblptr->howto = &mips_howto_table_ext[c];
331
332 *relptr++ = tblptr++;
333 }
334 *relptr = 0;
335 return section->reloc_count;
336 }
337
338 static CONST struct aout_backend_data MY(backend_data) = {
339 0, /* zmagic contiguous */
340 1, /* text incl header */
341 PAGE_SIZE, /* text vma */
342 MY_set_sizes,
343 0, /* text size includes exec header */
344 };
345
346 bfd_target aout_mips_little_vec =
347 {
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},
368
369 MY_core_file_failing_command,
370 MY_core_file_failing_signal,
371 MY_core_file_matches_executable_p,
372 MY_slurp_armap,
373 MY_slurp_extended_name_table,
374 MY_truncate_arname,
375 MY_write_armap,
376 MY_close_and_cleanup,
377 MY_set_section_contents,
378 MY_get_section_contents,
379 MY_new_section_hook,
380 MY_get_symtab_upper_bound,
381 MY_get_symtab,
382 MY_get_reloc_upper_bound,
383 MY_canonicalize_reloc,
384 MY_make_empty_symbol,
385 MY_print_symbol,
386 MY_get_lineno,
387 MY_set_arch_mach,
388 MY_openr_next_archived_file,
389 MY_find_nearest_line,
390 MY_generic_stat_arch_elt,
391 MY_sizeof_headers,
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 MY_reloc_howto_type_lookup,
398 MY_make_debug_symbol,
399 (PTR) MY_backend_data,
400 };
401
402 bfd_target aout_mips_big_vec =
403 {
404 "aout-mips-big", /* name */
405 bfd_target_aout_flavour,
406 true, /* target byte order (big) */
407 true, /* target headers byte order (big) */
408 (HAS_RELOC | EXEC_P | /* object flags */
409 HAS_LINENO | HAS_DEBUG |
410 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
411 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
412 MY_symbol_leading_char,
413 ' ', /* ar_pad_char */
414 15, /* ar_max_namelen */
415 1, /* minimum alignment */
416 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
417 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
418 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
419 bfd_generic_archive_p, MY_core_file_p},
420 {bfd_false, MY_mkobject, /* bfd_set_format */
421 _bfd_generic_mkarchive, bfd_false},
422 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
423 _bfd_write_archive_contents, bfd_false},
424
425 MY_core_file_failing_command,
426 MY_core_file_failing_signal,
427 MY_core_file_matches_executable_p,
428 MY_slurp_armap,
429 MY_slurp_extended_name_table,
430 MY_truncate_arname,
431 MY_write_armap,
432 MY_close_and_cleanup,
433 MY_set_section_contents,
434 MY_get_section_contents,
435 MY_new_section_hook,
436 MY_get_symtab_upper_bound,
437 MY_get_symtab,
438 MY_get_reloc_upper_bound,
439 MY_canonicalize_reloc,
440 MY_make_empty_symbol,
441 MY_print_symbol,
442 MY_get_lineno,
443 MY_set_arch_mach,
444 MY_openr_next_archived_file,
445 MY_find_nearest_line,
446 MY_generic_stat_arch_elt,
447 MY_sizeof_headers,
448 MY_bfd_debug_info_start,
449 MY_bfd_debug_info_end,
450 MY_bfd_debug_info_accumulate,
451 bfd_generic_get_relocated_section_contents,
452 bfd_generic_relax_section,
453 MY_reloc_howto_type_lookup,
454 MY_make_debug_symbol,
455 (PTR) MY_backend_data,
456 };
This page took 0.061542 seconds and 4 git commands to generate.