Skip to content

Commit

Permalink
tricore: fix rfm, ldlcx, lducx stack op set (#4035)
Browse files Browse the repository at this point in the history
* Fix TriCore's `rfm` stack op set
* Fix TriCore's `ldlcx` `lducx` set
  • Loading branch information
imbillow committed Dec 17, 2023
1 parent c0abdb8 commit 770084c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions librz/analysis/p/analysis_tricore_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,10 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
case TRICORE_INS_ADDS_U: {
op->type = RZ_ANALYSIS_OP_TYPE_ADD;
if (tricore_op_count(insn) >= 2) {
cs_tricore_op *op1 = tricore_get_op(insn, 1);
const cs_tricore_op *op1 = tricore_get_op(insn, 1);
if (op1->type == TRICORE_OP_IMM) {
op->val = op1->imm;

cs_tricore_op *op0 = tricore_get_op(insn, 0);
const cs_tricore_op *op0 = tricore_get_op(insn, 0);
if (op0->type == TRICORE_OP_REG && op0->reg == TRICORE_REG_SP) {
op->stackop = RZ_ANALYSIS_STACK_INC;
op->stackptr = op1->imm;
Expand Down Expand Up @@ -598,8 +597,9 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
case TRICORE_INS_LDLCX:
case TRICORE_INS_LDUCX:
op->refptr = 4 * 16;
op->type = RZ_ANALYSIS_OP_TYPE_LOAD;
op->stackop = RZ_ANALYSIS_STACK_GET;
// fallthrough
break;
case TRICORE_INS_LDMST:
case TRICORE_INS_LD_A:
case TRICORE_INS_LD_BU:
Expand All @@ -613,7 +613,7 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
op->refptr = 4;
op->type = RZ_ANALYSIS_OP_TYPE_LOAD;
if (insn->detail->tricore.op_count >= 2) {
cs_tricore_op *op1 = &insn->detail->tricore.operands[1];
const cs_tricore_op *op1 = tricore_get_op(insn, 1);
if (op1->type == TRICORE_OP_REG && op1->reg == TRICORE_REG_SP) {
op->stackop = RZ_ANALYSIS_STACK_GET;
}
Expand Down Expand Up @@ -782,13 +782,11 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
case TRICORE_INS_MSUBM_U:
case TRICORE_INS_MSUBMS_U: {
op->type = RZ_ANALYSIS_OP_TYPE_SUB;
cs_tricore_op *op0 = tricore_get_op(insn, 0);
const cs_tricore_op *op0 = tricore_get_op(insn, 0);
if (tricore_op_count(insn) >= 2) {
cs_tricore_op *op1 = tricore_get_op(insn, 1);
const cs_tricore_op *op1 = tricore_get_op(insn, 1);
if (op1->type == TRICORE_OP_IMM) {
op->val = op1->imm;

cs_tricore_op *op1 = tricore_get_op(insn, 1);
if (op0->type == TRICORE_OP_REG && op0->reg == TRICORE_REG_SP) {
op->stackop = RZ_ANALYSIS_STACK_INC;
op->stackptr = -op1->imm;
Expand Down Expand Up @@ -852,8 +850,9 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
break;
}
case TRICORE_INS_RFM:
op->type = RZ_ANALYSIS_OP_TYPE_RET;
op->stackop = RZ_ANALYSIS_STACK_SET;
// fallthrough
break;
case TRICORE_INS_RET:
case TRICORE_INS_RFE: {
op->type = RZ_ANALYSIS_OP_TYPE_RET;
Expand Down Expand Up @@ -908,7 +907,8 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
op->ptr = tricore_get_op_imm(insn, 0);
op->ptrsize = 4 * 16;
op->stackop = RZ_ANALYSIS_STACK_GET;
// fallthrough
op->type = RZ_ANALYSIS_OP_TYPE_STORE;
break;
case TRICORE_INS_ST_A:
case TRICORE_INS_ST_B:
case TRICORE_INS_ST_DA:
Expand All @@ -919,7 +919,7 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
case TRICORE_INS_ST_W: {
op->ptrsize = 4;
op->type = RZ_ANALYSIS_OP_TYPE_STORE;
cs_tricore_op *op0 = tricore_get_op(insn, 0);
const cs_tricore_op *op0 = tricore_get_op(insn, 0);
switch (op0->type) {
case TRICORE_OP_MEM:
case TRICORE_OP_INVALID:
Expand All @@ -933,7 +933,7 @@ static void tricore_op_set_type(RzAnalysisOp *op, csh h, cs_insn *insn) {
case TRICORE_OP_IMM: {
op->ptr = op0->imm;
break;
};
}
}
break;
}
Expand Down

0 comments on commit 770084c

Please sign in to comment.