Consolidate cpuid code.

This commit is contained in:
Vladimir Serbinenko 2013-10-27 00:02:01 +02:00
parent c1bee64676
commit c81acb7ff3
5 changed files with 22 additions and 124 deletions

View file

@ -18,42 +18,10 @@
#include <grub/efiemu/efiemu.h>
#include <grub/command.h>
#define cpuid(num,a,b,c,d) \
asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
: "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
: "0" (num))
#define bit_LM (1 << 29)
#include <grub/i386/cpuid.h>
const char *
grub_efiemu_get_default_core_name (void)
{
unsigned int eax, ebx, ecx, edx;
unsigned int max_level;
unsigned int ext_level;
/* See if we can use cpuid. */
asm volatile ("pushfl; pushfl; popl %0; movl %0,%1; xorl %2,%0;"
"pushl %0; popfl; pushfl; popl %0; popfl"
: "=&r" (eax), "=&r" (ebx)
: "i" (0x00200000));
if (((eax ^ ebx) & 0x00200000) == 0)
return "efiemu32.o";
/* Check the highest input value for eax. */
cpuid (0, eax, ebx, ecx, edx);
/* We only look at the first four characters. */
max_level = eax;
if (max_level == 0)
return "efiemu32.o";
cpuid (0x80000000, eax, ebx, ecx, edx);
ext_level = eax;
if (ext_level < 0x80000000)
return "efiemu32.o";
cpuid (0x80000001, eax, ebx, ecx, edx);
return (edx & bit_LM) ? "efiemu64.o" : "efiemu32.o";
return grub_cpuid_has_longmode ? "efiemu64.o" : "efiemu32.o";
}