Autoconfify, add CPUID helper program to detect HVM domains (Paolo Bonzini).
[virt-what.git] / virt-what-cpuid-helper.c
1 /* virt-what-cpuid-helper: Are we running inside KVM or Xen HVM?
2  * Copyright (C) 2008 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 /* This program was suggested by Gleb Natapov and written by Paolo
20  * Bonzini, with a few modifications by Richard W.M. Jones.
21  */
22
23 #include <stdio.h>
24 #include <string.h>
25
26 #if defined(__i386__) || defined(__x86_64__)
27 void
28 cpu_sig (char *sig)
29 {
30   unsigned int eax = 0x40000000;
31   unsigned int *sig32 = (unsigned int *)sig;
32   asm volatile (
33         "xor %%ebx, %%ebx; cpuid"
34         : "=a" (eax), "=b" (sig32[0]), "=c" (sig32[1]), "=d" (sig32[2])
35         : "0" (eax));
36   sig[12] = 0;
37 }
38 #else
39 void
40 cpu_sig (char *sig)
41 {
42   /* nothing for other architectures */
43 }
44 #endif
45
46 int
47 main()
48 {
49   char sig[13];
50
51   memset (sig, 0, sizeof sig);
52
53   cpu_sig (sig);
54
55   puts (sig);
56   /* Possible values:
57    * KVMKVMKVM     KVM guest
58    * XenVMMXenVMM  Xen HVM guest
59    */
60
61   return 0;
62 }