Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

CPUInfo.c File Reference

#include <windows.h>
#include <string.h>
#include "CPUInfo.h"

Go to the source code of this file.

Defines

#define WIN32_LEAN_AND_MEAN
#define CPUID   _asm _emit 0fh _asm _emit 0a2h
#define CPUINFO_VENDOR_STRING_LENGTH   16
#define CPUINFO_AMD_ID_STRING   "AuthenticAMD"
#define CPUINFO_INTEL_ID_STRING   "GenuineIntel"

Functions

void Test_CPU_bits (void)
uint32 CPUInfo_GetCPUIDEAX (uint32 funcNum)
uint32 CPUInfo_GetCPUIDEDX (uint32 funcNum)
uint32 CPUInfo_GetCPUIDString (uint32 funcNum, char *szId)
geBoolean CPUInfo_TestFor3DNow (void)
geBoolean CPUInfo_TestForMMX (void)

Variables

int Flag_CPUID = TRUE
int Flag_RDTSC = TRUE


Define Documentation

#define CPUID   _asm _emit 0fh _asm _emit 0a2h
 

Definition at line 31 of file CPUInfo.c.

#define CPUINFO_AMD_ID_STRING   "AuthenticAMD"
 

Definition at line 163 of file CPUInfo.c.

Referenced by CPUInfo_TestFor3DNow(), and CPUInfo_TestForMMX().

#define CPUINFO_INTEL_ID_STRING   "GenuineIntel"
 

Definition at line 164 of file CPUInfo.c.

Referenced by CPUInfo_TestForMMX().

#define CPUINFO_VENDOR_STRING_LENGTH   16
 

Definition at line 162 of file CPUInfo.c.

Referenced by CPUInfo_TestFor3DNow(), and CPUInfo_TestForMMX().

#define WIN32_LEAN_AND_MEAN
 

Definition at line 23 of file CPUInfo.c.


Function Documentation

uint32 CPUInfo_GetCPUIDEAX uint32  funcNum  )  [static]
 

Definition at line 72 of file CPUInfo.c.

References CPUID, Flag_CPUID, Test_CPU_bits(), and uint32.

Referenced by CPUInfo_TestFor3DNow(), and CPUInfo_TestForMMX().

00073 {
00074         uint32  retval;
00075 
00076         Test_CPU_bits();
00077         if (Flag_CPUID)
00078                 {
00079                         __try
00080                         {
00081                                 _asm
00082                                 {
00083                                         mov     eax,funcNum
00084                                         CPUID
00085                                         mov     retval,eax
00086                                 }
00087                         }__except(EXCEPTION_EXECUTE_HANDLER)
00088                         {
00089                                 retval  =0;
00090                         }
00091                 }
00092         else
00093                 {
00094                         retval = 0;
00095                 }
00096 
00097         return  retval;
00098 }

uint32 CPUInfo_GetCPUIDEDX uint32  funcNum  )  [static]
 

Definition at line 100 of file CPUInfo.c.

References CPUID, Flag_CPUID, Test_CPU_bits(), and uint32.

Referenced by CPUInfo_TestFor3DNow(), and CPUInfo_TestForMMX().

00101 {
00102         uint32  retval;
00103 
00104         Test_CPU_bits();
00105         if (Flag_CPUID)
00106                 {
00107                         __try
00108                         {
00109                                 _asm
00110                                 {
00111                                         mov     eax,funcNum
00112                                         CPUID
00113                                         mov     retval,edx
00114                                 }
00115                         }__except(EXCEPTION_EXECUTE_HANDLER)
00116                         {
00117                                 retval  =0;
00118                         }
00119                 }
00120         else
00121                 {
00122                         retval = 0;
00123                 }
00124         
00125         return  retval;
00126 }

uint32 CPUInfo_GetCPUIDString uint32  funcNum,
char *  szId
[static]
 

Definition at line 129 of file CPUInfo.c.

References CPUID, Flag_CPUID, Test_CPU_bits(), and uint32.

Referenced by CPUInfo_TestFor3DNow(), and CPUInfo_TestForMMX().

00130 {
00131         uint32  retval;
00132         
00133         Test_CPU_bits();
00134         if (Flag_CPUID)
00135                 {
00136                         __try
00137                         {
00138                                 _asm
00139                                 {
00140                                         mov     eax,funcNum
00141                                         CPUID
00142                                         mov     retval,eax
00143                                         mov     eax,szId
00144                                         mov     dword ptr[eax],ebx
00145                                         mov     dword ptr[eax+4],edx
00146                                         mov     dword ptr[eax+8],ecx
00147                                 }
00148                         }__except(EXCEPTION_EXECUTE_HANDLER)
00149                         {
00150                                 retval  =0;
00151                         }
00152                 }
00153         else
00154                 {
00155                         retval = 0;
00156                 }
00157 
00158         return  retval;
00159 }

geBoolean CPUInfo_TestFor3DNow void   ) 
 

Definition at line 166 of file CPUInfo.c.

References CPUINFO_AMD_ID_STRING, CPUInfo_GetCPUIDEAX(), CPUInfo_GetCPUIDEDX(), CPUInfo_GetCPUIDString(), CPUINFO_VENDOR_STRING_LENGTH, GE_FALSE, GE_TRUE, geBoolean, and uint32.

Referenced by SoftDrv_Init().

00167 {
00168         char VendorString[CPUINFO_VENDOR_STRING_LENGTH];
00169 
00170         CPUInfo_GetCPUIDString(0, VendorString);
00171         if(strncmp(VendorString, CPUINFO_AMD_ID_STRING,strlen(CPUINFO_AMD_ID_STRING))==0)
00172                 {
00173                         uint32  TypeFlags       =CPUInfo_GetCPUIDEAX(0x80000000);
00174                         if(TypeFlags)   //extended functions supported
00175                                 {
00176                                         TypeFlags       =CPUInfo_GetCPUIDEDX(0x80000001);
00177                                         if (TypeFlags & (1<<23))
00178                                                 return GE_TRUE;
00179                                 }
00180                 }
00181         return GE_FALSE;
00182 }

geBoolean CPUInfo_TestForMMX void   ) 
 

Definition at line 184 of file CPUInfo.c.

References CPUINFO_AMD_ID_STRING, CPUInfo_GetCPUIDEAX(), CPUInfo_GetCPUIDEDX(), CPUInfo_GetCPUIDString(), CPUINFO_INTEL_ID_STRING, CPUINFO_VENDOR_STRING_LENGTH, GE_FALSE, GE_TRUE, geBoolean, and uint32.

Referenced by SoftDrv_Init().

00185 {
00186         char VendorString[CPUINFO_VENDOR_STRING_LENGTH];
00187 
00188         CPUInfo_GetCPUIDString(0, VendorString);
00189         if(strncmp(VendorString, CPUINFO_AMD_ID_STRING,strlen(CPUINFO_AMD_ID_STRING))==0)
00190                 {
00191                         uint32  TypeFlags       =CPUInfo_GetCPUIDEAX(0x80000000);
00192                         if(TypeFlags)   //extended functions supported
00193                                 {
00194                                         TypeFlags       =CPUInfo_GetCPUIDEDX(0x80000001);
00195                                         if (TypeFlags & (1<<23))
00196                                                 return GE_TRUE;
00197                                 }
00198                 }
00199         else if(strncmp(VendorString, CPUINFO_INTEL_ID_STRING, strlen(CPUINFO_INTEL_ID_STRING))==0)
00200         {
00201                 uint32  TypeFlags                               =CPUInfo_GetCPUIDEDX(0x1);
00202                 if (TypeFlags & (1<<23))
00203                         return GE_TRUE;
00204         }
00205 
00206         return GE_FALSE;
00207 }

void Test_CPU_bits void   ) 
 

Definition at line 37 of file CPUInfo.c.

References CPUID, FALSE, Flag_CPUID, and Flag_RDTSC.

00038 {
00039         Flag_CPUID = FALSE;
00040         Flag_RDTSC = FALSE;
00041 _asm
00042     {
00043         pushad                    // (1) play nice and save everything
00044     pushfd                    // eax = ebx = extended flags
00045     pop     eax                              
00046     mov     ebx,eax
00047 
00048     xor     eax,200000h       // toggle bit 21
00049 
00050     push    eax               // extended flags = eax
00051         popfd
00052     xor     eax,ebx           // if bit 21 r/w then eax <> 0
00053 
00054     jz      done              // can't toggle id bit (21) no cpuid here
00055     mov     eax,1             // get standard features
00056     mov     Flag_CPUID,eax    // (and set cpuid flag to true)
00057 
00058         CPUID
00059     test    edx,10h           // is rdtsc available?
00060     jz      done
00061 
00062     mov     Flag_RDTSC,1
00063 done:
00064         popad                     // (1) restore everything
00065     }
00066 }


Variable Documentation

int Flag_CPUID = TRUE [static]
 

Definition at line 33 of file CPUInfo.c.

int Flag_RDTSC = TRUE [static]
 

Definition at line 34 of file CPUInfo.c.


Generated on Tue Sep 30 12:37:13 2003 for GTestAndEngine by doxygen 1.3.2