radare2/libr/asm/p/asm_m68k.c
Damien Zammit af0a865d9f WIP - Totally remove host endianness dependence
- 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>
2016-05-04 23:42:17 +10:00

58 lines
1.3 KiB
C

/* radare - GPL3 - Copyright 2009-2015 - nibble */
#include <stdio.h>
#include <string.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_asm.h>
#include "m68k/m68k_disasm/m68k_disasm.h"
static int disassemble(RAsm *a, RAsmOp *aop, const ut8 *buf, int len) {
m68k_word bof[8] = {0};
int iaddr = (int)a->pc;
char opcode[256], operands[256];
const unsigned char *buf2;
int ilen ;
static struct DisasmPara_68k dp;
/* initialize DisasmPara */
*operands = *opcode = 0;
memcpy (bof, buf, R_MIN(len, sizeof(bof)));
dp.opcode = opcode;
dp.operands = operands;
dp.iaddr = (m68k_word *) (size_t)iaddr;
dp.instr = bof;
buf2 = (const ut8*)M68k_Disassemble (&dp);
if (!buf2) {
// invalid instruction
return aop->size = 2;
}
ilen = (buf2-(const ut8*)bof);
if (*operands)
snprintf (aop->buf_asm, R_ASM_BUFSIZE, "%s %s", opcode, operands);
else snprintf (aop->buf_asm, R_ASM_BUFSIZE, "%s", opcode);
r_str_rmch (aop->buf_asm, '#');
aop->size = ilen;
return aop->size;
}
RAsmPlugin r_asm_plugin_m68k = {
.name = "m68k",
.arch = "m68k",
.license = "BSD",
.bits = 16|32,
.endian = R_SYS_ENDIAN_BIG,
.desc = "Motorola 68000",
.disassemble = &disassemble,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_m68k,
.version = R2_VERSION
};
#endif