[cfe-dev] error: invalid operand for instruction (inl)

John Calcote JCalcote at fusionio.com
Tue Nov 12 17:52:40 PST 2013


I have a small snippet of code for accessing the VMware backdoor:

$ cat vmw_backdoor.cpp
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#define MAX_UINT32              UINT32_MAX

#define VMW_MAGIC               0x564d5868
#define VMW_CMD_IOPORT          0x5658
#define VMW_CMD_GET_VER         0xa

struct registers
{
    uint32_t eax;
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t ebp;
    uint32_t edi;
    uint32_t esi;
};

static void vmw_backdoor(unsigned cmd, registers* regs)
{
    __asm__ __volatile__(
        "inl (%%dx)"
        : "=a" (regs->eax), "=c" (regs->ecx), "=d" (regs->edx), "=b" (regs->ebx)
        : "0" (VMW_MAGIC), "1" (cmd), "2" (VMW_CMD_IOPORT), "3" (MAX_UINT32)
        : "memory");
}

int main(void)
{
    registers regs;
    memset(&regs, 0, sizeof regs);
    vmw_backdoor(VMW_CMD_GET_VER, &regs);
    printf("VMware version: %d.\n", regs.eax);
    return 0;
}

$

This works in g++:

$ g++ vmw_backdoor.cpp
$ ./a.out
VMware version: 6.

It fails to compile in clang:

$ clang vmw_backdoor.cpp
vmw_backdoor.cpp:26:9: error: invalid operand for instruction
        "inl (%%dx)"
        ^
<inline asm>:1:6: note: instantiated into assembly here
        inl (%dx)
            ^
1 error generated.

Any ideas how to make this work? Or is this a clang bug - I know the inline assembler is probably the last component anyone really cares about, but any help would be much appreciated.

Thanks,
John Calcote

This e-mail (and any attachments) is confidential and may be privileged.  Any unauthorized use, copying, disclosure or dissemination of this communication is prohibited.  If you are not the intended recipient,  please notify the sender immediately and delete all copies of the message and its attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131113/ac984632/attachment.html>


More information about the cfe-dev mailing list