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

📄 ieee.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 5 页
字号:
      if (n == NULL)	return NULL;      for (i = ieee->section_table_size; i < c; i++)	n[i] = NULL;      ieee->section_table = n;      ieee->section_table_size = c;    }  if (ieee->section_table[index] == (asection *) NULL)    {      char *tmp = bfd_alloc (abfd, 11);      asection *section;      if (!tmp)	return NULL;      sprintf (tmp, " fsec%4d", index);      section = bfd_make_section (abfd, tmp);      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 voidieee_slurp_sections (abfd)     bfd *abfd;{  ieee_data_type *ieee = IEEE_DATA (abfd);  file_ptr offset = ieee->w.r.section_part;  asection *section = (asection *) NULL;  char *name;  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));		section = get_section_entry (abfd, ieee, section_index);		section_type[0] = this_byte_and_next (&(ieee->h));		/* Set minimal section attributes. Attributes are		   extended later, based on section contents. */		switch (section_type[0])		  {		  case 0xC1:		    /* Normal attributes for absolute sections	*/		    section_type[1] = this_byte (&(ieee->h));		    section->flags = SEC_ALLOC;		    switch (section_type[1])		      {		      case 0xD3:	/* AS Absolute section attributes */			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_CODE;			    break;			  case 0xC4:			    /* Normal data */			    next_byte (&(ieee->h));			    section->flags |= SEC_DATA;			    break;			  case 0xD2:			    next_byte (&(ieee->h));			    /* Normal rom data */			    section->flags |= SEC_ROM | SEC_DATA;			    break;			  default:			    break;			  }		      }		    break;		  case 0xC3:	/* Named relocatable sections (type C) */		    section_type[1] = this_byte (&(ieee->h));		    section->flags = SEC_ALLOC;		    switch (section_type[1])		      {		      case 0xD0:	/* Normal code (CP) */			next_byte (&(ieee->h));			section->flags |= SEC_CODE;			break;		      case 0xC4:	/* Normal data (CD) */			next_byte (&(ieee->h));			section->flags |= SEC_DATA;			break;		      case 0xD2:	/* Normal rom data (CR) */			next_byte (&(ieee->h));			section->flags |= SEC_ROM | SEC_DATA;			break;		      default:			break;		      }		  }		/* Read section name, use it if non empty. */		name = read_id (&ieee->h);		if (name[0])		  section->name = name;		/* Skip these fields, which we don't care about */		{		  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));		    section->lma = section->vma;		    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));		    section->lma = section->vma;		    break;		  case ieee_section_offset_enum:		    (void) must_parse_int (&(ieee->h));		    (void) must_parse_int (&(ieee->h));		    break;		  default:		    return;		  }	      }	      break;	    default:	      return;	    }	}    }}/* Make a section for the debugging information, if any.  We don't try   to interpret the debugging information; we just point the section   at the area in the file so that program which understand can dig it   out.  */static booleanieee_slurp_debug (abfd)     bfd *abfd;{  ieee_data_type *ieee = IEEE_DATA (abfd);  asection *sec;  file_ptr debug_end;  if (ieee->w.r.debug_information_part == 0)    return true;  sec = bfd_make_section (abfd, ".debug");  if (sec == NULL)    return false;  sec->flags |= SEC_DEBUGGING | SEC_HAS_CONTENTS;  sec->filepos = ieee->w.r.debug_information_part;  debug_end = ieee->w.r.data_part;  if (debug_end == 0)    debug_end = ieee->w.r.trailer_part;  if (debug_end == 0)    debug_end = ieee->w.r.me_record;  sec->_raw_size = debug_end - ieee->w.r.debug_information_part;  return true;}/************************************************************************  archive stuff*/const bfd_target *ieee_archive_p (abfd)     bfd *abfd;{  char *library;  unsigned int i;  unsigned char buffer[512];  file_ptr buffer_offset = 0;  ieee_ar_data_type *save = abfd->tdata.ieee_ar_data;  ieee_ar_data_type *ieee;  unsigned int alc_elts;  ieee_ar_obstack_type *elts = NULL;  abfd->tdata.ieee_ar_data =    (ieee_ar_data_type *) bfd_alloc (abfd, sizeof (ieee_ar_data_type));  if (!abfd->tdata.ieee_ar_data)    goto error_return;  ieee = IEEE_AR_DATA (abfd);  /* FIXME: Check return value.  I'm not sure whether it needs to read     the entire buffer or not.  */  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)    goto got_wrong_format_error;  next_byte (&(ieee->h));  library = read_id (&(ieee->h));  if (strcmp (library, "LIBRARY") != 0)    goto got_wrong_format_error;  /* Throw away the filename.  */  read_id (&(ieee->h));  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));  alc_elts = 10;  elts = (ieee_ar_obstack_type *) bfd_malloc (alc_elts * sizeof *elts);  if (elts == NULL)    goto error_return;  /* Read the index of the BB table.  */  while (1)    {      int rec;      ieee_ar_obstack_type *t;      rec = read_2bytes (&(ieee->h));      if (rec != (int) ieee_assign_value_to_variable_enum)	break;      if (ieee->element_count >= alc_elts)	{	  ieee_ar_obstack_type *n;	  alc_elts *= 2;	  n = ((ieee_ar_obstack_type *)	       bfd_realloc (elts, alc_elts * sizeof *elts));	  if (n == NULL)	    goto error_return;	  elts = n;	}      t = &elts[ieee->element_count];      ieee->element_count++;      must_parse_int (&(ieee->h));      t->file_offset = must_parse_int (&(ieee->h));      t->abfd = (bfd *) NULL;      /* Make sure that we don't go over the end of the buffer.  */      if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2)	{	  /* Past half way, reseek and reprime.  */	  buffer_offset += ieee_pos (abfd);	  if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)	    goto error_return;	  /* FIXME: Check return value.  I'm not sure whether it needs	     to read the entire buffer or not.  */	  bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);	  ieee->h.first_byte = buffer;	  ieee->h.input_p = buffer;	}    }  ieee->elements = ((ieee_ar_obstack_type *)		    bfd_alloc (abfd,			       ieee->element_count * sizeof *ieee->elements));  if (ieee->elements == NULL)    goto error_return;  memcpy (ieee->elements, elts,	  ieee->element_count * sizeof *ieee->elements);  free (elts);  elts = NULL;  /* Now scan the area again, and replace BB offsets with file offsets.  */  for (i = 2; i < ieee->element_count; i++)    {      if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)	goto error_return;      /* FIXME: Check return value.  I'm not sure whether it needs to	 read the entire buffer or not.  */      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));    }  /*  abfd->has_armap = ;*/  return abfd->xvec; got_wrong_format_error:  bfd_release (abfd, ieee);  abfd->tdata.ieee_ar_data = save;  bfd_set_error (bfd_error_wrong_format); error_return:  if (elts != NULL)    free (elts);  return NULL;}static booleanieee_mkobject (abfd)     bfd *abfd;{  abfd->tdata.ieee_data = (ieee_data_type *) bfd_zalloc (abfd, sizeof (ieee_data_type));  return abfd->tdata.ieee_data ? true : false;}const bfd_target *ieee_object_p (abfd)     bfd *abfd;{  char *processor;  unsigned int part;  ieee_data_type *ieee;  unsigned char buffer[300];  ieee_data_type *save = IEEE_DATA (abfd);  abfd->tdata.ieee_data = 0;  ieee_mkobject (abfd);  ieee = IEEE_DATA (abfd);  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)    goto fail;  /* Read the first few bytes in to see if it makes sense */  /* FIXME: Check return value.  I'm not sure whether it needs to read     the entire buffer or not.  */  bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);  ieee->h.input_p = buffer;  if (this_byte_and_next (&(ieee->h)) != Module_Beginning)    goto got_wrong_format;  ieee->read_symbols = false;  ieee->read_data = false;  ieee->section_count = 0;  ieee->external_symbol_max_index = 0;  ieee->external_symbol_min_index = IEEE_PUBLIC_BASE;  ieee->external_reference_min_index = IEEE_REFERENCE_BASE;  ieee->external_reference_max_index = 0;  ieee->h.abfd = abfd;  ieee->section_table = NULL;  ieee->section_table_size = 0;  processor = ieee->mb.processor = read_id (&(ieee->h));  if (strcmp (processor, "LIBRARY") == 0)    goto got_wrong_format;  ieee->mb.module_name = read_id (&(ieee->h));  if (abfd->filename == (CONST char *) NULL)    {      abfd->filename = ieee->mb.module_name;    }  /* Determine the architecture and machine type of the object file.     */  {    const bfd_arch_info_type *arch;    char family[10];    /* IEEE does not specify the format of the processor identificaton       string, so the compiler is free to put in it whatever it wants.       We try here to recognize different processors belonging to the       m68k family.  Code for other processors can be added here.  */    if ((processor[0] == '6') && (processor[1] == '8'))      {	if (processor[2] == '3')	    /* 683xx integrated processors */	  {	    switch (processor[3])	      {	      case '0':			    /* 68302, 68306, 68307 */	      case '2':			    /* 68322, 68328 */	      case '5':			    /* 68356 */		strcpy (family, "68000");   /* MC68000-based controllers */		break;	      case '3':			    /* 68330, 68331, 68332, 68333,					       68334, 68335, 68336, 68338 */	      case '6':			    /* 68360 */	      case '7':			    /* 68376 */		strcpy (family, "68332");   /* CPU32 and CPU32+ */		break;	      case '4':		if (processor[4] == '9')    /* 68349 */		  strcpy (family, "68030"); /* CPU030 */		else		            /* 68340, 68341 */		  strcpy (family, "68332"); /* CPU32 and CPU32+ */		break;	      default:			    /* Does not exist yet */		strcpy (family, "68332");   /* Guess it will be CPU32 */	      }	  }	else if (toupper (processor[3]) == 'F')   /* 68F333 */	  strcpy (family, "68332");	          /* CPU32 */	else if ((toupper (processor[3]) == 'C')  /* Embedded controllers */		 && ((toupper (processor[2]) == 'E')		     || (toupper (processor[2]) == 'H')		     || (toupper (processor[2]) == 'L')))	  {	    strcpy (family, "68");	    strncat (family, processor + 4, 7);	    family[9] = '\0';	  }	else				 /* "Regular" processors */	  {	    strncpy (family, processor, 9);	    family[9] = '\0';	  }      }    else if ((strncmp (processor, "cpu32", 5) == 0) /* CPU32 and CPU32+ */	     || (strncmp (processor, "CPU32", 5) == 0))      strcpy (family, "68332");    else      {	strncpy (family, processor, 9);	family[9] = '\0';      }    arch = bfd_scan_arch (family);    if (arch == 0)      goto got_wrong_format;    abfd->arch_info = arch;  }  if (this_byte (&(ieee->h)) != (int) ieee_address_descriptor_enum)    {      goto fail;    }  next_byte (&(ieee->h));  if (parse_int (&(ieee->h), &ieee->ad.number_of_bits_mau) == false)    {      goto fail;    }  if (parse_int (&(ieee->h), &ieee->ad.number_of_maus_in_address) == false)    {      goto fail;    }  /* If there is a byte order info, take it */  if (this_byte (&(ieee->h)) == (int) ieee_variable_L_enum ||      this_byte (&(ieee->h)) == (int) ieee_variable_M_enum)    next_byte (&(ieee->h));  for (part = 0; part < N_W_VARIABLES; part++)    {      boolean ok;      if (read_2bytes (&(ieee->h)) != (int) ieee_assign_value_to_variable_enum)	{	  goto fail;	}      if (this_byte_and_next (&(ieee->h)) != part)	{	  goto fail;	}      ieee->w.offset[part] = parse_i (&(ieee->h), &ok);      if (ok == false)	{	  goto fail;	}    }  if (ieee->w.r.external_part != 0)    abfd->flags = HAS_SYMS;  /* By now we know that this is a real IEEE file, we're going to read     the whole thing into memory so that we can run up and down it     quickly.  We can work out how big the file is from the trailer     record */

⌨️ 快捷键说明

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