s/boolean/bfd_boolean/ s/true/TRUE/ s/false/FALSE/. Simplify
[deliverable/binutils-gdb.git] / opcodes / cris-dis.c
index 0d13b8f180b4878d03efbb055da61dc9ddfb3686..6beb4abea1d47fdfb14650c51b506bc60c8f21fc 100644 (file)
@@ -1,5 +1,5 @@
 /* Disassembler code for CRIS.
-   Copyright (C) 2000 Free Software Foundation, Inc.
+   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
    Contributed by Axis Communications AB, Lund, Sweden.
    Written by Hans-Peter Nilsson.
 
@@ -7,7 +7,7 @@ This file is part of the GNU binutils and GDB, the GNU debugger.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2 of the License, or (at your option)
+Software Foundation; either version 2, or (at your option)
 any later version.
 
 This program is distributed in the hope that it will be useful, but WITHOUT
@@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "opcode/cris.h"
 #include "libiberty.h"
 \f
-
 /* No instruction will be disassembled longer than this.  In theory, and
    in silicon, address prefixes can be cascaded.  In practice, cascading
    is not used by GCC, and not supported by the assembler.  */
@@ -38,6 +37,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define PARSE_PREFIX 1
 #endif
 
+/* Sometimes we prefix all registers with this character.  */
+#define REGISTER_PREFIX_CHAR '$'
+
 /* Whether or not to trace the following sequence:
    sub* X,r%d
    bound* Y,r%d
@@ -75,25 +77,39 @@ static long no_of_case_offsets = 0;
 /* Candidate for next case_offset.  */
 static long last_immediate = 0;
 
-static int number_of_bits PARAMS ((unsigned int));
-static char *format_hex PARAMS ((unsigned long, char *));
-static char *format_dec PARAMS ((long, char *, int));
-static char *format_reg PARAMS ((int, char *));
-static int cris_constraint PARAMS ((const char *, unsigned int,
-                                   unsigned int));
-static unsigned bytes_to_skip PARAMS ((unsigned int,
-                                      const struct cris_opcode *));
-static char *print_flags PARAMS ((unsigned int, char *));
-static void print_with_operands PARAMS ((const struct cris_opcode *,
-                                        unsigned int, unsigned char *,
-                                        bfd_vma, disassemble_info *,
-                                        const struct cris_opcode *,
-                                        unsigned int, unsigned char *));
-static const struct cris_spec_reg *spec_reg_info PARAMS ((unsigned int));
+static int number_of_bits
+  PARAMS ((unsigned int));
+static char *format_hex
+  PARAMS ((unsigned long, char *));
+static char *format_dec
+  PARAMS ((long, char *, int));
+static char *format_reg
+  PARAMS ((int, char *, bfd_boolean));
+static int cris_constraint
+  PARAMS ((const char *, unsigned int, unsigned int));
+static unsigned bytes_to_skip
+  PARAMS ((unsigned int, const struct cris_opcode *));
+static char *print_flags
+  PARAMS ((unsigned int, char *));
+static void print_with_operands
+  PARAMS ((const struct cris_opcode *, unsigned int, unsigned char *,
+          bfd_vma, disassemble_info *, const struct cris_opcode *,
+          unsigned int, unsigned char *, bfd_boolean));
+static const struct cris_spec_reg *spec_reg_info
+  PARAMS ((unsigned int));
+static int print_insn_cris_generic
+  PARAMS ((bfd_vma, disassemble_info *, bfd_boolean));
+static int print_insn_cris_with_register_prefix
+  PARAMS ((bfd_vma, disassemble_info *));
+static int print_insn_cris_without_register_prefix
+  PARAMS ((bfd_vma, disassemble_info *));
+static const struct cris_opcode *get_opcode_entry
+  PARAMS ((unsigned int, unsigned int));
 
 /* Return the descriptor of a special register.
    FIXME: Depend on a CPU-version specific argument when all machinery
    is in place.  */
+
 static const struct cris_spec_reg *
 spec_reg_info (sreg)
      unsigned int sreg;
@@ -108,22 +124,22 @@ spec_reg_info (sreg)
   return NULL;
 }
 
-
 /* Return the number of bits in the argument.  */
+
 static int
 number_of_bits (val)
      unsigned int val;
 {
   int bits;
 
-  for (bits = 0; val != 0; val &= val-1)
+  for (bits = 0; val != 0; val &= val - 1)
     bits++;
 
   return bits;
 }
 
-
 /* Get an entry in the opcode-table.  */
+
 static const struct cris_opcode *
 get_opcode_entry (insn, prefix_insn)
      unsigned int insn;
@@ -281,8 +297,8 @@ get_opcode_entry (insn, prefix_insn)
   return max_matchedp;
 }
 
-
 /* Format number as hex with a leading "0x" into outbuffer.  */
+
 static char *
 format_hex (number, outbuffer)
      unsigned long number;
@@ -302,10 +318,10 @@ format_hex (number, outbuffer)
   return outbuffer + strlen (outbuffer);
 }
 
-
 /* Format number as decimal into outbuffer.  Parameter signedp says
    whether the number should be formatted as signed (!= 0) or
    unsigned (== 0).  */
+
 static char *
 format_dec (number, outbuffer, signedp)
      long number;
@@ -318,13 +334,19 @@ format_dec (number, outbuffer, signedp)
   return outbuffer + strlen (outbuffer);
 }
 
-
 /* Format the name of the general register regno into outbuffer.  */
+
 static char *
-format_reg (regno, outbuffer)
+format_reg (regno, outbuffer_start, with_reg_prefix)
      int regno;
-     char *outbuffer;
+     char *outbuffer_start;
+     bfd_boolean with_reg_prefix;
 {
+  char *outbuffer = outbuffer_start;
+
+  if (with_reg_prefix)
+    *outbuffer++ = REGISTER_PREFIX_CHAR;
+
   switch (regno)
     {
     case 15:
@@ -340,13 +362,13 @@ format_reg (regno, outbuffer)
       break;
     }
 
-  return outbuffer + strlen (outbuffer);
+  return outbuffer_start + strlen (outbuffer_start);
 }
 
-
 /* Return -1 if the constraints of a bitwise-matched instruction say
    that there is no match.  Otherwise return a nonnegative number
    indicating the confidence in the match (higher is better).  */
+
 static int
 cris_constraint (cs, insn, prefix_insn)
      const char *cs;
@@ -358,7 +380,7 @@ cris_constraint (cs, insn, prefix_insn)
   int prefix_ok = 0;
 
   const char *s;
-  for (s  = cs; *s; s++)
+  for (s = cs; *s; s++)
     switch (*s)
       {
       case '!':
@@ -493,8 +515,8 @@ cris_constraint (cs, insn, prefix_insn)
   return retval;
 }
 
-
 /* Return the length of an instruction.  */
+
 static unsigned
 bytes_to_skip (insn, matchedp)
      unsigned int insn;
@@ -536,8 +558,8 @@ bytes_to_skip (insn, matchedp)
   return to_skip;
 }
 
-
 /* Print condition code flags.  */
+
 static char *
 print_flags (insn, cp)
      unsigned int insn;
@@ -559,13 +581,13 @@ print_flags (insn, cp)
   return cp;
 }
 
-
 /* Print out an insn with its operands, and update the info->insn_type
    fields.  The prefix_opcodep and the rest hold a prefix insn that is
    supposed to be output as an address mode.  */
+
 static void
 print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
-                    prefix_insn, prefix_buffer)
+                    prefix_insn, prefix_buffer, with_reg_prefix)
      const struct cris_opcode *opcodep;
      unsigned int insn;
      unsigned char *buffer;
@@ -577,10 +599,11 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
      const struct cris_opcode *prefix_opcodep;
      unsigned int prefix_insn;
      unsigned char *prefix_buffer;
+     bfd_boolean with_reg_prefix;
 {
   /* Get a buffer of somewhat reasonable size where we store
      intermediate parts of the insn.  */
-  char temp[sizeof (".d [r13=r12-2147483648],r10") * 2];
+  char temp[sizeof (".d [$r13=$r12-2147483648],$r10") * 2];
   char *tp = temp;
   static const char mode_char[] = "bwd?";
   const char *s;
@@ -654,11 +677,11 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
 
       case 'D':
       case 'r':
-       tp = format_reg (insn & 15, tp);
+       tp = format_reg (insn & 15, tp, with_reg_prefix);
        break;
 
       case 'R':
-       tp = format_reg ((insn >> 12) & 15, tp);
+       tp = format_reg ((insn >> 12) & 15, tp, with_reg_prefix);
        break;
 
       case 'y':
@@ -804,7 +827,7 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
              {
                if (insn & 0x400)
                  {
-                   tp = format_reg (insn & 15, tp);
+                   tp = format_reg (insn & 15, tp, with_reg_prefix);
                    *tp++ = '=';
                  }
 
@@ -846,7 +869,8 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
                        info->target2 = prefix_insn & 15;
 
                        *tp++ = '[';
-                       tp = format_reg (prefix_insn & 15, tp);
+                       tp = format_reg (prefix_insn & 15, tp,
+                                        with_reg_prefix);
                        if (prefix_insn & 0x400)
                          *tp++ = '+';
                        *tp++ = ']';
@@ -862,7 +886,8 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
                        number -= 256;
 
                      /* Output "reg+num" or, if num < 0, "reg-num".  */
-                     tp = format_reg ((prefix_insn >> 12) & 15, tp);
+                     tp = format_reg ((prefix_insn >> 12) & 15, tp,
+                                      with_reg_prefix);
                      if (number >= 0)
                        *tp++ = '+';
                      tp = format_dec (number, tp, 1);
@@ -875,9 +900,10 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
 
                  case BIAP_OPCODE:
                    /* Output "r+R.m".  */
-                   tp = format_reg (prefix_insn & 15, tp);
+                   tp = format_reg (prefix_insn & 15, tp, with_reg_prefix);
                    *tp++ = '+';
-                   tp = format_reg ((prefix_insn >> 12) & 15, tp);
+                   tp = format_reg ((prefix_insn >> 12) & 15, tp,
+                                    with_reg_prefix);
                    *tp++ = '.';
                    *tp++ = mode_char[(prefix_insn >> 4) & 3];
 
@@ -899,7 +925,8 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
                  case BDAP_INDIR_OPCODE:
                    /* Output "r+s.m", or, if "s" is [pc+], "r+s" or
                       "r-s".  */
-                   tp = format_reg ((prefix_insn >> 12) & 15, tp);
+                   tp = format_reg ((prefix_insn >> 12) & 15, tp,
+                                    with_reg_prefix);
 
                    if ((prefix_insn & 0x400) && (prefix_insn & 15) == 15)
                      {
@@ -969,7 +996,8 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
                        /* Output "r+[R].m" or "r+[R+].m".  */
                        *tp++ = '+';
                        *tp++ = '[';
-                       tp = format_reg (prefix_insn & 15, tp);
+                       tp = format_reg (prefix_insn & 15, tp,
+                                        with_reg_prefix);
                        if (prefix_insn & 0x400)
                          *tp++ = '+';
                        *tp++ = ']';
@@ -998,7 +1026,7 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
              }
            else
              {
-               tp = format_reg (insn & 15, tp);
+               tp = format_reg (insn & 15, tp, with_reg_prefix);
 
                info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG;
                info->target = insn & 15;
@@ -1011,7 +1039,7 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
        break;
 
       case 'x':
-       tp = format_reg ((insn >> 12) & 15, tp);
+       tp = format_reg ((insn >> 12) & 15, tp, with_reg_prefix);
        *tp++ = '.';
        *tp++ = mode_char[(insn >> 4) & 3];
        break;
@@ -1083,7 +1111,7 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
 
        tp = format_dec (number, tp, 1);
        *tp++ = ',';
-       tp = format_reg ((insn >> 12) & 15, tp);
+       tp = format_reg ((insn >> 12) & 15, tp, with_reg_prefix);
       }
       break;
 
@@ -1105,6 +1133,8 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
          *tp++ = '?';
        else
          {
+           if (with_reg_prefix)
+             *tp++ = REGISTER_PREFIX_CHAR;
            strcpy (tp, sregp->name);
            tp += strlen (tp);
          }
@@ -1155,11 +1185,14 @@ print_with_operands (opcodep, insn, buffer, addr, info, prefix_opcodep,
 
 
 /* Print the CRIS instruction at address memaddr on stream.  Returns
-   length of the instruction, in bytes.  */
-int
-print_insn_cris (memaddr, info)
+   length of the instruction, in bytes.  Prefix register names with `$' if
+   WITH_REG_PREFIX.  */
+
+static int
+print_insn_cris_generic (memaddr, info, with_reg_prefix)
      bfd_vma memaddr;
      disassemble_info *info;
+     bfd_boolean with_reg_prefix;
 {
   int nbytes;
   unsigned int insn;
@@ -1170,7 +1203,7 @@ print_insn_cris (memaddr, info)
      bytes; stacked prefixes will not be expanded.  */
   unsigned char buffer[MAX_BYTES_PER_CRIS_INSN];
   unsigned char *bufp;
-  int status;
+  int status = 0;
   bfd_vma addr;
 
   /* There will be an "out of range" error after the last instruction.
@@ -1300,7 +1333,7 @@ print_insn_cris (memaddr, info)
                 to the operands.   */
              print_with_operands (matchedp, insn, bufp, addr, info,
                                   prefix_opcodep, prefix_insn,
-                                  prefix_buffer);
+                                  prefix_buffer, with_reg_prefix);
            }
        }
     }
@@ -1335,6 +1368,42 @@ print_insn_cris (memaddr, info)
   return advance;
 }
 
+/* Disassemble, prefixing register names with `$'.  */
+
+static int
+print_insn_cris_with_register_prefix (vma, info)
+     bfd_vma vma;
+     disassemble_info *info;
+{
+  return print_insn_cris_generic (vma, info, TRUE);
+}
+
+/* Disassemble, no prefixes on register names.  */
+
+static int
+print_insn_cris_without_register_prefix (vma, info)
+     bfd_vma vma;
+     disassemble_info *info;
+{
+  return print_insn_cris_generic (vma, info, FALSE);
+}
+
+/* Return a disassembler-function that prints registers with a `$' prefix,
+   or one that prints registers without a prefix.  */
+
+disassembler_ftype
+cris_get_disassembler (abfd)
+     bfd *abfd;
+{
+  /* If there's no bfd in sight, we return what is valid as input in all
+     contexts if fed back to the assembler: disassembly *with* register
+     prefix.  */
+  if (abfd == NULL || bfd_get_symbol_leading_char (abfd) == 0)
+    return print_insn_cris_with_register_prefix;
+
+  return print_insn_cris_without_register_prefix;
+}
+
 /*
  * Local variables:
  * eval: (c-set-style "gnu")
This page took 0.047421 seconds and 4 git commands to generate.