1 /* BFD back-end for oasys objects.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define UNDERSCORE_HACK 1
28 /* XXX - FIXME. offsetof belongs in the system-specific files in
30 /* Define offsetof for those systems which lack it */
33 #define offsetof(type, identifier) (size_t) &(((type *) 0)->identifier)
36 static boolean oasys_write_sections PARAMS ((bfd *));
38 /* Read in all the section data and relocation stuff too */
39 PROTO (static boolean, oasys_slurp_section_data, (bfd * CONST abfd));
42 oasys_read_record (abfd, record)
44 oasys_record_union_type *record;
47 bfd_read ((PTR) record, 1, sizeof (record->header), abfd);
49 if ((size_t) record->header.length <= (size_t) sizeof (record->header))
51 bfd_read ((PTR) (((char *) record) + sizeof (record->header)),
52 1, record->header.length - sizeof (record->header),
56 oasys_string_length (record)
57 oasys_record_union_type *record;
59 return record->header.length
60 - ((char *) record->symbol.name - (char *) record);
63 /*****************************************************************************/
67 Slurp the symbol table by reading in all the records at the start file
68 till we get to the first section record.
70 We'll sort the symbolss into two lists, defined and undefined. The
71 undefined symbols will be placed into the table according to their
74 We do this by placing all undefined symbols at the front of the table
75 moving in, and the defined symbols at the end of the table moving back.
80 oasys_slurp_symbol_table (abfd)
83 oasys_record_union_type record;
84 oasys_data_type *data = OASYS_DATA (abfd);
86 asymbol *dest_defined;
91 if (data->symbols != (asymbol *) NULL)
95 /* Buy enough memory for all the symbols and all the names */
97 (asymbol *) bfd_alloc (abfd, sizeof (asymbol) * abfd->symcount);
98 #ifdef UNDERSCORE_HACK
99 /* buy 1 more char for each symbol to keep the underscore in*/
100 data->strings = bfd_alloc (abfd, data->symbol_string_length +
103 data->strings = bfd_alloc (abfd, data->symbol_string_length);
105 if (!data->symbols || !data->strings)
107 bfd_set_error (bfd_error_no_memory);
111 dest_defined = data->symbols + abfd->symcount - 1;
113 string_ptr = data->strings;
114 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
118 oasys_read_record (abfd, &record);
119 switch (record.header.type)
121 case oasys_record_is_header_enum:
123 case oasys_record_is_local_enum:
124 case oasys_record_is_symbol_enum:
126 int flag = record.header.type == (int) oasys_record_is_local_enum ?
127 (BSF_LOCAL) : (BSF_GLOBAL | BSF_EXPORT);
130 size_t length = oasys_string_length (&record);
131 switch (record.symbol.relb & RELOCATION_TYPE_BITS)
133 case RELOCATION_TYPE_ABS:
134 dest = dest_defined--;
135 dest->section = &bfd_abs_section;
139 case RELOCATION_TYPE_REL:
140 dest = dest_defined--;
142 OASYS_DATA (abfd)->sections[record.symbol.relb &
143 RELOCATION_SECT_BITS];
144 if (record.header.type == (int) oasys_record_is_local_enum)
146 dest->flags = BSF_LOCAL;
147 if (dest->section == (asection *) (~0))
149 /* It seems that sometimes internal symbols are tied up, but
150 still get output, even though there is no
161 case RELOCATION_TYPE_UND:
162 dest = data->symbols + bfd_h_get_16 (abfd, record.symbol.refno);
163 dest->section = &bfd_und_section;
165 case RELOCATION_TYPE_COM:
166 dest = dest_defined--;
167 dest->name = string_ptr;
168 dest->the_bfd = abfd;
170 dest->section = &bfd_com_section;
174 dest = dest_defined--;
178 dest->name = string_ptr;
179 dest->the_bfd = abfd;
180 dest->udata = (PTR) NULL;
181 dest->value = bfd_h_get_32 (abfd, record.symbol.value);
183 #ifdef UNDERSCORE_HACK
184 if (record.symbol.name[0] != '_')
190 memcpy (string_ptr, record.symbol.name, length);
193 string_ptr[length] = 0;
194 string_ptr += length + 1;
205 oasys_get_symtab_upper_bound (abfd)
208 oasys_slurp_symbol_table (abfd);
210 return (abfd->symcount + 1) * (sizeof (oasys_symbol_type *));
216 extern bfd_target oasys_vec;
219 oasys_get_symtab (abfd, location)
224 unsigned int counter;
225 if (oasys_slurp_symbol_table (abfd) == false)
229 symbase = OASYS_DATA (abfd)->symbols;
230 for (counter = 0; counter < abfd->symcount; counter++)
232 *(location++) = symbase++;
235 return abfd->symcount;
238 /***********************************************************************
243 oasys_archive_p (abfd)
246 oasys_archive_header_type header;
247 oasys_extarchive_header_type header_ext;
251 bfd_seek (abfd, (file_ptr) 0, false);
252 bfd_read ((PTR) & header_ext, 1, sizeof (header_ext), abfd);
254 header.version = bfd_h_get_32 (abfd, header_ext.version);
255 header.mod_count = bfd_h_get_32 (abfd, header_ext.mod_count);
256 header.mod_tbl_offset = bfd_h_get_32 (abfd, header_ext.mod_tbl_offset);
257 header.sym_tbl_size = bfd_h_get_32 (abfd, header_ext.sym_tbl_size);
258 header.sym_count = bfd_h_get_32 (abfd, header_ext.sym_count);
259 header.sym_tbl_offset = bfd_h_get_32 (abfd, header_ext.sym_tbl_offset);
260 header.xref_count = bfd_h_get_32 (abfd, header_ext.xref_count);
261 header.xref_lst_offset = bfd_h_get_32 (abfd, header_ext.xref_lst_offset);
264 There isn't a magic number in an Oasys archive, so the best we
265 can do to verify reasnableness is to make sure that the values in
266 the header are too weird
269 if (header.version > 10000 ||
270 header.mod_count > 10000 ||
271 header.sym_count > 100000 ||
272 header.xref_count > 100000)
273 return (bfd_target *) NULL;
276 That all worked, let's buy the space for the header and read in
280 oasys_ar_data_type *ar =
281 (oasys_ar_data_type *) bfd_alloc (abfd, sizeof (oasys_ar_data_type));
283 oasys_module_info_type *module =
284 (oasys_module_info_type *)
285 bfd_alloc (abfd, sizeof (oasys_module_info_type) * header.mod_count);
286 oasys_module_table_type record;
290 bfd_set_error (bfd_error_no_memory);
294 abfd->tdata.oasys_ar_data = ar;
296 ar->module_count = header.mod_count;
298 filepos = header.mod_tbl_offset;
299 for (i = 0; i < header.mod_count; i++)
301 bfd_seek (abfd, filepos, SEEK_SET);
303 /* There are two ways of specifying the archive header */
307 oasys_extmodule_table_type_a_type record_ext;
308 bfd_read ((PTR) & record_ext, 1, sizeof (record_ext), abfd);
310 record.mod_size = bfd_h_get_32 (abfd, record_ext.mod_size);
311 record.file_offset = bfd_h_get_32 (abfd, record_ext.file_offset);
313 record.dep_count = bfd_h_get_32 (abfd, record_ext.dep_count);
314 record.depee_count = bfd_h_get_32 (abfd, record_ext.depee_count);
315 record.sect_count = bfd_h_get_32 (abfd, record_ext.sect_count);
317 module[i].name = bfd_alloc (abfd, 33);
320 bfd_set_error (bfd_error_no_error);
324 memcpy (module[i].name, record_ext.mod_name, 33);
326 sizeof (record_ext) +
327 record.dep_count * 4 +
328 record.depee_count * 4 +
329 record.sect_count * 8 + 187;
333 oasys_extmodule_table_type_b_type record_ext;
334 bfd_read ((PTR) & record_ext, 1, sizeof (record_ext), abfd);
336 record.mod_size = bfd_h_get_32 (abfd, record_ext.mod_size);
337 record.file_offset = bfd_h_get_32 (abfd, record_ext.file_offset);
339 record.dep_count = bfd_h_get_32 (abfd, record_ext.dep_count);
340 record.depee_count = bfd_h_get_32 (abfd, record_ext.depee_count);
341 record.sect_count = bfd_h_get_32 (abfd, record_ext.sect_count);
342 record.module_name_size = bfd_h_get_32 (abfd, record_ext.mod_name_length);
344 module[i].name = bfd_alloc (abfd, record.module_name_size + 1);
347 bfd_set_error (bfd_error_no_error);
350 bfd_read ((PTR) module[i].name, 1, record.module_name_size, abfd);
351 module[i].name[record.module_name_size] = 0;
353 sizeof (record_ext) +
354 record.dep_count * 4 +
355 record.module_name_size + 1;
360 module[i].size = record.mod_size;
361 module[i].pos = record.file_offset;
370 oasys_mkobject (abfd)
374 abfd->tdata.oasys_obj_data = (oasys_data_type *) bfd_alloc (abfd, sizeof (oasys_data_type));
375 return abfd->tdata.oasys_obj_data ? true : false;
380 oasys_object_p (abfd)
383 oasys_data_type *oasys;
384 oasys_data_type *save = OASYS_DATA (abfd);
386 boolean had_usefull = false;
388 abfd->tdata.oasys_obj_data = 0;
389 oasys_mkobject (abfd);
390 oasys = OASYS_DATA (abfd);
391 memset ((PTR) oasys->sections, 0xff, sizeof (oasys->sections));
393 /* Point to the start of the file */
394 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
395 oasys->symbol_string_length = 0;
396 /* Inspect the records, but only keep the section info -
397 remember the size of the symbols
399 oasys->first_data_record = 0;
402 oasys_record_union_type record;
403 oasys_read_record (abfd, &record);
404 if ((size_t) record.header.length < (size_t) sizeof (record.header))
408 switch ((oasys_record_enum_type) (record.header.type))
410 case oasys_record_is_header_enum:
413 case oasys_record_is_symbol_enum:
414 case oasys_record_is_local_enum:
415 /* Count symbols and remember their size for a future malloc */
417 oasys->symbol_string_length += 1 + oasys_string_length (&record);
420 case oasys_record_is_section_enum:
424 unsigned int section_number;
425 if (record.section.header.length != sizeof (record.section))
429 buffer = bfd_alloc (abfd, 3);
432 bfd_set_error (bfd_error_no_memory);
435 section_number = record.section.relb & RELOCATION_SECT_BITS;
436 sprintf (buffer, "%u", section_number);
437 s = bfd_make_section (abfd, buffer);
438 oasys->sections[section_number] = s;
439 switch (record.section.relb & RELOCATION_TYPE_BITS)
441 case RELOCATION_TYPE_ABS:
442 case RELOCATION_TYPE_REL:
444 case RELOCATION_TYPE_UND:
445 case RELOCATION_TYPE_COM:
449 s->_raw_size = bfd_h_get_32 (abfd, record.section.value);
450 s->vma = bfd_h_get_32 (abfd, record.section.vma);
455 case oasys_record_is_data_enum:
456 oasys->first_data_record = bfd_tell (abfd) - record.header.length;
457 case oasys_record_is_debug_enum:
458 case oasys_record_is_module_enum:
459 case oasys_record_is_named_section_enum:
460 case oasys_record_is_end_enum:
461 if (had_usefull == false)
469 oasys->symbols = (asymbol *) NULL;
471 Oasys support several architectures, but I can't see a simple way
472 to discover which one is in a particular file - we'll guess
474 bfd_default_set_arch_mach (abfd, bfd_arch_m68k, 0);
475 if (abfd->symcount != 0)
477 abfd->flags |= HAS_SYMS;
481 We don't know if a section has data until we've read it..
484 oasys_slurp_section_data (abfd);
490 (void) bfd_release (abfd, oasys);
491 abfd->tdata.oasys_obj_data = save;
492 return (bfd_target *) NULL;
497 oasys_get_symbol_info (ignore_abfd, symbol, ret)
502 bfd_symbol_info (symbol, ret);
503 if (!symbol->section)
504 ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
508 oasys_print_symbol (ignore_abfd, afile, symbol, how)
512 bfd_print_symbol_type how;
514 FILE *file = (FILE *) afile;
518 case bfd_print_symbol_name:
519 case bfd_print_symbol_more:
520 fprintf (file, "%s", symbol->name);
522 case bfd_print_symbol_all:
524 CONST char *section_name = symbol->section == (asection *) NULL ?
525 (CONST char *) "*abs" : symbol->section->name;
527 bfd_print_symbol_vandf ((PTR) file, symbol);
529 fprintf (file, " %-5s %s",
537 The howto table is build using the top two bits of a reloc byte to
538 index into it. The bits are PCREL,WORD/LONG
540 static reloc_howto_type howto_table[] =
543 HOWTO (0, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false),
544 HOWTO (0, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs32", true, 0xffffffff, 0xffffffff, false),
545 HOWTO (0, 0, 1, 16, true, 0, complain_overflow_signed, 0, "pcrel16", true, 0x0000ffff, 0x0000ffff, false),
546 HOWTO (0, 0, 2, 32, true, 0, complain_overflow_signed, 0, "pcrel32", true, 0xffffffff, 0xffffffff, false)
549 /* Read in all the section data and relocation stuff too */
551 oasys_slurp_section_data (abfd)
554 oasys_record_union_type record;
555 oasys_data_type *data = OASYS_DATA (abfd);
558 oasys_per_section_type *per;
562 /* See if the data has been slurped already .. */
563 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
565 per = oasys_per_section (s);
566 if (per->initialized == true)
570 if (data->first_data_record == 0)
573 bfd_seek (abfd, data->first_data_record, SEEK_SET);
576 oasys_read_record (abfd, &record);
577 switch (record.header.type)
579 case oasys_record_is_header_enum:
581 case oasys_record_is_data_enum:
584 bfd_byte *src = record.data.data;
585 bfd_byte *end_src = ((bfd_byte *) & record) + record.header.length;
587 bfd_byte *dst_base_ptr;
591 data->sections[record.data.relb & RELOCATION_SECT_BITS];
594 per = oasys_per_section (section);
596 if (per->initialized == false)
598 per->data = (bfd_byte *) bfd_zalloc (abfd, section->_raw_size);
601 bfd_set_error (bfd_error_no_memory);
604 per->reloc_tail_ptr = (oasys_reloc_type **) & (section->relocation);
605 per->had_vma = false;
606 per->initialized = true;
607 section->reloc_count = 0;
608 section->flags = SEC_ALLOC;
611 dst_offset = bfd_h_get_32 (abfd, record.data.addr);
612 if (per->had_vma == false)
614 /* Take the first vma we see as the base */
615 section->vma = dst_offset;
619 dst_offset -= section->vma;
621 dst_base_ptr = oasys_per_section (section)->data;
622 dst_ptr = oasys_per_section (section)->data +
627 section->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
629 while (src < end_src)
631 unsigned char mod_byte = *src++;
632 size_t gap = end_src - src;
635 if (mod_byte == 0 && gap >= 8)
650 for (relbit = 1; count-- != 0 && src < end_src; relbit <<= 1)
652 if (relbit & mod_byte)
654 unsigned char reloc = *src;
655 /* This item needs to be relocated */
656 switch (reloc & RELOCATION_TYPE_BITS)
658 case RELOCATION_TYPE_ABS:
662 case RELOCATION_TYPE_REL:
664 /* Relocate the item relative to the section */
665 oasys_reloc_type *r =
668 sizeof (oasys_reloc_type));
671 bfd_set_error (bfd_error_no_memory);
674 *(per->reloc_tail_ptr) = r;
675 per->reloc_tail_ptr = &r->next;
676 r->next = (oasys_reloc_type *) NULL;
677 /* Reference to undefined symbol */
679 /* There is no symbol */
681 /* Work out the howto */
685 data->sections[reloc &
686 RELOCATION_SECT_BITS];
689 r->relent.section->vma;
691 r->relent.address = dst_ptr - dst_base_ptr;
692 r->relent.howto = &howto_table[reloc >> 6];
693 r->relent.sym_ptr_ptr = (asymbol **) NULL;
694 section->reloc_count++;
696 /* Fake up the data to look like it's got the -ve pc in it, this makes
697 it much easier to convert into other formats. This is done by
700 if (r->relent.howto->pc_relative == true)
702 r->relent.addend -= dst_ptr - dst_base_ptr;
710 case RELOCATION_TYPE_UND:
712 oasys_reloc_type *r =
715 sizeof (oasys_reloc_type));
718 bfd_set_error (bfd_error_no_memory);
721 *(per->reloc_tail_ptr) = r;
722 per->reloc_tail_ptr = &r->next;
723 r->next = (oasys_reloc_type *) NULL;
724 /* Reference to undefined symbol */
726 /* Get symbol number */
727 r->symbol = (src[0] << 8) | src[1];
728 /* Work out the howto */
732 r->relent.section = (asection
735 r->relent.addend = 0;
736 r->relent.address = dst_ptr - dst_base_ptr;
737 r->relent.howto = &howto_table[reloc >> 6];
738 r->relent.sym_ptr_ptr = (asymbol **) NULL;
739 section->reloc_count++;
742 /* Fake up the data to look like it's got the -ve pc in it, this makes
743 it much easier to convert into other formats. This is done by
746 if (r->relent.howto->pc_relative == true)
748 r->relent.addend -= dst_ptr - dst_base_ptr;
755 case RELOCATION_TYPE_COM:
765 case oasys_record_is_local_enum:
766 case oasys_record_is_symbol_enum:
767 case oasys_record_is_section_enum:
779 oasys_new_section_hook (abfd, newsect)
783 newsect->used_by_bfd = (PTR)
784 bfd_alloc (abfd, sizeof (oasys_per_section_type));
785 if (!newsect->used_by_bfd)
787 bfd_set_error (bfd_error_no_memory);
790 oasys_per_section (newsect)->data = (bfd_byte *) NULL;
791 oasys_per_section (newsect)->section = newsect;
792 oasys_per_section (newsect)->offset = 0;
793 oasys_per_section (newsect)->initialized = false;
794 newsect->alignment_power = 1;
795 /* Turn the section string into an index */
797 sscanf (newsect->name, "%u", &newsect->target_index);
804 oasys_get_reloc_upper_bound (abfd, asect)
808 oasys_slurp_section_data (abfd);
809 return (asect->reloc_count + 1) * sizeof (arelent *);
813 oasys_get_section_contents (abfd, section, location, offset, count)
820 oasys_per_section_type *p = (oasys_per_section_type *) section->used_by_bfd;
821 oasys_slurp_section_data (abfd);
822 if (p->initialized == false)
824 (void) memset (location, 0, (int) count);
828 (void) memcpy (location, (PTR) (p->data + offset), (int) count);
835 oasys_canonicalize_reloc (ignore_abfd, section, relptr, symbols)
841 unsigned int reloc_count = 0;
842 oasys_reloc_type *src = (oasys_reloc_type *) (section->relocation);
843 while (src != (oasys_reloc_type *) NULL)
848 if (src->relent.section == (asection *) NULL)
850 src->relent.sym_ptr_ptr = symbols + src->symbol;
854 *relptr++ = &src->relent;
858 *relptr = (arelent *) NULL;
859 return section->reloc_count = reloc_count;
868 /* Calculate the checksum and write one record */
870 oasys_write_record (abfd, type, record, size)
872 CONST oasys_record_enum_type type;
873 oasys_record_union_type *record;
880 record->header.length = size;
881 record->header.type = (int) type;
882 record->header.check_sum = 0;
883 record->header.fill = 0;
884 ptr = (unsigned char *) &record->pad[0];
886 for (i = 0; i < size; i++)
890 record->header.check_sum = 0xff & (-checksum);
891 bfd_write ((PTR) record, 1, size, abfd);
895 /* Write out all the symbols */
897 oasys_write_syms (abfd)
901 asymbol **generic = bfd_get_outsymbols (abfd);
902 unsigned int index = 0;
903 for (count = 0; count < bfd_get_symcount (abfd); count++)
906 oasys_symbol_record_type symbol;
907 asymbol *CONST g = generic[count];
909 CONST char *src = g->name;
910 char *dst = symbol.name;
913 if (bfd_is_com_section (g->section))
915 symbol.relb = RELOCATION_TYPE_COM;
916 bfd_h_put_16 (abfd, index, symbol.refno);
919 else if (g->section == &bfd_abs_section)
921 symbol.relb = RELOCATION_TYPE_ABS;
922 bfd_h_put_16 (abfd, 0, symbol.refno);
925 else if (g->section == &bfd_und_section)
927 symbol.relb = RELOCATION_TYPE_UND;
928 bfd_h_put_16 (abfd, index, symbol.refno);
929 /* Overload the value field with the output index number */
932 else if (g->flags & BSF_DEBUGGING)
939 if (g->section == (asection *) NULL)
941 /* Sometime, the oasys tools give out a symbol with illegal
942 bits in it, we'll output it in the same broken way */
944 symbol.relb = RELOCATION_TYPE_REL | 0;
948 symbol.relb = RELOCATION_TYPE_REL | g->section->output_section->target_index;
950 bfd_h_put_16 (abfd, 0, symbol.refno);
952 #ifdef UNDERSCORE_HACK
962 bfd_h_put_32 (abfd, g->value, symbol.value);
965 if (g->flags & BSF_LOCAL)
967 oasys_write_record (abfd,
968 oasys_record_is_local_enum,
969 (oasys_record_union_type *) & symbol,
970 offsetof (oasys_symbol_record_type, name[0]) + l);
974 oasys_write_record (abfd,
975 oasys_record_is_symbol_enum,
976 (oasys_record_union_type *) & symbol,
977 offsetof (oasys_symbol_record_type, name[0]) + l);
979 g->value = index - 1;
984 /* Write a section header for each section */
986 oasys_write_sections (abfd)
990 static oasys_section_record_type out;
992 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
994 if (!isdigit (s->name[0]))
996 bfd_set_error (bfd_error_nonrepresentable_section);
999 out.relb = RELOCATION_TYPE_REL | s->target_index;
1000 bfd_h_put_32 (abfd, s->_cooked_size, out.value);
1001 bfd_h_put_32 (abfd, s->vma, out.vma);
1003 oasys_write_record (abfd,
1004 oasys_record_is_section_enum,
1005 (oasys_record_union_type *) & out,
1012 oasys_write_header (abfd)
1015 /* Create and write the header */
1016 oasys_header_record_type r;
1017 size_t length = strlen (abfd->filename);
1018 if (length > (size_t) sizeof (r.module_name))
1020 length = sizeof (r.module_name);
1023 (void) memcpy (r.module_name,
1026 (void) memset (r.module_name + length,
1028 sizeof (r.module_name) - length);
1030 r.version_number = OASYS_VERSION_NUMBER;
1031 r.rev_number = OASYS_REV_NUMBER;
1032 oasys_write_record (abfd,
1033 oasys_record_is_header_enum,
1034 (oasys_record_union_type *) & r,
1035 offsetof (oasys_header_record_type, description[0]));
1042 oasys_write_end (abfd)
1045 oasys_end_record_type end;
1046 unsigned char null = 0;
1047 end.relb = RELOCATION_TYPE_ABS;
1048 bfd_h_put_32 (abfd, abfd->start_address, end.entry);
1049 bfd_h_put_16 (abfd, 0, end.fill);
1051 oasys_write_record (abfd,
1052 oasys_record_is_end_enum,
1053 (oasys_record_union_type *) & end,
1055 bfd_write ((PTR) & null, 1, 1, abfd);
1063 arelent *a = *((arelent **) ap);
1064 arelent *b = *((arelent **) bp);
1065 return a->address - b->address;
1073 oasys_write_data (abfd)
1077 for (s = abfd->sections; s != (asection *) NULL; s = s->next)
1079 if (s->flags & SEC_LOAD)
1081 bfd_byte *raw_data = oasys_per_section (s)->data;
1082 oasys_data_record_type processed_data;
1083 bfd_size_type current_byte_index = 0;
1084 unsigned int relocs_to_go = s->reloc_count;
1085 arelent **p = s->orelocation;
1086 if (s->reloc_count != 0)
1088 /* Sort the reloc records so it's easy to insert the relocs into the
1091 qsort (s->orelocation,
1093 sizeof (arelent **),
1096 current_byte_index = 0;
1097 processed_data.relb = s->target_index | RELOCATION_TYPE_REL;
1099 while (current_byte_index < s->_cooked_size)
1101 /* Scan forwards by eight bytes or however much is left and see if
1102 there are any relocations going on */
1103 bfd_byte *mod = &processed_data.data[0];
1104 bfd_byte *dst = &processed_data.data[1];
1110 bfd_h_put_32 (abfd, s->vma + current_byte_index,
1111 processed_data.addr);
1113 /* Don't start a relocation unless you're sure you can finish it
1114 within the same data record. The worst case relocation is a
1115 4-byte relocatable value which is split across two modification
1116 bytes (1 relocation byte + 2 symbol reference bytes + 2 data +
1117 1 modification byte + 2 data = 8 bytes total). That's where
1118 the magic number 8 comes from.
1120 while (current_byte_index < s->_raw_size && dst <=
1121 &processed_data.data[sizeof (processed_data.data) - 8])
1125 if (relocs_to_go != 0)
1128 const reloc_howto_type *const how = r->howto;
1129 /* There is a relocation, is it for this byte ? */
1130 if (r->address == current_byte_index)
1132 unsigned char rel_byte;
1138 if (how->pc_relative)
1140 rel_byte = RELOCATION_PCREL_BIT;
1142 /* Also patch the raw data so that it doesn't have
1143 the -ve stuff any more */
1147 bfd_get_16 (abfd, raw_data) +
1148 current_byte_index, raw_data);
1154 bfd_get_32 (abfd, raw_data) +
1155 current_byte_index, raw_data);
1164 rel_byte |= RELOCATION_32BIT_BIT;
1167 /* Is this a section relative relocation, or a symbol
1168 relative relocation ? */
1172 if (r->section != (asection *) NULL)
1174 /* The relent has a section attached, so it must be section
1176 rel_byte |= RELOCATION_TYPE_REL;
1177 rel_byte |= r->section->output_section->target_index;
1183 asymbol *p = *(r->sym_ptr_ptr);
1185 /* If this symbol has a section attached, then it
1186 has already been resolved. Change from a symbol
1187 ref to a section ref */
1188 if (p->section != (asection *) NULL)
1190 rel_byte |= RELOCATION_TYPE_REL;
1192 p->section->output_section->target_index;
1197 rel_byte |= RELOCATION_TYPE_UND;
1199 /* Next two bytes are a symbol index - we can get
1200 this from the symbol value which has been zapped
1201 into the symbol index in the table when the
1202 symbol table was written
1204 *dst++ = p->value >> 8;
1208 #define ADVANCE { if (++i >= 8) { i = 0; mod = dst++; *mod = 0; } current_byte_index++; }
1209 /* relocations never occur from an unloadable section,
1210 so we can assume that raw_data is not NULL
1212 *dst++ = *raw_data++;
1214 * dst++ = *raw_data++;
1218 *dst++ = *raw_data++;
1220 * dst++ = *raw_data++;
1226 /* If this is coming from an unloadable section then copy
1228 if (raw_data == NULL)
1234 *dst++ = *raw_data++;
1239 /* Don't write a useless null modification byte */
1245 oasys_write_record (abfd,
1246 oasys_record_is_data_enum,
1247 (oasys_record_union_type *) & processed_data,
1248 dst - (bfd_byte *) & processed_data);
1255 oasys_write_object_contents (abfd)
1258 oasys_write_header (abfd);
1259 oasys_write_syms (abfd);
1260 if (!oasys_write_sections (abfd))
1262 oasys_write_data (abfd);
1263 oasys_write_end (abfd);
1270 /** exec and core file sections */
1272 /* set section contents is complicated with OASYS since the format is
1273 * not a byte image, but a record stream.
1276 oasys_set_section_contents (abfd, section, location, offset, count)
1281 bfd_size_type count;
1285 if (oasys_per_section (section)->data == (bfd_byte *) NULL)
1287 oasys_per_section (section)->data =
1288 (bfd_byte *) (bfd_alloc (abfd, section->_cooked_size));
1289 if (!oasys_per_section (section)->data)
1291 bfd_set_error (bfd_error_no_memory);
1295 (void) memcpy ((PTR) (oasys_per_section (section)->data + offset),
1304 /* Native-level interface to symbols. */
1306 /* We read the symbols into a buffer, which is discarded when this
1307 function exits. We read the strings into a buffer large enough to
1308 hold them all plus all the cached symbol entries. */
1311 oasys_make_empty_symbol (abfd)
1315 oasys_symbol_type *new =
1316 (oasys_symbol_type *) bfd_zalloc (abfd, sizeof (oasys_symbol_type));
1319 bfd_set_error (bfd_error_no_memory);
1322 new->symbol.the_bfd = abfd;
1323 return &new->symbol;
1329 /* User should have checked the file flags; perhaps we should return
1330 BFD_NO_MORE_SYMBOLS if there are none? */
1333 oasys_openr_next_archived_file (arch, prev)
1337 oasys_ar_data_type *ar = OASYS_AR_DATA (arch);
1338 oasys_module_info_type *p;
1339 /* take the next one from the arch state, or reset */
1340 if (prev == (bfd *) NULL)
1342 /* Reset the index - the first two entries are bogus*/
1343 ar->module_index = 0;
1346 p = ar->module + ar->module_index;
1349 if (ar->module_index <= ar->module_count)
1351 if (p->abfd == (bfd *) NULL)
1353 p->abfd = _bfd_create_empty_archive_element_shell (arch);
1354 p->abfd->origin = p->pos;
1355 p->abfd->filename = p->name;
1357 /* Fixup a pointer to this element for the member */
1358 p->abfd->arelt_data = (PTR) p;
1364 bfd_set_error (bfd_error_no_more_archived_files);
1365 return (bfd *) NULL;
1370 oasys_find_nearest_line (abfd,
1381 char **filename_ptr;
1382 char **functionname_ptr;
1383 unsigned int *line_ptr;
1390 oasys_generic_stat_arch_elt (abfd, buf)
1394 oasys_module_info_type *mod = (oasys_module_info_type *) abfd->arelt_data;
1395 if (mod == (oasys_module_info_type *) NULL)
1397 bfd_set_error (bfd_error_invalid_operation);
1402 buf->st_size = mod->size;
1403 buf->st_mode = 0666;
1409 oasys_sizeof_headers (abfd, exec)
1416 #define oasys_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
1417 #define oasys_core_file_failing_signal (int (*)())bfd_0
1418 #define oasys_core_file_matches_executable_p 0
1419 #define oasys_slurp_armap bfd_true
1420 #define oasys_slurp_extended_name_table bfd_true
1421 #define oasys_truncate_arname (void (*)())bfd_nullvoidptr
1422 #define oasys_write_armap 0
1423 #define oasys_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
1424 #define oasys_close_and_cleanup bfd_generic_close_and_cleanup
1425 #define oasys_set_arch_mach bfd_default_set_arch_mach
1426 #define oasys_bfd_debug_info_start bfd_void
1427 #define oasys_bfd_debug_info_end bfd_void
1428 #define oasys_bfd_debug_info_accumulate (FOO(void, (*), (bfd *, asection *)))bfd_void
1429 #define oasys_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
1430 #define oasys_bfd_relax_section bfd_generic_relax_section
1431 #define oasys_bfd_reloc_type_lookup \
1432 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
1433 #define oasys_bfd_make_debug_symbol \
1434 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
1435 #define oasys_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
1436 #define oasys_bfd_link_add_symbols _bfd_generic_link_add_symbols
1437 #define oasys_bfd_final_link _bfd_generic_final_link
1440 bfd_target oasys_vec =
1443 bfd_target_oasys_flavour,
1444 true, /* target byte order */
1445 true, /* target headers byte order */
1446 (HAS_RELOC | EXEC_P | /* object flags */
1447 HAS_LINENO | HAS_DEBUG |
1448 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1449 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
1450 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1451 0, /* leading underscore */
1452 ' ', /* ar_pad_char */
1453 16, /* ar_max_namelen */
1454 1, /* minimum alignment */
1455 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1456 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1457 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
1458 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1459 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1460 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
1463 oasys_object_p, /* bfd_check_format */
1467 { /* bfd_set_format */
1470 _bfd_generic_mkarchive,
1473 { /* bfd_write_contents */
1475 oasys_write_object_contents,
1476 _bfd_write_archive_contents,