#include <stdint.h>
#include <string.h>
#include <cpu.h>
Go to the source code of this file.
Functions | |
| static int | flag_is_changeable (unsigned int flag) |
| Test to see if CPU flag is changeable. | |
| void | get_cpuinfo (struct cpuinfo_x86 *cpu) |
| Get CPU information. | |
Definition in file cpu.c.
| static int flag_is_changeable | ( | unsigned int | flag | ) | [inline, static] |
Test to see if CPU flag is changeable.
| flag | Flag to test |
| can_change | Flag is changeable |
Definition at line 17 of file cpu.c.
References __asm__(), f1(), and f2().
Referenced by get_cpuinfo().
00017 { 00018 uint32_t f1, f2; 00019 00020 __asm__ ( "pushfl\n\t" 00021 "pushfl\n\t" 00022 "popl %0\n\t" 00023 "movl %0,%1\n\t" 00024 "xorl %2,%0\n\t" 00025 "pushl %0\n\t" 00026 "popfl\n\t" 00027 "pushfl\n\t" 00028 "popl %0\n\t" 00029 "popfl\n\t" 00030 : "=&r" ( f1 ), "=&r" ( f2 ) 00031 : "ir" ( flag ) ); 00032 00033 return ( ( ( f1 ^ f2 ) & flag ) != 0 ); 00034 }
| void get_cpuinfo | ( | struct cpuinfo_x86 * | cpu | ) |
Get CPU information.
| cpu | CPU information structure to fill in |
Definition at line 41 of file cpu.c.
References cpuinfo_x86::amd_features, DBG, cpuinfo_x86::features, flag_is_changeable(), memset(), and X86_EFLAGS_ID.
00041 { 00042 unsigned int cpuid_level; 00043 unsigned int cpuid_extlevel; 00044 unsigned int discard_1, discard_2, discard_3; 00045 00046 memset ( cpu, 0, sizeof ( *cpu ) ); 00047 00048 /* Check for CPUID instruction */ 00049 if ( ! flag_is_changeable ( X86_EFLAGS_ID ) ) { 00050 DBG ( "CPUID not supported\n" ); 00051 return; 00052 } 00053 00054 /* Get features, if present */ 00055 cpuid ( 0x00000000, &cpuid_level, &discard_1, 00056 &discard_2, &discard_3 ); 00057 if ( cpuid_level >= 0x00000001 ) { 00058 cpuid ( 0x00000001, &discard_1, &discard_2, 00059 &discard_3, &cpu->features ); 00060 } else { 00061 DBG ( "CPUID cannot return capabilities\n" ); 00062 } 00063 00064 /* Get 64-bit features, if present */ 00065 cpuid ( 0x80000000, &cpuid_extlevel, &discard_1, 00066 &discard_2, &discard_3 ); 00067 if ( ( cpuid_extlevel & 0xffff0000 ) == 0x80000000 ) { 00068 if ( cpuid_extlevel >= 0x80000001 ) { 00069 cpuid ( 0x80000001, &discard_1, &discard_2, 00070 &discard_3, &cpu->amd_features ); 00071 } 00072 } 00073 }
1.5.7.1