Move asm.snes into anal.snes ##asm

This commit is contained in:
pancake 2022-05-16 12:33:27 +02:00 committed by GitHub
parent 88a36ca9ea
commit a2c2036997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 66 additions and 124 deletions

View File

@ -95,7 +95,6 @@ asm.riscv_cs
asm.rsp
asm.lanai_gnu
asm.sh
asm.snes
asm.sparc_cs
asm.sparc_gnu
asm.tms320

View File

@ -89,7 +89,6 @@ asm.riscv_cs
asm.rsp
asm.lanai_gnu
asm.sh
asm.snes
asm.sparc_cs
asm.sparc_gnu
asm.tms320

View File

@ -73,7 +73,6 @@ asm.riscv
asm.rsp
asm.lanai_gnu
asm.sh
asm.snes
asm.sparc_gnu
asm.tms320
asm.v850

View File

@ -122,5 +122,4 @@ parse.v850_pseudo
parse.wasm_pseudo
parse.x86_pseudo"
SHARED="asm.6502
asm.snes
io.shm"

View File

@ -62,7 +62,6 @@ asm.propeller
asm.riscv
asm.lanai_gnu
asm.sh
asm.snes
asm.sparc_cs
asm.sparc_gnu
asm.xap

View File

@ -42,7 +42,6 @@ asm.nios2
asm.propeller
asm.riscv
asm.sh
asm.snes
asm.sparc_cs
asm.xap
asm.arm_as

View File

@ -60,7 +60,6 @@ asm.ppc_gnu
asm.riscv
asm.riscv_cs
asm.rsp
asm.snes
asm.sparc_cs
asm.sparc_gnu
asm.tms320

View File

@ -6,18 +6,75 @@
#include <r_asm.h>
#include <r_anal.h>
#include "../../asm/arch/snes/snes_op_table.h"
#include "../../asm/p/asm_snes.h"
static R_TH_LOCAL struct snes_asm_flags* snesflags = NULL;
struct snes_asm_flags {
unsigned char M;
unsigned char X;
};
static R_TH_LOCAL struct snes_asm_flags snesflags = {0};
static char *snes_disass(ut64 pc, const ut8 *buf, int len) {
int M_flag = snesflags.M;
int X_flag = snesflags.X;
snes_op_t *s_op = &snes_op[buf[0]];
int op_len = snes_op_get_size (M_flag, X_flag, s_op);
if (len < op_len) {
return 0;
}
const char *buf_asm = "invalid";
r_strf_buffer (64);
switch (s_op->len) {
case SNES_OP_8BIT:
buf_asm = s_op->name;
break;
case SNES_OP_16BIT:
if (*buf % 0x20 == 0x10 || *buf == 0x80) { // relative branch
buf_asm = r_strf (s_op->name, (ut32)(pc + 2 + (st8)buf[1]));
} else {
buf_asm = r_strf (s_op->name, buf[1]);
}
break;
case SNES_OP_24BIT:
if (*buf == 0x44 || *buf == 0x54) { // mvp and mvn
buf_asm = r_strf (s_op->name, buf[1], buf[2]);
} else if (*buf == 0x82) { // brl
buf_asm = r_strf (s_op->name, pc + 3 + (st16)ut8p_bw(buf + 1));
} else {
buf_asm = r_strf (s_op->name, ut8p_bw (buf + 1));
}
break;
case SNES_OP_32BIT:
buf_asm = r_strf (s_op->name, buf[1]|buf[2]<<8|buf[3]<<16);
break;
case SNES_OP_IMM_M:
if (M_flag) {
buf_asm = r_strf ("%s #0x%02x", s_op->name, buf[1]);
} else {
buf_asm = r_strf ("%s #0x%04x", s_op->name, ut8p_bw (buf + 1));
}
break;
case SNES_OP_IMM_X:
if (X_flag) {
buf_asm = r_strf ("%s #0x%02x", s_op->name, buf[1]);
} else {
buf_asm = r_strf ("%s #0x%04x", s_op->name, ut8p_bw (buf + 1));
}
break;
}
return strdup (buf_asm);
}
static int snes_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) {
op->size = snes_op_get_size(snesflags->M, snesflags->X, &snes_op[data[0]]);
op->size = snes_op_get_size(snesflags.M, snesflags.X, &snes_op[data[0]]);
if (op->size > len) {
return op->size = 0;
}
op->nopcode = 1;
op->addr = addr;
op->type = R_ANAL_OP_TYPE_UNK;
if (mask & R_ANAL_OP_MASK_DISASM) {
op->mnemonic = snes_disass (addr, data, len);
}
switch (data[0]) {
case 0xea: // nop
op->type = R_ANAL_OP_TYPE_NOP;
@ -220,46 +277,30 @@ static int snes_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l
break;
case 0xc2: // rep
if (((st8)data[1]) & 0x10) {
snesflags->X = 0;
snesflags.X = 0;
}
if (((st8)data[1]) & 0x20) {
snesflags->M = 0;
snesflags.M = 0;
}
break;
case 0xe2: // sep
if (((st8)data[1]) & 0x10) {
snesflags->X = 1;
snesflags.X = 1;
}
if (((st8)data[1]) & 0x20) {
snesflags->M = 1;
snesflags.M = 1;
}
break;
}
return op->size;
}
static int snes_anal_init(void* user) {
if (!snesflags) {
snesflags = malloc (sizeof (struct snes_asm_flags));
}
memset(snesflags,0,sizeof (struct snes_asm_flags));
return 0;
}
static int snes_anal_fini(void* user) {
free(snesflags);
snesflags = NULL;
return 0;
}
RAnalPlugin r_anal_plugin_snes = {
.name = "snes",
.desc = "SNES analysis plugin",
.license = "LGPL3",
.arch = "snes",
.bits = 16,
.init = snes_anal_init,
.fini = snes_anal_fini,
.bits = 8 | 16,
.op = &snes_anop,
};

View File

@ -47,7 +47,6 @@ r_asm_sources = [
join_paths('p','asm_riscv.c'),
join_paths('p','asm_rsp.c'),
join_paths('p','asm_sh.c'),
join_paths('p','asm_snes.c'),
join_paths('p','asm_sparc_cs.c'),
join_paths('p','asm_sparc_gnu.c'),
join_paths('p','asm_tms320.c'),
@ -130,7 +129,6 @@ r_asm_sources = [
#join_paths('arch','riscv','riscv.c'),
join_paths('arch','rsp','rsp_idec.c'),
join_paths('arch','sh','gnu','sh-dis.c'),
#join_paths('arch','snes','snesdis.c'),
join_paths('arch','sparc','gnu','sparc-dis.c'),
join_paths('arch','sparc','gnu','sparc-opc.c'),
join_paths('arch','tms320','c55x_plus','c55plus.c'),

View File

@ -20,7 +20,7 @@ ALL_TARGETS=
ARCHS=mips_gnu.mk x86_cs.mk sparc_cs.mk sparc_gnu.mk java.mk arm_gnu.mk dalvik.mk
ARCHS+=x86_as.mk x86_nz.mk cris_gnu.mk vax.mk arc.mk
ARCHS+=ppc_gnu.mk ppc_as.mk ppc_cs.mk xap.mk x86_nasm.mk avr.mk
ARCHS+=sh.mk arm_winedbg.mk tms320.mk gb.mk snes.mk ebc.mk malbolge.mk
ARCHS+=sh.mk arm_winedbg.mk tms320.mk gb.mk ebc.mk malbolge.mk
ARCHS+=6502.mk h8300.mk cr16.mk v850.mk propeller.mk i4004.mk
ARCHS+=lh5801.mk v810.mk mcs96.mk lm32.mk jdh8.mk
ARCHS+=riscv.mk rsp.mk mcore.mk

View File

@ -1,68 +0,0 @@
/* radare - LGPL - Copyright 2012-2021 - condret, pancake */
#include <r_types.h>
#include <r_util.h>
#include <r_asm.h>
#include <r_lib.h>
#include "../arch/snes/snesdis.c"
#include "asm_snes.h"
static R_TH_LOCAL struct snes_asm_flags* snesflags = NULL;
static bool snes_asm_init(void* user) {
if (!snesflags) {
snesflags = malloc (sizeof (struct snes_asm_flags));
}
memset(snesflags,0,sizeof (struct snes_asm_flags));
return 0;
}
static bool snes_asm_fini(void* user) {
free(snesflags);
snesflags = NULL;
return 0;
}
static int dis(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int dlen = snesDisass (snesflags->M, snesflags->X, a->pc, op, buf, len);
if (dlen < 0) {
dlen = 0;
}
op->size = dlen;
if (buf[0] == 0xc2) { //REP
if (buf[1] & 0x10) {
snesflags->X = 0;
}
if (buf[1] & 0x20) {
snesflags->M = 0;
}
} else if (buf[0] == 0xe2) { //SEP
if (buf[1] & 0x10) {
snesflags->X = 1;
}
if (buf[1] & 0x20) {
snesflags->M = 1;
}
}
return dlen;
}
RAsmPlugin r_asm_plugin_snes = {
.name = "snes",
.desc = "SuperNES CPU",
.arch = "snes",
.bits = 8|16,
.init = snes_asm_init,
.fini = snes_asm_fini,
.endian = R_SYS_ENDIAN_LITTLE,
.license = "LGPL3",
.disassemble = &dis
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_snes,
.version = R2_VERSION
};
#endif

View File

@ -1,9 +0,0 @@
#ifndef ASM_P_ASM_SNES_H
#define ASM_P_ASM_SNES_H
struct snes_asm_flags {
unsigned char M;
unsigned char X;
};
#endif

View File

@ -1,11 +0,0 @@
OBJ_SNES=asm_snes.o
STATIC_OBJ+=${OBJ_SNES}
TARGET_SNES=asm_snes.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_SNES}
${TARGET_SNES}: ${OBJ_SNES}
${CC} ${call libname,asm_snes} ${CFLAGS} -o ${TARGET_SNES} ${OBJ_SNES}
endif

View File

@ -225,7 +225,6 @@ extern RAsmPlugin r_asm_plugin_riscv;
extern RAsmPlugin r_asm_plugin_riscv_cs;
extern RAsmPlugin r_asm_plugin_rsp;
extern RAsmPlugin r_asm_plugin_sh;
extern RAsmPlugin r_asm_plugin_snes;
extern RAsmPlugin r_asm_plugin_sparc_cs;
extern RAsmPlugin r_asm_plugin_sparc_gnu;
extern RAsmPlugin r_asm_plugin_tms320;

View File

@ -211,7 +211,6 @@ asm_plugins += [
'riscv',
'rsp',
'sh',
'snes',
'sparc_cs',
'tms320',
'v810',