diff options
author | Jakub Zawadzki <darkjames@darkjames.pl> | 2014-05-31 11:22:56 +0200 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2014-05-31 13:01:08 +0000 |
commit | 531541660b31e87922021158454b2441e67935fa (patch) | |
tree | 6594ab833afa6c6887627c8058e990ba931ebedc | |
parent | 799972425dc2178b28067e729abc99d31e0ccc67 (diff) |
Move cpuid to seperate header file.
It'll be later used also for detecting sse4.2
Change-Id: I1930abb29026b455d453a79b5f301cdf37585160
Reviewed-on: https://code.wireshark.org/review/1803
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | version_info.c | 51 | ||||
-rw-r--r-- | wsutil/Makefile.common | 3 | ||||
-rw-r--r-- | wsutil/ws_cpuid.h | 66 |
3 files changed, 73 insertions, 47 deletions
diff --git a/version_info.c b/version_info.c index 293fb1d904..c400130fd5 100644 --- a/version_info.c +++ b/version_info.c @@ -40,6 +40,7 @@ #include "version_info.h" #include "capture-pcap-util.h" #include <wsutil/unicode-utils.h> +#include <wsutil/ws_cpuid.h> #include "version.h" @@ -618,51 +619,9 @@ void get_os_version_info(GString *str) * Get the CPU info, and append it to the GString */ -#if defined(_MSC_VER) -static void -do_cpuid(int *CPUInfo, guint32 selector){ - __cpuid(CPUInfo, selector); -} -#elif defined(__GNUC__) -#if defined(__x86_64__) -static inline void -do_cpuid(guint32 *CPUInfo, int selector) -{ - __asm__ __volatile__("cpuid" - : "=a" (CPUInfo[0]), - "=b" (CPUInfo[1]), - "=c" (CPUInfo[2]), - "=d" (CPUInfo[3]) - : "a"(selector)); -} -#else /* (__i386__) */ -/* would need a test if older proccesors have the cpuid instruction */ -static void -do_cpuid(guint32 *CPUInfo, int selector _U_){ - CPUInfo[0] = 0; -} - -#endif /* defined(__x86_64__)*/ -#else /* Other compilers */ -static void -do_cpuid(guint32 *CPUInfo, int selector _U_){ - CPUInfo[0] = 0; -} -#endif - -/* - * Get CPU info on platforms where the cpuid instruction can be used skip 32 bit versions for GCC - * http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/processor-identification-cpuid-instruction-note.pdf - * the get_cpuid() routine will return 0 in CPUInfo[0] if cpuinfo isn't available. - */ - static void get_cpu_info(GString *str _U_) { -#if defined(_MSC_VER) - int CPUInfo[4]; -#else guint32 CPUInfo[4]; -#endif char CPUBrandString[0x40]; unsigned nExIds; @@ -670,7 +629,7 @@ static void get_cpu_info(GString *str _U_) /* Calling __cpuid with 0x80000000 as the InfoType argument*/ /* gets the number of valid extended IDs.*/ - do_cpuid(CPUInfo, 0x80000000); + ws_cpuid(CPUInfo, 0x80000000); nExIds = CPUInfo[0]; if( nExIds<0x80000005) @@ -678,11 +637,11 @@ static void get_cpu_info(GString *str _U_) memset(CPUBrandString, 0, sizeof(CPUBrandString)); /* Interpret CPU brand string.*/ - do_cpuid(CPUInfo, 0x80000002); + ws_cpuid(CPUInfo, 0x80000002); memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo)); - do_cpuid(CPUInfo, 0x80000003); + ws_cpuid(CPUInfo, 0x80000003); memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo)); - do_cpuid(CPUInfo, 0x80000004); + ws_cpuid(CPUInfo, 0x80000004); memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo)); g_string_append_printf(str, "\n%s", CPUBrandString); diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index 5aa179ee29..94f8c8f51c 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -102,7 +102,8 @@ LIBWSUTIL_INCLUDES = \ time_util.h \ type_util.h \ u3.h \ - unicode-utils.h + unicode-utils.h \ + ws_cpuid.h # # Editor modelines - http://www.wireshark.org/tools/modelines.html diff --git a/wsutil/ws_cpuid.h b/wsutil/ws_cpuid.h new file mode 100644 index 0000000000..75500f2c4d --- /dev/null +++ b/wsutil/ws_cpuid.h @@ -0,0 +1,66 @@ +/* ws_cpuid.h + * Get the CPU info + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * Get CPU info on platforms where the cpuid instruction can be used skip 32 bit versions for GCC + * http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/processor-identification-cpuid-instruction-note.pdf + * the ws_cpuid() routine will return 0 in CPUInfo[0] if cpuinfo isn't available. + */ + +#if defined(_MSC_VER) /* MSVC */ +static void +ws_cpuid(guint32 *CPUInfo, guint32 selector) +{ + __cpuid((int *) CPUInfo, selector); +} + +#elif defined(__GNUC__) /* GCC/clang */ + +#if defined(__x86_64__) +static inline void +ws_cpuid(guint32 *CPUInfo, int selector) +{ + __asm__ __volatile__("cpuid" + : "=a" (CPUInfo[0]), + "=b" (CPUInfo[1]), + "=c" (CPUInfo[2]), + "=d" (CPUInfo[3]) + : "a"(selector)); +} +#else /* (__i386__) */ + +static void +ws_cpuid(guint32 *CPUInfo, int selector _U_) +{ + /* TODO: need a test if older proccesors have the cpuid instruction */ + CPUInfo[0] = 0; +} +#endif + +#else /* Other compilers */ + +static void +ws_cpuid(guint32 *CPUInfo, int selector _U_) +{ + CPUInfo[0] = 0; +} +#endif |