#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,
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 *