2017-04-07 00:17:15 +08:00
|
|
|
/* Opcode printing code for the WebAssembly target
|
2021-01-01 06:58:58 +08:00
|
|
|
Copyright (C) 2017-2021 Free Software Foundation, Inc.
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
This file is part of libopcodes.
|
|
|
|
|
|
|
|
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 of the License, 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"
|
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"
|
2017-04-07 00:17:15 +08:00
|
|
|
#include "opintl.h"
|
|
|
|
#include "safe-ctype.h"
|
|
|
|
#include "floatformat.h"
|
|
|
|
#include "libiberty.h"
|
|
|
|
#include "elf-bfd.h"
|
|
|
|
#include "elf/internal.h"
|
|
|
|
#include "elf/wasm32.h"
|
2021-03-31 07:37:02 +08:00
|
|
|
#include <stdint.h>
|
2017-04-07 00:17:15 +08:00
|
|
|
|
read_leb128 overflow checking
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote. It's to do with sleb128
values that have unnecessary excess bytes. For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes. This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value. A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts. Mind you, it is very unlikely
to be compiling binutils with such a compiler.)
bfd/
* wasm-module.c: Guard include of limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
opcodes/
* wasm32-dis.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
binutils/
* dwarf.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(read_leb128): Use CHAR_BIT to size "result" in bits. Correct
signed overflow checking.
* testsuite/binutils-all/pr26548.s,
* testsuite/binutils-all/pr26548.d,
* testsuite/binutils-all/pr26548e.d: New tests.
* testsuite/binutils-all/readelf.exp: Run them.
(readelf_test): Drop unused "xfails" parameter. Update all uses.
2021-02-16 21:16:40 +08:00
|
|
|
#include <limits.h>
|
|
|
|
#ifndef CHAR_BIT
|
|
|
|
#define CHAR_BIT 8
|
|
|
|
#endif
|
|
|
|
|
2017-04-07 00:17:15 +08:00
|
|
|
/* Type names for blocks and signatures. */
|
|
|
|
#define BLOCK_TYPE_NONE 0x40
|
|
|
|
#define BLOCK_TYPE_I32 0x7f
|
|
|
|
#define BLOCK_TYPE_I64 0x7e
|
|
|
|
#define BLOCK_TYPE_F32 0x7d
|
|
|
|
#define BLOCK_TYPE_F64 0x7c
|
|
|
|
|
|
|
|
enum wasm_class
|
|
|
|
{
|
|
|
|
wasm_typed,
|
|
|
|
wasm_special,
|
|
|
|
wasm_break,
|
|
|
|
wasm_break_if,
|
|
|
|
wasm_break_table,
|
|
|
|
wasm_return,
|
|
|
|
wasm_call,
|
|
|
|
wasm_call_import,
|
|
|
|
wasm_call_indirect,
|
|
|
|
wasm_get_local,
|
|
|
|
wasm_set_local,
|
|
|
|
wasm_tee_local,
|
|
|
|
wasm_drop,
|
|
|
|
wasm_constant_i32,
|
|
|
|
wasm_constant_i64,
|
|
|
|
wasm_constant_f32,
|
|
|
|
wasm_constant_f64,
|
|
|
|
wasm_unary,
|
|
|
|
wasm_binary,
|
|
|
|
wasm_conv,
|
|
|
|
wasm_load,
|
|
|
|
wasm_store,
|
|
|
|
wasm_select,
|
|
|
|
wasm_relational,
|
|
|
|
wasm_eqz,
|
|
|
|
wasm_current_memory,
|
|
|
|
wasm_grow_memory,
|
|
|
|
wasm_signature
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wasm32_private_data
|
|
|
|
{
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
bool print_registers;
|
|
|
|
bool print_well_known_globals;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
/* Limit valid symbols to those with a given prefix. */
|
|
|
|
const char *section_prefix;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
} wasm32_options_t;
|
|
|
|
|
|
|
|
static const wasm32_options_t options[] =
|
|
|
|
{
|
|
|
|
{ "registers", N_("Disassemble \"register\" names") },
|
|
|
|
{ "globals", N_("Name well-known globals") },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define WASM_OPCODE(opcode, name, intype, outtype, clas, signedness) \
|
|
|
|
{ name, wasm_ ## clas, opcode },
|
|
|
|
|
|
|
|
struct wasm32_opcode_s
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
enum wasm_class clas;
|
|
|
|
unsigned char opcode;
|
|
|
|
} wasm32_opcodes[] =
|
|
|
|
{
|
|
|
|
#include "opcode/wasm.h"
|
|
|
|
{ NULL, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Parse the disassembler options in OPTS and initialize INFO. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_wasm32_disassembler_options (struct disassemble_info *info,
|
|
|
|
const char *opts)
|
|
|
|
{
|
|
|
|
struct wasm32_private_data *private = info->private_data;
|
|
|
|
|
|
|
|
while (opts != NULL)
|
|
|
|
{
|
2021-03-19 18:50:26 +08:00
|
|
|
if (startswith (opts, "registers"))
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
private->print_registers = true;
|
2021-03-19 18:50:26 +08:00
|
|
|
else if (startswith (opts, "globals"))
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
private->print_well_known_globals = true;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
opts = strchr (opts, ',');
|
|
|
|
if (opts)
|
|
|
|
opts++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether SYM is valid. Special-case absolute symbols, which
|
|
|
|
are unhelpful to print, and arguments to a "call" insn, which we
|
|
|
|
want to be in a section matching a given prefix. */
|
|
|
|
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
static bool
|
2017-04-07 00:17:15 +08:00
|
|
|
wasm32_symbol_is_valid (asymbol *sym,
|
|
|
|
struct disassemble_info *info)
|
|
|
|
{
|
|
|
|
struct wasm32_private_data *private_data = info->private_data;
|
|
|
|
|
|
|
|
if (sym == NULL)
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
return false;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
if (strcmp(sym->section->name, "*ABS*") == 0)
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
return false;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
if (private_data && private_data->section_prefix != NULL
|
|
|
|
&& strncmp (sym->section->name, private_data->section_prefix,
|
|
|
|
strlen (private_data->section_prefix)))
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
return false;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
return true;
|
2017-04-07 00:17:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the disassembler structures for INFO. */
|
|
|
|
|
|
|
|
void
|
|
|
|
disassemble_init_wasm32 (struct disassemble_info *info)
|
|
|
|
{
|
|
|
|
if (info->private_data == NULL)
|
|
|
|
{
|
|
|
|
static struct wasm32_private_data private;
|
|
|
|
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
private.print_registers = false;
|
|
|
|
private.print_well_known_globals = false;
|
2017-04-07 00:17:15 +08:00
|
|
|
private.section_prefix = NULL;
|
|
|
|
|
|
|
|
info->private_data = &private;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->disassembler_options)
|
|
|
|
{
|
|
|
|
parse_wasm32_disassembler_options (info, info->disassembler_options);
|
|
|
|
|
|
|
|
info->disassembler_options = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->symbol_is_valid = wasm32_symbol_is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read an LEB128-encoded integer from INFO at address PC, reading one
|
|
|
|
byte at a time. Set ERROR_RETURN if no complete integer could be
|
|
|
|
read, LENGTH_RETURN to the number oof bytes read (including bytes
|
|
|
|
in incomplete numbers). SIGN means interpret the number as
|
|
|
|
SLEB128. Unfortunately, this is a duplicate of wasm-module.c's
|
|
|
|
wasm_read_leb128 (). */
|
|
|
|
|
|
|
|
static uint64_t
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
wasm_read_leb128 (bfd_vma pc,
|
|
|
|
struct disassemble_info *info,
|
|
|
|
bool *error_return,
|
|
|
|
unsigned int *length_return,
|
|
|
|
bool sign)
|
2017-04-07 00:17:15 +08:00
|
|
|
{
|
|
|
|
uint64_t result = 0;
|
|
|
|
unsigned int num_read = 0;
|
|
|
|
unsigned int shift = 0;
|
|
|
|
unsigned char byte = 0;
|
read_leb128 overflow checking
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote. It's to do with sleb128
values that have unnecessary excess bytes. For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes. This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value. A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts. Mind you, it is very unlikely
to be compiling binutils with such a compiler.)
bfd/
* wasm-module.c: Guard include of limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
opcodes/
* wasm32-dis.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
binutils/
* dwarf.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(read_leb128): Use CHAR_BIT to size "result" in bits. Correct
signed overflow checking.
* testsuite/binutils-all/pr26548.s,
* testsuite/binutils-all/pr26548.d,
* testsuite/binutils-all/pr26548e.d: New tests.
* testsuite/binutils-all/readelf.exp: Run them.
(readelf_test): Drop unused "xfails" parameter. Update all uses.
2021-02-16 21:16:40 +08:00
|
|
|
unsigned char lost, mask;
|
2019-12-23 15:28:09 +08:00
|
|
|
int status = 1;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
while (info->read_memory_func (pc + num_read, &byte, 1, info) == 0)
|
|
|
|
{
|
|
|
|
num_read++;
|
|
|
|
|
read_leb128 overflow checking
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote. It's to do with sleb128
values that have unnecessary excess bytes. For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes. This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value. A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts. Mind you, it is very unlikely
to be compiling binutils with such a compiler.)
bfd/
* wasm-module.c: Guard include of limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
opcodes/
* wasm32-dis.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
binutils/
* dwarf.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(read_leb128): Use CHAR_BIT to size "result" in bits. Correct
signed overflow checking.
* testsuite/binutils-all/pr26548.s,
* testsuite/binutils-all/pr26548.d,
* testsuite/binutils-all/pr26548e.d: New tests.
* testsuite/binutils-all/readelf.exp: Run them.
(readelf_test): Drop unused "xfails" parameter. Update all uses.
2021-02-16 21:16:40 +08:00
|
|
|
if (shift < CHAR_BIT * sizeof (result))
|
2019-12-23 15:28:09 +08:00
|
|
|
{
|
|
|
|
result |= ((uint64_t) (byte & 0x7f)) << shift;
|
read_leb128 overflow checking
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote. It's to do with sleb128
values that have unnecessary excess bytes. For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes. This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value. A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts. Mind you, it is very unlikely
to be compiling binutils with such a compiler.)
bfd/
* wasm-module.c: Guard include of limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
opcodes/
* wasm32-dis.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
binutils/
* dwarf.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(read_leb128): Use CHAR_BIT to size "result" in bits. Correct
signed overflow checking.
* testsuite/binutils-all/pr26548.s,
* testsuite/binutils-all/pr26548.d,
* testsuite/binutils-all/pr26548e.d: New tests.
* testsuite/binutils-all/readelf.exp: Run them.
(readelf_test): Drop unused "xfails" parameter. Update all uses.
2021-02-16 21:16:40 +08:00
|
|
|
/* These bits overflowed. */
|
|
|
|
lost = byte ^ (result >> shift);
|
|
|
|
/* And this is the mask of possible overflow bits. */
|
|
|
|
mask = 0x7f ^ ((uint64_t) 0x7f << shift >> shift);
|
2019-12-23 15:28:09 +08:00
|
|
|
shift += 7;
|
|
|
|
}
|
read_leb128 overflow checking
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote. It's to do with sleb128
values that have unnecessary excess bytes. For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes. This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value. A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts. Mind you, it is very unlikely
to be compiling binutils with such a compiler.)
bfd/
* wasm-module.c: Guard include of limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
opcodes/
* wasm32-dis.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
binutils/
* dwarf.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(read_leb128): Use CHAR_BIT to size "result" in bits. Correct
signed overflow checking.
* testsuite/binutils-all/pr26548.s,
* testsuite/binutils-all/pr26548.d,
* testsuite/binutils-all/pr26548e.d: New tests.
* testsuite/binutils-all/readelf.exp: Run them.
(readelf_test): Drop unused "xfails" parameter. Update all uses.
2021-02-16 21:16:40 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
lost = byte;
|
|
|
|
mask = 0x7f;
|
|
|
|
}
|
|
|
|
if ((lost & mask) != (sign && (int64_t) result < 0 ? mask : 0))
|
2019-12-23 15:28:09 +08:00
|
|
|
status |= 2;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
if ((byte & 0x80) == 0)
|
2019-12-23 15:28:09 +08:00
|
|
|
{
|
|
|
|
status &= ~1;
|
read_leb128 overflow checking
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote. It's to do with sleb128
values that have unnecessary excess bytes. For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes. This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value. A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts. Mind you, it is very unlikely
to be compiling binutils with such a compiler.)
bfd/
* wasm-module.c: Guard include of limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
opcodes/
* wasm32-dis.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
binutils/
* dwarf.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(read_leb128): Use CHAR_BIT to size "result" in bits. Correct
signed overflow checking.
* testsuite/binutils-all/pr26548.s,
* testsuite/binutils-all/pr26548.d,
* testsuite/binutils-all/pr26548e.d: New tests.
* testsuite/binutils-all/readelf.exp: Run them.
(readelf_test): Drop unused "xfails" parameter. Update all uses.
2021-02-16 21:16:40 +08:00
|
|
|
if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40))
|
2019-12-23 15:28:09 +08:00
|
|
|
result |= -((uint64_t) 1 << shift);
|
|
|
|
break;
|
|
|
|
}
|
2017-04-07 00:17:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (length_return != NULL)
|
|
|
|
*length_return = num_read;
|
|
|
|
if (error_return != NULL)
|
2019-12-23 15:28:09 +08:00
|
|
|
*error_return = status != 0;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a 32-bit IEEE float from PC using INFO, convert it to a host
|
|
|
|
double, and store it at VALUE. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_f32 (double *value, bfd_vma pc, struct disassemble_info *info)
|
|
|
|
{
|
|
|
|
bfd_byte buf[4];
|
|
|
|
|
|
|
|
if (info->read_memory_func (pc, buf, sizeof (buf), info))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
floatformat_to_double (&floatformat_ieee_single_little, buf,
|
|
|
|
value);
|
|
|
|
|
|
|
|
return sizeof (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a 64-bit IEEE float from PC using INFO, convert it to a host
|
|
|
|
double, and store it at VALUE. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_f64 (double *value, bfd_vma pc, struct disassemble_info *info)
|
|
|
|
{
|
|
|
|
bfd_byte buf[8];
|
|
|
|
|
|
|
|
if (info->read_memory_func (pc, buf, sizeof (buf), info))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
floatformat_to_double (&floatformat_ieee_double_little, buf,
|
|
|
|
value);
|
|
|
|
|
|
|
|
return sizeof (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main disassembly routine. Disassemble insn at PC using INFO. */
|
|
|
|
|
|
|
|
int
|
|
|
|
print_insn_wasm32 (bfd_vma pc, struct disassemble_info *info)
|
|
|
|
{
|
|
|
|
unsigned char opcode;
|
|
|
|
struct wasm32_opcode_s *op;
|
|
|
|
bfd_byte buffer[16];
|
|
|
|
void *stream = info->stream;
|
|
|
|
fprintf_ftype prin = info->fprintf_func;
|
|
|
|
struct wasm32_private_data *private_data = info->private_data;
|
2020-01-13 11:57:19 +08:00
|
|
|
uint64_t val;
|
|
|
|
int len;
|
|
|
|
unsigned int bytes_read;
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
bool error;
|
2017-04-07 00:17:15 +08:00
|
|
|
|
|
|
|
if (info->read_memory_func (pc, buffer, 1, info))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
opcode = buffer[0];
|
|
|
|
|
|
|
|
for (op = wasm32_opcodes; op->name; op++)
|
|
|
|
if (op->opcode == opcode)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!op->name)
|
|
|
|
{
|
|
|
|
prin (stream, "\t.byte 0x%02x\n", buffer[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
2020-01-13 11:57:19 +08:00
|
|
|
|
|
|
|
len = 1;
|
|
|
|
|
|
|
|
prin (stream, "\t");
|
|
|
|
prin (stream, "%s", op->name);
|
|
|
|
|
|
|
|
if (op->clas == wasm_typed)
|
2017-04-07 00:17:15 +08:00
|
|
|
{
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read, false);
|
2020-01-13 11:57:19 +08:00
|
|
|
if (error)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
switch (val)
|
|
|
|
{
|
|
|
|
case BLOCK_TYPE_NONE:
|
|
|
|
prin (stream, "[]");
|
|
|
|
break;
|
|
|
|
case BLOCK_TYPE_I32:
|
|
|
|
prin (stream, "[i]");
|
|
|
|
break;
|
|
|
|
case BLOCK_TYPE_I64:
|
|
|
|
prin (stream, "[l]");
|
|
|
|
break;
|
|
|
|
case BLOCK_TYPE_F32:
|
|
|
|
prin (stream, "[f]");
|
|
|
|
break;
|
|
|
|
case BLOCK_TYPE_F64:
|
|
|
|
prin (stream, "[d]");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (op->clas)
|
|
|
|
{
|
|
|
|
case wasm_special:
|
|
|
|
case wasm_eqz:
|
|
|
|
case wasm_binary:
|
|
|
|
case wasm_unary:
|
|
|
|
case wasm_conv:
|
|
|
|
case wasm_relational:
|
|
|
|
case wasm_drop:
|
|
|
|
case wasm_signature:
|
|
|
|
case wasm_call_import:
|
|
|
|
case wasm_typed:
|
|
|
|
case wasm_select:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_break_table:
|
|
|
|
{
|
|
|
|
uint32_t target_count, i;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
target_count = val;
|
|
|
|
if (error || target_count != val || target_count == (uint32_t) -1)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %u", target_count);
|
|
|
|
for (i = 0; i < target_count + 1; i++)
|
|
|
|
{
|
|
|
|
uint32_t target;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
target = val;
|
|
|
|
if (error || target != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %u", target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_break:
|
|
|
|
case wasm_break_if:
|
|
|
|
{
|
|
|
|
uint32_t depth;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
depth = val;
|
|
|
|
if (error || depth != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %u", depth);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_return:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_constant_i32:
|
|
|
|
case wasm_constant_i64:
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read, true);
|
2020-01-13 11:57:19 +08:00
|
|
|
if (error)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %" PRId64, val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_constant_f32:
|
|
|
|
{
|
|
|
|
double fconstant;
|
|
|
|
int ret;
|
|
|
|
/* This appears to be the best we can do, even though we're
|
|
|
|
using host doubles for WebAssembly floats. */
|
|
|
|
ret = read_f32 (&fconstant, pc + len, info);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
len += ret;
|
|
|
|
prin (stream, " %.9g", fconstant);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_constant_f64:
|
|
|
|
{
|
|
|
|
double fconstant;
|
|
|
|
int ret;
|
|
|
|
ret = read_f64 (&fconstant, pc + len, info);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
len += ret;
|
|
|
|
prin (stream, " %.17g", fconstant);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_call:
|
|
|
|
{
|
|
|
|
uint32_t function_index;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
function_index = val;
|
|
|
|
if (error || function_index != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " ");
|
|
|
|
private_data->section_prefix = ".space.function_index";
|
|
|
|
(*info->print_address_func) ((bfd_vma) function_index, info);
|
|
|
|
private_data->section_prefix = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_call_indirect:
|
|
|
|
{
|
|
|
|
uint32_t type_index, xtra_index;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
type_index = val;
|
|
|
|
if (error || type_index != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %u", type_index);
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
xtra_index = val;
|
|
|
|
if (error || xtra_index != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %u", xtra_index);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_get_local:
|
|
|
|
case wasm_set_local:
|
|
|
|
case wasm_tee_local:
|
|
|
|
{
|
|
|
|
uint32_t local_index;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
local_index = val;
|
|
|
|
if (error || local_index != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %u", local_index);
|
|
|
|
if (strcmp (op->name + 4, "local") == 0)
|
|
|
|
{
|
|
|
|
static const char *locals[] =
|
|
|
|
{
|
|
|
|
"$dpc", "$sp1", "$r0", "$r1", "$rpc", "$pc0",
|
|
|
|
"$rp", "$fp", "$sp",
|
|
|
|
"$r2", "$r3", "$r4", "$r5", "$r6", "$r7",
|
|
|
|
"$i0", "$i1", "$i2", "$i3", "$i4", "$i5", "$i6", "$i7",
|
|
|
|
"$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
|
|
|
|
};
|
|
|
|
if (private_data->print_registers
|
|
|
|
&& local_index < ARRAY_SIZE (locals))
|
|
|
|
prin (stream, " <%s>", locals[local_index]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const char *globals[] =
|
|
|
|
{
|
|
|
|
"$got", "$plt", "$gpo"
|
|
|
|
};
|
|
|
|
if (private_data->print_well_known_globals
|
|
|
|
&& local_index < ARRAY_SIZE (globals))
|
|
|
|
prin (stream, " <%s>", globals[local_index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_grow_memory:
|
|
|
|
case wasm_current_memory:
|
|
|
|
{
|
|
|
|
uint32_t reserved_size;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
reserved_size = val;
|
|
|
|
if (error || reserved_size != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " %u", reserved_size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wasm_load:
|
|
|
|
case wasm_store:
|
|
|
|
{
|
|
|
|
uint32_t flags, offset;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
flags = val;
|
|
|
|
if (error || flags != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
val = wasm_read_leb128 (pc + len, info, &error, &bytes_read,
|
Use bool in opcodes
cpu/
* frv.opc: Replace bfd_boolean with bool, FALSE with false, and
TRUE with true throughout.
opcodes/
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* aarch64-asm-2.c, * aarch64-asm.c, * aarch64-asm.h,
* aarch64-dis-2.c, * aarch64-dis.c, * aarch64-dis.h,
* aarch64-gen.c, * aarch64-opc.c, * aarch64-opc.h, * arc-dis.c,
* arc-dis.h, * arc-fxi.h, * arc-opc.c, * arm-dis.c, * bfin-dis.c,
* cris-dis.c, * csky-dis.c, * csky-opc.h, * dis-buf.c,
* disassemble.c, * frv-opc.c, * frv-opc.h, * h8300-dis.c,
* i386-dis.c, * m68k-dis.c, * metag-dis.c, * microblaze-dis.c,
* microblaze-dis.h, * micromips-opc.c, * mips-dis.c,
* mips-formats.h, * mips-opc.c, * mips16-opc.c, * mmix-dis.c,
* msp430-dis.c, * nds32-dis.c, * nfp-dis.c, * nios2-dis.c,
* ppc-dis.c, * riscv-dis.c, * score-dis.c, * score7-dis.c,
* tic6x-dis.c, * v850-dis.c, * vax-dis.c, * wasm32-dis.c,
* xtensa-dis.c: Replace bfd_boolean with bool, FALSE with false,
and TRUE with true throughout.
2021-03-31 08:06:19 +08:00
|
|
|
false);
|
2020-01-13 11:57:19 +08:00
|
|
|
offset = val;
|
|
|
|
if (error || offset != val)
|
|
|
|
return -1;
|
|
|
|
len += bytes_read;
|
|
|
|
prin (stream, " a=%u %u", flags, offset);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-07 00:17:15 +08:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print valid disassembler options to STREAM. */
|
|
|
|
|
|
|
|
void
|
|
|
|
print_wasm32_disassembler_options (FILE *stream)
|
|
|
|
{
|
|
|
|
unsigned int i, max_len = 0;
|
|
|
|
|
|
|
|
fprintf (stream, _("\
|
|
|
|
The following WebAssembly-specific disassembler options are supported for use\n\
|
|
|
|
with the -M switch:\n"));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE (options); i++)
|
|
|
|
{
|
|
|
|
unsigned int len = strlen (options[i].name);
|
|
|
|
|
|
|
|
if (max_len < len)
|
|
|
|
max_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, max_len++; i < ARRAY_SIZE (options); i++)
|
|
|
|
fprintf (stream, " %s%*c %s\n",
|
|
|
|
options[i].name,
|
|
|
|
(int)(max_len - strlen (options[i].name)), ' ',
|
|
|
|
_(options[i].description));
|
|
|
|
}
|