unicorn-engine / unicorn

Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, S390x, TriCore, X86)
http://www.unicorn-engine.org
GNU General Public License v2.0
7.67k stars 1.35k forks source link

SAL instruction wrong behavior #1998

Open cr3m opened 2 months ago

cr3m commented 2 months ago

I am using Unicorn-based emulator (Speakeasy) to emulate a sample but I saw that seems like the SAL instruction is not working properly

0x1401df85b: mem=0xd3cd2900000000f9
0x1401df85b: sal word ptr [rsp + r8 + 3], cl                             ; cf=0x0
0x1401df861: mem=0xd3cd2900000001f2
0x1401df861: inc rdx                                                     ; cf=0x1

The CF flag changed from 0 -> 1 while it shouldn't

SAL (or its synonym, SHL) shifts the bits of the operand upward. The high-order bit is shifted into the carry flag, and the low-order bit is set to 0.
wtdcode commented 2 months ago

Seems dup of #1717