This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Commit: FRV: Fix parsing of signed constants on 64-bit hosts


Hi Guys,

  I am applying the patch below to fix a couple of problems with the FRV
  port of GAS when building the Linux kernel on a 64-bit host.  There
  were a couple of places where we were not handling the sign extension
  correctly.

Cheers
  Nick


cpu/ChangeLog
2011-12-15  Nick Clifton  <nickc@redhat.com>

	* frv.opc (parse_uhi16): Fix handling of %hi operator on 64-bit
	hosts.

opcodes/ChangeLog
2011-12-15  Nick Clifton  <nickc@redhat.com>

	* cgen-asm.c (cgen_parse_signed_integer): Add code to handle the
	sign extension of negative values on a 64-bit host.
	* frv-asm.c: Regenerate.

gas/testsuite/ChangeLog
2011-12-15  Nick Clifton  <nickc@redhat.com>

	* gas/frv/immediates.s: New test file - checks assembly of
	constant values.
	* gas/frv/immediates.d: Expected disassembly.
	* gas/frv/allinsn.exp: Run the new test.

Index: cpu/frv.opc
===================================================================
RCS file: /cvs/src/src/cpu/frv.opc,v
retrieving revision 1.18
diff -u -3 -p -r1.18 frv.opc
--- cpu/frv.opc	8 Oct 2010 14:00:48 -0000	1.18
+++ cpu/frv.opc	15 Dec 2011 10:15:42 -0000
@@ -1343,11 +1343,11 @@ parse_uhi16 (CGEN_CPU_DESC cd,
 	  if (errmsg == NULL
 	      && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
 	    {
-	      /* If bfd_vma is wider than 32 bits, but we have a sign-
-		 or zero-extension, truncate it.  */
-	      if (value >= - ((bfd_vma)1 << 31)
-		  || value <= ((bfd_vma)1 << 31) - (bfd_vma)1)
-		value &= (((bfd_vma)1 << 16) << 16) - 1;
+ 	      /* If value is wider than 32 bits then be
+ 		 careful about how we extract bits 16-31.  */
+ 	      if (sizeof (value) > 4)
+ 		value &= (((bfd_vma)1 << 16) << 16) - 1;
+
 	      value >>= 16;
 	    }
 	  *valuep = value;

Index: opcodes/cgen-asm.c
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-asm.c,v
retrieving revision 1.14
diff -u -3 -p -r1.14 cgen-asm.c
--- opcodes/cgen-asm.c	2 Sep 2009 07:20:29 -0000	1.14
+++ opcodes/cgen-asm.c	15 Dec 2011 10:15:42 -0000
@@ -268,7 +268,23 @@ cgen_parse_signed_integer (CGEN_CPU_DESC
      &result, &value);
   /* FIXME: Examine `result'.  */
   if (!errmsg)
-    *valuep = value;
+    {
+      /* Handle the case where a hex value is parsed on a 64-bit host.
+	 A value like 0xffffe000 is clearly intended to be a negative
+	 16-bit value, but on a 64-bit host it will be parsed by gas
+	 as 0x00000000ffffe000.
+
+	 The shifts below are designed not to produce compile time
+	 warnings on a 32-bit host.  */
+      if (sizeof (value) > 4
+	  && result == CGEN_PARSE_OPERAND_RESULT_NUMBER
+	  && value > 0
+	  && (value & 0x80000000)
+	  && ((value >> 31) == 1))
+	value |= -1 << 31;
+
+      *valuep = value;
+    }
   return errmsg;
 }
 
Index: gas/testsuite/gas/frv/allinsn.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/frv/allinsn.exp,v
retrieving revision 1.6
diff -u -3 -p -r1.6 allinsn.exp
--- gas/testsuite/gas/frv/allinsn.exp	5 Jun 2007 17:00:32 -0000	1.6
+++ gas/testsuite/gas/frv/allinsn.exp	15 Dec 2011 10:15:43 -0000
@@ -17,4 +17,6 @@ if [istarget frv*-*-*] {
     run_list_test "fr450-media-issue" "-mcpu=fr450"
 
     run_dump_test "fr550-pack1"
+
+    run_dump_test "immediates"
 }
*** /dev/null	2011-12-15 08:16:22.938348492 +0000
--- gas/testsuite/gas/frv/immediates.s	2011-12-15 09:42:21.559491505 +0000
***************
*** 0 ****
--- 1,9 ----
+ 	;; These instructions can be found in the FRV Linux kernel.
+ 	;; They used to fail to assemble on 64-bit host machines
+ 	;; because of sign-extension problems.
+ 
+ 	.text
+ 	.global foo
+ foo:
+ 	setlos   #0xffffe000, gr3
+ 	sethi.p  %hi(~(0x80000000 | 0x40000000)), gr4
*** /dev/null	2011-12-15 08:16:22.938348492 +0000
--- gas/testsuite/gas/frv/immediates.d	2011-12-15 10:09:12.584536140 +0000
***************
*** 0 ****
--- 1,12 ----
+ #as:
+ #objdump: -d
+ #name: Parsing immediate values
+ 
+ .*: +file format .*
+ 
+ Disassembly of section \.text:
+ 
+ 00000000 <foo>:
+    0:[ 	]+86 fc e0 00[ 	]+setlos 0xff+e000,gr3
+    4:[ 	]+08 f8 3f ff[ 	]+sethi.p 0x3fff,gr4
+ 
  


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