#ifndef __VIRT_H_INCLUDE_GUARD__ #define __VIRT_H_INCLUDE_GUARD__ /* * Copyright (C) 2006, Intel Corporation * 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 */ #include #define CURRENT_CPU 0xFF typedef struct __cpu_registers { uint32_t eax; uint32_t ebx; uint32_t ecx; uint32_t edx; }cpu_registers; static inline void exec_cpuid( int cpu, uint32_t cmd, cpu_registers* regs) { cpu_set_t mask, oldmask; if (cpu != CURRENT_CPU) { sched_getaffinity(0, sizeof(oldmask), &oldmask); CPU_ZERO(&mask); CPU_SET(cpu, &mask); sched_setaffinity(0, sizeof(mask), &mask); } #if defined(__i386__) __asm__ __volatile__ ( "pushl %%ebx \n\t" "cpuid \n\t" "movl %%ebx,%%esi \n\t" "popl %%ebx \n\t" : "=a"(regs->eax),"=S"(regs->ebx), "=c"(regs->ecx),"=d"(regs->edx) : "a"(cmd) ); #elif defined (__x86_64__) __asm__ __volatile__ ( "cpuid \n\t" : "=a"(regs->eax),"=b"(regs->ebx), "=c"(regs->ecx),"=d"(regs->edx) : "a"(cmd) ); #endif if (cpu != CURRENT_CPU) { sched_setaffinity(0, sizeof(oldmask), &oldmask); } } #endif