capstone-engine / capstone

Capstone disassembly/disassembler framework for ARM, ARM64 (ARMv8), Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
http://www.capstone-engine.org
7.61k stars 1.56k forks source link

Tricore EA calculation #2504

Closed Rot127 closed 1 month ago

Rot127 commented 1 month ago

Your checklist for this pull request

Detailed description

Fixes two issues with address calculation:

Fix absolute address calculations.

Absolute effective addresses are decoded by DecodeBInstruction(). Because they are encoded as normal disp24 value. To form the EA: The lower 20bits are shifted by one, and the upper 4bits by 1 (jumps) or 7 (calls).

Fix PC relative disponents.

The ISA sign extends disponents values of 8, 15 and 24 bits. For address disponents it also shifts the results by 1 for alignment.

The ISA has two writing styles for this though: sign_ext(dispXX 2) and sign_ext(dispXX) 2.

Assuming that sign_ext() always works on the MSB of the value they are eqivalent. Because: sign_ext(disp8 2) = sign_ext(disp8 2 = disp9) = sign_ext(disp9) = sign_ext(disp8) * 2.

This let to confusion before and for the sign_ext(dispXX * 2) case, and the wrong bit was checked for sign extension (e.g bit 8 for an effective disp9 value).

Test plan

Not yet added.

Closing issues

...

Rot127 commented 1 month ago

@imbillow Please review this one before I fix the tests.

XVilka commented 1 month ago

@kabeor please merge this