arch/tms320/c55x_plus: drop utils.{c,h}, use rz_util helpers

The c55x_plus decoder shipped with two private string helpers in
utils.c:

  strcat_dup(s1, s2, n_free)  - allocate s1+s2 and optionally free
                                inputs, with a bitmask controlling
                                which of s1/s2 are released
  get_hex_str(n)              - format the low 8 bits of n as a
                                two-character lowercase hex string

Both have direct equivalents in rz_util:

  strcat_dup(s, lit, 1)       -> rz_str_append(s, lit)
  strcat_dup(lit, s, 2)       -> rz_str_prepend(s, lit)
  strcat_dup(s1, s2, 3)       -> rz_str_append_owned(s1, s2)
  strcat_dup(s1, s2, 1) where
    s2 is also owned and freed
    manually right afterwards -> rz_str_append_owned(s1, s2)
  get_hex_str(n)              -> rz_str_newf("%02x", n & 0xff)

This commit converts all 56 strcat_dup call sites in
c55plus_decode.c and decode_funcs.c plus the single get_hex_str
site, then deletes utils.c and utils.h entirely.

While here, replace several local sprintf-into-stack-buffer +
rz_str_dup patterns with direct rz_str_newf calls:

  - get_AR_regs_class1: was malloc(50) + sprintf per case, now a
    single rz_str_newf per case returning the result directly.
    The function is reduced from 34 lines to 14.
  - get_AR_regs_class2: same pattern, reduced from 130 lines to
    79 with no allocation needed at the top.
  - get_token_decoded case 40/48, 70/72/80, 41/73: sprintf into
    a 512-byte stack buffer then rz_str_dup -> single rz_str_newf.
  - decode_funcs.c case 2 of get_status_regs_and_bits: was
    calloc(50) + sprintf, now rz_str_newf.

The 512-byte stack buffer 'buff_aux' in get_token_decoded becomes
unused and is removed.

C55PLUS_DEBUG, the only useful symbol that used to live in utils.h,
moves to ins.h (which all c55x_plus translation units transitively
include). ins.h gains a direct <rz_util.h> include so the rest of
the headers don't need to pull it in indirectly.

No behavioural change. Full c55x_plus test regression passes:
asm/tms320_c55x+_32 104/104, analysis/tms320.c55x+_32 45/45,
parity against TI dis55.exe v4.3.6 on the 13-source testbins corpus
remains 140/140.
This commit is contained in:
Anton Kochkov 2026-05-27 06:36:10 +00:00 committed by NOT XVilka
parent 64c1cad7e5
commit 9ccee37999
8 changed files with 128 additions and 354 deletions

View file

@ -4,13 +4,11 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <rz_types.h>
#include <rz_util.h>
#include "ins.h"
#include "decode.h"
#include "utils.h"
#include "hashtable.h"
#include "decode_funcs.h"
@ -92,11 +90,6 @@ static ut32 get_ins_bits(ut32 hash_code, ut32 ins_pos, char *ins,
}
}
if (C55PLUS_DEBUG) {
printf("INS_BITS => 0x%x\n", res);
getchar();
}
return res;
}
@ -247,10 +240,6 @@ static char *decode_ins(st32 hash_code, ut32 ins_pos, ut32 ins_off, ut32 *ins_le
}
}
if (C55PLUS_DEBUG) {
printf("PSEUDO INS %s\n", ins);
}
pos = ins;
// instruction length
*ins_len_dec = ins_len;
@ -277,19 +266,12 @@ static char *decode_ins(st32 hash_code, ut32 ins_pos, ut32 ins_off, ut32 *ins_le
token_aux[len] = '\0';
pos = aux;
if (C55PLUS_DEBUG) {
printf("TOKEN AUX: %s\n", token_aux);
}
reg = NULL;
for (i = 0; i < len; i++) {
if (token_aux[i] == ',') {
len = (unsigned int)(size_t)(&token_aux[i] - token_aux);
reg = &token_aux[i + 1];
if (C55PLUS_DEBUG) {
printf("REG : %s\n", reg);
}
break;
}
}
@ -299,22 +281,15 @@ static char *decode_ins(st32 hash_code, ut32 ins_pos, ut32 ins_off, ut32 *ins_le
if (*err_code < 0) {
return NULL;
}
res_decode = strcat_dup(res_decode, aux, 3);
if (C55PLUS_DEBUG) {
printf("RET TOKEN %s\n", res_decode);
}
res_decode = rz_str_append_owned(res_decode, aux);
} else {
token_aux[0] = *pos;
token_aux[1] = '\0';
res_decode = strcat_dup(res_decode, token_aux, 1);
res_decode = rz_str_append(res_decode, token_aux);
}
pos++;
}
if (C55PLUS_DEBUG) {
printf("RESULT DECODE: %s\n", res_decode);
}
return res_decode;
}
@ -410,23 +385,19 @@ static char *do_decode(ut32 ins_off, ut32 ins_pos, ut32 two_ins, ut32 *next_ins_
*ins_hash_code = hash_code;
}
if (C55PLUS_DEBUG) {
printf("MAGIC VALUE 0x%x\n", 0x800);
}
if (hash_aux == 0x1E1 || hash_aux == 0x1E2) {
ins_aux = decode_ins(hash_aux, ins_pos, ins_off, &ins_len_dec, &reg_len_dec,
&ret_ins_bits, magic_value, two_ins, err_code);
if (*err_code < 0) {
return NULL;
}
ins_aux = strcat_dup(ins_aux, " ", 1);
ins_aux = rz_str_append(ins_aux, " ");
}
if (hash_code == 0x223) {
ins_res = strcat_dup(ins_aux, ".byte 0x", 1);
ins_aux = get_hex_str(get_ins_part(ins_pos, 1));
ins_res = strcat_dup(ins_res, ins_aux, 2);
char hex_buf[8];
ins_res = rz_str_append(ins_aux, ".byte 0x");
ins_res = rz_str_append(ins_res, rz_strf(hex_buf, "%02x", get_ins_part(ins_pos, 1) & 0xff));
*next_ins_pos = *next_ins_pos + 1;
} else {
free(ins_aux);
@ -436,9 +407,8 @@ static char *do_decode(ut32 ins_off, ut32 ins_pos, ut32 two_ins, ut32 *next_ins_
free(ins_aux);
return NULL;
}
ins_res = strcat_dup(ins_aux, ins_res, 1);
ins_res = rz_str_append_owned(ins_aux, ins_res);
// printf("NEXT POS %d %d\n", ins_len_dec, reg_len_dec);
// getchar();
*next_ins_pos += ins_len_dec; // reg_len_dec;
}
@ -484,13 +454,11 @@ char *c55plus_decode(ut32 ins_pos, ut32 *next_ins_pos) {
*next_ins_pos = next_ins2_pos;
if (hash_code == 0xF0 || hash_code == 0xF1) {
aux = strcat_dup(ins2, " || ", 1);
ins_res = strcat_dup(aux, ins1, 1);
free(ins1);
aux = rz_str_append(ins2, " || ");
ins_res = rz_str_append_owned(aux, ins1);
} else {
aux = strcat_dup(ins1, " || ", 1);
ins_res = strcat_dup(aux, ins2, 1);
free(ins2);
aux = rz_str_append(ins1, " || ");
ins_res = rz_str_append_owned(aux, ins2);
}
*next_ins_pos = next_ins1_pos + next_ins2_pos + 1;
if (*next_ins_pos != two_ins) {
@ -524,7 +492,6 @@ static char *get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l
ut32 ins_pos, ut32 ins_len, ut8 two_ins, int *err_code) {
ut32 tok_op, ins_bits;
char *res = NULL;
char buff_aux[512];
char *aux = NULL;
ut32 ret_len = 0, flag;
@ -537,11 +504,6 @@ static char *get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l
}
tok_op = *ins_token - 0x23;
if (C55PLUS_DEBUG) {
printf("WAY ins_bits: OP = %d 0x%x %s %d %d\n", tok_op, ins_bits, ins_token, ins_token_len, ins_pos);
getchar();
}
switch (tok_op) {
case 30:
case 31:
@ -571,8 +533,7 @@ static char *get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l
case 39: res = get_cmp_op(ins_bits); break;
case 40:
case 48:
sprintf(buff_aux, "#0x%x", (ins_bits << (32 - ins_token_len) >> (32 - ins_token_len)));
res = rz_str_dup(buff_aux);
res = rz_str_newf("#0x%x", (ins_bits << (32 - ins_token_len) >> (32 - ins_token_len)));
break;
case 70:
case 72:
@ -590,41 +551,34 @@ static char *get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l
*ret_ins_bits = ins_bits;
}
if (!reg_arg || *reg_arg != '-') {
sprintf(buff_aux, "#0x%lx", (long unsigned int)ins_bits);
res = rz_str_newf("#0x%lx", (long unsigned int)ins_bits);
} else {
sprintf(buff_aux, "-#0x%lx", (long unsigned int)ins_bits);
res = rz_str_newf("-#0x%lx", (long unsigned int)ins_bits);
}
res = rz_str_dup(buff_aux);
if (!reg_arg || *reg_arg != 'm') {
break;
}
res = strcat_dup(res, ")", 1);
res = strcat_dup("*(", res, 2);
res = rz_str_append(res, ")");
res = rz_str_prepend(res, "*(");
if (magic_value & 0xC0) {
res = strcat_dup(res, ")", 1);
res = strcat_dup("volatile(", res, 2);
res = rz_str_append(res, ")");
res = rz_str_prepend(res, "volatile(");
} else if (magic_value & 0x30) {
res = strcat_dup(res, ")", 1);
res = strcat_dup("port(", res, 2);
res = rz_str_append(res, ")");
res = rz_str_prepend(res, "port(");
}
break;
case 41:
case 73:
if ((reg_arg && *reg_arg == 'L') || hash_code == 105 || hash_code == 7) {
if (C55PLUS_DEBUG) {
fprintf(stderr, "Ooops!!! look up address in sections!! %d", hash_code);
}
}
if (reg_arg && *reg_arg == 'L') {
ins_bits = ins_bits << (32 - ins_token_len) >> (32 - ins_token_len);
}
if (reg_arg && *reg_arg == 'i') {
res = rz_str_dup("");
} else {
sprintf(buff_aux, "#0x%06lx", (long unsigned int)ins_bits);
res = rz_str_dup(buff_aux);
res = rz_str_newf("#0x%06lx", (long unsigned int)ins_bits);
}
break;
case 42:
@ -651,34 +605,34 @@ static char *get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l
aux = get_AR_regs_class2(ins_bits, &ret_len, ins_len + ins_pos, 1);
}
if (magic_value & 1) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("mmap(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "mmap(");
} else if ((magic_value & 4) && is_linear_circular(ins_bits)) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("linear(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "linear(");
} else if ((magic_value & 8) && is_linear_circular(ins_bits)) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("circular(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "circular(");
} else if (magic_value & 2) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("lock(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "lock(");
} else if (reg_arg) {
if (((magic_value & 0x10) && strchr(reg_arg, 'r')) ||
((magic_value & 0x20) && strchr(reg_arg, 'w'))) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("port(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "port(");
} else if (
((magic_value & 0x40) && strchr(reg_arg, 'r')) ||
((magic_value & 0x80000000) && strchr(reg_arg, 'w'))) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("volatile(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "volatile(");
}
}
if (flag) {
res = strcat_dup("t3 = ", aux, 2);
res = rz_str_prepend(aux, "t3 = ");
} else {
res = aux;
*ret_reg_len = ret_len;
@ -739,34 +693,34 @@ static char *get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l
tok_op = ins_bits & 0xF;
if (magic_value & 4) {
if (tok_op <= 7 || tok_op == 0xF) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("linear(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "linear(");
}
} else if (magic_value & 8) {
if (tok_op <= 7 || tok_op == 0xF) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("circular(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "circular(");
}
} else if (magic_value & 2) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("lock(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "lock(");
} else if (reg_arg) {
if (
((magic_value & 0x10) && *ins_token == 'X' && strchr(reg_arg, 'r')) ||
((magic_value & 0x20) && *ins_token == 'Y' && strchr(reg_arg, 'w'))) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("port(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "port(");
} else if (
((magic_value & 0x40) && *ins_token == 'X' && strchr(reg_arg, 'r')) ||
((magic_value & 0x80000000) && *ins_token == 'Y' && strchr(reg_arg, 'w'))
) {
aux = strcat_dup(aux, ")", 1);
aux = strcat_dup("volatile(", aux, 2);
aux = rz_str_append(aux, ")");
aux = rz_str_prepend(aux, "volatile(");
}
}
res = flag ? strcat_dup("t3 = ", aux, 2) : aux;
res = flag ? rz_str_prepend(aux, "t3 = ") : aux;
break;
case 0:
case 1:
@ -872,17 +826,11 @@ static char *get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l
return NULL;
}
if (res != NULL) {
if (C55PLUS_DEBUG) {
printf("OP(78): TOKEN=%s\n", res);
}
res = rz_str_dup(res);
}
break;
}
ret_decode:
if (C55PLUS_DEBUG) {
printf("RES = %s\n", (res) ? res : "NULL");
}
return res;
}

View file

@ -4,9 +4,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ins.h"
#include "utils.h"
char *get_tc2_tc1(ut32 ins_bits) {
char *res = "tc1";
@ -56,183 +54,95 @@ char *get_trans_reg(ut32 ins_bits) {
}
char *get_AR_regs_class1(ut32 ins_bits) {
ut32 op = (ins_bits >> 4) & 7;
char *res = (char *)calloc(1, 50);
if (!res) {
return NULL;
}
const ut32 op = (ins_bits >> 4) & 7;
const long n = (long int)ins_bits & 0xF;
switch (op) {
case 0:
sprintf(res, "*ar-%ld", (long int)ins_bits & 0xF);
break;
case 1:
sprintf(res, "*ar+%ld", (long int)ins_bits & 0xF);
break;
case 2:
sprintf(res, "*ar%ld(t0)", (long int)ins_bits & 0xF);
break;
case 3:
sprintf(res, "*ar%ld", (long int)ins_bits & 0xF);
break;
case 4:
sprintf(res, "*(ar%ld-t0)", (long int)ins_bits & 0xF);
break;
case 5:
sprintf(res, "*(ar%ld-t1)", (long int)ins_bits & 0xF);
break;
case 6:
sprintf(res, "*(ar%ld+t0)", (long int)ins_bits & 0xF);
break;
case 7:
sprintf(res, "*(ar%ld+t1)", (long int)ins_bits & 0xF);
break;
case 0: return rz_str_newf("*ar-%ld", n);
case 1: return rz_str_newf("*ar+%ld", n);
case 2: return rz_str_newf("*ar%ld(t0)", n);
case 3: return rz_str_newf("*ar%ld", n);
case 4: return rz_str_newf("*(ar%ld-t0)", n);
case 5: return rz_str_newf("*(ar%ld-t1)", n);
case 6: return rz_str_newf("*(ar%ld+t0)", n);
case 7: return rz_str_newf("*(ar%ld+t1)", n);
}
return res;
return NULL;
}
char *get_AR_regs_class2(ut32 ins_bits, ut32 *ret_len, ut32 ins_pos, ut32 idx) {
ut8 op, op2, reg_num, type;
char *res = NULL;
const ut8 op = ins_bits >> 6;
const ut8 op2 = ins_bits & 3;
const long reg_num = (ins_bits >> 2) & 0xF;
op = ins_bits >> 6;
op2 = ins_bits & 3;
reg_num = (ins_bits >> 2) & 0xF;
if (ret_len) {
*ret_len = 0;
}
// printf("OP1 %x OP2 0x%x %x\n", op, op2, reg_num);
res = malloc(50);
if (!res) {
return NULL;
}
if (op2 == 2) {
if (op) {
sprintf(res, "*ar%ld(short(#0x%lx))",
(long int)reg_num, (long int)idx * op);
} else {
sprintf(res, "*ar%ld", (long int)reg_num);
return rz_str_newf("*ar%ld(short(#0x%lx))", reg_num, (long int)idx * op);
}
} else {
type = (op >> 3 | 2 * op2);
if (type == 6) {
sprintf(res, "@#0x%lx", (long int)idx * (reg_num | 16 * (op & 7)));
} else if (type == 7) {
sprintf(res, "*sp(#0x%lx)", (long int)idx * (reg_num | 16 * (op & 7)));
} else {
type = idx | 16 * op;
switch (type) {
case 0:
sprintf(res, "*ar%ld-", (long int)reg_num);
break;
case 1:
sprintf(res, "*ar%ld+", (long int)reg_num);
break;
case 2:
sprintf(res, "*ar%ld(t0)", (long int)reg_num);
break;
case 3:
sprintf(res, "*ar%ld(t1)", (long int)reg_num);
break;
case 4:
sprintf(res, "*(ar%ld-t0)", (long int)reg_num);
break;
case 5:
sprintf(res, "*(ar%ld-t1)", (long int)reg_num);
break;
case 6:
sprintf(res, "*(ar%ld+t0)", (long int)reg_num);
break;
case 7:
sprintf(res, "*(ar%ld+t1)", (long int)reg_num);
break;
case 8:
sprintf(res, "*-ar%ld", (long int)reg_num);
break;
case 9:
sprintf(res, "*+ar%ld", (long int)reg_num);
break;
case 10:
sprintf(res, "*ar%ld(t2)", (long int)reg_num);
break;
case 11:
sprintf(res, "*ar%ld(t3)", (long int)reg_num);
break;
case 12:
sprintf(res, "*(ar%ld-t2)", (long int)reg_num);
break;
case 13:
sprintf(res, "*(ar%ld-t3)", (long int)reg_num);
break;
case 14:
sprintf(res, "*(ar%ld+t2)", (long int)reg_num);
break;
case 15:
sprintf(res, "*(ar%ld+t3)", (long int)reg_num);
break;
case 16:
sprintf(res, "*(ar%ld-t0b)", (long int)reg_num);
break;
case 17:
sprintf(res, "*(ar%ld+t0b)", (long int)reg_num);
break;
case 18:
sprintf(res, "*ar%ld(t0<<#1)", (long int)reg_num);
break;
case 19:
sprintf(res, "*ar%ld(t1<<#1)", (long int)reg_num);
break;
case 23:
sprintf(res, "*ar%ld(xar15)", (long int)reg_num);
break;
return rz_str_newf("*ar%ld", reg_num);
}
case 24:
case 25:
case 26:
case 27:
idx = get_ins_part(ins_pos, 2);
if (ret_len) {
*ret_len = 2;
}
switch (type) {
case 24:
sprintf(res, "*ar%ld(#%ld)", (long int)reg_num, (long int)op * idx);
break;
case 25:
sprintf(res, "*+ar%ld(#%ld)", (long int)reg_num, (long int)op * idx);
break;
case 26:
sprintf(res, "*abs16(#0x%lx)", (long int)idx);
break;
default:
sprintf(res, "*port(#0x%lx)", (long int)idx);
break;
}
break;
case 28:
case 29:
case 30:
idx = get_ins_part(ins_pos, 3);
if (ret_len) {
*ret_len = 3;
}
switch (type) {
case 28:
sprintf(res, "*ar%ld(#0x%lx)", (long int)reg_num, (long int)idx * op);
break;
case 29:
sprintf(res, "*+ar%ld(#0x%lx)", (long int)reg_num, (long int)idx * op);
break;
default:
sprintf(res, "*(#0x%lx)", (long int)idx);
break;
}
ut8 type = (op >> 3 | 2 * op2);
if (type == 6) {
return rz_str_newf("@#0x%lx", (long int)idx * (reg_num | 16 * (op & 7)));
} else if (type == 7) {
return rz_str_newf("*sp(#0x%lx)", (long int)idx * (reg_num | 16 * (op & 7)));
}
break;
}
type = idx | 16 * op;
switch (type) {
case 0: return rz_str_newf("*ar%ld-", reg_num);
case 1: return rz_str_newf("*ar%ld+", reg_num);
case 2: return rz_str_newf("*ar%ld(t0)", reg_num);
case 3: return rz_str_newf("*ar%ld(t1)", reg_num);
case 4: return rz_str_newf("*(ar%ld-t0)", reg_num);
case 5: return rz_str_newf("*(ar%ld-t1)", reg_num);
case 6: return rz_str_newf("*(ar%ld+t0)", reg_num);
case 7: return rz_str_newf("*(ar%ld+t1)", reg_num);
case 8: return rz_str_newf("*-ar%ld", reg_num);
case 9: return rz_str_newf("*+ar%ld", reg_num);
case 10: return rz_str_newf("*ar%ld(t2)", reg_num);
case 11: return rz_str_newf("*ar%ld(t3)", reg_num);
case 12: return rz_str_newf("*(ar%ld-t2)", reg_num);
case 13: return rz_str_newf("*(ar%ld-t3)", reg_num);
case 14: return rz_str_newf("*(ar%ld+t2)", reg_num);
case 15: return rz_str_newf("*(ar%ld+t3)", reg_num);
case 16: return rz_str_newf("*(ar%ld-t0b)", reg_num);
case 17: return rz_str_newf("*(ar%ld+t0b)", reg_num);
case 18: return rz_str_newf("*ar%ld(t0<<#1)", reg_num);
case 19: return rz_str_newf("*ar%ld(t1<<#1)", reg_num);
case 23: return rz_str_newf("*ar%ld(xar15)", reg_num);
case 24:
case 25:
case 26:
case 27:
idx = get_ins_part(ins_pos, 2);
if (ret_len) {
*ret_len = 2;
}
switch (type) {
case 24: return rz_str_newf("*ar%ld(#%ld)", reg_num, (long int)op * idx);
case 25: return rz_str_newf("*+ar%ld(#%ld)", reg_num, (long int)op * idx);
case 26: return rz_str_newf("*abs16(#0x%lx)", (long int)idx);
default: return rz_str_newf("*port(#0x%lx)", (long int)idx);
}
case 28:
case 29:
case 30:
idx = get_ins_part(ins_pos, 3);
if (ret_len) {
*ret_len = 3;
}
switch (type) {
case 28: return rz_str_newf("*ar%ld(#0x%lx)", reg_num, (long int)idx * op);
case 29: return rz_str_newf("*+ar%ld(#0x%lx)", reg_num, (long int)idx * op);
default: return rz_str_newf("*(#0x%lx)", (long int)idx);
}
}
return res;
return NULL;
}
char *get_reg_pair(ut32 idx) {
@ -1016,17 +926,17 @@ char *get_opers(ut8 oper_byte) {
char *reg_name = get_reg_name_4(oper_byte & 0x1F);
switch (oper_type) {
case 1u:
return strcat_dup(reg_name, " != #0", 1);
return rz_str_append(reg_name, " != #0");
case 0u:
return strcat_dup(reg_name, " == #0", 1);
return rz_str_append(reg_name, " == #0");
case 2u:
return strcat_dup(reg_name, " < #0", 1);
return rz_str_append(reg_name, " < #0");
case 3u:
return strcat_dup(reg_name, " >= #0", 1);
return rz_str_append(reg_name, " >= #0");
case 4u:
return strcat_dup(reg_name, " > #0", 1);
return rz_str_append(reg_name, " > #0");
case 5u:
return strcat_dup(reg_name, " <= #0", 1);
return rz_str_append(reg_name, " <= #0");
default:
free(reg_name);
return NULL;
@ -1039,11 +949,9 @@ char *get_opers(ut8 oper_byte) {
free(reg_name);
return NULL;
}
return strcat_dup(reg_name, " != #0", 1);
return rz_str_append(reg_name, " != #0");
} else {
// coverity may complain but strcat_dup set to null
// reg_name when free
return strcat_dup(reg_name, " == #0", 1);
return rz_str_append(reg_name, " == #0");
}
}
}
@ -1076,15 +984,10 @@ char *get_sim_reg(char *reg_arg, ut32 ins_bits) {
}
}
aux = get_reg_name_1(ins_bits >> 2);
res = strcat_dup("@", aux, 2);
res = rz_str_prepend(aux, "@");
break;
case 2:
aux = (char *)calloc(1, 50);
if (!aux) {
return NULL;
}
sprintf(aux, "@#0x%x", code);
res = aux;
res = rz_str_newf("@#0x%x", code);
break;
case 1:
case 3:

View file

@ -2809,11 +2809,6 @@ st32 get_hash_code(ut32 ins_pos) {
opcode = get_ins_part(ins_pos, 1);
ins_len = get_ins_len(opcode);
if (C55PLUS_DEBUG) {
printf("opcode: 0x%x part: %d\n", opcode, ins_pos);
printf("ins_len: 0x%x\n", ins_len);
}
if (ins_len > 1) {
len = ins_len - 1;
if (len >= 4) {
@ -2837,15 +2832,7 @@ st32 get_hash_code(ut32 ins_pos) {
// get_hashcode_func = *(ut32 *)(((ut8 *)ins_hash + sizeof(ut32)) + pos * 8);
get_hashcode_func = ins_hash[pos].hash_func;
if (C55PLUS_DEBUG) {
printf("hashfunc => %p 0x%x\n", get_hashcode_func, pos);
printf("hashargs => 0x%x 0x%x 0x%x\n", (ut32)arg, ins_part1, ins_part2);
}
hash_code = get_hashcode_func(arg, ins_part2);
if (C55PLUS_DEBUG) {
printf("ret hashcode: 0x%x\n", hash_code);
}
return hash_code;
}

View file

@ -51,9 +51,6 @@ ut32 get_ins_len(ut8 opcode) {
ut32 get_ins_part(ut32 pos, ut32 len) {
ut32 ret = 0;
has_failed = 0;
if (C55PLUS_DEBUG) {
printf("pos => 0x%x len => %d ins_buff_len => %d\n", pos, len, ins_buff_len);
}
if ((st32)pos < 0 || pos >= ins_buff_len) {
has_failed = 1;

View file

@ -5,7 +5,7 @@
#define INS_H
#include <rz_types.h>
#include "utils.h"
#include <rz_util.h>
// instruction length
ut32 get_ins_len(ut8 opcode);

View file

@ -1,46 +0,0 @@
// SPDX-FileCopyrightText: 2013 th0rpe <josediazfer@yahoo.es>
// SPDX-License-Identifier: LGPL-3.0-only
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
static char hex_str[] = "01234567890abcdef";
// TODO: Add in a Coverity modelling file
char *strcat_dup(char *s1, char *s2, st32 n_free) {
char *res;
ut32 len_s1 = s1 ? strlen(s1) : 0;
ut32 len_s2 = s2 ? strlen(s2) : 0;
if (!(res = (char *)malloc(len_s1 + len_s2 + 1))) {
return NULL;
}
if (len_s1 > 0) {
memcpy(res, s1, len_s1);
}
if (len_s2 > 0) {
memcpy(res + len_s1, s2, len_s2);
}
res[len_s1 + len_s2] = '\0';
if (n_free == 1) {
RZ_FREE(s1);
} else if (n_free == 2) {
RZ_FREE(s2);
} else if (n_free == 3) {
RZ_FREE(s1);
RZ_FREE(s2);
}
return res;
}
char *get_hex_str(ut32 hex_num) {
char aux[3];
aux[2] = '\0';
aux[1] = hex_str[hex_num & 0xF];
aux[0] = hex_str[(hex_num >> 4) & 0xF];
return rz_str_dup(aux);
}

View file

@ -1,14 +0,0 @@
// SPDX-FileCopyrightText: 2013-2021 th0rpe <josediazfer@yahoo.es>
// SPDX-License-Identifier: LGPL-3.0-only
#ifndef UUTILS_H
#define UUTILS_H
#include <rz_types.h>
#include <rz_util.h>
#define C55PLUS_DEBUG 0
char *strcat_dup(char *s1, char *s2, st32 n_free);
char *get_hex_str(ut32 hex_num);
#endif

View file

@ -320,7 +320,6 @@ arch_isa_sources = [
'isa/tms320/c55x_plus/hashtable.c',
'isa/tms320/c55x_plus/hashvector.c',
'isa/tms320/c55x_plus/ins.c',
'isa/tms320/c55x_plus/utils.c',
'isa/tms320/c64x/c64x.c',
'isa/tms320/tms320_dasm.c',
'isa/v810/v810_disas.c',