Rizin
unix-like reverse engineering framework and cli tools
asm_rsp.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016 bobby.smiles32 <bobby.smiles32@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 // TODO: add assembler
4 
5 #include <rz_types.h>
6 #include <rz_util.h>
7 #include <rz_asm.h>
8 #include <rz_lib.h>
9 
10 #include <stdarg.h>
11 #include <stdio.h>
12 
13 #include "rsp_idec.h"
14 
15 static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
16  rsp_instruction rz_instr;
17  int i;
18 
19  /* all instructions are 32bit words */
20  if (len < 4) {
21  op->size = 0;
22  return 0;
23  }
24  op->size = 4;
25 
26  ut32 iw = rz_read_ble32(buf, a->big_endian);
27  rz_instr = rsp_instruction_decode(a->pc, iw);
28 
29  rz_strbuf_append(&op->buf_asm, rz_instr.mnemonic);
30  for (i = 0; i < rz_instr.noperands; i++) {
31  rz_strbuf_append(&op->buf_asm, (i == 0) ? " " : ", ");
32 
33  switch (rz_instr.operands[i].type) {
34  case RSP_OPND_GP_REG:
35  rz_strbuf_append(&op->buf_asm, rsp_gp_reg_soft_names[rz_instr.operands[i].u]);
36  break;
37  case RSP_OPND_OFFSET:
38  case RSP_OPND_TARGET:
39  rz_strbuf_appendf(&op->buf_asm, "0x%08" PFMT64x, rz_instr.operands[i].u);
40  break;
41  case RSP_OPND_ZIMM: {
42  int shift = (rz_instr.operands[i].u & ~0xffff) ? 16 : 0;
43  rz_strbuf_appendf(&op->buf_asm, "0x%04" PFMT64x,
44  rz_instr.operands[i].u >> shift);
45  } break;
46  case RSP_OPND_SIMM:
47  rz_strbuf_appendf(&op->buf_asm, "%s0x%04" PFMT64x,
48  (rz_instr.operands[i].s < 0) ? "-" : "",
49  (rz_instr.operands[i].s < 0) ? -rz_instr.operands[i].s : rz_instr.operands[i].s);
50  break;
52  rz_strbuf_appendf(&op->buf_asm, "%" PFMT64u, rz_instr.operands[i].u);
53  break;
55  rz_strbuf_appendf(&op->buf_asm, "%s0x%04x(%s)",
56  (rz_instr.operands[i].s < 0) ? "-" : "",
57  (ut32)((rz_instr.operands[i].s < 0) ? -rz_instr.operands[i].s : rz_instr.operands[i].s),
58  rsp_gp_reg_soft_names[rz_instr.operands[i].u]);
59  break;
60  case RSP_OPND_C0_REG:
61  rz_strbuf_append(&op->buf_asm, rsp_c0_reg_soft_names[rz_instr.operands[i].u]);
62  break;
63  case RSP_OPND_C2_CREG:
64  rz_strbuf_append(&op->buf_asm, rsp_c2_creg_names[rz_instr.operands[i].u]);
65  break;
66  case RSP_OPND_C2_ACCU:
67  rz_strbuf_append(&op->buf_asm, rsp_c2_accu_names[rz_instr.operands[i].u]);
68  break;
69  case RSP_OPND_C2_VREG:
70  rz_strbuf_append(&op->buf_asm, rsp_c2_vreg_names[rz_instr.operands[i].u]);
71  break;
74  rz_strbuf_appendf(&op->buf_asm, "%s[%u]", rsp_c2_vreg_names[rz_instr.operands[i].u],
75  (ut32)rz_instr.operands[i].s);
76  break;
78  rz_strbuf_appendf(&op->buf_asm, "%s%s", rsp_c2_vreg_names[rz_instr.operands[i].u], rsp_c2_vreg_element_names[rz_instr.operands[i].s]);
79  break;
80  default: /* should not happend */
81  rz_strbuf_append(&op->buf_asm, "???");
82  break;
83  }
84  }
85 
86  return op->size;
87 }
88 
90  .name = "rsp",
91  .desc = "Reality Signal Processor",
92  .arch = "rsp",
93  .bits = 32,
94  .endian = RZ_SYS_ENDIAN_BI, /* For conveniance, we don't force BIG endian but allow both to be used */
95  .license = "LGPL3",
96  .disassemble = &disassemble
97 };
98 
99 #ifndef RZ_PLUGIN_INCORE
102  .data = &rz_asm_plugin_rsp,
104 };
105 #endif
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
Definition: arm_il32.c:190
RZ_API RzLibStruct rizin_plugin
Definition: asm_rsp.c:100
RzAsmPlugin rz_asm_plugin_rsp
Definition: asm_rsp.c:89
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_rsp.c:15
#define RZ_API
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
rsp_instruction rsp_instruction_decode(ut64 pc, ut32 iw)
Definition: rsp_idec.c:587
const char * rsp_c0_reg_soft_names[]
Definition: rsp_idec.c:13
const char * rsp_gp_reg_soft_names[]
Definition: rsp_idec.c:6
const char * rsp_c2_vreg_names[]
Definition: rsp_idec.c:68
const char * rsp_c2_accu_names[]
Definition: rsp_idec.c:64
const char * rsp_c2_creg_names[]
Definition: rsp_idec.c:60
const char * rsp_c2_vreg_element_names[]
Definition: rsp_idec.c:75
@ RSP_OPND_OFFSET
Definition: rsp_idec.h:150
@ RSP_OPND_BASE_OFFSET
Definition: rsp_idec.h:154
@ RSP_OPND_C2_ACCU
Definition: rsp_idec.h:157
@ RSP_OPND_C2_CREG
Definition: rsp_idec.h:156
@ RSP_OPND_SIMM
Definition: rsp_idec.h:152
@ RSP_OPND_C0_REG
Definition: rsp_idec.h:155
@ RSP_OPND_SHIFT_AMOUNT
Definition: rsp_idec.h:153
@ RSP_OPND_ZIMM
Definition: rsp_idec.h:151
@ RSP_OPND_C2_VREG_ELEMENT
Definition: rsp_idec.h:161
@ RSP_OPND_C2_VREG
Definition: rsp_idec.h:158
@ RSP_OPND_C2_VREG_BYTE
Definition: rsp_idec.h:159
@ RSP_OPND_C2_VREG_SCALAR
Definition: rsp_idec.h:160
@ RSP_OPND_TARGET
Definition: rsp_idec.h:149
@ RSP_OPND_GP_REG
Definition: rsp_idec.h:148
static ut32 rz_read_ble32(const void *src, bool big_endian)
Definition: rz_endian.h:497
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define RZ_SYS_ENDIAN_BI
Definition: rz_types.h:528
#define PFMT64u
Definition: rz_types.h:395
#define PFMT64x
Definition: rz_types.h:393
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
rsp_operand operands[RSP_MAX_OPNDS]
Definition: rsp_idec.h:176
const char * mnemonic
Definition: rsp_idec.h:173
rsp_operand_type type
Definition: rsp_idec.h:165
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
Definition: dis.c:32