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

x86: incorrect disassembly around FSTCW, FSTSW instructions #1611

Open
minexew opened this issue Apr 2, 2020 · 3 comments
Open

x86: incorrect disassembly around FSTCW, FSTSW instructions #1611

minexew opened this issue Apr 2, 2020 · 3 comments

Comments

@minexew
Copy link

minexew commented Apr 2, 2020

Env:

  • python 3.8
  • capstone 4.0.1
  • ubuntu 18.04 (WSL)

Repro:

import capstone
md = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_32)
md.detail = True

# case 1
# expected: fstcw  WORD PTR [ebp-0x4] (based on Objdump disassembly which round-trips with GNU as)
for insn in md.disasm(b"\x9B\xD9\x7D\xFC", 0):
    print(insn.address, insn.mnemonic, insn.op_str)

print()

# case 2
# expected: fstsw  WORD PTR [ebp-0x2]
for insn in md.disasm(b"\x9B\xDD\x7D\xFE", 0):
    print(insn.address, insn.mnemonic, insn.op_str)

Output:

0 wait
1 fnstcw word ptr [ebp - 4]

0 wait
1 fnstsw dword ptr [ebp - 2]
@tzoz
Copy link

tzoz commented Apr 11, 2020

The operand size for case 2 is wrong indeed, but FSTCW is equivalent to FWAIT/WAIT followed by FNSTCW. The same applies to FSTSW.

@minexew
Copy link
Author

minexew commented Apr 11, 2020

Technically it is, but the Intel reference manual, GMU binutils and nasm-ndisasm all follow this convention. Why be different?

@tzoz
Copy link

tzoz commented Apr 11, 2020

Probably because it is less complicated to parse them as separate instructions while still being technically correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants