Skip to content

Commit c20856d

Browse files
radaretrufae
authored andcommitted
Better pseudo support for tricore ##arch
1 parent 44a23da commit c20856d

File tree

3 files changed

+41
-45
lines changed

3 files changed

+41
-45
lines changed

libr/arch/p/tricore/pseudo.c

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,71 @@ static bool replace(int argc, char *argv[], char *newstr) {
88
#define MAXPSEUDOOPS 10
99
int i, j, k, d;
1010
char ch;
11+
const char *op0 = argv[0];
12+
if (!strcmp (op0, "ret") || !strcmp (op0, "rfe")) {
13+
strcpy (newstr, "return");
14+
return false;
15+
}
1116
struct {
1217
const char *op;
1318
const char *str;
1419
int args[MAXPSEUDOOPS]; // XXX can't use flex arrays, all unused will be 0
1520
} ops[] = {
21+
#if 0
1622
{ "ret", "return;"},
1723
{ "rfe", "return;"},
18-
{ "debug", "debug;"},
24+
#endif
25+
{ "nop", ""},
26+
{ "debug", "breakpoint"},
27+
{ "invalid", ""},
1928
{ "movh.a", "# = #", {1, 2}},
2029
{ "mov.aa", "# = #", {1, 2}},
2130
{ "mov.u", "# = #", {1, 2}},
31+
{ "mov.d", "# = #", {1, 2}},
32+
{ "mov.a", "# = #", {1, 2}},
33+
{ "movh", "# = #", {1, 2}},
2234
{ "mov", "# = #", {1, 2}},
35+
{ "sha", "# = #", {1, 2}},
2336
{ "lea", "# = #", {1, 2}},
37+
{ "nop", ";", {}},
2438
{ "jnz.t", "if (#) goto loc_#", {1, 2}},
2539
{ "jnz", "if (#) goto loc_#", {1, 2}},
2640
{ "jla", "if (la) goto loc_#", {1}},
41+
{ "jl.t", "if (la) goto loc_#", {1}},
2742
{ "jne", "if (# != #) goto loc_#", {1, 2, 3}},
2843
{ "jeq", "if (# == #) goto loc_#", {1, 2, 3}},
44+
{ "jgez", "if (# >= #) goto loc_#", {1, 2, 3}},
45+
{ "jz.t", "if (# == #) goto loc_#", {1, 2, 3}},
2946
{ "jge", "if (# >= #) goto loc_#", {1, 2, 3}},
47+
{ "jge.u", "if (# >= #) goto loc_#", {1, 2, 3}},
48+
{ "jge.u", "if (# >= #) goto loc_#", {1, 2, 3}},
49+
{ "jeq.a", "if (# == #) goto loc_#", {1, 2, 3}},
3050
{ "ji", "goto #", {1}},
3151
{ "jz.t", "if (!#) goto loc_#", {1, 2}},
3252
{ "jz.a", "if (!#) goto loc_#", {1, 2}},
3353
{ "jz", "if (!#) goto loc_#", {1, 2}},
54+
{ "jnz", "if (#) goto loc_#", {1, 2}},
55+
{ "calli", "call # ()", {1}},
3456
{ "sub", "# = # - #", {1, 2, 3}},
57+
{ "add.a", "# += #", {1, 2, 3}},
3558
{ "addsc.a", "# = # + #", {1, 2, 3}},
3659
{ "addih", "# = # + #", {1, 2, 3}},
3760
{ "add", "# = # + #", {1, 2, 3}},
3861
{ "and", "# &= #", {1, 2}},
62+
{ "or", "# = # | #", {1, 2, 3}},
63+
{ "isync", "", {}},
64+
{ "dsync", "", {}},
3965
{ "st.w", "# = #", {1, 2}},
66+
{ "st.h", "# = #", {1, 2}},
67+
{ "st.bu", "# = #", {1, 2}},
68+
{ "st.b", "# = #", {1, 2}},
4069
{ "st.a", "# = #", {1, 2}},
4170
{ "ld.bu", "# = #", {1, 2}},
4271
{ "ld.w", "# = #", {1, 2}},
4372
{ "ld.a", "# = #", {1, 2}},
73+
{ "ld.b", "# = #", {1, 2}},
74+
{ "ld.h", "# = #", {1, 2}},
75+
{ "ld.hu", "# = #", {1, 2}},
4476
{ "sha", "# = sha(#)", {1, 2}},
4577
{ "sh", "# = # >> #", {1, 2, 3}},
4678
{ NULL }
@@ -125,9 +157,11 @@ static int parse(RParse *p, const char *data, char *str) {
125157
}
126158
}
127159
if (par) ptr++;
128-
r_str_ncpy (w0, buf, R_MIN (ptr - buf, sizeof (w0)));
160+
r_str_ncpy (w0, buf, R_MIN (ptr - buf, sizeof (w0)) + 1);
161+
r_str_trim (w0);
129162
if (par) ptr--;
130-
r_str_ncpy (w1, ptr, R_MIN (end-ptr+1, sizeof (w1)));
163+
r_str_ncpy (w1, ptr, R_MIN (end-ptr+1, sizeof (w1)) + 1);
164+
r_str_trim (w1);
131165
optr = ptr;
132166
ptr = strchr (ptr, ',');
133167
if (ptr) {
@@ -157,47 +191,10 @@ static int parse(RParse *p, const char *data, char *str) {
157191
nw++;
158192
}
159193
}
160-
/* TODO: interpretation of memory location fails*/
161-
//ensure imul & mul interpretations works
162-
if (strstr (w0, "mul")) {
163-
if (nw == 2) {
164-
r_str_ncpy (wa[3], wa[1], sizeof (w3));
165-
166-
switch (wa[3][0]) {
167-
case 'q':
168-
case 'r': //qword, r..
169-
r_str_ncpy (wa[1], "rax", sizeof (w1));
170-
r_str_ncpy (wa[2], "rax", sizeof (w2));
171-
break;
172-
case 'd':
173-
case 'e': //dword, e..
174-
if (strlen (wa[3]) > 2) {
175-
r_str_ncpy (wa[1], "eax", sizeof (w1));
176-
r_str_ncpy (wa[2], "eax", sizeof (w2));
177-
break;
178-
}
179-
default : // .x, .p, .i or word
180-
if (wa[3][1] == 'x' || wa[3][1] == 'p' || \
181-
wa[3][1] == 'i' || wa[3][0] == 'w') {
182-
r_str_ncpy (wa[1], "ax", sizeof (w1));
183-
r_str_ncpy (wa[2], "ax", sizeof (w2));
184-
} else { // byte and lowest 8 bit registers
185-
r_str_ncpy (wa[1], "al", sizeof (w1));
186-
r_str_ncpy (wa[2], "al", sizeof (w2));
187-
}
188-
}
189-
} else if (nw == 3) {
190-
r_str_ncpy (wa[3], wa[2], sizeof (w3));
191-
r_str_ncpy (wa[2], wa[1], sizeof (w2));
192-
}
193-
replace (nw, wa, str);
194-
} else if (p->retleave_asm) {
195-
R_FREE (p->retleave_asm);
196-
replace (nw, wa, str);
197-
} else {
198-
replace (nw, wa, str);
199-
}
194+
#if 0
200195
r_str_fixspaces (str);
196+
#endif
197+
replace (nw, wa, str);
201198
free (buf);
202199
return true;
203200
}

libr/asm/parse.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ R_API RParseSession *r_parse_new_session(RParse *p, const char *name) {
3636
}
3737
return NULL;
3838
}
39-
40-
R_API char *r_parse_
4139
#endif
4240

4341
R_API RParse *r_parse_new(void) {

libr/core/disasm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
12081208
}
12091209
if (ds->pseudo) {
12101210
if (r_parse_parse (core->parser, ds->opstr, ds->str)) {
1211+
R_LOG_DEBUG ("asm.parse.pseudo (%s) -> (%s)", ds->opstr, ds->str);
12111212
if (R_STR_ISNOTEMPTY (ds->str)) {
12121213
free (ds->opstr);
12131214
ds->opstr = strdup (ds->str);

0 commit comments

Comments
 (0)