2004-01-01 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gas / config / tc-h8300.c
index 794a509792a689f1fd39b05fb1b04ab3927ce868..8ff86ea7a041302f4bc623b7d6bb9d915def4d43 100644 (file)
@@ -43,24 +43,23 @@ const char comment_chars[] = ";";
 const char line_comment_chars[] = "#";
 const char line_separator_chars[] = "";
 
-void cons        PARAMS ((int));
-void sbranch     PARAMS ((int));
-void h8300hmode  PARAMS ((int));
-void h8300smode  PARAMS ((int));
-void h8300hnmode PARAMS ((int));
-void h8300snmode PARAMS ((int));
-void h8300sxmode PARAMS ((int));
-static void pint PARAMS ((int));
+static void sbranch (int);
+static void h8300hmode (int);
+static void h8300smode (int);
+static void h8300hnmode (int);
+static void h8300snmode (int);
+static void h8300sxmode (int);
+static void h8300sxnmode (int);
+static void pint (int);
 
 int Hmode;
 int Smode;
 int Nmode;
 int SXmode;
 
-#define PSIZE (Hmode ? L_32 : L_16)
-#define DSYMMODE (Hmode ? L_24 : L_16)
+#define PSIZE (Hmode && !Nmode ? L_32 : L_16)
 
-int bsize = L_8;               /* Default branch displacement.  */
+static int bsize = L_8;                /* Default branch displacement.  */
 
 struct h8_instruction
 {
@@ -71,11 +70,10 @@ struct h8_instruction
   const struct h8_opcode *opcode;
 };
 
-struct h8_instruction *h8_instructions;
+static struct h8_instruction *h8_instructions;
 
-void
-h8300hmode (arg)
-     int arg ATTRIBUTE_UNUSED;
+static void
+h8300hmode (int arg ATTRIBUTE_UNUSED)
 {
   Hmode = 1;
   Smode = 0;
@@ -85,9 +83,8 @@ h8300hmode (arg)
 #endif
 }
 
-void
-h8300smode (arg)
-     int arg ATTRIBUTE_UNUSED;
+static void
+h8300smode (int arg ATTRIBUTE_UNUSED)
 {
   Smode = 1;
   Hmode = 1;
@@ -97,9 +94,8 @@ h8300smode (arg)
 #endif
 }
 
-void
-h8300hnmode (arg)
-     int arg ATTRIBUTE_UNUSED;
+static void
+h8300hnmode (int arg ATTRIBUTE_UNUSED)
 {
   Hmode = 1;
   Smode = 0;
@@ -110,9 +106,8 @@ h8300hnmode (arg)
 #endif
 }
 
-void
-h8300snmode (arg)
-     int arg ATTRIBUTE_UNUSED;
+static void
+h8300snmode (int arg ATTRIBUTE_UNUSED)
 {
   Smode = 1;
   Hmode = 1;
@@ -123,9 +118,8 @@ h8300snmode (arg)
 #endif
 }
 
-void
-h8300sxmode (arg)
-     int arg ATTRIBUTE_UNUSED;
+static void
+h8300sxmode (int arg ATTRIBUTE_UNUSED)
 {
   Smode = 1;
   Hmode = 1;
@@ -136,16 +130,27 @@ h8300sxmode (arg)
 #endif
 }
 
-void
-sbranch (size)
-     int size;
+static void
+h8300sxnmode (int arg ATTRIBUTE_UNUSED)
+{
+  Smode = 1;
+  Hmode = 1;
+  SXmode = 1;
+  Nmode = 1;
+#ifdef BFD_ASSEMBLER
+  if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, bfd_mach_h8300sxn))
+    as_warn (_("could not set architecture and machine"));
+#endif
+}
+
+static void
+sbranch (int size)
 {
   bsize = size;
 }
 
 static void
-pint (arg)
-     int arg ATTRIBUTE_UNUSED;
+pint (int arg ATTRIBUTE_UNUSED)
 {
   cons (Hmode ? 4 : 2);
 }
@@ -163,6 +168,7 @@ const pseudo_typeS md_pseudo_table[] =
   {"h8300s",  h8300smode,  0},
   {"h8300sn", h8300snmode, 0},
   {"h8300sx", h8300sxmode, 0},
+  {"h8300sxn", h8300sxnmode, 0},
   {"sbranch", sbranch, L_8},
   {"lbranch", sbranch, L_16},
 
@@ -194,7 +200,7 @@ static struct hash_control *opcode_hash_control;    /* Opcode mnemonics.  */
    needs.  */
 
 void
-md_begin ()
+md_begin (void)
 {
   unsigned int nopcodes;
   struct h8_opcode *p, *p1;
@@ -304,13 +310,6 @@ md_begin ()
   linkrelax = 1;
 }
 
-struct h8_exp
-{
-  char *e_beg;
-  char *e_end;
-  expressionS e_exp;
-};
-
 struct h8_op
 {
   op_type mode;
@@ -318,21 +317,20 @@ struct h8_op
   expressionS exp;
 };
 
-static void clever_message PARAMS ((const struct h8_instruction *, struct h8_op *));
-static void fix_operand_size PARAMS ((struct h8_op *, int));
-static void build_bytes    PARAMS ((const struct h8_instruction *, struct h8_op *));
-static void do_a_fix_imm   PARAMS ((int, int, struct h8_op *, int));
-static void check_operand  PARAMS ((struct h8_op *, unsigned int, char *));
-static const struct h8_instruction * get_specific PARAMS ((const struct h8_instruction *, struct h8_op *, int));
-static char * get_operands PARAMS ((unsigned, char *, struct h8_op *));
-static void   get_operand  PARAMS ((char **, struct h8_op *, int));
-static char * skip_colonthing PARAMS ((char *, expressionS *, int *));
-static char * parse_exp PARAMS ((char *, expressionS *));
-static int    parse_reg PARAMS ((char *, op_type *, unsigned *, int));
-char * colonmod24 PARAMS ((struct h8_op *, char *));
-
-static int constant_fits_width_p PARAMS ((struct h8_op *, unsigned int));
-static int constant_fits_size_p PARAMS ((struct h8_op *, int, int));
+static void clever_message (const struct h8_instruction *, struct h8_op *);
+static void fix_operand_size (struct h8_op *, int);
+static void build_bytes (const struct h8_instruction *, struct h8_op *);
+static void do_a_fix_imm (int, int, struct h8_op *, int);
+static void check_operand (struct h8_op *, unsigned int, char *);
+static const struct h8_instruction * get_specific (const struct h8_instruction *, struct h8_op *, int) ;
+static char *get_operands (unsigned, char *, struct h8_op *);
+static void get_operand (char **, struct h8_op *, int);
+static int parse_reg (char *, op_type *, unsigned *, int);
+static char *skip_colonthing (char *, int *);
+static char *parse_exp (char *, struct h8_op *);
+
+static int constant_fits_width_p (struct h8_op *, unsigned int);
+static int constant_fits_size_p (struct h8_op *, int, int);
 
 /*
   parse operands
@@ -348,11 +346,7 @@ static int constant_fits_size_p PARAMS ((struct h8_op *, int, int));
 /* Try to parse a reg name.  Return the number of chars consumed.  */
 
 static int
-parse_reg (src, mode, reg, direction)
-     char *src;
-     op_type *mode;
-     unsigned int *reg;
-     int direction;
+parse_reg (char *src, op_type *mode, unsigned int *reg, int direction)
 {
   char *end;
   int len;
@@ -459,56 +453,61 @@ parse_reg (src, mode, reg, direction)
   return 0;
 }
 
+
+/* Parse an immediate or address-related constant and store it in OP.
+   If the user also specifies the operand's size, store that size
+   in OP->MODE, otherwise leave it for later code to decide.  */
+
 static char *
-parse_exp (s, op)
-     char *s;
-     expressionS *op;
+parse_exp (char *src, struct h8_op *op)
 {
-  char *save = input_line_pointer;
-  char *new;
+  char *save;
 
-  input_line_pointer = s;
-  expression (op);
-  if (op->X_op == O_absent)
+  save = input_line_pointer;
+  input_line_pointer = src;
+  expression (&op->exp);
+  if (op->exp.X_op == O_absent)
     as_bad (_("missing operand"));
-  new = input_line_pointer;
+  src = input_line_pointer;
   input_line_pointer = save;
-  return new;
+
+  return skip_colonthing (src, &op->mode);
 }
 
+
+/* If SRC starts with an explicit operand size, skip it and store the size
+   in *MODE.  Leave *MODE unchanged otherwise.  */
+
 static char *
-skip_colonthing (ptr, exp, mode)
-     char *ptr;
-     expressionS *exp ATTRIBUTE_UNUSED;
-     int *mode;
+skip_colonthing (char *src, int *mode)
 {
-  if (*ptr == ':')
+  if (*src == ':')
     {
-      ptr++;
+      src++;
       *mode &= ~SIZE;
-      if (ptr[0] == '8' && ! ISDIGIT (ptr[1]))
+      if (src[0] == '8' && !ISDIGIT (src[1]))
        *mode |= L_8;
-      else if (ptr[0] == '2' && ! ISDIGIT (ptr[1]))
+      else if (src[0] == '2' && !ISDIGIT (src[1]))
        *mode |= L_2;
-      else if (ptr[0] == '3' && ! ISDIGIT (ptr[1]))
+      else if (src[0] == '3' && !ISDIGIT (src[1]))
        *mode |= L_3;
-      else if (ptr[0] == '4' && ! ISDIGIT (ptr[1]))
+      else if (src[0] == '4' && !ISDIGIT (src[1]))
        *mode |= L_4;
-      else if (ptr[0] == '5' && ! ISDIGIT (ptr[1]))
+      else if (src[0] == '5' && !ISDIGIT (src[1]))
        *mode |= L_5;
-      else if (ptr[0] == '2' && ptr[1] == '4')
+      else if (src[0] == '2' && src[1] == '4' && !ISDIGIT (src[2]))
        *mode |= L_24;
-      else if (ptr[0] == '3' && ptr[1] == '2')
+      else if (src[0] == '3' && src[1] == '2' && !ISDIGIT (src[2]))
        *mode |= L_32;
-      else if (ptr[0] == '1' && ptr[1] == '6')
+      else if (src[0] == '1' && src[1] == '6' && !ISDIGIT (src[2]))
        *mode |= L_16;
       else
        as_bad (_("invalid operand size requested"));
 
-      while (ISDIGIT (*ptr))
-       ptr++;
+      while (ISDIGIT (*src))
+       src++;
     }
-  return ptr;
+  return src;
 }
 
 /* The many forms of operand:
@@ -526,48 +525,15 @@ skip_colonthing (ptr, exp, mode)
    @(exp:[8], pc)      pc rel
    @@aa[:8]            memory indirect.  */
 
-char *
-colonmod24 (op, src)
-     struct h8_op *op;
-     char *src;
-{
-  int mode = 0;
-  src = skip_colonthing (src, &op->exp, &mode);
-
-  if (!mode)
-    {
-      /* If the operand is a 16-bit constant integer, leave fix_operand_size
-        to calculate its size.  Otherwise choose a default here.  */
-      if (op->exp.X_add_number < -32768
-         || op->exp.X_add_number > 32767)
-       {
-         if (Hmode)
-           mode = L_24;
-         else
-           mode = L_16;
-       }
-      else if (op->exp.X_add_symbol
-              || op->exp.X_op_symbol)
-       mode = DSYMMODE;
-    }
-
-  op->mode |= mode;
-  return src;
-}
-
 static int
-constant_fits_width_p (operand, width)
-     struct h8_op *operand;
-     unsigned int width;
+constant_fits_width_p (struct h8_op *operand, unsigned int width)
 {
   return ((operand->exp.X_add_number & ~width) == 0
          || (operand->exp.X_add_number | width) == (unsigned)(~0));
 }
 
 static int
-constant_fits_size_p (operand, size, no_symbols)
-     struct h8_op *operand;
-     int size, no_symbols;
+constant_fits_size_p (struct h8_op *operand, int size, int no_symbols)
 {
   offsetT num = operand->exp.X_add_number;
   if (no_symbols
@@ -601,10 +567,7 @@ constant_fits_size_p (operand, size, no_symbols)
 }
 
 static void
-get_operand (ptr, op, direction)
-     char **ptr;
-     struct h8_op *op;
-     int direction;
+get_operand (char **ptr, struct h8_op *op, int direction)
 {
   char *src = *ptr;
   op_type mode;
@@ -628,15 +591,18 @@ get_operand (ptr, op, direction)
       low = src[2] - '0';
       high = src[6] - '0';
 
-      if (high == low)
-       as_bad (_("Invalid register list for ldm/stm\n"));
-
-      if (high < low)
+       /* Check register pair's validity as per tech note TN-H8*-193A/E
+         from Renesas for H8S and H8SX hardware manual.  */
+      if (   !(low == 0 && (high == 1 || high == 2 || high == 3))
+          && !(low == 1 && (high == 2 || high == 3 || high == 4) && SXmode)
+          && !(low == 2 && (high == 3 || ((high == 4 || high == 5) && SXmode)))
+          && !(low == 3 && (high == 4 || high == 5 || high == 6) && SXmode)
+          && !(low == 4 && (high == 5 || high == 6))
+          && !(low == 4 && high == 7 && SXmode)
+          && !(low == 5 && (high == 6 || high == 7) && SXmode)
+          && !(low == 6 && high == 7 && SXmode))
        as_bad (_("Invalid register list for ldm/stm\n"));
 
-      if (high - low > 3)
-       as_bad (_("Invalid register list for ldm/stm)\n"));
-
       /* Even sicker.  We encode two registers into op->reg.  One
         for the low register to save, the other for the high
         register to save;  we also set the high bit in op->reg
@@ -692,16 +658,10 @@ get_operand (ptr, op, direction)
       src++;
       if (*src == '@')
        {
-         src++;
-         src = parse_exp (src, &op->exp);
-
-         src = skip_colonthing (src, &op->exp, &op->mode);
-
-         *ptr = src;
-
+         *ptr = parse_exp (src + 1, op);
          if (op->exp.X_add_number >= 0x100)
            {
-             int divisor;
+             int divisor = 1;
 
              op->mode = VECIND;
              /* FIXME : 2?  or 4?  */
@@ -716,32 +676,28 @@ get_operand (ptr, op, direction)
            }
          else
            op->mode = MEMIND;
-
          return;
        }
 
       if (*src == '-' || *src == '+')
        {
-         char c = *src;
-         src++;
-         len = parse_reg (src, &mode, &num, direction);
+         len = parse_reg (src + 1, &mode, &num, direction);
          if (len == 0)
            {
              /* Oops, not a reg after all, must be ordinary exp.  */
-             src--;
-             /* Must be a symbol.  */
-             op->mode = ABS | PSIZE | direction;
-             *ptr = skip_colonthing (parse_exp (src, &op->exp),
-                                     &op->exp, &op->mode);
-
+             op->mode = ABS | direction;
+             *ptr = parse_exp (src, op);
              return;
            }
 
-         if ((mode & SIZE) != PSIZE)
+         if (((mode & SIZE) != PSIZE)
+             /* For Normal mode accept 16 bit and 32 bit pointer registers.  */
+             && (!Nmode || ((mode & SIZE) != L_32)))
            as_bad (_("Wrong size pointer register for architecture."));
-         op->mode = c == '-' ? RDPREDEC : RDPREINC;
+
+         op->mode = src[0] == '-' ? RDPREDEC : RDPREINC;
          op->reg = num;
-         *ptr = src + len;
+         *ptr = src + 1 + len;
          return;
        }
       if (*src == '(')
@@ -786,15 +742,11 @@ get_operand (ptr, op, direction)
 
          /* Start off assuming a 16 bit offset.  */
 
-         src = parse_exp (src, &op->exp);
-
-         src = colonmod24 (op, src);
-
+         src = parse_exp (src, op);
          if (*src == ')')
            {
-             src++;
              op->mode |= ABS | direction;
-             *ptr = src;
+             *ptr = src + 1;
              return;
            }
 
@@ -802,7 +754,6 @@ get_operand (ptr, op, direction)
            {
              as_bad (_("expected @(exp, reg16)"));
              return;
-
            }
          src++;
 
@@ -834,7 +785,7 @@ get_operand (ptr, op, direction)
            }
          else
            op->mode |= DISP | direction;
-         src = skip_colonthing (src, &op->exp, &op->mode);
+         src = skip_colonthing (src, &op->mode);
 
          if (*src != ')' && '(')
            {
@@ -842,7 +793,6 @@ get_operand (ptr, op, direction)
              return;
            }
          *ptr = src + 1;
-
          return;
        }
       len = parse_reg (src, &mode, &num, direction);
@@ -852,7 +802,9 @@ get_operand (ptr, op, direction)
          src += len;
          if (*src == '+' || *src == '-')
            {
-             if ((mode & SIZE) != PSIZE)
+             if (((mode & SIZE) != PSIZE)
+                 /* For Normal mode accept 16 bit and 32 bit pointer registers.  */
+                 && (!Nmode || ((mode & SIZE) != L_32)))
                as_bad (_("Wrong size pointer register for architecture."));
              op->mode = *src == '+' ? RSPOSTINC : RSPOSTDEC;
              op->reg = num;
@@ -860,7 +812,9 @@ get_operand (ptr, op, direction)
              *ptr = src;
              return;
            }
-         if ((mode & SIZE) != PSIZE)
+         if (((mode & SIZE) != PSIZE)
+             /* For Normal mode accept 16 bit and 32 bit pointer registers.  */
+             && (!Nmode || ((mode & SIZE) != L_32)))
            as_bad (_("Wrong size pointer register for architecture."));
 
          op->mode = direction | IND | PSIZE;
@@ -874,21 +828,15 @@ get_operand (ptr, op, direction)
          /* must be a symbol */
 
          op->mode = ABS | direction;
-         src = parse_exp (src, &op->exp);
-
-         *ptr = colonmod24 (op, src);
-
+         *ptr = parse_exp (src, op);
          return;
        }
     }
 
   if (*src == '#')
     {
-      src++;
       op->mode = IMM;
-      src = parse_exp (src, &op->exp);
-      *ptr = skip_colonthing (src, &op->exp, &op->mode);
-
+      *ptr = parse_exp (src + 1, op);
       return;
     }
   else if (strncmp (src, "mach", 4) == 0 || 
@@ -903,43 +851,13 @@ get_operand (ptr, op, direction)
     }
   else
     {
-      src = parse_exp (src, &op->exp);
-      /* Trailing ':' size ? */
-      if (*src == ':')
-       {
-         if (src[1] == '1' && src[2] == '6')
-           {
-             op->mode = PCREL | L_16;
-             src += 3;
-           }
-         else if (src[1] == '8')
-           {
-             op->mode = PCREL | L_8;
-             src += 2;
-           }
-         else
-           as_bad (_("expect :8 or :16 here"));
-       }
-      else
-       {
-         int val = op->exp.X_add_number;
-
-         op->mode = PCREL;
-         if (-128 < val && val < 127)
-           op->mode |= L_8;
-         else
-           op->mode |= L_16;
-       }
-
-      *ptr = src;
+      op->mode = PCREL;
+      *ptr = parse_exp (src, op);
     }
 }
 
 static char *
-get_operands (noperands, op_end, operand)
-     unsigned int noperands;
-     char *op_end;
-     struct h8_op *operand;
+get_operands (unsigned int noperands, char *op_end, struct h8_op *operand)
 {
   char *ptr = op_end;
 
@@ -995,8 +913,7 @@ get_mova_operands (char *op_end, struct h8_op *operand)
     goto error;
   ptr += 3;
   operand[0].mode = 0;
-  ptr = parse_exp (ptr, &operand[0].exp);
-  ptr = colonmod24 (operand + 0, ptr);
+  ptr = parse_exp (ptr, &operand[0]);
 
   if (*ptr !=',')
     goto error;
@@ -1056,7 +973,6 @@ get_mova_operands (char *op_end, struct h8_op *operand)
 
  error:
   as_bad (_("expected valid addressing mode for mova: \"@(disp, ea.sz),ERn\""));
-  return;
 }
 
 static void
@@ -1076,29 +992,19 @@ get_rtsl_operands (char *ptr, struct h8_op *operand)
       as_bad (_("expected register"));
       return;
     }
-  if (type == 1)
+  ptr += len;
+  if (*ptr == '-')
     {
-      ptr += len;
-      if (*ptr++ != '-')
-       {
-         as_bad (_("expected register list"));
-         return;
-       }
-      len = parse_reg (ptr, &mode, &num2, SRC);
+      len = parse_reg (++ptr, &mode, &num2, SRC);
       if (len == 0 || (mode & MODE) != REG)
        {
          as_bad (_("expected register"));
          return;
        }
       ptr += len;
-      if (*ptr++ != ')')
-       {
-         as_bad (_("expected closing paren"));
-         return;
-       }
       /* CONST_xxx are used as placeholders in the opcode table.  */
       num = num2 - num;
-      if (num < 1 || num > 3)
+      if (num < 0 || num > 3)
        {
          as_bad (_("invalid register list"));
          return;
@@ -1106,6 +1012,11 @@ get_rtsl_operands (char *ptr, struct h8_op *operand)
     }
   else
     num2 = num, num = 0;
+  if (type == 1 && *ptr++ != ')')
+    {
+      as_bad (_("expected closing paren"));
+      return;
+    }
   operand[0].mode = RS32;
   operand[1].mode = RD32;
   operand[0].reg = num;
@@ -1117,10 +1028,8 @@ get_rtsl_operands (char *ptr, struct h8_op *operand)
    provided.  */
 
 static const struct h8_instruction *
-get_specific (instruction, operands, size)
-     const struct h8_instruction *instruction;
-     struct h8_op *operands;
-     int size;
+get_specific (const struct h8_instruction *instruction,
+             struct h8_op *operands, int size)
 {
   const struct h8_instruction *this_try = instruction;
   const struct h8_instruction *found_other = 0, *found_mismatched = 0;
@@ -1260,9 +1169,11 @@ get_specific (instruction, operands, size)
                }
              else if (op_mode == PCREL && op_mode == x_mode)
                {
-                 /* movsd only comes in PCREL16 flavour:
+                 /* movsd, bsr/bc and bsr/bs only come in PCREL16 flavour:
                     If x_size is L_8, promote it.  */
-                 if (OP_KIND (this_try->opcode->how) == O_MOVSD)
+                 if (OP_KIND (this_try->opcode->how) == O_MOVSD
+                     || OP_KIND (this_try->opcode->how) == O_BSRBC
+                     || OP_KIND (this_try->opcode->how) == O_BSRBS)
                    if (x_size == L_8)
                      x_size = L_16;
 
@@ -1292,6 +1203,7 @@ get_specific (instruction, operands, size)
 #endif
 
                  if (((x_size == L_16 && op_size == L_16U)
+                      || (x_size == L_8 && op_size == L_8U)
                       || (x_size == L_3 && op_size == L_3NZ))
                      /* We're deliberately more permissive for ABS modes.  */
                      && (op_mode == ABS
@@ -1343,10 +1255,7 @@ get_specific (instruction, operands, size)
 }
 
 static void
-check_operand (operand, width, string)
-     struct h8_op *operand;
-     unsigned int width;
-     char *string;
+check_operand (struct h8_op *operand, unsigned int width, char *string)
 {
   if (operand->exp.X_add_symbol == 0
       && operand->exp.X_op_symbol == 0)
@@ -1393,10 +1302,7 @@ check_operand (operand, width, string)
      (may relax into an 8bit absolute address).  */
 
 static void
-do_a_fix_imm (offset, nibble, operand, relaxmode)
-     int offset, nibble;
-     struct h8_op *operand;
-     int relaxmode;
+do_a_fix_imm (int offset, int nibble, struct h8_op *operand, int relaxmode)
 {
   int idx;
   int size;
@@ -1508,9 +1414,7 @@ do_a_fix_imm (offset, nibble, operand, relaxmode)
 /* Now we know what sort of opcodes it is, let's build the bytes.  */
 
 static void
-build_bytes (this_try, operand)
-     const struct h8_instruction *this_try;
-     struct h8_op *operand;
+build_bytes (const struct h8_instruction *this_try, struct h8_op *operand)
 {
   int i;
   char *output = frag_more (this_try->length);
@@ -1806,9 +1710,8 @@ build_bytes (this_try, operand)
    detect errors.  */
 
 static void
-clever_message (instruction, operand)
-     const struct h8_instruction *instruction;
-     struct h8_op *operand;
+clever_message (const struct h8_instruction *instruction,
+               struct h8_op *operand)
 {
   /* Find out if there was more than one possible opcode.  */
 
@@ -1869,24 +1772,23 @@ clever_message (instruction, operand)
 }
 
 
-/* Adjust OPERAND's value and size given that it is accessing a field
-   of SIZE bytes.
+/* If OPERAND is part of an address, adjust its size and value given
+   that it addresses SIZE bytes.
 
-   This function handles the choice between @(d:2,ERn) and @(d:16,ERn)
-   when no size is explicitly given.  It also scales down the assembly-level
+   This function decides how big non-immediate constants are when no
+   size was explicitly given.  It also scales down the assembly-level
    displacement in an @(d:2,ERn) operand.  */
 
 static void
-fix_operand_size (operand, size)
-     struct h8_op *operand;
-     int size;
+fix_operand_size (struct h8_op *operand, int size)
 {
-  if ((operand->mode & MODE) == DISP)
+  if (SXmode && (operand->mode & MODE) == DISP)
     {
       /* If the user didn't specify an operand width, see if we
         can use @(d:2,ERn).  */
-      if (SXmode
-         && (operand->mode & SIZE) == 0
+      if ((operand->mode & SIZE) == 0
+         && operand->exp.X_add_symbol == 0
+         && operand->exp.X_op_symbol == 0
          && (operand->exp.X_add_number == size
              || operand->exp.X_add_number == size * 2
              || operand->exp.X_add_number == size * 3))
@@ -1902,8 +1804,6 @@ fix_operand_size (operand, size)
        }
     }
 
-  /* If the operand needs a size but doesn't have one yet, it must be
-     a 16-bit integer (see colonmod24).  */
   if ((operand->mode & SIZE) == 0)
     switch (operand->mode & MODE)
       {
@@ -1912,7 +1812,27 @@ fix_operand_size (operand, size)
       case INDEXW:
       case INDEXL:
       case ABS:
-       operand->mode |= L_16;
+       /* Pick a 24-bit address unless we know that a 16-bit address
+          is safe.  get_specific() will relax L_24 into L_32 where
+          necessary.  */
+       if (Hmode
+           && !Nmode 
+           && (operand->exp.X_add_number < -32768
+               || operand->exp.X_add_number > 32767
+               || operand->exp.X_add_symbol != 0
+               || operand->exp.X_op_symbol != 0))
+         operand->mode |= L_24;
+       else
+         operand->mode |= L_16;
+       break;
+
+      case PCREL:
+       /* This condition is long standing, though somewhat suspect.  */
+       if (operand->exp.X_add_number > -128
+           && operand->exp.X_add_number < 127)
+         operand->mode |= L_8;
+       else
+         operand->mode |= L_16;
        break;
       }
 }
@@ -1923,8 +1843,7 @@ fix_operand_size (operand, size)
    the frags/bytes it assembles.  */
 
 void
-md_assemble (str)
-     char *str;
+md_assemble (char *str)
 {
   char *op_start;
   char *op_end;
@@ -1933,6 +1852,7 @@ md_assemble (str)
   const struct h8_instruction *prev_instruction;
 
   char *dot = 0;
+  char *slash = 0;
   char c;
   int size, i;
 
@@ -1952,6 +1872,8 @@ md_assemble (str)
          op_end += 2;
          break;
        }
+      else if (*op_end == '/' && ! slash)
+       slash = op_end;
     }
 
   if (op_end == op_start)
@@ -1962,6 +1884,12 @@ md_assemble (str)
 
   *op_end = 0;
 
+  /* The assembler stops scanning the opcode at slashes, so it fails
+     to make characters following them lower case.  Fix them.  */
+  if (slash)
+    while (*++slash)
+      *slash = TOLOWER (*slash);
+
   instruction = (const struct h8_instruction *)
     hash_find (opcode_hash_control, op_start);
 
@@ -1991,10 +1919,31 @@ md_assemble (str)
   *op_end = c;
   prev_instruction = instruction;
 
+  /* Now we have operands from instruction.
+     Let's check them out for ldm and stm.  */
+  if (OP_KIND (instruction->opcode->how) == O_LDM)
+    {
+      /* The first operand must be @er7+, and the
+        second operand must be a register pair.  */
+      if ((operand[0].mode != RSINC)
+           || (operand[0].reg != 7)
+           || ((operand[1].reg & 0x80000000) == 0))
+       as_bad (_("invalid operand in ldm"));
+    }
+  else if (OP_KIND (instruction->opcode->how) == O_STM)
+    {
+      /* The first operand must be a register pair,
+        and the second operand must be @-er7.  */
+      if (((operand[0].reg & 0x80000000) == 0)
+            || (operand[1].mode != RDDEC)
+            || (operand[1].reg != 7))
+       as_bad (_("invalid operand in stm"));
+    }
+
   size = SN;
   if (dot)
     {
-      switch (*dot)
+      switch (TOLOWER (*dot))
        {
        case 'b':
          size = SB;
@@ -2069,24 +2018,21 @@ md_assemble (str)
 
 #ifndef BFD_ASSEMBLER
 void
-tc_crawl_symbol_chain (headers)
-     object_headers *headers ATTRIBUTE_UNUSED;
+tc_crawl_symbol_chain (object_headers *headers ATTRIBUTE_UNUSED)
 {
   printf (_("call to tc_crawl_symbol_chain \n"));
 }
 #endif
 
 symbolS *
-md_undefined_symbol (name)
-     char *name ATTRIBUTE_UNUSED;
+md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
 {
   return 0;
 }
 
 #ifndef BFD_ASSEMBLER
 void
-tc_headers_hook (headers)
-     object_headers *headers ATTRIBUTE_UNUSED;
+tc_headers_hook (object_headers *headers ATTRIBUTE_UNUSED)
 {
   printf (_("call to tc_headers_hook \n"));
 }
@@ -2102,10 +2048,7 @@ tc_headers_hook (headers)
    returned, or NULL on OK.  */
 
 char *
-md_atof (type, litP, sizeP)
-     char type;
-     char *litP;
-     int *sizeP;
+md_atof (int type, char *litP, int *sizeP)
 {
   int prec;
   LITTLENUM_TYPE words[MAX_LITTLENUMS];
@@ -2163,37 +2106,34 @@ struct option md_longopts[] = {
 size_t md_longopts_size = sizeof (md_longopts);
 
 int
-md_parse_option (c, arg)
-     int c ATTRIBUTE_UNUSED;
-     char *arg ATTRIBUTE_UNUSED;
+md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
 {
   return 0;
 }
 
 void
-md_show_usage (stream)
-     FILE *stream ATTRIBUTE_UNUSED;
+md_show_usage (FILE *stream ATTRIBUTE_UNUSED)
 {
 }
 \f
-void tc_aout_fix_to_chars PARAMS ((void));
+void tc_aout_fix_to_chars (void);
 
 void
-tc_aout_fix_to_chars ()
+tc_aout_fix_to_chars (void)
 {
   printf (_("call to tc_aout_fix_to_chars \n"));
   abort ();
 }
 
 void
-md_convert_frag (headers, seg, fragP)
+md_convert_frag (
 #ifdef BFD_ASSEMBLER
-     bfd *headers ATTRIBUTE_UNUSED;
+                bfd *headers ATTRIBUTE_UNUSED,
 #else
-     object_headers *headers ATTRIBUTE_UNUSED;
+                object_headers *headers ATTRIBUTE_UNUSED,
 #endif
-     segT seg ATTRIBUTE_UNUSED;
-     fragS *fragP ATTRIBUTE_UNUSED;
+                segT seg ATTRIBUTE_UNUSED,
+                fragS *fragP ATTRIBUTE_UNUSED)
 {
   printf (_("call to md_convert_frag \n"));
   abort ();
@@ -2201,18 +2141,14 @@ md_convert_frag (headers, seg, fragP)
 
 #ifdef BFD_ASSEMBLER
 valueT
-md_section_align (segment, size)
-     segT segment;
-     valueT size;
+md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
   return ((size + (1 << align) - 1) & (-1 << align));
 }
 #else
 valueT
-md_section_align (seg, size)
-     segT seg;
-     valueT size;
+md_section_align (segT seg, valueT size)
 {
   return ((size + (1 << section_alignment[(int) seg]) - 1)
          & (-1 << section_alignment[(int) seg]));
@@ -2221,10 +2157,7 @@ md_section_align (seg, size)
 
 
 void
-md_apply_fix3 (fixP, valP, seg)
-     fixS *fixP;
-     valueT *valP;
-     segT seg ATTRIBUTE_UNUSED;
+md_apply_fix3 (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 {
   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
   long val = *valP;
@@ -2253,9 +2186,8 @@ md_apply_fix3 (fixP, valP, seg)
 }
 
 int
-md_estimate_size_before_relax (fragP, segment_type)
-     register fragS *fragP ATTRIBUTE_UNUSED;
-     register segT segment_type ATTRIBUTE_UNUSED;
+md_estimate_size_before_relax (register fragS *fragP ATTRIBUTE_UNUSED,
+                              register segT segment_type ATTRIBUTE_UNUSED)
 {
   printf (_("call tomd_estimate_size_before_relax \n"));
   abort ();
@@ -2263,28 +2195,20 @@ md_estimate_size_before_relax (fragP, segment_type)
 
 /* Put number into target byte order.  */
 void
-md_number_to_chars (ptr, use, nbytes)
-     char *ptr;
-     valueT use;
-     int nbytes;
+md_number_to_chars (char *ptr, valueT use, int nbytes)
 {
   number_to_chars_bigendian (ptr, use, nbytes);
 }
 
 long
-md_pcrel_from (fixP)
-     fixS *fixP ATTRIBUTE_UNUSED;
+md_pcrel_from (fixS *fixP ATTRIBUTE_UNUSED)
 {
   abort ();
 }
 
 #ifndef BFD_ASSEMBLER
 void
-tc_reloc_mangle (fix_ptr, intr, base)
-     fixS *fix_ptr;
-     struct internal_reloc *intr;
-     bfd_vma base;
-
+tc_reloc_mangle (fixS *fix_ptr, struct internal_reloc *intr, bfd_vma base)
 {
   symbolS *symbol_ptr;
 
@@ -2343,9 +2267,7 @@ tc_reloc_mangle (fix_ptr, intr, base)
 }
 #else /* BFD_ASSEMBLER */
 arelent *
-tc_gen_reloc (section, fixp)
-     asection *section ATTRIBUTE_UNUSED;
-     fixS *fixp;
+tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
 {
   arelent *rel;
   bfd_reloc_code_real_type r_type;
This page took 0.035431 seconds and 4 git commands to generate.