/* * Copyright (C) 2006, Intel Corp * Copyright (C) 2007, AMD Inc * * This file is part of the Linux-ready Firmware Developer Kit * * This program file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation;version 2.1 of the License. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program in a file named COPYING; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ /* * This test checks if the virtual machine setup is done correctly by the BIOS */ #define _GNU_SOURCE #include #include #include extern int do_virt_check_svm(); extern int do_virt_check_vmx(); #include "virt.h" #define CPUID_NUM_FEATURES 0x00000000L static int is_amd() { char stramd[64]; memset(stramd, 0, 64); cpu_registers regs; exec_cpuid(CURRENT_CPU, CPUID_NUM_FEATURES, ®s); memcpy(stramd, ®s.ebx, 4 ); memcpy(stramd + 4, ®s.edx, 4); memcpy(stramd + 8, ®s.ecx, 4); return (!strcmp("AuthenticAMD", stramd)); } static int is_intel() { char strintel[64]; memset( strintel, 0, 64 ); cpu_registers regs; exec_cpuid(CURRENT_CPU, CPUID_NUM_FEATURES, ®s); memcpy(strintel, ®s.ebx, 4); memcpy(strintel + 4, ®s.edx, 4); memcpy(strintel + 8, ®s.ecx, 4); return (!strcmp("GenuineIntel", strintel)); } int main(int argc, char **argv) { if (is_amd()) { return do_virt_check_svm(); } else if (is_intel()) { return do_virt_check_vmx(); } }