[BACK]Return to csky-dis.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / external / gpl3 / binutils / dist / opcodes

File: [cvs.NetBSD.org] / src / external / gpl3 / binutils / dist / opcodes / csky-dis.c (download)

Revision 1.1.1.1 (vendor branch), Fri Apr 3 23:39:47 2020 UTC (3 years, 11 months ago) by christos
Branch: MAIN, FSF
CVS Tags: phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, netbsd-10-base, netbsd-10-0-RELEASE, netbsd-10-0-RC6, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, binutils-2-34
Branch point for: phil-wifi
Changes since 1.1: +0 -0 lines

Import binutils-2.34

2020-01-18  Nick Clifton  <nickc@redhat.com>

	Binutils 2.34 branch created.

2020-01-18  Nick Clifton  <nickc@redhat.com>

	Synchronize top level configure files with master version:

	2020-01-01  Ben Elliston  <bje@gnu.org>

	* config.guess: Update copyright years.
	* config.sub: Likewise.

	2019-12-21  Ben Elliston  <bje@gnu.org>

	* config.guess (set_cc_for_build): Prevent multiple calls by
	checking if $tmp is already set. We can't check CC_FOR_BUILD as
	the user may set it externally. Thanks to Torbjörn Granlund for
	the bug report.

	2019-12-21  Torbjörn Granlund  <tg@gmplib.org>

	* config.guess (alpha:Linux:*:*): Guard against missing
	/proc/cpuinfo by redirecting standard error to /dev/null.

	2019-09-12  Daniel Bittman  <danielbittman1@gmail.com>

	* config.guess (*:Twizzler:*:*): New.
	* config.sub (-twizzler*): New.

	2019-07-24  Ben Elliston  <bje@gnu.org>

	* config.guess (mips:OSF1:*.*): Whitespace cleanup.

	2019-06-30  Ben Elliston  <bje@gnu.org>

	* config.sub (case $os): Match nsk* and powerunix. Don't later
	match nsk* and set os=nsk which removes the OS version number.

	2019-06-30  Ben Elliston  <bje@gnu.org>

	* config.sub: Recognise os108*.

	2019-06-26  Ben Elliston  <bje@gnu.org>

	* config.sub (hp300): Set $os to hpux.

	2019-06-26  Ben Elliston  <bje@gnu.org>

	* config.sub (vsta): Move into alphabetical order.

	2019-06-10  Ben Elliston  <bje@gnu.org>

	* config.guess (*:OS108:*:*): Recognise new OS.

	2019-05-28  Ben Elliston  <bje@gnu.org>

	* config.guess (*:Darwin:*:*): Run xcode-select to determine if a
	system compiler is installed. If not, do not run set_cc_for_build,
	as the default cc will open a dialog box asking to install
	Xcode. If no C compiler is available, guess based on uname -p and
	uname -m.

	2019-05-28  Ben Elliston  <bje@gnu.org>

	* config.guess (*:Darwin:*:*): Simplify UNAME_PROCESSOR.

2020-01-17  Simon Marchi  <simon.marchi@efficios.com>

	* Makefile.def: Add dependencies of all-gdbsupport on all-bfd.
	* Makefile.in: Re-generate.

2020-01-14  Tom Tromey  <tom@tromey.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add gdbsupport.
	* MAINTAINERS: Add gdbsupport.
	* configure: Rebuild.
	* configure.ac (configdirs): Add gdbsupport.
	* gdbsupport: New directory, move from gdb/gdbsupport.
	* Makefile.def (host_modules, dependencies): Add gnulib.
	* Makefile.in: Rebuild.

2020-01-09  Aaron Merey  <amerey@redhat.com>

        * config/debuginfod.m4: New file. Add macro AC_DEBUGINFOD. Adds
        new configure option --with-debuginfod.
        * configure: Regenerate.
        * configure.ac: Call AC_DEBUGINFOD.

2019-12-26  Christian Biesinger  <cbiesinger@google.com>

	* .gitignore: Add perf.data and perf.data.old.

2019-10-17  Sergio Durigan Junior  <sergiodj@redhat.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add libctf.

2019-10-17  Alan Modra  <amodra@gmail.com>

	PR 29
	* src-release.sh (getver): Replace "head -1" with "head -n 1".

2019-07-30  Nick Alcock  <nick.alcock@oracle.com>

	* Makefile.def (host_modules): libctf is no longer no_install.
	* Makefile.in: Regenerated.

2019-07-13  Nick Alcock  <nick.alcock@oracle.com>

	* Makefile.def (dependencies): all-ld depends on all-libctf.
	* Makefile.in: Regenerated.

2019-09-09  Phil Blundell  <pb@pbcl.net>

	binutils 2.33 branch created

2019-08-19  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac: Add --with-static-standard-libraries.

2019-08-09  Nick Clifton  <nickc@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2019-08-08  Martin Liska  <mliska@suse.cz>

	PR bootstrap/91352
	* lrealpath.c (is_valid_fd): New function.

	2019-07-24  Martin Liska  <mliska@suse.cz>

	PR lto/91228
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Find first '\0' starting from gnu_lto + 1.

	2019-07-12  Ren Kimura  <rkx1209dev@gmail.com>

	* simple-object-elf.c (simple_object_elf_match): Check zero value shstrndx.
	This fixes a Bug 90924.

	2019-07-22  Martin Liska  <mliska@suse.cz>

	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Do not search for gnu_lto_v1, but search for first '\0'.

	2019-07-18  Eduard-Mihai Burtescu  <eddyb@lyken.rs>

	* cplus-dem.c: Include rust-demangle.h.
	* rust-demangle.c: Include rust-demangle.h.
	* rust-demangle.h: New file.

	2019-05-31  Michael Forney  <mforney@mforney.org>

	* cp-demangle.c: Don't define CP_DYNAMIC_ARRAYS if __STDC_NO_VLA__
	is non-zero.

	2019-04-30  Ben L  <bobsayshilol@live.co.uk>

	* d-demangle.c (dlang_parse_assocarray): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_tuple): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_structlit): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_arrayliteral): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_integer): Fix stack underflow.
	* testsuite/d-demangle-expected: Add testcase.

	* cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.
	* testsuite/demangle-expected: Add testcase.

	* cp-demangle.c (d_encoding): Guard against NULL return values from
	d_right (dc).
	* testsuite/demangle-expected: Add testcase.

	2019-04-29  Ben L  <bobsayshilol@live.co.uk>

	* cp-demangle.c (d_expression_1): Don't peek ahead unless the current
	char is valid.
	* testsuite/demangle-expected: Add testcase.

	2019-04-10  Nick Clifton  <nickc@redhat.com>

	PR 89394
	* cp-demangle.c (cplus_demangle_fill_name): Reject negative
	lengths.
	(d_count_templates_scopes): Replace num_templates and num_scopes
	parameters with a struct d_print_info pointer parameter.  Adjust
	body of the function accordingly.  Add recursion counter and check
	that the recursion limit is not reached.
	(d_print_init): Pass dpi parameter to d_count_templates_scopes.
	Reset recursion counter afterwards, unless the recursion limit was
	reached.

2019-07-13  Joel Brobecker  <brobecker@adacore.com>

	* src-release (getver): If $tool/gdbsupport/create-version.sh
	exists, use that to determine the version number.

2019-06-21  Andreas Schwab  <schwab@linux-m68k.org>

	* src-release.sh (GDB_SUPPORT_DIRS): Add gnulib.

2019-06-14  Tom Tromey  <tom@tromey.com>

	* MAINTAINERS: Add gnulib.
	* gnulib: New directory, move from gdb/gnulib.
	* configure.ac (host_libs): Add gnulib.
	* configure: Rebuild.
	* Makefile.def (host_modules, dependencies): Add gnulib.
	* Makefile.in: Rebuild.

2019-06-03  Nick Clifton  <nickc@redhat.com>

	Revert:
	2019-05-29  Nick Clifton  <nickc@redhat.com>

	* configure.ac (noconfigdirs): Add libctf if the target does not use
	the ELF file format.
	* configure: Regenerate.

2019-05-29  Nick Clifton  <nickc@redhat.com>

	* src-release.sh (do_proto_toplev): Add libctf to list of
	directories that can be disabled.

2019-05-29  Nick Clifton  <nickc@redhat.com>

	* configure.ac (noconfigdirs): Add libctf if the target does not use
	the ELF file format.
	* configure: Regenerate.

2019-05-28  Nick Alcock  <nick.alcock@oracle.com>

	* Makefile.def (dependencies): configure-libctf depends on all-bfd
	and all its deps.
	* Makefile.in: Regenerated.

2019-05-28  Nick Alcock  <nick.alcock@oracle.com>

	* MAINTAINERS: Add libctf.

2019-05-28  Nick Alcock  <nick.alcock@oracle.com>

	* Makefile.def (host_modules): Add libctf.
	* Makefile.def (dependencies): Likewise.
	libctf depends on zlib, libiberty, and bfd.
	* Makefile.in: Regenerated.
	* configure.ac (host_libs): Add libctf.
	* configure: Regenerated.

2019-05-23  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* config.guess: Synchronize with config project master sources.
	* config.sub: Likewise.
	* readline/support/config.guess: Likewise.
	* readline/support/config.sub: Likewise.

2019-04-10  Nick Clifton  <nickc@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2019-04-10  Nick Clifton  <nickc@redhat.com>

	PR 89394
	* cp-demangle.c (cplus_demangle_fill_name): Reject negative
	lengths.
	(d_count_templates_scopes): Replace num_templates and num_scopes
	parameters with a struct d_print_info pointer parameter.  Adjust
	body of the function accordingly.  Add recursion counter and check
	that the recursion limit is not reached.
	(d_print_init): Pass dpi parameter to d_count_templates_scopes.
	Reset recursion counter afterwards, unless the recursion limit was
	reached.

2018-06-24  Nick Clifton  <nickc@redhat.com>

	2.32 branch created.

2019-01-14  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	Merge from GCC:
	PR target/88535
	* config.guess: Import upstream version 2019-01-03.
	* config.sub: Import upstream version 2019-01-01.

2019-01-10  Nick Clifton  <nickc@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2019-01-09  Sandra Loosemore  <sandra@codesourcery.com>

	PR other/16615

	* cp-demangle.c: Mechanically replace "can not" with "cannot".
	* floatformat.c: Likewise.
	* strerror.c: Likewise.

	2018-12-22  Jason Merrill  <jason@redhat.com>

	Remove support for demangling GCC 2.x era mangling schemes.
	* cplus-dem.c: Remove cplus_mangle_opname, cplus_demangle_opname,
	internal_cplus_demangle, and all subroutines.
	(libiberty_demanglers): Remove entries for ancient GNU (pre-3.0),
	Lucid, ARM, HP, and EDG demangling styles.
	(cplus_demangle): Remove 'work' variable.  Don't call
	internal_cplus_demangle.

2019-01-03  илн алазов  <dilyan.palauzov@aegee.org>

	* configure.ac: Don't configure readline if --with-system-readline is
	used.
	* configure: Re-generate.

2018-10-31  Joseph Myers  <joseph@codesourcery.com>

	Merge from GCC:
	PR bootstrap/82856
	* multilib.am: New file.  From automake.

2018-09-12  Sergio Durigan Junior  <sergiodj@redhat.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add "contrib".

2018-07-16  Nick Clifton  <nickc@redhat.com>

@ -20,6 +338,18 @@
	* config.guess: Sync with upstream version 2018-06-26.
	* config.sub: Sync with upstream version 2018-07-02.

2018-06-29  Alexandre Oliva <oliva@adacore.com>

	* configure.ac: Introduce support for @unless/@endunless.
	* Makefile.tpl (dep-kind): Rewrite with cond; return
	postbootstrap in some cases.
	(make-postboot-dep, postboot-targets): New.
	(dependencies): Do not output postbootstrap dependencies at
	first.  Output non-target ones changed for configure to depend
	on stage_last @if gcc-bootstrap, and the original deps @unless
	gcc-bootstrap.
	* configure.in, Makefile.in: Rebuilt.

2018-06-24  Nick Clifton  <nickc@redhat.com>

	* configure: Regenerate.

/* C-SKY disassembler.
   Copyright (C) 1988-2020 Free Software Foundation, Inc.
   Contributed by C-SKY Microsystems and Mentor Graphics.

   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 3, or (at your option)
   any later version.

   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., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#include "sysdep.h"
#include "config.h"
#include <stdio.h>
#include "bfd_stdint.h"
#include "disassemble.h"
#include "elf-bfd.h"
#include "opcode/csky.h"
#include "libiberty.h"
#include "csky-opc.h"
#include "floatformat.h"

#define CSKY_INST_TYPE unsigned long
#define HAS_SUB_OPERAND (unsigned int)0xffffffff

enum sym_type
{
  CUR_TEXT,
  CUR_DATA
};

struct csky_dis_info
{
  /* Mem to disassemble.  */
  bfd_vma mem;
  /* Disassemble info.  */
  disassemble_info *info;
  /* Opcode information.  */
  struct csky_opcode_info const *opinfo;
  /* The value of operand to show.  */
  int value;
  /* Whether to look up/print a symbol name.  */
  int need_output_symbol;
} dis_info;


enum sym_type last_type;
int last_map_sym = 1;
bfd_vma last_map_addr = 0;

/* Only for objdump tool.  */
#define INIT_MACH_FLAG  0xffffffff
#define BINARY_MACH_FLAG 0x0

static unsigned int mach_flag = INIT_MACH_FLAG;

static void
print_insn_data (bfd_vma pc ATTRIBUTE_UNUSED,
		 struct disassemble_info *info,
		 long given)
{
  switch (info->bytes_per_chunk)
    {
    case 1:
      info->fprintf_func (info->stream, ".byte\t0x%02lx", given);
      break;
    case 2:
      info->fprintf_func (info->stream, ".short\t0x%04lx", given);
      break;
    case 4:
      info->fprintf_func (info->stream, ".long\t0x%08lx", given);
      break;
    default:
      abort ();
    }
}

static int
get_sym_code_type (struct disassemble_info *info,
		   int n,
		   enum sym_type *sym_type)
{
  const char *name;
  name = bfd_asymbol_name (info->symtab[n]);
  if (name[0] == '$' && (name[1] == 't' || name[1] == 'd')
      && (name[2] == 0 || name[2] == '.'))
    {
      *sym_type = ((name[1] == 't') ? CUR_TEXT : CUR_DATA);
      return TRUE;
    }
  return FALSE;
}

static int
csky_get_operand_mask (struct operand const *oprnd)
{
  int mask = 0;
  if (oprnd->mask == HAS_SUB_OPERAND)
    {
      struct soperand *sop = (struct soperand *)oprnd;
      mask |= csky_get_operand_mask (&sop->subs[0]);
      mask |= csky_get_operand_mask (&sop->subs[1]);
      return mask;
    }
  return oprnd->mask;
}

static int
csky_get_mask (struct csky_opcode_info const *pinfo)
{
  int i = 0;
  int mask = 0;
  /* List type.  */
  if (pinfo->operand_num == -1)
    mask |= csky_get_operand_mask (&pinfo->oprnd.oprnds[i]);
  else
    for (; i < pinfo->operand_num; i++)
      mask |= csky_get_operand_mask (&pinfo->oprnd.oprnds[i]);

  mask = ~mask;
  return mask;
}

static unsigned int
csky_chars_to_number (unsigned char * buf, int n)
{
  int i;
  unsigned int val = 0;

  if (dis_info.info->endian == BFD_ENDIAN_BIG)
    for (i = 0; i < n; i++)
      val = val << 8 | buf[i];
  else
    for (i = n - 1; i >= 0; i--)
      val = val << 8 | buf[i];
  return val;
}

static struct csky_opcode const *g_opcodeP;

static struct csky_opcode const *
csky_find_inst_info (struct csky_opcode_info const **pinfo,
		     CSKY_INST_TYPE inst, int length)
{
  int i;
  unsigned int mask;
  struct csky_opcode const *p;

  p = g_opcodeP;
  while (p->mnemonic)
    {
      /* Get the opcode mask.  */
      for (i = 0; i < OP_TABLE_NUM; i++)
	if (length == 2)
	  {
	    mask =  csky_get_mask (&p->op16[i]);
	    if (mask != 0 && (inst & mask) == p->op16[i].opcode)
	      {
		*pinfo = &p->op16[i];
		g_opcodeP = p;
		return p;
	      }
	  }
	else if (length == 4)
	  {
	    mask =  csky_get_mask (&p->op32[i]);
	    if (mask != 0
		&& ((unsigned long)(inst & mask)
		    == (unsigned long)p->op32[i].opcode))
	      {
		*pinfo = &p->op32[i];
		g_opcodeP = p;
		return p;
	      }
	  }
      p++;
    }

  return NULL;
}

static bfd_boolean
is_extern_symbol (struct disassemble_info *info, int addr)
{
  unsigned int rel_count = 0;

  if (info->section == NULL)
    return 0;
  if ((info->section->flags & SEC_RELOC) != 0)	/* Fit .o file.  */
    {
      struct reloc_cache_entry *pt = info->section->relocation;
      for (; rel_count < info->section->reloc_count; rel_count++, pt++)
	if ((long unsigned int)addr == pt->address)
	  return TRUE;
      return FALSE;
    }
  return FALSE;
}


/* Suppress printing of mapping symbols emitted by the assembler to mark
   the beginning of code and data sequences.  */

bfd_boolean
csky_symbol_is_valid (asymbol *sym,
		      struct disassemble_info *info ATTRIBUTE_UNUSED)
{
  const char *name;

  if (sym == NULL)
    return FALSE;
  name = bfd_asymbol_name (sym);
  return name && *name != '$';
}

disassembler_ftype
csky_get_disassembler (bfd *abfd)
{
  if (abfd != NULL)
    mach_flag = elf_elfheader (abfd)->e_flags;
  return print_insn_csky;
}

static int
csky_output_operand (char *str, struct operand const *oprnd,
		     CSKY_INST_TYPE inst, int reloc ATTRIBUTE_UNUSED)
{
  int ret = 0;;
  int bit = 0;
  int result = 0;
  bfd_vma value;
  int mask = oprnd->mask;
  int max = 0;
  char buf[128];

  /* Get operand value with mask.  */
  value = inst & mask;
  for (; mask; mask >>= 1, value >>=1)
    if (mask & 0x1)
      {
	result |= ((value & 0x1) << bit);
	max |= (1 << bit);
	bit++;
      }
  value = result;

  /* Here is general instructions that have no reloc.  */
  switch (oprnd->type)
    {
    case OPRND_TYPE_CTRLREG:
      if (IS_CSKY_V1 (mach_flag))
	{
	  /* In V1 only cr0-cr12 have alias names.  */
	  if (value <= 12)
	    strcat (str, csky_ctrl_regs[value].name);
	  /* Others using crn(n > 12).  */
	  else if (value <= 30)
	    {
	      sprintf (buf, "cr%d", (int)value);
	      strcat (str, buf);
	    }
	  else
	    return -1;
	}
      else
	{
	  int sel;
	  int crx;
	  sel = value >> 5;
	  crx = value & 0x1f;
	  sprintf (buf, "cr<%d, %d>", crx, sel);
	  strcat (str, buf);
	}
      break;
    case OPRND_TYPE_DUMMY_REG:
      mask = dis_info.opinfo->oprnd.oprnds[0].mask;
      value = inst & mask;
      for (; mask; mask >>= 1, value >>=1)
	if (mask & 0x1)
	  {
	    result |= ((value & 0x1) << bit);
	    bit++;
	  }
      value = result;
      strcat (str, csky_general_reg[value]);
      break;
    case OPRND_TYPE_GREG0_7:
    case OPRND_TYPE_GREG0_15:
    case OPRND_TYPE_GREG16_31:
    case OPRND_TYPE_REGnsplr:
    case OPRND_TYPE_AREG:
      if (IS_CSKY_V2 (mach_flag) && value == 14)
	strcat (str, "sp");
      else
	strcat (str, csky_general_reg[value]);
      dis_info.value = value;
      break;
    case OPRND_TYPE_CPREG:
      strcat (str, csky_cp_reg[value]);
      break;
    case OPRND_TYPE_FREG:
      sprintf (buf, "fr%d", (int)value);
      strcat (str, buf);
      break;
    case OPRND_TYPE_VREG:
      sprintf (buf, "vr%d", (int)value);
      strcat (str, buf);
      break;
    case OPRND_TYPE_CPCREG:
      strcat (str, csky_cp_creg[value]);
      break;
    case OPRND_TYPE_CPIDX:
      strcat (str, csky_cp_idx[value]);
      break;
    case OPRND_TYPE_IMM2b_JMPIX:
      value = (value + 2) << 3;
      sprintf (buf, "%d", (int)value);
      strcat (str, buf);
      break;
    case OPRND_TYPE_IMM_LDST:
    case OPRND_TYPE_IMM_FLDST:
      value <<= oprnd->shift;
      sprintf (buf, "0x%x", (unsigned int)value);
      strcat (str, buf);
      break;
    case OPRND_TYPE_IMM7b_LS2:
    case OPRND_TYPE_IMM8b_LS2:
      sprintf (buf, "%d", (int)(value << 2));
      strcat (str, buf);
      ret = 0;
      break;
    case OPRND_TYPE_IMM5b_BMASKI:
      if ((value != 0) && (value > 31 || value < 8))
	{
	  ret = -1;
	  break;
	}
      sprintf (buf, "%d", (int)value);
      strcat (str, buf);
      ret = 0;
      break;
    case OPRND_TYPE_IMM5b_1_31:
      if (value > 31 || value < 1)
	{
	  ret = -1;
	  break;
	}
      sprintf (buf, "%d", (int)value);
      strcat (str, buf);
      ret = 0;
      break;
    case OPRND_TYPE_IMM5b_7_31:
      if (value > 31 || value < 7)
	{
	  ret = -1;
	  break;
	}
      sprintf (buf, "%d", (int)value);
      strcat (str, buf);
      ret = 0;
      break;
    case OPRND_TYPE_MSB2SIZE:
    case OPRND_TYPE_LSB2SIZE:
      {
	static int size;
	if (oprnd->type == OPRND_TYPE_MSB2SIZE)
	  size = value;
	else
	  {
	    str[strlen (str) - 2] = '\0';
	    sprintf (buf, "%d, %d", (int)(size + value), (int)value);
	    strcat (str, buf);
	  }
	break;
      }
    case OPRND_TYPE_IMM1b:
    case OPRND_TYPE_IMM2b:
    case OPRND_TYPE_IMM4b:
    case OPRND_TYPE_IMM5b:
    case OPRND_TYPE_IMM7b:
    case OPRND_TYPE_IMM8b:
    case OPRND_TYPE_IMM12b:
    case OPRND_TYPE_IMM15b:
    case OPRND_TYPE_IMM16b:
    case OPRND_TYPE_IMM16b_MOVIH:
    case OPRND_TYPE_IMM16b_ORI:
      sprintf (buf, "%d", (int)value);
      strcat (str, buf);
      ret = 0;
      break;
    case OPRND_TYPE_OFF8b:
    case OPRND_TYPE_OFF16b:
      {
	unsigned char ibytes[4];
	int shift = oprnd->shift;
	int status;
	unsigned int mem_val;

	dis_info.info->stop_vma = 0;

	value = ((dis_info.mem + (value << shift)
		  + ((IS_CSKY_V1 (mach_flag)) ? 2 : 0))
		 & 0xfffffffc);
	status = dis_info.info->read_memory_func (value, ibytes, 4,
						  dis_info.info);
	if (status != 0)
	  {
	    dis_info.info->memory_error_func (status, dis_info.mem,
					      dis_info.info);
	    return -1;
	  }
	mem_val = csky_chars_to_number (ibytes, 4);
	/* Remove [] around literal value to match ABI syntax.  */
	sprintf (buf, "0x%X", mem_val);
	strcat (str, buf);
	/* For jmpi/jsri, we'll try to get a symbol for the target.  */
	if (dis_info.info->print_address_func && mem_val != 0)
	  {
	    dis_info.value = mem_val;
	    dis_info.need_output_symbol = 1;
	  }
	else
	  {
	    sprintf (buf, "\t// from address pool at 0x%x",
		     (unsigned int)value);
	    strcat (str, buf);
	  }
	break;
      }
    case OPRND_TYPE_BLOOP_OFF4b:
    case OPRND_TYPE_BLOOP_OFF12b:
    case OPRND_TYPE_OFF11b:
    case OPRND_TYPE_OFF16b_LSL1:
    case OPRND_TYPE_IMM_OFF18b:
    case OPRND_TYPE_OFF26b:
      {
	int shift = oprnd->shift;
	if (value & ((max >> 1) + 1))
	  value |= ~max;
	if (is_extern_symbol (dis_info.info, dis_info.mem))
	  value = 0;
	else if (IS_CSKY_V1 (mach_flag))
	  value = dis_info.mem + 2 + (value << shift);
	else
	  value = dis_info.mem + (value << shift);
	dis_info.need_output_symbol = 1;
	dis_info.value= value;
	sprintf (buf, "0x%x", (unsigned int)value);
	strcat (str, buf);
	break;
      }
    case OPRND_TYPE_CONSTANT:
    case OPRND_TYPE_FCONSTANT:
      {
	int shift = oprnd->shift;
	char ibytes[8];
	int status;
	bfd_vma addr;
	int nbytes;

	dis_info.info->stop_vma = 0;
	value <<= shift;

	if (IS_CSKY_V1 (mach_flag))
	  addr = (dis_info.mem + 2 + value) & 0xfffffffc;
	else
	  addr = (dis_info.mem + value) & 0xfffffffc;

	if (oprnd->type == OPRND_TYPE_FCONSTANT
	    && dis_info.opinfo->opcode != CSKYV2_INST_FLRW)
	  nbytes = 8;
	else
	  nbytes = 4;

	status = dis_info.info->read_memory_func (addr, (bfd_byte *)ibytes,
						  nbytes, dis_info.info);
	if (status != 0)
	  /* Address out of bounds.  -> lrw rx, [pc, 0ffset]. */
	  sprintf (buf, "[pc, %d]\t// from address pool at %x", (int)value,
		   (unsigned int)addr);
	else
	  {
	    dis_info.value = addr;
	    value = csky_chars_to_number ((unsigned char *)ibytes, 4);
	  }

	if (oprnd->type == OPRND_TYPE_FCONSTANT)
	  {
	    double f;

	    if (dis_info.opinfo->opcode == CSKYV2_INST_FLRW)
	      /* flrws.  */
	      floatformat_to_double ((dis_info.info->endian == BFD_ENDIAN_BIG
				      ? &floatformat_ieee_single_big
				      : &floatformat_ieee_single_little),
				     ibytes, &f);
	    else
	      floatformat_to_double ((dis_info.info->endian == BFD_ENDIAN_BIG
				      ? &floatformat_ieee_double_big
				      : &floatformat_ieee_double_little),
				     ibytes, &f);
	    sprintf (buf, "%f", f);
	  }
	else
	  {
	    dis_info.need_output_symbol = 1;
	    sprintf (buf, "0x%x", (unsigned int)value);
	  }

	strcat (str, buf);
	break;
      }
    case OPRND_TYPE_ELRW_CONSTANT:
      {
	int shift = oprnd->shift;
	char ibytes[4];
	int status;
	bfd_vma addr;
	dis_info.info->stop_vma = 0;

	value = 0x80 + ((~value) & 0x7f);

	value = value << shift;
	addr = (dis_info.mem + value) & 0xfffffffc;

	status = dis_info.info->read_memory_func (addr, (bfd_byte *)ibytes,
						  4, dis_info.info);
	if (status != 0)
	  /* Address out of bounds.  -> lrw rx, [pc, 0ffset]. */
	  sprintf (buf, "[pc, %d]\t// from address pool at %x", (int) value,
		   (unsigned int)addr);
	else
	  {
	    dis_info.value = addr;
	    value = csky_chars_to_number ((unsigned char *)ibytes, 4);
	    dis_info.need_output_symbol = 1;
	    sprintf (buf, "0x%x", (unsigned int)value);
	  }

	strcat (str, buf);
	break;
      }
    case OPRND_TYPE_SFLOAT:
    case OPRND_TYPE_DFLOAT:
      {
	/* This is for fmovis/fmovid, which have an internal 13-bit
	   encoding that they convert to single/double precision
	   (respectively).  We'll convert the 13-bit encoding to an IEEE
	   double and then to host double format to print it.
	   Sign bit: bit 20.
	   4-bit exponent: bits 19:16, biased by 11.
	   8-bit mantissa: split between 24:21 and 7:4.  */
	uint64_t imm4;
	uint64_t imm8;
	uint64_t dbnum;
	unsigned char valbytes[8];
	double fvalue;

	imm4 = ((inst >> 16) & 0xf);
	imm4 = (uint64_t)(1023 - (imm4 - 11)) << 52;

	imm8 = (uint64_t)((inst >> 4) & 0xf) << 44;
	imm8 |= (uint64_t)((inst >> 21) & 0xf) << 48;

	dbnum = (uint64_t)((inst >> 20) & 1) << 63;
	dbnum |= imm4 | imm8;

	/* Do this a byte at a time so we don't have to
	   worry about the host's endianness.  */
	valbytes[0] = dbnum & 0xff;
	valbytes[1] = (dbnum >> 8) & 0xff;
	valbytes[2] = (dbnum >> 16) & 0xff;
	valbytes[3] = (dbnum >> 24) & 0xff;
	valbytes[4] = (dbnum >> 32) & 0xff;
	valbytes[5] = (dbnum >> 40) & 0xff;
	valbytes[6] = (dbnum >> 48) & 0xff;
	valbytes[7] = (dbnum >> 56) & 0xff;

	floatformat_to_double (&floatformat_ieee_double_little, valbytes,
			       &fvalue);

	sprintf (buf, "%f", fvalue);
	strcat (str, buf);
	break;
      }
    case OPRND_TYPE_LABEL_WITH_BRACKET:
      sprintf (buf, "[0x%x]", (unsigned int)value);
      strcat (str, buf);
      strcat (str, "\t// the offset is based on .data");
      break;
    case OPRND_TYPE_OIMM3b:
    case OPRND_TYPE_OIMM4b:
    case OPRND_TYPE_OIMM5b:
    case OPRND_TYPE_OIMM5b_IDLY:
    case OPRND_TYPE_OIMM8b:
    case OPRND_TYPE_OIMM12b:
    case OPRND_TYPE_OIMM16b:
    case OPRND_TYPE_OIMM18b:
      value += 1;
      sprintf (buf, "%d", (int)value);
      strcat (str, buf);
      break;
    case OPRND_TYPE_OIMM5b_BMASKI:
      if (value > 32 || value < 16)
	{
	  ret = -1;
	  break;
	}
      sprintf (buf, "%d", (int)(value + 1));
      strcat (str, buf);
      ret = 0;
      break;
    case OPRND_TYPE_FREGLIST_DASH:
      if (IS_CSKY_V2 (mach_flag))
	{
	  int vrx = value & 0xf;
	  int vry = vrx + (value >> 4);
	  sprintf (buf, "fr%d-fr%d", vrx, vry);
	  strcat (str, buf);
	}
      break;
    case OPRND_TYPE_REGLIST_DASH:
      if (IS_CSKY_V1 (mach_flag))
	{
	  strcat (str, csky_general_reg[value]);
	  strcat (str, "-r15");
	}
      else
	{
	  strcat (str, csky_general_reg[value >> 5]);
	  strcat (str, "-");
	  strcat (str, csky_general_reg[(value & 0x1f) + (value >> 5)]);
	}
      break;
    case OPRND_TYPE_PSR_BITS_LIST:
      {
	struct psrbit const *bits;
	int first_oprnd = TRUE;
	int i = 0;
	if (IS_CSKY_V1 (mach_flag))
	  {
	    if (value == 0)
	      {
		strcat (str, "af");
		break;
	      }
	    bits = cskyv1_psr_bits;
	  }
	else
	  bits = cskyv2_psr_bits;
	while (value != 0 && bits[i].name != NULL)
	    {
	      if (value & bits[i].value)
		{
		  if (!first_oprnd)
		    strcat (str, ", ");
		  strcat (str, bits[i].name);
		  value &= ~bits[i].value;
		  first_oprnd = FALSE;
		}
	      i++;
	    }
	break;
      }
    case OPRND_TYPE_REGbsp:
      if (IS_CSKY_V1 (mach_flag))
	strcat (str, "(sp)");
      else
	strcat (str, "(sp)");
      break;
    case OPRND_TYPE_REGsp:
      if (IS_CSKY_V1 (mach_flag))
	strcat (str, "sp");
      else
	strcat (str, "sp");
      break;
    case OPRND_TYPE_REGnr4_r7:
    case OPRND_TYPE_AREG_WITH_BRACKET:
      if (IS_CSKY_V1 (mach_flag) && (value < 4 || value > 7))
	{
	  strcat (str, "(");
	  strcat (str, csky_general_reg[value]);
	  strcat (str, ")");
	}
      else
	{
	  strcat (str, "(");
	  strcat (str, csky_general_reg[value]);
	  strcat (str, ")");
	}
      break;
    case OPRND_TYPE_AREG_WITH_LSHIFT:
      strcat (str, csky_general_reg[value >> 5]);
      strcat (str, " << ");
      if ((value & 0x1f) == 0x1)
	strcat (str, "0");
      else if ((value & 0x1f) == 0x2)
	strcat (str, "1");
      else if ((value & 0x1f) == 0x4)
	strcat (str, "2");
      else if ((value & 0x1f) == 0x8)
	strcat (str, "3");
      break;
    case OPRND_TYPE_AREG_WITH_LSHIFT_FPU:
      strcat (str, csky_general_reg[value >> 2]);
      strcat (str, " << ");
      if ((value & 0x3) == 0x0)
	strcat (str, "0");
      else if ((value & 0x3) == 0x1)
	strcat (str, "1");
      else if ((value & 0x3) == 0x2)
	strcat (str, "2");
      else if ((value & 0x3) == 0x3)
	strcat (str, "3");
      break;
    case OPRND_TYPE_FREG_WITH_INDEX:
      {
	unsigned freg_val = value & 0xf;
	unsigned index_val = (value >> 4) & 0xf;
	sprintf (buf, "vr%d[%d]", freg_val, index_val);
	strcat(str, buf);
	break;
      }
    case OPRND_TYPE_REGr4_r7:
      if (IS_CSKY_V1 (mach_flag))
	strcat (str, "r4-r7");
      break;
    case OPRND_TYPE_CONST1:
      strcat (str, "1");
      break;
    case OPRND_TYPE_REG_r1a:
    case OPRND_TYPE_REG_r1b:
      strcat (str, "r1");
      break;
    case OPRND_TYPE_REG_r28:
      strcat (str, "r28");
      break;
    case OPRND_TYPE_REGLIST_DASH_COMMA:
      /* 16-bit reglist.  */
      if (value & 0xf)
	{
	  strcat (str, "r4");
	  if ((value & 0xf) > 1)
	    {
	      strcat (str, "-");
	      strcat (str, csky_general_reg[(value & 0xf) + 3]);
	    }
	  if (value & ~0xf)
	    strcat (str, ", ");
	}
      if (value & 0x10)
	{
	  /* r15.  */
	  strcat (str, "r15");
	  if (value & ~0x1f)
	    strcat (str, ", ");
	}
      if (dis_info.opinfo->oprnd.oprnds[0].mask != OPRND_MASK_0_4)
	{
	  /* 32bits reglist.  */
	  value >>= 5;
	  if (value & 0x3)
	    {
	      strcat (str, "r16");
	      if ((value & 0x7) > 1)
		{
		  strcat (str, "-");
		  strcat (str, csky_general_reg[(value & 0xf) + 15]);
		}
	      if (value & ~0x7)
		strcat (str, ", ");
	      }
	  if (value & 0x8)
	    /* r15.  */
	    strcat (str, "r28");
	}
      break;
    case OPRND_TYPE_UNCOND10b:
    case OPRND_TYPE_UNCOND16b:
    case OPRND_TYPE_COND10b:
    case OPRND_TYPE_COND16b:
      {
	int shift = oprnd->shift;

	if (value & ((max >> 1) + 1))
	  value |= ~max;
	if (is_extern_symbol (dis_info.info, dis_info.mem))
	  value = 0;
	else
	  value = dis_info.mem + (value << shift);
	sprintf (buf, "0x%x", (unsigned int)value);
	strcat (str, buf);
	dis_info.need_output_symbol = 1;
	dis_info.value = value;
      }
      break;

    default:
      ret = -1;
      break;
    }
  return ret;
}

static int
csky_print_operand (char *str, struct operand const *oprnd,
		    CSKY_INST_TYPE inst, int reloc)
{
  int ret = -1;
  char *lc = "";
  char *rc = "";
  if (oprnd->mask == HAS_SUB_OPERAND)
    {
      struct soperand *sop = (struct soperand *)oprnd;
      if (oprnd->type == OPRND_TYPE_BRACKET)
	{
	  lc = "(";
	  rc = ")";
	}
      else if (oprnd->type == OPRND_TYPE_ABRACKET)
	{
	  lc = "<";
	  rc = ">";
	}
      strcat (str, lc);
      ret = csky_print_operand (str, &sop->subs[0], inst, reloc);
      if (ret)
	return ret;
      strcat (str, ", ");
      ret = csky_print_operand (str, &sop->subs[1], inst, reloc);
      strcat (str, rc);
      return ret;
    }
  return csky_output_operand (str, oprnd, inst, reloc);
}

static int
csky_print_operands (char *str, struct csky_opcode_info const *pinfo,
		     struct disassemble_info *info, CSKY_INST_TYPE inst,
		     int reloc)
{
  int i = 0;
  int ret = 0;
  if (pinfo->operand_num)
    strcat (str, "      \t");
  if (pinfo->operand_num == -1)
    {
      ret = csky_print_operand (str, &pinfo->oprnd.oprnds[i], inst, reloc);
      if (ret)
	return ret;
    }
  else
    for (; i < pinfo->operand_num; i++)
      {
	if (i != 0)
	  strcat (str, ", ");
	ret = csky_print_operand (str, &pinfo->oprnd.oprnds[i], inst, reloc);
	if (ret)
	  return ret;
      }
  info->fprintf_func (info->stream, "%s", str);
  if (dis_info.need_output_symbol)
    {
      info->fprintf_func (info->stream, "\t// ");
      info->print_address_func (dis_info.value, dis_info.info);
    }
  return 0;
}

static void
number_to_chars_littleendian (char *buf, CSKY_INST_TYPE val, int n)
{
  if (n <= 0)
    abort ();
  while (n--)
    {
      *buf++ = val & 0xff;
      val >>= 8;
    }
}

#define CSKY_READ_DATA()                                        \
{                                                               \
  status = info->read_memory_func (memaddr, buf, 2, info);      \
  if (status)                                                   \
    {                                                           \
      info->memory_error_func (status, memaddr, info);          \
      return -1;                                                \
    }                                                           \
  if (info->endian == BFD_ENDIAN_BIG)                           \
    inst |= (buf[0] << 8) | buf[1];                             \
  else if (info->endian == BFD_ENDIAN_LITTLE)                   \
    inst |= (buf[1] << 8) | buf[0];                             \
  else                                                          \
    abort();                                                    \
  info->bytes_per_chunk += 2;                                   \
  memaddr += 2;                                                 \
}

int
print_insn_csky (bfd_vma memaddr, struct disassemble_info *info)
{
  unsigned char buf[4];
  CSKY_INST_TYPE inst = 0;
  int status;
  char str[256];
  long given;
  int is_data = FALSE;
  void (*printer) (bfd_vma, struct disassemble_info *, long);
  unsigned int  size = 4;

  memset (str, 0, sizeof (str));
  info->bytes_per_chunk = 0;
  info->bytes_per_chunk = 0;
  dis_info.mem = memaddr;
  dis_info.info = info;
  dis_info.need_output_symbol = 0;
  if (mach_flag != INIT_MACH_FLAG && mach_flag != BINARY_MACH_FLAG)
    info->mach = mach_flag;
  else if (mach_flag == INIT_MACH_FLAG)
    mach_flag = info->mach;

  if (mach_flag == BINARY_MACH_FLAG && info->endian == BFD_ENDIAN_UNKNOWN)
    info->endian = BFD_ENDIAN_LITTLE;

  /* First check the full symtab for a mapping symbol, even if there
     are no usable non-mapping symbols for this address.  */
  if (info->symtab_size != 0
      && bfd_asymbol_flavour (*info->symtab) == bfd_target_elf_flavour)
    {
      bfd_vma addr;
      int n;
      int last_sym = -1;
      enum sym_type type = CUR_TEXT;

      if (memaddr <= last_map_addr)
	last_map_sym = -1;
      /* Start scanning at the start of the function, or wherever
	 we finished last time.  */
      n = 0;
      if (n < last_map_sym)
	n = last_map_sym;

      /* Scan up to the location being disassembled.  */
      for (; n < info->symtab_size; n++)
	{
	  addr = bfd_asymbol_value (info->symtab[n]);
	  if (addr > memaddr)
	    break;
	  if ((info->section == NULL
	       || info->section == info->symtab[n]->section)
	      && get_sym_code_type (info, n, &type))
	    last_sym = n;
	}
      last_map_sym = last_sym;
      last_type = type;
      is_data = (last_type == CUR_DATA);
      if (is_data)
	{
	  size = 4 - ( memaddr & 3);
	  for (n = last_sym + 1; n < info->symtab_size; n++)
	    {
	      addr = bfd_asymbol_value (info->symtab[n]);
	      if (addr > memaddr)
		{
		  if (addr - memaddr < size)
		    size = addr - memaddr;
		  break;
		}
	    }
	  /* If the next symbol is after three bytes, we need to
	     print only part of the data, so that we can use either
	     .byte or .short.  */
	  if (size == 3)
	    size = (memaddr & 1) ? 1 : 2;
	}
    }
  info->bytes_per_line = 4;

  if (is_data)
    {
      int i;

      /* Size was already set above.  */
      info->bytes_per_chunk = size;
      printer = print_insn_data;

      status = info->read_memory_func (memaddr, (bfd_byte *) buf, size, info);
      given = 0;
      if (info->endian == BFD_ENDIAN_LITTLE)
	for (i = size - 1; i >= 0; i--)
	  given = buf[i] | (given << 8);
      else
	for (i = 0; i < (int) size; i++)
	  given = buf[i] | (given << 8);

      printer (memaddr, info, given);
      return info->bytes_per_chunk;
    }

  /* Handle instructions.  */
  CSKY_READ_DATA();
  if ((inst & 0xc000) == 0xc000 && IS_CSKY_V2 (mach_flag))
    {
      /* It's a 32-bit instruction.  */
      inst <<= 16;
      CSKY_READ_DATA();
      if (info->buffer && (info->endian == BFD_ENDIAN_LITTLE))
	{
	  char* src = (char *)(info->buffer
			       + ((memaddr - 4 - info->buffer_vma)
				  * info->octets_per_byte));
	  if (info->endian == BFD_ENDIAN_LITTLE)
	    number_to_chars_littleendian (src, inst, 4);
	}
    }

  if (IS_CSKY_V1 (mach_flag))
    g_opcodeP = csky_v1_opcodes;
  else
    g_opcodeP = csky_v2_opcodes;

  do
    {
      struct csky_opcode const *op;
      struct csky_opcode_info const *pinfo = NULL;
      int reloc;

      memset (str, 0, sizeof (str));
      op = csky_find_inst_info (&pinfo, inst, info->bytes_per_chunk);
      if (!op)
	{
	  if (IS_CSKY_V1 (mach_flag))
	    info->fprintf_func (info->stream, ".short: 0x%04x",
				(unsigned short)inst);
	  else
	    info->fprintf_func (info->stream, ".long: 0x%08x",
				(unsigned int)inst);
	  return info->bytes_per_chunk;
	}

      if (info->bytes_per_chunk == 2)
	reloc = op->reloc16;
      else
	reloc = op->reloc32;
      dis_info.opinfo = pinfo;
      strcat (str, op->mnemonic);

      if (csky_print_operands (str, pinfo, info, inst, reloc))
	g_opcodeP++;
      else
	break;
    } while (1);

  return info->bytes_per_chunk;
}