libbfd.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,383 行 · 第 1/3 页

C
1,383
字号
#define COERCE32(x) \  ((bfd_signed_vma) (long) (((unsigned long) (x) ^ 0x80000000) - 0x80000000))#define EIGHT_GAZILLION (((BFD_HOST_64_BIT)0x80000000) << 32)#define COERCE64(x) \  (((bfd_signed_vma) (x) ^ EIGHT_GAZILLION) - EIGHT_GAZILLION)bfd_vmabfd_getb16 (addr)     register const bfd_byte *addr;{  return (addr[0] << 8) | addr[1];}bfd_vmabfd_getl16 (addr)     register const bfd_byte *addr;{  return (addr[1] << 8) | addr[0];}bfd_signed_vmabfd_getb_signed_16 (addr)     register const bfd_byte *addr;{  return COERCE16((addr[0] << 8) | addr[1]);}bfd_signed_vmabfd_getl_signed_16 (addr)     register const bfd_byte *addr;{  return COERCE16((addr[1] << 8) | addr[0]);}voidbfd_putb16 (data, addr)     bfd_vma data;     register bfd_byte *addr;{  addr[0] = (bfd_byte) (data >> 8);  addr[1] = (bfd_byte) data;}voidbfd_putl16 (data, addr)     bfd_vma data;     register bfd_byte *addr;{  addr[0] = (bfd_byte) data;  addr[1] = (bfd_byte) (data >> 8);}bfd_vmabfd_getb32 (addr)     register const bfd_byte *addr;{  unsigned long v;  v = (unsigned long) addr[0] << 24;  v |= (unsigned long) addr[1] << 16;  v |= (unsigned long) addr[2] << 8;  v |= (unsigned long) addr[3];  return (bfd_vma) v;}bfd_vmabfd_getl32 (addr)     register const bfd_byte *addr;{  unsigned long v;  v = (unsigned long) addr[0];  v |= (unsigned long) addr[1] << 8;  v |= (unsigned long) addr[2] << 16;  v |= (unsigned long) addr[3] << 24;  return (bfd_vma) v;}bfd_signed_vmabfd_getb_signed_32 (addr)     register const bfd_byte *addr;{  unsigned long v;  v = (unsigned long) addr[0] << 24;  v |= (unsigned long) addr[1] << 16;  v |= (unsigned long) addr[2] << 8;  v |= (unsigned long) addr[3];  return COERCE32 (v);}bfd_signed_vmabfd_getl_signed_32 (addr)     register const bfd_byte *addr;{  unsigned long v;  v = (unsigned long) addr[0];  v |= (unsigned long) addr[1] << 8;  v |= (unsigned long) addr[2] << 16;  v |= (unsigned long) addr[3] << 24;  return COERCE32 (v);}bfd_vmabfd_getb64 (addr)     register const bfd_byte *addr ATTRIBUTE_UNUSED;{#ifdef BFD64  bfd_vma low, high;  high= ((((((((addr[0]) << 8) |              addr[1]) << 8) |            addr[2]) << 8) |          addr[3]) );  low = (((((((((bfd_vma)addr[4]) << 8) |              addr[5]) << 8) |            addr[6]) << 8) |          addr[7]));  return high << 32 | low;#else  BFD_FAIL();  return 0;#endif}bfd_vmabfd_getl64 (addr)     register const bfd_byte *addr ATTRIBUTE_UNUSED;{#ifdef BFD64  bfd_vma low, high;  high= (((((((addr[7] << 8) |              addr[6]) << 8) |            addr[5]) << 8) |          addr[4]));  low = ((((((((bfd_vma)addr[3] << 8) |              addr[2]) << 8) |            addr[1]) << 8) |          addr[0]) );  return high << 32 | low;#else  BFD_FAIL();  return 0;#endif}bfd_signed_vmabfd_getb_signed_64 (addr)     register const bfd_byte *addr ATTRIBUTE_UNUSED;{#ifdef BFD64  bfd_vma low, high;  high= ((((((((addr[0]) << 8) |              addr[1]) << 8) |            addr[2]) << 8) |          addr[3]) );  low = (((((((((bfd_vma)addr[4]) << 8) |              addr[5]) << 8) |            addr[6]) << 8) |          addr[7]));  return COERCE64(high << 32 | low);#else  BFD_FAIL();  return 0;#endif}bfd_signed_vmabfd_getl_signed_64 (addr)     register const bfd_byte *addr ATTRIBUTE_UNUSED;{#ifdef BFD64  bfd_vma low, high;  high= (((((((addr[7] << 8) |              addr[6]) << 8) |            addr[5]) << 8) |          addr[4]));  low = ((((((((bfd_vma)addr[3] << 8) |              addr[2]) << 8) |            addr[1]) << 8) |          addr[0]) );  return COERCE64(high << 32 | low);#else  BFD_FAIL();  return 0;#endif}voidbfd_putb32 (data, addr)     bfd_vma data;     register bfd_byte *addr;{        addr[0] = (bfd_byte) (data >> 24);        addr[1] = (bfd_byte) (data >> 16);        addr[2] = (bfd_byte) (data >>  8);        addr[3] = (bfd_byte) data;}voidbfd_putl32 (data, addr)     bfd_vma data;     register bfd_byte *addr;{        addr[0] = (bfd_byte) data;        addr[1] = (bfd_byte) (data >>  8);        addr[2] = (bfd_byte) (data >> 16);        addr[3] = (bfd_byte) (data >> 24);}voidbfd_putb64 (data, addr)     bfd_vma data ATTRIBUTE_UNUSED;     register bfd_byte *addr ATTRIBUTE_UNUSED;{#ifdef BFD64  addr[0] = (bfd_byte) (data >> (7*8));  addr[1] = (bfd_byte) (data >> (6*8));  addr[2] = (bfd_byte) (data >> (5*8));  addr[3] = (bfd_byte) (data >> (4*8));  addr[4] = (bfd_byte) (data >> (3*8));  addr[5] = (bfd_byte) (data >> (2*8));  addr[6] = (bfd_byte) (data >> (1*8));  addr[7] = (bfd_byte) (data >> (0*8));#else  BFD_FAIL();#endif}voidbfd_putl64 (data, addr)     bfd_vma data ATTRIBUTE_UNUSED;     register bfd_byte *addr ATTRIBUTE_UNUSED;{#ifdef BFD64  addr[7] = (bfd_byte) (data >> (7*8));  addr[6] = (bfd_byte) (data >> (6*8));  addr[5] = (bfd_byte) (data >> (5*8));  addr[4] = (bfd_byte) (data >> (4*8));  addr[3] = (bfd_byte) (data >> (3*8));  addr[2] = (bfd_byte) (data >> (2*8));  addr[1] = (bfd_byte) (data >> (1*8));  addr[0] = (bfd_byte) (data >> (0*8));#else  BFD_FAIL();#endif}voidbfd_put_bits (data, addr, bits, big_p)     bfd_vma data;     bfd_byte *addr;     int bits;     boolean big_p;{  int i;  int bytes;  if (bits % 8 != 0)    abort ();  bytes = bits / 8;  for (i = 0; i < bytes; i++)    {      int index = big_p ? bytes - i - 1 : i;      addr[index] = (bfd_byte) data;      data >>= 8;    }}bfd_vmabfd_get_bits (addr, bits, big_p)     bfd_byte *addr;     int bits;     boolean big_p;{  bfd_vma data;  int i;  int bytes;  if (bits % 8 != 0)    abort ();  data = 0;  bytes = bits / 8;  for (i = 0; i < bytes; i++)    {      int index = big_p ? i : bytes - i - 1;      data = (data << 8) | addr[index];    }  return data;}/* Default implementation */boolean_bfd_generic_get_section_contents (abfd, section, location, offset, count)     bfd *abfd;     sec_ptr section;     PTR location;     file_ptr offset;     bfd_size_type count;{  if (count == 0)    return true;  if ((bfd_size_type) (offset + count) > section->_raw_size)    {      bfd_set_error (bfd_error_invalid_operation);      return false;    }  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0      || bfd_read (location, (bfd_size_type) 1, count, abfd) != count)    return false;  return true;}boolean_bfd_generic_get_section_contents_in_window (abfd, section, w, offset, count)     bfd *abfd ATTRIBUTE_UNUSED;     sec_ptr section ATTRIBUTE_UNUSED;     bfd_window *w ATTRIBUTE_UNUSED;     file_ptr offset ATTRIBUTE_UNUSED;     bfd_size_type count ATTRIBUTE_UNUSED;{#ifdef USE_MMAP  if (count == 0)    return true;  if (abfd->xvec->_bfd_get_section_contents != _bfd_generic_get_section_contents)    {      /* We don't know what changes the bfd's get_section_contents	 method may have to make.  So punt trying to map the file	 window, and let get_section_contents do its thing.  */      /* @@ FIXME : If the internal window has a refcount of 1 and was	 allocated with malloc instead of mmap, just reuse it.  */      bfd_free_window (w);      w->i = (bfd_window_internal *) bfd_zmalloc (sizeof (bfd_window_internal));      if (w->i == NULL)	return false;      w->i->data = (PTR) bfd_malloc ((size_t) count);      if (w->i->data == NULL)	{	  free (w->i);	  w->i = NULL;	  return false;	}      w->i->mapped = 0;      w->i->refcount = 1;      w->size = w->i->size = count;      w->data = w->i->data;      return bfd_get_section_contents (abfd, section, w->data, offset, count);    }  if ((bfd_size_type) (offset+count) > section->_raw_size      || (bfd_get_file_window (abfd, section->filepos + offset, count, w, true)	  == false))    return false;  return true;#else  abort ();#endif}/* This generic function can only be used in implementations where creating   NEW sections is disallowed.  It is useful in patching existing sections   in read-write files, though.  See other set_section_contents functions   to see why it doesn't work for new sections.  */boolean_bfd_generic_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)    return true;  if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) == -1      || bfd_write (location, (bfd_size_type) 1, count, abfd) != count)    return false;  return true;}/*INTERNAL_FUNCTION	bfd_log2SYNOPSIS	unsigned int bfd_log2(bfd_vma x);DESCRIPTION	Return the log base 2 of the value supplied, rounded up.  E.g., an	@var{x} of 1025 returns 11.*/unsigned intbfd_log2 (x)     bfd_vma x;{  unsigned int result = 0;  while ((x = (x >> 1)) != 0)    ++result;  return result;}booleanbfd_generic_is_local_label_name (abfd, name)     bfd *abfd;     const char *name;{  char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';  return (name[0] == locals_prefix);}/*  Can be used from / for bfd_merge_private_bfd_data to check that    endianness matches between input and output file.  Returns    true for a match, otherwise returns false and emits an error.  */boolean_bfd_generic_verify_endian_match (ibfd, obfd)     bfd *ibfd;     bfd *obfd;{  if (ibfd->xvec->byteorder != obfd->xvec->byteorder      && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN      && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)    {      const char *msg;      if (bfd_big_endian (ibfd))	msg = _("%s: compiled for a big endian system and target is little endian");      else	msg = _("%s: compiled for a little endian system and target is big endian");      (*_bfd_error_handler) (msg, bfd_get_filename (ibfd));      bfd_set_error (bfd_error_wrong_format);      return false;    }  return true;}

⌨️ 快捷键说明

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