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

📄 oasys.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 3 页
字号:
				(oasys_record_union_type *) & out,				sizeof (out)))	return false;    }  return true;}static booleanoasys_write_header (abfd)     bfd *abfd;{  /* Create and write the header */  oasys_header_record_type r;  size_t length = strlen (abfd->filename);  if (length > (size_t) sizeof (r.module_name))    {      length = sizeof (r.module_name);    }  (void) memcpy (r.module_name,		 abfd->filename,		 length);  (void) memset (r.module_name + length,		 ' ',		 sizeof (r.module_name) - length);  r.version_number = OASYS_VERSION_NUMBER;  r.rev_number = OASYS_REV_NUMBER;  if (! oasys_write_record (abfd,			    oasys_record_is_header_enum,			    (oasys_record_union_type *) & r,			    offsetof (oasys_header_record_type,				      description[0])))    return false;  return true;}static booleanoasys_write_end (abfd)     bfd *abfd;{  oasys_end_record_type end;  unsigned char null = 0;  end.relb = RELOCATION_TYPE_ABS;  bfd_h_put_32 (abfd, abfd->start_address, end.entry);  bfd_h_put_16 (abfd, 0, end.fill);  end.zero = 0;  if (! oasys_write_record (abfd,			    oasys_record_is_end_enum,			    (oasys_record_union_type *) & end,			    sizeof (end)))    return false;  if (bfd_write ((PTR) & null, 1, 1, abfd) != 1)    return false;  return true;}static intcomp (ap, bp)     CONST PTR ap;     CONST PTR bp;{  arelent *a = *((arelent **) ap);  arelent *b = *((arelent **) bp);  return a->address - b->address;}/* Writing data..*/static booleanoasys_write_data (abfd)     bfd *abfd;{  asection *s;  for (s = abfd->sections; s != (asection *) NULL; s = s->next)    {      if (s->flags & SEC_LOAD)	{	  bfd_byte *raw_data = oasys_per_section (s)->data;	  oasys_data_record_type processed_data;	  bfd_size_type current_byte_index = 0;	  unsigned int relocs_to_go = s->reloc_count;	  arelent **p = s->orelocation;	  if (s->reloc_count != 0)	    {/* Sort the reloc records so it's easy to insert the relocs into the	   data */	      qsort (s->orelocation,		     s->reloc_count,		     sizeof (arelent **),		     comp);	    }	  current_byte_index = 0;	  processed_data.relb = s->target_index | RELOCATION_TYPE_REL;	  while (current_byte_index < s->_cooked_size)	    {	      /* Scan forwards by eight bytes or however much is left and see if	       there are any relocations going on */	      bfd_byte *mod = &processed_data.data[0];	      bfd_byte *dst = &processed_data.data[1];	      unsigned int i = 0;	      *mod = 0;	      bfd_h_put_32 (abfd, s->vma + current_byte_index,			    processed_data.addr);	      /* Don't start a relocation unless you're sure you can finish it 	       within the same data record.  The worst case relocation is a 	       4-byte relocatable value which is split across two modification 	       bytes (1 relocation byte + 2 symbol reference bytes + 2 data + 	       1 modification byte + 2 data = 8 bytes total).  That's where 	       the magic number 8 comes from. 	    */	      while (current_byte_index < s->_raw_size && dst <=		     &processed_data.data[sizeof (processed_data.data) - 8])		{		  if (relocs_to_go != 0)		    {		      arelent *r = *p;		      reloc_howto_type *const how = r->howto;		      /* There is a relocation, is it for this byte ? */		      if (r->address == current_byte_index)			{			  unsigned char rel_byte;			  p++;			  relocs_to_go--;			  *mod |= (1 << i);			  if (how->pc_relative)			    {			      rel_byte = RELOCATION_PCREL_BIT;			      /* Also patch the raw data so that it doesn't have			 the -ve stuff any more */			      if (how->size != 2)				{				  bfd_put_16 (abfd,					      bfd_get_16 (abfd, raw_data) +					      current_byte_index, raw_data);				}			      else				{				  bfd_put_32 (abfd,					      bfd_get_32 (abfd, raw_data) +					      current_byte_index, raw_data);				}			    }			  else			    {			      rel_byte = 0;			    }			  if (how->size == 2)			    {			      rel_byte |= RELOCATION_32BIT_BIT;			    }			  /* Is this a section relative relocation, or a symbol		       relative relocation ? */			  abort ();#if 0			  if (r->section != (asection *) NULL)			    {			      /* The relent has a section attached, so it must be section			     relative */			      rel_byte |= RELOCATION_TYPE_REL;			      rel_byte |= r->section->output_section->target_index;			      *dst++ = rel_byte;			    }			  else#endif			    {			      asymbol *p = *(r->sym_ptr_ptr);			      /* If this symbol has a section attached, then it			     has already been resolved.  Change from a symbol			     ref to a section ref */			      if (p->section != (asection *) NULL)				{				  rel_byte |= RELOCATION_TYPE_REL;				  rel_byte |=				    p->section->output_section->target_index;				  *dst++ = rel_byte;				}			      else				{				  rel_byte |= RELOCATION_TYPE_UND;				  *dst++ = rel_byte;				  /* Next two bytes are a symbol index - we can get			       this from the symbol value which has been zapped			       into the symbol index in the table when the			       symbol table was written			       */				  *dst++ = p->value >> 8;				  *dst++ = p->value;				}			    }#define ADVANCE { if (++i >= 8) { i = 0; mod = dst++; *mod = 0; } current_byte_index++; }			  /* relocations never occur from an unloadable section,		       so we can assume that raw_data is not NULL		     */			  *dst++ = *raw_data++;			  ADVANCE			    * dst++ = *raw_data++;			  ADVANCE			    if (how->size == 2)			    {			      *dst++ = *raw_data++;			      ADVANCE				* dst++ = *raw_data++;			      ADVANCE			    }			  continue;			}		    }		  /* If this is coming from an unloadable section then copy		   zeros */		  if (raw_data == NULL)		    {		      *dst++ = 0;		    }		  else		    {		      *dst++ = *raw_data++;		    }		  ADVANCE		}	      /* Don't write a useless null modification byte */	      if (dst == mod + 1)		{		  --dst;		}	      if (! oasys_write_record (abfd,					oasys_record_is_data_enum,					((oasys_record_union_type *)					 & processed_data),					dst - (bfd_byte *) & processed_data))		return false;	    }	}    }  return true;}static booleanoasys_write_object_contents (abfd)     bfd *abfd;{  if (! oasys_write_header (abfd))    return false;  if (! oasys_write_syms (abfd))    return false;  if (! oasys_write_sections (abfd))    return false;  if (! oasys_write_data (abfd))    return false;  if (! oasys_write_end (abfd))    return false;  return true;}/** exec and core file sections *//* set section contents is complicated with OASYS since the format is* not a byte image, but a record stream.*/static booleanoasys_set_section_contents (abfd, section, location, offset, count)     bfd *abfd;     sec_ptr section;     PTR location;     file_ptr offset;     bfd_size_type count;{  if (count != 0)    {      if (oasys_per_section (section)->data == (bfd_byte *) NULL)	{	  oasys_per_section (section)->data =	    (bfd_byte *) (bfd_alloc (abfd, section->_cooked_size));	  if (!oasys_per_section (section)->data)	    return false;	}      (void) memcpy ((PTR) (oasys_per_section (section)->data + offset),		     location,		     (size_t) count);    }  return true;}/* Native-level interface to symbols. *//* We read the symbols into a buffer, which is discarded when thisfunction exits.  We read the strings into a buffer large enough tohold them all plus all the cached symbol entries. */static asymbol *oasys_make_empty_symbol (abfd)     bfd *abfd;{  oasys_symbol_type *new =  (oasys_symbol_type *) bfd_zalloc (abfd, sizeof (oasys_symbol_type));  if (!new)    return NULL;  new->symbol.the_bfd = abfd;  return &new->symbol;}/* User should have checked the file flags; perhaps we should returnBFD_NO_MORE_SYMBOLS if there are none? */static bfd *oasys_openr_next_archived_file (arch, prev)     bfd *arch;     bfd *prev;{  oasys_ar_data_type *ar = OASYS_AR_DATA (arch);  oasys_module_info_type *p;  /* take the next one from the arch state, or reset */  if (prev == (bfd *) NULL)    {      /* Reset the index - the first two entries are bogus*/      ar->module_index = 0;    }  p = ar->module + ar->module_index;  ar->module_index++;  if (ar->module_index <= ar->module_count)    {      if (p->abfd == (bfd *) NULL)	{	  p->abfd = _bfd_create_empty_archive_element_shell (arch);	  p->abfd->origin = p->pos;	  p->abfd->filename = p->name;	  /* Fixup a pointer to this element for the member */	  p->abfd->arelt_data = (PTR) p;	}      return p->abfd;    }  else    {      bfd_set_error (bfd_error_no_more_archived_files);      return (bfd *) NULL;    }}static booleanoasys_find_nearest_line (abfd,			 section,			 symbols,			 offset,			 filename_ptr,			 functionname_ptr,			 line_ptr)     bfd *abfd ATTRIBUTE_UNUSED;     asection *section ATTRIBUTE_UNUSED;     asymbol **symbols ATTRIBUTE_UNUSED;     bfd_vma offset ATTRIBUTE_UNUSED;     char **filename_ptr ATTRIBUTE_UNUSED;     char **functionname_ptr ATTRIBUTE_UNUSED;     unsigned int *line_ptr ATTRIBUTE_UNUSED;{  return false;}static intoasys_generic_stat_arch_elt (abfd, buf)     bfd *abfd;     struct stat *buf;{  oasys_module_info_type *mod = (oasys_module_info_type *) abfd->arelt_data;  if (mod == (oasys_module_info_type *) NULL)    {      bfd_set_error (bfd_error_invalid_operation);      return -1;    }  else    {      buf->st_size = mod->size;      buf->st_mode = 0666;      return 0;    }}static intoasys_sizeof_headers (abfd, exec)     bfd *abfd ATTRIBUTE_UNUSED;     boolean exec ATTRIBUTE_UNUSED;{  return 0;}#define	oasys_close_and_cleanup _bfd_generic_close_and_cleanup#define oasys_bfd_free_cached_info _bfd_generic_bfd_free_cached_info#define oasys_slurp_armap bfd_true#define oasys_slurp_extended_name_table bfd_true#define oasys_construct_extended_name_table \  ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \   bfd_true)#define oasys_truncate_arname bfd_dont_truncate_arname#define oasys_write_armap \  ((boolean (*) \    PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int))) \   bfd_true)#define oasys_read_ar_hdr bfd_nullvoidptr#define oasys_get_elt_at_index _bfd_generic_get_elt_at_index#define oasys_update_armap_timestamp bfd_true#define oasys_bfd_is_local_label_name bfd_generic_is_local_label_name#define oasys_get_lineno _bfd_nosymbols_get_lineno#define oasys_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol#define oasys_read_minisymbols _bfd_generic_read_minisymbols#define oasys_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol#define oasys_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup#define oasys_set_arch_mach bfd_default_set_arch_mach#define oasys_get_section_contents_in_window \  _bfd_generic_get_section_contents_in_window#define oasys_bfd_get_relocated_section_contents \  bfd_generic_get_relocated_section_contents#define oasys_bfd_relax_section bfd_generic_relax_section#define oasys_bfd_gc_sections bfd_generic_gc_sections#define oasys_bfd_link_hash_table_create _bfd_generic_link_hash_table_create#define oasys_bfd_link_add_symbols _bfd_generic_link_add_symbols#define oasys_bfd_final_link _bfd_generic_final_link#define oasys_bfd_link_split_section _bfd_generic_link_split_section/*SUPPRESS 460 */const bfd_target oasys_vec ={  "oasys",			/* name */  bfd_target_oasys_flavour,  BFD_ENDIAN_BIG,		/* target byte order */  BFD_ENDIAN_BIG,		/* target headers byte order */  (HAS_RELOC | EXEC_P |		/* object flags */   HAS_LINENO | HAS_DEBUG |   HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),  (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS   | SEC_ALLOC | SEC_LOAD | SEC_RELOC),	/* section flags */  0,				/* leading underscore */  ' ',				/* ar_pad_char */  16,				/* ar_max_namelen */  bfd_getb64, bfd_getb_signed_64, bfd_putb64,  bfd_getb32, bfd_getb_signed_32, bfd_putb32,  bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* data */  bfd_getb64, bfd_getb_signed_64, bfd_putb64,  bfd_getb32, bfd_getb_signed_32, bfd_putb32,  bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* hdrs */  {_bfd_dummy_target,   oasys_object_p,		/* bfd_check_format */   oasys_archive_p,   _bfd_dummy_target,  },  {				/* bfd_set_format */    bfd_false,    oasys_mkobject,    _bfd_generic_mkarchive,    bfd_false  },  {				/* bfd_write_contents */    bfd_false,    oasys_write_object_contents,    _bfd_write_archive_contents,    bfd_false,  },  BFD_JUMP_TABLE_GENERIC (oasys),  BFD_JUMP_TABLE_COPY (_bfd_generic),  BFD_JUMP_TABLE_CORE (_bfd_nocore),  BFD_JUMP_TABLE_ARCHIVE (oasys),  BFD_JUMP_TABLE_SYMBOLS (oasys),  BFD_JUMP_TABLE_RELOCS (oasys),  BFD_JUMP_TABLE_WRITE (oasys),  BFD_JUMP_TABLE_LINK (oasys),  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),  NULL,    (PTR) 0};

⌨️ 快捷键说明

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