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

John Calcote john.calcote at gmail.com
Tue Nov 12 17:54:20 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

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131112/a504e371/attachment.html>


More information about the cfe-dev mailing list