cpu-ns32k.c

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

C
845
字号
	    if ((bfd_vma) check > reloc_unsigned_max)	      flag = bfd_reloc_overflow;	  }	  break;	case complain_overflow_bitfield:	  {	    /* Assumes two's complement.  This expression avoids	       overflow if howto->bitsize is the number of bits in	       bfd_vma.  */	    bfd_vma reloc_bits = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;	    if (((bfd_vma) check & ~reloc_bits) != 0		&& ((bfd_vma) check & ~reloc_bits) != (-1 & ~reloc_bits))	      {		/* The above right shift is incorrect for a signed		   value.  See if turning on the upper bits fixes the		   overflow.  */		if (howto->rightshift > howto->bitpos		    && (bfd_signed_vma) relocation < 0)		  {		    check |= ((bfd_vma) - 1			      & ~((bfd_vma) - 1				  >> (howto->rightshift - howto->bitpos)));		    if (((bfd_vma) check & ~reloc_bits) != (-1 & ~reloc_bits))		      flag = bfd_reloc_overflow;		  }		else		  flag = bfd_reloc_overflow;	      }	  }	  break;	default:	  abort ();	}    }  /*    Either we are relocating all the way, or we don't want to apply    the relocation to the reloc entry (probably because there isn't    any room in the output format to describe addends to relocs)    */  /* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler     (OSF version 1.3, compiler version 3.11).  It miscompiles the     following program:     struct str     {       unsigned int i0;     } s = { 0 };     int     main ()     {       unsigned long x;       x = 0x100000000;       x <<= (unsigned long) s.i0;       if (x == 0)	 printf ("failed\n");       else	 printf ("succeeded (%lx)\n", x);     }     */  relocation >>= (bfd_vma) howto->rightshift;  /* Shift everything up to where it's going to be used */  relocation <<= (bfd_vma) howto->bitpos;  /* Wait for the day when all have the mask in them */  /* What we do:     i instruction to be left alone     o offset within instruction     r relocation offset to apply     S src mask     D dst mask     N ~dst mask     A part 1     B part 2     R result     Do this:     i i i i i o o o o o        from bfd_get<size>     and           S S S S S    to get the size offset we want     +   r r r r r r r r r r  to get the final value to place     and           D D D D D  to chop to right size     -----------------------     A A A A A     And this:     ...   i i i i i o o o o o  from bfd_get<size>     and   N N N N N            get instruction     -----------------------     ...   B B B B B     And then:     B B B B B     or              A A A A A     -----------------------     R R R R R R R R R R        put into bfd_put<size>     */#define DOIT(x) \  x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) +  relocation) & howto->dst_mask))  switch (howto->size)    {    case 0:      {	char x = get_data (data, addr, 1);	DOIT (x);	overflow = put_data(x, data, addr, 1);      }      break;    case 1:      if (relocation)	{	  short x = get_data (data, addr, 2);	  DOIT (x);	  overflow = put_data(x, (unsigned char *) data, addr, 2);	}      break;    case 2:      if (relocation)	{	  long x = get_data (data, addr, 4);	  DOIT (x);	  overflow = put_data(x, data, addr, 4);	}      break;    case -2:      {	long  x = get_data(data, addr, 4);	relocation = -relocation;	DOIT(x);	overflow = put_data(x, data , addr, 4);      }      break;    case 3:      /* Do nothing */      break;    case 4:#ifdef BFD64      if (relocation)	{	  bfd_vma x = get_data (data, addr, 8);	  DOIT (x);	  overflow = put_data(x, data, addr, 8);	}#else      abort ();#endif      break;    default:      return bfd_reloc_other;    }  if ((howto->complain_on_overflow != complain_overflow_dont) && overflow)    return bfd_reloc_overflow;  return flag;}/* Relocate a given location using a given value and howto.  */bfd_reloc_status_type_bfd_do_ns32k_reloc_contents ( howto, input_bfd, relocation, location,			      get_data, put_data)     reloc_howto_type *howto;     bfd *input_bfd ATTRIBUTE_UNUSED;     bfd_vma relocation;     bfd_byte *location;     long (*get_data) ();     int (*put_data) ();{  int size;  bfd_vma x;  boolean overflow;  /* If the size is negative, negate RELOCATION.  This isn't very     general.  */  if (howto->size < 0)    relocation = -relocation;  /* Get the value we are going to relocate.  */  size = bfd_get_reloc_size (howto);  switch (size)    {    default:    case 0:      abort ();    case 1:    case 2:    case 4:#ifdef BFD64    case 8:#endif      x = get_data (location, 0, size);      break;    }  /* Check for overflow.  FIXME: We may drop bits during the addition     which we don't check for.  We must either check at every single     operation, which would be tedious, or we must do the computations     in a type larger than bfd_vma, which would be inefficient.  */  overflow = false;  if (howto->complain_on_overflow != complain_overflow_dont)    {      bfd_vma check;      bfd_signed_vma signed_check;      bfd_vma add;      bfd_signed_vma signed_add;      if (howto->rightshift == 0)	{	  check = relocation;	  signed_check = (bfd_signed_vma) relocation;	}      else	{	  /* Drop unwanted bits from the value we are relocating to.  */	  check = relocation >> howto->rightshift;	  /* If this is a signed value, the rightshift just dropped	     leading 1 bits (assuming twos complement).  */	  if ((bfd_signed_vma) relocation >= 0)	    signed_check = check;	  else	    signed_check = (check			    | ((bfd_vma) - 1			       & ~((bfd_vma) - 1 >> howto->rightshift)));	}      /* Get the value from the object file.  */      add = x & howto->src_mask;      /* Get the value from the object file with an appropriate sign.	 The expression involving howto->src_mask isolates the upper	 bit of src_mask.  If that bit is set in the value we are	 adding, it is negative, and we subtract out that number times	 two.  If src_mask includes the highest possible bit, then we	 can not get the upper bit, but that does not matter since	 signed_add needs no adjustment to become negative in that	 case.  */      signed_add = add;      if ((add & (((~howto->src_mask) >> 1) & howto->src_mask)) != 0)	signed_add -= (((~howto->src_mask) >> 1) & howto->src_mask) << 1;      /* Add the value from the object file, shifted so that it is a	 straight number.  */      if (howto->bitpos == 0)	{	  check += add;	  signed_check += signed_add;	}      else	{	  check += add >> howto->bitpos;	  /* For the signed case we use ADD, rather than SIGNED_ADD,	     to avoid warnings from SVR4 cc.  This is OK since we	     explictly handle the sign bits.  */	  if (signed_add >= 0)	    signed_check += add >> howto->bitpos;	  else	    signed_check += ((add >> howto->bitpos)			     | ((bfd_vma) - 1				& ~((bfd_vma) - 1 >> howto->bitpos)));	}      switch (howto->complain_on_overflow)	{	case complain_overflow_signed:	  {	    /* Assumes two's complement.  */	    bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;	    bfd_signed_vma reloc_signed_min = ~reloc_signed_max;	    if (signed_check > reloc_signed_max		|| signed_check < reloc_signed_min)	      overflow = true;	  }	  break;	case complain_overflow_unsigned:	  {	    /* Assumes two's complement.  This expression avoids	       overflow if howto->bitsize is the number of bits in	       bfd_vma.  */	    bfd_vma reloc_unsigned_max =	    (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;	    if (check > reloc_unsigned_max)	      overflow = true;	  }	  break;	case complain_overflow_bitfield:	  {	    /* Assumes two's complement.  This expression avoids	       overflow if howto->bitsize is the number of bits in	       bfd_vma.  */	    bfd_vma reloc_bits = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;	    if ((check & ~reloc_bits) != 0		&& (((bfd_vma) signed_check & ~reloc_bits)		    != (-1 & ~reloc_bits)))	      overflow = true;	  }	  break;	default:	  abort ();	}    }  /* Put RELOCATION in the right bits.  */  relocation >>= (bfd_vma) howto->rightshift;  relocation <<= (bfd_vma) howto->bitpos;  /* Add RELOCATION to the right bits of X.  */  x = ((x & ~howto->dst_mask)       | (((x & howto->src_mask) + relocation) & howto->dst_mask));  /* Put the relocated value back in the object file.  */  switch (size)    {    default:    case 0:      abort ();    case 1:    case 2:    case 4:#ifdef BFD64    case 8:#endif      put_data(x, location, 0, size);      break;    }  return overflow ? bfd_reloc_overflow : bfd_reloc_ok;}bfd_reloc_status_type_bfd_ns32k_reloc_disp (abfd, reloc_entry, symbol, data, input_section,		       output_bfd, error_message)     bfd *abfd;     arelent *reloc_entry;     struct symbol_cache_entry *symbol;     PTR data;     asection *input_section;     bfd *output_bfd;     char **error_message;{  return do_ns32k_reloc (abfd, reloc_entry, symbol, data, input_section,			 output_bfd, error_message,			 _bfd_ns32k_get_displacement,			 _bfd_ns32k_put_displacement);}bfd_reloc_status_type_bfd_ns32k_reloc_imm (abfd, reloc_entry, symbol, data, input_section,		      output_bfd, error_message)     bfd *abfd;     arelent *reloc_entry;     struct symbol_cache_entry *symbol;     PTR data;     asection *input_section;     bfd *output_bfd;     char **error_message;{  return do_ns32k_reloc (abfd, reloc_entry, symbol, data, input_section,			 output_bfd, error_message, _bfd_ns32k_get_immediate,			 _bfd_ns32k_put_immediate);}bfd_reloc_status_type_bfd_ns32k_final_link_relocate (howto, input_bfd, input_section, contents,				address, value, addend)     reloc_howto_type *howto;     bfd *input_bfd;     asection *input_section;     bfd_byte *contents;     bfd_vma address;     bfd_vma value;     bfd_vma addend;{  bfd_vma relocation;  /* Sanity check the address.  */  if (address > input_section->_cooked_size)    return bfd_reloc_outofrange;  /* This function assumes that we are dealing with a basic relocation     against a symbol.  We want to compute the value of the symbol to     relocate to.  This is just VALUE, the value of the symbol, plus     ADDEND, any addend associated with the reloc.  */  relocation = value + addend;  /* If the relocation is PC relative, we want to set RELOCATION to     the distance between the symbol (currently in RELOCATION) and the     location we are relocating.  Some targets (e.g., i386-aout)     arrange for the contents of the section to be the negative of the     offset of the location within the section; for such targets     pcrel_offset is false.  Other targets (e.g., m88kbcs or ELF)     simply leave the contents of the section as zero; for such     targets pcrel_offset is true.  If pcrel_offset is false we do not     need to subtract out the offset of the location within the     section (which is just ADDRESS).  */  if (howto->pc_relative)    {      relocation -= (input_section->output_section->vma		     + input_section->output_offset);      if (howto->pcrel_offset)	relocation -= address;    }  return _bfd_ns32k_relocate_contents (howto, input_bfd, relocation,				       contents + address);}

⌨️ 快捷键说明

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