Skip to content

Commit

Permalink
Implement sep for cosmac with the new r= esil op ##esil
Browse files Browse the repository at this point in the history
* v35arm64 linkage happening once for make targets
  • Loading branch information
radare authored Dec 27, 2024
1 parent 898e946 commit 762d251
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 264 deletions.
2 changes: 1 addition & 1 deletion global.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ endif
-include $(TOP)/mk/platform.mk
-include $(TOP)/mk/${COMPILER}.mk

WWWROOT=${DATADIR}/radare2/${VERSION}/www
WWWROOT=$(DATADIR)/radare2/${VERSION}/www
endif
6 changes: 3 additions & 3 deletions libr/arch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ CFLAGS:=-I.. -I$(LTOP)/arch/include -DR2_PLUGIN_INCORE -Iarch -I$(TOP)/shlr $(CF
LDFLAGS+=$(CS_LDFLAGS)

.PHONY: pre
pre: p v35pre
pre: p
$(MAKE) libr_arch.$(EXT_SO)
$(MAKE) libr_arch.$(EXT_AR)

v35pre:
$(MAKE) -C p/arm/v35
# v35pre:
# $(MAKE) -C p/arm/v35

include $(STATIC_ARCH_PLUGINS)
include $(STOP)/java/deps.mk
Expand Down
21 changes: 4 additions & 17 deletions libr/arch/p/arm/v35/deps-arm64.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
V35ARM64_HOME=$(SPRJ)/v35arm64
V35ARM64_SRCDIR=$(V35ARM64_HOME)/disassembler/
# V35ARM64_HOME=$(SPRJ2)/v35arm64
V35ARM64_SRCDIR=$(shell realpath $(V35ARM64_HOME))/

V35ARM64_CFLAGS=-I$(V35ARM64_SRCDIR)
# V35ARM64_OBJS+=encodings.o
# V35ARM64_OBJS+=test.o
V35ARM64_OBJS+=decode.o
V35ARM64_OBJS+=decode0.o
V35ARM64_OBJS+=decode1.o
Expand All @@ -18,17 +16,6 @@ V35ARM64_OBJS+=operations.o
V35ARM64_OBJS+=pcode.o
V35ARM64_OBJS+=regs.o
V35ARM64_OBJS+=sysregs.o
V35ARM64_LINK=$(addprefix $(V35ARM64_SRCDIR),$(V35ARM64_OBJS))
V35ARM64_LIBS=$(V35ARM64_HOME)/v35arm64.a

${V35ARM64_LINK}: $(V35ARM64_SRCDIR)
$(V35ARM64_SRCDIR):

# $(MAKE) -C $(V35ARM64_HOME) arch-arm64
# $(MAKE) $(V35ARM64_HOME)/v35arm64.a
# $(MAKE) git-clone-arm64v35

git-clone-arm64v35:
$(MAKE) -C $(V35ARM64_HOME) arch-arm64

.PHONY: git-clone-arm64v35
V35ARM64_LINK=$(addprefix $(V35ARM64_SRCDIR),$(V35ARM64_OBJS))
# V35ARM64_LIBS=$(V35ARM64_HOME)/v35arm64.a
14 changes: 8 additions & 6 deletions libr/arch/p/arm_v35.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ include ../../config-user.mk
include ../../global.mk

N=arch_arm_v35
V35ARM64_HOME=$(SHLR)../subprojects/v35arm64/disassembler
V35ARM64_HOME=$(TOP)/subprojects/v35arm64/disassembler

include ../arch/p/arm/v35/deps-arm64.mk
include p/arm/v35/deps-arm64.mk

OBJ_ARM_V35=p/arm/plugin_v35.o
V35ARM64_LDFLAGS+=p/arm/v35/v35arm64.a
LDFLAGS+=p/arm/v35/v35arm64.a
OBJ_ARM_V35+=$(V35ARM64_LINK)
# V35ARM64_LDFLAGS+=p/arm/v35/v35arm64.a
# LDFLAGS+=p/arm/v35/v35arm64.a
# LDFLAGS+=$(V35ARM64_LINK)

STATIC_OBJ+=${OBJ_ARM_V35}

Expand All @@ -20,5 +22,5 @@ ALL_TARGETS+=$(TARGET_ARM_V35)

$(TARGET_ARM_V35):
${CC} $(V35ARM64_CFLAGS) ${CFLAGS} $(call libname,$(N)) \
-lr_util -lr_search \
-o $(TARGET_ARM_V35) ${OBJ_ARM_V35} $(V35ARM64_LDFLAGS)
-lr_util -lr_search -o $(TARGET_ARM_V35) \
${OBJ_ARM_V35} $(V35ARM64_LDFLAGS)
469 changes: 235 additions & 234 deletions libr/arch/p/cosmac/plugin.c

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion libr/esil/esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ static bool default_is_reg(void *reg, const char *name) {
return true;
}

#if 0
static bool default_reg_alias(void *reg, int kind, const char *name) {
return r_reg_set_name ((RReg *)reg, kind, name);
}
#endif

static bool default_reg_read(void *reg, const char *name, ut64 *val) {
RRegItem *ri = r_reg_get ((RReg *)reg, name, -1);
if (!ri) {
Expand All @@ -149,7 +155,8 @@ static REsilRegInterface simple_reg_if = {
.is_reg = default_is_reg,
.reg_read = default_reg_read,
.reg_write = (REsilRegWrite)r_reg_setv,
.reg_size = default_reg_size
.reg_size = default_reg_size,
// .reg_alias = default_reg_alias
};

R_API REsil *r_esil_new_simple(ut32 addrsize, void *reg, void *iob) {
Expand Down
23 changes: 22 additions & 1 deletion libr/esil/esil_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,27 @@ static bool esil_cmp(REsil *esil) {
return ret;
}

#if 1
// needed for COSMAC
static bool esil_regalias(REsil *esil) {
R_RETURN_VAL_IF_FAIL (esil, false);
ut64 num;
bool ret = false;
char *dst = r_esil_pop (esil);
char *src = r_esil_pop (esil);
if (src && r_esil_get_parm (esil, src, &num)) {
ret = true;
int kind = r_reg_get_name_idx (dst);
if (kind != -1) {
r_reg_set_name (esil->anal->reg, kind, src);
}
}
free (dst);
free (src);
return ret;
}
#endif

#if 0
x86 documentation:
CF - carry flag -- Set on high-order bit carry or borrow; cleared otherwise
Expand Down Expand Up @@ -2942,7 +2963,7 @@ R_API bool r_esil_setup_ops(REsil *esil) {
ret &= OP ("$ds", esil_ds, 1, 0, OT_UNK);
ret &= OP ("$jt", esil_jt, 1, 0, OT_UNK);
ret &= OP ("$js", esil_js, 1, 0, OT_UNK);
//OP ("$r", esil_rs, 1, 0, OT_UNK); // R_DEPRECATE
ret &= OP ("r=", esil_regalias, 1, 0, OT_UNK); // r0,PC,@= -> change PC alias to r0
ret &= OP ("$$", esil_address, 1, 0, OT_UNK);
ret &= OP ("~", esil_signext, 1, 2, OT_MATH);
ret &= OP ("~=", esil_signexteq, 0, 2, OT_MATH);
Expand Down
4 changes: 3 additions & 1 deletion libr/include/r_esil.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ typedef bool (*REsilIsReg)(void *reg, const char *name);
typedef bool (*REsilRegRead)(void *reg, const char *name, ut64 *val);
typedef bool (*REsilRegWrite)(void *reg, const char *name, ut64 val);
typedef ut32 (*REsilRegSize)(void *reg, const char *name);
// typedef bool (*REsilRegAlias)(void *reg, int kind, const char *name);

typedef struct r_esil_register_interface_t {
union {
void *reg;
void *user;
};
REsilIsReg is_reg;
REsilIsReg is_reg; /// IsReg breaks the REsilReg prefix naming
REsilRegRead reg_read;
REsilRegWrite reg_write;
REsilRegSize reg_size;
// REsilRegAlias reg_alias;
} REsilRegInterface;

typedef void (*REsilVoyeurRegRead)(void *user, const char *name, ut64 val);
Expand Down

0 comments on commit 762d251

Please sign in to comment.