]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - opcodes/ia64-opc.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / opcodes / ia64-opc.c
index 9726381dd6af7bb52ea795958a81d2ead3ea987a..7f9bb495ecdc5c40b84c7cdf0da1ea1c1919ce85 100644 (file)
@@ -1,43 +1,42 @@
 /* ia64-opc.c -- Functions to access the compacted opcode table
-   Copyright 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1999-2021 Free Software Foundation, Inc.
    Written by Bob Manson of Cygnus Solutions, <manson@cygnus.com>
 
-   This file is part of GDB, GAS, and the GNU binutils.
+   This file is part of the GNU opcodes library.
 
-   GDB, GAS, and the GNU binutils are free software; you can redistribute
-   them and/or modify them under the terms of the GNU General Public
-   License as published by the Free Software Foundation; either version
-   2, or (at your option) any later version.
+   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 3, or (at your option)
+   any later version.
 
-   GDB, GAS, and the GNU binutils are distributed in the hope that they
-   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 file; see the file COPYING.  If not, write to the
-   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
-#include "ansidecl.h"
-#include "libiberty.h"
 #include "sysdep.h"
+#include "libiberty.h"
 #include "ia64-asmtab.h"
 #include "ia64-asmtab.c"
 
-static void get_opc_prefix PARAMS ((const char **, char *));
-static short int find_string_ent PARAMS ((const char *));
-static short int find_main_ent PARAMS ((short int));
-static short int find_completer PARAMS ((short int, short int, const char *));
-static ia64_insn apply_completer PARAMS ((ia64_insn, int));
-static int extract_op_bits PARAMS ((int, int, int));
-static int extract_op PARAMS ((int, int *, unsigned int *));
-static int opcode_verify PARAMS ((ia64_insn, int, enum ia64_insn_type));
-static int locate_opcode_ent PARAMS ((ia64_insn, enum ia64_insn_type));
+static void get_opc_prefix (const char **, char *);
+static short int find_string_ent (const char *);
+static short int find_main_ent (short int);
+static short int find_completer (short int, short int, const char *);
+static ia64_insn apply_completer (ia64_insn, int);
+static int extract_op_bits (int, int, int);
+static int extract_op (int, int *, unsigned int *);
+static int opcode_verify (ia64_insn, int, enum ia64_insn_type);
+static int locate_opcode_ent (ia64_insn, enum ia64_insn_type);
 static struct ia64_opcode *make_ia64_opcode
-  PARAMS ((ia64_insn, const char *, int, int));
+  (ia64_insn, const char *, int, int);
 static struct ia64_opcode *ia64_find_matching_opcode
-  PARAMS ((const char *, short int));
+  (const char *, short int);
 
 const struct ia64_templ_desc ia64_templ_desc[16] =
   {
@@ -65,9 +64,7 @@ const struct ia64_templ_desc ia64_templ_desc[16] =
    of the opcode, or at the NUL character. */
 
 static void
-get_opc_prefix (ptr, dest)
-     const char **ptr;
-     char *dest;
+get_opc_prefix (const char **ptr, char *dest)
 {
   char *c = strchr (*ptr, '.');
   if (c != NULL)
@@ -89,8 +86,7 @@ get_opc_prefix (ptr, dest)
    STR; return -1 if one does not exist. */
 
 static short
-find_string_ent (str)
-     const char *str;
+find_string_ent (const char *str)
 {
   short start = 0;
   short end = sizeof (ia64_strings) / sizeof (const char *);
@@ -124,11 +120,10 @@ find_string_ent (str)
    return -1 if one does not exist. */
 
 static short
-find_main_ent (nameindex)
-     short nameindex;
+find_main_ent (short nameindex)
 {
   short start = 0;
-  short end = sizeof (main_table) / sizeof (struct ia64_main_table);
+  short end = ARRAY_SIZE (main_table);
   short i = (start + end) / 2;
 
   if (nameindex < main_table[0].name_index
@@ -164,10 +159,7 @@ find_main_ent (nameindex)
    return -1 if one does not exist. */
 
 static short
-find_completer (main_ent, prev_completer, name)
-     short main_ent;
-     short prev_completer;
-     const char *name;
+find_completer (short main_ent, short prev_completer, const char *name)
 {
   short name_index = find_string_ent (name);
 
@@ -200,9 +192,7 @@ find_completer (main_ent, prev_completer, name)
    return the result. */
 
 static ia64_insn
-apply_completer (opcode, completer_index)
-     ia64_insn opcode;
-     int completer_index;
+apply_completer (ia64_insn opcode, int completer_index)
 {
   ia64_insn mask = completer_table[completer_index].mask;
   ia64_insn bits = completer_table[completer_index].bits;
@@ -220,10 +210,7 @@ apply_completer (opcode, completer_index)
    first byte in OP_POINTER.) */
 
 static int
-extract_op_bits (op_pointer, bitoffset, bits)
-     int op_pointer;
-     int bitoffset;
-     int bits;
+extract_op_bits (int op_pointer, int bitoffset, int bits)
 {
   int res = 0;
 
@@ -259,10 +246,7 @@ extract_op_bits (op_pointer, bitoffset, bits)
    state entry in bits is returned. */
 
 static int
-extract_op (op_pointer, opval, op)
-     int op_pointer;
-     int *opval;
-     unsigned int *op;
+extract_op (int op_pointer, int *opval, unsigned int *op)
 {
   int oplen = 5;
 
@@ -317,10 +301,7 @@ extract_op (op_pointer, opval, op)
    PLACE matches OPCODE and is of type TYPE. */
 
 static int
-opcode_verify (opcode, place, type)
-     ia64_insn opcode;
-     int place;
-     enum ia64_insn_type type;
+opcode_verify (ia64_insn opcode, int place, enum ia64_insn_type type)
 {
   if (main_table[place].opcode_type != type)
     {
@@ -364,9 +345,7 @@ opcode_verify (opcode, place, type)
    priority. */
 
 static int
-locate_opcode_ent (opcode, type)
-     ia64_insn opcode;
-     enum ia64_insn_type type;
+locate_opcode_ent (ia64_insn opcode, enum ia64_insn_type type)
 {
   int currtest[41];
   int bitpos[41];
@@ -385,7 +364,7 @@ locate_opcode_ent (opcode, type)
       unsigned int op;
       int currbitnum = bitpos[currstatenum];
       int oplen;
-      int opval[3];
+      int opval[3] = {0};
       int next_op;
       int currbit;
 
@@ -393,13 +372,16 @@ locate_opcode_ent (opcode, type)
 
       bitpos[currstatenum] = currbitnum;
 
-      /* Skip opval[0] bits in the instruction. */
+      /* Skip opval[0] bits in the instruction.  */
       if (op & 0x40)
        {
          currbitnum -= opval[0];
        }
 
-      /* The value of the current bit being tested. */
+      if (currbitnum < 0)
+       currbitnum = 0;
+
+      /* The value of the current bit being tested.  */
       currbit = opcode & (((ia64_insn) 1) << currbitnum) ? 1 : 0;
       next_op = -1;
 
@@ -484,7 +466,7 @@ locate_opcode_ent (opcode, type)
 
          if (next_op > 65535)
            {
-             abort ();
+             return -1;
            }
 
          /* Run through the list of opcodes to check, trying to find
@@ -545,11 +527,7 @@ locate_opcode_ent (opcode, type)
 /* Construct an ia64_opcode entry based on OPCODE, NAME and PLACE. */
 
 static struct ia64_opcode *
-make_ia64_opcode (opcode, name, place, depind)
-     ia64_insn opcode;
-     const char *name;
-     int place;
-     int depind;
+make_ia64_opcode (ia64_insn opcode, const char *name, int place, int depind)
 {
   struct ia64_opcode *res =
     (struct ia64_opcode *) xmalloc (sizeof (struct ia64_opcode));
@@ -572,9 +550,7 @@ make_ia64_opcode (opcode, name, place, depind)
 /* Determine the ia64_opcode entry for the opcode specified by INSN
    and TYPE.  If a valid entry is not found, return NULL. */
 struct ia64_opcode *
-ia64_dis_opcode (insn, type)
-     ia64_insn insn;
-     enum ia64_insn_type type;
+ia64_dis_opcode (ia64_insn insn, enum ia64_insn_type type)
 {
   int disent = locate_opcode_ent (insn, type);
 
@@ -633,14 +609,15 @@ ia64_dis_opcode (insn, type)
    matches NAME.  Return NULL if one is not found. */
 
 static struct ia64_opcode *
-ia64_find_matching_opcode (name, place)
-     const char *name;
-     short place;
+ia64_find_matching_opcode (const char *name, short place)
 {
   char op[129];
   const char *suffix;
   short name_index;
 
+  if ((unsigned) place >= ARRAY_SIZE (main_table))
+    return NULL;
+
   if (strlen (name) > 128)
     {
       return NULL;
@@ -696,8 +673,7 @@ ia64_find_matching_opcode (name, place)
    release any resources used by the returned entry. */
 
 struct ia64_opcode *
-ia64_find_next_opcode (prev_ent)
-     struct ia64_opcode *prev_ent;
+ia64_find_next_opcode (struct ia64_opcode *prev_ent)
 {
   return ia64_find_matching_opcode (prev_ent->name,
                                    prev_ent->ent_index + 1);
@@ -710,8 +686,7 @@ ia64_find_next_opcode (prev_ent)
    release any resources used by the returned entry. */
 
 struct ia64_opcode *
-ia64_find_opcode (name)
-     const char *name;
+ia64_find_opcode (const char *name)
 {
   char op[129];
   const char *suffix;
@@ -741,22 +716,20 @@ ia64_find_opcode (name)
 
 /* Free any resources used by ENT. */
 void
-ia64_free_opcode (ent)
-     struct ia64_opcode *ent;
+ia64_free_opcode (struct ia64_opcode *ent)
 {
   free ((void *)ent->name);
   free (ent);
 }
 
 const struct ia64_dependency *
-ia64_find_dependency (index)
-  int index;
+ia64_find_dependency (int dep_index)
 {
-  index = DEP(index);
+  dep_index = DEP(dep_index);
 
-  if (index < 0
-      || index >= (int)(sizeof(dependencies) / sizeof(dependencies[0])))
+  if (dep_index < 0
+      || dep_index >= (int) ARRAY_SIZE (dependencies))
     return NULL;
 
-  return &dependencies[index];
+  return &dependencies[dep_index];
 }