Rizin
unix-like reverse engineering framework and cli tools
asm_mcs96.c File Reference
#include <rz_types.h>
#include <string.h>
#include <rz_asm.h>
#include <rz_lib.h>
#include "../arch/mcs96/mcs96.h"

Go to the source code of this file.

Functions

static int mcs96_len (const ut8 *buf, int len, RzStrBuf *asm_buf)
 
static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 

Variables

RzAsmPlugin rz_asm_plugin_mcs96
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ disassemble()

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

Definition at line 102 of file asm_mcs96.c.

102  {
103  if (len > 1 && !memcmp(buf, "\xff\xff", 2)) {
104  return -1;
105  }
106  op->size = mcs96_len(buf, len, &op->buf_asm);
107  return op->size;
108 }
size_t len
Definition: 6502dis.c:15
static int mcs96_len(const ut8 *buf, int len, RzStrBuf *asm_buf)
Definition: asm_mcs96.c:10
voidpf void * buf
Definition: ioapi.h:138
Definition: dis.c:32

References len, and mcs96_len().

◆ mcs96_len()

static int mcs96_len ( const ut8 buf,
int  len,
RzStrBuf asm_buf 
)
static

Definition at line 10 of file asm_mcs96.c.

10  {
11  int ret = 1;
12  if (buf[0] == 0xfe) {
13  if (len < 2) {
14  return 0;
15  }
16  if (mcs96_op[buf[1]].type & MCS96_FE) {
17  if (mcs96_op[buf[1]].type & MCS96_5B_OR_6B) {
18  if (len < 3) {
19  return 0;
20  }
21  ret = 6 + (buf[2] & 0x1);
22  }
23  if (mcs96_op[buf[1]].type & MCS96_4B_OR_5B) {
24  if (len < 3) {
25  return 0;
26  }
27  ret = 5 + (buf[2] & 0x1);
28  }
29  if (mcs96_op[buf[1]].type & MCS96_3B_OR_4B) {
30  if (len < 3) {
31  return 0;
32  }
33  ret = 4 + (buf[1] & 0x1);
34  }
35  if (mcs96_op[buf[1]].type & MCS96_5B) {
36  ret = 6;
37  }
38  if (mcs96_op[buf[1]].type & MCS96_4B) {
39  ret = 5;
40  }
41  if (mcs96_op[buf[1]].type & MCS96_3B) {
42  ret = 4;
43  }
44  if (mcs96_op[buf[1]].type & MCS96_2B) {
45  ret = 3;
46  }
47  if (ret <= len) {
48  const ut32 fe_idx = ((buf[1] & 0x70) >> 4) ^ 0x4;
49  rz_strbuf_set(asm_buf, mcs96_fe_op[fe_idx]);
50  if ((mcs96_op[buf[1]].type & (MCS96_2OP | MCS96_REG_8)) == (MCS96_2OP | MCS96_REG_8) &&
51  buf[2] > 0x19 && buf[3] > 0x19) {
52  rz_strbuf_appendf(asm_buf, " rb%02x, rb%02x", buf[2] - 0x1a, buf[3] - 0x1a);
53  }
54  } else {
55  ret = 0;
56  }
57  return ret;
58  }
59  }
60  if (mcs96_op[buf[0]].type & MCS96_5B_OR_6B) {
61  if (len < 2) {
62  return 0;
63  }
64  ret = 5 + (buf[1] & 0x1);
65  }
66  if (mcs96_op[buf[0]].type & MCS96_4B_OR_5B) {
67  if (len < 2) {
68  return 0;
69  }
70  ret = 4 + (buf[1] & 0x1);
71  }
72  if (mcs96_op[buf[0]].type & MCS96_3B_OR_4B) {
73  if (len < 2) {
74  return 0;
75  }
76  ret = 3 + (buf[1] & 0x1);
77  }
78  if (mcs96_op[buf[0]].type & MCS96_5B) {
79  ret = 5;
80  }
81  if (mcs96_op[buf[0]].type & MCS96_4B) {
82  ret = 4;
83  }
84  if (mcs96_op[buf[0]].type & MCS96_3B) {
85  ret = 3;
86  }
87  if (mcs96_op[buf[0]].type & MCS96_2B) {
88  ret = 2;
89  }
90  if (ret <= len) {
91  rz_strbuf_set(asm_buf, mcs96_op[buf[0]].ins);
92  if ((mcs96_op[buf[0]].type & (MCS96_2OP | MCS96_REG_8)) == (MCS96_2OP | MCS96_REG_8) &&
93  buf[1] > 0x19 && buf[2] > 0x19) {
94  rz_strbuf_appendf(asm_buf, " rb%02x, rb%02x", buf[1] - 0x1a, buf[2] - 0x1a);
95  }
96  } else {
97  ret = 0;
98  }
99  return ret;
100 }
uint32_t ut32
#define MCS96_FE
Definition: mcs96.h:29
#define MCS96_3B
Definition: mcs96.h:14
#define MCS96_2OP
Definition: mcs96.h:22
static const char * mcs96_fe_op[]
Definition: mcs96.h:291
#define MCS96_REG_8
Definition: mcs96.h:27
#define MCS96_4B
Definition: mcs96.h:15
#define MCS96_4B_OR_5B
Definition: mcs96.h:19
#define MCS96_5B
Definition: mcs96.h:16
#define MCS96_5B_OR_6B
Definition: mcs96.h:20
#define MCS96_3B_OR_4B
Definition: mcs96.h:18
#define MCS96_2B
Definition: mcs96.h:13
static Mcs96Op mcs96_op[]
Definition: mcs96.h:31
int type
Definition: mipsasm.c:17
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2

References len, MCS96_2B, MCS96_2OP, MCS96_3B, MCS96_3B_OR_4B, MCS96_4B, MCS96_4B_OR_5B, MCS96_5B, MCS96_5B_OR_6B, MCS96_FE, mcs96_fe_op, mcs96_op, MCS96_REG_8, rz_strbuf_appendf(), rz_strbuf_set(), and type.

Referenced by disassemble().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_mcs96
Definition: asm_mcs96.c:110
@ 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 121 of file asm_mcs96.c.

◆ rz_asm_plugin_mcs96

RzAsmPlugin rz_asm_plugin_mcs96
Initial value:
= {
.name = "mcs96",
.desc = "condrets car",
.arch = "mcs96",
.license = "LGPL3",
.bits = 16,
.endian = RZ_SYS_ENDIAN_NONE,
.disassemble = &disassemble
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_mcs96.c:102
#define RZ_SYS_ENDIAN_NONE
Definition: rz_types.h:525

Definition at line 110 of file asm_mcs96.c.