Rizin
unix-like reverse engineering framework and cli tools
vax-dis.c File Reference
#include "sysdep.h"
#include <setjmp.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "vax.h"
#include "disas-asm.h"

Go to the source code of this file.

Classes

struct  private
 

Macros

#define COERCE_SIGNED_CHAR(ch)   ((signed char)(ch))
 
#define NEXTBYTE(p)
 
#define COERCE16(x)   ((int)(((x) ^ 0x8000) - 0x8000))
 
#define NEXTWORD(p)
 
#define COERCE32(x)   ((int)(((x) ^ 0x80000000) - 0x80000000))
 
#define NEXTLONG(p)
 
#define MAXLEN   25
 
#define FETCH_DATA(info, addr)
 

Functions

static int fetch_data (struct disassemble_info *info, bfd_byte *addr)
 
static int print_insn_mode (const char *d, int size, unsigned char *p0, bfd_vma addr, disassemble_info *info)
 
static int print_insn_arg (const char *d, unsigned char *p0, bfd_vma addr, disassemble_info *info)
 
int print_insn_vax (bfd_vma memaddr, disassemble_info *info)
 

Variables

static char * reg_names []
 

Macro Definition Documentation

◆ COERCE16

#define COERCE16 (   x)    ((int)(((x) ^ 0x8000) - 0x8000))

Definition at line 65 of file vax-dis.c.

◆ COERCE32

#define COERCE32 (   x)    ((int)(((x) ^ 0x80000000) - 0x80000000))

Definition at line 71 of file vax-dis.c.

◆ COERCE_SIGNED_CHAR

#define COERCE_SIGNED_CHAR (   ch)    ((signed char)(ch))

Definition at line 57 of file vax-dis.c.

◆ FETCH_DATA

#define FETCH_DATA (   info,
  addr 
)
Value:
((addr) <= ((struct private *)((info)->private_data))->max_fetched \
? 1 \
: fetch_data((info), (addr)))
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
static int fetch_data(struct disassemble_info *info, bfd_byte *addr)
Definition: vax-dis.c:96
static int addr
Definition: z80asm.c:58

Definition at line 90 of file vax-dis.c.

◆ MAXLEN

#define MAXLEN   25

Definition at line 77 of file vax-dis.c.

◆ NEXTBYTE

#define NEXTBYTE (   p)
Value:
((p) += 1, FETCH_DATA(info, p), \
COERCE_SIGNED_CHAR((p)[-1]))
void * p
Definition: libc.cpp:67
#define FETCH_DATA(info, addr)
Definition: vax-dis.c:90

Definition at line 60 of file vax-dis.c.

◆ NEXTLONG

#define NEXTLONG (   p)
Value:
((p) += 4, FETCH_DATA(info, p), \
(COERCE32(((((((p)[-1] << 8) + (p)[-2]) << 8) + (p)[-3]) << 8) + (p)[-4])))
#define COERCE32(x)
Definition: vax-dis.c:71

Definition at line 72 of file vax-dis.c.

◆ NEXTWORD

#define NEXTWORD (   p)
Value:
((p) += 2, FETCH_DATA(info, p), \
COERCE16(((p)[-1] << 8) + (p)[-2]))

Definition at line 66 of file vax-dis.c.

Function Documentation

◆ fetch_data()

static int fetch_data ( struct disassemble_info info,
bfd_byte addr 
)
static

Definition at line 96 of file vax-dis.c.

96  {
97  int status;
98  struct private *priv = (struct private *)info->private_data;
99  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
100 
101  status = (*info->read_memory_func)(start,
102  priv->max_fetched,
103  addr - priv->max_fetched,
104  info);
105  if (status != 0) {
106  (*info->memory_error_func)(status, start, info);
107  longjmp(priv->bailout, 1);
108  } else {
109  priv->max_fetched = addr;
110  }
111 
112  return 1;
113 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
BFD_HOST_U_64_BIT bfd_vma
Definition: mybfd.h:111
bfd_byte the_buffer[MAXLEN]
Definition: vax-dis.c:82
jmp_buf bailout
Definition: vax-dis.c:84
bfd_vma insn_start
Definition: vax-dis.c:83
bfd_byte * max_fetched
Definition: vax-dis.c:81

References addr, private::bailout, info(), private::insn_start, private::max_fetched, start, status, and private::the_buffer.

◆ print_insn_arg()

static int print_insn_arg ( const char *  d,
unsigned char *  p0,
bfd_vma  addr,
disassemble_info info 
)
static

Definition at line 251 of file vax-dis.c.

254  {
255  int arg_len;
256 
257  /* Check validity of addressing length. */
258  switch (d[1]) {
259  case 'b': arg_len = 1; break;
260  case 'd': arg_len = 8; break;
261  case 'f': arg_len = 4; break;
262  case 'g': arg_len = 8; break;
263  case 'h': arg_len = 16; break;
264  case 'l': arg_len = 4; break;
265  case 'o': arg_len = 16; break;
266  case 'w': arg_len = 2; break;
267  case 'q': arg_len = 8; break;
268  default: abort();
269  }
270 
271  /* Branches have no mode byte. */
272  if (d[0] == 'b') {
273  unsigned char *p = p0;
274 
275  if (arg_len == 1) {
276  (*info->print_address_func)(addr + 1 + NEXTBYTE(p), info);
277  } else {
278  (*info->print_address_func)(addr + 2 + NEXTWORD(p), info);
279  }
280 
281  return p - p0;
282  }
283 
284  return print_insn_mode(d, arg_len, p0, addr, info);
285 }
#define d(i)
Definition: sha256.c:44
#define NEXTWORD(p)
Definition: vax-dis.c:66
static int print_insn_mode(const char *d, int size, unsigned char *p0, bfd_vma addr, disassemble_info *info)
Definition: vax-dis.c:136
#define NEXTBYTE(p)
Definition: vax-dis.c:60

References addr, d, info(), NEXTBYTE, NEXTWORD, p, and print_insn_mode().

Referenced by print_insn_vax().

◆ print_insn_mode()

static int print_insn_mode ( const char *  d,
int  size,
unsigned char *  p0,
bfd_vma  addr,
disassemble_info info 
)
static

Definition at line 136 of file vax-dis.c.

140  {
141  unsigned char *p = p0;
142  unsigned char mode, reg;
143 
144  /* Fetch and interpret mode byte. */
145  mode = (unsigned char)NEXTBYTE(p);
146  reg = mode & 0xF;
147  switch (mode & 0xF0) {
148  case 0x00:
149  case 0x10:
150  case 0x20:
151  case 0x30: /* Literal mode $number. */
152  if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h') {
153  (*info->fprintf_func)(info->stream, "$0x%x [%c-float]", mode, d[1]);
154  } else {
155  (*info->fprintf_func)(info->stream, "$0x%x", mode);
156  }
157  break;
158  case 0x40: /* Index: base-addr[Rn] */
159  p += print_insn_mode(d, size, p0 + 1, addr + 1, info);
160  (*info->fprintf_func)(info->stream, "[%s]", reg_names[reg]);
161  break;
162  case 0x50: /* Register: Rn */
163  (*info->fprintf_func)(info->stream, "%s", reg_names[reg]);
164  break;
165  case 0x60: /* Register deferred: (Rn) */
166  (*info->fprintf_func)(info->stream, "(%s)", reg_names[reg]);
167  break;
168  case 0x70: /* Autodecrement: -(Rn) */
169  (*info->fprintf_func)(info->stream, "-(%s)", reg_names[reg]);
170  break;
171  case 0x80: /* Autoincrement: (Rn)+ */
172  if (reg == 0xF) { /* Immediate? */
173  int i;
174 
175  FETCH_DATA(info, p + size);
176  (*info->fprintf_func)(info->stream, "$0x");
177  if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h') {
178  int float_word;
179 
180  float_word = p[0] | (p[1] << 8);
181  if ((d[1] == 'd' || d[1] == 'f') && (float_word & 0xff80) == 0x8000) {
182  (*info->fprintf_func)(info->stream, "[invalid %c-float]",
183  d[1]);
184  } else {
185  for (i = 0; i < size; i++) {
186  (*info->fprintf_func)(info->stream, "%02x",
187  p[size - i - 1]);
188  }
189  (*info->fprintf_func)(info->stream, " [%c-float]", d[1]);
190  }
191  } else {
192  for (i = 0; i < size; i++) {
193  (*info->fprintf_func)(info->stream, "%02x", p[size - i - 1]);
194  }
195  }
196  p += size;
197  } else {
198  (*info->fprintf_func)(info->stream, "(%s)+", reg_names[reg]);
199  }
200  break;
201  case 0x90: /* Autoincrement deferred: @(Rn)+ */
202  if (reg == 0xF) {
203  (*info->fprintf_func)(info->stream, "*0x%x", NEXTLONG(p));
204  } else {
205  (*info->fprintf_func)(info->stream, "@(%s)+", reg_names[reg]);
206  }
207  break;
208  case 0xB0: /* Displacement byte deferred: *displ(Rn). */
209  (*info->fprintf_func)(info->stream, "*");
210  // fallthrough
211  case 0xA0: /* Displacement byte: displ(Rn). */
212  if (reg == 0xF) {
213  (*info->print_address_func)(addr + 2 + NEXTBYTE(p), info);
214  } else {
215  (*info->fprintf_func)(info->stream, "0x%x(%s)", NEXTBYTE(p),
216  reg_names[reg]);
217  }
218  break;
219  case 0xD0: /* Displacement word deferred: *displ(Rn). */
220  (*info->fprintf_func)(info->stream, "*");
221  // fallthrough
222  case 0xC0: /* Displacement word: displ(Rn). */
223  if (reg == 0xF) {
224  (*info->print_address_func)(addr + 3 + NEXTWORD(p), info);
225  } else {
226  (*info->fprintf_func)(info->stream, "0x%x(%s)", NEXTWORD(p),
227  reg_names[reg]);
228  }
229  break;
230  case 0xF0: /* Displacement long deferred: *displ(Rn). */
231  (*info->fprintf_func)(info->stream, "*");
232  // fallthrough
233  case 0xE0: /* Displacement long: displ(Rn). */
234  if (reg == 0xF) {
235  (*info->print_address_func)(addr + 5 + NEXTLONG(p), info);
236  } else {
237  (*info->fprintf_func)(info->stream, "0x%x(%s)", NEXTLONG(p),
238  reg_names[reg]);
239  }
240  break;
241  }
242 
243  return p - p0;
244 }
lzma_index ** i
Definition: index.h:629
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
#define reg(n)
#define NEXTLONG(p)
Definition: vax-dis.c:72
static char * reg_names[]
Definition: vax-dis.c:34

References addr, d, FETCH_DATA, i, info(), NEXTBYTE, NEXTLONG, NEXTWORD, p, reg, and reg_names.

Referenced by print_insn_arg().

◆ print_insn_vax()

int print_insn_vax ( bfd_vma  memaddr,
disassemble_info info 
)

Definition at line 290 of file vax-dis.c.

290  {
291  // static bfd_boolean parsed_disassembler_options = FALSE;
292  const struct vot *votp;
293  const char *argp;
294  unsigned char *arg;
295  struct private priv;
296  bfd_byte *buffer = priv.the_buffer;
297 
298  info->private_data = &priv;
299  priv.max_fetched = priv.the_buffer;
300  priv.insn_start = memaddr;
301 
302  if (setjmp(priv.bailout) != 0) {
303  /* Error return. */
304  return -1;
305  }
306 
307  argp = NULL;
308  /* Check if the info buffer has more than one byte left since
309  the last opcode might be a single byte with no argument data. */
310  if (info->buffer_length - (memaddr - info->buffer_vma) > 1) {
311  FETCH_DATA(info, buffer + 2);
312  } else {
313  FETCH_DATA(info, buffer + 1);
314  buffer[1] = 0;
315  }
316 
317  for (votp = &votstrs[0]; votp->name[0]; votp++) {
318  vax_opcodeT opcode = votp->detail.code;
319 
320  /* 2 byte codes match 2 buffer pos. */
321  if ((bfd_byte)opcode == buffer[0] && (opcode >> 8 == 0 || opcode >> 8 == buffer[1])) {
322  argp = votp->detail.args;
323  break;
324  }
325  }
326  if (!argp) {
327  /* Handle undefined instructions. */
328  (*info->fprintf_func)(info->stream, ".word 0x%x",
329  (buffer[0] << 8) + buffer[1]);
330  return 2;
331  }
332 
333  /* Point at first byte of argument data, and at descriptor for first
334  argument. */
335  arg = buffer + ((votp->detail.code >> 8) ? 2 : 1);
336 
337  /* Make sure we have it in mem */
338  FETCH_DATA(info, arg);
339 
340  (*info->fprintf_func)(info->stream, "%s", votp->name);
341  if (*argp) {
342  (*info->fprintf_func)(info->stream, " ");
343  }
344 
345  while (*argp) {
346  arg += print_insn_arg(argp, arg, memaddr + arg - buffer, info);
347  argp += 2;
348  if (*argp) {
349  (*info->fprintf_func)(info->stream, ", ");
350  }
351  }
352 
353  return arg - buffer;
354 }
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
Definition: arm_esil32.c:136
struct buffer buffer
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char argp
Definition: sflib.h:62
unsigned char bfd_byte
Definition: mybfd.h:176
Definition: buffer.h:15
const char * args
Definition: vax.h:31
vax_opcodeT code
Definition: vax.h:32
Definition: vax.h:36
const char * name
Definition: vax.h:37
struct vot_wot detail
Definition: vax.h:38
static int print_insn_arg(const char *d, unsigned char *p0, bfd_vma addr, disassemble_info *info)
Definition: vax-dis.c:251
#define vax_opcodeT
Definition: vax.h:25
static const struct vot votstrs[]
Definition: vax.h:47

References arg(), argp, vot_wot::args, private::bailout, vot_wot::code, vot::detail, FETCH_DATA, info(), private::insn_start, private::max_fetched, vot::name, NULL, print_insn_arg(), private::the_buffer, vax_opcodeT, and votstrs.

Referenced by disassemble().

Variable Documentation

◆ reg_names

char* reg_names[]
static
Initial value:
= {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc"
}

Definition at line 34 of file vax-dis.c.

Referenced by print_insn_mode().