Migrate lh5801 plugin + add missing regprofile ##arch

This commit is contained in:
Luc Tielen 2023-03-28 20:13:18 +02:00 committed by GitHub
parent a215f295a8
commit 561032abe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 113 additions and 74 deletions

View File

@ -25,7 +25,7 @@ anal.i8080
anal.java
arch.kvx
arch.lanai
anal.lh5801
arch.lh5801
arch.lm32
anal.loongarch_gnu
anal.m680x_cs

View File

@ -17,7 +17,7 @@ anal.h8300
anal.i8080
anal.java
arch.kvx
anal.lh5801
arch.lh5801
anal.m68k_cs
anal.m680x_cs
arch.mcore

View File

@ -14,7 +14,7 @@ anal.h8300
anal.i8080
anal.java
arch.kvx
anal.lh5801
arch.lh5801
arch.xtensa
arch.mcore
anal.mips_gnu

View File

@ -14,7 +14,7 @@ anal.i8080
anal.java
anal.hppa_gnu
arch.kvx
anal.lh5801
arch.lh5801
arch.lm32
anal.m68k_cs
anal.mips_cs

View File

@ -20,7 +20,7 @@ arch.ws
arch.xap
anal.x86_cs
anal.xcore_cs
anal.lh5801
arch.lh5801
arch.6502
arch.snes
arch.riscv

View File

@ -6,7 +6,7 @@ anal.bf
anal.dalvik
anal.gb
anal.java
anal.lh5801
arch.lh5801
anal.mips_cs
anal.mips_gnu
anal.null

View File

@ -42,7 +42,7 @@ r_anal_sources = [
'p/anal_6502_cs.c',
'p/anal_8051.c',
# 'arch/p/arc/plugin.c',
# '../arch/p/arc/plugin.c',
# 'arch/arc/gnu/arc-dis.c',
# 'arch/arc/gnu/arc-opc.c',
# 'arch/arc/gnu/arc-ext.c',
@ -59,7 +59,7 @@ r_anal_sources = [
'p/anal_h8300.c',
'p/anal_i8080.c',
'p/anal_java.c',
'p/anal_lh5801.c',
'../arch/p/lh5801/plugin.c',
'p/anal_m680x_cs.c',
'p/anal_m68k_cs.c',
'p/anal_m68k_gnu.c',

View File

@ -1,52 +0,0 @@
/* radare2, Sharp LH5801 disassembler.
* (C) Copyright 2014-2015 jn, published under the LGPLv3 */
#include "../arch/lh5801/lh5801.c"
#include <r_anal.h>
#include <r_types.h>
#include <r_lib.h>
static int lh5801_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
struct lh5801_insn insn = {0};
if (!op) {
return 0;
}
int consumed = lh5801_decode (&insn, buf, len);
if (consumed == -1 || consumed == 0) {
if (mask & R_ARCH_OP_MASK_DISASM) {
op->mnemonic = strdup ("invalid");
}
op->size = 1;
return 0;
}
if (mask & R_ARCH_OP_MASK_DISASM) {
const int buf_len = 128;
char *buf_asm = calloc (buf_len, 1);
if (buf_asm) {
lh5801_print_insn (buf_asm, buf_len, &insn);
op->mnemonic = buf_asm;
}
}
op->size = consumed;
//op->payload = lh5801_insn_descs[insn.type].format & 3;
// ^ MAYBE?
return op->size;
}
RAnalPlugin r_anal_plugin_lh5801 = {
.name = "lh5801",
.arch = "LH5801",
.license = "LGPL3",
.bits = 8,
.endian = R_SYS_ENDIAN_NONE,
.desc = "SHARP LH5801 disassembler",
.op = &lh5801_op
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_lh5801,
.version = R2_VERSION
};
#endif

View File

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

View File

@ -80,6 +80,7 @@ r_arch_sources = [
'p/pdp11/plugin.c',
'p/pdp11/pdp11-dis.c',
'p/pdp11/pdp11-opc.c',
'p/lh5801/plugin.c',
]
if arch_plugins.contains('x86_nz')

View File

@ -1,7 +1,7 @@
/* radare - LGPL - Copyright 2012-2022 - pancake */
#include <r_lib.h>
#include <r_anal.h>
#include <r_arch.h>
#include "disas-asm.h"
#include <mybfd.h>

11
libr/arch/p/lh5801.mk Normal file
View File

@ -0,0 +1,11 @@
OBJ_LH5801=p/lh5801/plugin.o
STATIC_OBJ+=${OBJ_LH5801}
TARGET_LH5801=lh5801.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_LH5801}
${TARGET_LH5801}: ${OBJ_LH5801}
${CC} ${call libname,lh5801} ${CFLAGS} -o ${TARGET_LH5801} ${OBJ_LH5801}
endif

View File

@ -0,0 +1,90 @@
/* radare2, Sharp LH5801 disassembler.
* (C) Copyright 2014-2015 jn, published under the LGPLv3 */
#include "./lh5801.c"
#include <r_arch.h>
static bool decode(RArchSession *as, RAnalOp *op, RAnalOpMask mask) {
struct lh5801_insn insn = {0};
const int len = op->size;
const ut8 *buf = op->bytes;
if (!op || len < 1) {
return false;
}
int consumed = lh5801_decode (&insn, buf, len);
if (consumed == -1 || consumed == 0) {
if (mask & R_ARCH_OP_MASK_DISASM) {
op->mnemonic = strdup ("invalid");
}
op->size = 1;
return false;
}
if (mask & R_ARCH_OP_MASK_DISASM) {
const int buf_len = 128;
char *buf_asm = calloc (buf_len, 1);
if (buf_asm) {
lh5801_print_insn (buf_asm, buf_len, &insn);
op->mnemonic = buf_asm;
}
}
op->size = consumed;
//op->payload = lh5801_insn_descs[insn.type].format & 3;
// ^ MAYBE?
return op->size > 0;
}
static int info(RArchSession *as, ut32 q) {
return 0;
}
static char* regs(RArchSession *as) {
const char *reg =
"=PC PC\n"
"=A0 A\n"
"=A1 UH\n"
"=A2 UL\n"
"=A3 XH\n"
"=A4 XL\n"
"=A5 YH\n"
"=A6 YL\n"
"gpr PC .16 0 0\n"
"gpr A .8 2 0\n"
"flg F .8 3 0\n"
"flg H .1 4.4 0\n"
"flg V .1 4.5 0\n"
"flg Z .1 4.6 0\n"
"flg C .1 4.8 0\n"
"gpr U .16 4 0\n"
"gpr UH .8 4 0\n"
"gpr UL .8 5 0\n"
"gpr X .16 6 0\n"
"gpr XH .8 6 0\n"
"gpr XL .8 7 0\n"
"gpr Y .16 8 0\n"
"gpr YH .8 8 0\n"
"gpr YL .8 9 0\n";
return strdup (reg);
}
RArchPlugin r_arch_plugin_lh5801 = {
.name = "lh5801",
.arch = "LH5801",
.license = "LGPL3",
.bits = R_SYS_BITS_PACK1 (8),
.endian = R_SYS_ENDIAN_NONE,
.desc = "SHARP LH5801 disassembler",
.decode = &decode,
.info = info,
.regs = regs,
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ARCH,
.data = &r_arch_plugin_lh5801,
.version = R2_VERSION
};
#endif

View File

@ -1575,7 +1575,6 @@ extern RAnalPlugin r_anal_plugin_gb;
extern RAnalPlugin r_anal_plugin_h8300;
extern RAnalPlugin r_anal_plugin_i8080;
extern RAnalPlugin r_anal_plugin_java;
extern RAnalPlugin r_anal_plugin_lh5801;
extern RAnalPlugin r_anal_plugin_m68k_cs;
extern RAnalPlugin r_anal_plugin_m680x_cs;
extern RAnalPlugin r_anal_plugin_mips_cs;

View File

@ -319,6 +319,7 @@ extern RArchPlugin r_arch_plugin_cris;
extern RArchPlugin r_arch_plugin_cr16;
extern RArchPlugin r_arch_plugin_arc;
extern RArchPlugin r_arch_plugin_pdp11;
extern RArchPlugin r_arch_plugin_lh5801;
#ifdef __cplusplus
}

View File

@ -7,6 +7,7 @@ asm_plugins = [ 'null' ]
anal_plugins = [ 'null' ]
arch_plugins = [ 'null',
# 'arc',
'lh5801',
'sh',
'x86_nz',
'alpha',
@ -163,7 +164,6 @@ anal_plugins += [
'h8300',
'i8080',
'java',
'lh5801',
'loongarch_gnu',
'm68k_cs',
'm68k_gnu',