Skip to content

Commit

Permalink
fix xtensa esil pc mod
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Nov 5, 2024
1 parent 6491c55 commit 82320c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions librz/arch/isa/xtensa/xtensa.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ static inline int32_t xtensa_op_l32r(cs_insn *insn, unsigned int index) {
#define REGO(I) REG(xtensa_op_reg(ctx->insn, I))
#define IMM(I) xtensa_op_imm(ctx->insn, I)
#define L32R(I) xtensa_op_l32r(ctx->insn, I)
#define INSN_SIZE (ctx->insn->size)

#endif // RIZIN_XTENSA_H
20 changes: 10 additions & 10 deletions librz/arch/isa/xtensa/xtensa_esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static void esil_branch_compare_imm(XtensaContext *ctx, RzAnalysisOp *op) {
// ISA defines branch target as offset + 4,
// but at the time of ESIL evaluation
// PC will be already incremented by 3
esil_push_signed_imm(&op->esil, IMM(2) + 4 - 3);
esil_push_signed_imm(&op->esil, IMM(2) - INSN_SIZE);

rz_strbuf_appendf(&op->esil, "pc" CM "+=" CM "}");
}
Expand Down Expand Up @@ -361,7 +361,7 @@ static void esil_branch_compare(XtensaContext *ctx, RzAnalysisOp *op) {
REGO(0),
compare_op);

esil_push_signed_imm(&op->esil, IMM(2));
esil_push_signed_imm(&op->esil, IMM(2) - INSN_SIZE);

rz_strbuf_append(&op->esil, "pc" CM "+=" CM "}");
}
Expand Down Expand Up @@ -405,7 +405,7 @@ static void esil_branch_compare_single(XtensaContext *ctx, RzAnalysisOp *op) {
REGO(0),
compare_op);

esil_push_signed_imm(&op->esil, IMM(1));
esil_push_signed_imm(&op->esil, IMM(1) - INSN_SIZE);

rz_strbuf_append(&op->esil, "pc" CM "+=" CM "}");
}
Expand Down Expand Up @@ -461,7 +461,7 @@ static void esil_branch_check_mask(XtensaContext *ctx, RzAnalysisOp *op) {
REGO(1),
compare_op);

esil_push_signed_imm(&op->esil, IMM(2));
esil_push_signed_imm(&op->esil, IMM(2) - INSN_SIZE);

rz_strbuf_append(&op->esil, "pc" CM "+=" CM "}");
}
Expand Down Expand Up @@ -527,7 +527,7 @@ static void esil_branch_check_bit_imm(XtensaContext *ctx, RzAnalysisOp *op) {
IMM(1),
cmp_op);

esil_push_signed_imm(&op->esil, IMM(2));
esil_push_signed_imm(&op->esil, IMM(2) - INSN_SIZE);

rz_strbuf_appendf(
&op->esil,
Expand Down Expand Up @@ -572,7 +572,7 @@ static void esil_branch_check_bit(XtensaContext *ctx, RzAnalysisOp *op) {
REGO(0),
cmp_op);

esil_push_signed_imm(&op->esil, IMM(2));
esil_push_signed_imm(&op->esil, IMM(2) - INSN_SIZE);

rz_strbuf_appendf(
&op->esil,
Expand Down Expand Up @@ -632,7 +632,7 @@ static void esil_call(XtensaContext *ctx, RzAnalysisOp *op) {
"=" CM);
}

esil_push_signed_imm(&op->esil, IMM(0));
esil_push_signed_imm(&op->esil, IMM(0) - INSN_SIZE);

rz_strbuf_append(&op->esil, "pc" CM "+=");
}
Expand Down Expand Up @@ -835,9 +835,9 @@ void xtensa_analyze_op_esil(XtensaContext *ctx, RzAnalysisOp *op) {
case XTENSA_INS_EXTUI: /* extui */
esil_extract_unsigned(ctx, op);
break;
// case 79: /* ill */
// rz_strbuf_setf(&op->esil, "%s", "");
// break;
case XTENSA_INS_ILL: /* ill */
rz_strbuf_setf(&op->esil, "%s", "");
break;
// TODO: windowed calls?
case XTENSA_INS_CALL4:
break;
Expand Down
13 changes: 10 additions & 3 deletions librz/arch/p/analysis/analysis_xtensa_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static void xtensa_analyze_op(RzAnalysis *a, RzAnalysisOp *op, XtensaContext *ct
case XTENSA_INS_ADDX2: /* addx2 */
case XTENSA_INS_ADDX4: /* addx4 */
case XTENSA_INS_ADDX8: /* addx8 */
case XTENSA_INS_ADD_N:
op->type = RZ_ANALYSIS_OP_TYPE_ADD;
break;
case XTENSA_INS_SUB: /* sub */
Expand All @@ -126,15 +127,20 @@ static void xtensa_analyze_op(RzAnalysis *a, RzAnalysisOp *op, XtensaContext *ct
op->type = RZ_ANALYSIS_OP_TYPE_MOV;
break;
// case 0: /* excw */
case XTENSA_INS_EXCW:
case XTENSA_INS_NOP: /* nop.n */
op->type = RZ_ANALYSIS_OP_TYPE_NOP;
break;
case XTENSA_INS_S32I: /* s32i */
case XTENSA_INS_S16I: /* s16i */
case XTENSA_INS_S8I: /* s8i */
case XTENSA_INS_S32I_N:
case XTENSA_INS_S32C1I:
op->type = RZ_ANALYSIS_OP_TYPE_STORE;
break;
case XTENSA_INS_ADDI: /* addi */
case XTENSA_INS_ADDI_N:
case XTENSA_INS_ADD_S:
op->type = RZ_ANALYSIS_OP_TYPE_ADD;
break;
case XTENSA_INS_RET: /* ret */
Expand All @@ -145,9 +151,9 @@ static void xtensa_analyze_op(RzAnalysis *a, RzAnalysisOp *op, XtensaContext *ct
case XTENSA_INS_L16SI: /* l16si */
case XTENSA_INS_L32I: /* l32i */
case XTENSA_INS_L8UI: /* l8ui */
op->type = RZ_ANALYSIS_OP_TYPE_LOAD;
break;
case XTENSA_INS_L32R: /* l32r */
case XTENSA_INS_L32I_N:
case XTENSA_INS_L32R:
case XTENSA_INS_L32E:
op->type = RZ_ANALYSIS_OP_TYPE_LOAD;
break;
case XTENSA_INS_ADDMI: /* addmi */
Expand Down Expand Up @@ -211,6 +217,7 @@ static void xtensa_analyze_op(RzAnalysis *a, RzAnalysisOp *op, XtensaContext *ct
op->type = RZ_ANALYSIS_OP_TYPE_CMOV;
break;
case XTENSA_INS_ABS: /* abs */
case XTENSA_INS_ABS_S:
op->type = RZ_ANALYSIS_OP_TYPE_ABS;
break;
case XTENSA_INS_NEG: /* neg */
Expand Down
2 changes: 1 addition & 1 deletion subprojects/capstone-next.wrap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[wrap-git]
url = https://github.com/imbillow/capstone.git
revision = bd401889132d2c5215cba1b9c3ca91035059db49
revision = 4970c4abb10fe53f7df46d46a045c0a3d999e510
directory = capstone-next
patch_directory = capstone-next
depth = 1

0 comments on commit 82320c9

Please sign in to comment.