1 |
/* BFD back-end for PPCbug boot records. |
/* BFD back-end for PPCbug boot records. |
2 |
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
3 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
4 |
Written by Michael Meissner, Cygnus Support, <meissner@cygnus.com> |
Written by Michael Meissner, Cygnus Support, <meissner@cygnus.com> |
5 |
|
|
87 |
a start symbol, an end symbol, and an absolute length symbol. */ |
a start symbol, an end symbol, and an absolute length symbol. */ |
88 |
#define PPCBOOT_SYMS 3 |
#define PPCBOOT_SYMS 3 |
89 |
|
|
90 |
static boolean ppcboot_mkobject PARAMS ((bfd *)); |
static bfd_boolean ppcboot_mkobject PARAMS ((bfd *)); |
91 |
static const bfd_target *ppcboot_object_p PARAMS ((bfd *)); |
static const bfd_target *ppcboot_object_p PARAMS ((bfd *)); |
92 |
static boolean ppcboot_set_arch_mach |
static bfd_boolean ppcboot_set_arch_mach |
93 |
PARAMS ((bfd *, enum bfd_architecture, unsigned long)); |
PARAMS ((bfd *, enum bfd_architecture, unsigned long)); |
94 |
static boolean ppcboot_get_section_contents |
static bfd_boolean ppcboot_get_section_contents |
95 |
PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type)); |
PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type)); |
96 |
static long ppcboot_get_symtab_upper_bound PARAMS ((bfd *)); |
static long ppcboot_get_symtab_upper_bound PARAMS ((bfd *)); |
97 |
static char *mangle_name PARAMS ((bfd *, char *)); |
static char *mangle_name PARAMS ((bfd *, char *)); |
98 |
static long ppcboot_get_symtab PARAMS ((bfd *, asymbol **)); |
static long ppcboot_canonicalize_symtab PARAMS ((bfd *, asymbol **)); |
99 |
static void ppcboot_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *)); |
static void ppcboot_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *)); |
100 |
static boolean ppcboot_set_section_contents |
static bfd_boolean ppcboot_set_section_contents |
101 |
PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type)); |
PARAMS ((bfd *, asection *, const PTR, file_ptr, bfd_size_type)); |
102 |
static int ppcboot_sizeof_headers PARAMS ((bfd *, boolean)); |
static int ppcboot_sizeof_headers PARAMS ((bfd *, bfd_boolean)); |
103 |
static boolean ppcboot_bfd_print_private_bfd_data PARAMS ((bfd *, PTR)); |
static bfd_boolean ppcboot_bfd_print_private_bfd_data PARAMS ((bfd *, PTR)); |
104 |
|
|
105 |
#define ppcboot_set_tdata(abfd, ptr) ((abfd)->tdata.any = (PTR) (ptr)) |
#define ppcboot_set_tdata(abfd, ptr) ((abfd)->tdata.any = (PTR) (ptr)) |
106 |
#define ppcboot_get_tdata(abfd) ((ppcboot_data_t *) ((abfd)->tdata.any)) |
#define ppcboot_get_tdata(abfd) ((ppcboot_data_t *) ((abfd)->tdata.any)) |
107 |
|
|
108 |
/* Create a ppcboot object. Invoked via bfd_set_format. */ |
/* Create a ppcboot object. Invoked via bfd_set_format. */ |
109 |
|
|
110 |
static boolean |
static bfd_boolean |
111 |
ppcboot_mkobject (abfd) |
ppcboot_mkobject (abfd) |
112 |
bfd *abfd; |
bfd *abfd; |
113 |
{ |
{ |
117 |
ppcboot_set_tdata (abfd, bfd_zalloc (abfd, amt)); |
ppcboot_set_tdata (abfd, bfd_zalloc (abfd, amt)); |
118 |
} |
} |
119 |
|
|
120 |
return true; |
return TRUE; |
121 |
} |
} |
122 |
|
|
123 |
|
|
124 |
/* Set the architecture to PowerPC */ |
/* Set the architecture to PowerPC */ |
125 |
static boolean |
static bfd_boolean |
126 |
ppcboot_set_arch_mach (abfd, arch, machine) |
ppcboot_set_arch_mach (abfd, arch, machine) |
127 |
bfd *abfd; |
bfd *abfd; |
128 |
enum bfd_architecture arch; |
enum bfd_architecture arch; |
132 |
arch = bfd_arch_powerpc; |
arch = bfd_arch_powerpc; |
133 |
|
|
134 |
else if (arch != bfd_arch_powerpc) |
else if (arch != bfd_arch_powerpc) |
135 |
return false; |
return FALSE; |
136 |
|
|
137 |
return bfd_default_set_arch_mach (abfd, arch, machine); |
return bfd_default_set_arch_mach (abfd, arch, machine); |
138 |
} |
} |
210 |
return NULL; |
return NULL; |
211 |
sec->flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_CODE | SEC_HAS_CONTENTS; |
sec->flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_CODE | SEC_HAS_CONTENTS; |
212 |
sec->vma = 0; |
sec->vma = 0; |
213 |
sec->_raw_size = statbuf.st_size - sizeof (ppcboot_hdr_t); |
sec->size = statbuf.st_size - sizeof (ppcboot_hdr_t); |
214 |
sec->filepos = sizeof (ppcboot_hdr_t); |
sec->filepos = sizeof (ppcboot_hdr_t); |
215 |
|
|
216 |
ppcboot_mkobject (abfd); |
ppcboot_mkobject (abfd); |
229 |
|
|
230 |
/* Get contents of the only section. */ |
/* Get contents of the only section. */ |
231 |
|
|
232 |
static boolean |
static bfd_boolean |
233 |
ppcboot_get_section_contents (abfd, section, location, offset, count) |
ppcboot_get_section_contents (abfd, section, location, offset, count) |
234 |
bfd *abfd; |
bfd *abfd; |
235 |
asection *section ATTRIBUTE_UNUSED; |
asection *section ATTRIBUTE_UNUSED; |
239 |
{ |
{ |
240 |
if (bfd_seek (abfd, offset + (file_ptr) sizeof (ppcboot_hdr_t), SEEK_SET) != 0 |
if (bfd_seek (abfd, offset + (file_ptr) sizeof (ppcboot_hdr_t), SEEK_SET) != 0 |
241 |
|| bfd_bread (location, count, abfd) != count) |
|| bfd_bread (location, count, abfd) != count) |
242 |
return false; |
return FALSE; |
243 |
return true; |
return TRUE; |
244 |
} |
} |
245 |
|
|
246 |
|
|
287 |
/* Return the symbol table. */ |
/* Return the symbol table. */ |
288 |
|
|
289 |
static long |
static long |
290 |
ppcboot_get_symtab (abfd, alocation) |
ppcboot_canonicalize_symtab (abfd, alocation) |
291 |
bfd *abfd; |
bfd *abfd; |
292 |
asymbol **alocation; |
asymbol **alocation; |
293 |
{ |
{ |
298 |
|
|
299 |
syms = (asymbol *) bfd_alloc (abfd, amt); |
syms = (asymbol *) bfd_alloc (abfd, amt); |
300 |
if (syms == NULL) |
if (syms == NULL) |
301 |
return false; |
return FALSE; |
302 |
|
|
303 |
/* Start symbol. */ |
/* Start symbol. */ |
304 |
syms[0].the_bfd = abfd; |
syms[0].the_bfd = abfd; |
311 |
/* End symbol. */ |
/* End symbol. */ |
312 |
syms[1].the_bfd = abfd; |
syms[1].the_bfd = abfd; |
313 |
syms[1].name = mangle_name (abfd, "end"); |
syms[1].name = mangle_name (abfd, "end"); |
314 |
syms[1].value = sec->_raw_size; |
syms[1].value = sec->size; |
315 |
syms[1].flags = BSF_GLOBAL; |
syms[1].flags = BSF_GLOBAL; |
316 |
syms[1].section = sec; |
syms[1].section = sec; |
317 |
syms[1].udata.p = NULL; |
syms[1].udata.p = NULL; |
319 |
/* Size symbol. */ |
/* Size symbol. */ |
320 |
syms[2].the_bfd = abfd; |
syms[2].the_bfd = abfd; |
321 |
syms[2].name = mangle_name (abfd, "size"); |
syms[2].name = mangle_name (abfd, "size"); |
322 |
syms[2].value = sec->_raw_size; |
syms[2].value = sec->size; |
323 |
syms[2].flags = BSF_GLOBAL; |
syms[2].flags = BSF_GLOBAL; |
324 |
syms[2].section = bfd_abs_section_ptr; |
syms[2].section = bfd_abs_section_ptr; |
325 |
syms[2].udata.p = NULL; |
syms[2].udata.p = NULL; |
345 |
bfd_symbol_info (symbol, ret); |
bfd_symbol_info (symbol, ret); |
346 |
} |
} |
347 |
|
|
348 |
|
#define ppcboot_bfd_is_target_special_symbol \ |
349 |
|
((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) |
350 |
#define ppcboot_bfd_is_local_label_name bfd_generic_is_local_label_name |
#define ppcboot_bfd_is_local_label_name bfd_generic_is_local_label_name |
351 |
#define ppcboot_get_lineno _bfd_nosymbols_get_lineno |
#define ppcboot_get_lineno _bfd_nosymbols_get_lineno |
352 |
#define ppcboot_find_nearest_line _bfd_nosymbols_find_nearest_line |
#define ppcboot_find_nearest_line _bfd_nosymbols_find_nearest_line |
362 |
|
|
363 |
/* Write section contents of a ppcboot file. */ |
/* Write section contents of a ppcboot file. */ |
364 |
|
|
365 |
static boolean |
static bfd_boolean |
366 |
ppcboot_set_section_contents (abfd, sec, data, offset, size) |
ppcboot_set_section_contents (abfd, sec, data, offset, size) |
367 |
bfd *abfd; |
bfd *abfd; |
368 |
asection *sec; |
asection *sec; |
369 |
PTR data; |
const PTR data; |
370 |
file_ptr offset; |
file_ptr offset; |
371 |
bfd_size_type size; |
bfd_size_type size; |
372 |
{ |
{ |
386 |
for (s = abfd->sections; s != NULL; s = s->next) |
for (s = abfd->sections; s != NULL; s = s->next) |
387 |
s->filepos = s->vma - low; |
s->filepos = s->vma - low; |
388 |
|
|
389 |
abfd->output_has_begun = true; |
abfd->output_has_begun = TRUE; |
390 |
} |
} |
391 |
|
|
392 |
return _bfd_generic_set_section_contents (abfd, sec, data, offset, size); |
return _bfd_generic_set_section_contents (abfd, sec, data, offset, size); |
396 |
static int |
static int |
397 |
ppcboot_sizeof_headers (abfd, exec) |
ppcboot_sizeof_headers (abfd, exec) |
398 |
bfd *abfd ATTRIBUTE_UNUSED; |
bfd *abfd ATTRIBUTE_UNUSED; |
399 |
boolean exec ATTRIBUTE_UNUSED; |
bfd_boolean exec ATTRIBUTE_UNUSED; |
400 |
{ |
{ |
401 |
return sizeof (ppcboot_hdr_t); |
return sizeof (ppcboot_hdr_t); |
402 |
} |
} |
404 |
|
|
405 |
/* Print out the program headers. */ |
/* Print out the program headers. */ |
406 |
|
|
407 |
static boolean |
static bfd_boolean |
408 |
ppcboot_bfd_print_private_bfd_data (abfd, farg) |
ppcboot_bfd_print_private_bfd_data (abfd, farg) |
409 |
bfd *abfd; |
bfd *abfd; |
410 |
PTR farg; |
PTR farg; |
462 |
} |
} |
463 |
|
|
464 |
fprintf (f, "\n"); |
fprintf (f, "\n"); |
465 |
return true; |
return TRUE; |
466 |
} |
} |
467 |
|
|
468 |
|
|
471 |
#define ppcboot_bfd_relax_section bfd_generic_relax_section |
#define ppcboot_bfd_relax_section bfd_generic_relax_section |
472 |
#define ppcboot_bfd_gc_sections bfd_generic_gc_sections |
#define ppcboot_bfd_gc_sections bfd_generic_gc_sections |
473 |
#define ppcboot_bfd_merge_sections bfd_generic_merge_sections |
#define ppcboot_bfd_merge_sections bfd_generic_merge_sections |
474 |
|
#define ppcboot_bfd_is_group_section bfd_generic_is_group_section |
475 |
#define ppcboot_bfd_discard_group bfd_generic_discard_group |
#define ppcboot_bfd_discard_group bfd_generic_discard_group |
476 |
|
#define ppcboot_section_already_linked \ |
477 |
|
_bfd_generic_section_already_linked |
478 |
#define ppcboot_bfd_link_hash_table_create _bfd_generic_link_hash_table_create |
#define ppcboot_bfd_link_hash_table_create _bfd_generic_link_hash_table_create |
479 |
#define ppcboot_bfd_link_hash_table_free _bfd_generic_link_hash_table_free |
#define ppcboot_bfd_link_hash_table_free _bfd_generic_link_hash_table_free |
480 |
#define ppcboot_bfd_link_add_symbols _bfd_generic_link_add_symbols |
#define ppcboot_bfd_link_add_symbols _bfd_generic_link_add_symbols |
488 |
#define ppcboot_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data |
#define ppcboot_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data |
489 |
#define ppcboot_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data |
#define ppcboot_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data |
490 |
#define ppcboot_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data |
#define ppcboot_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data |
491 |
|
#define ppcboot_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data |
492 |
#define ppcboot_bfd_set_private_flags _bfd_generic_bfd_set_private_flags |
#define ppcboot_bfd_set_private_flags _bfd_generic_bfd_set_private_flags |
493 |
#define ppcboot_bfd_print_private_bfd_dat ppcboot_bfd_print_private_bfd_data |
#define ppcboot_bfd_print_private_bfd_dat ppcboot_bfd_print_private_bfd_data |
494 |
|
|