⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ieee.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
      ){  /* Need a new symbol */  unsigned int new_index = must_parse_int(&(ieee->h));  if (new_index != last_index) {    ieee_symbol_type  *   new_symbol = (ieee_symbol_type *)bfd_alloc(ieee->h.abfd,								     sizeof(ieee_symbol_type));    new_symbol->index = new_index;    last_index = new_index;    ( *symbol_count)++;	    ** pptr= new_symbol;    *pptr = &new_symbol->next;    if (new_index > *max_index) {      *max_index = new_index;    }    return new_symbol;  }  return last_symbol;}static voidDEFUN(ieee_slurp_external_symbols,(abfd),      bfd *abfd){  ieee_data_type *ieee = IEEE_DATA(abfd);  file_ptr offset = ieee->w.r.external_part;  ieee_symbol_type **prev_symbols_ptr = &ieee->external_symbols;  ieee_symbol_type **prev_reference_ptr = &ieee->external_reference;  ieee_symbol_type  *symbol = (ieee_symbol_type *)NULL;  unsigned int symbol_count = 0;  boolean loop = true;  last_index = 0xffffff;  ieee->symbol_table_full = true;  ieee_seek(abfd, offset );  while (loop) {    switch (this_byte(&(ieee->h))) {    case ieee_nn_record:      next_byte(&(ieee->h));      symbol = get_symbol(abfd, ieee, symbol, &symbol_count,			  &prev_symbols_ptr, 			  &ieee->external_symbol_max_index);      symbol->symbol.the_bfd = abfd;      symbol->symbol.name = read_id(&(ieee->h));      symbol->symbol.udata = (PTR)NULL;      symbol->symbol.flags = BSF_NO_FLAGS;            break;    case ieee_external_symbol_enum:      next_byte(&(ieee->h));					           symbol = get_symbol(abfd, ieee, symbol, &symbol_count,			  &prev_symbols_ptr,			  &ieee->external_symbol_max_index);      BFD_ASSERT (symbol->index >= ieee->external_symbol_min_index);      symbol->symbol.the_bfd = abfd;      symbol->symbol.name = read_id(&(ieee->h));      symbol->symbol.udata = (PTR)NULL;      symbol->symbol.flags = BSF_NO_FLAGS;      break;    case ieee_attribute_record_enum >> 8:	{	  unsigned int symbol_name_index;	  unsigned int symbol_type_index;	  unsigned int symbol_attribute_def;	  bfd_vma value;	  next_byte(&(ieee->h)); /* Skip prefix */	  next_byte(&(ieee->h));	  symbol_name_index = must_parse_int(&(ieee->h));	  symbol_type_index = must_parse_int(&(ieee->h));	  symbol_attribute_def = must_parse_int(&(ieee->h));	  switch (symbol_attribute_def) {	  case 63:	    /* Module misc; followed by two fields which describe the	       current module block. The first fired is the type id	       number, the second is the number of asn records	       associated with the directive */	    parse_int(&(ieee->h),&value);	    parse_int(&(ieee->h),&value);	    break;	  default:	    parse_int(&(ieee->h),&value);	    break;	  }	}      break;    case ieee_value_record_enum >> 8:	{	  unsigned int symbol_name_index;	  ieee_symbol_index_type symbol_ignore;	  boolean pcrel_ignore;	  unsigned int extra;	  next_byte(&(ieee->h));	  next_byte(&(ieee->h));	  symbol_name_index = must_parse_int(&(ieee->h));	  parse_expression(ieee,			   &symbol->symbol.value,			   &symbol_ignore, 			   &pcrel_ignore, 			   &extra,			   &symbol->symbol.section);	    symbol->symbol.flags  = BSF_GLOBAL | BSF_EXPORT;	}      break;    case ieee_weak_external_reference_enum:	{ bfd_vma size;	  bfd_vma value ;	  next_byte(&(ieee->h));	  /* Throw away the external reference index */	  (void)must_parse_int(&(ieee->h));	  /* Fetch the default size if not resolved */	  size = must_parse_int(&(ieee->h));	  /* Fetch the defautlt value if available */	  if (  parse_int(&(ieee->h), &value) == false) {	    value = 0;	  }	  /* This turns into a common */	  symbol->symbol.section = &bfd_com_section;	  symbol->symbol.value = size;	}      break;    case ieee_external_reference_enum:       next_byte(&(ieee->h));      symbol = get_symbol(abfd, ieee, symbol, &symbol_count,			  &prev_reference_ptr,			  &ieee->external_reference_max_index);      symbol->symbol.the_bfd = abfd;      symbol->symbol.name = read_id(&(ieee->h));      symbol->symbol.udata = (PTR)NULL;      symbol->symbol.section = &bfd_und_section;      symbol->symbol.value = (bfd_vma)0;      symbol->symbol.flags =  0;      BFD_ASSERT (symbol->index >= ieee->external_reference_min_index);      break;    default:      loop = false;    }  }  if (ieee->external_symbol_max_index != 0) {    ieee->external_symbol_count =       ieee->external_symbol_max_index -	ieee->external_symbol_min_index + 1  ;  }  else  {    ieee->external_symbol_count = 0;  }  if(ieee->external_reference_max_index != 0) {    ieee->external_reference_count =       ieee->external_reference_max_index -	ieee->external_reference_min_index + 1;  }  else {    ieee->external_reference_count = 0;  }  abfd->symcount =    ieee->external_reference_count +  ieee->external_symbol_count;  if (symbol_count != abfd->symcount) {    /* There are gaps in the table -- */    ieee->symbol_table_full = false;  }  *prev_symbols_ptr = (ieee_symbol_type *)NULL;  *prev_reference_ptr = (ieee_symbol_type *)NULL;}static voidDEFUN(ieee_slurp_symbol_table,(abfd),      bfd *abfd){  if (IEEE_DATA(abfd)->read_symbols == false) {    ieee_slurp_external_symbols(abfd);    IEEE_DATA(abfd)->read_symbols= true;  }}unsigned intDEFUN(ieee_get_symtab_upper_bound,(abfd),      bfd *abfd){  ieee_slurp_symbol_table (abfd);  return (abfd->symcount != 0) ?     (abfd->symcount+1) * (sizeof (ieee_symbol_type *)) : 0;}/* Move from our internal lists to the canon table, and insert insymbol index order*/extern bfd_target ieee_vec;unsigned intDEFUN(ieee_get_symtab,(abfd, location),      bfd *abfd AND      asymbol **location){  ieee_symbol_type *symp;  static bfd dummy_bfd;  static asymbol empty_symbol =  { &dummy_bfd," ieee empty",(symvalue)0,BSF_DEBUGGING , &bfd_abs_section};  if (abfd->symcount) {    ieee_data_type *ieee = IEEE_DATA(abfd);    dummy_bfd.xvec= &ieee_vec;    ieee_slurp_symbol_table(abfd);    if (ieee->symbol_table_full == false) {      /* Arrgh - there are gaps in the table, run through and fill them */      /* up with pointers to a null place */      unsigned int i;      for (i= 0; i < abfd->symcount; i++) {	location[i] = &empty_symbol;      }    }    ieee->external_symbol_base_offset= -  ieee->external_symbol_min_index;    for (symp = IEEE_DATA(abfd)->external_symbols;	 symp != (ieee_symbol_type *)NULL;	 symp = symp->next) {      /* Place into table at correct index locations */      location[symp->index + ieee->external_symbol_base_offset] = &symp->symbol;    }    /* The external refs are indexed in a bit */    ieee->external_reference_base_offset   =     -  ieee->external_reference_min_index +ieee->external_symbol_count ;    for (symp = IEEE_DATA(abfd)->external_reference;	 symp != (ieee_symbol_type *)NULL;	 symp = symp->next) {      location[symp->index + ieee->external_reference_base_offset] =       &symp->symbol;    }  }  location[abfd->symcount] = (asymbol *)NULL;  return abfd->symcount;}static asection *DEFUN(get_section_entry,(abfd, ieee,index), bfd *abfd AND     ieee_data_type *ieee AND      unsigned int index){  if (ieee->section_table[index] == (asection *)NULL) {    asection *section = bfd_make_section(abfd, " tempname");    ieee->section_table[index] = section;    section->flags = SEC_NO_FLAGS;    section->target_index = index;    ieee->section_table[index] = section;  }  return ieee->section_table[index];}static voidDEFUN(ieee_slurp_sections,(abfd),      bfd *abfd){  ieee_data_type *ieee = IEEE_DATA(abfd);  file_ptr offset = ieee->w.r.section_part;  asection *section = (asection *)NULL;  if (offset != 0) {    bfd_byte section_type[3];    ieee_seek(abfd, offset);    while (true) {      switch (this_byte(&(ieee->h))) {      case ieee_section_type_enum:	  {	    unsigned int section_index ;	    next_byte(&(ieee->h));	    section_index = must_parse_int(&(ieee->h));	    /* Fixme to be nice about a silly number of sections */	    BFD_ASSERT(section_index < NSECTIONS);	    section =get_section_entry(abfd, ieee, section_index);	    section_type[0] =  this_byte_and_next(&(ieee->h));	    switch (section_type[0]) {	    case 0xC1:	      /* Normal attributes for absolute sections	*/	      section_type[1] = this_byte(&(ieee->h));	      section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;	      switch(section_type[1]) {	      case 0xD3:		next_byte(&(ieee->h));		section_type[2] = this_byte(&(ieee->h));		switch (section_type[2]) 		    {		    case 0xD0:		      /* Normal code */		      next_byte(&(ieee->h));		      section->flags |= SEC_LOAD | SEC_CODE;		      break;		    case 0xC4:		      next_byte(&(ieee->h));		      section->flags |= SEC_LOAD  | SEC_DATA;		      /* Normal data */		      break;		    case 0xD2:		      next_byte(&(ieee->h));		      /* Normal rom data */		      section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;		      break;		    default:		      break;		    }	      }	      break;	    case 0xC3:	      section_type[1] = this_byte(&(ieee->h));	      section->flags = SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS;	      switch (section_type[1]) {	      case 0xD0:		/* Normal code */		next_byte(&(ieee->h));		section->flags |= SEC_LOAD | SEC_CODE;		break;	      case 0xC4:		next_byte(&(ieee->h));		section->flags |= SEC_LOAD  | SEC_DATA;		/* Normal data */		break;	      case 0xD2:		next_byte(&(ieee->h));		/* Normal rom data */		section->flags |= SEC_LOAD | SEC_ROM | SEC_DATA;		break;	      default:		break;	      }	    }	    section->name = read_id(&(ieee->h));	      { bfd_vma parent, brother, context;		parse_int(&(ieee->h), &parent);		parse_int(&(ieee->h), &brother);		parse_int(&(ieee->h), &context);	      }	  }	break;      case ieee_section_alignment_enum:	  { 	    unsigned int section_index;	    bfd_vma value;	    asection *section;	    next_byte(&(ieee->h));	    section_index = must_parse_int(&ieee->h);	    section = get_section_entry(abfd, ieee, section_index);	    if (section_index > ieee->section_count) {	      ieee->section_count = section_index;	    }	    section->alignment_power =	      bfd_log2(must_parse_int(&ieee->h));	    (void)parse_int(&(ieee->h), & value);	  }	break;      case ieee_e2_first_byte_enum: 	  {	    ieee_record_enum_type t = (ieee_record_enum_type)(read_2bytes(&(ieee->h)));	    switch (t) {	    case ieee_section_size_enum:	      section = ieee->section_table[must_parse_int(&(ieee->h))];	      section->_raw_size = must_parse_int(&(ieee->h));	      break;	    case ieee_physical_region_size_enum:	      section = ieee->section_table[must_parse_int(&(ieee->h))];	      section->_raw_size = must_parse_int(&(ieee->h));	      break;	    case ieee_region_base_address_enum:	      section = ieee->section_table[must_parse_int(&(ieee->h))];	      section->vma = must_parse_int(&(ieee->h));	      break;	    case ieee_mau_size_enum:	      must_parse_int(&(ieee->h));	      must_parse_int(&(ieee->h));	      break;	    case ieee_m_value_enum:	      must_parse_int(&(ieee->h));	      must_parse_int(&(ieee->h));	      break;	    case ieee_section_base_address_enum:	      section = ieee->section_table[must_parse_int(&(ieee->h))];	      section->vma = must_parse_int(&(ieee->h));	      break;	    case ieee_section_offset_enum:	      (void) must_parse_int(&(ieee->h));	      (void) must_parse_int(&(ieee->h));	      break;	    default:	      return;	    }	  }	break;      default:	return;      }    }  }}/************************************************************************  archive stuff */bfd_target *DEFUN(ieee_archive_p,(abfd),      bfd *abfd){  char *library;  boolean loop;  unsigned int i;uint8e_type buffer[512];  struct obstack ob;  file_ptr buffer_offset = 0;  ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;  ieee_ar_data_type *ieee ;  abfd->tdata.ieee_ar_data = (ieee_ar_data_type *)bfd_alloc(abfd, sizeof(ieee_ar_data_type));  ieee=  IEEE_AR_DATA(abfd);  bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);  ieee->h.first_byte = buffer;  ieee->h.input_p = buffer;  ieee->h.abfd = abfd;  if (this_byte(&(ieee->h)) != Module_Beginning) {    abfd->tdata.ieee_ar_data = save;      return (bfd_target*)NULL;    }    next_byte(&(ieee->h));  library= read_id(&(ieee->h));  if (strcmp(library , "LIBRARY") != 0) {    bfd_release(abfd, ieee);    abfd->tdata.ieee_ar_data = save;    return (bfd_target *)NULL;  }  /* Throw away the filename */  free( read_id(&(ieee->h)));  /* This must be an IEEE archive, so we'll buy some space to do     things */  obstack_begin(&ob, 128);  ieee->element_count = 0;  ieee->element_index = 0;  next_byte(&(ieee->h));	/* Drop the ad part */  must_parse_int(&(ieee->h));	/* And the two dummy numbers */  must_parse_int(&(ieee->h));  loop = true;  /* Read the index of the BB table */  while (loop) {    ieee_ar_obstack_type t;     int rec =read_2bytes(&(ieee->h));    if (rec ==(int)ieee_assign_value_to_variable_enum) {      int record_number = must_parse_int(&(ieee->h));      t.file_offset = must_parse_int(&(ieee->h));      t.abfd = (bfd *)NULL;      ieee->element_count++;      obstack_grow(&ob, (PTR)&t, sizeof(t));      /* Make sure that we don't go over the end of the buffer */      if (ieee_pos(abfd) > sizeof(buffer)/2) {	/* Past half way, reseek and reprime */	buffer_offset += ieee_pos(abfd);	bfd_seek(abfd, buffer_offset, SEEK_SET);	bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);	ieee->h.first_byte = buffer;	ieee->h.input_p = buffer;      }    }    else loop = false;  }  ieee->elements = (ieee_ar_obstack_type *)obstack_finish(&ob);  /* Now scan the area again, and replace BB offsets with file */  /* offsets */  for (i = 2; i < ieee->element_count; i++) {    bfd_seek(abfd, ieee->elements[i].file_offset, SEEK_SET);    bfd_read((PTR)buffer, 1, sizeof(buffer), abfd);    ieee->h.first_byte = buffer;    ieee->h.input_p = buffer;        next_byte(&(ieee->h));	/* Drop F8 */    next_byte(&(ieee->h));	/* Drop 14 */    must_parse_int(&(ieee->h));	/* Drop size of block */    if (must_parse_int(&(ieee->h)) != 0) {      /* This object has been deleted */      ieee->elements[i].file_offset = 0;    }    else {      ieee->elements[i].file_offset = must_parse_int(&(ieee->h));    }  }  return abfd->xvec;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -