Add wip archinfo and wip regs and make mcs96 an arch plugin ##arch

This commit is contained in:
pancake 2023-03-29 17:15:21 +02:00 committed by pancake
parent df330b9107
commit 2175715b0a
4 changed files with 68 additions and 3 deletions

View File

@ -111,9 +111,54 @@ static bool decode(RArchSession *as, RAnalOp *op, RArchDecodeMask mask) {
if (mask & R_ARCH_OP_MASK_DISASM) {
// do nothing
}
if (r_str_startswith (op->mnemonic, "invalid")) {
return false;
}
return ilen > 0;
}
// WORDs must be aligned at even byte boundaries in the address space.
static int archinfo(RArchSession *as, ut32 q) {
// R2_590
switch (q) {
case R_ANAL_ARCHINFO_ALIGN:
return 1;
case R_ANAL_ARCHINFO_DATA_ALIGN:
return 2; // data alignment depends on word size used
#if 0
case R_ARCH_INFO_DATA4_ALIGN:
return 4;
case R_ARCH_INFO_DATA8_ALIGN:
return 8;
#endif
case R_ANAL_ARCHINFO_MAX_OP_SIZE:
return 5;
case R_ANAL_ARCHINFO_MIN_OP_SIZE:
return 1;
}
return 0;
}
// 512 bytes register RAM
// window selection registers
// PSW, INT_MASK, INT_MASK1
// http://datasheets.chipdb.org/Intel/MCS96/MANUALS/27231703.PDF
static char *regs(RArchSession *s) {
const char *p =
"=PC pc\n"
"=SP r3\n"
"=A0 r0\n"
"=ZF z\n"
"=SF s\n"
"=OF ov\n"
"=CF cy\n"
"gpr pc .32 0 0\n"
"gpr psw .32 4 0\n"
"gpr int_mask .32 8 0\n"
"gpr int_mask1 .32 12 0\n"
;
return strdup (p);
}
RArchPlugin r_arch_plugin_mcs96 = {
.name = "mcs96",
.desc = "Intel MCS96 microcontroller, also known as 8xC196 or 80196",
@ -121,13 +166,15 @@ RArchPlugin r_arch_plugin_mcs96 = {
.license = "LGPL3",
.decode = &decode,
.author = "condret",
.bits = R_SYS_BITS_PACK1 (16),
.regs = regs,
.info = archinfo,
.bits = R_SYS_BITS_PACK3 (16, 32, 64), // can work with 64bit registers too
.endian = R_SYS_ENDIAN_NONE,
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.type = R_LIB_TYPE_ARCH,
.data = &r_arch_plugin_mcs96,
.version = R2_VERSION
};

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2015-2022 - danielps, pancake */
/* radare - LGPL - Copyright 2015-2023 - danielps, pancake */
#include <r_arch.h>
#include "./v810_disas.h"
@ -447,6 +447,19 @@ static char *v810_regs(RArchSession *s) {
return strdup (p);
}
static int archinfo(RArchSession *as, ut32 q) {
switch (q) {
case R_ANAL_ARCHINFO_ALIGN:
case R_ANAL_ARCHINFO_DATA_ALIGN:
return 2;
case R_ANAL_ARCHINFO_MAX_OP_SIZE:
return 8;
case R_ANAL_ARCHINFO_MIN_OP_SIZE:
return 2;
}
return 0;
}
RArchPlugin r_arch_plugin_v810 = {
.name = "v810",
.desc = "V810 code analysis plugin",
@ -455,6 +468,7 @@ RArchPlugin r_arch_plugin_v810 = {
.bits = R_SYS_BITS_PACK1 (32),
.decode = v810_decode,
.regs = v810_regs,
.info = archinfo,
};
#ifndef R2_PLUGIN_INCORE

View File

@ -22,6 +22,9 @@ typedef enum {
#define R_ARCH_INFO_INV_OP_SIZE 2
#define R_ARCH_INFO_ALIGN 4
#define R_ARCH_INFO_DATA_ALIGN 8
#define R_ARCH_INFO_DATA2_ALIGN 16
#define R_ARCH_INFO_DATA4_ALIGN 32
#define R_ARCH_INFO_DATA8_ALIGN 64
#else
#define USE_REG_NAMES 0
#define R_ANAL_ARCHINFO_MIN_OP_SIZE 0

View File

@ -77,6 +77,7 @@ cd "$(dirname $0)"/..
(git grep -n -e 'eprintf ("Could' -e 'eprintf ("Failed' -e 'eprintf ("Cannot' libr \
| grep -v -e ^libr/core/cmd -e ^libr/main/ -e ^libr/util/syscmd \
| grep -v -e r_cons_eprintf -e alloc) && exit 1
(git grep R_LIB_TYPE_ANAL libr/arch/p) && exit 1
(
# ensure c++ compat