Migrate the hppa.gnu ##arch

This commit is contained in:
pancake 2023-04-09 23:20:32 +02:00 committed by GitHub
parent b5cd2f3731
commit 4968d69f18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1448 additions and 1409 deletions

View File

@ -20,7 +20,7 @@ arch.dis
arch.evm
anal.gb
arch.h8300
anal.hppa_gnu
arch.hppa_gnu
anal.i8080
anal.java
arch.kvx

View File

@ -10,7 +10,7 @@ anal.chip8
arch.lanai
arch.cris
arch.cr16
anal.hppa_gnu
arch.hppa_gnu
anal.dalvik
anal.gb
arch.h8300

View File

@ -25,7 +25,7 @@ arch.or1k
anal.ppc_gnu
arch.mcs96
anal.s390_gnu
anal.hppa_gnu
arch.hppa_gnu
arch.lm32
arch.nios2
arch.sh

View File

@ -12,7 +12,7 @@ anal.gb
arch.mcs96
anal.i8080
anal.java
anal.hppa_gnu
arch.hppa_gnu
arch.kvx
arch.lh5801
arch.lm32

View File

@ -1,79 +0,0 @@
/* radare - LGPL - Copyright 2015-2022 - pancake */
#include <r_asm.h>
#include "disas-asm.h"
static int hppa_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
int delta = (memaddr - info->buffer_vma);
if (delta < 0) {
return -1; // disable backward reads
}
if ((delta + length) > 4) {
return -1;
}
ut8 *bytes = info->buffer;
memcpy (myaddr, bytes + delta, length);
return 0;
}
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info) {
return 0;
}
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info) {
//--
}
DECLARE_GENERIC_PRINT_ADDRESS_FUNC_NOGLOBALS()
DECLARE_GENERIC_FPRINTF_FUNC_NOGLOBALS()
static int hppa_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
ut8 bytes[8] = {0};
struct disassemble_info disasm_obj = {0};
RStrBuf *sb = NULL;
if (mask & R_ARCH_OP_MASK_DISASM) {
sb = r_strbuf_new (NULL);
}
memcpy (bytes, buf, R_MIN (sizeof (bytes), len)); // TODO handle thumb
/* prepare disassembler */
disasm_obj.buffer = bytes;
disasm_obj.buffer_vma = addr;
disasm_obj.read_memory_func = &hppa_buffer_read_memory;
disasm_obj.symbol_at_address_func = &symbol_at_address;
disasm_obj.memory_error_func = &memory_error_func;
disasm_obj.print_address_func = &generic_print_address_func;
disasm_obj.endian = !R_ARCH_CONFIG_IS_BIG_ENDIAN (a->config);
disasm_obj.fprintf_func = &generic_fprintf_func;
disasm_obj.stream = sb;
op->size = print_insn_hppa ((bfd_vma)addr, &disasm_obj);
if (mask & R_ARCH_OP_MASK_DISASM) {
op->mnemonic = r_strbuf_drain (sb);
sb = NULL;
r_str_replace_ch (op->mnemonic, '\t', ' ', true);
} else {
r_strbuf_free (sb);
}
return op->size;
}
RAnalPlugin r_anal_plugin_hppa_gnu = {
.name = "hppa",
.arch = "hppa",
.license = "GPL3",
.cpus = "",
.bits = 16,
.endian = R_SYS_ENDIAN_BIG,
.desc = "HP PA-RISC",
.op = &hppa_op
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_hppa_gnu,
.version = R2_VERSION
};
#endif

View File

@ -1,12 +0,0 @@
OBJ_HPPA=anal_hppa_gnu.o
OBJ_HPPA+=../../asm/arch/hppa/gnu/hppa-dis.o
STATIC_OBJ+=${OBJ_HPPA}
TARGET_HPPA=anal_hppa_gnu.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_HPPA}
${TARGET_HPPA}: ${OBJ_HPPA}
${CC} $(call libname,anal_hppa) ${LDFLAGS} ${CFLAGS} -o anal_hppa_gnu.${EXT_SO} ${OBJ_HPPA}
endif

View File

@ -26,6 +26,10 @@ r_arch_sources = [
'p/sparc/plugin_gnu.c',
'p/sparc/gnu/sparc-dis.c',
'p/sparc/gnu/sparc-opc.c',
# fails on windows
# error LNK2005: SocketNotificationRetrieveEvents already defined in p_hppa_gnu_hppa-dis.c.obj
# 'p/hppa/plugin_gnu.c',
# 'p/hppa/gnu/hppa-dis.c',
'p/xtensa/gnu/elf32-xtensa.c',
'p/xtensa/gnu/xtensa-dis.c',
'p/xtensa/gnu/xtensa-isa.c',

View File

@ -612,38 +612,26 @@ extern disassemble_info tm_print_insn_info;
* bfd_getm32 - To retrieve the upper 16-bits of the ARCtangent-A5
* basecase (32-bit) instruction
*/
static bfd_vma
bfd_getm32 (data)
unsigned int data;
{
bfd_vma value = 0;
value = ((data & 0xff00) | (data & 0xff)) << 16;
value |= ((data & 0xff0000) | (data & 0xff000000)) >> 16;
return value;
static bfd_vma bfd_getm32(unsigned int data) {
bfd_vma value = ((data & 0xff00) | (data & 0xff)) << 16;
value |= ((data & 0xff0000) | (data & 0xff000000)) >> 16;
return value;
}
/*
* bfd_getm32_ac - To retrieve the upper 8-bits of the ARCompact
* 16-bit instruction
*/
static bfd_vma
bfd_getm32_ac (data)
unsigned int data;
{
bfd_vma value = 0;
value = ((data & 0xff) << 8 | (data & 0xff00) >> 8);
return value;
static bfd_vma bfd_getm32_ac (unsigned int data) {
bfd_vma value = (data & 0xff) << 8 | (data & 0xff00) >> 8;
return value;
}
/*
* sign_extend - Sign Extend the value
*
*/
static int
sign_extend (int value, int bits)
{
static int sign_extend(int value, int bits) {
if (BIT (value, (bits - 1))) {
value |= (0xffffffff << bits);
}

View File

@ -1530,7 +1530,7 @@ static bool parseOperands(char* str, ArmOp *op) {
int operand = 0;
char *token = t;
char *x;
int imm_count = 0;
// int imm_count = 0;
int mem_opt = 0;
int msr_op_index = 0;
size_t index_bound = strcspn (t, "]");
@ -1577,7 +1577,7 @@ static bool parseOperands(char* str, ArmOp *op) {
op->operands_count ++;
op->operands[operand].type = ARM_CONSTANT;
op->operands[operand].immediate = msr_const[msr_op_index].val;
imm_count++;
// imm_count++;
break;
}
}
@ -1773,7 +1773,7 @@ static bool parseOperands(char* str, ArmOp *op) {
op->operands[operand].type = ARM_CONSTANT;
op->operands[operand].immediate = r_num_math (NULL, token + 1);
op->operands[operand].preindex = token - t < index_bound;
imm_count++;
// imm_count++;
break;
case '-':
op->operands[operand].sign = -1;
@ -1783,7 +1783,7 @@ static bool parseOperands(char* str, ArmOp *op) {
op->operands[operand].type = ARM_CONSTANT;
op->operands[operand].immediate = r_num_math (NULL, token);
op->operands[operand].preindex = token - t < index_bound;
imm_count++;
// imm_count++;
break;
}
token = next;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,176 @@
/* radare - LGPL - Copyright 2015-2023 - pancake */
#include <r_asm.h>
#include "disas-asm.h"
static int hppa_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
int delta = (memaddr - info->buffer_vma);
if (delta < 0) {
return -1; // disable backward reads
}
if ((delta + length) > 4) {
return -1;
}
ut8 *bytes = info->buffer;
memcpy (myaddr, bytes + delta, length);
return 0;
}
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info) {
return 0;
}
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info) {
//--
}
DECLARE_GENERIC_PRINT_ADDRESS_FUNC_NOGLOBALS()
DECLARE_GENERIC_FPRINTF_FUNC_NOGLOBALS()
static bool decode(RArchSession *as, RAnalOp *op, RArchDecodeMask mask) {
// static int hppa_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
const ut8 *buf = op->bytes;
const int len = op->size;
ut8 bytes[8] = {0};
struct disassemble_info disasm_obj = {0};
RStrBuf *sb = NULL;
if (mask & R_ARCH_OP_MASK_DISASM) {
sb = r_strbuf_new (NULL);
}
memcpy (bytes, buf, R_MIN (sizeof (bytes), len)); // TODO handle thumb
/* prepare disassembler */
disasm_obj.buffer = bytes;
disasm_obj.buffer_vma = op->addr;
disasm_obj.read_memory_func = &hppa_buffer_read_memory;
disasm_obj.symbol_at_address_func = &symbol_at_address;
disasm_obj.memory_error_func = &memory_error_func;
disasm_obj.print_address_func = &generic_print_address_func;
disasm_obj.endian = !R_ARCH_CONFIG_IS_BIG_ENDIAN (as->config);
disasm_obj.fprintf_func = &generic_fprintf_func;
disasm_obj.stream = sb;
op->size = print_insn_hppa ((bfd_vma)op->addr, &disasm_obj);
if (mask & R_ARCH_OP_MASK_DISASM) {
op->mnemonic = r_strbuf_drain (sb);
sb = NULL;
r_str_replace_ch (op->mnemonic, '\t', ' ', true);
switch (*op->mnemonic) {
case 'a':
op->type = R_ANAL_OP_TYPE_ADD;
break;
case 'b':
op->type = R_ANAL_OP_TYPE_CJMP;
break;
case 'c':
op->type = R_ANAL_OP_TYPE_CMP;
break;
case 'l':
op->type = R_ANAL_OP_TYPE_LOAD;
break;
case 's':
op->type = R_ANAL_OP_TYPE_STORE;
break;
case '#':
op->type = R_ANAL_OP_TYPE_ILL;
free (op->mnemonic);
op->mnemonic = strdup ("invalid");
break;
}
} else {
r_strbuf_free (sb);
}
return op->size;
}
static char *regs(RArchSession *s) {
const char *p =
"=PC pc\n"
"=SP sp\n"
"=BP ep\n"
"=SN r1\n"
"=ZF z\n"
"=A0 r1\n"
"=A1 r5\n"
"=A2 r6\n"
"=A3 r7\n"
"=A4 r8\n"
"=SF s\n"
"=OF ov\n"
"=CF cy\n"
"gpr r0 .32 ? 0\n"
"gpr r1 .32 4 0\n"
"gpr r2 .32 8 0\n"
"gpr sp .32 12 0\n"
"gpr r3 .32 12 0\n"
"gpr gp .32 16 0\n"
"gpr r4 .32 16 0\n"
"gpr r5 .32 20 0\n"
"gpr tp .32 20 0\n"
"gpr r6 .32 24 0\n"
"gpr r7 .32 28 0\n"
"gpr r8 .32 32 0\n"
"gpr r9 .32 36 0\n"
"gpr r10 .32 40 0\n"
"gpr r11 .32 44 0\n"
"gpr r12 .32 48 0\n"
"gpr r13 .32 52 0\n"
"gpr r14 .32 56 0\n"
"gpr r15 .32 60 0\n"
"gpr r16 .32 64 0\n"
"gpr r17 .32 68 0\n"
"gpr r18 .32 72 0\n"
"gpr r19 .32 76 0\n"
"gpr r20 .32 80 0\n"
"gpr r21 .32 84 0\n"
"gpr r22 .32 88 0\n"
"gpr r23 .32 92 0\n"
"gpr r24 .32 96 0\n"
"gpr r25 .32 100 0\n"
"gpr r26 .32 104 0\n"
"gpr r27 .32 108 0\n"
"gpr r28 .32 112 0\n"
"gpr r29 .32 116 0\n"
"gpr r30 .32 120 0\n"
"gpr ep .32 120 0\n"
"gpr r31 .32 124 0\n"
"gpr lp .32 124 0\n"
"gpr pc .32 128 0\n"
// 32bit [ RFU ][NP EP ID SAT CY OV S Z]
"gpr psw .32 132 0\n" // program status word
"gpr npi .1 132.16 0\n" // non maskerable interrupt (NMI)
"gpr epi .1 132.17 0\n" // exception processing interrupt
"gpr id .1 132.18 0\n" // :? should be id
"gpr sat .1 132.19 0\n" // saturation detection
"flg cy .1 132.28 0 carry\n" // carry or borrow
"flg ov .1 132.29 0 overflow\n" // overflow
"flg s .1 132.30 0 sign\n" // signed result
"flg z .1 132.31 0 zero\n" // zero result
;
return strdup (p);
}
static int info(RArchSession *as, ut32 q) {
return 4; /* :D */
}
RArchPlugin r_arch_plugin_hppa_gnu = {
.name = "hppa",
.arch = "hppa",
.license = "GPL3",
.bits = R_SYS_BITS_PACK1 (16),
.endian = R_SYS_ENDIAN_BIG,
.desc = "HP PA-RISC",
.info = info,
.regs = regs,
.decode = &decode
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ARCH,
.data = &r_arch_plugin_hppa_gnu,
.version = R2_VERSION
};
#endif

12
libr/arch/p/hppa_gnu.mk Normal file
View File

@ -0,0 +1,12 @@
OBJ_HPPA=p/hppa/plugin_gnu.o
OBJ_HPPA+=p/hppa/gnu/hppa-dis.o
STATIC_OBJ+=${OBJ_HPPA}
TARGET_HPPA=arch_hppa_gnu.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_HPPA}
${TARGET_HPPA}: ${OBJ_HPPA}
${CC} $(call libname,arch_hppa) ${LDFLAGS} ${CFLAGS} -o arch_hppa_gnu.${EXT_SO} ${OBJ_HPPA}
endif

View File

@ -72,19 +72,11 @@ unsigned long tricore_mask_ssr;
unsigned long tricore_mask_ssro;
unsigned long tricore_opmask[TRICORE_FMT_MAX];
int
bfd_default_scan (info, string)
const bfd_arch_info_type *info;
const char *string;
{
int bfd_default_scan (const bfd_arch_info_type *info, const char *string) {
return true;
}
const bfd_arch_info_type *
bfd_default_compatible (a, b)
const bfd_arch_info_type *a;
const bfd_arch_info_type *b;
{
const bfd_arch_info_type *bfd_default_compatible(const bfd_arch_info_type *a, const bfd_arch_info_type *b) {
if (a->arch != b->arch) {
return NULL;
}
@ -183,10 +175,7 @@ const bfd_arch_info_type bfd_tricore_arch =
also have to call this if it ever accesses the variables below, but
it currently doesn't. */
void
tricore_init_arch_vars (mach)
unsigned long mach;
{
void tricore_init_arch_vars (unsigned long mach) {
switch (mach & bfd_mach_rider_mask)
{
case bfd_mach_rider_a:

View File

@ -37,7 +37,7 @@ static void nothing(void) {
#define OPCODES_SIGLONGJMP(buf,val) siglongjmp((buf), (val))
#endif
int show_raw_fields;
static const int show_raw_fields = false;
struct dis_private
{
@ -135,8 +135,7 @@ print_xtensa_operand (bfd_vma memaddr,
/* Print the Xtensa instruction at address MEMADDR on info->stream.
Returns length of the instruction in bytes. */
int print_insn_xtensa (bfd_vma memaddr, struct disassemble_info *info) {
int print_insn_xtensa(bfd_vma memaddr, struct disassemble_info *info) {
unsigned operand_val;
int bytes_fetched, size, maxsize, i, n, noperands, nslots;
xtensa_isa isa;

View File

@ -59,6 +59,7 @@ static int filename_cmp(const char *s1, const char *s2) {
}
#endif
}
// XXX globals
xtensa_isa_status xtisa_errno;
char xtisa_error_msg[1024];
@ -71,7 +72,7 @@ xtensa_isa_errno (xtensa_isa isa __attribute__ ((unused)))
char *
xtensa_isa_error_msg (xtensa_isa isa __attribute__ ((unused)))
xtensa_isa_error_msg(xtensa_isa isa __attribute__ ((unused)))
{
return xtisa_error_msg;
}

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,6 @@ static const char *gethtmlcolor(const char ptrch) {
R_API char *r_cons_html_filter(const char *ptr, int *newlen) {
const char *str = ptr;
int esc = 0;
int len = 0;
bool inv = false;
char text_color[16] = {0};
char background_color[16] = {0};
@ -237,7 +236,6 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) {
continue;
}
}
len++;
}
r_strbuf_append_n (res, str, ptr - str);
if (has_set) {

View File

@ -1594,7 +1594,6 @@ extern RAnalPlugin r_anal_plugin_x86_udis;
extern RAnalPlugin r_anal_plugin_xcore_cs;
extern RAnalPlugin r_anal_plugin_pickle;
extern RAnalPlugin r_anal_plugin_evm_cs;
extern RAnalPlugin r_anal_plugin_hppa_gnu;
extern RAnalPlugin r_anal_plugin_m68k_gnu;
#ifdef __cplusplus

View File

@ -329,6 +329,7 @@ extern RArchPlugin r_arch_plugin_pyc;
extern RArchPlugin r_arch_plugin_h8300;
extern RArchPlugin r_arch_plugin_bf;
extern RArchPlugin r_arch_plugin_sparc_gnu;
extern RArchPlugin r_arch_plugin_hppa_gnu;
#ifdef __cplusplus

View File

@ -191,6 +191,7 @@ if no_user_plugins
arch_plugins += [
'z80',
'pdp11',
# 'hppa_gnu',
'sparc_gnu',
'lanai'
]