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]

Re: [patch] Some improvements for m68k/mri mode - update


Nick Clifton wrote:
> 
> Hi Peter,
> 
> > This patch corrects some 68k/mri mode problems.
> 
> >       * gas/macro.c (macro_expand): Allow macro invocation with empty
> >       extension.
> 
> This part of your patch breaks the gasp MRI macro test in the gas
> testsuite.  Since I am not familiar with MRI I do not know if the test
> or the patch is broken.  Please can you have a look at this and
> resubmit your patch either with a corrected test or a fixed change to
> macro.c.
> 

Opps,

don't have working dejagnu/exspect here. Hope this works:




This patch corrects some 68k/mri mode problems.

The operands of structured control directives must be swapped to
make the resulting code compatible with the Microtec assembler.
The patch allows upper case extensions like in THEN.S etc.
Some conditions (HS, LO) have been added for compatibility.
Some other small problems have been fixed (see below).


src/gas ChangeLog:

2001-06-06  Peter Jakubek <pjak@snafu.de>
        * gas/config/tc-m68k.c (parse_mri_control_operand): Fix handling
        of AND/OR.
        (swap_mri_condition): Add HS (alias fo CC) and LO (alias for CS).
        (reverse_mri_condition): Likewise.
        (swap_mri_condition): Issue warning for conditions that can not be
        swapped.
        (build_mri_control_operand): Fix order of operands (swapped).
        (build_mri_control_operand): Allow upper case extension in structured
        control directives.
        (s_mri_else): Likewise.
        (s_mri_next): Likewise.
        (s_mri_for): Likewise.
        (s_mri_if): Fix handling comment ('*') in mri mode.
        (s_mri_while): Likewise.
        * gas/macro.c (macro_expand): Allow macro invocation with empty
        extension.


src/gas/testsuite ChangeLog:

2001-06-06  Peter Jakubek <pjak@snafu.de>
        * gas/mri/for.d: Correct for swapped operands.
        * gas/mri/if.d: Likewise.
        * gas/mri/repeat.d: Likewise.
        * gas/mri/while.d: Likewise.



diff -ru src.orig/gas/config/tc-m68k.c src/gas/config/tc-m68k.c
--- src.orig/gas/config/tc-m68k.c	Wed Jun 06 22:11:06 2001
+++ src/gas/config/tc-m68k.c	Wed Jun 06 23:24:46 2001
@@ -5728,11 +5728,17 @@
   /* Look ahead for AND or OR or end of line.  */
   for (s = input_line_pointer; *s != '\0'; ++s)
     {
-      if ((strncasecmp (s, "AND", 3) == 0
-	   && (s[3] == '.' || ! is_part_of_name (s[3])))
-	  || (strncasecmp (s, "OR", 2) == 0
-	      && (s[2] == '.' || ! is_part_of_name (s[2]))))
-	break;
+      /* We must make sure we don't misinterpret AND/OR at the end of labels!
+         if d0 <eq> #FOOAND and d1 <ne> #BAROR then
+                        ^^^                 ^^ */
+      if (    (    s == input_line_pointer
+                || *(s-1) == ' '
+                || *(s-1) == '\t')
+           && (    (    strncasecmp (s, "AND", 3) == 0
+                     && (s[3] == '.' || ! is_part_of_name (s[3])))
+                || (    strncasecmp (s, "OR", 2) == 0
+                     && (s[2] == '.' || ! is_part_of_name (s[2])))))
+	      break;
     }
 
   *rightstart = input_line_pointer;
@@ -5759,7 +5765,11 @@
     {
     case MCC ('h', 'i'): return MCC ('c', 's');
     case MCC ('l', 's'): return MCC ('c', 'c');
+    /* <HS> is an alias for <CC> */
+    case MCC ('h', 's'):
     case MCC ('c', 'c'): return MCC ('l', 's');
+    /* <LO> is an alias for <CS> */
+    case MCC ('l', 'o'):
     case MCC ('c', 's'): return MCC ('h', 'i');
     case MCC ('p', 'l'): return MCC ('m', 'i');
     case MCC ('m', 'i'): return MCC ('p', 'l');
@@ -5767,6 +5777,15 @@
     case MCC ('l', 't'): return MCC ('g', 't');
     case MCC ('g', 't'): return MCC ('l', 't');
     case MCC ('l', 'e'): return MCC ('g', 'e');
+    /* issue a warning for conditions we can not swap */
+    case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
+    case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
+    case MCC ('v', 'c'):
+    case MCC ('v', 's'):
+    default :
+	   as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
+		         (char) (cc >> 8), (char) (cc));
+      break;
     }
   return cc;
 }
@@ -5781,7 +5800,11 @@
     {
     case MCC ('h', 'i'): return MCC ('l', 's');
     case MCC ('l', 's'): return MCC ('h', 'i');
+    /* <HS> is an alias for <CC> */
+    case MCC ('h', 's'): return MCC ('l', 'o');
     case MCC ('c', 'c'): return MCC ('c', 's');
+    /* <LO> is an alias for <CS> */
+    case MCC ('l', 'o'): return MCC ('h', 's');
     case MCC ('c', 's'): return MCC ('c', 'c');
     case MCC ('n', 'e'): return MCC ('e', 'q');
     case MCC ('e', 'q'): return MCC ('n', 'e');
@@ -5848,13 +5871,28 @@
 	{
 	  char *temp;
 
-	  cc = swap_mri_condition (cc);
+     /* Correct conditional handling:
+        if #1 <lt> d0 then  ;means if (1 < d0)
+           ...
+        endi
+
+        should assemble to:
+
+         cmp #1,d0        if we do *not* swap the operands
+         bgt true         we need the swapped condition!
+         ble false
+        true:
+         ...
+        false:
+     */
 	  temp = leftstart;
 	  leftstart = rightstart;
 	  rightstart = temp;
 	  temp = leftstop;
 	  leftstop = rightstop;
 	  rightstop = temp;
+	} else {
+	  cc = swap_mri_condition (cc);
 	}
     }
 
@@ -5874,7 +5912,7 @@
       *s++ = 'm';
       *s++ = 'p';
       if (qual != '\0')
-	*s++ = qual;
+	*s++ = tolower(qual);
       *s++ = ' ';
       memcpy (s, leftstart, leftstop - leftstart);
       s += leftstop - leftstart;
@@ -5892,7 +5930,7 @@
   *s++ = cc >> 8;
   *s++ = cc & 0xff;
   if (extent != '\0')
-    *s++ = extent;
+    *s++ = tolower(extent);
   *s++ = ' ';
   strcpy (s, truelab);
   mri_assemble (buf);
@@ -6027,8 +6065,17 @@
   /* A structured control directive must end with THEN with an
      optional qualifier.  */
   s = input_line_pointer;
-  while (! is_end_of_line[(unsigned char) *s]
-	 && (! flag_mri || *s != '*'))
+  /* We only accept '*' as introduction of comments if preceded by white space
+     or at first column of a line (I think this can't actually happen here?)
+     This is important when assembling:
+       if d0 <ne> 12(a0,d0*2) then
+       if d0 <ne> #CONST*20   then */
+  while ( ! (    is_end_of_line[(unsigned char) *s]
+              || (     flag_mri
+                   && *s == '*'
+                   && (    s == input_line_pointer
+                        || *(s-1) == ' '
+                        || *(s-1) == '\t'))))
     ++s;
   --s;
   while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
@@ -6133,7 +6180,7 @@
   mri_control_stack->else_seen = 1;
 
   buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
-  q[0] = qual;
+  q[0] = tolower(qual);
   q[1] = '\0';
   sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
   mri_assemble (buf);
@@ -6206,7 +6253,7 @@
     }
 
   buf = (char *) xmalloc (20 + strlen (n->bottom));
-  ex[0] = extent;
+  ex[0] = tolower(extent);
   ex[1] = '\0';
   sprintf (buf, "bra%s %s", ex, n->bottom);
   mri_assemble (buf);
@@ -6245,7 +6292,7 @@
     }
 
   buf = (char *) xmalloc (20 + strlen (n->next));
-  ex[0] = extent;
+  ex[0] = tolower(extent);
   ex[1] = '\0';
   sprintf (buf, "bra%s %s", ex, n->next);
   mri_assemble (buf);
@@ -6429,7 +6476,7 @@
   *s++ = 'v';
   *s++ = 'e';
   if (qual != '\0')
-    *s++ = qual;
+    *s++ = tolower(qual);
   *s++ = ' ';
   memcpy (s, initstart, initstop - initstart);
   s += initstop - initstart;
@@ -6447,7 +6494,7 @@
   *s++ = 'm';
   *s++ = 'p';
   if (qual != '\0')
-    *s++ = qual;
+    *s++ = tolower(qual);
   *s++ = ' ';
   memcpy (s, endstart, endstop - endstart);
   s += endstop - endstart;
@@ -6458,7 +6505,7 @@
   mri_assemble (buf);
 
   /* bcc bottom */
-  ex[0] = extent;
+  ex[0] = tolower(extent);
   ex[1] = '\0';
   if (up)
     sprintf (buf, "blt%s %s", ex, n->bottom);
@@ -6474,7 +6521,7 @@
     strcpy (s, "sub");
   s += 3;
   if (qual != '\0')
-    *s++ = qual;
+    *s++ = tolower(qual);
   *s++ = ' ';
   memcpy (s, bystart, bystop - bystart);
   s += bystop - bystart;
@@ -6597,8 +6644,17 @@
   struct mri_control_info *n;
 
   s = input_line_pointer;
-  while (! is_end_of_line[(unsigned char) *s]
-	 && (! flag_mri || *s != '*'))
+  /* We only accept '*' as introduction of comments if preceded by white space
+     or at first column of a line (I think this can't actually happen here?)
+     This is important when assembling:
+       while d0 <ne> 12(a0,d0*2) do
+       while d0 <ne> #CONST*20   do */
+  while ( ! (    is_end_of_line[(unsigned char) *s]
+              || (     flag_mri
+                   && *s == '*'
+                   && (    s == input_line_pointer
+                        || *(s-1) == ' '
+                        || *(s-1) == '\t'))))
     s++;
   --s;
   while (*s == ' ' || *s == '\t')
diff -ru src.orig/gas/macro.c src/gas/macro.c
--- src.orig/gas/macro.c	Fri Mar 09 01:24:22 2001
+++ src/gas/macro.c	Wed Jun 06 23:24:46 2001
@@ -935,21 +935,29 @@
       /* The macro may be called with an optional qualifier, which may
          be referred to in the macro body as \0.  */
       if (idx < in->len && in->ptr[idx] == '.')
-	{
-	  formal_entry *n;
+        {
+          /* The Microtec assembler ignores this if followed by a white space.
+    		   (Macro invocation with empty extension) */
+          idx++;
+          if (    idx < in->len
+	            && in->ptr[idx] != ' '
+               && in->ptr[idx] != '\t')
+            {
+              formal_entry *n;
 
-	  n = (formal_entry *) xmalloc (sizeof (formal_entry));
-	  sb_new (&n->name);
-	  sb_new (&n->def);
-	  sb_new (&n->actual);
-	  n->index = QUAL_INDEX;
+              n = (formal_entry *) xmalloc (sizeof (formal_entry));
+              sb_new (&n->name);
+              sb_new (&n->def);
+              sb_new (&n->actual);
+              n->index = QUAL_INDEX;
 
-	  n->next = m->formals;
-	  m->formals = n;
+              n->next = m->formals;
+              m->formals = n;
 
-	  idx = get_any_string (idx + 1, in, &n->actual, 1, 0);
-	}
-    }
+              idx = get_any_string (idx, in, &n->actual, 1, 0);
+            }
+        }
+  }
 
   /* Peel off the actuals and store them away in the hash tables' actuals.  */
   idx = sb_skip_white (idx, in);
diff -ru src.orig/gas/testsuite/gas/mri/for.d src/gas/testsuite/gas/mri/for.d
--- src.orig/gas/testsuite/gas/mri/for.d	Mon May 03 09:28:52 1999
+++ src/gas/testsuite/gas/mri/for.d	Wed Jun 06 23:40:08 2001
@@ -21,7 +21,7 @@
 0+01c <foo\+(0x|)1c> cmpiw #1,%d0
 0+020 <foo\+(0x|)20> bgts 0+030 <foo\+(0x|)30>
 0+022 <foo\+(0x|)22> cmpiw #100,%d1
-0+026 <foo\+(0x|)26> bgts 0+02a <foo\+(0x|)2a>
+0+026 <foo\+(0x|)26> blts 0+02a <foo\+(0x|)2a>
 0+028 <foo\+(0x|)28> bras 0+02c <foo\+(0x|)2c>
 0+02a <foo\+(0x|)2a> addw %d0,%d1
 0+02c <foo\+(0x|)2c> subqw #1,%d0
diff -ru src.orig/gas/testsuite/gas/mri/if.d src/gas/testsuite/gas/mri/if.d
--- src.orig/gas/testsuite/gas/mri/if.d	Mon May 03 09:28:52 1999
+++ src/gas/testsuite/gas/mri/if.d	Wed Jun 06 23:52:08 2001
@@ -8,18 +8,18 @@
 
 Disassembly of section .text:
 0+000 <foo> cmpw %d1,%d0
-0+002 <foo\+(0x|)2> bles 0+014 <foo\+(0x|)14>
+0+002 <foo\+(0x|)2> bges 0+014 <foo\+(0x|)14>
 0+004 <foo\+(0x|)4> cmpw %d2,%d0
-0+006 <foo\+(0x|)6> bles 0+014 <foo\+(0x|)14>
+0+006 <foo\+(0x|)6> bges 0+014 <foo\+(0x|)14>
 0+008 <foo\+(0x|)8> cmpw %d1,%d2
-0+00a <foo\+(0x|)a> bles 0+010 <foo\+(0x|)10>
+0+00a <foo\+(0x|)a> bges 0+010 <foo\+(0x|)10>
 0+00c <foo\+(0x|)c> movew %d1,%d3
 0+00e <foo\+(0x|)e> bras 0+012 <foo\+(0x|)12>
 0+010 <foo\+(0x|)10> movew %d2,%d3
 0+012 <foo\+(0x|)12> bras 0+01e <foo\+(0x|)1e>
 0+014 <foo\+(0x|)14> cmpw %d0,%d1
-0+016 <foo\+(0x|)16> bgts 0+01c <foo\+(0x|)1c>
+0+016 <foo\+(0x|)16> blts 0+01c <foo\+(0x|)1c>
 0+018 <foo\+(0x|)18> cmpw %d0,%d2
-0+01a <foo\+(0x|)1a> bles 0+01e <foo\+(0x|)1e>
+0+01a <foo\+(0x|)1a> bges 0+01e <foo\+(0x|)1e>
 0+01c <foo\+(0x|)1c> movew %d0,%d3
 0+01e <foo\+(0x|)1e> nop
diff -ru src.orig/gas/testsuite/gas/mri/repeat.d src/gas/testsuite/gas/mri/repeat.d
--- src.orig/gas/testsuite/gas/mri/repeat.d	Mon May 03 09:28:52 1999
+++ src/gas/testsuite/gas/mri/repeat.d	Wed Jun 06 23:46:43 2001
@@ -11,6 +11,6 @@
 0+002 <foo\+(0x|)2> clrw %d1
 0+004 <foo\+(0x|)4> addqw #1,%d1
 0+006 <foo\+(0x|)6> cmpiw #10,%d1
-0+00a <foo\+(0x|)a> bgts 0+004 <foo\+(0x|)4>
+0+00a <foo\+(0x|)a> blts 0+004 <foo\+(0x|)4>
 0+00c <foo\+(0x|)c> nop
 0+00e <foo\+(0x|)e> nop
diff -ru src.orig/gas/testsuite/gas/mri/while.d src/gas/testsuite/gas/mri/while.d
--- src.orig/gas/testsuite/gas/mri/while.d	Mon May 03 09:28:52 1999
+++ src/gas/testsuite/gas/mri/while.d	Wed Jun 06 23:48:01 2001
@@ -11,7 +11,7 @@
 0+002 <foo\+(0x|)2> bras 0+000 <foo>
 0+004 <foo\+(0x|)4> clrw %d1
 0+006 <foo\+(0x|)6> cmpiw #10,%d1
-0+00a <foo\+(0x|)a> blts 0+010 <foo\+(0x|)10>
+0+00a <foo\+(0x|)a> bgts 0+010 <foo\+(0x|)10>
 0+00c <foo\+(0x|)c> addqw #1,%d1
 0+00e <foo\+(0x|)e> bras 0+006 <foo\+(0x|)6>
 0+010 <foo\+(0x|)10> nop



-- 
Peter Jakubek
pjak@snafu.de


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