This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 08/12] btrace: identify cpu


Add a struct for identifying a processor and a function to identify the
processor we're running on.

We will need this feature for the new btrace format.

2014-07-14  Markus Metzger  <markus.t.metzger@intel.com>

	* common/btrace-common.h (btrace_cpu_vendor, btrace_cpu)
	(btrace_this_cpu): New.
	* common/btrace-common.c: Include i386-cpuid.h.
	(btrace_this_cpu): New.


---
 gdb/common/btrace-common.c | 37 +++++++++++++++++++++++++++++++++++++
 gdb/common/btrace-common.h | 30 ++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/gdb/common/btrace-common.c b/gdb/common/btrace-common.c
index 90774a2..178ad35 100644
--- a/gdb/common/btrace-common.c
+++ b/gdb/common/btrace-common.c
@@ -18,10 +18,47 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "btrace-common.h"
+#include "nat/i386-cpuid.h"
 
 
 /* See btrace-common.h.  */
 
+struct btrace_cpu
+btrace_this_cpu (void)
+{
+  struct btrace_cpu cpu;
+  unsigned int eax, ebx, ecx, edx;
+  int ok;
+
+  memset (&cpu, 0, sizeof (cpu));
+
+  ok = i386_cpuid (0, &eax, &ebx, &ecx, &edx);
+  if (ok != 0)
+    {
+      if (ebx == signature_INTEL_ebx && ecx == signature_INTEL_ecx
+	  && edx == signature_INTEL_edx)
+	{
+	  unsigned int cpuid, ignore;
+
+	  ok = i386_cpuid (1, &cpuid, &ignore, &ignore, &ignore);
+	  if (ok != 0)
+	    {
+	      cpu.vendor = CV_INTEL;
+
+	      cpu.family = (cpuid >> 8) & 0xf;
+	      cpu.model = (cpuid >> 4) & 0xf;
+
+	      if (cpu.family == 0x6)
+		cpu.model += (cpuid >> 12) & 0xf0;
+	    }
+	}
+    }
+
+  return cpu;
+}
+
+/* See btrace-common.h.  */
+
 const char *
 btrace_format_string (enum btrace_format format)
 {
diff --git a/gdb/common/btrace-common.h b/gdb/common/btrace-common.h
index 3629736..5fa9806 100644
--- a/gdb/common/btrace-common.h
+++ b/gdb/common/btrace-common.h
@@ -74,6 +74,34 @@ enum btrace_error
   BTRACE_ERR_OVERFLOW
 };
 
+/* An enumeration of cpu vendors.  */
+
+enum btrace_cpu_vendor
+{
+  /* We do not know this vendor.  */
+  CV_UNKNOWN,
+
+  /* Intel.  */
+  CV_INTEL
+};
+
+/* A cpu identifier.  */
+
+struct btrace_cpu
+{
+  /* The processor vendor.  */
+  enum btrace_cpu_vendor vendor;
+
+  /* The cpu family.  */
+  unsigned short family;
+
+  /* The cpu model.  */
+  unsigned char model;
+
+  /* The cpu stepping.  */
+  unsigned char stepping;
+};
+
 /* A BTS configuration.  */
 
 struct btrace_config_bts
@@ -147,6 +175,8 @@ struct btrace_data
   } variant;
 };
 
+/* Identify the cpu we're running on.  */
+extern struct btrace_cpu btrace_this_cpu (void);
 
 /* Return a string representation of FORMAT.  */
 extern const char *btrace_format_string (enum btrace_format format);
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]