Rizin
unix-like reverse engineering framework and cli tools
asm_cris_gnu.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "disas-asm.h"

Go to the source code of this file.

Functions

static int cris_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info)
 
static int symbol_at_address (bfd_vma addr, struct disassemble_info *info)
 
static void memory_error_func (int status, bfd_vma memaddr, struct disassemble_info *info)
 
bfd_boolean cris_parse_disassembler_options (disassemble_info *info, int distype)
 
int print_insn_crisv10_v32_with_register_prefix (bfd_vma vma, disassemble_info *info)
 
int print_insn_crisv10_v32_without_register_prefix (bfd_vma vma, disassemble_info *info)
 
int print_insn_cris_with_register_prefix (bfd_vma vma, disassemble_info *info)
 
int print_insn_cris_without_register_prefix (bfd_vma vma, disassemble_info *info)
 
int print_insn_crisv32_with_register_prefix (bfd_vma vma, disassemble_info *info)
 
int print_insn_crisv32_without_register_prefix (bfd_vma vma, disassemble_info *info)
 
static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 

Variables

static unsigned long Offset = 0
 
static RzStrBufbuf_global = NULL
 
static unsigned char bytes [8]
 
RzAsmPlugin rz_asm_plugin_cris_gnu
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ cris_buffer_read_memory()

static int cris_buffer_read_memory ( bfd_vma  memaddr,
bfd_byte myaddr,
ut32  length,
struct disassemble_info info 
)
static

Definition at line 28 of file asm_cris_gnu.c.

28  {
29  int delta = (memaddr - Offset);
30  if (delta < 0) {
31  return -1; // disable backward reads
32  }
33  if ((delta + length) > 8) {
34  return -1;
35  }
36  memcpy(myaddr, bytes + delta, length);
37  return 0;
38 }
static unsigned char bytes[8]
Definition: asm_cris_gnu.c:26
static unsigned long Offset
Definition: asm_cris_gnu.c:24
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 length
Definition: sflib.h:133
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static st64 delta
Definition: vmenus.c:2425

References bytes, delta, length, memcpy(), and Offset.

Referenced by disassemble().

◆ cris_parse_disassembler_options()

bfd_boolean cris_parse_disassembler_options ( disassemble_info info,
int  distype 
)

Referenced by disassemble().

◆ disassemble()

static int disassemble ( RzAsm a,
RzAsmOp op,
const ut8 buf,
int  len 
)
static

Definition at line 61 of file asm_cris_gnu.c.

61  {
62  struct disassemble_info disasm_obj;
63  int mode = 2;
64  if (len < 4) {
65  return -1;
66  }
67  buf_global = &op->buf_asm;
68  Offset = a->pc;
69  memcpy(bytes, buf, RZ_MIN(len, 8)); // TODO handle thumb
70 
71  /* prepare disassembler */
72  memset(&disasm_obj, '\0', sizeof(struct disassemble_info));
73  disasm_obj.disassembler_options = (a->bits == 64) ? "64" : "";
74  disasm_obj.buffer = bytes;
75  disasm_obj.read_memory_func = &cris_buffer_read_memory;
76  disasm_obj.symbol_at_address_func = &symbol_at_address;
77  disasm_obj.memory_error_func = &memory_error_func;
78  disasm_obj.print_address_func = &generic_print_address_func;
79  disasm_obj.endian = !a->big_endian;
80  disasm_obj.fprintf_func = &generic_fprintf_func;
81  disasm_obj.stream = stdout;
82 
83  if (a->cpu && *a->cpu) {
84  // enum cris_disass_family { cris_dis_v0_v10, cris_dis_common_v10_v32, cris_dis_v32 };
85  // 0: v0-v10
86  // 1: v10-v32
87  // 2: v32
88  mode = 0;
89  if (strstr(a->cpu, "v10")) {
90  mode = 1;
91  }
92  if (strstr(a->cpu, "v32")) {
93  mode = 2;
94  }
95  } else {
96  mode = 2;
97  }
98  (void)cris_parse_disassembler_options(&disasm_obj, mode);
99  if (a->syntax == RZ_ASM_SYNTAX_ATT) {
100  switch (mode) {
101  case 0:
102  op->size = print_insn_cris_with_register_prefix((bfd_vma)Offset, &disasm_obj);
103  break;
104  case 1:
106  break;
107  default:
109  break;
110  }
111  } else {
112  switch (mode) {
113  case 0:
115  break;
116  case 1:
118  break;
119  default:
121  break;
122  }
123  }
124  if (op->size == -1) {
125  rz_strbuf_set(&op->buf_asm, "(data)");
126  }
127  return op->size;
128 }
size_t len
Definition: 6502dis.c:15
int print_insn_cris_without_register_prefix(bfd_vma vma, disassemble_info *info)
Definition: cris-dis.c:1594
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info)
Definition: asm_cris_gnu.c:44
int print_insn_crisv32_without_register_prefix(bfd_vma vma, disassemble_info *info)
Definition: cris-dis.c:1606
int print_insn_cris_with_register_prefix(bfd_vma vma, disassemble_info *info)
Definition: cris-dis.c:1557
int print_insn_crisv32_with_register_prefix(bfd_vma vma, disassemble_info *info)
Definition: cris-dis.c:1569
int print_insn_crisv10_v32_with_register_prefix(bfd_vma vma, disassemble_info *info)
Definition: cris-dis.c:1582
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info)
Definition: asm_cris_gnu.c:40
static RzStrBuf * buf_global
Definition: asm_cris_gnu.c:25
static int cris_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info)
Definition: asm_cris_gnu.c:28
bfd_boolean cris_parse_disassembler_options(disassemble_info *info, int distype)
int print_insn_crisv10_v32_without_register_prefix(bfd_vma vma, disassemble_info *info)
Definition: cris-dis.c:1619
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)
BFD_HOST_U_64_BIT bfd_vma
Definition: mybfd.h:111
@ RZ_ASM_SYNTAX_ATT
Definition: rz_asm.h:51
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
#define RZ_MIN(x, y)
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32

References a, buf_global, disassemble_info::buffer, bytes, cris_buffer_read_memory(), cris_parse_disassembler_options(), disassemble_info::disassembler_options, disassemble_info::endian, disassemble_info::fprintf_func, len, memcpy(), memory_error_func(), disassemble_info::memory_error_func, memset(), Offset, disassemble_info::print_address_func, print_insn_cris_with_register_prefix(), print_insn_cris_without_register_prefix(), print_insn_crisv10_v32_with_register_prefix(), print_insn_crisv10_v32_without_register_prefix(), print_insn_crisv32_with_register_prefix(), print_insn_crisv32_without_register_prefix(), disassemble_info::read_memory_func, RZ_ASM_SYNTAX_ATT, RZ_MIN, rz_strbuf_set(), disassemble_info::stream, symbol_at_address(), and disassemble_info::symbol_at_address_func.

◆ memory_error_func()

static void memory_error_func ( int  status,
bfd_vma  memaddr,
struct disassemble_info info 
)
static

Definition at line 44 of file asm_cris_gnu.c.

44  {
45  //--
46 }

Referenced by disassemble().

◆ print_insn_cris_with_register_prefix()

int print_insn_cris_with_register_prefix ( bfd_vma  vma,
disassemble_info info 
)

Definition at line 1557 of file cris-dis.c.

1559 {
1560  if (!info->private_data && !cris_parse_disassembler_options (info, cris_dis_v0_v10)) {
1561  return -1;
1562  }
1563  return print_insn_cris_generic (vma, info, TRUE);
1564 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
bfd_boolean cris_parse_disassembler_options(disassemble_info *info, enum cris_disass_family distype)
Definition: cris-dis.c:106
@ cris_dis_v0_v10
Definition: cris-dis.c:73
int print_insn_cris_generic(bfd_vma memaddr, disassemble_info *info, bfd_boolean with_reg_prefix)
Definition: cris-dis.c:1387
#define TRUE
Definition: mybfd.h:103

References cris_dis_v0_v10, cris_parse_disassembler_options(), info(), print_insn_cris_generic(), and TRUE.

Referenced by cris_get_disassembler(), and disassemble().

◆ print_insn_cris_without_register_prefix()

int print_insn_cris_without_register_prefix ( bfd_vma  vma,
disassemble_info info 
)

Definition at line 1594 of file cris-dis.c.

1596 {
1597  if (!info->private_data && !cris_parse_disassembler_options (info, cris_dis_v0_v10)) {
1598  return -1;
1599  }
1600  return print_insn_cris_generic (vma, info, FALSE);
1601 }
#define FALSE
Definition: mybfd.h:102

References cris_dis_v0_v10, cris_parse_disassembler_options(), FALSE, info(), and print_insn_cris_generic().

Referenced by cris_get_disassembler(), and disassemble().

◆ print_insn_crisv10_v32_with_register_prefix()

int print_insn_crisv10_v32_with_register_prefix ( bfd_vma  vma,
disassemble_info info 
)

Definition at line 1582 of file cris-dis.c.

1584 {
1586  return -1;
1587  }
1588  return print_insn_cris_generic (vma, info, TRUE);
1589 }
@ cris_dis_common_v10_v32
Definition: cris-dis.c:73

References cris_dis_common_v10_v32, cris_parse_disassembler_options(), info(), print_insn_cris_generic(), and TRUE.

Referenced by cris_get_disassembler(), and disassemble().

◆ print_insn_crisv10_v32_without_register_prefix()

int print_insn_crisv10_v32_without_register_prefix ( bfd_vma  vma,
disassemble_info info 
)

Definition at line 1619 of file cris-dis.c.

1621 {
1623  return -1;
1624  }
1625  return print_insn_cris_generic (vma, info, FALSE);
1626 }

References cris_dis_common_v10_v32, cris_parse_disassembler_options(), FALSE, info(), and print_insn_cris_generic().

Referenced by cris_get_disassembler(), and disassemble().

◆ print_insn_crisv32_with_register_prefix()

int print_insn_crisv32_with_register_prefix ( bfd_vma  vma,
disassemble_info info 
)

Definition at line 1569 of file cris-dis.c.

1571 {
1572  if (!info->private_data && !cris_parse_disassembler_options (info, cris_dis_v32)) {
1573  return -1;
1574  }
1575  return print_insn_cris_generic (vma, info, TRUE);
1576 }
@ cris_dis_v32
Definition: cris-dis.c:73

References cris_dis_v32, cris_parse_disassembler_options(), info(), print_insn_cris_generic(), and TRUE.

Referenced by cris_get_disassembler(), and disassemble().

◆ print_insn_crisv32_without_register_prefix()

int print_insn_crisv32_without_register_prefix ( bfd_vma  vma,
disassemble_info info 
)

Definition at line 1606 of file cris-dis.c.

1608 {
1609  if (!info->private_data && !cris_parse_disassembler_options (info, cris_dis_v32)) {
1610  return -1;
1611  }
1612  return print_insn_cris_generic (vma, info, FALSE);
1613 }

References cris_dis_v32, cris_parse_disassembler_options(), FALSE, info(), and print_insn_cris_generic().

Referenced by cris_get_disassembler(), and disassemble().

◆ symbol_at_address()

static int symbol_at_address ( bfd_vma  addr,
struct disassemble_info info 
)
static

Definition at line 40 of file asm_cris_gnu.c.

40  {
41  return 0;
42 }

Referenced by disassemble().

Variable Documentation

◆ buf_global

RzStrBuf* buf_global = NULL
static

Definition at line 25 of file asm_cris_gnu.c.

Referenced by disassemble().

◆ bytes

unsigned char bytes[8]
static

Definition at line 26 of file asm_cris_gnu.c.

Referenced by cris_buffer_read_memory(), and disassemble().

◆ Offset

unsigned long Offset = 0
static

Definition at line 24 of file asm_cris_gnu.c.

Referenced by cris_buffer_read_memory(), and disassemble().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_cris_gnu
Definition: asm_cris_gnu.c:130
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_asm.h:133

Definition at line 143 of file asm_cris_gnu.c.

◆ rz_asm_plugin_cris_gnu

RzAsmPlugin rz_asm_plugin_cris_gnu
Initial value:
= {
.name = "cris",
.arch = "cris",
.cpus = "v0,v10,v32",
.license = "GPL3",
.author = "pancake",
.bits = 32,
.desc = "Axis Communications 32-bit embedded processor",
.disassemble = &disassemble
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_cris_gnu.c:61
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 130 of file asm_cris_gnu.c.