From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32750 invoked by alias); 20 Nov 2014 10:47:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32609 invoked by uid 89); 20 Nov 2014 10:47:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga02.intel.com Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Nov 2014 10:47:40 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 20 Nov 2014 02:47:31 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 20 Nov 2014 02:47:29 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id sAKAlSWj008500; Thu, 20 Nov 2014 10:47:28 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id sAKAlSxF010277; Thu, 20 Nov 2014 11:47:28 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id sAKAlS51010273; Thu, 20 Nov 2014 11:47:28 +0100 From: Markus Metzger To: palves@redhat.com Cc: gdb-patches@sourceware.org Subject: [PATCH v2 09/13] btrace: identify cpu Date: Thu, 20 Nov 2014 10:47:00 -0000 Message-Id: <1416480444-9943-10-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1416480444-9943-1-git-send-email-markus.t.metzger@intel.com> References: <1416480444-9943-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2014-11/txt/msg00461.txt.bz2 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-11-20 Markus Metzger * nat/x86-btrace.h (btrace_cpu_vendor, btrace_cpu) (btrace_this_cpu): New. * nat/x86-btrace.c: Include x86-cpuid.h. (btrace_this_cpu): New. --- gdb/nat/x86-btrace.c | 37 +++++++++++++++++++++++++++++++++++++ gdb/nat/x86-btrace.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/gdb/nat/x86-btrace.c b/gdb/nat/x86-btrace.c index 5ca5731..845e895 100644 --- a/gdb/nat/x86-btrace.c +++ b/gdb/nat/x86-btrace.c @@ -18,10 +18,47 @@ along with this program. If not, see . */ #include "x86-btrace.h" +#include "x86-cpuid.h" /* See x86-btrace.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 = x86_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 = x86_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 x86-btrace.h. */ + const char * btrace_format_string (enum btrace_format format) { diff --git a/gdb/nat/x86-btrace.h b/gdb/nat/x86-btrace.h index 48d6284..05d41fd 100644 --- a/gdb/nat/x86-btrace.h +++ b/gdb/nat/x86-btrace.h @@ -62,6 +62,34 @@ enum btrace_format BTRACE_FORMAT_BTS }; +/* 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 @@ -141,6 +169,9 @@ enum btrace_error BTRACE_ERR_OVERFLOW }; +/* 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