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

Re: [PATCH] MIPS gas: use $zero as alias for $0


Daniel Jacobowitz wrote:
> On Sat, Jun 01, 2002 at 04:00:20AM +0200, Thiemo Seufer wrote:
> > Hi All,
> > 
> > this adds '$zero' as an alias name for the hardware special register $0.
> > It also allows the use of $kt0, $kt1 aliases, this is compatible to native
> > mips tools.
> 
> > @@ -8231,6 +8219,11 @@ mips_ip (str, ip)
> >  			  s += 4;
> >  			  regno = KT1;
> >  			}
> > +		      else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == '0')
> > +			{
> > +			  s += 5;
> > +			  regno = ZERO;
> > +			}
> >  		      else if (itbl_have_entries)
> >  			{
> >  			  char *p, *n;
> 
> Surely you meant 's[4] == 'o''?

Yes. :-) Thanks for spotting this.

> > @@ -12230,6 +12203,12 @@ tc_get_register (frame)
> >  	reg = GP;
> >        else if (strncmp (input_line_pointer, "at", 2) == 0)
> >  	reg = AT;
> > +      else if (strncmp (input_line_pointer, "kt0", 3) == 0)
> > +	reg = KT0;
> > +      else if (strncmp (input_line_pointer, "kt1", 3) == 0)
> > +	reg = KT1;
> > +      else if (strncmp (input_line_pointer, "zero", 4) == 0)
> > +	reg = ZERO;
> >        else
> >  	{
> >  	  as_warn (_("Unrecognized register name"));
> 
> This isn't introduced by your patch, but - what will this code do with
> "$at1" or "$kt12"?

It should ignore that there is no word seaparator and complain about
a bogus '1' or '2'.

I see that incrementing the input_line_pointer is broken in this code.
The updated patch below fixes this.


Thiemo


2002-06-01  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>

	/gas/ChangeLog
	* config/tc-mips.c: Add define for $zero register.
	(md_begin): Add $zero as alias name for $0.
	(mips_ip): Likewise.
	(mips16_ip): Likewise.
	(s_cplocal): Demand empty rest of input line.
	(tc_get_register): Likewise. Add support for $kt0, kt1 register
	names. Use ZERO define. Fix input_line_pointer progress.
	(insn_uses_reg): Use ZERO define.


diff -BurpNX /bigdisk/src/binutils-exclude source-orig/gas/config/tc-mips.c source/gas/config/tc-mips.c
--- source-orig/gas/config/tc-mips.c	Fri May 31 04:31:10 2002
+++ source/gas/config/tc-mips.c	Fri May 31 20:56:30 2002
@@ -82,6 +82,7 @@ static int mips_output_flavor () { retur
 static char *mips_regmask_frag;
 #endif
 
+#define ZERO 0
 #define AT  1
 #define TREG 24
 #define PIC_CALL_REG 25
@@ -1351,6 +1351,8 @@ md_begin ()
 				   &zero_address_frag));
   symbol_table_insert (symbol_new ("$kt1", reg_section, KT1,
 				   &zero_address_frag));
+  symbol_table_insert (symbol_new ("$zero", reg_section, ZERO,
+				   &zero_address_frag));
   symbol_table_insert (symbol_new ("$pc", reg_section, -1,
 				   &zero_address_frag));
 
@@ -1534,8 +1536,8 @@ insn_uses_reg (ip, reg, class)
       class = MIPS_GR_REG;
     }
 
-  /* Don't report on general register 0, since it never changes.  */
-  if (class == MIPS_GR_REG && reg == 0)
+  /* Don't report on general register ZERO, since it never changes.  */
+  if (class == MIPS_GR_REG && reg == ZERO)
     return 0;
 
   if (class == MIPS_FP_REG)
@@ -8231,6 +8219,11 @@ mips_ip (str, ip)
 			  s += 4;
 			  regno = KT1;
 			}
+		      else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
+			{
+			  s += 5;
+			  regno = ZERO;
+			}
 		      else if (itbl_have_entries)
 			{
 			  char *p, *n;
@@ -9189,6 +9115,11 @@ mips16_ip (str, ip)
 		      s += 4;
 		      regno = KT1;
 		    }
+		  else if (s[1] == 'z' && s[2] == 'e' && s[3] == 'r' && s[4] == 'o')
+		    {
+		      s += 5;
+		      regno = ZERO;
+		    }
 		  else
 		    break;
 		}
@@ -11949,6 +11922,7 @@ s_cplocal (ignore)
     }
 
   mips_gp_register = tc_get_register (0);
+  demand_empty_rest_of_line ();
 }
 
 /* Handle the .cprestore pseudo-op.  This stores $gp into a given
@@ -12207,7 +12181,7 @@ tc_get_register (frame)
   if (*input_line_pointer++ != '$')
     {
       as_warn (_("expected `$'"));
-      reg = 0;
+      reg = ZERO;
     }
   else if (ISDIGIT (*input_line_pointer))
     {
@@ -12215,27 +12189,58 @@ tc_get_register (frame)
       if (reg < 0 || reg >= 32)
 	{
 	  as_warn (_("Bad register number"));
-	  reg = 0;
+	  reg = ZERO;
 	}
     }
   else
     {
       if (strncmp (input_line_pointer, "ra", 2) == 0)
-	reg = RA;
+	{
+	  reg = RA;
+	  input_line_pointer += 2;
+	}
       else if (strncmp (input_line_pointer, "fp", 2) == 0)
-	reg = FP;
+	{
+	  reg = FP;
+	  input_line_pointer += 2;
+	}
       else if (strncmp (input_line_pointer, "sp", 2) == 0)
-	reg = SP;
+	{
+	  reg = SP;
+	  input_line_pointer += 2;
+	}
       else if (strncmp (input_line_pointer, "gp", 2) == 0)
-	reg = GP;
+	{
+	  reg = GP;
+	  input_line_pointer += 2;
+	}
       else if (strncmp (input_line_pointer, "at", 2) == 0)
-	reg = AT;
+	{
+	  reg = AT;
+	  input_line_pointer += 2;
+	}
+      else if (strncmp (input_line_pointer, "kt0", 3) == 0)
+	{
+	  reg = KT0;
+	  input_line_pointer += 3;
+	}
+      else if (strncmp (input_line_pointer, "kt1", 3) == 0)
+	{
+	  reg = KT1;
+	  input_line_pointer += 3;
+	}
+      else if (strncmp (input_line_pointer, "zero", 4) == 0)
+	{
+	  reg = ZERO;
+	  input_line_pointer += 4;
+	}
       else
 	{
 	  as_warn (_("Unrecognized register name"));
-	  reg = 0;
+	  reg = ZERO;
+	  while (ISALNUM(*input_line_pointer))
+	   input_line_pointer++;
 	}
-      input_line_pointer += 2;
     }
   if (frame)
     {


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