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)
36 DEFUN(oasys_read_record,(abfd, record),
38 oasys_record_union_type *record)
41 bfd_read(record, 1, sizeof(record->header), abfd);
43 if ((size_t) record->header.length <= (size_t) sizeof (record->header))
45 bfd_read(((char *)record )+ sizeof(record->header),
46 1, record->header.length - sizeof(record->header),
50 DEFUN(oasys_string_length,(record),
51 oasys_record_union_type *record)
53 return record->header.length
54 - ((char *)record->symbol.name - (char *)record);
57 /*****************************************************************************/
61 Slurp the symbol table by reading in all the records at the start file
62 till we get to the first section record.
64 We'll sort the symbolss into two lists, defined and undefined. The
65 undefined symbols will be placed into the table according to their
68 We do this by placing all undefined symbols at the front of the table
69 moving in, and the defined symbols at the end of the table moving back.
74 DEFUN(oasys_slurp_symbol_table,(abfd),
77 oasys_record_union_type record;
78 oasys_data_type *data = oasys_data(abfd);
80 asymbol *dest_undefined;
81 asymbol *dest_defined;
86 if (data->symbols != (asymbol *)NULL) {
89 /* Buy enough memory for all the symbols and all the names */
91 (asymbol *)bfd_alloc(abfd, sizeof(asymbol) * abfd->symcount);
92 #ifdef UNDERSCORE_HACK
93 /* buy 1 more char for each symbol to keep the underscore in*/
94 data->strings = bfd_alloc(abfd, data->symbol_string_length +
97 data->strings = bfd_alloc(abfd, data->symbol_string_length);
100 dest_undefined = data->symbols;
101 dest_defined = data->symbols + abfd->symcount -1;
103 string_ptr = data->strings;
104 bfd_seek(abfd, (file_ptr)0, SEEK_SET);
107 oasys_read_record(abfd, &record);
108 switch (record.header.type) {
109 case oasys_record_is_header_enum:
111 case oasys_record_is_local_enum:
112 case oasys_record_is_symbol_enum:
114 int flag = record.header.type == oasys_record_is_local_enum ?
115 (BSF_LOCAL) : (BSF_GLOBAL | BSF_EXPORT);
118 size_t length = oasys_string_length(&record);
119 switch (record.symbol.relb & RELOCATION_TYPE_BITS) {
120 case RELOCATION_TYPE_ABS:
121 dest = dest_defined--;
123 dest->flags = BSF_ABSOLUTE | flag;
125 case RELOCATION_TYPE_REL:
126 dest = dest_defined--;
128 oasys_data(abfd)->sections[record.symbol.relb &
129 RELOCATION_SECT_BITS];
130 if (record.header.type == oasys_record_is_local_enum)
132 dest->flags = BSF_LOCAL;
139 case RELOCATION_TYPE_UND:
140 dest = data->symbols + bfd_h_getshort(abfd, &record.symbol.refno[0]);
141 dest->section = (asection *)NULL;
142 dest->flags = BSF_UNDEFINED;
144 case RELOCATION_TYPE_COM:
145 dest = dest_defined--;
146 dest->name = string_ptr;
147 dest->the_bfd = abfd;
149 dest->section = (asection *)NULL;
150 dest->flags = BSF_FORT_COMM;
153 dest->name = string_ptr;
154 dest->the_bfd = abfd;
155 dest->udata = (PTR)NULL;
156 dest->value = bfd_h_getlong(abfd, &record.symbol.value[0]);
158 #ifdef UNDERSCORE_HACK
159 if (record.symbol.name[0] != '_') {
164 memcpy(string_ptr, record.symbol.name, length);
167 string_ptr[length] =0;
168 string_ptr += length +1;
180 DEFUN(oasys_get_symtab_upper_bound,(abfd),
183 oasys_slurp_symbol_table (abfd);
185 return (abfd->symcount+1) * (sizeof (oasys_symbol_type *));
191 extern bfd_target oasys_vec;
194 DEFUN(oasys_get_symtab,(abfd, location),
199 unsigned int counter ;
200 if (oasys_slurp_symbol_table(abfd) == false) {
203 symbase = oasys_data(abfd)->symbols;
204 for (counter = 0; counter < abfd->symcount; counter++) {
205 *(location++) = symbase++;
208 return abfd->symcount;
211 /***********************************************************************
214 #define swap(x) x = bfd_h_get_x(abfd, &x);
216 DEFUN(oasys_archive_p,(abfd),
219 oasys_archive_header_type header;
222 bfd_seek(abfd, (file_ptr) 0, false);
225 bfd_read(&header, 1, sizeof(header), abfd);
228 swap(header.version);
229 swap(header.mod_count);
230 swap(header.mod_tbl_offset);
231 swap(header.sym_tbl_size);
232 swap(header.sym_count);
233 swap(header.sym_tbl_offset);
234 swap(header.xref_count);
235 swap(header.xref_lst_offset);
238 There isn't a magic number in an Oasys archive, so the best we
239 can do to verify reasnableness is to make sure that the values in
240 the header are too weird
243 if (header.version>10000 ||
244 header.mod_count>10000 ||
245 header.sym_count>100000 ||
246 header.xref_count > 100000) return (bfd_target *)NULL;
249 That all worked, lets buy the space for the header and read in
253 oasys_ar_data_type *ar =
254 (oasys_ar_data_type*) bfd_alloc(abfd, sizeof(oasys_ar_data_type));
257 oasys_module_info_type *module =
258 (oasys_module_info_type*)
259 bfd_alloc(abfd, sizeof(oasys_module_info_type) * header.mod_count);
261 oasys_module_table_type record;
265 ar->module_count = header.mod_count;
267 bfd_seek(abfd , header.mod_tbl_offset, SEEK_SET);
268 for (i = 0; i < header.mod_count; i++) {
270 bfd_read(&record, 1, sizeof(record), abfd);
271 swap(record.mod_size);
272 swap(record.file_offset);
273 swap(record.mod_name_length);
274 module[i].name = bfd_alloc(abfd,record.mod_name_length+1);
276 bfd_read(module[i].name, 1, record.mod_name_length +1, abfd);
277 /* SKip some stuff */
278 bfd_seek(abfd, record.dep_count * sizeof(int32_type),
281 module[i].size = record.mod_size;
282 module[i].pos = record.file_offset;
290 DEFUN(oasys_mkobject,(abfd),
293 oasys_data_type *oasys;
296 (oasys_data_type*)bfd_alloc(abfd, sizeof(oasys_data_type)));
297 oasys = oasys_data(abfd);
303 DEFUN(oasys_object_p,(abfd),
306 oasys_data_type *oasys;
308 boolean had_usefull = false;
311 oasys_mkobject(abfd);
312 oasys = oasys_data(abfd);
313 memset((PTR)oasys->sections, 0xff, sizeof(oasys->sections));
315 /* Point to the start of the file */
316 bfd_seek(abfd, (file_ptr)0, SEEK_SET);
317 oasys->symbol_string_length = 0;
318 /* Inspect the records, but only keep the section info -
319 remember the size of the symbols
321 oasys->first_data_record = 0;
323 oasys_record_union_type record;
324 oasys_read_record(abfd, &record);
325 if ((size_t)record.header.length < (size_t)sizeof(record.header))
329 switch ((oasys_record_enum_type)(record.header.type)) {
330 case oasys_record_is_header_enum:
333 case oasys_record_is_symbol_enum:
334 case oasys_record_is_local_enum:
335 /* Count symbols and remember their size for a future malloc */
337 oasys->symbol_string_length += 1 + oasys_string_length(&record);
340 case oasys_record_is_section_enum:
344 unsigned int section_number;
345 if (record.section.header.length != sizeof(record.section))
349 buffer = bfd_alloc(abfd, 3);
350 section_number= record.section.relb & RELOCATION_SECT_BITS;
351 sprintf(buffer,"%u", section_number);
352 s = bfd_make_section(abfd,buffer);
353 oasys->sections[section_number] = s;
354 switch (record.section.relb & RELOCATION_TYPE_BITS) {
355 case RELOCATION_TYPE_ABS:
356 case RELOCATION_TYPE_REL:
358 case RELOCATION_TYPE_UND:
359 case RELOCATION_TYPE_COM:
363 s->size = bfd_h_getlong(abfd, & record.section.value[0]) ;
364 s->vma = bfd_h_getlong(abfd, &record.section.vma[0]);
365 s->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
369 case oasys_record_is_data_enum:
370 oasys->first_data_record = bfd_tell(abfd) - record.header.length;
371 case oasys_record_is_debug_enum:
372 case oasys_record_is_module_enum:
373 case oasys_record_is_named_section_enum:
374 case oasys_record_is_end_enum:
375 if (had_usefull == false) goto fail;
382 oasys->symbols = (asymbol *)NULL;
384 Oasys support several architectures, but I can't see a simple way
385 to discover which one is in a particular file - we'll guess
387 abfd->obj_arch = bfd_arch_m68k;
388 abfd->obj_machine =0;
389 if (abfd->symcount != 0) {
390 abfd->flags |= HAS_SYMS;
395 (void) bfd_release(abfd, oasys);
396 return (bfd_target *)NULL;
401 DEFUN(oasys_print_symbol,(ignore_abfd, file, symbol, how),
405 bfd_print_symbol_enum_type how)
408 case bfd_print_symbol_name_enum:
409 case bfd_print_symbol_type_enum:
410 fprintf(file,"%s", symbol->name);
412 case bfd_print_symbol_all_enum:
414 CONST char *section_name = symbol->section == (asection *)NULL ?
415 "*abs" : symbol->section->name;
417 bfd_print_symbol_vandf((PTR)file,symbol);
419 fprintf(file," %-5s %s",
427 The howto table is build using the top two bits of a reloc byte to
428 index into it. The bits are PCREL,WORD/LONG
430 static reloc_howto_type howto_table[]=
433 HOWTO( 0, 0, 1, 16, false,0, true,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false),
434 HOWTO( 0, 0, 2, 32, false,0, true,true,0,"abs32",true,0xffffffff, 0xffffffff,false),
435 HOWTO( 0, 0, 1, 16, true,0, true,true,0,"pcrel16",true,0x0000ffff, 0x0000ffff,false),
436 HOWTO( 0, 0, 2, 32, true,0, true,true,0,"pcrel32",true,0xffffffff, 0xffffffff,false)
439 /* Read in all the section data and relocation stuff too */
441 DEFUN(oasys_slurp_section_data,(abfd),
444 oasys_record_union_type record;
445 oasys_data_type *data = oasys_data(abfd);
448 oasys_per_section_type *per ;
452 /* Buy enough memory for all the section data and relocations */
453 for (s = abfd->sections; s != (asection *)NULL; s= s->next) {
454 per = oasys_per_section(s);
455 if (per->data != (bfd_byte*)NULL) return true;
456 per->data = (bfd_byte *) bfd_alloc(abfd, s->size);
457 per->reloc_tail_ptr = (oasys_reloc_type **)&(s->relocation);
458 per->had_vma = false;
462 if (data->first_data_record == 0) return true;
463 bfd_seek(abfd, data->first_data_record, SEEK_SET);
465 oasys_read_record(abfd, &record);
466 switch (record.header.type) {
467 case oasys_record_is_header_enum:
469 case oasys_record_is_data_enum:
472 uint8e_type *src = record.data.data;
473 uint8e_type *end_src = ((uint8e_type *)&record) +
474 record.header.length;
477 bfd_byte *dst_base_ptr ;
480 data->sections[record.data.relb & RELOCATION_SECT_BITS];
482 per = oasys_per_section(section);
483 dst_offset = bfd_h_getlong(abfd, record.data.addr) ;
484 if (per->had_vma == false) {
485 /* Take the first vma we see as the base */
487 section->vma = dst_offset;
492 dst_offset -= section->vma;
495 dst_base_ptr = oasys_per_section(section)->data;
496 dst_ptr = oasys_per_section(section)->data +
499 while (src < end_src) {
500 uint32_type gap = end_src - src -1;
501 uint8e_type mod_byte = *src++;
503 if (mod_byte == 0 && gap >= 8) {
516 for (relbit = 1; count-- != 0 && gap != 0; gap --, relbit <<=1)
518 if (relbit & mod_byte)
520 uint8e_type reloc = *src;
521 /* This item needs to be relocated */
522 switch (reloc & RELOCATION_TYPE_BITS) {
523 case RELOCATION_TYPE_ABS:
527 case RELOCATION_TYPE_REL:
529 /* Relocate the item relative to the section */
530 oasys_reloc_type *r =
533 sizeof(oasys_reloc_type));
534 *(per->reloc_tail_ptr) = r;
535 per->reloc_tail_ptr = &r->next;
536 r->next= (oasys_reloc_type *)NULL;
537 /* Reference to undefined symbol */
539 /* There is no symbol */
541 /* Work out the howto */
543 data->sections[reloc & RELOCATION_SECT_BITS];
544 r->relent.addend = - r->relent.section->vma;
545 r->relent.address = dst_ptr - dst_base_ptr;
546 r->relent.howto = &howto_table[reloc>>6];
547 r->relent.sym_ptr_ptr = (asymbol **)NULL;
548 section->reloc_count++;
550 /* Fake up the data to look like it's got the -ve pc in it, this makes
551 it much easier to convert into other formats. This is done by
554 if (r->relent.howto->pc_relative == true) {
555 r->relent.addend -= dst_ptr - dst_base_ptr;
563 case RELOCATION_TYPE_UND:
565 oasys_reloc_type *r =
568 sizeof(oasys_reloc_type));
569 *(per->reloc_tail_ptr) = r;
570 per->reloc_tail_ptr = &r->next;
571 r->next= (oasys_reloc_type *)NULL;
572 /* Reference to undefined symbol */
574 /* Get symbol number */
575 r->symbol = (src[0]<<8) | src[1];
576 /* Work out the howto */
577 r->relent.section = (asection *)NULL;
578 r->relent.addend = 0;
579 r->relent.address = dst_ptr - dst_base_ptr;
580 r->relent.howto = &howto_table[reloc>>6];
581 r->relent.sym_ptr_ptr = (asymbol **)NULL;
582 section->reloc_count++;
585 /* Fake up the data to look like it's got the -ve pc in it, this makes
586 it much easier to convert into other formats. This is done by
589 if (r->relent.howto->pc_relative == true) {
590 r->relent.addend -= dst_ptr - dst_base_ptr;
597 case RELOCATION_TYPE_COM:
607 case oasys_record_is_local_enum:
608 case oasys_record_is_symbol_enum:
609 case oasys_record_is_section_enum:
621 bfd_error_vector_type bfd_error_vector;
624 DEFUN(oasys_new_section_hook,(abfd, newsect),
628 newsect->used_by_bfd = (PTR)
629 bfd_alloc(abfd, sizeof(oasys_per_section_type));
630 oasys_per_section( newsect)->data = (bfd_byte *)NULL;
631 oasys_per_section(newsect)->section = newsect;
632 oasys_per_section(newsect)->offset = 0;
633 newsect->alignment_power = 3;
634 /* Turn the section string into an index */
636 sscanf(newsect->name,"%u", &newsect->target_index);
643 DEFUN(oasys_get_reloc_upper_bound, (abfd, asect),
647 oasys_slurp_section_data(abfd);
648 return (asect->reloc_count+1) * sizeof(arelent *);
652 DEFUN(oasys_get_section_contents,(abfd, section, location, offset, count),
659 oasys_per_section_type *p = (oasys_per_section_type *) section->used_by_bfd;
660 oasys_slurp_section_data(abfd);
661 (void) memcpy(location, p->data + offset, count);
667 DEFUN(oasys_canonicalize_reloc,(abfd, section, relptr, symbols),
673 unsigned int reloc_count = 0;
674 oasys_reloc_type *src = (oasys_reloc_type *)(section->relocation);
675 while (src != (oasys_reloc_type *)NULL) {
676 if (src->relent.section == (asection *)NULL)
678 src->relent.sym_ptr_ptr = symbols + src->symbol;
680 *relptr ++ = &src->relent;
684 *relptr = (arelent *)NULL;
685 return section->reloc_count = reloc_count;
690 DEFUN(oasys_set_arch_mach, (abfd, arch, machine),
692 enum bfd_architecture arch AND
693 unsigned long machine)
695 abfd->obj_arch = arch;
696 abfd->obj_machine = machine;
705 /* Calculate the checksum and write one record */
707 DEFUN(oasys_write_record,(abfd, type, record, size),
709 CONST oasys_record_enum_type type AND
710 oasys_record_union_type *record AND
716 record->header.length = size;
717 record->header.type = type;
718 record->header.check_sum = 0;
719 record->header.fill = 0;
720 ptr = &record->pad[0];
722 for (i = 0; i < size; i++) {
725 record->header.check_sum = 0xff & (- checksum);
726 bfd_write((PTR)record, 1, size, abfd);
730 /* Write out all the symbols */
732 DEFUN(oasys_write_syms, (abfd),
736 asymbol **generic = bfd_get_outsymbols(abfd);
737 unsigned int index = 0;
738 for (count = 0; count < bfd_get_symcount(abfd); count++) {
740 oasys_symbol_record_type symbol;
741 asymbol * CONST g = generic[count];
743 CONST char *src = g->name;
744 char *dst = symbol.name;
747 if (g->flags & BSF_FORT_COMM) {
748 symbol.relb = RELOCATION_TYPE_COM;
749 bfd_h_putshort(abfd, index, (uint8e_type *)(&symbol.refno[0]));
752 else if (g->flags & BSF_ABSOLUTE) {
753 symbol.relb = RELOCATION_TYPE_ABS;
754 bfd_h_putshort(abfd, 0, (uint8e_type *)(&symbol.refno[0]));
757 else if (g->flags & BSF_UNDEFINED) {
758 symbol.relb = RELOCATION_TYPE_UND ;
759 bfd_h_putshort(abfd, index, (uint8e_type *)(&symbol.refno[0]));
760 /* Overload the value field with the output index number */
763 else if (g->flags & BSF_DEBUGGING) {
768 symbol.relb = RELOCATION_TYPE_REL | g->section->output_section->target_index;
769 bfd_h_putshort(abfd, 0, (uint8e_type *)(&symbol.refno[0]));
776 bfd_h_putlong(abfd, g->value, symbol.value);
779 if (g->flags & BSF_LOCAL) {
780 oasys_write_record(abfd,
781 oasys_record_is_local_enum,
782 (oasys_record_union_type *) &symbol,
783 offsetof(oasys_symbol_record_type, name[0]) + l);
786 oasys_write_record(abfd,
787 oasys_record_is_symbol_enum,
788 (oasys_record_union_type *) &symbol,
789 offsetof(oasys_symbol_record_type, name[0]) + l);
796 /* Write a section header for each section */
798 DEFUN(oasys_write_sections, (abfd),
802 static oasys_section_record_type out = {0};
804 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
805 if (!isdigit(s->name[0]))
807 bfd_error_vector.nonrepresentable_section(abfd,
810 out.relb = RELOCATION_TYPE_REL | s->target_index;
811 bfd_h_putlong(abfd, s->size, out.value);
812 bfd_h_putlong(abfd, s->vma, out.vma);
814 oasys_write_record(abfd,
815 oasys_record_is_section_enum,
816 (oasys_record_union_type *) &out,
822 DEFUN(oasys_write_header, (abfd),
825 /* Create and write the header */
826 oasys_header_record_type r;
827 size_t length = strlen(abfd->filename);
828 if (length > (size_t)sizeof(r.module_name)) {
829 length = sizeof(r.module_name);
832 (void)memcpy(r.module_name,
835 (void)memset(r.module_name + length,
837 sizeof(r.module_name) - length);
839 r.version_number = OASYS_VERSION_NUMBER;
840 r.rev_number = OASYS_REV_NUMBER;
841 oasys_write_record(abfd,
842 oasys_record_is_header_enum,
843 (oasys_record_union_type *)&r,
844 offsetof(oasys_header_record_type, description[0]));
851 DEFUN(oasys_write_end,(abfd),
854 oasys_end_record_type end;
855 end.relb = RELOCATION_TYPE_ABS;
856 bfd_h_putlong(abfd, abfd->start_address, end.entry);
857 bfd_h_putshort(abfd, 0, end.fill);
859 oasys_write_record(abfd,
860 oasys_record_is_end_enum,
861 (oasys_record_union_type *)&end,
870 arelent *a = *((arelent **)ap);
871 arelent *b = *((arelent **)bp);
872 return a->address - b->address;
880 DEFUN(oasys_write_data, (abfd),
884 for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
885 uint8e_type *raw_data = oasys_per_section(s)->data;
886 oasys_data_record_type processed_data;
887 unsigned int current_byte_index = 0;
888 unsigned int relocs_to_go = s->reloc_count;
889 arelent **p = s->orelocation;
890 if (s->reloc_count != 0) {
891 /* Sort the reloc records so it's easy to insert the relocs into the
894 qsort(s->orelocation,
899 current_byte_index = 0;
900 processed_data.relb = s->target_index | RELOCATION_TYPE_REL;
902 while ((size_t)current_byte_index < s->size)
904 /* Scan forwards by eight bytes or however much is left and see if
905 there are any relocations going on */
906 uint8e_type *mod = &processed_data.data[0];
907 uint8e_type *dst = &processed_data.data[1];
910 unsigned int long_length = 128;
913 bfd_h_putlong(abfd, s->vma + current_byte_index, processed_data.addr);
914 if ((size_t)(long_length + current_byte_index) > (size_t)(s->size)) {
915 long_length = s->size - current_byte_index;
917 while (long_length > 0 && (dst - (uint8e_type*)&processed_data < 128)) {
919 unsigned int length = long_length;
924 for (i = 0; i < length; i++) {
925 if (relocs_to_go != 0) {
927 reloc_howto_type *CONST how=r->howto;
928 /* There is a relocation, is it for this byte ? */
929 if (r->address == current_byte_index) {
930 uint8e_type rel_byte;
935 if(how->pc_relative) {
938 /* Also patch the raw data so that it doesn't have
939 the -ve stuff any more */
940 if (how->size != 2) {
942 bfd_getshort(abfd,raw_data) +
943 current_byte_index, raw_data);
948 bfd_getlong(abfd,raw_data) +
949 current_byte_index, raw_data);
959 /* Is this a section relative relocation, or a symbol
960 relative relocation ? */
961 if (r->section != (asection*)NULL)
963 /* The relent has a section attatched, so it must be section
965 rel_byte |= RELOCATION_TYPE_REL;
966 rel_byte |= r->section->output_section->target_index;
971 asymbol *p = *(r->sym_ptr_ptr);
973 /* If this symbol has a section attatched, then it
974 has already been resolved. Change from a symbol
975 ref to a section ref */
976 if(p->section != (asection *)NULL) {
977 rel_byte |= RELOCATION_TYPE_REL;
979 p->section->output_section->target_index;
983 rel_byte |= RELOCATION_TYPE_UND;
987 /* Next two bytes are a symbol index - we can get
988 this from the symbol value which has been zapped
989 into the symbol index in the table when the
990 symbol table was written
992 *dst++ = p->value >> 8;
999 /* If this is coming from an unloadable section then copy
1001 if (raw_data == (uint8e_type *)NULL) {
1005 *dst++ = *raw_data++;
1007 current_byte_index++;
1010 long_length -= length;
1013 oasys_write_record(abfd,
1014 oasys_record_is_data_enum,
1015 (oasys_record_union_type *)&processed_data,
1016 dst - (uint8e_type*)&processed_data);
1022 DEFUN(oasys_write_object_contents, (abfd),
1025 oasys_write_header(abfd);
1026 oasys_write_syms(abfd);
1027 oasys_write_sections(abfd);
1028 oasys_write_data(abfd);
1029 oasys_write_end(abfd);
1036 /** exec and core file sections */
1038 /* set section contents is complicated with OASYS since the format is
1039 * not a byte image, but a record stream.
1042 DEFUN(oasys_set_section_contents,(abfd, section, location, offset, count),
1045 unsigned char *location AND
1050 if (oasys_per_section(section)->data == (bfd_byte *)NULL )
1052 oasys_per_section(section)->data =
1053 (bfd_byte *)(bfd_alloc(abfd,section->size));
1055 (void) memcpy(oasys_per_section(section)->data + offset,
1064 /* Native-level interface to symbols. */
1066 /* We read the symbols into a buffer, which is discarded when this
1067 function exits. We read the strings into a buffer large enough to
1068 hold them all plus all the cached symbol entries. */
1071 DEFUN(oasys_make_empty_symbol,(abfd),
1075 oasys_symbol_type *new =
1076 (oasys_symbol_type *)bfd_zalloc (abfd, sizeof (oasys_symbol_type));
1077 new->symbol.the_bfd = abfd;
1078 return &new->symbol;
1084 /* Obsbolete procedural interface; better to look at the cache directly */
1086 /* User should have checked the file flags; perhaps we should return
1087 BFD_NO_MORE_SYMBOLS if there are none? */
1092 oasys_close_and_cleanup (abfd)
1095 if (bfd_read_p (abfd) == false)
1096 switch (abfd->format) {
1098 if (!_bfd_write_archive_contents (abfd)) {
1103 if (!oasys_write_object_contents (abfd)) {
1108 bfd_error = invalid_operation;
1118 oasys_openr_next_archived_file(arch, prev)
1122 oasys_ar_data_type *ar = oasys_ar_data(arch);
1123 oasys_module_info_type *p;
1124 /* take the next one from the arch state, or reset */
1125 if (prev == (bfd *)NULL) {
1126 /* Reset the index - the first two entries are bogus*/
1127 ar->module_index = 0;
1130 p = ar->module + ar->module_index;
1133 if (ar->module_index <= ar->module_count) {
1134 if (p->abfd == (bfd *)NULL) {
1135 p->abfd = _bfd_create_empty_archive_element_shell(arch);
1136 p->abfd->origin = p->pos;
1137 p->abfd->filename = p->name;
1139 /* Fixup a pointer to this element for the member */
1140 p->abfd->arelt_data = (PTR)p;
1145 bfd_error = no_more_archived_files;
1151 oasys_find_nearest_line(abfd,
1162 char **filename_ptr;
1163 char **functionname_ptr;
1164 unsigned int *line_ptr;
1171 DEFUN(oasys_generic_stat_arch_elt,(abfd, buf),
1175 oasys_module_info_type *mod = (oasys_module_info_type *) abfd->arelt_data;
1176 if (mod == (oasys_module_info_type *)NULL) {
1177 bfd_error = invalid_operation;
1181 buf->st_size = mod->size;
1182 buf->st_mode = 0666;
1188 DEFUN(oasys_sizeof_headers,(abfd),
1194 #define oasys_core_file_failing_command bfd_false
1195 #define oasys_core_file_failing_signal bfd_false
1196 #define oasys_core_file_matches_executable_p bfd_false
1197 #define oasys_slurp_armap bfd_false
1198 #define oasys_slurp_extended_name_table bfd_false
1199 #define oasys_truncate_arname bfd_false
1200 #define oasys_write_armap bfd_false
1201 #define oasys_get_lineno bfd_false
1206 bfd_target oasys_vec =
1209 bfd_target_oasys_flavour_enum,
1210 true, /* target byte order */
1211 true, /* target headers byte order */
1212 (HAS_RELOC | EXEC_P | /* object flags */
1213 HAS_LINENO | HAS_DEBUG |
1214 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
1215 (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
1216 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1217 ' ', /* ar_pad_char */
1218 16, /* ar_max_namelen */
1220 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* data */
1221 _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* hdrs */
1224 oasys_object_p, /* bfd_check_format */
1231 _bfd_generic_mkarchive,