/* CGEN generic disassembler support code.
- Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2007
- Free Software Foundation, Inc.
+ Copyright (C) 1996-2021 Free Software Foundation, Inc.
This file is part of libopcodes.
#include "bfd.h"
#include "symcat.h"
#include "opcode/cgen.h"
+#include "disassemble.h"
static CGEN_INSN_LIST * hash_insn_array (CGEN_CPU_DESC, const CGEN_INSN *, int, int, CGEN_INSN_LIST **, CGEN_INSN_LIST *);
static CGEN_INSN_LIST * hash_insn_list (CGEN_CPU_DESC, const CGEN_INSN_LIST *, CGEN_INSN_LIST **, CGEN_INSN_LIST *);
{
unsigned mask = CGEN_INSN_BASE_MASK (insn);
int bits = 0;
- int m;
+ unsigned m;
+
for (m = 1; m != 0; m <<= 1)
{
if (mask & m)
return bits;
}
-/* Add an instruction to the hash chain. */
+/* Add an instruction to the hash chain. */
static void
add_insn_to_hash_chain (CGEN_INSN_LIST *hentbuf,
const CGEN_INSN *insn,
The result is a pointer to the next entry to use.
The table is scanned backwards as additions are made to the front of the
- list and we want earlier ones to be prefered. */
+ list and we want earlier ones to be preferred. */
static CGEN_INSN_LIST *
hash_insn_array (CGEN_CPU_DESC cd,
CGEN_INSN_LIST ** htable,
CGEN_INSN_LIST * hentbuf)
{
- int big_p = CGEN_CPU_ENDIAN (cd) == CGEN_ENDIAN_BIG;
+ int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
int i;
for (i = count - 1; i >= 0; --i, ++hentbuf)
{
unsigned int hash;
- char buf [4];
+ char buf [8];
unsigned long value;
const CGEN_INSN *insn = &insns[i];
+ size_t size;
if (! (* cd->dis_hash_p) (insn))
continue;
to hash on, so set both up. */
value = CGEN_INSN_BASE_VALUE (insn);
- bfd_put_bits ((bfd_vma) value,
- buf,
- CGEN_INSN_MASK_BITSIZE (insn),
- big_p);
+ size = CGEN_INSN_MASK_BITSIZE (insn);
+ OPCODES_ASSERT (size <= sizeof (buf) * 8);
+ bfd_put_bits ((bfd_vma) value, buf, size, big_p);
hash = (* cd->dis_hash) (buf, value);
add_insn_to_hash_chain (hentbuf, insn, htable, hash);
}
CGEN_INSN_LIST **htable,
CGEN_INSN_LIST *hentbuf)
{
- int big_p = CGEN_CPU_ENDIAN (cd) == CGEN_ENDIAN_BIG;
+ int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
const CGEN_INSN_LIST *ilist;
for (ilist = insns; ilist != NULL; ilist = ilist->next, ++ hentbuf)
dis_hash_table, hash_entry_buf);
/* Add runtime added insns.
- Later added insns will be prefered over earlier ones. */
+ Later added insns will be preferred over earlier ones. */
hash_entry_buf = hash_insn_list (cd, insn_table->new_entries,
dis_hash_table, hash_entry_buf);