Lee Leahy | 2da9524 | 2015-06-12 17:30:33 -0700 | [diff] [blame^] | 1 | #include <console/console.h> |
| 2 | #include <cpu/cpu.h> |
| 3 | #include <arch/io.h> |
| 4 | #include <string.h> |
| 5 | #include <cpu/x86/mtrr.h> |
| 6 | #include <cpu/x86/msr.h> |
| 7 | #include <cpu/x86/lapic.h> |
| 8 | #include <arch/cpu.h> |
| 9 | #include <device/path.h> |
| 10 | #include <device/device.h> |
| 11 | #include <smp/spinlock.h> |
| 12 | |
| 13 | /* Standard macro to see if a specific flag is changeable */ |
| 14 | static inline int flag_is_changeable_p(uint32_t flag) |
| 15 | { |
| 16 | uint32_t f1, f2; |
| 17 | |
| 18 | asm( |
| 19 | "pushfl\n\t" |
| 20 | "pushfl\n\t" |
| 21 | "popl %0\n\t" |
| 22 | "movl %0,%1\n\t" |
| 23 | "xorl %2,%0\n\t" |
| 24 | "pushl %0\n\t" |
| 25 | "popfl\n\t" |
| 26 | "pushfl\n\t" |
| 27 | "popl %0\n\t" |
| 28 | "popfl\n\t" |
| 29 | : "=&r" (f1), "=&r" (f2) |
| 30 | : "ir" (flag)); |
| 31 | return ((f1^f2) & flag) != 0; |
| 32 | } |
| 33 | |
| 34 | /* Probe for the CPUID instruction */ |
| 35 | int cpu_have_cpuid(void) |
| 36 | { |
| 37 | return flag_is_changeable_p(X86_EFLAGS_ID); |
| 38 | } |
| 39 | |
| 40 | int cpu_cpuid_extended_level(void) |
| 41 | { |
| 42 | return cpuid_eax(0x80000000); |
| 43 | } |
| 44 | |
| 45 | int cpu_phys_address_size(void) |
| 46 | { |
| 47 | if (!(cpu_have_cpuid())) |
| 48 | return 32; |
| 49 | |
| 50 | if (cpu_cpuid_extended_level() >= 0x80000008) |
| 51 | return cpuid_eax(0x80000008) & 0xff; |
| 52 | |
| 53 | if (cpuid_edx(1) & (CPUID_FEATURE_PAE | CPUID_FEATURE_PSE36)) |
| 54 | return 36; |
| 55 | return 32; |
| 56 | } |