Skip to content
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

TriCore instruction loop16 #2386

Closed
arkup opened this issue Jun 10, 2024 · 8 comments
Closed

TriCore instruction loop16 #2386

arkup opened this issue Jun 10, 2024 · 8 comments
Labels
bug Something is not working as it should TriCore Arch
Milestone

Comments

@arkup
Copy link
Contributor

arkup commented Jun 10, 2024

Hi, while decoding the TriCore instruction loop16, the second operand is displayed in the format of a relative jump (not absolute), which is inconsistent with other instructions and, in my opinion (IMHO), makes it harder to read.

0x80000492: 04 FF | ld.bu d15, [a15+]
0x80000494: 24 4F | st.b [a4+], d15
0x80000496: FC 2E | loop a2, #-4               ;<===

Expected, preferred output:

0x80000492: 04 FF |  ld.bu d15, [a15+] 
0x80000494: 24 4F |  st.b [a4+], d15
0x80000496: FC 2E |  loop a2, 0x80000492       ;<===
Questions Answers
OS/arch/bits Windows x64 etc.
Architecture CS_ARCH_TRICORE, CS_MODE_TRICORE_162
Source of Capstone git clone,
Version/git commit v5.0.1, commit/3f87ce0f6a665abb2675adada507362985bb46a4

Instruction bytes giving faulty results

unsigned char loop_chars[] =
{
  0xFC, 0x2E
};

Expected results

loop16          a2, 0x...(absolut address)
@XVilka
Copy link
Contributor

XVilka commented Jun 11, 2024

@imbillow could you please take a look when you have time?

@Rot127 Rot127 added bug Something is not working as it should TriCore Arch labels Jun 12, 2024
@Rot127 Rot127 added this to the v6 milestone Jun 12, 2024
@imbillow
Copy link
Contributor

Hi, while decoding the TriCore instruction loop16, the second operand is displayed in the format of a relative jump (not absolute), which is inconsistent with other instructions and, in my opinion (IMHO), makes it harder to read.

0x80000492: 04 FF | ld.bu d15, [a15+]
0x80000494: 24 4F | st.b [a4+], d15
0x80000496: FC 2E | loop a2, #-4               ;<===

Expected, preferred output:

0x80000492: 04 FF |  ld.bu d15, [a15+] 
0x80000494: 24 4F |  st.b [a4+], d15
0x80000496: FC 2E |  loop a2, 0x80000492       ;<===

Questions Answers
OS/arch/bits Windows x64 etc.
Architecture CS_ARCH_TRICORE, CS_MODE_TRICORE_162
Source of Capstone git clone,
Version/git commit v5.0.1, commit/3f87ce0f6a665abb2675adada507362985bb46a4

Instruction bytes giving faulty results

unsigned char loop_chars[] =
{
  0xFC, 0x2E
};

Expected results

loop16          a2, 0x...(absolut address)

The instruction you mention is LOOP (SBR), and its second operand is interpreted as a relative offset rather than an absolute address.

For more information, see TriCoreTM TC1.6.2 core architecture manual - Instruction set on page 3-179.

image

@imbillow
Copy link
Contributor

There is indeed another instruction with the same name LOOP in a different format but it has [0..7]=0xfd

@imbillow
Copy link
Contributor

imbillow commented Jun 16, 2024

I'm sorry I do not get it. But it is fixed in the next branch. @arkup

@arkup
Copy link
Contributor Author

arkup commented Jun 16, 2024

I'm sorry I do not get it. But it is fixed in the next branch. @arkup

OK, thanks. My point was that it's harder to read 'loop $reg, #-disp4' when I have to subtract disp4 from the loop $pc address in my head, instead of having an absolute address. In IDA/Ghidra, it's already formatted as an absolute address 'loop $reg, 0x???'

@cqke
Copy link

cqke commented Aug 31, 2024

Is there any possibility to release the fix in Capstone V5 also ? @radare is working hard to get TriCore RE functional, it just need some tweaks to rely fully on Capstone engine (v5 for now). Amazing things are coming ! Thank you very much.

@Rot127 Rot127 modified the milestones: v6 - Alpha, v5.0.4 Aug 31, 2024
@Rot127
Copy link
Collaborator

Rot127 commented Aug 31, 2024

@cqke Added it to the v5.0.4 milestone. @imbillow Do you think you could cherry-pick the fix into v5?

@arkup Regarding your wish to print absolute addresses. For archs like PPC, ARM and AArch64 we have this options enabled via CS_OPT_NO_BRANCH_OFFSET which toggles this. I will rename the option before the release and check everything works with it.
But in general we can do this for TriCore as well. @imbillow Are there many operands which are PC relative? Do you think we could get this feature into v6 in a week?

kabeor pushed a commit that referenced this issue Nov 1, 2024
@Rot127
Copy link
Collaborator

Rot127 commented Nov 10, 2024

Wasn't closed with #2527 for whatever reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working as it should TriCore Arch
Projects
Status: Done
Development

No branches or pull requests

5 participants