Rizin
unix-like reverse engineering framework and cli tools
arc-dis.h File Reference

Go to the source code of this file.

Classes

struct  arcDisState
 

Macros

#define __TRANSLATION_REQUIRED(state)   ((state).acnt != 0)
 

Enumerations

enum  NullifyMode { BR_exec_when_no_jump , BR_exec_always , BR_exec_when_jump }
 
enum  ARC_Debugger_OperandType {
  ARC_UNDEFINED , ARC_LIMM , ARC_SHIMM , ARC_REGISTER ,
  ARCOMPACT_REGISTER
}
 
enum  Flow {
  noflow , direct_jump , direct_call , indirect_jump ,
  indirect_call , invalid_instr
}
 
enum  { no_reg = 99 }
 
enum  { allOperandsSize = 256 }
 

Functions

int ARCompact_decodeInstr (bfd_vma address, disassemble_info *info)
 

Macro Definition Documentation

◆ __TRANSLATION_REQUIRED

#define __TRANSLATION_REQUIRED (   state)    ((state).acnt != 0)

Definition at line 110 of file arc-dis.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
no_reg 

Definition at line 55 of file arc-dis.h.

55 { no_reg = 99 };
@ no_reg
Definition: arc-dis.h:55

◆ anonymous enum

anonymous enum
Enumerator
allOperandsSize 

Definition at line 56 of file arc-dis.h.

56 { allOperandsSize = 256 };
@ allOperandsSize
Definition: arc-dis.h:56

◆ ARC_Debugger_OperandType

Enumerator
ARC_UNDEFINED 
ARC_LIMM 
ARC_SHIMM 
ARC_REGISTER 
ARCOMPACT_REGISTER 

Definition at line 34 of file arc-dis.h.

35 {
37  ARC_LIMM,
38  ARC_SHIMM,
40  ARCOMPACT_REGISTER /* Valid only for the
41  registers allowed in
42  16 bit mode */
43 };
@ ARC_SHIMM
Definition: arc-dis.h:38
@ ARCOMPACT_REGISTER
Definition: arc-dis.h:40
@ ARC_UNDEFINED
Definition: arc-dis.h:36
@ ARC_LIMM
Definition: arc-dis.h:37
@ ARC_REGISTER
Definition: arc-dis.h:39

◆ Flow

enum Flow
Enumerator
noflow 
direct_jump 
direct_call 
indirect_jump 
indirect_call 
invalid_instr 

Definition at line 45 of file arc-dis.h.

46 {
47  noflow,
53 };
@ invalid_instr
Definition: arc-dis.h:52
@ indirect_jump
Definition: arc-dis.h:50
@ direct_jump
Definition: arc-dis.h:48
@ indirect_call
Definition: arc-dis.h:51
@ direct_call
Definition: arc-dis.h:49
@ noflow
Definition: arc-dis.h:47

◆ NullifyMode

Enumerator
BR_exec_when_no_jump 
BR_exec_always 
BR_exec_when_jump 

Definition at line 27 of file arc-dis.h.

28 {
32 };
@ BR_exec_when_jump
Definition: arc-dis.h:31
@ BR_exec_when_no_jump
Definition: arc-dis.h:29
@ BR_exec_always
Definition: arc-dis.h:30

Function Documentation

◆ ARCompact_decodeInstr()

int ARCompact_decodeInstr ( bfd_vma  address,
disassemble_info info 
)

Definition at line 3722 of file arcompact-dis.c.

3723  {
3724  int status;
3725  bfd_byte buffer[4];
3726  struct arcDisState s; /* ARC Disassembler state */
3727  void *stream = info->stream; /* output stream */
3728  fprintf_ftype func = info->fprintf_func;
3729  int bytes;
3730  int lowbyte, highbyte;
3731  char buf[256];
3732 
3733  if (info->disassembler_options) {
3734  parse_disassembler_options(info->disassembler_options);
3735 
3736  /* To avoid repeated parsing of these options, we remove them here. */
3737  info->disassembler_options = NULL;
3738  }
3739 
3740  lowbyte = ((info->endian == BFD_ENDIAN_LITTLE) ? 1 : 0);
3741  highbyte = ((info->endian == BFD_ENDIAN_LITTLE) ? 0 : 1);
3742 
3743  memset(&s, 0, sizeof(struct arcDisState));
3744 
3745  /* read first instruction */
3746  status = (*info->read_memory_func)(address, buffer, 2, info);
3747 
3748  if (status != 0) {
3749  (*info->memory_error_func)(status, address, info);
3750  return -1;
3751  }
3752 
3753  if (((buffer[lowbyte] & 0xf8) > 0x38) && ((buffer[lowbyte] & 0xf8) != 0x48)) {
3754  s.instructionLen = 2;
3755  s.words[0] = (buffer[lowbyte] << 8) | buffer[highbyte];
3756  (*info->read_memory_func)(address + 2, buffer, 4, info);
3757  if (info->endian == BFD_ENDIAN_LITTLE) {
3758  s.words[1] = bfd_getl32(buffer);
3759  } else {
3760  s.words[1] = bfd_getb32(buffer);
3761  }
3762  } else {
3763  s.instructionLen = 4;
3764  status = (*info->read_memory_func)(address + 2, &buffer[2], 2, info);
3765  if (status != 0) {
3766  (*info->memory_error_func)(status, address + 2, info);
3767  return -1;
3768  }
3769  if (info->endian == BFD_ENDIAN_LITTLE) {
3770  s.words[0] = bfd_getl32(buffer);
3771  } else {
3772  s.words[0] = bfd_getb32(buffer);
3773  }
3774 
3775  /* always read second word in case of limm */
3776  /* we ignore the result since last insn may not have a limm */
3777  (*info->read_memory_func)(address + 4, buffer, 4, info);
3778  if (info->endian == BFD_ENDIAN_LITTLE) {
3779  s.words[1] = bfd_getl32(buffer);
3780  } else {
3781  s.words[1] = bfd_getb32(buffer);
3782  }
3783  }
3784 
3785  s._this = &s;
3786  s.coreRegName = _coreRegName;
3787  s.auxRegName = _auxRegName;
3788  s.condCodeName = _condCodeName;
3789  s.instName = _instName;
3790 
3791  /* disassemble */
3792  bytes = dsmOneArcInst(address, (void *)&s, info);
3793 
3794  /* display the disassembled instruction */
3795  {
3796  char *instr = s.instrBuffer;
3797  char *operand = s.operandBuffer;
3798  char *space = strchr(instr, ' ');
3799 
3800  if (enable_insn_stream) {
3801  /* Show instruction stream from MSB to LSB*/
3802 
3803  if (s.instructionLen == 2) {
3804  (*func)(stream, " %04x ", (unsigned int)s.words[0]);
3805  } else {
3806  (*func)(stream, "%08x ", (unsigned int)s.words[0]);
3807  }
3808 
3809  (*func)(stream, " ");
3810  }
3811 
3812  /* if the operand is actually in the instruction buffer */
3813  if ((space != NULL) && (operand[0] == '\0')) {
3814  *space = '\0';
3815  operand = space + 1;
3816  }
3817 
3818  (*func)(stream, "%s ", instr);
3819 
3820  if (__TRANSLATION_REQUIRED(s)) {
3821  bfd_vma addr;
3822  char *tmpBuffer;
3823  int i = 1;
3824 
3825  if (operand[0] != '@') {
3826  /* Branch instruction with 3 operands, Translation is required
3827  only for the third operand. Print the first 2 operands */
3828  strncpy(buf, operand, sizeof(buf));
3829  buf[sizeof(buf) - 1] = '\0';
3830  tmpBuffer = strtok(buf, "@");
3831  (*func)(stream, "%s", tmpBuffer);
3832  i = strlen(tmpBuffer) + 1;
3833  }
3834 
3835  addr = s.addresses[operand[i] - '0'];
3836  (*info->print_address_func)((bfd_vma)addr, info);
3837  //(*func) (stream, "\n");
3838  } else {
3839  (*func)(stream, "%s", operand);
3840  }
3841  }
3842 
3843  /* We print max bytes for instruction */
3844  info->bytes_per_line = 8;
3845 
3846  return bytes; // s.instructionLen;
3847 }
lzma_index ** i
Definition: index.h:629
#define __TRANSLATION_REQUIRED(state)
Definition: arc-dis.h:110
operand
Definition: arc-opc.c:39
static int dsmOneArcInst(bfd_vma addr, struct arcDisState *state, disassemble_info *info)
static const char * _coreRegName(void *_this ATTRIBUTE_UNUSED, int v)
static const char * _instName(void *_this ATTRIBUTE_UNUSED, int op1, int op2, int *flags)
static const char * _auxRegName(void *_this ATTRIBUTE_UNUSED, int v)
static void parse_disassembler_options(char *options)
static const char * _condCodeName(void *_this ATTRIBUTE_UNUSED, int v)
static ut8 bytes[32]
Definition: asm_arc.c:23
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
#define NULL
Definition: cris-opc.c:27
int(* fprintf_ftype)(void *, const char *,...) ATTRIBUTE_FPTR_PRINTF_2
Definition: disas-asm.h:45
voidpf stream
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
unsigned char bfd_byte
Definition: mybfd.h:176
BFD_HOST_U_64_BIT bfd_vma
Definition: mybfd.h:111
static bfd_vma bfd_getb32(const void *p)
Definition: mybfd.h:4979
@ BFD_ENDIAN_LITTLE
Definition: mybfd.h:4618
static bfd_vma bfd_getl32(const void *p)
Definition: mybfd.h:4990
static RzSocket * s
Definition: rtr.c:28
static int
Definition: sfsocketcall.h:114
Definition: buffer.h:15
static int addr
Definition: z80asm.c:58