* config/tc-m68k.c (md_apply_fix3): Change val back to a signed type.
[deliverable/binutils-gdb.git] / gas / config / tc-m68k.c
index 32e18f7427d1ffcf649ba61a677d357148960a44..20c9c107b58ec6d6ede3d093a21f4832e98d43c6 100644 (file)
@@ -20,8 +20,8 @@
    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
-#include <ctype.h>
 #include "as.h"
+#include "safe-ctype.h"
 #include "obstack.h"
 #include "subsegs.h"
 #include "dwarf2dbg.h"
@@ -257,9 +257,9 @@ insop (w, opcode)
      const struct m68k_incant *opcode;
 {
   int z;
-  for(z=the_ins.numo;z>opcode->m_codenum;--z)
+  for (z = the_ins.numo; z > opcode->m_codenum; --z)
     the_ins.opcode[z]=the_ins.opcode[z-1];
-  for(z=0;z<the_ins.nrel;z++)
+  for (z = 0;z < the_ins.nrel; z++)
     the_ins.reloc[z].n+=2;
   for (z = 0; z < the_ins.nfrag; z++)
     the_ins.fragb[z].fragoff++;
@@ -348,7 +348,6 @@ static void s_mri_repeat PARAMS ((int));
 static void s_mri_until PARAMS ((int));
 static void s_mri_while PARAMS ((int));
 static void s_mri_endw PARAMS ((int));
-static void md_apply_fix_2 PARAMS ((fixS *, offsetT));
 static void md_convert_frag_1 PARAMS ((fragS *));
 
 static int current_architecture;
@@ -432,10 +431,10 @@ static const int n_archs = sizeof (archs) / sizeof (archs[0]);
    BYTE and SHORT forms, punting if that isn't enough.  This gives us four
    different relaxation modes for branches:  */
 
-#define BRANCHBWL      1       /* branch byte, word, or long */
-#define BRABSJUNC      2       /* absolute jump for LONG, unconditional */
-#define BRABSJCOND     3       /* absolute jump for LONG, conditional */
-#define BRANCHBW       4       /* branch byte or word */
+#define BRANCHBWL      0       /* branch byte, word, or long */
+#define BRABSJUNC      1       /* absolute jump for LONG, unconditional */
+#define BRABSJCOND     2       /* absolute jump for LONG, conditional */
+#define BRANCHBW       3       /* branch byte or word */
 
 /* We also relax coprocessor branches and DBcc's.  All CPUs that support
    coprocessor branches support them in word and long forms, so we have only
@@ -445,9 +444,9 @@ static const int n_archs = sizeof (archs) / sizeof (archs[0]);
    This gives us two relaxation modes.  If long branches are not available and
    absolute jumps are not acceptable, we don't relax DBcc's.  */
 
-#define FBRANCH                5       /* coprocessor branch */
-#define DBCCLBR                6       /* DBcc relaxable with a long branch */
-#define DBCCABSJ       7       /* DBcc relaxable with an absolute jump */
+#define FBRANCH                4       /* coprocessor branch */
+#define DBCCLBR                5       /* DBcc relaxable with a long branch */
+#define DBCCABSJ       6       /* DBcc relaxable with an absolute jump */
 
 /* That's all for instruction relaxation.  However, we also relax PC-relative
    operands.  Specifically, we have three operand relaxation modes.  On the
@@ -460,9 +459,9 @@ static const int n_archs = sizeof (archs) / sizeof (archs[0]);
    form of the PC+displacement+index operand.  Finally, some absolute operands
    can be relaxed down to 16-bit PC-relative.  */
 
-#define PCREL1632      8       /* 16-bit or 32-bit PC-relative */
-#define PCINDEX                9       /* PC+displacement+index */
-#define ABSTOPCREL     10      /* absolute relax down to 16-bit PC-relative */
+#define PCREL1632      7       /* 16-bit or 32-bit PC-relative */
+#define PCINDEX                8       /* PC+displacement+index */
+#define ABSTOPCREL           /* absolute relax down to 16-bit PC-relative */
 
 /* Note that calls to frag_var need to specify the maximum expansion
    needed; this is currently 10 bytes for DBCC.  */
@@ -475,60 +474,55 @@ static const int n_archs = sizeof (archs) / sizeof (archs[0]);
    */
 relax_typeS md_relax_table[] =
 {
-  {1, 1, 0, 0},                        /* First entries aren't used */
-  {1, 1, 0, 0},                        /* For no good reason except */
-  {1, 1, 0, 0},                        /* that the VAX doesn't either */
-  {1, 1, 0, 0},
-
-  {(127), (-128), 0, TAB (BRANCHBWL, SHORT)},
-  {(32767), (-32768), 2, TAB (BRANCHBWL, LONG)},
-  {0, 0, 4, 0},
-  {1, 1, 0, 0},
-
-  {(127), (-128), 0, TAB (BRABSJUNC, SHORT)},
-  {(32767), (-32768), 2, TAB (BRABSJUNC, LONG)},
-  {0, 0, 4, 0},
-  {1, 1, 0, 0},
-
-  {(127), (-128), 0, TAB (BRABSJCOND, SHORT)},
-  {(32767), (-32768), 2, TAB (BRABSJCOND, LONG)},
-  {0, 0, 6, 0},
-  {1, 1, 0, 0},
-
-  {(127), (-128), 0, TAB (BRANCHBW, SHORT)},
-  {0, 0, 2, 0},
-  {1, 1, 0, 0},
-  {1, 1, 0, 0},
-
-  {1, 1, 0, 0},                        /* FBRANCH doesn't come BYTE */
-  {(32767), (-32768), 2, TAB (FBRANCH, LONG)},
-  {0, 0, 4, 0},
-  {1, 1, 0, 0},
-
-  {1, 1, 0, 0},                        /* DBCC doesn't come BYTE */
-  {(32767), (-32768), 2, TAB (DBCCLBR, LONG)},
-  {0, 0, 10, 0},
-  {1, 1, 0, 0},
-
-  {1, 1, 0, 0},                        /* DBCC doesn't come BYTE */
-  {(32767), (-32768), 2, TAB (DBCCABSJ, LONG)},
-  {0, 0, 10, 0},
-  {1, 1, 0, 0},
-
-  {1, 1, 0, 0},                        /* PCREL1632 doesn't come BYTE */
-  {32767, -32768, 2, TAB (PCREL1632, LONG)},
-  {0, 0, 6, 0},
-  {1, 1, 0, 0},
-
-  {125, -130, 0, TAB (PCINDEX, SHORT)},
-  {32765, -32770, 2, TAB (PCINDEX, LONG)},
-  {0, 0, 4, 0},
-  {1, 1, 0, 0},
-
-  {1, 1, 0, 0},                        /* ABSTOPCREL doesn't come BYTE */
-  {(32767), (-32768), 2, TAB (ABSTOPCREL, LONG)},
-  {0, 0, 4, 0},
-  {1, 1, 0, 0},
+  {   127,   -128,  0, TAB (BRANCHBWL, SHORT) },
+  { 32767, -32768,  2, TAB (BRANCHBWL, LONG) },
+  {     0,     0,  4, 0 },
+  {     1,     1,  0, 0 },
+
+  {   127,   -128,  0, TAB (BRABSJUNC, SHORT) },
+  { 32767, -32768,  2, TAB (BRABSJUNC, LONG) },
+  {    0,      0,  4, 0 },
+  {    1,      1,  0, 0 },
+
+  {   127,   -128,  0, TAB (BRABSJCOND, SHORT) },
+  { 32767, -32768,  2, TAB (BRABSJCOND, LONG) },
+  {    0,      0,  6, 0 },
+  {    1,      1,  0, 0 },
+
+  {   127,   -128,  0, TAB (BRANCHBW, SHORT) },
+  {    0,      0,  2, 0 },
+  {    1,      1,  0, 0 },
+  {    1,      1,  0, 0 },
+
+  {    1,      1,  0, 0 },             /* FBRANCH doesn't come BYTE */
+  { 32767, -32768,  2, TAB (FBRANCH, LONG) },
+  {    0,      0,  4, 0 },
+  {    1,      1,  0, 0 },
+
+  {    1,      1,  0, 0 },             /* DBCC doesn't come BYTE */
+  { 32767, -32768,  2, TAB (DBCCLBR, LONG) },
+  {    0,      0, 10, 0 },
+  {    1,      1,  0, 0 },
+
+  {    1,      1,  0, 0 },             /* DBCC doesn't come BYTE */
+  { 32767, -32768,  2, TAB (DBCCABSJ, LONG) },
+  {    0,      0, 10, 0 },
+  {    1,      1,  0, 0 },
+
+  {    1,      1,  0, 0 },             /* PCREL1632 doesn't come BYTE */
+  { 32767, -32768,  2, TAB (PCREL1632, LONG) },
+  {    0,      0,  6, 0 },
+  {    1,      1,  0, 0 },
+
+  {   125,   -130,  0, TAB (PCINDEX, SHORT) },
+  { 32765, -32770,  2, TAB (PCINDEX, LONG) },
+  {    0,      0,  4, 0 },
+  {    1,      1,  0, 0 },
+
+  {    1,      1,  0, 0 },             /* ABSTOPCREL doesn't come BYTE */
+  { 32767, -32768,  2, TAB (ABSTOPCREL, LONG) },
+  {    0,      0,  4, 0 },
+  {    1,      1,  0, 0 },
 };
 
 /* These are the machine dependent pseudo-ops.  These are included so
@@ -653,8 +647,6 @@ CONST pseudo_typeS mote_pseudo_table[] =
 
 extern char *input_line_pointer;
 
-static char mklower_table[256];
-#define mklower(c) (mklower_table[(unsigned char) (c)])
 static char notend_table[256];
 static char alt_notend_table[256];
 #define notend(s)                                              \
@@ -2580,14 +2572,14 @@ m68k_ip (instring)
              if (adds (&opP->disp) == 0)
                {
                  if (the_ins.opcode[0] == 0x6000)      /* jbra */
-                   the_ins.opcode[0] = 0x4EF1;
+                   the_ins.opcode[0] = 0x4EF9;
                  else if (the_ins.opcode[0] == 0x6100) /* jbsr */
-                   the_ins.opcode[0] = 0x4EB1;
+                   the_ins.opcode[0] = 0x4EB9;
                  else                                  /* jCC */
                    {
                      the_ins.opcode[0] ^= 0x0100;
                      the_ins.opcode[0] |= 0x0006;
-                     addword (0x4EF1);
+                     addword (0x4EF9);
                    }
                  add_fix ('l', &opP->disp, 0, 0);
                  addword (0);
@@ -3316,7 +3308,7 @@ insert_reg (regname, regnum)
                                   &zero_address_frag));
 
   for (i = 0; regname[i]; i++)
-    buf[i] = islower (regname[i]) ? toupper (regname[i]) : regname[i];
+    buf[i] = TOUPPER (regname[i]);
   buf[i] = '\0';
 
   symbol_table_insert (symbol_new (buf, reg_section, regnum,
@@ -3786,11 +3778,10 @@ md_begin ()
      my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
      names.  */
 
-  register const struct m68k_opcode *ins;
-  register struct m68k_incant *hack, *slak;
-  register const char *retval = 0;     /* empty string, or error msg text */
-  register int i;
-  register char c;
+  const struct m68k_opcode *ins;
+  struct m68k_incant *hack, *slak;
+  const char *retval = 0;      /* empty string, or error msg text */
+  int i;
 
   if (flag_mri)
     {
@@ -3885,9 +3876,6 @@ md_begin ()
        }
     }
 
-  for (i = 0; i < (int) sizeof (mklower_table); i++)
-    mklower_table[i] = (isupper (c = (char) i)) ? tolower (c) : c;
-
   for (i = 0; i < (int) sizeof (notend_table); i++)
     {
       notend_table[i] = 0;
@@ -4233,11 +4221,13 @@ md_number_to_chars (buf, val, n)
   number_to_chars_bigendian (buf, val, n);
 }
 
-static void
-md_apply_fix_2 (fixP, val)
+void
+md_apply_fix3 (fixP, valP, seg)
      fixS *fixP;
-     offsetT val;
+     valueT *valP;
+     segT seg ATTRIBUTE_UNUSED;
 {
+  offsetT val = *valP;
   addressT upper_limit;
   offsetT lower_limit;
 
@@ -4249,6 +4239,9 @@ md_apply_fix_2 (fixP, val)
 
   val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
 
+  if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
+    fixP->fx_done = 1;
+
 #ifdef OBJ_ELF
   if (fixP->fx_addsy)
     {
@@ -4271,8 +4264,8 @@ md_apply_fix_2 (fixP, val)
 
   switch (fixP->fx_size)
     {
-      /* The cast to offsetT below are necessary to make code correct for
-        machines where ints are smaller than offsetT */
+      /* The cast to offsetT below are necessary to make code
+        correct for machines where ints are smaller than offsetT.  */
     case 1:
       *buf++ = val;
       upper_limit = 0x7f;
@@ -4332,24 +4325,6 @@ md_apply_fix_2 (fixP, val)
     as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
 }
 
-#ifdef BFD_ASSEMBLER
-int
-md_apply_fix (fixP, valp)
-     fixS *fixP;
-     valueT *valp;
-{
-  md_apply_fix_2 (fixP, (addressT) *valp);
-  return 1;
-}
-#else
-void md_apply_fix (fixP, val)
-     fixS *fixP;
-     long val;
-{
-  md_apply_fix_2 (fixP, (addressT) val);
-}
-#endif
-
 /* *fragP has been relaxed to its final size, and now needs to have
    the bytes inside it modified to conform to the new size  There is UGLY
    MAGIC here. ..
@@ -4375,10 +4350,6 @@ md_convert_frag_1 (fragP)
   disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
   disp = (disp + fragP->fr_offset) - object_address;
 
-#ifdef BFD_ASSEMBLER
-  disp += symbol_get_frag (fragP->fr_symbol)->fr_address;
-#endif
-
   switch (fragP->fr_subtype)
     {
     case TAB (BRANCHBWL, BYTE):
@@ -4594,10 +4565,6 @@ md_estimate_size_before_relax (fragP, segment)
      register fragS *fragP;
      segT segment;
 {
-  int old_fix;
-
-  old_fix = fragP->fr_fix;
-
   /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT.  */
   switch (fragP->fr_subtype)
     {
@@ -4694,44 +4661,31 @@ md_estimate_size_before_relax (fragP, segment)
     case TAB (BRABSJCOND, BYTE):
     case TAB (BRANCHBW, BYTE):
       /* We can't do a short jump to the next instruction, so in that
-        case we force word mode.  At this point S_GET_VALUE should
-        return the offset of the symbol within its frag.  If the
-        symbol is at the start of a frag, and it is the next frag
-        with any data in it (usually this is just the next frag, but
-        assembler listings may introduce empty frags), we must use
-        word mode.  */
-      if (fragP->fr_symbol && S_GET_VALUE (fragP->fr_symbol) == 0)
+        case we force word mode.  If the symbol is at the start of a
+        frag, and it is the next frag with any data in it (usually
+        this is just the next frag, but assembler listings may
+        introduce empty frags), we must use word mode.  */
+      if (fragP->fr_symbol)
        {
-         fragS *stop;
-         fragS *l;
+         fragS *sym_frag;
 
-         stop = symbol_get_frag (fragP->fr_symbol);
-
-         for (l = fragP->fr_next; l != stop; l = l->fr_next)
+         sym_frag = symbol_get_frag (fragP->fr_symbol);
+         if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
            {
-             /* Catch empty alignment frags whoes fr_offset field
-                is an alignment requirement of 2 bytes.  The check
-                below will misinterpret this as evidence that real
-                code exists between the symbol and the instruction
-                and so will not convert the short jump into a word
-                jump.  */
-             if (l->fr_fix == 0
-                 && l->fr_var == 1
-                 && (l->fr_type == rs_align || l->fr_type == rs_align_code))
-               continue;
-    
-             if (l->fr_fix + l->fr_var != 0)
-               break;
+             fragS *l;
+
+             for (l = fragP->fr_next; l != sym_frag; l = l->fr_next)
+               if (l->fr_fix != 0)
+                 break;
+             if (l == sym_frag)
+               fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
            }
-         if (l == stop)
-           fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
        }
       break;
     default:
       break;
     }
-  fragP->fr_var = md_relax_table[fragP->fr_subtype].rlx_length;
-  return fragP->fr_var + fragP->fr_fix - old_fix;
+  return md_relax_table[fragP->fr_subtype].rlx_length;
 }
 
 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
@@ -5396,7 +5350,7 @@ s_reg (ignore)
   SKIP_WHITESPACE ();
 
   s = input_line_pointer;
-  while (isalnum ((unsigned char) *input_line_pointer)
+  while (ISALNUM (*input_line_pointer)
 #ifdef REGISTER_PREFIX
         || *input_line_pointer == REGISTER_PREFIX
 #endif
@@ -5608,10 +5562,7 @@ mri_assemble (str)
 
   /* md_assemble expects the opcode to be in lower case.  */
   for (s = str; *s != ' ' && *s != '\0'; s++)
-    {
-      if (isupper ((unsigned char) *s))
-       *s = tolower ((unsigned char) *s);
-    }
+    *s = TOLOWER (*s);
 
   md_assemble (str);
 }
@@ -5693,10 +5644,8 @@ parse_mri_condition (pcc)
   ++input_line_pointer;
   SKIP_WHITESPACE ();
 
-  if (isupper (c1))
-    c1 = tolower (c1);
-  if (isupper (c2))
-    c2 = tolower (c2);
+  c1 = TOLOWER (c1);
+  c2 = TOLOWER (c2);
 
   *pcc = (c1 << 8) | c2;
 
@@ -5938,7 +5887,7 @@ build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
       *s++ = 'm';
       *s++ = 'p';
       if (qual != '\0')
-       *s++ = tolower(qual);
+       *s++ = TOLOWER (qual);
       *s++ = ' ';
       memcpy (s, leftstart, leftstop - leftstart);
       s += leftstop - leftstart;
@@ -5956,7 +5905,7 @@ build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
   *s++ = cc >> 8;
   *s++ = cc & 0xff;
   if (extent != '\0')
-    *s++ = tolower(extent);
+    *s++ = TOLOWER (extent);
   *s++ = ' ';
   strcpy (s, truelab);
   mri_assemble (buf);
@@ -6206,7 +6155,7 @@ s_mri_else (qual)
   mri_control_stack->else_seen = 1;
 
   buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
-  q[0] = tolower(qual);
+  q[0] = TOLOWER (qual);
   q[1] = '\0';
   sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
   mri_assemble (buf);
@@ -6279,7 +6228,7 @@ s_mri_break (extent)
     }
 
   buf = (char *) xmalloc (20 + strlen (n->bottom));
-  ex[0] = tolower(extent);
+  ex[0] = TOLOWER (extent);
   ex[1] = '\0';
   sprintf (buf, "bra%s %s", ex, n->bottom);
   mri_assemble (buf);
@@ -6318,7 +6267,7 @@ s_mri_next (extent)
     }
 
   buf = (char *) xmalloc (20 + strlen (n->next));
-  ex[0] = tolower(extent);
+  ex[0] = TOLOWER (extent);
   ex[1] = '\0';
   sprintf (buf, "bra%s %s", ex, n->next);
   mri_assemble (buf);
@@ -6502,7 +6451,7 @@ s_mri_for (qual)
   *s++ = 'v';
   *s++ = 'e';
   if (qual != '\0')
-    *s++ = tolower(qual);
+    *s++ = TOLOWER (qual);
   *s++ = ' ';
   memcpy (s, initstart, initstop - initstart);
   s += initstop - initstart;
@@ -6520,7 +6469,7 @@ s_mri_for (qual)
   *s++ = 'm';
   *s++ = 'p';
   if (qual != '\0')
-    *s++ = tolower(qual);
+    *s++ = TOLOWER (qual);
   *s++ = ' ';
   memcpy (s, endstart, endstop - endstart);
   s += endstop - endstart;
@@ -6531,7 +6480,7 @@ s_mri_for (qual)
   mri_assemble (buf);
 
   /* bcc bottom */
-  ex[0] = tolower(extent);
+  ex[0] = TOLOWER (extent);
   ex[1] = '\0';
   if (up)
     sprintf (buf, "blt%s %s", ex, n->bottom);
@@ -6547,7 +6496,7 @@ s_mri_for (qual)
     strcpy (s, "sub");
   s += 3;
   if (qual != '\0')
-    *s++ = tolower(qual);
+    *s++ = TOLOWER (qual);
   *s++ = ' ';
   memcpy (s, bystart, bystop - bystart);
   s += bystop - bystart;
This page took 0.034055 seconds and 4 git commands to generate.