]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - opcodes/tic54x-dis.c
C++ comments
[thirdparty/binutils-gdb.git] / opcodes / tic54x-dis.c
index c531b0b915a2148b55bc657c643c758fcd5855cd..18851680beb00f83e7b84d07cc08354159c73451 100644 (file)
@@ -1,38 +1,40 @@
 /* Disassembly routines for TMS320C54X architecture
-   Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999-2020 Free Software Foundation, Inc.
    Contributed by Timothy Wall (twall@cygnus.com)
 
-   This program is free software; you can redistribute it and/or modify
+   This file is part of the GNU opcodes library.
+
+   This library 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) any later version.
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   It is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   along with this file; see the file COPYING.  If not, write to the
+   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
+#include "sysdep.h"
 #include <errno.h>
 #include <math.h>
 #include <stdlib.h>
-#include "sysdep.h"
-#include "dis-asm.h"
+#include "disassemble.h"
 #include "opcode/tic54x.h"
 #include "coff/tic54x.h"
 
-static int has_lkaddr (unsigned short, const template *);
-static int get_insn_size (unsigned short, const template *);
+static int has_lkaddr (unsigned short, const insn_template *);
+static int get_insn_size (unsigned short, const insn_template *);
 static int print_instruction (disassemble_info *, bfd_vma,
                               unsigned short, const char *,
                               const enum optype [], int, int);
 static int print_parallel_instruction (disassemble_info *, bfd_vma,
-                                       unsigned short, 
-                                       const template *, int);
+                                       unsigned short,
+                                       const insn_template *, int);
 static int sprint_dual_address (disassemble_info *,char [],
                                 unsigned short);
 static int sprint_indirect_address (disassemble_info *,char [],
@@ -49,7 +51,7 @@ print_insn_tic54x (bfd_vma memaddr, disassemble_info *info)
   bfd_byte opbuf[2];
   unsigned short opcode;
   int status, size;
-  const template* tm;
+  const insn_template* tm;
 
   status = (*info->read_memory_func) (memaddr, opbuf, 2, info);
   if (status != 0)
@@ -84,7 +86,7 @@ print_insn_tic54x (bfd_vma memaddr, disassemble_info *info)
 }
 
 static int
-has_lkaddr (unsigned short memdata, const template *tm)
+has_lkaddr (unsigned short memdata, const insn_template *tm)
 {
   return (IS_LKADDR (memdata)
          && (OPTYPE (tm->operand_types[0]) == OP_Smem
@@ -97,11 +99,11 @@ has_lkaddr (unsigned short memdata, const template *tm)
 
 /* always returns 1 (whether an insn template was found) since we provide an
    "unknown instruction" template */
-const template*
-tic54x_get_insn (disassemble_info *info, bfd_vma addr, 
+const insn_template*
+tic54x_get_insn (disassemble_info *info, bfd_vma addr,
                  unsigned short memdata, int *size)
 {
-  const template *tm = NULL;
+  const insn_template *tm = NULL;
 
   for (tm = tic54x_optab; tm->name; tm++)
   {
@@ -115,7 +117,7 @@ tic54x_get_insn (disassemble_info *info, bfd_vma addr,
           bfd_byte opbuf[2];
           bfd_vma addr2 = addr + 1 + has_lkaddr (memdata, tm);
           int status = (*info->read_memory_func) (addr2, opbuf, 2, info);
-          // FIXME handle errors
+          /* FIXME handle errors.  */
           if (status == 0)
             {
               unsigned short data2 = bfd_getl16 (opbuf);
@@ -133,7 +135,7 @@ tic54x_get_insn (disassemble_info *info, bfd_vma addr,
         }
     }
   }
-  for (tm = (template *) tic54x_paroptab; tm->name; tm++)
+  for (tm = (insn_template *) tic54x_paroptab; tm->name; tm++)
   {
     if (tm->opcode == (memdata & tm->mask))
     {
@@ -147,7 +149,7 @@ tic54x_get_insn (disassemble_info *info, bfd_vma addr,
 }
 
 static int
-get_insn_size (unsigned short memdata, const template *insn)
+get_insn_size (unsigned short memdata, const insn_template *insn)
 {
   int size;
 
@@ -165,14 +167,13 @@ get_insn_size (unsigned short memdata, const template *insn)
 }
 
 int
-print_instruction (info, memaddr, opcode, tm_name, tm_operands, size, ext)
-  disassemble_info *info;
-  bfd_vma memaddr;
-  unsigned short opcode;
-  const char *tm_name;
-  const enum optype tm_operands[];
-  int size;
-  int ext;
+print_instruction (disassemble_info *info,
+                  bfd_vma memaddr,
+                  unsigned short opcode,
+                  const char *tm_name,
+                  const enum optype tm_operands[],
+                  int size,
+                  int ext)
 {
   static int n;
   /* string storage for multiple operands */
@@ -378,7 +379,10 @@ print_instruction (info, memaddr, opcode, tm_name, tm_operands, size, ext)
         case OP_CC3:
         {
           const char *code[] = { "eq", "lt", "gt", "neq" };
-          sprintf (operand[i], code[CC3 (opcode)]);
+
+         /* Do not use sprintf with only two parameters as a
+            compiler warning could be generated in such conditions.  */
+         sprintf (operand[i], "%s", code[CC3 (opcode)]);
           info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
           break;
         }
@@ -390,8 +394,7 @@ print_instruction (info, memaddr, opcode, tm_name, tm_operands, size, ext)
             break;
           }
         case OP_k5:
-          sprintf (operand[i], "#%d",
-                   (int) (((signed char) opcode & 0x1F) << 3) >> 3);
+          sprintf (operand[i], "#%d", ((opcode & 0x1F) ^ 0x10) - 0x10);
           info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
           break;
         case OP_k8u:
@@ -463,12 +466,11 @@ print_instruction (info, memaddr, opcode, tm_name, tm_operands, size, ext)
 }
 
 static int
-print_parallel_instruction (info, memaddr, opcode, ptm, size)
-  disassemble_info *info;
-  bfd_vma memaddr;
-  unsigned short opcode;
-  const template *ptm;
-  int size;
+print_parallel_instruction (disassemble_info *info,
+                           bfd_vma memaddr,
+                           unsigned short opcode,
+                           const insn_template *ptm,
+                           int size)
 {
   print_instruction (info, memaddr, opcode,
                      ptm->name, ptm->operand_types, size, 0);
@@ -478,10 +480,9 @@ print_parallel_instruction (info, memaddr, opcode, ptm, size)
 }
 
 static int
-sprint_dual_address (info, buf, code)
-  disassemble_info *info ATTRIBUTE_UNUSED;
-  char buf[];
-  unsigned short code;
+sprint_dual_address (disassemble_info *info ATTRIBUTE_UNUSED,
+                    char buf[],
+                    unsigned short code)
 {
   const char *formats[] = {
     "*ar%d",
@@ -493,10 +494,9 @@ sprint_dual_address (info, buf, code)
 }
 
 static int
-sprint_indirect_address (info, buf, opcode)
-  disassemble_info *info ATTRIBUTE_UNUSED;
-  char buf[];
-  unsigned short opcode;
+sprint_indirect_address (disassemble_info *info ATTRIBUTE_UNUSED,
+                        char buf[],
+                        unsigned short opcode)
 {
   const char *formats[] = {
     "*ar%d",
@@ -516,22 +516,20 @@ sprint_indirect_address (info, buf, opcode)
 }
 
 static int
-sprint_direct_address (info, buf, opcode)
-  disassemble_info *info ATTRIBUTE_UNUSED;
-  char buf[];
-  unsigned short opcode;
+sprint_direct_address (disassemble_info *info ATTRIBUTE_UNUSED,
+                      char buf[],
+                      unsigned short opcode)
 {
   /* FIXME -- look up relocation if available */
   return sprintf (buf, "DP+0x%02x", (int) (opcode & 0x7F));
 }
 
 static int
-sprint_mmr (info, buf, mmr)
-  disassemble_info *info ATTRIBUTE_UNUSED;
-  char buf[];
-  int mmr;
+sprint_mmr (disassemble_info *info ATTRIBUTE_UNUSED,
+           char buf[],
+           int mmr)
 {
-  symbol *reg = (symbol *) mmregs;
+  tic54x_symbol *reg = (tic54x_symbol *) mmregs;
   while (reg->name != NULL)
     {
       if (mmr == reg->value)
@@ -546,10 +544,9 @@ sprint_mmr (info, buf, mmr)
 }
 
 static int
-sprint_cc2 (info, buf, opcode)
-  disassemble_info *info ATTRIBUTE_UNUSED;
-  char *buf;
-  unsigned short opcode;
+sprint_cc2 (disassemble_info *info ATTRIBUTE_UNUSED,
+           char *buf,
+           unsigned short opcode)
 {
   const char *cc2[] = {
     "??", "??", "ageq", "alt", "aneq", "aeq", "agt", "aleq",
@@ -559,10 +556,9 @@ sprint_cc2 (info, buf, opcode)
 }
 
 static int
-sprint_condition (info, buf, opcode)
-  disassemble_info *info ATTRIBUTE_UNUSED;
-  char *buf;
-  unsigned short opcode;
+sprint_condition (disassemble_info *info ATTRIBUTE_UNUSED,
+                 char *buf,
+                 unsigned short opcode)
 {
   char *start = buf;
   const char *cmp[] = {