]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Make VMWare hypervisor port detection code PIC.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Dec 2010 15:20:54 +0000 (16:20 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Dec 2010 15:20:54 +0000 (16:20 +0100)
src/fireinfo.c

index 3a03a39f0c574ac8be30d776f927aee8fe55dac4..03317e152d64dcc73026afa65e7ac3d9fca8212b 100644 (file)
 
 #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 *