1 /* bfd backend for oasys objects.
2 Written by Steve Chamberlain of Cygnus Support <steve@cygnus.com> */
4 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Diddler.
8 BFD is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 1, or (at your option)
13 BFD is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with BFD; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #define UNDERSCORE_HACK 1
25 #define offsetof(type, identifier) (size_t) &(((type *) 0)->identifier)
34 DEFUN(oasys_read_record,(abfd, record),
36 oasys_record_union_type *record)
39 bfd_read((PTR)record, 1, sizeof(record->header), abfd);
41 if ((size_t) record->header.length <= (size_t) sizeof (record->header))
43 bfd_read((PTR)(((char *)record )+ sizeof(record->header)),
44 1, record->header.length - sizeof(record->header),
48 DEFUN(oasys_string_length,(record),
49 oasys_record_union_type *record)
51 return record->header.length
52 - ((char *)record->symbol.name - (char *)record);
55 /*****************************************************************************/
59 Slurp the symbol table by reading in all the records at the start file
60 till we get to the first section record.
62 We'll sort the symbolss into two lists, defined and undefined. The
63 undefined symbols will be placed into the table according to their
66 We do this by placing all undefined symbols at the front of the table
67 moving in, and the defined symbols at the end of the table moving back.
72 DEFUN(oasys_slurp_symbol_table,(abfd),
75 oasys_record_union_type record;
76 oasys_data_type *data = oasys_data(abfd);
78 asymbol *dest_defined;
83 if (data->symbols != (asymbol *)NULL) {
86 /* Buy enough memory for all the symbols and all the names */
88 (asymbol *)bfd_alloc(abfd, sizeof(asymbol) * abfd->symcount);
89 #ifdef UNDERSCORE_HACK
90 /* buy 1 more char for each symbol to keep the underscore in*/
91 data->strings = bfd_alloc(abfd, data->symbol_string_length +
94 data->strings = bfd_alloc(abfd, data->symbol_string_length);
98 dest_defined = data->symbols + abfd->symcount -1;
100 string_ptr = data->strings;
101 bfd_seek(abfd, (file_ptr)0, SEEK_SET);
104 oasys_read_record(abfd, &record);
105 switch (record.header.type) {
106 case oasys_record_is_header_enum:
108 case oasys_record_is_local_enum:
109 case oasys_record_is_symbol_enum:
111 int flag = record.header.type == oasys_record_is_local_enum ?
112 (BSF_LOCAL) : (BSF_GLOBAL | BSF_EXPORT);
115 size_t length = oasys_string_length(&record);
116 switch (record.symbol.relb & RELOCATION_TYPE_BITS) {
117 case RELOCATION_TYPE_ABS:
118 dest = dest_defined--;
120 dest->flags = BSF_ABSOLUTE | flag;
122 case RELOCATION_TYPE_REL:
123 dest = dest_defined--;
125 oasys_data(abfd)->sections[record.symbol.relb &
126 RELOCATION_SECT_BITS];
127 if (record.header.type == oasys_record_is_local_enum)
129 dest->flags = BSF_LOCAL;
136 case RELOCATION_TYPE_UND:
137 dest = data->symbols + bfd_h_get_16(abfd, (bfd_byte *)&record.symbol.refno[0]);
138 dest->section = (asection *)NULL;
139 dest->flags = BSF_UNDEFINED;
141 case RELOCATION_TYPE_COM:
142 dest = dest_defined--;
143 dest->name = string_ptr;
144 dest->the_bfd = abfd;
146 dest->section = (asection *)NULL;
147 dest->flags = BSF_FORT_COMM;
150 dest->name = string_ptr;
151 dest->the_bfd = abfd;
152 dest->udata = (PTR)NULL;
153 dest->value = bfd_h_get_32(abfd, &record.symbol.value[0]);
155 #ifdef UNDERSCORE_HACK
156 if (record.symbol.name[0] != '_') {
161 memcpy(string_ptr, record.symbol.name, length);
164 string_ptr[length] =0;
165 string_ptr += length +1;
177 DEFUN(oasys_get_symtab_upper_bound,(abfd),
180 oasys_slurp_symbol_table (abfd);
182 return (abfd->symcount+1) * (sizeof (oasys_symbol_type *));
188 extern bfd_target oasys_vec;
191 DEFUN(oasys_get_symtab,(abfd, location),
196 unsigned int counter ;
197 if (oasys_slurp_symbol_table(abfd) == false) {
200 symbase = oasys_data(abfd)->symbols;
201 for (counter = 0; counter < abfd->symcount; counter++) {
202 *(location++) = symbase++;
205 return abfd->symcount;
208 /***********************************************************************
213 DEFUN(oasys_archive_p,(abfd),
216 oasys_archive_header_type header;
217 oasys_external_archive_header_type header_ext;
220 bfd_seek(abfd, (file_ptr) 0, false);
223 bfd_read((PTR)&header_ext, 1, sizeof(header_ext), abfd);
226 header.version = bfd_h_get_32(abfd, header_ext.version);
227 header.mod_count = bfd_h_get_32(abfd, header_ext.mod_count);
228 header.mod_tbl_offset = bfd_h_get_32(abfd, header_ext.mod_tbl_offset);
229 header.sym_tbl_size = bfd_h_get_32(abfd, header_ext.sym_tbl_size);
230 header.sym_count = bfd_h_get_32(abfd, header_ext.sym_count);
231 header.sym_tbl_offset = bfd_h_get_32(abfd, header_ext.sym_tbl_offset);
232 header.xref_count = bfd_h_get_32(abfd, header_ext.xref_count);
233 header.xref_lst_offset = bfd_h_get_32(abfd, header_ext.xref_lst_offset);
236 There isn't a magic number in an Oasys archive, so the best we
237 can do to verify reasnableness is to make sure that the values in
238 the header are too weird
241 if (header.version>10000 ||
242 header.mod_count>10000 ||
243 header.sym_count>100000 ||
244 header.xref_count > 100000) return (bfd_target *)NULL;
247 That all worked, lets buy the space for the header and read in
251 oasys_ar_data_type *ar =
252 (oasys_ar_data_type*) bfd_alloc(abfd, sizeof(oasys_ar_data_type));
255 oasys_module_info_type *module =
256 (oasys_module_info_type*)
257 bfd_alloc(abfd, sizeof(oasys_module_info_type) * header.mod_count);
260 oasys_module_table_type record;
261 oasys_external_module_table_type record_ext;
265 ar->module_count = header.mod_count;
268 filepos = header.mod_tbl_offset;
269 for (i = 0; i < header.mod_count; i++) {
270 bfd_seek(abfd , filepos, SEEK_SET);
271 bfd_read((PTR)&record_ext, 1, sizeof(record_ext), abfd);
273 record.mod_size = bfd_h_get_32(abfd, record_ext.mod_size);
274 record.file_offset = bfd_h_get_32(abfd,
275 record_ext.file_offset);
277 record.dep_count = bfd_h_get_32(abfd, record_ext.dep_count);
278 record.depee_count = bfd_h_get_32(abfd, record_ext.depee_count);
279 record.sect_count = bfd_h_get_32(abfd, record_ext.sect_count);
282 module[i].name = bfd_alloc(abfd,33);
284 memcpy(module[i].name, record_ext.mod_name, 33);
287 record.dep_count * 4 +
288 record.depee_count * 4 +
289 record.sect_count * 8 + 187,
292 module[i].size = record.mod_size;
293 module[i].pos = record.file_offset;
302 DEFUN(oasys_mkobject,(abfd),
305 oasys_data_type *oasys;
308 (oasys_data_type*)bfd_alloc(abfd, sizeof(oasys_data_type)));
309 oasys = oasys_data(abfd);
315 DEFUN(oasys_object_p,(abfd),
318 oasys_data_type *oasys;
319 oasys_data_type *save = oasys_data(abfd);
321 boolean had_usefull = false;
324 oasys_mkobject(abfd);
325 oasys = oasys_data(abfd);
326 memset((PTR)oasys->sections, 0xff, sizeof(oasys->sections));
328 /* Point to the start of the file */
329 bfd_seek(abfd, (file_ptr)0, SEEK_SET);
330 oasys->symbol_string_length = 0;
331 /* Inspect the records, but only keep the section info -
332 remember the size of the symbols
334 oasys->first_data_record = 0;
336 oasys_record_union_type record;
337 oasys_read_record(abfd, &record);
338 if ((size_t)record.header.length < (size_t)sizeof(record.header))
342 switch ((oasys_record_enum_type)(record.header.type)) {
343 case oasys_record_is_header_enum:
346 case oasys_record_is_symbol_enum:
347 case oasys_record_is_local_enum:
348 /* Count symbols and remember their size for a future malloc */
350 oasys->symbol_string_length += 1 + oasys_string_length(&record);
353 case oasys_record_is_section_enum:
357 unsigned int section_number;
358 if (record.section.header.length != sizeof(record.section))
362 buffer = bfd_alloc(abfd, 3);
363 section_number= record.section.relb & RELOCATION_SECT_BITS;
364 sprintf(buffer,"%u", section_number);
365 s = bfd_make_section(abfd,buffer);
366 oasys->sections[section_number] = s;
367 switch (record.section.relb & RELOCATION_TYPE_BITS) {
368 case RELOCATION_TYPE_ABS:
369 case RELOCATION_TYPE_REL:
371 case RELOCATION_TYPE_UND:
372 case RELOCATION_TYPE_COM:
376 s->size = bfd_h_get_32(abfd, & record.section.value[0]) ;
377 s->vma = bfd_h_get_32(abfd, &record.section.vma[0]);
378 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
382 case oasys_record_is_data_enum:
383 oasys->first_data_record = bfd_tell(abfd) - record.header.length;
384 case oasys_record_is_debug_enum:
385 case oasys_record_is_module_enum:
386 case oasys_record_is_named_section_enum:
387 case oasys_record_is_end_enum:
388 if (had_usefull == false) goto fail;
395 oasys->symbols = (asymbol *)NULL;
397 Oasys support several architectures, but I can't see a simple way
398 to discover which one is in a particular file - we'll guess
400 abfd->obj_arch = bfd_arch_m68k;
401 abfd->obj_machine =0;
402 if (abfd->symcount != 0) {
403 abfd->flags |= HAS_SYMS;
408 (void) bfd_release(abfd, oasys);
409 set_tdata (abfd, save);
410 return (bfd_target *)NULL;
415 DEFUN(oasys_print_symbol,(ignore_abfd, afile, symbol, how),
419 bfd_print_symbol_enum_type how)
421 FILE *file = (FILE *)afile;
424 case bfd_print_symbol_name_enum:
425 case bfd_print_symbol_type_enum:
426 fprintf(file,"%s", symbol->name);
428 case bfd_print_symbol_all_enum:
430 CONST char *section_name = symbol->section == (asection *)NULL ?
431 "*abs" : symbol->section->name;
433 bfd_print_symbol_vandf((PTR)file,symbol);
435 fprintf(file," %-5s %s",
443 The howto table is build using the top two bits of a reloc byte to
444 index into it. The bits are PCREL,WORD/LONG
446 static reloc_howto_type howto_table[]=
449 HOWTO( 0, 0, 1, 16, false,0, true,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false),
450 HOWTO( 0, 0, 2, 32, false,0, true,true,0,"abs32",true,0xffffffff, 0xffffffff,false),
451 HOWTO( 0, 0, 1, 16, true,0, true,true,0,"pcrel16",true,0x0000ffff, 0x0000ffff,false),
452 HOWTO( 0, 0, 2, 32, true,0, true,true,0,"pcrel32",true,0xffffffff, 0xffffffff,false)
455 /* Read in all the section data and relocation stuff too */
457 DEFUN(oasys_slurp_section_data,(abfd),
460 oasys_record_union_type record;
461 oasys_data_type *data = oasys_data(abfd);
464 oasys_per_section_type *per ;
468 /* Buy enough memory for all the section data and relocations */
469 for (s = abfd->sections; s != (asection *)NULL; s= s->next) {
470 per = oasys_per_section(s);
471 if (per->data != (bfd_byte*)NULL) return true;
472 per->data = (bfd_byte *) bfd_alloc(abfd, s->size);
473 per->reloc_tail_ptr = (oasys_reloc_type **)&(s->relocation);
474 per->had_vma = false;
478 if (data->first_data_record == 0) return true;
479 bfd_seek(abfd, data->first_data_record, SEEK_SET);
481 oasys_read_record(abfd, &record);
482 switch (record.header.type) {
483 case oasys_record_is_header_enum:
485 case oasys_record_is_data_enum:
488 uint8e_type *src = record.data.data;
489 uint8e_type *end_src = ((uint8e_type *)&record) +
490 record.header.length;
493 bfd_byte *dst_base_ptr ;
496 data->sections[record.data.relb & RELOCATION_SECT_BITS];
498 per = oasys_per_section(section);
499 dst_offset = bfd_h_get_32(abfd, record.data.addr) ;
500 if (per->had_vma == false) {
501 /* Take the first vma we see as the base */
503 section->vma = dst_offset;
508 dst_offset -= section->vma;
511 dst_base_ptr = oasys_per_section(section)->data;
512 dst_ptr = oasys_per_section(section)->data +
515 while (src < end_src) {
516 uint32_type gap = end_src - src -1;
517 uint8e_type mod_byte = *src++;
519 if (mod_byte == 0 && gap >= 8) {
532 for (relbit = 1; count-- != 0 && gap != 0; gap --, relbit <<=1)
534 if (relbit & mod_byte)
536 uint8e_type reloc = *src;
537 /* This item needs to be relocated */
538 switch (reloc & RELOCATION_TYPE_BITS) {
539 case RELOCATION_TYPE_ABS:
543 case RELOCATION_TYPE_REL:
545 /* Relocate the item relative to the section */
546 oasys_reloc_type *r =
549 sizeof(oasys_reloc_type));
550 *(per->reloc_tail_ptr) = r;
551 per->reloc_tail_ptr = &r->next;
552 r->next= (oasys_reloc_type *)NULL;
553 /* Reference to undefined symbol */
555 /* There is no symbol */
557 /* Work out the howto */
559 data->sections[reloc & RELOCATION_SECT_BITS];
560 r->relent.addend = - r->relent.section->vma;
561 r->relent.address = dst_ptr - dst_base_ptr;
562 r->relent.howto = &howto_table[reloc>>6];
563 r->relent.sym_ptr_ptr = (asymbol **)NULL;
564 section->reloc_count++;
566 /* Fake up the data to look like it's got the -ve pc in it, this makes
567 it much easier to convert into other formats. This is done by
570 if (r->relent.howto->pc_relative == true) {
571 r->relent.addend -= dst_ptr - dst_base_ptr;
579 case RELOCATION_TYPE_UND:
581 oasys_reloc_type *r =
584 sizeof(oasys_reloc_type));
585 *(per->reloc_tail_ptr) = r;
586 per->reloc_tail_ptr = &r->next;
587 r->next= (oasys_reloc_type *)NULL;
588 /* Reference to undefined symbol */
590 /* Get symbol number */
591 r->symbol = (src[0]<<8) | src[1];
592 /* Work out the howto */
593 r->relent.section = (asection *)NULL;
594 r->relent.addend = 0;
595 r->relent.address = dst_ptr - dst_base_ptr;
596 r->relent.howto = &howto_table[reloc>>6];
597 r->relent.sym_ptr_ptr = (asymbol **)NULL;
598 section->reloc_count++;
601 /* Fake up the data to look like it's got the -ve pc in it, this makes
602 it much easier to convert into other formats. This is done by
605 if (r->relent.howto->pc_relative == true) {
606 r->relent.addend -= dst_ptr - dst_base_ptr;
613 case RELOCATION_TYPE_COM:
623 case oasys_record_is_local_enum:
624 case oasys_record_is_symbol_enum:
625 case oasys_record_is_section_enum:
637 bfd_error_vector_type bfd_error_vector;
640 DEFUN(oasys_new_section_hook,(abfd, newsect),
644 newsect->used_by_bfd = (PTR)
645 bfd_alloc(abfd, sizeof(oasys_per_section_type));
646 oasys_per_section( newsect)->data = (bfd_byte *)NULL;
647 oasys_per_section(newsect)->section = newsect;
648 oasys_per_section(newsect)->offset = 0;
649 newsect->alignment_power = 3;
650 /* Turn the section string into an index */
652 sscanf(newsect->name,"%u", &newsect->target_index);
659 DEFUN(oasys_get_reloc_upper_bound, (abfd, asect),
663 oasys_slurp_section_data(abfd);
664 return (asect->reloc_count+1) * sizeof(arelent *);
668 DEFUN(oasys_get_section_contents,(abfd, section, location, offset, count),
675 oasys_per_section_type *p = (oasys_per_section_type *) section->used_by_bfd;
676 oasys_slurp_section_data(abfd);
677 (void) memcpy(location, p->data + offset, (int)count);
683 DEFUN(oasys_canonicalize_reloc,(abfd, section, relptr, symbols),
689 unsigned int reloc_count = 0;
690 oasys_reloc_type *src = (oasys_reloc_type *)(section->relocation);
691 while (src != (oasys_reloc_type *)NULL) {
692 if (src->relent.section == (asection *)NULL)
694 src->relent.sym_ptr_ptr = symbols + src->symbol;
696 *relptr ++ = &src->relent;
700 *relptr = (arelent *)NULL;
701 return section->reloc_count = reloc_count;
706 DEFUN(oasys_set_arch_mach, (abfd, arch, machine),
708 enum bfd_architecture arch AND
709 unsigned long machine)
711 abfd->obj_arch = arch;
712 abfd->obj_machine = machine;
721 /* Calculate the checksum and write one record */
723 DEFUN(oasys_write_record,(abfd, type, record, size),
725 CONST oasys_record_enum_type type AND
726 oasys_record_union_type *record AND
732 record->header.length = size;
733 record->header.type = type;
734 record->header.check_sum = 0;
735 record->header.fill = 0;
736 ptr = &record->pad[0];
738 for (i = 0; i < size; i++) {
741 record->header.check_sum = 0xff & (- checksum);
742 bfd_write((PTR)record, 1, size, abfd);
746 /* Write out all the symbols */
748 DEFUN(oasys_write_syms, (abfd),
752 asymbol **generic = bfd_get_outsymbols(abfd);
753 unsigned int index = 0;
754 for (count = 0; count < bfd_get_symcount(abfd); count++) {
756 oasys_symbol_record_type symbol;
757 asymbol * CONST g = generic[count];
759 CONST char *src = g->name;
760 char *dst = symbol.name;
763 if (g->flags & BSF_FORT_COMM) {
764 symbol.relb = RELOCATION_TYPE_COM;
765 bfd_h_put_16(abfd, index, (uint8e_type *)(&symbol.refno[0]));
768 else if (g->flags & BSF_ABSOLUTE) {
769 symbol.relb = RELOCATION_TYPE_ABS;
770 bfd_h_put_16(abfd, 0, (uint8e_type *)(&symbol.refno[0]));
773 else if (g->flags & BSF_UNDEFINED) {
774 symbol.relb = RELOCATION_TYPE_UND ;
775 bfd_h_put_16(abfd, index, (uint8e_type *)(&symbol.refno[0]));
776 /* Overload the value field with the output index number */
779 else if (g->flags & BSF_DEBUGGING) {
784 symbol.relb = RELOCATION_TYPE_REL | g->section->output_section->target_index;
785 bfd_h_put_16(abfd, 0, (uint8e_type *)(&symbol.refno[0]));
792 bfd_h_put_32(abfd, g->value, symbol.value);
795 if (g->flags & BSF_LOCAL) {
796 oasys_write_record(abfd,
797 oasys_record_is_local_enum,
798 (oasys_record_union_type *) &symbol,
799 offsetof(oasys_symbol_record_type, name[0]) + l);
802 oasys_write_record(abfd,
803 oasys_record_is_symbol_enum,
804 (oasys_record_union_type *) &symbol,
805 offsetof(oasys_symbol_record_type, name[0]) + l);
812 /* Write a section header for each section */
814 DEFUN(oasys_write_sections, (abfd),
818 static oasys_section_record_type out = {0};
820 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
821 if (!isdigit(s->name[0]))
823 bfd_error_vector.nonrepresentable_section(abfd,
826 out.relb = RELOCATION_TYPE_REL | s->target_index;
827 bfd_h_put_32(abfd, s->size, out.value);
828 bfd_h_put_32(abfd, s->vma, out.vma);
830 oasys_write_record(abfd,
831 oasys_record_is_section_enum,
832 (oasys_record_union_type *) &out,
838 DEFUN(oasys_write_header, (abfd),
841 /* Create and write the header */
842 oasys_header_record_type r;
843 size_t length = strlen(abfd->filename);
844 if (length > (size_t)sizeof(r.module_name)) {
845 length = sizeof(r.module_name);
848 (void)memcpy(r.module_name,
851 (void)memset(r.module_name + length,
853 sizeof(r.module_name) - length);
855 r.version_number = OASYS_VERSION_NUMBER;
856 r.rev_number = OASYS_REV_NUMBER;
857 oasys_write_record(abfd,
858 oasys_record_is_header_enum,
859 (oasys_record_union_type *)&r,
860 offsetof(oasys_header_record_type, description[0]));
867 DEFUN(oasys_write_end,(abfd),
870 oasys_end_record_type end;
871 uint8e_type null = 0;
872 end.relb = RELOCATION_TYPE_ABS;
873 bfd_h_put_32(abfd, abfd->start_address, end.entry);
874 bfd_h_put_16(abfd, 0, end.fill);
876 oasys_write_record(abfd,
877 oasys_record_is_end_enum,
878 (oasys_record_union_type *)&end,
880 bfd_write((PTR)&null, 1, 1, abfd);
888 arelent *a = *((arelent **)ap);
889 arelent *b = *((arelent **)bp);
890 return a->address - b->address;
898 DEFUN(oasys_write_data, (abfd),
902 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
903 uint8e_type *raw_data = oasys_per_section(s)->data;
904 oasys_data_record_type processed_data;
905 bfd_size_type current_byte_index = 0;
906 unsigned int relocs_to_go = s->reloc_count;
907 arelent **p = s->orelocation;
908 if (s->reloc_count != 0) {
909 /* Sort the reloc records so it's easy to insert the relocs into the
912 qsort(s->orelocation,
917 current_byte_index = 0;
918 processed_data.relb = s->target_index | RELOCATION_TYPE_REL;
920 while (current_byte_index < s->size)
922 /* Scan forwards by eight bytes or however much is left and see if
923 there are any relocations going on */
924 uint8e_type *mod = &processed_data.data[0];
925 uint8e_type *dst = &processed_data.data[1];
928 unsigned int long_length = 128;
931 bfd_h_put_32(abfd, s->vma + current_byte_index, processed_data.addr);
932 if ((size_t)(long_length + current_byte_index) > (size_t)(s->size)) {
933 long_length = s->size - current_byte_index;
935 while (long_length > 0 && (dst - (uint8e_type*)&processed_data < 128)) {
937 unsigned int length = long_length;
942 for (i = 0; i < length; i++) {
943 if (relocs_to_go != 0) {
945 reloc_howto_type *CONST how=r->howto;
946 /* There is a relocation, is it for this byte ? */
947 if (r->address == current_byte_index) {
948 uint8e_type rel_byte;
953 if(how->pc_relative) {
956 /* Also patch the raw data so that it doesn't have
957 the -ve stuff any more */
958 if (how->size != 2) {
960 bfd_get_16(abfd,raw_data) +
961 current_byte_index, raw_data);
966 bfd_get_32(abfd,raw_data) +
967 current_byte_index, raw_data);
977 /* Is this a section relative relocation, or a symbol
978 relative relocation ? */
979 if (r->section != (asection*)NULL)
981 /* The relent has a section attatched, so it must be section
983 rel_byte |= RELOCATION_TYPE_REL;
984 rel_byte |= r->section->output_section->target_index;
989 asymbol *p = *(r->sym_ptr_ptr);
991 /* If this symbol has a section attatched, then it
992 has already been resolved. Change from a symbol
993 ref to a section ref */
994 if(p->section != (asection *)NULL) {
995 rel_byte |= RELOCATION_TYPE_REL;
997 p->section->output_section->target_index;
1001 rel_byte |= RELOCATION_TYPE_UND;
1005 /* Next two bytes are a symbol index - we can get
1006 this from the symbol value which has been zapped
1007 into the symbol index in the table when the
1008 symbol table was written
1010 *dst++ = p->value >> 8;
1017 /* If this is coming from an unloadable section then copy
1019 if (raw_data == (uint8e_type *)NULL) {
1023 *dst++ = *raw_data++;
1025 current_byte_index++;
1028 long_length -= length;
1031 oasys_write_record(abfd,
1032 oasys_record_is_data_enum,
1033 (oasys_record_union_type *)&processed_data,
1034 dst - (uint8e_type*)&processed_data);
1040 DEFUN(oasys_write_object_contents, (abfd),
1043 oasys_write_header(abfd);
1044 oasys_write_syms(abfd);
1045 oasys_write_sections(abfd);
1046 oasys_write_data(abfd);
1047 oasys_write_end(abfd);
1054 /** exec and core file sections */
1056 /* set section contents is complicated with OASYS since the format is
1057 * not a byte image, but a record stream.
1060 DEFUN(oasys_set_section_contents,(abfd, section, location, offset, count),
1065 bfd_size_type count)
1068 if (oasys_per_section(section)->data == (bfd_byte *)NULL )
1070 oasys_per_section(section)->data =
1071 (bfd_byte *)(bfd_alloc(abfd,section->size));
1073 (void) memcpy(oasys_per_section(section)->data + offset,
1082 /* Native-level interface to symbols. */
1084 /* We read the symbols into a buffer, which is discarded when this
1085 function exits. We read the strings into a buffer large enough to
1086 hold them all plus all the cached symbol entries. */
1089 DEFUN(oasys_make_empty_symbol,(abfd),
1093 oasys_symbol_type *new =
1094 (oasys_symbol_type *)bfd_zalloc (abfd, sizeof (oasys_symbol_type));
1095 new->symbol.the_bfd = abfd;
1096 return &new->symbol;
1103 /* User should have checked the file flags; perhaps we should return
1104 BFD_NO_MORE_SYMBOLS if there are none? */
1107 oasys_openr_next_archived_file(arch, prev)
1111 oasys_ar_data_type *ar = oasys_ar_data(arch);
1112 oasys_module_info_type *p;
1113 /* take the next one from the arch state, or reset */
1114 if (prev == (bfd *)NULL) {
1115 /* Reset the index - the first two entries are bogus*/
1116 ar->module_index = 0;
1119 p = ar->module + ar->module_index;
1122 if (ar->module_index <= ar->module_count) {
1123 if (p->abfd == (bfd *)NULL) {
1124 p->abfd = _bfd_create_empty_archive_element_shell(arch);
1125 p->abfd->origin = p->pos;
1126 p->abfd->filename = p->name;
1128 /* Fixup a pointer to this element for the member */
1129 p->abfd->arelt_data = (PTR)p;
1134 bfd_error = no_more_archived_files;
1140 oasys_find_nearest_line(abfd,
1151 char **filename_ptr;
1152 char **functionname_ptr;
1153 unsigned int *line_ptr;
1160 DEFUN(oasys_generic_stat_arch_elt,(abfd, buf),
1164 oasys_module_info_type *mod = (oasys_module_info_type *) abfd->arelt_data;
1165 if (mod == (oasys_module_info_type *)NULL) {
1166 bfd_error = invalid_operation;
1170 buf->st_size = mod->size;
1171 buf->st_mode = 0666;
1177 DEFUN(oasys_sizeof_headers,(abfd, exec),
1184 #define oasys_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
1185 #define oasys_core_file_failing_signal (int (*)())bfd_0
1186 #define oasys_core_file_matches_executable_p 0 /*(PROTO(boolean, (*),(bfd*, bfd*)))bfd_false*/
1187 #define oasys_slurp_armap bfd_true
1188 #define oasys_slurp_extended_name_table bfd_true
1189 #define oasys_truncate_arname (void (*)())bfd_nullvoidptr
1190 #define oasys_write_armap 0 /* (PROTO( boolean, (*),(bfd *, unsigned int, struct orl *, int, int))) bfd_nullvoidptr*/
1191 #define oasys_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
1192 #define oasys_close_and_cleanup bfd_generic_close_and_cleanup
1197 bfd_target oasys_vec =
1200 bfd_target_oasys_flavour_enum,
1201 true, /* target byte order */
1202 true, /* target headers byte order */
1203 (HAS_RELOC | EXEC_P | /* object flags */
1204 HAS_LINENO | HAS_DEBUG |
1205 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
1206 (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
1207 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1208 ' ', /* ar_pad_char */
1209 16, /* ar_max_namelen */
1211 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
1212 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
1215 oasys_object_p, /* bfd_check_format */
1219 { /* bfd_set_format */
1222 _bfd_generic_mkarchive,
1225 { /* bfd_write_contents */
1227 oasys_write_object_contents,
1228 _bfd_write_archive_contents,