Skip to content

Commit e2f1dc8

Browse files
authored
Tms32c64x Little Endian (#2648)
* Add little endian support for TMS320c64x. This requires now to initialize TMS320c64x with the CS_MODE_BIG_ENDIAN flag. * Fix typo
1 parent 5464c91 commit e2f1dc8

File tree

6 files changed

+60
-5
lines changed

6 files changed

+60
-5
lines changed

arch/TMS320C64x/TMS320C64xDisassembler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ bool TMS320C64x_getInstruction(csh ud, const uint8_t *code, size_t code_len,
600600
if(MI->flat_insn->detail)
601601
memset(MI->flat_insn->detail, 0, offsetof(cs_detail, tms320c64x)+sizeof(cs_tms320c64x));
602602

603-
insn = (code[3] << 0) | (code[2] << 8) | (code[1] << 16) | ((uint32_t) code[0] << 24);
603+
insn = readBytes32(MI, code);
604604
result = decodeInstruction_4(DecoderTable32, MI, insn, address, info, 0);
605605

606606
if(result == MCDisassembler_Success) {

arch/TMS320C64x/TMS320C64xInstPrinter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void TMS320C64x_post_printer(csh ud, cs_insn *insn, SStream *insn_asm, MCInst *m
6262
SStream_concat(&ss, "[%c%s]|", (tms320c64x->condition.zero == 1) ? '!' : '|', cs_reg_name(ud, tms320c64x->condition.reg));
6363

6464
// Sorry for all the fixes below. I don't have time to add more helper SStream functions.
65-
// Before that they messed around with the private buffer of th stream.
66-
// So it is better now. But still not effecient.
65+
// Before that they messed around with the private buffer of the stream.
66+
// So it is better now. But still not efficient.
6767
op_str_ptr = strchr(SStream_rbuf(insn_asm), '\t');
6868

6969
if ((op_str_ptr != NULL) && (((p2 = strchr(op_str_ptr, '[')) != NULL) || ((p2 = strchr(op_str_ptr, '(')) != NULL))) {

arch/TMS320C64x/TMS320C64xModule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ cs_err TMS320C64x_global_init(cs_struct *ud)
3333

3434
cs_err TMS320C64x_option(cs_struct *handle, cs_opt_type type, size_t value)
3535
{
36+
switch (type) {
37+
case CS_OPT_MODE:
38+
handle->mode |= (cs_mode)value;
39+
break;
40+
case CS_OPT_SYNTAX:
41+
handle->syntax |= (int)value;
42+
break;
43+
default:
44+
break;
45+
}
3646
return CS_ERR_OK;
3747
}
3848

cs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ typedef struct cs_arch_config {
188188
{ \
189189
TMS320C64x_global_init, \
190190
TMS320C64x_option, \
191-
~(CS_MODE_BIG_ENDIAN), \
191+
~(CS_MODE_LITTLE_ENDIAN | CS_MODE_BIG_ENDIAN), \
192192
}
193193
#define CS_ARCH_CONFIG_M680X \
194194
{ \

cstool/cstool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ static struct {
178178
{ "m68k40", "m68k40", CS_ARCH_M68K, CS_MODE_M68K_040 },
179179

180180
{ "tms320c64x", "tms320c64x, big endian", CS_ARCH_TMS320C64X, CS_MODE_BIG_ENDIAN },
181+
{ "tms320c64xle", "tms320c64x, little endian", CS_ARCH_TMS320C64X, CS_MODE_LITTLE_ENDIAN },
181182

182183
{ "m6800", "m680x, M6800/2", CS_ARCH_M680X, CS_MODE_M680X_6800 },
183184
{ "m6801", "m680x, M6801/3", CS_ARCH_M680X, CS_MODE_M680X_6801 },

tests/details/tms320c64x.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ test_cases:
33
input:
44
bytes: [ 0x01, 0xac, 0x88, 0x40, 0x81, 0xac, 0x88, 0x43, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x32, 0x96, 0x02, 0x80, 0x46, 0x9e, 0x05, 0x3c, 0x83, 0xe6, 0x0b, 0x0c, 0x8b, 0x24 ]
55
arch: "tms320c64x"
6-
options: [ CS_OPT_DETAIL ]
6+
options: [ CS_OPT_DETAIL, CS_MODE_BIG_ENDIAN ]
77
address: 0x1000
88
expected:
99
insns:
@@ -144,4 +144,48 @@ test_cases:
144144
funit_side_set: true
145145
parallel: 0
146146
parallel_set: true
147+
-
148+
input:
149+
bytes: [ 0xa9, 0xff, 0x7f, 0x02 ]
150+
name: "Little/big endian test"
151+
arch: "tms320c64x"
152+
options: [ CS_OPT_DETAIL, CS_MODE_LITTLE_ENDIAN ]
153+
address: 0x1000
154+
expected:
155+
insns:
156+
-
157+
asm_text: "mvk.S1 -1, a4 ||"
158+
-
159+
input:
160+
bytes: [ 0x02, 0x7f, 0xff, 0xa9 ]
161+
name: "Little/big endian test"
162+
arch: "tms320c64x"
163+
options: [ CS_OPT_DETAIL, CS_MODE_BIG_ENDIAN ]
164+
address: 0x1000
165+
expected:
166+
insns:
167+
-
168+
asm_text: "mvk.S1 -1, a4 ||"
169+
-
170+
input:
171+
bytes: [ 0xa9, 0xff, 0x7f, 0x02 ]
172+
name: "Little/big endian test no detail fixup."
173+
arch: "tms320c64x"
174+
options: [ CS_MODE_LITTLE_ENDIAN ]
175+
address: 0x1000
176+
expected:
177+
insns:
178+
-
179+
asm_text: "mvk -1, a4"
180+
-
181+
input:
182+
bytes: [ 0x02, 0x7f, 0xff, 0xa9 ]
183+
name: "Little/big endian test no detail fixup"
184+
arch: "tms320c64x"
185+
options: [ CS_MODE_BIG_ENDIAN ]
186+
address: 0x1000
187+
expected:
188+
insns:
189+
-
190+
asm_text: "mvk -1, a4"
147191

0 commit comments

Comments
 (0)