From: Michael Tremer Date: Sun, 26 Dec 2010 15:20:54 +0000 (+0100) Subject: Make VMWare hypervisor port detection code PIC. X-Git-Tag: v0.13.1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89ee06f9044dd038354a7ef30e40246db7a9d84b;p=oddments%2Ffireinfo.git Make VMWare hypervisor port detection code PIC. --- diff --git a/src/fireinfo.c b/src/fireinfo.c index 3a03a39..03317e1 100644 --- a/src/fireinfo.c +++ b/src/fireinfo.c @@ -40,14 +40,6 @@ #define VMWARE_PORT_CMD_GETVERSION 10 -#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx)" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "0"(VMWARE_HYPERVISOR_MAGIC), \ - "1"(VMWARE_PORT_CMD_##cmd), \ - "2"(VMWARE_HYPERVISOR_PORT), "3"(UINT_MAX) : \ - "memory"); - /* virtualization types */ enum { VIRT_NONE = 0, @@ -288,14 +280,43 @@ is_virtualized() { return false; } +void +hypervisor_port(unsigned int cmd, unsigned int *eax, unsigned int *ebx, + unsigned int *ecx, unsigned int *edx) +{ + __asm__( +#if defined(__PIC__) && defined(__i386__) + /* x86 PIC really cannot clobber ebx */ + "pushl %%ebx;" + "inl (%%dx);" + "movl %%ebx, %%esi;" + "popl %%ebx;" + : "=S" (*ebx), +#else + "inl (%%dx);" + : "=b" (*ebx), +#endif + "=a" (*eax), + "=c" (*ecx), + "=d" (*edx) + : "0" (VMWARE_HYPERVISOR_MAGIC), + "1" (cmd), + "2" (VMWARE_HYPERVISOR_PORT), + "3" (UINT_MAX) + : "memory" + ); +} + int hypervisor_port_check(void) { - uint32_t eax, ebx, ecx, edx; - VMWARE_PORT(GETVERSION, eax, ebx, ecx, edx); - if (ebx == VMWARE_HYPERVISOR_MAGIC) - return 1; // Success - running under VMware - else - return 0; + uint32_t eax, ebx, ecx, edx; + + hypervisor_port(VMWARE_PORT_CMD_GETVERSION, &eax, &ebx, &ecx, &edx); + + if (ebx == VMWARE_HYPERVISOR_MAGIC) + return 1; // Success - running under VMware + else + return 0; } static PyObject *