capstone icon indicating copy to clipboard operation
capstone copied to clipboard

x86: Capstone does not decode reserved x87 encodings (`DC D0–DF`, `DD C8–CF`, `DE D0–DF`, `DF C8–CF`)

Open MariusVanDerWijden opened this issue 1 month ago • 2 comments

Summary

Capstone rejects a family of x87 FPU encodings that alias documented instructions — the reserved Dx ModRM ranges of FCOM/FCOMP/FXCH. XED and Zydis decode them (and CPUs execute them as the documented forms); Capstone returns "invalid". Filing to clarify whether Capstone intends to support these aliases, since they're a large share of the XED/Zydis-vs-Capstone decode gap.

Environment

  • Capstone 5.0.9 (cstool), CS_ARCH_X86 / CS_MODE_64.

Reproducer

$ cstool x64 "dcd0"      # alias of D8 D0
ERROR: invalid assembly code
$ cstool x64 "ddc8"      # alias of D9 C8
ERROR: invalid assembly code
$ cstool x64 "ded1"
ERROR: invalid assembly code
$ cstool x64 "dfc9"
ERROR: invalid assembly code

The documented encodings in the same opcode space decode fine:

$ cstool x64 "d8d0"
 0  d8 d0    fcom	st(0)
$ cstool x64 "d9c8"
 0  d9 c8    fxch	st(0)

What other decoders do

  • XED: dc d0 → fcom st, st(0), dd c8 → fxch st, st(0), de d1 → fcomp st, st(1), df c9 → fxch st, st(1).
  • Zydis: decodes all of the above (2-byte instructions).

These Dx-range encodings are listed as reserved in the SDM but are executed by hardware as the corresponding FCOM/FCOMP/FXCH, which is why XED and Zydis accept them.

MariusVanDerWijden avatar Oct 13 '26 07:10 MariusVanDerWijden

I reproduced the four-byte families from this report against the current next checkout: dc d0, dd c8, de d1, and df c9 are rejected while their documented counterparts decode. I am interested in contributing a focused regression/test change, but the contributor guide asks for maintainer direction before changing an architecture module. Would you accept these reserved-but-hardware-executed x87 aliases, and should they be represented as the corresponding documented instruction in the X86 backend?

Henglie avatar Oct 21 '26 06:10 Henglie

guide asks for maintainer direction before changing an architecture module

You can always send bug fixes for things like these.

Asking for maintainer directions is about complete rewrites or updates. So only for big changes.

Rot127 avatar Oct 21 '26 15:10 Rot127