Deleted Added
full compact
ppcboot.c (78828) ppcboot.c (89857)
1/* BFD back-end for PPCbug boot records.
1/* BFD back-end for PPCbug boot records.
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Written by Michael Meissner, Cygnus Support, <meissner@cygnus.com>
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or

--- 16 unchanged lines hidden (view full) ---

27 This is very simple. The only complication is that the real data
28 will start at some address X, and in some cases we will not want to
29 include X zeroes just to get to that point. Since the start
30 address is not meaningful for this object file format, we use it
31 instead to indicate the number of zeroes to skip at the start of
32 the file. objcopy cooperates by specially setting the start
33 address to zero by default. */
34
3 Free Software Foundation, Inc.
4 Written by Michael Meissner, Cygnus Support, <meissner@cygnus.com>
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or

--- 16 unchanged lines hidden (view full) ---

27 This is very simple. The only complication is that the real data
28 will start at some address X, and in some cases we will not want to
29 include X zeroes just to get to that point. Since the start
30 address is not meaningful for this object file format, we use it
31 instead to indicate the number of zeroes to skip at the start of
32 the file. objcopy cooperates by specially setting the start
33 address to zero by default. */
34
35#include <ctype.h>
36
35#include "safe-ctype.h"
37#include "bfd.h"
38#include "sysdep.h"
39#include "libbfd.h"
40
41/* PPCbug location structure */
42typedef struct ppcboot_location {
43 bfd_byte ind;
44 bfd_byte head;

--- 47 unchanged lines hidden (view full) ---

92static const bfd_target *ppcboot_object_p PARAMS ((bfd *));
93static boolean ppcboot_set_arch_mach
94 PARAMS ((bfd *, enum bfd_architecture, unsigned long));
95static boolean ppcboot_get_section_contents
96 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
97static long ppcboot_get_symtab_upper_bound PARAMS ((bfd *));
98static char *mangle_name PARAMS ((bfd *, char *));
99static long ppcboot_get_symtab PARAMS ((bfd *, asymbol **));
36#include "bfd.h"
37#include "sysdep.h"
38#include "libbfd.h"
39
40/* PPCbug location structure */
41typedef struct ppcboot_location {
42 bfd_byte ind;
43 bfd_byte head;

--- 47 unchanged lines hidden (view full) ---

91static const bfd_target *ppcboot_object_p PARAMS ((bfd *));
92static boolean ppcboot_set_arch_mach
93 PARAMS ((bfd *, enum bfd_architecture, unsigned long));
94static boolean ppcboot_get_section_contents
95 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
96static long ppcboot_get_symtab_upper_bound PARAMS ((bfd *));
97static char *mangle_name PARAMS ((bfd *, char *));
98static long ppcboot_get_symtab PARAMS ((bfd *, asymbol **));
100static asymbol *ppcboot_make_empty_symbol PARAMS ((bfd *));
101static void ppcboot_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
102static boolean ppcboot_set_section_contents
103 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
104static int ppcboot_sizeof_headers PARAMS ((bfd *, boolean));
105static boolean ppcboot_bfd_print_private_bfd_data PARAMS ((bfd *, PTR));
106
107#define ppcboot_set_tdata(abfd, ptr) ((abfd)->tdata.any = (PTR) (ptr))
108#define ppcboot_get_tdata(abfd) ((ppcboot_data_t *) ((abfd)->tdata.any))
109
110/* Create a ppcboot object. Invoked via bfd_set_format. */
111
112static boolean
113ppcboot_mkobject (abfd)
114 bfd *abfd;
115{
116 if (!ppcboot_get_tdata (abfd))
99static void ppcboot_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
100static boolean ppcboot_set_section_contents
101 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
102static int ppcboot_sizeof_headers PARAMS ((bfd *, boolean));
103static boolean ppcboot_bfd_print_private_bfd_data PARAMS ((bfd *, PTR));
104
105#define ppcboot_set_tdata(abfd, ptr) ((abfd)->tdata.any = (PTR) (ptr))
106#define ppcboot_get_tdata(abfd) ((ppcboot_data_t *) ((abfd)->tdata.any))
107
108/* Create a ppcboot object. Invoked via bfd_set_format. */
109
110static boolean
111ppcboot_mkobject (abfd)
112 bfd *abfd;
113{
114 if (!ppcboot_get_tdata (abfd))
117 ppcboot_set_tdata (abfd, bfd_zalloc (abfd, sizeof (ppcboot_data_t)));
115 {
116 bfd_size_type amt = sizeof (ppcboot_data_t);
117 ppcboot_set_tdata (abfd, bfd_zalloc (abfd, amt));
118 }
118
119 return true;
120}
121
122
123/* Set the architecture to PowerPC */
124static boolean
125ppcboot_set_arch_mach (abfd, arch, machine)

--- 41 unchanged lines hidden (view full) ---

167 }
168
169 if ((size_t) statbuf.st_size < sizeof (ppcboot_hdr_t))
170 {
171 bfd_set_error (bfd_error_wrong_format);
172 return NULL;
173 }
174
119
120 return true;
121}
122
123
124/* Set the architecture to PowerPC */
125static boolean
126ppcboot_set_arch_mach (abfd, arch, machine)

--- 41 unchanged lines hidden (view full) ---

168 }
169
170 if ((size_t) statbuf.st_size < sizeof (ppcboot_hdr_t))
171 {
172 bfd_set_error (bfd_error_wrong_format);
173 return NULL;
174 }
175
175 if (bfd_read ((PTR) &hdr, sizeof (hdr), 1, abfd) != sizeof (hdr))
176 if (bfd_bread ((PTR) &hdr, (bfd_size_type) sizeof (hdr), abfd)
177 != sizeof (hdr))
176 {
177 if (bfd_get_error () != bfd_error_system_call)
178 bfd_set_error (bfd_error_wrong_format);
179
180 return NULL;
181 }
182
183 /* Now do some basic checks. */

--- 27 unchanged lines hidden (view full) ---

211 sec->_raw_size = statbuf.st_size - sizeof (ppcboot_hdr_t);
212 sec->filepos = sizeof (ppcboot_hdr_t);
213
214 ppcboot_mkobject (abfd);
215 tdata = ppcboot_get_tdata (abfd);
216 tdata->sec = sec;
217 memcpy ((PTR) &tdata->header, (PTR) &hdr, sizeof (ppcboot_hdr_t));
218
178 {
179 if (bfd_get_error () != bfd_error_system_call)
180 bfd_set_error (bfd_error_wrong_format);
181
182 return NULL;
183 }
184
185 /* Now do some basic checks. */

--- 27 unchanged lines hidden (view full) ---

213 sec->_raw_size = statbuf.st_size - sizeof (ppcboot_hdr_t);
214 sec->filepos = sizeof (ppcboot_hdr_t);
215
216 ppcboot_mkobject (abfd);
217 tdata = ppcboot_get_tdata (abfd);
218 tdata->sec = sec;
219 memcpy ((PTR) &tdata->header, (PTR) &hdr, sizeof (ppcboot_hdr_t));
220
219 ppcboot_set_arch_mach (abfd, bfd_arch_powerpc, 0);
221 ppcboot_set_arch_mach (abfd, bfd_arch_powerpc, 0L);
220 return abfd->xvec;
221}
222
223#define ppcboot_close_and_cleanup _bfd_generic_close_and_cleanup
224#define ppcboot_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
225#define ppcboot_new_section_hook _bfd_generic_new_section_hook
226
227
228/* Get contents of the only section. */
229
230static boolean
231ppcboot_get_section_contents (abfd, section, location, offset, count)
232 bfd *abfd;
233 asection *section ATTRIBUTE_UNUSED;
234 PTR location;
235 file_ptr offset;
236 bfd_size_type count;
237{
222 return abfd->xvec;
223}
224
225#define ppcboot_close_and_cleanup _bfd_generic_close_and_cleanup
226#define ppcboot_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
227#define ppcboot_new_section_hook _bfd_generic_new_section_hook
228
229
230/* Get contents of the only section. */
231
232static boolean
233ppcboot_get_section_contents (abfd, section, location, offset, count)
234 bfd *abfd;
235 asection *section ATTRIBUTE_UNUSED;
236 PTR location;
237 file_ptr offset;
238 bfd_size_type count;
239{
238 if (bfd_seek (abfd, offset + sizeof (ppcboot_hdr_t), SEEK_SET) != 0
239 || bfd_read (location, 1, count, abfd) != count)
240 if (bfd_seek (abfd, offset + (file_ptr) sizeof (ppcboot_hdr_t), SEEK_SET) != 0
241 || bfd_bread (location, count, abfd) != count)
240 return false;
241 return true;
242}
243
244
245/* Return the amount of memory needed to read the symbol table. */
246
247static long

--- 6 unchanged lines hidden (view full) ---

254
255/* Create a symbol name based on the bfd's filename. */
256
257static char *
258mangle_name (abfd, suffix)
259 bfd *abfd;
260 char *suffix;
261{
242 return false;
243 return true;
244}
245
246
247/* Return the amount of memory needed to read the symbol table. */
248
249static long

--- 6 unchanged lines hidden (view full) ---

256
257/* Create a symbol name based on the bfd's filename. */
258
259static char *
260mangle_name (abfd, suffix)
261 bfd *abfd;
262 char *suffix;
263{
262 int size;
264 bfd_size_type size;
263 char *buf;
264 char *p;
265
266 size = (strlen (bfd_get_filename (abfd))
267 + strlen (suffix)
268 + sizeof "_ppcboot__");
269
270 buf = (char *) bfd_alloc (abfd, size);
271 if (buf == NULL)
272 return "";
273
274 sprintf (buf, "_ppcboot_%s_%s", bfd_get_filename (abfd), suffix);
275
276 /* Change any non-alphanumeric characters to underscores. */
277 for (p = buf; *p; p++)
265 char *buf;
266 char *p;
267
268 size = (strlen (bfd_get_filename (abfd))
269 + strlen (suffix)
270 + sizeof "_ppcboot__");
271
272 buf = (char *) bfd_alloc (abfd, size);
273 if (buf == NULL)
274 return "";
275
276 sprintf (buf, "_ppcboot_%s_%s", bfd_get_filename (abfd), suffix);
277
278 /* Change any non-alphanumeric characters to underscores. */
279 for (p = buf; *p; p++)
278 if (! isalnum ((unsigned char) *p))
280 if (! ISALNUM (*p))
279 *p = '_';
280
281 return buf;
282}
283
284
285/* Return the symbol table. */
286
287static long
288ppcboot_get_symtab (abfd, alocation)
289 bfd *abfd;
290 asymbol **alocation;
291{
292 asection *sec = ppcboot_get_tdata (abfd)->sec;
293 asymbol *syms;
294 unsigned int i;
281 *p = '_';
282
283 return buf;
284}
285
286
287/* Return the symbol table. */
288
289static long
290ppcboot_get_symtab (abfd, alocation)
291 bfd *abfd;
292 asymbol **alocation;
293{
294 asection *sec = ppcboot_get_tdata (abfd)->sec;
295 asymbol *syms;
296 unsigned int i;
297 bfd_size_type amt = PPCBOOT_SYMS * sizeof (asymbol);
295
298
296 syms = (asymbol *) bfd_alloc (abfd, PPCBOOT_SYMS * sizeof (asymbol));
299 syms = (asymbol *) bfd_alloc (abfd, amt);
297 if (syms == NULL)
298 return false;
299
300 /* Start symbol. */
301 syms[0].the_bfd = abfd;
302 syms[0].name = mangle_name (abfd, "start");
303 syms[0].value = 0;
304 syms[0].flags = BSF_GLOBAL;

--- 18 unchanged lines hidden (view full) ---

323
324 for (i = 0; i < PPCBOOT_SYMS; i++)
325 *alocation++ = syms++;
326 *alocation = NULL;
327
328 return PPCBOOT_SYMS;
329}
330
300 if (syms == NULL)
301 return false;
302
303 /* Start symbol. */
304 syms[0].the_bfd = abfd;
305 syms[0].name = mangle_name (abfd, "start");
306 syms[0].value = 0;
307 syms[0].flags = BSF_GLOBAL;

--- 18 unchanged lines hidden (view full) ---

326
327 for (i = 0; i < PPCBOOT_SYMS; i++)
328 *alocation++ = syms++;
329 *alocation = NULL;
330
331 return PPCBOOT_SYMS;
332}
333
331
332/* Make an empty symbol. */
333
334static asymbol *
335ppcboot_make_empty_symbol (abfd)
336 bfd *abfd;
337{
338 return (asymbol *) bfd_alloc (abfd, sizeof (asymbol));
339}
340
341
334#define ppcboot_make_empty_symbol _bfd_generic_make_empty_symbol
342#define ppcboot_print_symbol _bfd_nosymbols_print_symbol
343
344/* Get information about a symbol. */
345
346static void
347ppcboot_get_symbol_info (ignore_abfd, symbol, ret)
348 bfd *ignore_abfd ATTRIBUTE_UNUSED;
349 asymbol *symbol;

--- 120 unchanged lines hidden (view full) ---

470 return true;
471}
472
473
474#define ppcboot_bfd_get_relocated_section_contents \
475 bfd_generic_get_relocated_section_contents
476#define ppcboot_bfd_relax_section bfd_generic_relax_section
477#define ppcboot_bfd_gc_sections bfd_generic_gc_sections
335#define ppcboot_print_symbol _bfd_nosymbols_print_symbol
336
337/* Get information about a symbol. */
338
339static void
340ppcboot_get_symbol_info (ignore_abfd, symbol, ret)
341 bfd *ignore_abfd ATTRIBUTE_UNUSED;
342 asymbol *symbol;

--- 120 unchanged lines hidden (view full) ---

463 return true;
464}
465
466
467#define ppcboot_bfd_get_relocated_section_contents \
468 bfd_generic_get_relocated_section_contents
469#define ppcboot_bfd_relax_section bfd_generic_relax_section
470#define ppcboot_bfd_gc_sections bfd_generic_gc_sections
471#define ppcboot_bfd_merge_sections bfd_generic_merge_sections
478#define ppcboot_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
479#define ppcboot_bfd_link_add_symbols _bfd_generic_link_add_symbols
480#define ppcboot_bfd_final_link _bfd_generic_final_link
481#define ppcboot_bfd_link_split_section _bfd_generic_link_split_section
482#define ppcboot_get_section_contents_in_window \
483 _bfd_generic_get_section_contents_in_window
484
485#define ppcboot_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data

--- 57 unchanged lines hidden ---
472#define ppcboot_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
473#define ppcboot_bfd_link_add_symbols _bfd_generic_link_add_symbols
474#define ppcboot_bfd_final_link _bfd_generic_final_link
475#define ppcboot_bfd_link_split_section _bfd_generic_link_split_section
476#define ppcboot_get_section_contents_in_window \
477 _bfd_generic_get_section_contents_in_window
478
479#define ppcboot_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data

--- 57 unchanged lines hidden ---