This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 64-bit clean-up in mn10300 disassembler


On May 24, 2000, Alexandre Oliva <aoliva@cygnus.com> wrote:

> Probably because value (which is unsigned long) is printed with "%d",
> which is a problem in itself.

> +		value = ((value ^ ((unsigned long)1) << (operand->bits - 1))

This could use some extra parenthesizing.  Here's a new patch that
obviates the previous one, and addresses both issues.  Ok to install?

Index: opcodes/ChangeLog
from  Alexandre Oliva  <aoliva@cygnus.com>

	* m10300-dis.c (disassemble): Don't assume 32-bit longs when
	sign-extending operands.

Index: opcodes/m10300-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/m10300-dis.c,v
retrieving revision 1.4
diff -u -r1.4 m10300-dis.c
--- opcodes/m10300-dis.c	2000/04/20 22:15:32	1.4
+++ opcodes/m10300-dis.c	2000/05/24 15:15:04
@@ -484,6 +484,8 @@
 		  temp = extension >> operand->shift;
 		  temp &= ((1 << (32 - operand->bits)) - 1);
 		  value |= temp;
+		  value = ((value ^ (((unsigned long)1) << 31))
+			   - (((unsigned long)1) << 31));
 		}
 	      else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
 		{
@@ -494,7 +496,7 @@
 		  temp &= ((1 << (24 - operand->bits)) - 1);
 		  value |= temp;
 		  if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
-		    value = ((value & 0xffffff) ^ (~0x7fffff)) + 0x800000;
+		    value = ((value & 0xffffff) ^ 0x800000) - 0x800000;
 		}
 	      else if ((operand->flags & MN10300_OPERAND_EXTENDED) != 0)
 		{
@@ -508,11 +510,10 @@
 		}
 
 	      if ((operand->flags & MN10300_OPERAND_SIGNED) != 0
-		   /* These are properly extended by the code above.  */
-		   && ((operand->flags & MN10300_OPERAND_24BIT) == 0)
-		  )
-		value = ((long)(value << (32 - operand->bits))
-			  >> (32 - operand->bits));
+		  /* These are properly extended by the code above.  */
+		  && ((operand->flags & MN10300_OPERAND_24BIT) == 0))
+		value = ((value ^ (((unsigned long)1) << (operand->bits - 1)))
+			 - (((unsigned long)1) << (operand->bits - 1)));
 
 	      if (!nocomma
 		  && (!paren
@@ -525,14 +526,14 @@
 		{
 		  value = ((insn >> (operand->shift + extra_shift))
 			   & ((1 << operand->bits) - 1));
-		  (*info->fprintf_func) (info->stream, "d%d", value);
+		  (*info->fprintf_func) (info->stream, "d%d", (int)value);
 		}
 
 	      else if ((operand->flags & MN10300_OPERAND_AREG) != 0)
 		{
 		  value = ((insn >> (operand->shift + extra_shift))
 			   & ((1 << operand->bits) - 1));
-		  (*info->fprintf_func) (info->stream, "a%d", value);
+		  (*info->fprintf_func) (info->stream, "a%d", (int)value);
 		}
 
 	      else if ((operand->flags & MN10300_OPERAND_SP) != 0)
@@ -549,11 +550,11 @@
 		  value = ((insn >> (operand->shift + extra_shift))
 			   & ((1 << operand->bits) - 1));
 		  if (value < 8)
-		    (*info->fprintf_func) (info->stream, "r%d", value);
+		    (*info->fprintf_func) (info->stream, "r%d", (int)value);
 		  else if (value < 12)
-		    (*info->fprintf_func) (info->stream, "a%d", value - 8);
+		    (*info->fprintf_func) (info->stream, "a%d", (int)value - 8);
 		  else
-		    (*info->fprintf_func) (info->stream, "d%d", value - 12);
+		    (*info->fprintf_func) (info->stream, "d%d", (int)value - 12);
 		}
 
 	      else if ((operand->flags & MN10300_OPERAND_XRREG) != 0)
@@ -563,7 +564,7 @@
 		  if (value == 0)
 		    (*info->fprintf_func) (info->stream, "sp", value);
 		  else
-		  (*info->fprintf_func) (info->stream, "xr%d", value);
+		  (*info->fprintf_func) (info->stream, "xr%d", (int)value);
 		}
 
 	      else if ((operand->flags & MN10300_OPERAND_USP) != 0)
@@ -670,7 +671,7 @@
 		}
 
 	      else 
-		(*info->fprintf_func) (info->stream, "%d", value);
+		(*info->fprintf_func) (info->stream, "%ld", (long)value);
 	    }
 	  /* All done. */
 	  break;

-- 
Alexandre Oliva    Enjoy Guaranį, see http://www.ic.unicamp.br/~oliva/
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]