mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-04 12:36:30 +00:00
af0a865d9f
- Adds endian aware functions - Removes references to host endian - Uses binary detected endianness else tries LE and restricts by RAsmPlugin - Fixes gdb debugger endianness when debugging BE qemu gdbserver Signed-off-by: Damien Zammit <damien@zamaudio.com>
72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
/* radare2 - LGPL - Copyright 2013-2015 - pancake */
|
|
|
|
// instruction set : http://www.tachyonsoft.com/inst390m.htm
|
|
|
|
#include <r_asm.h>
|
|
#include <r_lib.h>
|
|
#include <capstone/capstone.h>
|
|
|
|
static csh cd = 0;
|
|
|
|
static bool the_end(void *p) {
|
|
if (cd) {
|
|
cs_close (&cd);
|
|
cd = 0;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
|
static int omode = 0;
|
|
int mode, n, ret;
|
|
ut64 off = a->pc;
|
|
cs_insn* insn = NULL;
|
|
mode = CS_MODE_BIG_ENDIAN;
|
|
if (cd && mode != omode) {
|
|
cs_close (&cd);
|
|
cd = 0;
|
|
}
|
|
op->size = 0;
|
|
omode = mode;
|
|
if (cd == 0) {
|
|
ret = cs_open (CS_ARCH_SYSZ, mode, &cd);
|
|
if (ret) return 0;
|
|
cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
|
|
}
|
|
n = cs_disasm (cd, (const ut8*)buf, len, off, 1, &insn);
|
|
if (n>0) {
|
|
if (insn->size>0) {
|
|
op->size = insn->size;
|
|
char *ptrstr;
|
|
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
|
insn->mnemonic, insn->op_str[0]?" ":"",
|
|
insn->op_str);
|
|
ptrstr = strstr (op->buf_asm, "ptr ");
|
|
if (ptrstr) {
|
|
memmove (ptrstr, ptrstr+4, strlen (ptrstr+4)+1);
|
|
}
|
|
}
|
|
cs_free (insn, n);
|
|
}
|
|
return op->size;
|
|
}
|
|
|
|
RAsmPlugin r_asm_plugin_sysz = {
|
|
.name = "sysz",
|
|
.desc = "SystemZ CPU disassembler",
|
|
.license = "BSD",
|
|
.arch = "sysz",
|
|
.bits = 32,
|
|
.endian = R_SYS_ENDIAN_BIG,
|
|
.fini = the_end,
|
|
.disassemble = &disassemble,
|
|
};
|
|
|
|
#ifndef CORELIB
|
|
struct r_lib_struct_t radare_plugin = {
|
|
.type = R_LIB_TYPE_ASM,
|
|
.data = &r_asm_plugin_sysz,
|
|
.version = R2_VERSION
|
|
};
|
|
#endif
|