-#define MAX_SECS 16
-static bfd_target *
-DEFUN(oasys_object_p,(abfd),
- bfd *abfd)
-{
- oasys_data_type *oasys;
- oasys_data_type *save = oasys_data(abfd);
- boolean loop = true;
- boolean had_usefull = false;
-
- set_tdata (abfd, 0);
- oasys_mkobject(abfd);
- oasys = oasys_data(abfd);
- memset((PTR)oasys->sections, 0xff, sizeof(oasys->sections));
-
- /* Point to the start of the file */
- bfd_seek(abfd, (file_ptr)0, SEEK_SET);
- oasys->symbol_string_length = 0;
- /* Inspect the records, but only keep the section info -
- remember the size of the symbols
- */
- oasys->first_data_record = 0;
- while (loop) {
- oasys_record_union_type record;
- oasys_read_record(abfd, &record);
- if ((size_t)record.header.length < (size_t)sizeof(record.header))
- goto fail;
-
-
- switch ((oasys_record_enum_type)(record.header.type)) {
- case oasys_record_is_header_enum:
- had_usefull = true;
- break;
- case oasys_record_is_symbol_enum:
- case oasys_record_is_local_enum:
- /* Count symbols and remember their size for a future malloc */
- abfd->symcount++;
- oasys->symbol_string_length += 1 + oasys_string_length(&record);
- had_usefull = true;
- break;
- case oasys_record_is_section_enum:
- {
- asection *s;
- char *buffer;
- unsigned int section_number;
- if (record.section.header.length != sizeof(record.section))
- {
- goto fail;
- }
- buffer = bfd_alloc(abfd, 3);
- section_number= record.section.relb & RELOCATION_SECT_BITS;
- sprintf(buffer,"%u", section_number);
- s = bfd_make_section(abfd,buffer);
- oasys->sections[section_number] = s;
- switch (record.section.relb & RELOCATION_TYPE_BITS) {
- case RELOCATION_TYPE_ABS:
- case RELOCATION_TYPE_REL:
- break;
- case RELOCATION_TYPE_UND:
- case RELOCATION_TYPE_COM:
- BFD_FAIL();
- }
-
- s->size = bfd_h_get_32(abfd, (bfd_byte *) & record.section.value[0]) ;
- s->vma = bfd_h_get_32(abfd, (bfd_byte *)&record.section.vma[0]);
- s->flags= 0;
- had_usefull = true;
- }
- break;
- case oasys_record_is_data_enum:
- oasys->first_data_record = bfd_tell(abfd) - record.header.length;
- case oasys_record_is_debug_enum:
- case oasys_record_is_module_enum:
- case oasys_record_is_named_section_enum:
- case oasys_record_is_end_enum:
- if (had_usefull == false) goto fail;
- loop = false;
- break;
- default:
- goto fail;
- }
- }
- oasys->symbols = (asymbol *)NULL;
- /*
- Oasys support several architectures, but I can't see a simple way
- to discover which one is in a particular file - we'll guess
- */
- abfd->obj_arch = bfd_arch_m68k;
- abfd->obj_machine =0;
- if (abfd->symcount != 0) {
- abfd->flags |= HAS_SYMS;
- }
-
- /*
- We don't know if a section has data until we've read it..
- */
-
- oasys_slurp_section_data(abfd);
-
-
- return abfd->xvec;
-
- fail:
- (void) bfd_release(abfd, oasys);
- set_tdata (abfd, save);
- return (bfd_target *)NULL;