Index: lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp =================================================================== --- lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp +++ lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp @@ -980,6 +980,44 @@ insn->opcode == 0xE3) attrMask ^= ATTR_ADSIZE; + /* + * In 64-bit mode all f64 superscripted opcodes ignore opcode size prefix + * In the current implementation, CALL/JMP/JCC instructions need to ignore 0x66 + * this implements correct disassembly and consumes all 4 bytes of the immediate/displacement + * NOTE: intel spec states that all rel16 with f64 superscripts are Not Supported in 64-bit mode + */ + + if (insn->mode == MODE_64BIT && isPrefixAtLocation(insn, 0x66, insn->necessaryPrefixLocation)){ + switch (insn->opcode){ + case 0xE8: + case 0xE9: + attrMask ^= ATTR_OPSIZE; + insn->immediateSize = 4; + insn->displacementSize = 4; + break; + case 0x82: + case 0x83: + case 0x84: + case 0x85: + case 0x86: + case 0x87: + case 0x88: + case 0x89: + case 0x8A: + case 0x8B: + case 0x8C: + case 0x8D: + case 0x8E: + case 0x8F: + if (insn-> opcodeType == TWOBYTE){ // breaks lea and three byte ops otherwise + attrMask ^= ATTR_OPSIZE; + insn->immediateSize = 4; + insn->displacementSize = 4; // otherwise not sign extended, for some reason + } + break; + } + } + if (getIDWithAttrMask(&instructionID, insn, attrMask)) return -1; Index: test/MC/Disassembler/X86/x86-64.txt =================================================================== --- test/MC/Disassembler/X86/x86-64.txt +++ test/MC/Disassembler/X86/x86-64.txt @@ -301,3 +301,108 @@ # CHECK: movq %rax, 1515870810 0x67, 0x48 0xa3 0x5a 0x5a 0x5a 0x5a + +# CHECK: callq -32769 +0x66 0xe8 0xff 0x7f 0xff 0xff + +# CHECK: callq -32769 +0x66 0x66 0x48 0xe8 0xff 0x7f 0xff 0xff + +# CHECK: jmp -32769 +0xe9 0xff 0x7f 0xff 0xff + +# CHECK: jmp -32769 +0x66 0xe9 0xff 0x7f 0xff 0xff + +# CHECK: jmp -32769 +0x66 0x66 0x48 0xe9 0xff 0x7f 0xff 0xff + +# CHECK: jb -32769 +0x0f 0x82 0xff 0x7f 0xff 0xff + +# CHECK: jb -32769 +0x66 0x0f 0x82 0xff 0x7f 0xff 0xff + +# CHECK: jae -32769 +0x0f 0x83 0xff 0x7f 0xff 0xff + +# CHECK: jae -32769 +0x66 0x0f 0x83 0xff 0x7f 0xff 0xff + +# CHECK: je -32769 +0x0f 0x84 0xff 0x7f 0xff 0xff + +# CHECK: je -32769 +0x66 0x0f 0x84 0xff 0x7f 0xff 0xff + +# CHECK: jne -32769 +0x0f 0x85 0xff 0x7f 0xff 0xff + +# CHECK: jne -32769 +0x66 0x0f 0x85 0xff 0x7f 0xff 0xff + +# CHECK: jbe -32769 +0x0f 0x86 0xff 0x7f 0xff 0xff + +# CHECK: jbe -32769 +0x66 0x0f 0x86 0xff 0x7f 0xff 0xff + +# CHECK: ja -32769 +0x0f 0x87 0xff 0x7f 0xff 0xff + +# CHECK: ja -32769 +0x66 0x0f 0x87 0xff 0x7f 0xff 0xff + +# CHECK: js -32769 +0x0f 0x88 0xff 0x7f 0xff 0xff + +# CHECK: js -32769 +0x66 0x0f 0x88 0xff 0x7f 0xff 0xff + +# CHECK: jns -32769 +0x0f 0x89 0xff 0x7f 0xff 0xff + +# CHECK: jns -32769 +0x66 0x0f 0x89 0xff 0x7f 0xff 0xff + +# CHECK: jp -32769 +0x0f 0x8a 0xff 0x7f 0xff 0xff + +# CHECK: jp -32769 +0x66 0x0f 0x8a 0xff 0x7f 0xff 0xff + +# CHECK: jnp -32769 +0x0f 0x8b 0xff 0x7f 0xff 0xff + +# CHECK: jnp -32769 +0x66 0x0f 0x8b 0xff 0x7f 0xff 0xff + +# CHECK: jl -32769 +0x0f 0x8c 0xff 0x7f 0xff 0xff + +# CHECK: jl -32769 +0x66 0x0f 0x8c 0xff 0x7f 0xff 0xff + +# CHECK: jge -32769 +0x0f 0x8d 0xff 0x7f 0xff 0xff + +# CHECK: jge -32769 +0x66 0x0f 0x8d 0xff 0x7f 0xff 0xff + +# CHECK: jle -32769 +0x0f 0x8e 0xff 0x7f 0xff 0xff + +# CHECK: jle -32769 +0x66 0x0f 0x8e 0xff 0x7f 0xff 0xff + +# CHECK: jg -32769 +0x0f 0x8f 0xff 0x7f 0xff 0xff + +# CHECK: jg -32769 +0x66 0x0f 0x8f 0xff 0x7f 0xff 0xff + +# CHECK: lcallw *-32769(%rip) +0x66 0xff 0x1d 0xff 0x7f 0xff 0xff + +# CHECK: ljmpw *-32769(%rip) +0x66 0xff 0x2d 0xff 0x7f 0xff 0xff