-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing TriCore disasm instructions #2088
Conversation
2cdeaae
to
8c383ac
Compare
@imbillow take a look please when you have time |
arch/TriCore/TriCoreInstPrinter.c
Outdated
static void off8_fixup(MCInst *MI, uint64_t *off8) | ||
{ | ||
switch (MCInst_getOpcode(MI)) { | ||
case TRICORE_LD_A_sc: | ||
case TRICORE_ST_A_sc: | ||
case TRICORE_ST_W_sc: | ||
case TRICORE_LD_W_sc: { | ||
*off8 *= 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static void off8_fixup(MCInst *MI, uint64_t *off8) | |
{ | |
switch (MCInst_getOpcode(MI)) { | |
case TRICORE_LD_A_sc: | |
case TRICORE_ST_A_sc: | |
case TRICORE_ST_W_sc: | |
case TRICORE_LD_W_sc: { | |
*off8 *= 4; | |
static void const8_fixup(MCInst *MI, uint64_t *const8) | |
{ | |
switch (MCInst_getOpcode(MI)) { | |
case TRICORE_LD_A_sc: | |
case TRICORE_ST_A_sc: | |
case TRICORE_ST_W_sc: | |
case TRICORE_LD_W_sc: { | |
*const8 *= 4; |
arch/TriCore/TriCoreInstPrinter.c
Outdated
@@ -235,6 +248,9 @@ static void print_zero_ext(MCInst *MI, int OpNum, SStream *O, unsigned n) | |||
if (n == 4) { | |||
off4_fixup(MI, &imm); | |||
} | |||
if (n == 8) { | |||
off8_fixup(MI, &imm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off8_fixup(MI, &imm); | |
const8_fixup(MI, &imm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
case TRICORE_ABSS_H_rr: | ||
case TRICORE_ABS_H_rr: | ||
case TRICORE_ABS_B_rr: | ||
case TRICORE_ABS_rr: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked and found that you still haven't fully fixed it here.
Can you please double-check the following instructions?
d, s2[, s1[, n]]
ADDSC.A
ADDSC.AT
MOV.A
MOV.AA
MOV.D
CRC32.B
CRC32B.W
CRC32L.W
a
UPDFL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have been correct before. Not sure why. These are the insns I sent to capstone as well as GNU objdump and they agree.
CODE = b'\x01\x23\x01\x16' # addsc.a %a1,%a2,%d3,1
CODE += b'\x01\x34\x20\x26' # addsc.at %a2,%a3,%d4
CODE += b'\x01\x20\x30\x16' # mov.a %a1,%d2
CODE += b'\x01\x30\x00\x20' # mov.aa %a2,%a3
CODE += b'\x01\xb0\xc0\xa4' # mov.d %d10,%a11
CODE += b'\x4b\xbc\x60\xa0' # crc32.b %d10,%d11,%d12
CODE += b'\x4b\xbc\x30\xa0' # crc32 %d10,%d11,%d12
CODE += b'\x4b\xbc\x70\xa0' # crc32l.w %d10,%d11,%d12
CODE += b'\x4b\x0a\xc1\xa0' # updfl %d10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remembered that we can also change the order of operands in the td file.
@bkoppelmann @imbillow do we have tests for instructions in question? If not - we should add in a testsuite. |
8c383ac
to
16ec69d
Compare
I can create tests. However, I'm not quite sure where to put them. Is |
Yes |
when we got 2 operands we were expecting them to be one of the CACHE insns. However, 2 operands are also used by ld/st insns with bitreverse +r addressing mode. In that case we would print the registers in the wrong order.
abs instruction use 's2' as the first source operand and not 's1'.
extr and extr.u in the RRRR format use 's3' as the second source operand instead of 's2'.
For these insns destination and source are swapped compared to their ld counterparts.
we need to multiply const8 by 4 for the SC variants of ld/sw.
16ec69d
to
62b99ad
Compare
Done |
@imbillow take a look again please. |
@kabeor this one is ready to merge. Also worth importing into v5 branch. |
Great! Thanks for your contribution! |
* Add Python bindings for WASM * Update Python bindings for m68k * Update Python bindings for mos65xx * Update Python bindings for x86 * Add Python bindings for SH * Update CS_* constants in Python bindings * Update constants from ARM auto-sync patch * Fixing TriCore disasm instructions (#2088) * allow absolute CMAKE_INSTALL_*DIR (#2134) This patch fixes Capstone 5 build on NixOS. NixOS's build infrastructure sets CMAKE_INSTALL_{LIB,INCLUDE}DIR to absolute paths. If you append it to ${prefix}, you get the wrong path. NixOS automatically detects it and links this issue: NixOS/nixpkgs#144170 --------- Co-authored-by: Peace-Maker <peace-maker@wcfan.de> Co-authored-by: Bastian Koppelmann <bkoppelmann@users.noreply.github.com> Co-authored-by: chayleaf <chayleaf@protonmail.com>
* Add Python bindings for WASM * Update Python bindings for m68k * Update Python bindings for mos65xx * Update Python bindings for x86 * Add Python bindings for SH * Update CS_* constants in Python bindings * Update constants from ARM auto-sync patch * Fixing TriCore disasm instructions (#2088) * allow absolute CMAKE_INSTALL_*DIR (#2134) This patch fixes Capstone 5 build on NixOS. NixOS's build infrastructure sets CMAKE_INSTALL_{LIB,INCLUDE}DIR to absolute paths. If you append it to ${prefix}, you get the wrong path. NixOS automatically detects it and links this issue: NixOS/nixpkgs#144170 * Disable swift binding const generate * update bindings const * update capstone version * update ChangeLog --------- Co-authored-by: Peace-Maker <peace-maker@wcfan.de> Co-authored-by: Bastian Koppelmann <bkoppelmann@users.noreply.github.com> Co-authored-by: chayleaf <chayleaf@protonmail.com>
Hi,
while trying to integrate Capstone into QEMU, I came across some bugs.
Here are the fixes :)
Cheers,
Bastian