2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/efiemu/efiemu.h>
20 #include <grub/machine/efiemu.h>
21 #include <grub/command.h>
23 #define cpuid(num,a,b,c,d) \
24 asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
25 : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
28 #define bit_LM (1 << 29)
31 grub_efiemu_get_default_core_name (void)
34 unsigned int eax
, ebx
, ecx
, edx
;
35 unsigned int max_level
;
36 unsigned int ext_level
;
38 /* See if we can use cpuid. */
39 asm volatile ("pushfl; pushfl; popl %0; movl %0,%1; xorl %2,%0;"
40 "pushl %0; popfl; pushfl; popl %0; popfl"
41 : "=&r" (eax
), "=&r" (ebx
)
43 if (((eax
^ ebx
) & 0x00200000) == 0)
46 /* Check the highest input value for eax. */
47 cpuid (0, eax
, ebx
, ecx
, edx
);
48 /* We only look at the first four characters. */
53 cpuid (0x80000000, eax
, ebx
, ecx
, edx
);
55 if (ext_level
< 0x80000000)
58 cpuid (0x80000001, eax
, ebx
, ecx
, edx
);
59 return (edx
& bit_LM
) ? "efiemu64.o" : "efiemu32.o";