1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-12-16 16:35:45 +00:00

Ported to Win32 (MSVC 2005), added MSVC solution and project files. Seems to work :)

git-svn-id: https://svn.code.sf.net/p/libcpuid/code/HEAD/libcpuid@26 3b4be424-7ac5-41d7-8526-f4ddcb85d872
This commit is contained in:
Veselin Georgiev 2008-11-20 18:26:46 +00:00
parent ef4d92a9ea
commit 4dfb11f699
7 changed files with 500 additions and 42 deletions

View file

@ -137,6 +137,7 @@ const int sz_match = (sizeof(matchtable) / sizeof(matchtable[0]));
static void usage(void) static void usage(void)
{ {
int line_fill, l, i;
printf("Usage: cpuid_tool [options]\n\n"); printf("Usage: cpuid_tool [options]\n\n");
printf("Options:\n"); printf("Options:\n");
printf(" -h,--help - Show this help\n"); printf(" -h,--help - Show this help\n");
@ -152,7 +153,7 @@ static void usage(void)
printf("\n"); printf("\n");
printf("Query switches (generate 1 line of ouput per switch; in order of appearance):"); printf("Query switches (generate 1 line of ouput per switch; in order of appearance):");
int line_fill = 80, l, i; line_fill = 80;
for (i = 0; i < sz_match; i++) { for (i = 0; i < sz_match; i++) {
l = (int) strlen(matchtable[i].synopsis); l = (int) strlen(matchtable[i].synopsis);
if (line_fill + l > 76) { if (line_fill + l > 76) {
@ -177,6 +178,8 @@ static int parse_cmdline(int argc, char** argv)
fprintf(stderr, "Error: %s\n\n", msg); \ fprintf(stderr, "Error: %s\n\n", msg); \
fprintf(stderr, "Use -h to get a list of supported options\n"); \ fprintf(stderr, "Use -h to get a list of supported options\n"); \
return -1; return -1;
int i, j, recog;
if (argc == 1) { if (argc == 1) {
/* Default command line options */ /* Default command line options */
need_output = 1; need_output = 1;
@ -186,7 +189,6 @@ static int parse_cmdline(int argc, char** argv)
need_verbose = 1; need_verbose = 1;
return 1; return 1;
} }
int i, j, recog;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
char *arg = argv[i]; char *arg = argv[i];
recog = 0; recog = 0;
@ -389,11 +391,12 @@ int main(int argc, char** argv)
int parseres = parse_cmdline(argc, argv); int parseres = parse_cmdline(argc, argv);
int i, readres, writeres; int i, readres, writeres;
int only_clock_queries; int only_clock_queries;
if (parseres != 1)
return parseres;
struct cpu_raw_data_t raw; struct cpu_raw_data_t raw;
struct cpu_id_t data; struct cpu_id_t data;
if (parseres != 1)
return parseres;
/* In quiet mode, disable libcpuid warning messages: */ /* In quiet mode, disable libcpuid warning messages: */
if (need_quiet) if (need_quiet)
cpuid_set_warn_function(NULL); cpuid_set_warn_function(NULL);

View file

@ -0,0 +1,207 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="cpuid_tool"
ProjectGUID="{854A36FB-EA23-4165-9110-A55EB97C6377}"
RootNamespace="cpuid_tool"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../libcpuid"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
CompileAs="1"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libcpuid.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="../libcpuid/Debug"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../libcpuid"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="1"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libcpuid.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="../libcpuid/Release"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\cpuid_tool.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

28
libcpuid.sln Normal file
View file

@ -0,0 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcpuid", "libcpuid\libcpuid.vcproj", "{92BDBA37-96E3-4D85-B762-185E4407BB49}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpuid_tool", "cpuid_tool\cpuid_tool.vcproj", "{854A36FB-EA23-4165-9110-A55EB97C6377}"
ProjectSection(ProjectDependencies) = postProject
{92BDBA37-96E3-4D85-B762-185E4407BB49} = {92BDBA37-96E3-4D85-B762-185E4407BB49}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{92BDBA37-96E3-4D85-B762-185E4407BB49}.Debug|Win32.ActiveCfg = Debug|Win32
{92BDBA37-96E3-4D85-B762-185E4407BB49}.Debug|Win32.Build.0 = Debug|Win32
{92BDBA37-96E3-4D85-B762-185E4407BB49}.Release|Win32.ActiveCfg = Release|Win32
{92BDBA37-96E3-4D85-B762-185E4407BB49}.Release|Win32.Build.0 = Release|Win32
{854A36FB-EA23-4165-9110-A55EB97C6377}.Debug|Win32.ActiveCfg = Debug|Win32
{854A36FB-EA23-4165-9110-A55EB97C6377}.Debug|Win32.Build.0 = Debug|Win32
{854A36FB-EA23-4165-9110-A55EB97C6377}.Release|Win32.ActiveCfg = Release|Win32
{854A36FB-EA23-4165-9110-A55EB97C6377}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -191,13 +191,8 @@ static void load_features_common(struct cpu_raw_data_t* raw, struct cpu_id_t* da
static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data) static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
{ {
int i, j; int i, j, basic, xmodel, xfamily, ext;
char brandstr[64] = {0};
memcpy(data->vendor_str + 0, &raw->basic_cpuid[0][1], 4);
memcpy(data->vendor_str + 4, &raw->basic_cpuid[0][3], 4);
memcpy(data->vendor_str + 8, &raw->basic_cpuid[0][2], 4);
data->vendor_str[12] = 0;
/* Determine vendor: */
const struct { cpu_vendor_t vendor; char match[16]; } const struct { cpu_vendor_t vendor; char match[16]; }
matchtable[NUM_CPU_VENDORS] = { matchtable[NUM_CPU_VENDORS] = {
/* source: http://www.sandpile.org/ia32/cpuid.htm */ /* source: http://www.sandpile.org/ia32/cpuid.htm */
@ -212,6 +207,12 @@ static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* dat
{ VENDOR_SIS , "SiS SiS SiS " }, { VENDOR_SIS , "SiS SiS SiS " },
{ VENDOR_NSC , "Geode by NSC" }, { VENDOR_NSC , "Geode by NSC" },
}; };
memcpy(data->vendor_str + 0, &raw->basic_cpuid[0][1], 4);
memcpy(data->vendor_str + 4, &raw->basic_cpuid[0][3], 4);
memcpy(data->vendor_str + 8, &raw->basic_cpuid[0][2], 4);
data->vendor_str[12] = 0;
/* Determine vendor: */
data->vendor = VENDOR_UNKNOWN; data->vendor = VENDOR_UNKNOWN;
for (i = 0; i < NUM_CPU_VENDORS; i++) for (i = 0; i < NUM_CPU_VENDORS; i++)
if (!strcmp(data->vendor_str, matchtable[i].match)) { if (!strcmp(data->vendor_str, matchtable[i].match)) {
@ -220,8 +221,7 @@ static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* dat
} }
if (data->vendor == VENDOR_UNKNOWN) if (data->vendor == VENDOR_UNKNOWN)
return set_error(ERR_CPU_UNKN); return set_error(ERR_CPU_UNKN);
int basic = raw->basic_cpuid[0][0]; basic = raw->basic_cpuid[0][0];
int xmodel, xfamily;
if (basic >= 1) { if (basic >= 1) {
data->family = (raw->basic_cpuid[1][0] >> 8) & 0xf; data->family = (raw->basic_cpuid[1][0] >> 8) & 0xf;
data->model = (raw->basic_cpuid[1][0] >> 4) & 0xf; data->model = (raw->basic_cpuid[1][0] >> 4) & 0xf;
@ -234,10 +234,9 @@ static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* dat
data->ext_family = data->family + xfamily; data->ext_family = data->family + xfamily;
data->ext_model = data->model + (xmodel << 4); data->ext_model = data->model + (xmodel << 4);
} }
int ext = raw->ext_cpuid[0][0] - 0x8000000; ext = raw->ext_cpuid[0][0] - 0x8000000;
/* obtain the brand string, if present: */ /* obtain the brand string, if present: */
char brandstr[64] = {0};
if (ext >= 4) { if (ext >= 4) {
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
@ -342,7 +341,7 @@ int cpuid_deserialize_raw_data(struct cpu_raw_data_t* data, const char* filename
if (!f) return set_error(ERR_OPEN); if (!f) return set_error(ERR_OPEN);
while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
++cur_line; ++cur_line;
len = strlen(line); len = (int) strlen(line);
if (len < 2) continue; if (len < 2) continue;
if (line[len - 1] == '\n') if (line[len - 1] == '\n')
line[--len] = '\0'; line[--len] = '\0';

221
libcpuid/libcpuid.vcproj Normal file
View file

@ -0,0 +1,221 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="libcpuid"
ProjectGUID="{92BDBA37-96E3-4D85-B762-185E4407BB49}"
RootNamespace="libcpuid"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;VERSION=&quot;\&quot;0.1.0\&quot;&quot;"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
CompileAs="1"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(ProjectDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VERSION=&quot;\&quot;0.1.0\&quot;&quot;"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
CompileAs="1"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\asm-bits.c"
>
</File>
<File
RelativePath=".\cpuid_main.c"
>
</File>
<File
RelativePath=".\libcpuid_util.c"
>
</File>
<File
RelativePath=".\rdtsc.c"
>
</File>
<File
RelativePath=".\recog_amd.c"
>
</File>
<File
RelativePath=".\recog_intel.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\asm-bits.h"
>
</File>
<File
RelativePath=".\libcpuid.h"
>
</File>
<File
RelativePath=".\libcpuid_constants.h"
>
</File>
<File
RelativePath=".\libcpuid_types.h"
>
</File>
<File
RelativePath=".\libcpuid_util.h"
>
</File>
<File
RelativePath=".\recog_amd.h"
>
</File>
<File
RelativePath=".\recog_intel.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -48,9 +48,9 @@ libcpuid_warn_fn_t _warn_fun = default_warn;
void warnf(const char* format, ...) void warnf(const char* format, ...)
{ {
if (!_warn_fun) return;
char buff[1024]; char buff[1024];
va_list va; va_list va;
if (!_warn_fun) return;
va_start(va, format); va_start(va, format);
vsnprintf(buff, sizeof(buff), format, va); vsnprintf(buff, sizeof(buff), format, va);
va_end(va); va_end(va);

View file

@ -443,28 +443,35 @@ static void decode_intel_codename(struct cpu_raw_data_t* raw, struct cpu_id_t* d
intel_code_t code = NO_CODE; intel_code_t code = NO_CODE;
int i; int i;
const char* bs = data->brand_str; const char* bs = data->brand_str;
const struct { int cache_size; intel_code_t code; } match_cache[] = {
{ 512, CORE_DUO_512K },
{ 1024, CORE_DUO_1024K },
{ 2048, ALLENDALE },
{ 3072, PENRYN },
{ 6144, WOLFDALE },
};
const struct { intel_code_t c; const char *search; } matchtable[] = {
{ XEONMP, "Xeon MP" },
{ XEONMP, "Xeon(TM) MP" },
{ XEON, "Xeon" },
{ CELERON, "Celeron" },
{ MOBILE_PENTIUM_M, "Pentium(R) M" },
{ PENTIUM_D, "Pentium(R) D" },
{ PENTIUM, "Pentium" },
{ CORE_SOLO, "Genuine Intel(R) CPU" },
{ CORE_SOLO, "Intel(R) Core(TM)2" },
{ ATOM_DIAMONDVILLE, "Atom(TM) CPU 2" },
{ ATOM_DIAMONDVILLE, "Atom(TM) CPU N" },
{ ATOM_DUALCORE, "Atom(TM) CPU 3" },
{ ATOM_SILVERTHORNE, "Atom(TM) CPU Z" },
};
if (strstr(bs, "Mobile")) { if (strstr(bs, "Mobile")) {
if (strstr(bs, "Celeron")) if (strstr(bs, "Celeron"))
code = MOBILE_CELERON; code = MOBILE_CELERON;
else if (strstr(bs, "Pentium")) else if (strstr(bs, "Pentium"))
code = MOBILE_PENTIUM; code = MOBILE_PENTIUM;
} else { } else {
const struct { intel_code_t c; const char *search; }
matchtable[] = {
{ XEONMP, "Xeon MP" },
{ XEONMP, "Xeon(TM) MP" },
{ XEON, "Xeon" },
{ CELERON, "Celeron" },
{ MOBILE_PENTIUM_M, "Pentium(R) M" },
{ PENTIUM_D, "Pentium(R) D" },
{ PENTIUM, "Pentium" },
{ CORE_SOLO, "Genuine Intel(R) CPU" },
{ CORE_SOLO, "Intel(R) Core(TM)2" },
{ ATOM_DIAMONDVILLE, "Atom(TM) CPU 2" },
{ ATOM_DIAMONDVILLE, "Atom(TM) CPU N" },
{ ATOM_DUALCORE, "Atom(TM) CPU 3" },
{ ATOM_SILVERTHORNE, "Atom(TM) CPU Z" },
};
for (i = 0; i < COUNT_OF(matchtable); i++) for (i = 0; i < COUNT_OF(matchtable); i++)
if (strstr(bs, matchtable[i].search)) { if (strstr(bs, matchtable[i].search)) {
code = matchtable[i].c; code = matchtable[i].c;
@ -497,14 +504,7 @@ static void decode_intel_codename(struct cpu_raw_data_t* raw, struct cpu_id_t* d
code = MORE_THAN_QUADCORE; break; code = MORE_THAN_QUADCORE; break;
} }
} }
const struct { int cache_size; intel_code_t code; }
match_cache[] = {
{ 512, CORE_DUO_512K },
{ 1024, CORE_DUO_1024K },
{ 2048, ALLENDALE },
{ 3072, PENRYN },
{ 6144, WOLFDALE },
};
if (code == CORE_DUO && data->l2_cache != 4096) { if (code == CORE_DUO && data->l2_cache != 4096) {
for (i = 0; i < COUNT_OF(match_cache); i++) { for (i = 0; i < COUNT_OF(match_cache); i++) {
if (match_cache[i].cache_size == data->l2_cache) { if (match_cache[i].cache_size == data->l2_cache) {