2000-03-27 16:39:14 +08:00
|
|
|
/* Disassemble AVR instructions.
|
2024-01-04 19:52:08 +08:00
|
|
|
Copyright (C) 1999-2024 Free Software Foundation, Inc.
|
2000-03-27 16:39:14 +08:00
|
|
|
|
|
|
|
Contributed by Denis Chertykov <denisc@overta.ru>
|
|
|
|
|
2007-07-05 17:49:03 +08:00
|
|
|
This file is part of libopcodes.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2005-07-01 19:16:33 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-05 17:49:03 +08:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2007-07-05 17:49:03 +08:00
|
|
|
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.
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2005-07-01 19:16:33 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2007-07-05 17:49:03 +08:00
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2000-04-14 12:16:58 +08:00
|
|
|
#include "sysdep.h"
|
2012-05-17 23:13:28 +08:00
|
|
|
#include <assert.h>
|
Move print_insn_XXX to an opcodes internal header
With the changes done in previous patches, print_insn_XXX functions
don't have to be external visible out of opcodes, because both gdb
and objdump select disassemblers through a single interface.
This patch moves these print_insn_XXX declarations from
include/dis-asm.h to opcodes/disassemble.h, which is a new header
added by this patch.
include:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* dis-asm.h: Move some function declarations to
opcodes/disassemble.h.
opcodes:
2017-05-24 Yao Qi <yao.qi@linaro.org>
* alpha-dis.c: Include disassemble.h, don't include
dis-asm.h.
* avr-dis.c, bfin-dis.c, cr16-dis.c: Likewise.
* crx-dis.c, d10v-dis.c, d30v-dis.c: Likewise.
* disassemble.c, dlx-dis.c, epiphany-dis.c: Likewise.
* fr30-dis.c, ft32-dis.c, h8300-dis.c, h8500-dis.c: Likewise.
* hppa-dis.c, i370-dis.c, i386-dis.c: Likewise.
* i860-dis.c, i960-dis.c, ip2k-dis.c: Likewise.
* iq2000-dis.c, lm32-dis.c, m10200-dis.c: Likewise.
* m10300-dis.c, m32r-dis.c, m68hc11-dis.c: Likewise.
* m68k-dis.c, m88k-dis.c, mcore-dis.c: Likewise.
* metag-dis.c, microblaze-dis.c, mmix-dis.c: Likewise.
* moxie-dis.c, msp430-dis.c, mt-dis.c:
* nds32-dis.c, nios2-dis.c, ns32k-dis.c: Likewise.
* or1k-dis.c, pdp11-dis.c, pj-dis.c: Likewise.
* ppc-dis.c, pru-dis.c, riscv-dis.c: Likewise.
* rl78-dis.c, s390-dis.c, score-dis.c: Likewise.
* sh-dis.c, sh64-dis.c, tic30-dis.c: Likewise.
* tic4x-dis.c, tic54x-dis.c, tic6x-dis.c: Likewise.
* tic80-dis.c, tilegx-dis.c, tilepro-dis.c: Likewise.
* v850-dis.c, vax-dis.c, visium-dis.c: Likewise.
* w65-dis.c, wasm32-dis.c, xc16x-dis.c: Likewise.
* xgate-dis.c, xstormy16-dis.c, xtensa-dis.c: Likewise.
* z80-dis.c, z8k-dis.c: Likewise.
* disassemble.h: New file.
2017-05-25 00:23:52 +08:00
|
|
|
#include "disassemble.h"
|
2000-03-27 16:39:14 +08:00
|
|
|
#include "opintl.h"
|
2002-11-19 00:54:08 +08:00
|
|
|
#include "libiberty.h"
|
2021-03-31 07:37:02 +08:00
|
|
|
#include <stdint.h>
|
* avr-dis.c (reg_fmul_d): New. Extract destination register from
FMUL instruction.
(reg_fmul_r): New. Extract source register from FMUL instruction.
(reg_muls_d): New. Extract destination register from MULS instruction.
(reg_muls_r): New. Extract source register from MULS instruction.
(reg_movw_d): New. Extract destination register from MOVW instruction.
(reg_movw_r): New. Extract source register from MOVW instruction.
(print_insn_avr): Handle MOVW, MULS, MULSU, FMUL, FMULS, FMULSU,
EICALL, EIJMP, LPM r,Z, ELPM r,Z, SPM, ESPM instructions.
2000-05-01 16:45:11 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
struct avr_opcodes_s
|
2000-03-27 16:39:14 +08:00
|
|
|
{
|
2000-06-08 01:45:44 +08:00
|
|
|
char *name;
|
|
|
|
char *constraints;
|
|
|
|
char *opcode;
|
2005-07-01 19:16:33 +08:00
|
|
|
int insn_size; /* In words. */
|
2000-06-08 01:45:44 +08:00
|
|
|
int isa;
|
|
|
|
unsigned int bin_opcode;
|
|
|
|
};
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
#define AVR_INSN(NAME, CONSTR, OPCODE, SIZE, ISA, BIN) \
|
2002-11-19 00:54:08 +08:00
|
|
|
{#NAME, CONSTR, OPCODE, SIZE, ISA, BIN},
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2002-11-19 00:54:08 +08:00
|
|
|
const struct avr_opcodes_s avr_opcodes[] =
|
2000-03-27 16:39:14 +08:00
|
|
|
{
|
2000-06-08 01:45:44 +08:00
|
|
|
#include "opcode/avr.h"
|
2002-11-19 00:54:08 +08:00
|
|
|
{NULL, NULL, NULL, 0, 0, 0}
|
2000-06-08 01:45:44 +08:00
|
|
|
};
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2007-02-16 18:24:48 +08:00
|
|
|
static const char * comment_start = "0x";
|
|
|
|
|
2000-08-06 22:12:36 +08:00
|
|
|
static int
|
2021-12-02 21:57:11 +08:00
|
|
|
avr_operand (unsigned int insn,
|
|
|
|
unsigned int insn2,
|
|
|
|
unsigned int pc,
|
|
|
|
int constraint,
|
|
|
|
char * opcode_str,
|
|
|
|
char * buf,
|
|
|
|
char * comment,
|
2022-07-04 18:25:42 +08:00
|
|
|
enum disassembler_style * style,
|
2021-12-02 21:57:11 +08:00
|
|
|
int regs,
|
|
|
|
int * sym,
|
|
|
|
bfd_vma * sym_addr,
|
|
|
|
disassemble_info * info)
|
2000-03-27 16:39:14 +08:00
|
|
|
{
|
2000-08-06 22:12:36 +08:00
|
|
|
int ok = 1;
|
2004-12-15 06:27:05 +08:00
|
|
|
*sym = 0;
|
2000-08-06 22:12:36 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
switch (constraint)
|
|
|
|
{
|
|
|
|
/* Any register operand. */
|
|
|
|
case 'r':
|
|
|
|
if (regs)
|
2005-07-01 19:16:33 +08:00
|
|
|
insn = (insn & 0xf) | ((insn & 0x0200) >> 5); /* Source register. */
|
2000-06-08 01:45:44 +08:00
|
|
|
else
|
2005-07-01 19:16:33 +08:00
|
|
|
insn = (insn & 0x01f0) >> 4; /* Destination register. */
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
sprintf (buf, "r%d", insn);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
if (regs)
|
|
|
|
sprintf (buf, "r%d", 16 + (insn & 0xf));
|
|
|
|
else
|
|
|
|
sprintf (buf, "r%d", 16 + ((insn & 0xf0) >> 4));
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'w':
|
|
|
|
sprintf (buf, "r%d", 24 + ((insn & 0x30) >> 3));
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'a':
|
|
|
|
if (regs)
|
|
|
|
sprintf (buf, "r%d", 16 + (insn & 7));
|
|
|
|
else
|
|
|
|
sprintf (buf, "r%d", 16 + ((insn >> 4) & 7));
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'v':
|
|
|
|
if (regs)
|
|
|
|
sprintf (buf, "r%d", (insn & 0xf) * 2);
|
|
|
|
else
|
|
|
|
sprintf (buf, "r%d", ((insn & 0xf0) >> 3));
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e':
|
2000-08-06 22:12:36 +08:00
|
|
|
{
|
|
|
|
char *xyz;
|
|
|
|
|
|
|
|
switch (insn & 0x100f)
|
|
|
|
{
|
|
|
|
case 0x0000: xyz = "Z"; break;
|
|
|
|
case 0x1001: xyz = "Z+"; break;
|
|
|
|
case 0x1002: xyz = "-Z"; break;
|
|
|
|
case 0x0008: xyz = "Y"; break;
|
|
|
|
case 0x1009: xyz = "Y+"; break;
|
|
|
|
case 0x100a: xyz = "-Y"; break;
|
|
|
|
case 0x100c: xyz = "X"; break;
|
|
|
|
case 0x100d: xyz = "X+"; break;
|
|
|
|
case 0x100e: xyz = "-X"; break;
|
|
|
|
default: xyz = "??"; ok = 0;
|
|
|
|
}
|
2008-11-06 20:03:24 +08:00
|
|
|
strcpy (buf, xyz);
|
2000-08-06 22:12:36 +08:00
|
|
|
|
|
|
|
if (AVR_UNDEF_P (insn))
|
|
|
|
sprintf (comment, _("undefined"));
|
|
|
|
}
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
*buf++ = 'Z';
|
2011-03-23 02:10:48 +08:00
|
|
|
|
|
|
|
/* Check for post-increment. */
|
|
|
|
char *s;
|
|
|
|
for (s = opcode_str; *s; ++s)
|
|
|
|
{
|
|
|
|
if (*s == '+')
|
|
|
|
{
|
2011-07-02 00:11:27 +08:00
|
|
|
if (insn & (1 << (15 - (s - opcode_str))))
|
|
|
|
*buf++ = '+';
|
2011-03-23 02:10:48 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
*buf = '\0';
|
2000-08-06 22:12:36 +08:00
|
|
|
if (AVR_UNDEF_P (insn))
|
|
|
|
sprintf (comment, _("undefined"));
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
{
|
2000-08-06 22:12:36 +08:00
|
|
|
unsigned int x;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
x = (insn & 7);
|
|
|
|
x |= (insn >> 7) & (3 << 3);
|
|
|
|
x |= (insn >> 8) & (1 << 5);
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
if (insn & 0x8)
|
|
|
|
*buf++ = 'Y';
|
|
|
|
else
|
|
|
|
*buf++ = 'Z';
|
|
|
|
sprintf (buf, "+%d", x);
|
|
|
|
sprintf (comment, "0x%02x", x);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_register;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'h':
|
2004-12-15 06:27:05 +08:00
|
|
|
*sym = 1;
|
|
|
|
*sym_addr = ((((insn & 1) | ((insn & 0x1f0) >> 3)) << 16) | insn2) * 2;
|
2007-02-03 06:54:50 +08:00
|
|
|
/* See PR binutils/2454. Ideally we would like to display the hex
|
2006-04-12 21:09:10 +08:00
|
|
|
value of the address only once, but this would mean recoding
|
|
|
|
objdump_print_address() which would affect many targets. */
|
2015-08-12 19:45:07 +08:00
|
|
|
sprintf (buf, "%#lx", (unsigned long) *sym_addr);
|
2008-11-06 20:03:24 +08:00
|
|
|
strcpy (comment, comment_start);
|
2021-12-02 21:57:11 +08:00
|
|
|
info->insn_info_valid = 1;
|
|
|
|
info->insn_type = dis_jsr;
|
|
|
|
info->target = *sym_addr;
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_address;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'L':
|
|
|
|
{
|
|
|
|
int rel_addr = (((insn & 0xfff) ^ 0x800) - 0x800) * 2;
|
|
|
|
sprintf (buf, ".%+-8d", rel_addr);
|
2004-12-15 06:27:05 +08:00
|
|
|
*sym = 1;
|
|
|
|
*sym_addr = pc + 2 + rel_addr;
|
2008-11-06 20:03:24 +08:00
|
|
|
strcpy (comment, comment_start);
|
2021-12-02 21:57:11 +08:00
|
|
|
info->insn_info_valid = 1;
|
|
|
|
info->insn_type = dis_branch;
|
|
|
|
info->target = *sym_addr;
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_address_offset;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
{
|
|
|
|
int rel_addr = ((((insn >> 3) & 0x7f) ^ 0x40) - 0x40) * 2;
|
2007-02-16 18:24:48 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
sprintf (buf, ".%+-8d", rel_addr);
|
2004-12-15 06:27:05 +08:00
|
|
|
*sym = 1;
|
|
|
|
*sym_addr = pc + 2 + rel_addr;
|
2008-11-06 20:03:24 +08:00
|
|
|
strcpy (comment, comment_start);
|
2021-12-02 21:57:11 +08:00
|
|
|
info->insn_info_valid = 1;
|
|
|
|
info->insn_type = dis_condbranch;
|
|
|
|
info->target = *sym_addr;
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_address_offset;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i':
|
2016-06-10 00:00:57 +08:00
|
|
|
{
|
|
|
|
unsigned int val = insn2 | 0x800000;
|
|
|
|
*sym = 1;
|
|
|
|
*sym_addr = val;
|
|
|
|
sprintf (buf, "0x%04X", insn2);
|
|
|
|
strcpy (comment, comment_start);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2016-06-10 00:00:57 +08:00
|
|
|
}
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2014-07-01 17:20:17 +08:00
|
|
|
|
|
|
|
case 'j':
|
|
|
|
{
|
|
|
|
unsigned int val = ((insn & 0xf) | ((insn & 0x600) >> 5)
|
|
|
|
| ((insn & 0x100) >> 2));
|
2019-10-09 20:48:06 +08:00
|
|
|
if ((insn & 0x100) == 0)
|
|
|
|
val |= 0x80;
|
2016-06-10 00:00:57 +08:00
|
|
|
*sym = 1;
|
|
|
|
*sym_addr = val | 0x800000;
|
2014-07-01 17:20:17 +08:00
|
|
|
sprintf (buf, "0x%02x", val);
|
2016-06-10 00:00:57 +08:00
|
|
|
strcpy (comment, comment_start);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2014-07-01 17:20:17 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'M':
|
|
|
|
sprintf (buf, "0x%02X", ((insn & 0xf00) >> 4) | (insn & 0xf));
|
|
|
|
sprintf (comment, "%d", ((insn & 0xf00) >> 4) | (insn & 0xf));
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
2000-08-06 22:12:36 +08:00
|
|
|
sprintf (buf, "??");
|
opcodes error messages
Another patch aimed at making binutils comply with the GNU coding
standard. The generated files require
https://sourceware.org/ml/cgen/2018-q1/msg00004.html
cpu/
* frv.opc: Include opintl.h.
(add_next_to_vliw): Use opcodes_error_handler to print error.
Standardize error message.
(fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise.
opcodes/
* sysdep.h (opcodes_error_handler): Define.
(_bfd_error_handler): Declare.
* Makefile.am: Remove stray #.
* opc2c.c (main): Remove bogus -l arg handling. Print "DO NOT
EDIT" comment.
* aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c,
* d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c,
* riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use
opcodes_error_handler to print errors. Standardize error messages.
* msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise,
and include opintl.h.
* nds32-asm.c: Likewise, and include sysdep.h and opintl.h.
* i386-gen.c: Standardize error messages.
* msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate.
* Makefile.in: Regenerate.
* epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c,
* epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c,
* fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c,
* frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c,
* iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c,
* lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c,
* m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c,
* m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c,
* mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c,
* mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c,
* or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c,
* xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c,
* xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.
2018-03-02 05:53:50 +08:00
|
|
|
/* xgettext:c-format */
|
|
|
|
opcodes_error_handler (_("internal disassembler error"));
|
2000-08-06 22:12:36 +08:00
|
|
|
ok = 0;
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'K':
|
2000-08-06 22:12:36 +08:00
|
|
|
{
|
|
|
|
unsigned int x;
|
|
|
|
|
|
|
|
x = (insn & 0xf) | ((insn >> 2) & 0x30);
|
|
|
|
sprintf (buf, "0x%02x", x);
|
|
|
|
sprintf (comment, "%d", x);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2000-08-06 22:12:36 +08:00
|
|
|
}
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 's':
|
|
|
|
sprintf (buf, "%d", insn & 7);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'S':
|
|
|
|
sprintf (buf, "%d", (insn >> 4) & 7);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2000-06-08 01:45:44 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case 'P':
|
|
|
|
{
|
|
|
|
unsigned int x;
|
2005-07-01 19:16:33 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
x = (insn & 0xf);
|
|
|
|
x |= (insn >> 5) & 0x30;
|
|
|
|
sprintf (buf, "0x%02x", x);
|
|
|
|
sprintf (comment, "%d", x);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_address;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
{
|
|
|
|
unsigned int x;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
x = (insn >> 3) & 0x1f;
|
|
|
|
sprintf (buf, "0x%02x", x);
|
|
|
|
sprintf (comment, "%d", x);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_address;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2011-03-23 02:10:48 +08:00
|
|
|
case 'E':
|
|
|
|
sprintf (buf, "%d", (insn >> 4) & 15);
|
2022-07-04 18:25:42 +08:00
|
|
|
*style = dis_style_immediate;
|
2011-03-23 02:10:48 +08:00
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
case '?':
|
|
|
|
*buf = '\0';
|
|
|
|
break;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
default:
|
2000-08-06 22:12:36 +08:00
|
|
|
sprintf (buf, "??");
|
opcodes error messages
Another patch aimed at making binutils comply with the GNU coding
standard. The generated files require
https://sourceware.org/ml/cgen/2018-q1/msg00004.html
cpu/
* frv.opc: Include opintl.h.
(add_next_to_vliw): Use opcodes_error_handler to print error.
Standardize error message.
(fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise.
opcodes/
* sysdep.h (opcodes_error_handler): Define.
(_bfd_error_handler): Declare.
* Makefile.am: Remove stray #.
* opc2c.c (main): Remove bogus -l arg handling. Print "DO NOT
EDIT" comment.
* aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c,
* d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c,
* riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use
opcodes_error_handler to print errors. Standardize error messages.
* msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise,
and include opintl.h.
* nds32-asm.c: Likewise, and include sysdep.h and opintl.h.
* i386-gen.c: Standardize error messages.
* msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate.
* Makefile.in: Regenerate.
* epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c,
* epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c,
* fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c,
* frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c,
* iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c,
* lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c,
* m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c,
* m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c,
* mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c,
* mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c,
* or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c,
* xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c,
* xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.
2018-03-02 05:53:50 +08:00
|
|
|
/* xgettext:c-format */
|
|
|
|
opcodes_error_handler (_("unknown constraint `%c'"), constraint);
|
2000-08-06 22:12:36 +08:00
|
|
|
ok = 0;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
2000-08-06 22:12:36 +08:00
|
|
|
|
|
|
|
return ok;
|
2000-03-27 16:39:14 +08:00
|
|
|
}
|
|
|
|
|
2016-12-29 23:47:40 +08:00
|
|
|
/* Read the opcode from ADDR. Return 0 in success and save opcode
|
|
|
|
in *INSN, otherwise, return -1. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
avrdis_opcode (bfd_vma addr, disassemble_info *info, uint16_t *insn)
|
2000-03-27 16:39:14 +08:00
|
|
|
{
|
|
|
|
bfd_byte buffer[2];
|
|
|
|
int status;
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
|
|
status = info->read_memory_func (addr, buffer, 2, info);
|
|
|
|
|
|
|
|
if (status == 0)
|
2016-12-29 23:47:40 +08:00
|
|
|
{
|
|
|
|
*insn = bfd_getl16 (buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-01 19:16:33 +08:00
|
|
|
|
|
|
|
info->memory_error_func (status, addr, info);
|
|
|
|
return -1;
|
2000-03-27 16:39:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-07-01 19:16:33 +08:00
|
|
|
print_insn_avr (bfd_vma addr, disassemble_info *info)
|
2000-03-27 16:39:14 +08:00
|
|
|
{
|
2016-12-29 23:47:40 +08:00
|
|
|
uint16_t insn, insn2;
|
2002-11-19 00:54:08 +08:00
|
|
|
const struct avr_opcodes_s *opcode;
|
|
|
|
static unsigned int *maskptr;
|
2000-03-27 16:39:14 +08:00
|
|
|
void *stream = info->stream;
|
2022-07-04 18:25:42 +08:00
|
|
|
fprintf_styled_ftype prin = info->fprintf_styled_func;
|
2002-11-19 00:54:08 +08:00
|
|
|
static unsigned int *avr_bin_masks;
|
2000-06-08 01:45:44 +08:00
|
|
|
static int initialized;
|
2000-03-27 16:39:14 +08:00
|
|
|
int cmd_len = 2;
|
2000-08-06 22:12:36 +08:00
|
|
|
int ok = 0;
|
|
|
|
char op1[20], op2[20], comment1[40], comment2[40];
|
2022-07-04 18:25:42 +08:00
|
|
|
enum disassembler_style style_op1, style_op2;
|
2004-12-15 06:27:05 +08:00
|
|
|
int sym_op1 = 0, sym_op2 = 0;
|
|
|
|
bfd_vma sym_addr1, sym_addr2;
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2021-12-02 21:57:11 +08:00
|
|
|
/* Clear instruction information field. */
|
|
|
|
info->insn_info_valid = 0;
|
|
|
|
info->branch_delay_insns = 0;
|
|
|
|
info->data_size = 0;
|
|
|
|
info->insn_type = dis_noninsn;
|
|
|
|
info->target = 0;
|
|
|
|
info->target2 = 0;
|
2007-02-16 18:24:48 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
if (!initialized)
|
|
|
|
{
|
2002-11-19 00:54:08 +08:00
|
|
|
unsigned int nopcodes;
|
|
|
|
|
2007-02-16 18:24:48 +08:00
|
|
|
/* PR 4045: Try to avoid duplicating the 0x prefix that
|
|
|
|
objdump_print_addr() will put on addresses when there
|
|
|
|
is no symbol table available. */
|
|
|
|
if (info->symtab_size == 0)
|
|
|
|
comment_start = " ";
|
|
|
|
|
2002-11-19 00:54:08 +08:00
|
|
|
nopcodes = sizeof (avr_opcodes) / sizeof (struct avr_opcodes_s);
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2005-07-01 19:16:33 +08:00
|
|
|
avr_bin_masks = xmalloc (nopcodes * sizeof (unsigned int));
|
2002-11-19 00:54:08 +08:00
|
|
|
|
|
|
|
for (opcode = avr_opcodes, maskptr = avr_bin_masks;
|
|
|
|
opcode->name;
|
|
|
|
opcode++, maskptr++)
|
2000-06-08 01:45:44 +08:00
|
|
|
{
|
|
|
|
char * s;
|
|
|
|
unsigned int bin = 0;
|
|
|
|
unsigned int mask = 0;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
for (s = opcode->opcode; *s; ++s)
|
|
|
|
{
|
|
|
|
bin <<= 1;
|
|
|
|
mask <<= 1;
|
|
|
|
bin |= (*s == '1');
|
|
|
|
mask |= (*s == '1' || *s == '0');
|
|
|
|
}
|
|
|
|
assert (s - opcode->opcode == 16);
|
|
|
|
assert (opcode->bin_opcode == bin);
|
2002-11-19 00:54:08 +08:00
|
|
|
*maskptr = mask;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
2002-11-19 00:54:08 +08:00
|
|
|
|
|
|
|
initialized = 1;
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
2000-03-27 16:39:14 +08:00
|
|
|
|
2016-12-29 23:47:40 +08:00
|
|
|
if (avrdis_opcode (addr, info, &insn) != 0)
|
|
|
|
return -1;
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2002-11-19 00:54:08 +08:00
|
|
|
for (opcode = avr_opcodes, maskptr = avr_bin_masks;
|
|
|
|
opcode->name;
|
|
|
|
opcode++, maskptr++)
|
2014-07-01 17:20:17 +08:00
|
|
|
{
|
|
|
|
if ((opcode->isa == AVR_ISA_TINY) && (info->mach != bfd_mach_avrtiny))
|
|
|
|
continue;
|
|
|
|
if ((insn & *maskptr) == opcode->bin_opcode)
|
|
|
|
break;
|
|
|
|
}
|
2015-08-12 19:45:07 +08:00
|
|
|
|
2000-08-06 22:12:36 +08:00
|
|
|
/* Special case: disassemble `ldd r,b+0' as `ld r,b', and
|
|
|
|
`std b+0,r' as `st b,r' (next entry in the table). */
|
|
|
|
|
|
|
|
if (AVR_DISP0_P (insn))
|
|
|
|
opcode++;
|
|
|
|
|
|
|
|
op1[0] = 0;
|
|
|
|
op2[0] = 0;
|
|
|
|
comment1[0] = 0;
|
|
|
|
comment2[0] = 0;
|
2022-07-04 18:25:42 +08:00
|
|
|
style_op1 = dis_style_text;
|
|
|
|
style_op2 = dis_style_text;
|
2000-08-06 22:12:36 +08:00
|
|
|
|
2000-06-08 01:45:44 +08:00
|
|
|
if (opcode->name)
|
2000-03-27 16:39:14 +08:00
|
|
|
{
|
2011-03-23 02:10:48 +08:00
|
|
|
char *constraints = opcode->constraints;
|
|
|
|
char *opcode_str = opcode->opcode;
|
2000-06-08 01:45:44 +08:00
|
|
|
|
2000-07-04 06:25:33 +08:00
|
|
|
insn2 = 0;
|
2000-08-06 22:12:36 +08:00
|
|
|
ok = 1;
|
2000-06-08 01:45:44 +08:00
|
|
|
|
|
|
|
if (opcode->insn_size > 1)
|
|
|
|
{
|
2016-12-29 23:47:40 +08:00
|
|
|
if (avrdis_opcode (addr + 2, info, &insn2) != 0)
|
|
|
|
return -1;
|
2000-06-08 01:45:44 +08:00
|
|
|
cmd_len = 4;
|
|
|
|
}
|
|
|
|
|
2011-03-23 02:10:48 +08:00
|
|
|
if (*constraints && *constraints != '?')
|
2000-06-08 01:45:44 +08:00
|
|
|
{
|
2011-03-23 02:10:48 +08:00
|
|
|
int regs = REGISTER_P (*constraints);
|
2000-06-08 01:45:44 +08:00
|
|
|
|
2021-12-02 21:57:11 +08:00
|
|
|
ok = avr_operand (insn, insn2, addr, *constraints, opcode_str, op1,
|
2022-07-04 18:25:42 +08:00
|
|
|
comment1, &style_op1, 0, &sym_op1, &sym_addr1,
|
|
|
|
info);
|
2000-06-08 01:45:44 +08:00
|
|
|
|
2011-03-23 02:10:48 +08:00
|
|
|
if (ok && *(++constraints) == ',')
|
2021-12-02 21:57:11 +08:00
|
|
|
ok = avr_operand (insn, insn2, addr, *(++constraints), opcode_str,
|
2022-07-04 18:25:42 +08:00
|
|
|
op2, *comment1 ? comment2 : comment1,
|
|
|
|
&style_op2, regs, &sym_op2, &sym_addr2,
|
|
|
|
info);
|
2000-06-08 01:45:44 +08:00
|
|
|
}
|
2000-08-06 22:12:36 +08:00
|
|
|
}
|
2000-06-08 01:45:44 +08:00
|
|
|
|
2000-08-06 22:12:36 +08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
/* Unknown opcode, or invalid combination of operands. */
|
|
|
|
sprintf (op1, "0x%04x", insn);
|
|
|
|
op2[0] = 0;
|
|
|
|
sprintf (comment1, "????");
|
|
|
|
comment2[0] = 0;
|
|
|
|
}
|
2000-06-08 01:45:44 +08:00
|
|
|
|
2022-07-04 18:25:42 +08:00
|
|
|
(*prin) (stream, ok ? dis_style_mnemonic : dis_style_assembler_directive,
|
|
|
|
"%s", ok ? opcode->name : ".word");
|
|
|
|
|
2000-08-06 22:12:36 +08:00
|
|
|
if (*op1)
|
2022-07-04 18:25:42 +08:00
|
|
|
(*prin) (stream, style_op1, "\t%s", op1);
|
2000-06-08 01:45:44 +08:00
|
|
|
|
2000-08-06 22:12:36 +08:00
|
|
|
if (*op2)
|
2022-07-04 18:25:42 +08:00
|
|
|
{
|
|
|
|
(*prin) (stream, dis_style_text, ", ");
|
|
|
|
(*prin) (stream, style_op2, "%s", op2);
|
|
|
|
}
|
2000-08-06 22:12:36 +08:00
|
|
|
|
|
|
|
if (*comment1)
|
2022-07-04 18:25:42 +08:00
|
|
|
(*prin) (stream, dis_style_comment_start, "\t; %s", comment1);
|
2000-08-06 22:12:36 +08:00
|
|
|
|
2004-12-15 06:27:05 +08:00
|
|
|
if (sym_op1)
|
2004-12-15 06:30:28 +08:00
|
|
|
info->print_address_func (sym_addr1, info);
|
2004-12-15 06:27:05 +08:00
|
|
|
|
2000-08-06 22:12:36 +08:00
|
|
|
if (*comment2)
|
2022-07-04 18:25:42 +08:00
|
|
|
(*prin) (stream, dis_style_comment_start, " %s", comment2);
|
2000-06-08 01:45:44 +08:00
|
|
|
|
2004-12-15 06:27:05 +08:00
|
|
|
if (sym_op2)
|
2004-12-15 06:30:28 +08:00
|
|
|
info->print_address_func (sym_addr2, info);
|
2004-12-15 06:27:05 +08:00
|
|
|
|
2000-03-27 16:39:14 +08:00
|
|
|
return cmd_len;
|
|
|
|
}
|