nlmcode.h

来自「基于4个mips核的noc设计」· C头文件 代码 · 共 2,035 行 · 第 1/5 页

H
2,035
字号
  for (;;)    {      position = bfd_tell (abfd);      if (bfd_read ((PTR) tempstr, sizeof (tempstr), 1, abfd) !=	  sizeof (tempstr))	return (false);      if (bfd_seek (abfd, position, SEEK_SET) == -1)	return (false);      if (strncmp (tempstr, "VeRsIoN#", 8) == 0)	{	  Nlm_External_Version_Header thdr;	  if (bfd_read ((PTR) & thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))	    return (false);	  memcpy (nlm_version_header (abfd)->stamp, thdr.stamp,		  sizeof (thdr.stamp));	  nlm_version_header (abfd)->majorVersion =	    get_word (abfd, (bfd_byte *) thdr.majorVersion);	  nlm_version_header (abfd)->minorVersion =	    get_word (abfd, (bfd_byte *) thdr.minorVersion);	  nlm_version_header (abfd)->revision =	    get_word (abfd, (bfd_byte *) thdr.revision);	  nlm_version_header (abfd)->year =	    get_word (abfd, (bfd_byte *) thdr.year);	  nlm_version_header (abfd)->month =	    get_word (abfd, (bfd_byte *) thdr.month);	  nlm_version_header (abfd)->day =	    get_word (abfd, (bfd_byte *) thdr.day);	}      else if (strncmp (tempstr, "MeSsAgEs", 8) == 0)	{	  Nlm_External_Extended_Header thdr;	  if (bfd_read ((PTR) & thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))	    return (false);	  memcpy (nlm_extended_header (abfd)->stamp, thdr.stamp,		  sizeof (thdr.stamp));	  nlm_extended_header (abfd)->languageID =	    get_word (abfd, (bfd_byte *) thdr.languageID);	  nlm_extended_header (abfd)->messageFileOffset =	    get_word (abfd, (bfd_byte *) thdr.messageFileOffset);	  nlm_extended_header (abfd)->messageFileLength =	    get_word (abfd, (bfd_byte *) thdr.messageFileLength);	  nlm_extended_header (abfd)->messageCount =	    get_word (abfd, (bfd_byte *) thdr.messageCount);	  nlm_extended_header (abfd)->helpFileOffset =	    get_word (abfd, (bfd_byte *) thdr.helpFileOffset);	  nlm_extended_header (abfd)->helpFileLength =	    get_word (abfd, (bfd_byte *) thdr.helpFileLength);	  nlm_extended_header (abfd)->RPCDataOffset =	    get_word (abfd, (bfd_byte *) thdr.RPCDataOffset);	  nlm_extended_header (abfd)->RPCDataLength =	    get_word (abfd, (bfd_byte *) thdr.RPCDataLength);	  nlm_extended_header (abfd)->sharedCodeOffset =	    get_word (abfd, (bfd_byte *) thdr.sharedCodeOffset);	  nlm_extended_header (abfd)->sharedCodeLength =	    get_word (abfd, (bfd_byte *) thdr.sharedCodeLength);	  nlm_extended_header (abfd)->sharedDataOffset =	    get_word (abfd, (bfd_byte *) thdr.sharedDataOffset);	  nlm_extended_header (abfd)->sharedDataLength =	    get_word (abfd, (bfd_byte *) thdr.sharedDataLength);	  nlm_extended_header (abfd)->sharedRelocationFixupOffset =	    get_word (abfd, (bfd_byte *) thdr.sharedRelocationFixupOffset);	  nlm_extended_header (abfd)->sharedRelocationFixupCount =	    get_word (abfd, (bfd_byte *) thdr.sharedRelocationFixupCount);	  nlm_extended_header (abfd)->sharedExternalReferenceOffset =	    get_word (abfd, (bfd_byte *) thdr.sharedExternalReferenceOffset);	  nlm_extended_header (abfd)->sharedExternalReferenceCount =	    get_word (abfd, (bfd_byte *) thdr.sharedExternalReferenceCount);	  nlm_extended_header (abfd)->sharedPublicsOffset =	    get_word (abfd, (bfd_byte *) thdr.sharedPublicsOffset);	  nlm_extended_header (abfd)->sharedPublicsCount =	    get_word (abfd, (bfd_byte *) thdr.sharedPublicsCount);	  nlm_extended_header (abfd)->sharedDebugRecordOffset =	    get_word (abfd, (bfd_byte *) thdr.sharedDebugRecordOffset);	  nlm_extended_header (abfd)->sharedDebugRecordCount =	    get_word (abfd, (bfd_byte *) thdr.sharedDebugRecordCount);	  nlm_extended_header (abfd)->SharedInitializationOffset =	    get_word (abfd, (bfd_byte *) thdr.sharedInitializationOffset);	  nlm_extended_header (abfd)->SharedExitProcedureOffset =	    get_word (abfd, (bfd_byte *) thdr.SharedExitProcedureOffset);	  nlm_extended_header (abfd)->productID =	    get_word (abfd, (bfd_byte *) thdr.productID);	  nlm_extended_header (abfd)->reserved0 =	    get_word (abfd, (bfd_byte *) thdr.reserved0);	  nlm_extended_header (abfd)->reserved1 =	    get_word (abfd, (bfd_byte *) thdr.reserved1);	  nlm_extended_header (abfd)->reserved2 =	    get_word (abfd, (bfd_byte *) thdr.reserved2);	  nlm_extended_header (abfd)->reserved3 =	    get_word (abfd, (bfd_byte *) thdr.reserved3);	  nlm_extended_header (abfd)->reserved4 =	    get_word (abfd, (bfd_byte *) thdr.reserved4);	  nlm_extended_header (abfd)->reserved5 =	    get_word (abfd, (bfd_byte *) thdr.reserved5);	}      else if (strncmp (tempstr, "CoPyRiGhT=", 10) == 0)	{	  if (bfd_read ((PTR) nlm_copyright_header (abfd)->stamp,			sizeof (nlm_copyright_header (abfd)->stamp),			1, abfd)	      != sizeof (nlm_copyright_header (abfd)->stamp))	    return (false);	  if (bfd_read ((PTR) & (nlm_copyright_header (abfd)				 ->copyrightMessageLength),			1, 1, abfd) != 1)	    return (false);	  /* The copyright message is a variable length string.  */	  if (bfd_read ((PTR) nlm_copyright_header (abfd)->copyrightMessage,		    nlm_copyright_header (abfd)->copyrightMessageLength + 1,			1, abfd) !=	      ((bfd_size_type)	       nlm_copyright_header (abfd)->copyrightMessageLength + 1))	    return (false);	}      else if (strncmp (tempstr, "CuStHeAd", 8) == 0)	{	  Nlm_External_Custom_Header thdr;	  bfd_size_type hdrLength;	  file_ptr dataOffset;	  bfd_size_type dataLength;	  char dataStamp[8];	  PTR hdr;	  /* Read the stamp ("CuStHeAd").  */	  if (bfd_read ((PTR) thdr.stamp, 1, sizeof (thdr.stamp), abfd)	      != sizeof (thdr.stamp))	    return false;	  /* Read the length of this custom header.  */	  if (bfd_read ((PTR) thdr.length, 1, sizeof (thdr.length), abfd)	      != sizeof (thdr.length))	    return false;	  hdrLength = get_word (abfd, (bfd_byte *) thdr.length);	  /* Read further fields if we have them.  */	  if (hdrLength < NLM_TARGET_LONG_SIZE)	    dataOffset = 0;	  else	    {	      if (bfd_read ((PTR) thdr.dataOffset, 1,			    sizeof (thdr.dataOffset), abfd)		  != sizeof (thdr.dataOffset))		return false;	      dataOffset = get_word (abfd, (bfd_byte *) thdr.dataOffset);	    }	  if (hdrLength < 2 * NLM_TARGET_LONG_SIZE)	    dataLength = 0;	  else	    {	      if (bfd_read ((PTR) thdr.dataLength, 1,			    sizeof (thdr.dataLength), abfd)		  != sizeof (thdr.dataLength))		return false;	      dataLength = get_word (abfd, (bfd_byte *) thdr.dataLength);	    }	  if (hdrLength < 2 * NLM_TARGET_LONG_SIZE + 8)	    memset (dataStamp, 0, sizeof (dataStamp));	  else	    {	      if (bfd_read ((PTR) dataStamp, 1, sizeof (dataStamp), abfd)		  != sizeof (dataStamp))		return false;	    }	  /* Read the rest of the header, if any.  */	  if (hdrLength <= 2 * NLM_TARGET_LONG_SIZE + 8)	    {	      hdr = NULL;	      hdrLength = 0;	    }	  else	    {	      hdrLength -= 2 * NLM_TARGET_LONG_SIZE + 8;	      hdr = bfd_alloc (abfd, hdrLength);	      if (hdr == NULL)		return false;	      if (bfd_read (hdr, 1, hdrLength, abfd) != hdrLength)		return false;	    }	  /* If we have found a Cygnus header, process it.  Otherwise,	     just save the associated data without trying to interpret	     it.  */	  if (strncmp (dataStamp, "CyGnUsEx", 8) == 0)	    {	      file_ptr pos;	      bfd_byte *contents;	      bfd_byte *p, *pend;	      BFD_ASSERT (hdrLength == 0 && hdr == NULL);	      pos = bfd_tell (abfd);	      if (bfd_seek (abfd, dataOffset, SEEK_SET) != 0)		return false;	      contents = (bfd_byte *) bfd_alloc (abfd, dataLength);	      if (contents == NULL)		return false;	      if (bfd_read (contents, 1, dataLength, abfd) != dataLength)		return false;	      if (bfd_seek (abfd, pos, SEEK_SET) != 0)		return false;	      memcpy (nlm_cygnus_ext_header (abfd), "CyGnUsEx", 8);	      nlm_cygnus_ext_header (abfd)->offset = dataOffset;	      nlm_cygnus_ext_header (abfd)->length = dataLength;	      /* This data this header points to provides a list of		 the sections which were in the original object file		 which was converted to become an NLM.  We locate		 those sections and add them to the BFD.  Note that		 this is likely to create a second .text, .data and		 .bss section; retrieving the sections by name will		 get the actual NLM sections, which is what we want to		 happen.  The sections from the original file, which		 may be subsets of the NLM section, can only be found		 using bfd_map_over_sections.  */	      p = contents;	      pend = p + dataLength;	      while (p < pend)		{		  char *name;		  size_t l;		  file_ptr filepos;		  bfd_size_type size;		  asection *newsec;		  /* The format of this information is		     null terminated section name		     zeroes to adjust to 4 byte boundary		     4 byte section data file pointer		     4 byte section size		     */		  name = (char *) p;		  l = strlen (name) + 1;		  l = (l + 3) &~ 3;		  p += l;		  filepos = bfd_h_get_32 (abfd, p);		  p += 4;		  size = bfd_h_get_32 (abfd, p);		  p += 4;		  newsec = bfd_make_section_anyway (abfd, name);		  if (newsec == (asection *) NULL)		    return false;		  newsec->_raw_size = size;		  if (filepos != 0)		    {		      newsec->filepos = filepos;		      newsec->flags |= SEC_HAS_CONTENTS;		    }		}	    }	  else	    {	      memcpy (nlm_custom_header (abfd)->stamp, thdr.stamp,		      sizeof (thdr.stamp));	      nlm_custom_header (abfd)->hdrLength = hdrLength;	      nlm_custom_header (abfd)->dataOffset = dataOffset;	      nlm_custom_header (abfd)->dataLength = dataLength;	      memcpy (nlm_custom_header (abfd)->dataStamp, dataStamp,		      sizeof (dataStamp));	      nlm_custom_header (abfd)->hdr = hdr;	    }	}      else	{	  break;	}    }  return (true);}/* Return whether there is a non-zero byte in a memory block.  */static booleanfind_nonzero (buf, size)     PTR buf;     size_t size;{  char *p = (char *) buf;  while (size-- != 0)    if (*p++ != 0)      return true;  return false;}/* Swap out the contents of the auxiliary headers.  We create those   auxiliary headers which have been set non-zero.  We do not require   the caller to set up the stamp fields.  */static booleannlm_swap_auxiliary_headers_out (abfd)     bfd *abfd;{  /* Write out the version header if there is one.  */  if (find_nonzero ((PTR) nlm_version_header (abfd),		    sizeof (Nlm_Internal_Version_Header)))    {      Nlm_External_Version_Header thdr;      memcpy (thdr.stamp, "VeRsIoN#", 8);      put_word (abfd, (bfd_vma) nlm_version_header (abfd)->majorVersion,		(bfd_byte *) thdr.majorVersion);      put_word (abfd, (bfd_vma) nlm_version_header (abfd)->minorVersion,		(bfd_byte *) thdr.minorVersion);      put_word (abfd, (bfd_vma) nlm_version_header (abfd)->revision,		(bfd_byte *) thdr.revision);      put_word (abfd, (bfd_vma) nlm_version_header (abfd)->year,		(bfd_byte *) thdr.year);      put_word (abfd, (bfd_vma) nlm_version_header (abfd)->month,		(bfd_byte *) thdr.month);      put_word (abfd, (bfd_vma) nlm_version_header (abfd)->day,		(bfd_byte *) thdr.day);      if (bfd_write ((PTR) & thdr, sizeof (thdr), 1, abfd) != sizeof (thdr))	return false;    }  /* Write out the extended header if there is one.  */  if (find_nonzero ((PTR) nlm_extended_header (abfd),		    sizeof (Nlm_Internal_Extended_Header)))    {      Nlm_External_Extended_Header thdr;      memcpy (thdr.stamp, "MeSsAgEs", 8);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->languageID,		(bfd_byte *) thdr.languageID);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->messageFileOffset,		(bfd_byte *) thdr.messageFileOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->messageFileLength,		(bfd_byte *) thdr.messageFileLength);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->messageCount,		(bfd_byte *) thdr.messageCount);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->helpFileOffset,		(bfd_byte *) thdr.helpFileOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->helpFileLength,		(bfd_byte *) thdr.helpFileLength);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->RPCDataOffset,		(bfd_byte *) thdr.RPCDataOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->RPCDataLength,		(bfd_byte *) thdr.RPCDataLength);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->sharedCodeOffset,		(bfd_byte *) thdr.sharedCodeOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->sharedCodeLength,		(bfd_byte *) thdr.sharedCodeLength);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->sharedDataOffset,		(bfd_byte *) thdr.sharedDataOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->sharedDataLength,		(bfd_byte *) thdr.sharedDataLength);      put_word (abfd,	  (bfd_vma) nlm_extended_header (abfd)->sharedRelocationFixupOffset,		(bfd_byte *) thdr.sharedRelocationFixupOffset);      put_word (abfd,	   (bfd_vma) nlm_extended_header (abfd)->sharedRelocationFixupCount,		(bfd_byte *) thdr.sharedRelocationFixupCount);      put_word (abfd,	(bfd_vma) nlm_extended_header (abfd)->sharedExternalReferenceOffset,		(bfd_byte *) thdr.sharedExternalReferenceOffset);      put_word (abfd,	 (bfd_vma) nlm_extended_header (abfd)->sharedExternalReferenceCount,		(bfd_byte *) thdr.sharedExternalReferenceCount);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->sharedPublicsOffset,		(bfd_byte *) thdr.sharedPublicsOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->sharedPublicsCount,		(bfd_byte *) thdr.sharedPublicsCount);      put_word (abfd,	      (bfd_vma) nlm_extended_header (abfd)->sharedDebugRecordOffset,		(bfd_byte *) thdr.sharedDebugRecordOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->sharedDebugRecordCount,		(bfd_byte *) thdr.sharedDebugRecordCount);      put_word (abfd,	   (bfd_vma) nlm_extended_header (abfd)->SharedInitializationOffset,		(bfd_byte *) thdr.sharedInitializationOffset);      put_word (abfd,	    (bfd_vma) nlm_extended_header (abfd)->SharedExitProcedureOffset,		(bfd_byte *) thdr.SharedExitProcedureOffset);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->productID,		(bfd_byte *) thdr.productID);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->reserved0,		(bfd_byte *) thdr.reserved0);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->reserved1,		(bfd_byte *) thdr.reserved1);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->reserved2,		(bfd_byte *) thdr.reserved2);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->reserved3,		(bfd_byte *) thdr.reserved3);      put_word (abfd,		(bfd_vma) nlm_extended_header (abfd)->reserved4,

⌨️ 快捷键说明

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