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]

[PATCH] Check value range for 16 bit immediate in load immediate intruction for bfin target of gas


I'll commit this patch in a short time to fix an issue of bfin target
of gas. Previously bfin target gas will silently accept such
instruction:

r0 = 0x12345678;

and translate it into

r0 = 0x5678 (X);

With this patch, gas will throw an "immediate out of range" error for
such instructions.

Jie
	* config/bfin-parse.y (asm_1): Check value range for 16 bit immediate
	in load immediate intruction.

Index: config/bfin-parse.y
===================================================================
RCS file: /cvs/src/src/gas/config/bfin-parse.y,v
retrieving revision 1.3
diff -u -r1.3 bfin-parse.y
--- config/bfin-parse.y	20 Jan 2006 16:57:09 -0000	1.3
+++ config/bfin-parse.y	20 Jan 2006 17:14:46 -0000
@@ -1221,24 +1221,21 @@
 	      /* 7 bit immediate value if possible.
 		 We will check for that constant value for efficiency
 		 If it goes to reloc, it will be 16 bit.  */
-	      if (IS_CONST ($3) && IS_IMM ($3, 7) && (IS_DREG ($1) || IS_PREG ($1)))
+	      if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_DREG ($1))
 		{
-		  /* if the expr is a relocation, generate it.  */
-		  if (IS_DREG ($1) && IS_IMM ($3, 7))
-		    {
-		      notethat ("COMPI2opD: dregs = imm7 (x) \n");
-		      $$ = COMPI2OPD (&$1, imm7 ($3), 0);
-		    }
-		  else if (IS_PREG ($1) && IS_IMM ($3, 7))
-		    {
-		      notethat ("COMPI2opP: pregs = imm7 (x)\n");
-		      $$ = COMPI2OPP (&$1, imm7 ($3), 0);
-		    }
-		  else
-		    return yyerror ("Bad register or value for assigment");
+		  notethat ("COMPI2opD: dregs = imm7 (x) \n");
+		  $$ = COMPI2OPD (&$1, imm7 ($3), 0);
+		}
+	      else if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_PREG ($1))
+		{
+		  notethat ("COMPI2opP: pregs = imm7 (x)\n");
+		  $$ = COMPI2OPP (&$1, imm7 ($3), 0);
 		}
 	      else
 		{
+		  if (IS_CONST ($3) && !IS_IMM ($3, 16))
+		    return yyerror ("Immediate value out of range");
+
 		  notethat ("LDIMMhalf: regs = luimm16 (x)\n");
 		  /* reg, H, S, Z.   */
 		  $$ = LDIMMHALF_R5 (&$1, 0, 1, 0, $3);
@@ -1248,6 +1245,10 @@
 	    {
 	      /* (z) There is no 7 bit zero extended instruction.
 	      If the expr is a relocation, generate it.   */
+
+	      if (IS_CONST ($3) && !IS_UIMM ($3, 16))
+		return yyerror ("Immediate value out of range");
+
 	      notethat ("LDIMMhalf: regs = luimm16 (x)\n");
 	      /* reg, H, S, Z.  */
 	      $$ = LDIMMHALF_R5 (&$1, 0, 0, 1, $3);

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