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

Go to the source code of this file.

Functions

void arc_print_disassembler_options (FILE *stream)
 
struct arcDisState arcAnalyzeInstr (bfd_vma address, disassemble_info *info)
 
int ARCompact_decodeInstr (bfd_vma address, disassemble_info *info)
 

Function Documentation

◆ arc_print_disassembler_options()

void arc_print_disassembler_options ( FILE *  stream)

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

3925  {
3926  fprintf(stream, "\n\
3927  ARC-specific disassembler options:\n\
3928  use with the -M switch, with options separated by commas\n\n");
3929 
3930  fprintf(stream, " insn-stream Show the instruction byte stream from most\n");
3931  fprintf(stream, " significant byte to least significant byte (excluding LIMM).\n");
3932  fprintf(stream, " This option is useful for viewing the actual encoding of instructions.\n");
3933 
3934  fprintf(stream, " simd Enable SIMD instructions disassembly.\n\n");
3935 }
voidpf stream
Definition: ioapi.h:138

◆ arcAnalyzeInstr()

struct arcDisState arcAnalyzeInstr ( bfd_vma  address,
disassemble_info info 
)

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

3858  {
3859  int status;
3860  bfd_byte buffer[4];
3861  struct arcDisState s; /* ARC Disassembler state */
3862  int bytes;
3863  int lowbyte, highbyte;
3864 
3865  lowbyte = ((info->endian == BFD_ENDIAN_LITTLE) ? 1 : 0);
3866  highbyte = ((info->endian == BFD_ENDIAN_LITTLE) ? 0 : 1);
3867 
3868  memset(&s, 0, sizeof(struct arcDisState));
3869 
3870  /* read first instruction */
3871  status = (*info->read_memory_func)(address, buffer, 2, info);
3872 
3873  if (status != 0) {
3874  (*info->memory_error_func)(status, address, info);
3875  s.instructionLen = -1;
3876  return s;
3877  }
3878 
3879  if (((buffer[lowbyte] & 0xf8) > 0x38) && ((buffer[lowbyte] & 0xf8) != 0x48)) {
3880  s.instructionLen = 2;
3881  s.words[0] = (buffer[lowbyte] << 8) | buffer[highbyte];
3882  (*info->read_memory_func)(address + 2, buffer, 4, info);
3883  if (info->endian == BFD_ENDIAN_LITTLE) {
3884  s.words[1] = bfd_getl32(buffer);
3885  } else {
3886  s.words[1] = bfd_getb32(buffer);
3887  }
3888  } else {
3889  s.instructionLen = 4;
3890  status = (*info->read_memory_func)(address + 2, &buffer[2], 2, info);
3891  if (status != 0) {
3892  (*info->memory_error_func)(status, address + 2, info);
3893  s.instructionLen = -1;
3894  return s;
3895  }
3896  if (info->endian == BFD_ENDIAN_LITTLE) {
3897  s.words[0] = bfd_getl32(buffer);
3898  } else {
3899  s.words[0] = bfd_getb32(buffer);
3900  }
3901 
3902  /* always read second word in case of limm */
3903  /* we ignore the result since last insn may not have a limm */
3904  (*info->read_memory_func)(address + 4, buffer, 4, info);
3905  if (info->endian == BFD_ENDIAN_LITTLE) {
3906  s.words[1] = bfd_getl32(buffer);
3907  } else {
3908  s.words[1] = bfd_getb32(buffer);
3909  }
3910  }
3911 
3912  s._this = &s;
3913  s.coreRegName = _coreRegName;
3914  s.auxRegName = _auxRegName;
3915  s.condCodeName = _condCodeName;
3916  s.instName = _instName;
3917 
3918  /* disassemble */
3919  bytes = dsmOneArcInst(address, (void *)&s, info);
3920  /* We print max bytes for instruction */
3921  info->bytes_per_line = bytes;
3922  return s;
3923 }
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 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
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
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
Definition: buffer.h:15

References __TRANSLATION_REQUIRED, _auxRegName(), _condCodeName(), _coreRegName(), _instName(), addr, BFD_ENDIAN_LITTLE, bfd_getb32(), bfd_getl32(), bytes, dsmOneArcInst(), i, info(), int, memset(), NULL, parse_disassembler_options(), s, and status.

◆ 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 void parse_disassembler_options(char *options)
#define NULL
Definition: cris-opc.c:27
int(* fprintf_ftype)(void *, const char *,...) ATTRIBUTE_FPTR_PRINTF_2
Definition: disas-asm.h:45
voidpf void * buf
Definition: ioapi.h:138
BFD_HOST_U_64_BIT bfd_vma
Definition: mybfd.h:111
static int
Definition: sfsocketcall.h:114
static int addr
Definition: z80asm.c:58