Initial import of the VAX asm/anal/bin support

This commit is contained in:
pancake 2015-11-23 12:34:53 +01:00
parent b4308219e7
commit a31cd1101e
12 changed files with 993 additions and 8 deletions

102
libr/anal/p/anal_vax.c Normal file
View File

@ -0,0 +1,102 @@
/* radare - LGPL - Copyright 2015 - pancake */
#include <string.h>
#include <r_types.h>
#include <r_util.h>
#include <r_lib.h>
#include <r_asm.h>
#include <r_anal.h>
// XXX: this is just a PoC
// XXX: do not hardcode size/type here, use proper decoding table
// http://hotkosc.ru:8080/method-vax.doc
static int vax_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
op->size = 1;
if (len<1) return -1;
op->type = R_ANAL_OP_TYPE_UNK;
switch (buf[0]) {
case 0xd0:
case 0x2e:
op->type = R_ANAL_OP_TYPE_MOV;
op->size = 8;
break;
case 0x78:
op->type = R_ANAL_OP_TYPE_SHL;
op->size = 8;
break;
case 0xc0:
case 0xd8:
op->type = R_ANAL_OP_TYPE_ADD;
op->size = 8;
break;
case 0x00:
op->type = R_ANAL_OP_TYPE_TRAP; // HALT
break;
case 0x01:
op->type = R_ANAL_OP_TYPE_NOP;
break;
case 0x51:
case 0x73:
op->type = R_ANAL_OP_TYPE_CMP;
break;
case 0xac:
op->type = R_ANAL_OP_TYPE_XOR;
op->size = 4;
break;
case 0x5a:
op->size = 2;
break;
case 0x11:
case 0x18:
op->size = 2;
op->type = R_ANAL_OP_TYPE_CJMP;
break;
case 0x31:
case 0xe9:
op->size = 3;
op->type = R_ANAL_OP_TYPE_CJMP;
break;
case 0xc6:
case 0xc7:
op->size = 8;
op->type = R_ANAL_OP_TYPE_DIV;
break;
case 0xd6:
case 0x61:
op->size = 2;
op->type = R_ANAL_OP_TYPE_ADD;
break;
case 0x62:
op->type = R_ANAL_OP_TYPE_SUB;
break;
case 0xff:
op->size = 2;
break;
}
return op->size;
}
RAnalPlugin r_anal_plugin_vax = {
.name = "vax",
.desc = "VAX code analysis plugin",
.license = "LGPL3",
.arch = "vax",
.esil = true,
.bits = 8 | 32,
.op = &vax_op,
#if 0
.archinfo = archinfo,
.set_reg_profile = &set_reg_profile,
.esil_init = esil_vax_init,
.esil_fini = esil_vax_fini,
#endif
};
#ifndef CORELIB
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_vax,
.version = R2_VERSION
};
#endif

9
libr/anal/p/vax.mk Normal file
View File

@ -0,0 +1,9 @@
OBJ_VAX=anal_vax.o
STATIC_OBJ+=${OBJ_VAX}
TARGET_VAX=anal_vax.${EXT_SO}
ALL_TARGETS+=${TARGET_VAX}
${TARGET_VAX}: ${OBJ_VAX}
${CC} $(call libname,anal_vax) ${CFLAGS} -o anal_vax.${EXT_SO} ${OBJ_VAX}

362
libr/asm/arch/vax/vax-dis.c Normal file
View File

@ -0,0 +1,362 @@
/* Print VAX instructions.
Copyright 1995, 1998, 2000, 2001, 2002, 2005, 2007, 2009, 2012
Free Software Foundation, Inc.
Contributed by Pauline Middelink <middelin@polyware.iaf.nl>
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 <setjmp.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "vax.h"
#include "dis-asm.h"
static char *reg_names[] =
{
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc"
};
#if 0
/* Definitions for the function entry mask bits. */
static char *entry_mask_bit[] =
{
/* Registers 0 and 1 shall not be saved, since they're used to pass back
a function's result to its caller... */
"~r0~", "~r1~",
/* Registers 2 .. 11 are normal registers. */
"r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11",
/* Registers 12 and 13 are argument and frame pointer and must not
be saved by using the entry mask. */
"~ap~", "~fp~",
/* Bits 14 and 15 control integer and decimal overflow. */
"IntOvfl", "DecOvfl",
};
#endif
/* Sign-extend an (unsigned char). */
#define COERCE_SIGNED_CHAR(ch) ((signed char)(ch))
/* Get a 1 byte signed integer. */
#define NEXTBYTE(p) \
(p += 1, FETCH_DATA (info, p), \
COERCE_SIGNED_CHAR(p[-1]))
/* Get a 2 byte signed integer. */
#define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
#define NEXTWORD(p) \
(p += 2, FETCH_DATA (info, p), \
COERCE16 ((p[-1] << 8) + p[-2]))
/* Get a 4 byte signed integer. */
#define COERCE32(x) ((int) (((x) ^ 0x80000000) - 0x80000000))
#define NEXTLONG(p) \
(p += 4, FETCH_DATA (info, p), \
(COERCE32 ((((((p[-1] << 8) + p[-2]) << 8) + p[-3]) << 8) + p[-4])))
/* Maximum length of an instruction. */
#define MAXLEN 25
struct private
{
/* Points to first byte not fetched. */
bfd_byte * max_fetched;
bfd_byte the_buffer[MAXLEN];
bfd_vma insn_start;
jmp_buf bailout;
};
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
to ADDR (exclusive) are valid. Returns 1 for success, longjmps
on error. */
#define FETCH_DATA(info, addr) \
((addr) <= ((struct private *)(info->private_data))->max_fetched \
? 1 : fetch_data ((info), (addr)))
static int
fetch_data (struct disassemble_info *info, bfd_byte *addr)
{
int status;
struct private *priv = (struct private *) info->private_data;
bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
status = (*info->read_memory_func) (start,
priv->max_fetched,
addr - priv->max_fetched,
info);
if (status != 0)
{
(*info->memory_error_func) (status, start, info);
longjmp (priv->bailout, 1);
}
else
priv->max_fetched = addr;
return 1;
}
/* Entry mask handling. */
static unsigned int entry_addr_occupied_slots = 0;
static unsigned int entry_addr_total_slots = 0;
static bfd_vma * entry_addr = NULL;
/* Parse the VAX specific disassembler options. These contain function
entry addresses, which can be useful to disassemble ROM images, since
there's no symbol table. Returns TRUE upon success, FALSE otherwise. */
/* Check if the given address is a known function entry point. This is
the case if there is a symbol of the function type at this address.
We also check for synthetic symbols as these are used for PLT entries
(weak undefined symbols may not have the function type set). Finally
the address may have been forced to be treated as an entry point. The
latter helps in disassembling ROM images, because there's no symbol
table at all. Forced entry points can be given by supplying several
-M options to objdump: -M entry:0xffbb7730. */
static int
print_insn_mode (const char *d,
int size,
unsigned char *p0,
bfd_vma addr, /* PC for this arg to be relative to. */
disassemble_info *info)
{
unsigned char *p = p0;
unsigned char mode, reg;
/* Fetch and interpret mode byte. */
mode = (unsigned char) NEXTBYTE (p);
reg = mode & 0xF;
switch (mode & 0xF0)
{
case 0x00:
case 0x10:
case 0x20:
case 0x30: /* Literal mode $number. */
if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
(*info->fprintf_func) (info->stream, "$0x%x [%c-float]", mode, d[1]);
else
(*info->fprintf_func) (info->stream, "$0x%x", mode);
break;
case 0x40: /* Index: base-addr[Rn] */
p += print_insn_mode (d, size, p0 + 1, addr + 1, info);
(*info->fprintf_func) (info->stream, "[%s]", reg_names[reg]);
break;
case 0x50: /* Register: Rn */
(*info->fprintf_func) (info->stream, "%s", reg_names[reg]);
break;
case 0x60: /* Register deferred: (Rn) */
(*info->fprintf_func) (info->stream, "(%s)", reg_names[reg]);
break;
case 0x70: /* Autodecrement: -(Rn) */
(*info->fprintf_func) (info->stream, "-(%s)", reg_names[reg]);
break;
case 0x80: /* Autoincrement: (Rn)+ */
if (reg == 0xF)
{ /* Immediate? */
int i;
FETCH_DATA (info, p + size);
(*info->fprintf_func) (info->stream, "$0x");
if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
{
int float_word;
float_word = p[0] | (p[1] << 8);
if ((d[1] == 'd' || d[1] == 'f')
&& (float_word & 0xff80) == 0x8000)
{
(*info->fprintf_func) (info->stream, "[invalid %c-float]",
d[1]);
}
else
{
for (i = 0; i < size; i++)
(*info->fprintf_func) (info->stream, "%02x",
p[size - i - 1]);
(*info->fprintf_func) (info->stream, " [%c-float]", d[1]);
}
}
else
{
for (i = 0; i < size; i++)
(*info->fprintf_func) (info->stream, "%02x", p[size - i - 1]);
}
p += size;
}
else
(*info->fprintf_func) (info->stream, "(%s)+", reg_names[reg]);
break;
case 0x90: /* Autoincrement deferred: @(Rn)+ */
if (reg == 0xF)
(*info->fprintf_func) (info->stream, "*0x%x", NEXTLONG (p));
else
(*info->fprintf_func) (info->stream, "@(%s)+", reg_names[reg]);
break;
case 0xB0: /* Displacement byte deferred: *displ(Rn). */
(*info->fprintf_func) (info->stream, "*");
case 0xA0: /* Displacement byte: displ(Rn). */
if (reg == 0xF)
(*info->print_address_func) (addr + 2 + NEXTBYTE (p), info);
else
(*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTBYTE (p),
reg_names[reg]);
break;
case 0xD0: /* Displacement word deferred: *displ(Rn). */
(*info->fprintf_func) (info->stream, "*");
case 0xC0: /* Displacement word: displ(Rn). */
if (reg == 0xF)
(*info->print_address_func) (addr + 3 + NEXTWORD (p), info);
else
(*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTWORD (p),
reg_names[reg]);
break;
case 0xF0: /* Displacement long deferred: *displ(Rn). */
(*info->fprintf_func) (info->stream, "*");
case 0xE0: /* Displacement long: displ(Rn). */
if (reg == 0xF)
(*info->print_address_func) (addr + 5 + NEXTLONG (p), info);
else
(*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTLONG (p),
reg_names[reg]);
break;
}
return p - p0;
}
/* Returns number of bytes "eaten" by the operand, or return -1 if an
invalid operand was found, or -2 if an opcode tabel error was
found. */
static int
print_insn_arg (const char *d,
unsigned char *p0,
bfd_vma addr, /* PC for this arg to be relative to. */
disassemble_info *info)
{
int arg_len;
/* Check validity of addressing length. */
switch (d[1])
{
case 'b' : arg_len = 1; break;
case 'd' : arg_len = 8; break;
case 'f' : arg_len = 4; break;
case 'g' : arg_len = 8; break;
case 'h' : arg_len = 16; break;
case 'l' : arg_len = 4; break;
case 'o' : arg_len = 16; break;
case 'w' : arg_len = 2; break;
case 'q' : arg_len = 8; break;
default : abort ();
}
/* Branches have no mode byte. */
if (d[0] == 'b')
{
unsigned char *p = p0;
if (arg_len == 1)
(*info->print_address_func) (addr + 1 + NEXTBYTE (p), info);
else
(*info->print_address_func) (addr + 2 + NEXTWORD (p), info);
return p - p0;
}
return print_insn_mode (d, arg_len, p0, addr, info);
}
/* Print the vax instruction at address MEMADDR in debugged memory,
on INFO->STREAM. Returns length of the instruction, in bytes. */
int
print_insn_vax (bfd_vma memaddr, disassemble_info *info)
{
static bfd_boolean parsed_disassembler_options = FALSE;
const struct vot *votp;
const char *argp;
unsigned char *arg;
struct private priv;
bfd_byte *buffer = priv.the_buffer;
info->private_data = & priv;
priv.max_fetched = priv.the_buffer;
priv.insn_start = memaddr;
if (setjmp (priv.bailout) != 0)
/* Error return. */
return -1;
argp = NULL;
/* Check if the info buffer has more than one byte left since
the last opcode might be a single byte with no argument data. */
if (info->buffer_length - (memaddr - info->buffer_vma) > 1)
{
FETCH_DATA (info, buffer + 2);
}
else
{
FETCH_DATA (info, buffer + 1);
buffer[1] = 0;
}
for (votp = &votstrs[0]; votp->name[0]; votp++)
{
vax_opcodeT opcode = votp->detail.code;
/* 2 byte codes match 2 buffer pos. */
if ((bfd_byte) opcode == buffer[0]
&& (opcode >> 8 == 0 || opcode >> 8 == buffer[1]))
{
argp = votp->detail.args;
break;
}
}
if (argp == NULL)
{
/* Handle undefined instructions. */
(*info->fprintf_func) (info->stream, ".word 0x%x",
(buffer[0] << 8) + buffer[1]);
return 2;
}
/* Point at first byte of argument data, and at descriptor for first
argument. */
arg = buffer + ((votp->detail.code >> 8) ? 2 : 1);
/* Make sure we have it in mem */
FETCH_DATA (info, arg);
(*info->fprintf_func) (info->stream, "%s", votp->name);
if (*argp)
(*info->fprintf_func) (info->stream, " ");
while (*argp)
{
arg += print_insn_arg (argp, arg, memaddr + arg - buffer, info);
argp += 2;
if (*argp)
(*info->fprintf_func) (info->stream, ", ");
}
return arg - buffer;
}

383
libr/asm/arch/vax/vax.h Normal file
View File

@ -0,0 +1,383 @@
/* Vax opcde list.
Copyright 1989, 1991, 1992, 1995, 2010 Free Software Foundation, Inc.
This file is part of GDB and GAS.
GDB and GAS are free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GDB and GAS are 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 GDB or GAS; see the file COPYING3. If not, write to
the Free Software Foundation, 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1301, USA. */
#ifndef vax_opcodeT
#define vax_opcodeT int
#endif /* no vax_opcodeT */
struct vot_wot /* vax opcode table: wot to do with this */
/* particular opcode */
{
const char *args; /* how to compile said opcode */
vax_opcodeT code; /* op-code (may be > 8 bits!) */
};
struct vot /* vax opcode text */
{
const char *name; /* opcode name: lowercase string [key] */
struct vot_wot detail; /* rest of opcode table [datum] */
};
#define vot_how args
#define vot_code code
#define vot_detail detail
#define vot_name name
static const struct vot
votstrs[] =
{
{ "halt", {"", 0x00 } },
{ "nop", {"", 0x01 } },
{ "rei", {"", 0x02 } },
{ "bpt", {"", 0x03 } },
{ "ret", {"", 0x04 } },
{ "rsb", {"", 0x05 } },
{ "ldpctx", {"", 0x06 } },
{ "svpctx", {"", 0x07 } },
{ "cvtps", {"rwabrwab", 0x08 } },
{ "cvtsp", {"rwabrwab", 0x09 } },
{ "index", {"rlrlrlrlrlwl", 0x0a } },
{ "crc", {"abrlrwab", 0x0b } },
{ "prober", {"rbrwab", 0x0c } },
{ "probew", {"rbrwab", 0x0d } },
{ "insque", {"abab", 0x0e } },
{ "remque", {"abwl", 0x0f } },
{ "bsbb", {"bb", 0x10 } },
{ "brb", {"bb", 0x11 } },
{ "bneq", {"bb", 0x12 } },
{ "bnequ", {"bb", 0x12 } },
{ "beql", {"bb", 0x13 } },
{ "beqlu", {"bb", 0x13 } },
{ "bgtr", {"bb", 0x14 } },
{ "bleq", {"bb", 0x15 } },
{ "jsb", {"ab", 0x16 } },
{ "jmp", {"ab", 0x17 } },
{ "bgeq", {"bb", 0x18 } },
{ "blss", {"bb", 0x19 } },
{ "bgtru", {"bb", 0x1a } },
{ "blequ", {"bb", 0x1b } },
{ "bvc", {"bb", 0x1c } },
{ "bvs", {"bb", 0x1d } },
{ "bcc", {"bb", 0x1e } },
{ "bgequ", {"bb", 0x1e } },
{ "blssu", {"bb", 0x1f } },
{ "bcs", {"bb", 0x1f } },
{ "addp4", {"rwabrwab", 0x20 } },
{ "addp6", {"rwabrwabrwab", 0x21 } },
{ "subp4", {"rwabrwab", 0x22 } },
{ "subp6", {"rwabrwabrwab", 0x23 } },
{ "cvtpt", {"rwababrwab", 0x24 } },
{ "mulp", {"rwabrwabrwab", 0x25 } },
{ "cvttp", {"rwababrwab", 0x26 } },
{ "divp", {"rwabrwabrwab", 0x27 } },
{ "movc3", {"rwabab", 0x28 } },
{ "cmpc3", {"rwabab", 0x29 } },
{ "scanc", {"rwababrb", 0x2a } },
{ "spanc", {"rwababrb", 0x2b } },
{ "movc5", {"rwabrbrwab", 0x2c } },
{ "cmpc5", {"rwabrbrwab", 0x2d } },
{ "movtc", {"rwabrbabrwab", 0x2e } },
{ "movtuc", {"rwabrbabrwab", 0x2f } },
{ "bsbw", {"bw", 0x30 } },
{ "brw", {"bw", 0x31 } },
{ "cvtwl", {"rwwl", 0x32 } },
{ "cvtwb", {"rwwb", 0x33 } },
{ "movp", {"rwabab", 0x34 } },
{ "cmpp3", {"rwabab", 0x35 } },
{ "cvtpl", {"rwabwl", 0x36 } },
{ "cmpp4", {"rwabrwab", 0x37 } },
{ "editpc", {"rwababab", 0x38 } },
{ "matchc", {"rwabrwab", 0x39 } },
{ "locc", {"rbrwab", 0x3a } },
{ "skpc", {"rbrwab", 0x3b } },
{ "movzwl", {"rwwl", 0x3c } },
{ "acbw", {"rwrwmwbw", 0x3d } },
{ "movaw", {"awwl", 0x3e } },
{ "pushaw", {"aw", 0x3f } },
{ "addf2", {"rfmf", 0x40 } },
{ "addf3", {"rfrfwf", 0x41 } },
{ "subf2", {"rfmf", 0x42 } },
{ "subf3", {"rfrfwf", 0x43 } },
{ "mulf2", {"rfmf", 0x44 } },
{ "mulf3", {"rfrfwf", 0x45 } },
{ "divf2", {"rfmf", 0x46 } },
{ "divf3", {"rfrfwf", 0x47 } },
{ "cvtfb", {"rfwb", 0x48 } },
{ "cvtfw", {"rfww", 0x49 } },
{ "cvtfl", {"rfwl", 0x4a } },
{ "cvtrfl", {"rfwl", 0x4b } },
{ "cvtbf", {"rbwf", 0x4c } },
{ "cvtwf", {"rwwf", 0x4d } },
{ "cvtlf", {"rlwf", 0x4e } },
{ "acbf", {"rfrfmfbw", 0x4f } },
{ "movf", {"rfwf", 0x50 } },
{ "cmpf", {"rfrf", 0x51 } },
{ "mnegf", {"rfwf", 0x52 } },
{ "tstf", {"rf", 0x53 } },
{ "emodf", {"rfrbrfwlwf", 0x54 } },
{ "polyf", {"rfrwab", 0x55 } },
{ "cvtfd", {"rfwd", 0x56 } },
/* opcode 57 is not defined yet */
{ "adawi", {"rwmw", 0x58 } },
/* opcode 59 is not defined yet */
/* opcode 5a is not defined yet */
/* opcode 5b is not defined yet */
{ "insqhi", {"abaq", 0x5c } },
{ "insqti", {"abaq", 0x5d } },
{ "remqhi", {"aqwl", 0x5e } },
{ "remqti", {"aqwl", 0x5f } },
{ "addd2", {"rdmd", 0x60 } },
{ "addd3", {"rdrdwd", 0x61 } },
{ "subd2", {"rdmd", 0x62 } },
{ "subd3", {"rdrdwd", 0x63 } },
{ "muld2", {"rdmd", 0x64 } },
{ "muld3", {"rdrdwd", 0x65 } },
{ "divd2", {"rdmd", 0x66 } },
{ "divd3", {"rdrdwd", 0x67 } },
{ "cvtdb", {"rdwb", 0x68 } },
{ "cvtdw", {"rdww", 0x69 } },
{ "cvtdl", {"rdwl", 0x6a } },
{ "cvtrdl", {"rdwl", 0x6b } },
{ "cvtbd", {"rbwd", 0x6c } },
{ "cvtwd", {"rwwd", 0x6d } },
{ "cvtld", {"rlwd", 0x6e } },
{ "acbd", {"rdrdmdbw", 0x6f } },
{ "movd", {"rdwd", 0x70 } },
{ "cmpd", {"rdrd", 0x71 } },
{ "mnegd", {"rdwd", 0x72 } },
{ "tstd", {"rd", 0x73 } },
{ "emodd", {"rdrbrdwlwd", 0x74 } },
{ "polyd", {"rdrwab", 0x75 } },
{ "cvtdf", {"rdwf", 0x76 } },
/* opcode 77 is not defined yet */
{ "ashl", {"rbrlwl", 0x78 } },
{ "ashq", {"rbrqwq", 0x79 } },
{ "emul", {"rlrlrlwq", 0x7a } },
{ "ediv", {"rlrqwlwl", 0x7b } },
{ "clrd", {"wd", 0x7c } },
{ "clrg", {"wg", 0x7c } },
{ "clrq", {"wd", 0x7c } },
{ "movq", {"rqwq", 0x7d } },
{ "movaq", {"aqwl", 0x7e } },
{ "movad", {"adwl", 0x7e } },
{ "pushaq", {"aq", 0x7f } },
{ "pushad", {"ad", 0x7f } },
{ "addb2", {"rbmb", 0x80 } },
{ "addb3", {"rbrbwb", 0x81 } },
{ "subb2", {"rbmb", 0x82 } },
{ "subb3", {"rbrbwb", 0x83 } },
{ "mulb2", {"rbmb", 0x84 } },
{ "mulb3", {"rbrbwb", 0x85 } },
{ "divb2", {"rbmb", 0x86 } },
{ "divb3", {"rbrbwb", 0x87 } },
{ "bisb2", {"rbmb", 0x88 } },
{ "bisb3", {"rbrbwb", 0x89 } },
{ "bicb2", {"rbmb", 0x8a } },
{ "bicb3", {"rbrbwb", 0x8b } },
{ "xorb2", {"rbmb", 0x8c } },
{ "xorb3", {"rbrbwb", 0x8d } },
{ "mnegb", {"rbwb", 0x8e } },
{ "caseb", {"rbrbrb", 0x8f } },
{ "movb", {"rbwb", 0x90 } },
{ "cmpb", {"rbrb", 0x91 } },
{ "mcomb", {"rbwb", 0x92 } },
{ "bitb", {"rbrb", 0x93 } },
{ "clrb", {"wb", 0x94 } },
{ "tstb", {"rb", 0x95 } },
{ "incb", {"mb", 0x96 } },
{ "decb", {"mb", 0x97 } },
{ "cvtbl", {"rbwl", 0x98 } },
{ "cvtbw", {"rbww", 0x99 } },
{ "movzbl", {"rbwl", 0x9a } },
{ "movzbw", {"rbww", 0x9b } },
{ "rotl", {"rbrlwl", 0x9c } },
{ "acbb", {"rbrbmbbw", 0x9d } },
{ "movab", {"abwl", 0x9e } },
{ "pushab", {"ab", 0x9f } },
{ "addw2", {"rwmw", 0xa0 } },
{ "addw3", {"rwrwww", 0xa1 } },
{ "subw2", {"rwmw", 0xa2 } },
{ "subw3", {"rwrwww", 0xa3 } },
{ "mulw2", {"rwmw", 0xa4 } },
{ "mulw3", {"rwrwww", 0xa5 } },
{ "divw2", {"rwmw", 0xa6 } },
{ "divw3", {"rwrwww", 0xa7 } },
{ "bisw2", {"rwmw", 0xa8 } },
{ "bisw3", {"rwrwww", 0xa9 } },
{ "bicw2", {"rwmw", 0xaa } },
{ "bicw3", {"rwrwww", 0xab } },
{ "xorw2", {"rwmw", 0xac } },
{ "xorw3", {"rwrwww", 0xad } },
{ "mnegw", {"rwww", 0xae } },
{ "casew", {"rwrwrw", 0xaf } },
{ "movw", {"rwww", 0xb0 } },
{ "cmpw", {"rwrw", 0xb1 } },
{ "mcomw", {"rwww", 0xb2 } },
{ "bitw", {"rwrw", 0xb3 } },
{ "clrw", {"ww", 0xb4 } },
{ "tstw", {"rw", 0xb5 } },
{ "incw", {"mw", 0xb6 } },
{ "decw", {"mw", 0xb7 } },
{ "bispsw", {"rw", 0xb8 } },
{ "bicpsw", {"rw", 0xb9 } },
{ "popr", {"rw", 0xba } },
{ "pushr", {"rw", 0xbb } },
{ "chmk", {"rw", 0xbc } },
{ "chme", {"rw", 0xbd } },
{ "chms", {"rw", 0xbe } },
{ "chmu", {"rw", 0xbf } },
{ "addl2", {"rlml", 0xc0 } },
{ "addl3", {"rlrlwl", 0xc1 } },
{ "subl2", {"rlml", 0xc2 } },
{ "subl3", {"rlrlwl", 0xc3 } },
{ "mull2", {"rlml", 0xc4 } },
{ "mull3", {"rlrlwl", 0xc5 } },
{ "divl2", {"rlml", 0xc6 } },
{ "divl3", {"rlrlwl", 0xc7 } },
{ "bisl2", {"rlml", 0xc8 } },
{ "bisl3", {"rlrlwl", 0xc9 } },
{ "bicl2", {"rlml", 0xca } },
{ "bicl3", {"rlrlwl", 0xcb } },
{ "xorl2", {"rlml", 0xcc } },
{ "xorl3", {"rlrlwl", 0xcd } },
{ "mnegl", {"rlwl", 0xce } },
{ "casel", {"rlrlrl", 0xcf } },
{ "movl", {"rlwl", 0xd0 } },
{ "cmpl", {"rlrl", 0xd1 } },
{ "mcoml", {"rlwl", 0xd2 } },
{ "bitl", {"rlrl", 0xd3 } },
{ "clrf", {"wf", 0xd4 } },
{ "clrl", {"wl", 0xd4 } },
{ "tstl", {"rl", 0xd5 } },
{ "incl", {"ml", 0xd6 } },
{ "decl", {"ml", 0xd7 } },
{ "adwc", {"rlml", 0xd8 } },
{ "sbwc", {"rlml", 0xd9 } },
{ "mtpr", {"rlrl", 0xda } },
{ "mfpr", {"rlwl", 0xdb } },
{ "movpsl", {"wl", 0xdc } },
{ "pushl", {"rl", 0xdd } },
{ "moval", {"alwl", 0xde } },
{ "movaf", {"afwl", 0xde } },
{ "pushal", {"al", 0xdf } },
{ "pushaf", {"af", 0xdf } },
{ "bbs", {"rlvbbb", 0xe0 } },
{ "bbc", {"rlvbbb", 0xe1 } },
{ "bbss", {"rlvbbb", 0xe2 } },
{ "bbcs", {"rlvbbb", 0xe3 } },
{ "bbsc", {"rlvbbb", 0xe4 } },
{ "bbcc", {"rlvbbb", 0xe5 } },
{ "bbssi", {"rlvbbb", 0xe6 } },
{ "bbcci", {"rlvbbb", 0xe7 } },
{ "blbs", {"rlbb", 0xe8 } },
{ "blbc", {"rlbb", 0xe9 } },
{ "ffs", {"rlrbvbwl", 0xea } },
{ "ffc", {"rlrbvbwl", 0xeb } },
{ "cmpv", {"rlrbvbrl", 0xec } },
{ "cmpzv", {"rlrbvbrl", 0xed } },
{ "extv", {"rlrbvbwl", 0xee } },
{ "extzv", {"rlrbvbwl", 0xef } },
{ "insv", {"rlrlrbvb", 0xf0 } },
{ "acbl", {"rlrlmlbw", 0xf1 } },
{ "aoblss", {"rlmlbb", 0xf2 } },
{ "aobleq", {"rlmlbb", 0xf3 } },
{ "sobgeq", {"mlbb", 0xf4 } },
{ "sobgtr", {"mlbb", 0xf5 } },
{ "cvtlb", {"rlwb", 0xf6 } },
{ "cvtlw", {"rlww", 0xf7 } },
{ "ashp", {"rbrwabrbrwab", 0xf8 } },
{ "cvtlp", {"rlrwab", 0xf9 } },
{ "callg", {"abab", 0xfa } },
{ "calls", {"rlab", 0xfb } },
{ "xfc", {"", 0xfc } },
/* undefined opcodes here */
{ "cvtdh", {"rdwh", 0x32fd } },
{ "cvtgf", {"rgwh", 0x33fd } },
{ "addg2", {"rgmg", 0x40fd } },
{ "addg3", {"rgrgwg", 0x41fd } },
{ "subg2", {"rgmg", 0x42fd } },
{ "subg3", {"rgrgwg", 0x43fd } },
{ "mulg2", {"rgmg", 0x44fd } },
{ "mulg3", {"rgrgwg", 0x45fd } },
{ "divg2", {"rgmg", 0x46fd } },
{ "divg3", {"rgrgwg", 0x47fd } },
{ "cvtgb", {"rgwb", 0x48fd } },
{ "cvtgw", {"rgww", 0x49fd } },
{ "cvtgl", {"rgwl", 0x4afd } },
{ "cvtrgl", {"rgwl", 0x4bfd } },
{ "cvtbg", {"rbwg", 0x4cfd } },
{ "cvtwg", {"rwwg", 0x4dfd } },
{ "cvtlg", {"rlwg", 0x4efd } },
{ "acbg", {"rgrgmgbw", 0x4ffd } },
{ "movg", {"rgwg", 0x50fd } },
{ "cmpg", {"rgrg", 0x51fd } },
{ "mnegg", {"rgwg", 0x52fd } },
{ "tstg", {"rg", 0x53fd } },
{ "emodg", {"rgrwrgwlwg", 0x54fd } },
{ "polyg", {"rgrwab", 0x55fd } },
{ "cvtgh", {"rgwh", 0x56fd } },
/* undefined opcodes here */
{ "addh2", {"rhmh", 0x60fd } },
{ "addh3", {"rhrhwh", 0x61fd } },
{ "subh2", {"rhmh", 0x62fd } },
{ "subh3", {"rhrhwh", 0x63fd } },
{ "mulh2", {"rhmh", 0x64fd } },
{ "mulh3", {"rhrhwh", 0x65fd } },
{ "divh2", {"rhmh", 0x66fd } },
{ "divh3", {"rhrhwh", 0x67fd } },
{ "cvthb", {"rhwb", 0x68fd } },
{ "cvthw", {"rhww", 0x69fd } },
{ "cvthl", {"rhwl", 0x6afd } },
{ "cvtrhl", {"rhwl", 0x6bfd } },
{ "cvtbh", {"rbwh", 0x6cfd } },
{ "cvtwh", {"rwwh", 0x6dfd } },
{ "cvtlh", {"rlwh", 0x6efd } },
{ "acbh", {"rhrhmhbw", 0x6ffd } },
{ "movh", {"rhwh", 0x70fd } },
{ "cmph", {"rhrh", 0x71fd } },
{ "mnegh", {"rhwh", 0x72fd } },
{ "tsth", {"rh", 0x73fd } },
{ "emodh", {"rhrwrhwlwh", 0x74fd } },
{ "polyh", {"rhrwab", 0x75fd } },
{ "cvthg", {"rhwg", 0x76fd } },
/* undefined opcodes here */
{ "clrh", {"wh", 0x7cfd } },
{ "clro", {"wo", 0x7cfd } },
{ "movo", {"rowo", 0x7dfd } },
{ "movah", {"ahwl", 0x7efd } },
{ "movao", {"aowl", 0x7efd } },
{ "pushah", {"ah", 0x7ffd } },
{ "pushao", {"ao", 0x7ffd } },
/* undefined opcodes here */
{ "cvtfh", {"rfwh", 0x98fd } },
{ "cvtfg", {"rfwg", 0x99fd } },
/* undefined opcodes here */
{ "cvthf", {"rhwf", 0xf6fd } },
{ "cvthd", {"rhwd", 0xf7fd } },
/* undefined opcodes here */
{ "bugl", {"rl", 0xfdff } },
{ "bugw", {"rw", 0xfeff } },
/* undefined opcodes here */
{ "", {"", 0} } /* empty is end sentinel */
}; /* votstrs */
/* end: vax.opcode.h */

View File

@ -15,7 +15,7 @@ foo: all
ALL_TARGETS=
# TODO: rename to enabled plugins
ARCHS=mips_gnu.mk x86_cs.mk sparc_cs.mk sparc_gnu.mk java.mk bf.mk arm_gnu.mk dalvik.mk
ARCHS+=x86_as.mk x86_nz.mk cris_gnu.mk
ARCHS+=x86_as.mk x86_nz.mk cris_gnu.mk vax.mk
ARCHS+=ppc_gnu.mk ppc_cs.mk x86_olly.mk x86_udis.mk csr.mk x86_nasm.mk avr.mk
ARCHS+=sh.mk arm_winedbg.mk tms320.mk gb.mk snes.mk ebc.mk malbolge.mk ws.mk
ARCHS+=6502.mk h8300.mk cr16.mk v850.mk spc700.mk propeller.mk msp430.mk i4004.mk z80_cr.mk

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2014 - nibble */
/* radare - LGPL - Copyright 2009-2015 - nibble */
#include <stdio.h>
#include <stdarg.h>
@ -44,12 +44,12 @@ static int buf_fprintf(void *stream, const char *format, ...) {
if (buf_global == NULL)
return 0;
va_start (ap, format);
flen = strlen (format);
glen = strlen (buf_global);
tmp = malloc (flen + glen + 2);
memcpy (tmp, buf_global, glen);
memcpy (tmp+glen, format, flen);
tmp[flen+glen] = 0;
flen = strlen (format);
glen = strlen (buf_global);
tmp = malloc (flen + glen + 2);
memcpy (tmp, buf_global, glen);
memcpy (tmp+glen, format, flen);
tmp[flen+glen] = 0;
// XXX: overflow here?
vsprintf (buf_global, tmp, ap);
va_end (ap);

110
libr/asm/p/asm_vax.c Normal file
View File

@ -0,0 +1,110 @@
/* radare - LGPL - Copyright 2015 - pancake */
// TODO: add support for the assembler
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <r_types.h>
#include <r_util.h>
#include <r_lib.h>
#include <r_asm.h>
#include "dis-asm.h"
#include "../arch/vax/vax.h"
static unsigned long Offset = 0;
static char *buf_global = NULL;
static ut8 *bytes = NULL;
static int bytes_size = 0;
static int vax_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
int delta = (memaddr - Offset);
if (delta<0) {
return -1; // disable backward reads
}
//if ((delta+length)>4) return -1;
memcpy (myaddr, bytes+delta, R_MIN (length, bytes_size));
return 0;
}
static int symbol_at_address(bfd_vma addr, struct disassemble_info * info) {
return 0;
}
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info) {
//--
}
static void print_address(bfd_vma address, struct disassemble_info *info) {
char tmp[32];
if (!buf_global) return;
sprintf (tmp, "0x%08"PFMT64x, (ut64)address);
strcat (buf_global, tmp);
}
static int buf_fprintf(void *stream, const char *format, ...) {
int flen, glen;
va_list ap;
char *tmp;
if (buf_global == NULL)
return 0;
va_start (ap, format);
flen = strlen (format);
glen = strlen (buf_global);
tmp = malloc (flen + glen + 2);
memcpy (tmp, buf_global, glen);
memcpy (tmp+glen, format, flen);
tmp[flen+glen] = 0;
// XXX: overflow here?
vsprintf (buf_global, tmp, ap);
va_end (ap);
free (tmp);
return 0;
}
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
struct disassemble_info disasm_obj;
op->buf_asm[0]='\0';
if (len<4)
return -1;
buf_global = op->buf_asm;
bytes = buf;
bytes_size = len;
Offset = a->pc;
/* prepare disassembler */
memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
disasm_obj.buffer = bytes;
disasm_obj.read_memory_func = &vax_buffer_read_memory;
disasm_obj.symbol_at_address_func = &symbol_at_address;
disasm_obj.memory_error_func = &memory_error_func;
disasm_obj.print_address_func = &print_address;
disasm_obj.endian = !a->big_endian;
disasm_obj.fprintf_func = &buf_fprintf;
disasm_obj.stream = stdout;
op->size = print_insn_vax ((bfd_vma)Offset, &disasm_obj);
if (op->size == -1)
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
return op->size;
}
RAsmPlugin r_asm_plugin_vax = {
.name = "vax",
.arch = "vax",
.license = "GPL",
.bits = 8 | 32,
.desc = "VAX",
.disassemble = &disassemble
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_vax,
.version = R2_VERSION
};
#endif

13
libr/asm/p/vax.mk Normal file
View File

@ -0,0 +1,13 @@
OBJ_VAX=asm_vax.o
OBJ_VAX+=../arch/vax/vax-dis.o
STATIC_OBJ+=${OBJ_VAX}
TARGET_VAX=asm_vax.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_VAX}
${TARGET_VAX}: ${OBJ_VAX}
${CC} $(call libname,asm_vax) ${LDFLAGS} \
-I../arch/vax ${CFLAGS} -o asm_vax.${EXT_SO} ${OBJ_VAX}
endif

View File

@ -896,6 +896,8 @@ char* Elf_(r_bin_elf_get_arch)(struct Elf_(r_bin_elf_obj_t) *bin) {
return strdup ("microblaze.gnu");
case EM_RISCV:
return strdup ("riscv");
case EM_VAX:
return strdup ("vax");
case EM_SH: return strdup ("sh");
default: return strdup ("x86");
}

View File

@ -1536,6 +1536,7 @@ extern RAnalPlugin r_anal_plugin_v810;
extern RAnalPlugin r_anal_plugin_6502;
extern RAnalPlugin r_anal_plugin_snes;
extern RAnalPlugin r_anal_plugin_riscv;
extern RAnalPlugin r_anal_plugin_vax;
#ifdef __cplusplus
}
#endif

View File

@ -221,6 +221,7 @@ extern RAsmPlugin r_asm_plugin_v810;
extern RAsmPlugin r_asm_plugin_mcs96;
extern RAsmPlugin r_asm_plugin_lm32;
extern RAsmPlugin r_asm_plugin_riscv;
extern RAsmPlugin r_asm_plugin_vax;
#endif
#ifdef __cplusplus

View File

@ -35,6 +35,7 @@ anal.x86_udis
anal.xcore_cs
anal.z80
anal.v810
anal.vax
anal.6502
anal.snes
anal.riscv
@ -91,6 +92,7 @@ asm.z80
asm.z80_cr
asm.lh5801
asm.v810
asm.vax
asm.mcs96
bin.any
bin.art