* [PATCH 2/2] btrace: use i386-cpuid's cpu identifier
2014-02-13 12:30 [PATCH 1/2] i386-cpuid: add support for identifying a processor Markus Metzger
@ 2014-02-13 12:30 ` Markus Metzger
2014-02-13 13:29 ` [PATCH 1/2] i386-cpuid: add support for identifying a processor Mark Kettenis
2014-02-14 17:29 ` Mike Frysinger
2 siblings, 0 replies; 8+ messages in thread
From: Markus Metzger @ 2014-02-13 12:30 UTC (permalink / raw)
To: jan.kratochvil; +Cc: gdb-patches
2014-02-13 Markus Metzger <markus.t.metzger@intel.com>
* common/linux-btrace.c (intel_supports_btrace): Update parameters.
(cpu_supports_btrace): Call i386_this_cpu.
---
gdb/common/linux-btrace.c | 35 +++++++++++++----------------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/gdb/common/linux-btrace.c b/gdb/common/linux-btrace.c
index 218e0ce..46b28bd 100644
--- a/gdb/common/linux-btrace.c
+++ b/gdb/common/linux-btrace.c
@@ -348,22 +348,12 @@ kernel_supports_btrace (void)
/* Check whether an Intel cpu supports branch tracing. */
static int
-intel_supports_btrace (void)
+intel_supports_btrace (const struct i386_cpu *cpu)
{
- unsigned int cpuid, model, family;
-
- if (!i386_cpuid (1, &cpuid, NULL, NULL, NULL))
- return 0;
-
- family = (cpuid >> 8) & 0xf;
- model = (cpuid >> 4) & 0xf;
-
- switch (family)
+ switch (cpu->family)
{
case 0x6:
- model += (cpuid >> 12) & 0xf0;
-
- switch (model)
+ switch (cpu->model)
{
case 0x1a: /* Nehalem */
case 0x1f:
@@ -391,17 +381,18 @@ intel_supports_btrace (void)
static int
cpu_supports_btrace (void)
{
- unsigned int ebx, ecx, edx;
+ struct i386_cpu cpu;
- if (!i386_cpuid (0, NULL, &ebx, &ecx, &edx))
- return 0;
-
- if (ebx == signature_INTEL_ebx && ecx == signature_INTEL_ecx
- && edx == signature_INTEL_edx)
- return intel_supports_btrace ();
+ cpu = i386_this_cpu ();
+ switch (cpu.vendor)
+ {
+ default:
+ /* Don't know about others. Let's assume they do. */
+ return 1;
- /* Don't know about others. Let's assume they do. */
- return 1;
+ case CV_INTEL:
+ return intel_supports_btrace (&cpu);
+ }
}
/* See linux-btrace.h. */
--
1.8.3.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] i386-cpuid: add support for identifying a processor
@ 2014-02-13 12:30 Markus Metzger
2014-02-13 12:30 ` [PATCH 2/2] btrace: use i386-cpuid's cpu identifier Markus Metzger
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Markus Metzger @ 2014-02-13 12:30 UTC (permalink / raw)
To: jan.kratochvil; +Cc: gdb-patches, Mark Kettenis
Add a struct i386_cpu to identify an x86 cpu and a function i386_this_cpu
to identify the cpu we're running on.
CC: Mark Kettenis <mark.kettenis@xs4all.nl>
2014-02-13 Markus Metzger <markus.t.metzger@intel.com>
* common/i386-cpuid.h (i386_cpu_vendor, i386_cpu)
(i386_this_cpu): New.
* common/i386-cpuid.c (i386_this_cpu): New.
* Makefile.in: (SFILES): Added i386-cpuid.c.
(HFILES_NO_SRCDIR): Added i386-cpuid.h.
(COMMON_OBS): Added i386-cpuid.o.
(i386-cpuid.o): New target.
gdbserver/
* Makefile.in: (SFILES): Added i386-cpuid.c.
(OBS): Added i386-cpuid.o.
(i386-cpuid.o): New target.
---
gdb/Makefile.in | 9 ++++--
gdb/common/i386-cpuid.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
gdb/common/i386-cpuid.h | 33 +++++++++++++++++++++
gdb/gdbserver/Makefile.in | 9 ++++--
4 files changed, 121 insertions(+), 4 deletions(-)
create mode 100644 gdb/common/i386-cpuid.c
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index ea56854..212cb93 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -839,7 +839,8 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
common/gdb_vecs.c common/common-utils.c common/xml-utils.c \
common/ptid.c common/buffer.c gdb-dlfcn.c common/agent.c \
common/format.c common/filestuff.c btrace.c record-btrace.c ctf.c \
- target/waitstatus.c common/print-utils.c common/rsp-low.c
+ target/waitstatus.c common/print-utils.c common/rsp-low.c \
+ common/i386-cpuid.c
LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
@@ -1021,7 +1022,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
gdb_vecs.o jit.o progspace.o skip.o probe.o \
common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
format.o registry.o btrace.o record-btrace.o waitstatus.o \
- print-utils.o rsp-low.o
+ print-utils.o rsp-low.o i386-cpuid.o
TSOBS = inflow.o
@@ -2150,6 +2151,10 @@ rsp-low.o: ${srcdir}/common/rsp-low.c
$(COMPILE) $(srcdir)/common/rsp-low.c
$(POSTCOMPILE)
+i386-cpuid.o: ${srcdir}/common/i386-cpuid.c
+ $(COMPILE) $(srcdir)/common/i386-cpuid.c
+ $(POSTCOMPILE)
+
#
# gdb/target/ dependencies
#
diff --git a/gdb/common/i386-cpuid.c b/gdb/common/i386-cpuid.c
new file mode 100644
index 0000000..7ac05d4
--- /dev/null
+++ b/gdb/common/i386-cpuid.c
@@ -0,0 +1,74 @@
+/*
+ Copyright (C) 2014 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This file 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 3, 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, see <http://www.gnu.org/licenses/>. */
+
+#include "i386-cpuid.h"
+
+#if defined(__i386__) || defined(__x86_64__)
+
+/* See i386-cpuid.h. */
+
+struct i386_cpu
+i386_this_cpu (void)
+{
+ struct i386_cpu cpu;
+ unsigned int eax, ebx, ecx, edx;
+ int ok;
+
+ cpu.vendor = CV_UNKNOWN;
+
+ 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;
+ cpu.stepping = cpuid & 0xf;
+
+ if (cpu.family == 0x6)
+ cpu.model += (cpuid >> 12) & 0xf0;
+ }
+ }
+ }
+
+ return cpu;
+}
+
+#else /* i386 && x86_64 */
+
+/* See i386-cpuid.h. */
+
+struct i386_cpu
+i386_this_cpu (void)
+{
+ struct i386_cpu cpu;
+
+ cpu.vendor = CV_UNKNOWN;
+
+ return cpu;
+}
+
+#endif /* i386 && x86_64 */
diff --git a/gdb/common/i386-cpuid.h b/gdb/common/i386-cpuid.h
index 9aea054..1ed0251 100644
--- a/gdb/common/i386-cpuid.h
+++ b/gdb/common/i386-cpuid.h
@@ -22,6 +22,35 @@
/* Always include the header for the cpu bit defines. */
#include "i386-gcc-cpuid.h"
+/* An enumeration of cpu vendors. */
+
+enum i386_cpu_vendor
+{
+ /* We do not know this vendor. */
+ CV_UNKNOWN,
+
+ /* Intel. */
+ CV_INTEL
+};
+
+/* A cpu identifier. */
+
+struct i386_cpu
+{
+ /* The processor vendor. */
+ enum i386_cpu_vendor vendor;
+
+ /* The cpu family. */
+ unsigned short family;
+
+ /* The cpu model. */
+ unsigned char model;
+
+ /* The cpu stepping. */
+ unsigned char stepping;
+};
+
+
#if defined(__i386__) || defined(__x86_64__)
/* Return cpuid data for requested cpuid level, as found in returned
@@ -60,4 +89,8 @@ i386_cpuid (unsigned int __level,
#endif /* i386 && x86_64 */
+/* Identify the cpu we're running on. */
+
+extern struct i386_cpu i386_this_cpu (void);
+
#endif /* I386_CPUID_COMMON_H */
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 5f69ddb..52d0248 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -164,7 +164,7 @@ SFILES= $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
$(srcdir)/common/buffer.c $(srcdir)/common/linux-btrace.c \
$(srcdir)/common/filestuff.c $(srcdir)/target/waitstatus.c \
$(srcdir)/common/mips-linux-watch.c $(srcdir)/common/print-utils.c \
- $(srcdir)/common/rsp-low.c
+ $(srcdir)/common/rsp-low.c $(srcdir)/common/i386-cpuid.c
DEPFILES = @GDBSERVER_DEPFILES@
@@ -177,7 +177,8 @@ OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
target.o waitstatus.o utils.o debug.o version.o vec.o gdb_vecs.o \
mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
- tdesc.o print-utils.o rsp-low.o $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
+ tdesc.o print-utils.o rsp-low.o i386-cpuid.o $(XML_BUILTIN) $(DEPFILES) \
+ $(LIBOBJS)
GDBREPLAY_OBS = gdbreplay.o version.o
GDBSERVER_LIBS = @GDBSERVER_LIBS@
XM_CLIBS = @LIBS@
@@ -537,6 +538,10 @@ mips-linux-watch.o: ../common/mips-linux-watch.c
$(COMPILE) $<
$(POSTCOMPILE)
+i386-cpuid.o: ../common/i386-cpuid.c
+ $(COMPILE) $<
+ $(POSTCOMPILE)
+
# Native object files rules from ../nat
linux-waitpid.o: ../nat/linux-waitpid.c
--
1.8.3.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] i386-cpuid: add support for identifying a processor
2014-02-13 12:30 [PATCH 1/2] i386-cpuid: add support for identifying a processor Markus Metzger
2014-02-13 12:30 ` [PATCH 2/2] btrace: use i386-cpuid's cpu identifier Markus Metzger
@ 2014-02-13 13:29 ` Mark Kettenis
2014-02-13 13:34 ` Metzger, Markus T
2014-02-14 17:29 ` Mike Frysinger
2 siblings, 1 reply; 8+ messages in thread
From: Mark Kettenis @ 2014-02-13 13:29 UTC (permalink / raw)
To: markus.t.metzger; +Cc: jan.kratochvil, gdb-patches
> From: Markus Metzger <markus.t.metzger@intel.com>
> Date: Thu, 13 Feb 2014 13:30:14 +0100
>
> Add a struct i386_cpu to identify an x86 cpu and a function i386_this_cpu
> to identify the cpu we're running on.
This code really has no place in GDB. The only reason this was
accepted in the linux-btrace.c is as a workaround for the fact that
Linux kernels advertised this feature on hardware where it was broken.
Moving this code in its own file and making it generally available
only encourages misuse.
> 2014-02-13 Markus Metzger <markus.t.metzger@intel.com>
>
> * common/i386-cpuid.h (i386_cpu_vendor, i386_cpu)
> (i386_this_cpu): New.
> * common/i386-cpuid.c (i386_this_cpu): New.
> * Makefile.in: (SFILES): Added i386-cpuid.c.
> (HFILES_NO_SRCDIR): Added i386-cpuid.h.
> (COMMON_OBS): Added i386-cpuid.o.
> (i386-cpuid.o): New target.
>
> gdbserver/
> * Makefile.in: (SFILES): Added i386-cpuid.c.
> (OBS): Added i386-cpuid.o.
> (i386-cpuid.o): New target.
>
>
> ---
> gdb/Makefile.in | 9 ++++--
> gdb/common/i386-cpuid.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
> gdb/common/i386-cpuid.h | 33 +++++++++++++++++++++
> gdb/gdbserver/Makefile.in | 9 ++++--
> 4 files changed, 121 insertions(+), 4 deletions(-)
> create mode 100644 gdb/common/i386-cpuid.c
>
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index ea56854..212cb93 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -839,7 +839,8 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
> common/gdb_vecs.c common/common-utils.c common/xml-utils.c \
> common/ptid.c common/buffer.c gdb-dlfcn.c common/agent.c \
> common/format.c common/filestuff.c btrace.c record-btrace.c ctf.c \
> - target/waitstatus.c common/print-utils.c common/rsp-low.c
> + target/waitstatus.c common/print-utils.c common/rsp-low.c \
> + common/i386-cpuid.c
>
> LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
>
> @@ -1021,7 +1022,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
> gdb_vecs.o jit.o progspace.o skip.o probe.o \
> common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
> format.o registry.o btrace.o record-btrace.o waitstatus.o \
> - print-utils.o rsp-low.o
> + print-utils.o rsp-low.o i386-cpuid.o
>
> TSOBS = inflow.o
>
> @@ -2150,6 +2151,10 @@ rsp-low.o: ${srcdir}/common/rsp-low.c
> $(COMPILE) $(srcdir)/common/rsp-low.c
> $(POSTCOMPILE)
>
> +i386-cpuid.o: ${srcdir}/common/i386-cpuid.c
> + $(COMPILE) $(srcdir)/common/i386-cpuid.c
> + $(POSTCOMPILE)
> +
> #
> # gdb/target/ dependencies
> #
> diff --git a/gdb/common/i386-cpuid.c b/gdb/common/i386-cpuid.c
> new file mode 100644
> index 0000000..7ac05d4
> --- /dev/null
> +++ b/gdb/common/i386-cpuid.c
> @@ -0,0 +1,74 @@
> +/*
> + Copyright (C) 2014 Free Software Foundation, Inc.
> +
> + This file is part of GDB.
> +
> + This file 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 3, 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, see <http://www.gnu.org/licenses/>. */
> +
> +#include "i386-cpuid.h"
> +
> +#if defined(__i386__) || defined(__x86_64__)
> +
> +/* See i386-cpuid.h. */
> +
> +struct i386_cpu
> +i386_this_cpu (void)
> +{
> + struct i386_cpu cpu;
> + unsigned int eax, ebx, ecx, edx;
> + int ok;
> +
> + cpu.vendor = CV_UNKNOWN;
> +
> + 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;
> + cpu.stepping = cpuid & 0xf;
> +
> + if (cpu.family == 0x6)
> + cpu.model += (cpuid >> 12) & 0xf0;
> + }
> + }
> + }
> +
> + return cpu;
> +}
> +
> +#else /* i386 && x86_64 */
> +
> +/* See i386-cpuid.h. */
> +
> +struct i386_cpu
> +i386_this_cpu (void)
> +{
> + struct i386_cpu cpu;
> +
> + cpu.vendor = CV_UNKNOWN;
> +
> + return cpu;
> +}
> +
> +#endif /* i386 && x86_64 */
> diff --git a/gdb/common/i386-cpuid.h b/gdb/common/i386-cpuid.h
> index 9aea054..1ed0251 100644
> --- a/gdb/common/i386-cpuid.h
> +++ b/gdb/common/i386-cpuid.h
> @@ -22,6 +22,35 @@
> /* Always include the header for the cpu bit defines. */
> #include "i386-gcc-cpuid.h"
>
> +/* An enumeration of cpu vendors. */
> +
> +enum i386_cpu_vendor
> +{
> + /* We do not know this vendor. */
> + CV_UNKNOWN,
> +
> + /* Intel. */
> + CV_INTEL
> +};
> +
> +/* A cpu identifier. */
> +
> +struct i386_cpu
> +{
> + /* The processor vendor. */
> + enum i386_cpu_vendor vendor;
> +
> + /* The cpu family. */
> + unsigned short family;
> +
> + /* The cpu model. */
> + unsigned char model;
> +
> + /* The cpu stepping. */
> + unsigned char stepping;
> +};
> +
> +
> #if defined(__i386__) || defined(__x86_64__)
>
> /* Return cpuid data for requested cpuid level, as found in returned
> @@ -60,4 +89,8 @@ i386_cpuid (unsigned int __level,
>
> #endif /* i386 && x86_64 */
>
> +/* Identify the cpu we're running on. */
> +
> +extern struct i386_cpu i386_this_cpu (void);
> +
> #endif /* I386_CPUID_COMMON_H */
> diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
> index 5f69ddb..52d0248 100644
> --- a/gdb/gdbserver/Makefile.in
> +++ b/gdb/gdbserver/Makefile.in
> @@ -164,7 +164,7 @@ SFILES= $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
> $(srcdir)/common/buffer.c $(srcdir)/common/linux-btrace.c \
> $(srcdir)/common/filestuff.c $(srcdir)/target/waitstatus.c \
> $(srcdir)/common/mips-linux-watch.c $(srcdir)/common/print-utils.c \
> - $(srcdir)/common/rsp-low.c
> + $(srcdir)/common/rsp-low.c $(srcdir)/common/i386-cpuid.c
>
> DEPFILES = @GDBSERVER_DEPFILES@
>
> @@ -177,7 +177,8 @@ OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
> target.o waitstatus.o utils.o debug.o version.o vec.o gdb_vecs.o \
> mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
> common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
> - tdesc.o print-utils.o rsp-low.o $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
> + tdesc.o print-utils.o rsp-low.o i386-cpuid.o $(XML_BUILTIN) $(DEPFILES) \
> + $(LIBOBJS)
> GDBREPLAY_OBS = gdbreplay.o version.o
> GDBSERVER_LIBS = @GDBSERVER_LIBS@
> XM_CLIBS = @LIBS@
> @@ -537,6 +538,10 @@ mips-linux-watch.o: ../common/mips-linux-watch.c
> $(COMPILE) $<
> $(POSTCOMPILE)
>
> +i386-cpuid.o: ../common/i386-cpuid.c
> + $(COMPILE) $<
> + $(POSTCOMPILE)
> +
> # Native object files rules from ../nat
>
> linux-waitpid.o: ../nat/linux-waitpid.c
> --
> 1.8.3.1
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 1/2] i386-cpuid: add support for identifying a processor
2014-02-13 13:29 ` [PATCH 1/2] i386-cpuid: add support for identifying a processor Mark Kettenis
@ 2014-02-13 13:34 ` Metzger, Markus T
2014-02-13 18:32 ` Pedro Alves
0 siblings, 1 reply; 8+ messages in thread
From: Metzger, Markus T @ 2014-02-13 13:34 UTC (permalink / raw)
To: Mark Kettenis; +Cc: jan.kratochvil, gdb-patches
> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] On Behalf Of Mark Kettenis
> Sent: Thursday, February 13, 2014 2:29 PM
> > Add a struct i386_cpu to identify an x86 cpu and a function i386_this_cpu
> > to identify the cpu we're running on.
>
> This code really has no place in GDB. The only reason this was
> accepted in the linux-btrace.c is as a workaround for the fact that
> Linux kernels advertised this feature on hardware where it was broken.
> Moving this code in its own file and making it generally available
> only encourages misuse.
I need this for btrace so I thought I'd make it available to others, too.
I'm OK to leave it in the btrace area. I'll send another patch.
Thanks,
Markus.
> > 2014-02-13 Markus Metzger <markus.t.metzger@intel.com>
> >
> > * common/i386-cpuid.h (i386_cpu_vendor, i386_cpu)
> > (i386_this_cpu): New.
> > * common/i386-cpuid.c (i386_this_cpu): New.
> > * Makefile.in: (SFILES): Added i386-cpuid.c.
> > (HFILES_NO_SRCDIR): Added i386-cpuid.h.
> > (COMMON_OBS): Added i386-cpuid.o.
> > (i386-cpuid.o): New target.
> >
> > gdbserver/
> > * Makefile.in: (SFILES): Added i386-cpuid.c.
> > (OBS): Added i386-cpuid.o.
> > (i386-cpuid.o): New target.
> >
> >
> > ---
> > gdb/Makefile.in | 9 ++++--
> > gdb/common/i386-cpuid.c | 74
> +++++++++++++++++++++++++++++++++++++++++++++++
> > gdb/common/i386-cpuid.h | 33 +++++++++++++++++++++
> > gdb/gdbserver/Makefile.in | 9 ++++--
> > 4 files changed, 121 insertions(+), 4 deletions(-)
> > create mode 100644 gdb/common/i386-cpuid.c
> >
> > diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> > index ea56854..212cb93 100644
> > --- a/gdb/Makefile.in
> > +++ b/gdb/Makefile.in
> > @@ -839,7 +839,8 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-
> valprint.c ada-tasks.c \
> > common/gdb_vecs.c common/common-utils.c common/xml-utils.c \
> > common/ptid.c common/buffer.c gdb-dlfcn.c common/agent.c \
> > common/format.c common/filestuff.c btrace.c record-btrace.c ctf.c \
> > - target/waitstatus.c common/print-utils.c common/rsp-low.c
> > + target/waitstatus.c common/print-utils.c common/rsp-low.c \
> > + common/i386-cpuid.c
> >
> > LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
> >
> > @@ -1021,7 +1022,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS)
> $(YYOBJ) \
> > gdb_vecs.o jit.o progspace.o skip.o probe.o \
> > common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
> > format.o registry.o btrace.o record-btrace.o waitstatus.o \
> > - print-utils.o rsp-low.o
> > + print-utils.o rsp-low.o i386-cpuid.o
> >
> > TSOBS = inflow.o
> >
> > @@ -2150,6 +2151,10 @@ rsp-low.o: ${srcdir}/common/rsp-low.c
> > $(COMPILE) $(srcdir)/common/rsp-low.c
> > $(POSTCOMPILE)
> >
> > +i386-cpuid.o: ${srcdir}/common/i386-cpuid.c
> > + $(COMPILE) $(srcdir)/common/i386-cpuid.c
> > + $(POSTCOMPILE)
> > +
> > #
> > # gdb/target/ dependencies
> > #
> > diff --git a/gdb/common/i386-cpuid.c b/gdb/common/i386-cpuid.c
> > new file mode 100644
> > index 0000000..7ac05d4
> > --- /dev/null
> > +++ b/gdb/common/i386-cpuid.c
> > @@ -0,0 +1,74 @@
> > +/*
> > + Copyright (C) 2014 Free Software Foundation, Inc.
> > +
> > + This file is part of GDB.
> > +
> > + This file 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 3, 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, see <http://www.gnu.org/licenses/>.
> */
> > +
> > +#include "i386-cpuid.h"
> > +
> > +#if defined(__i386__) || defined(__x86_64__)
> > +
> > +/* See i386-cpuid.h. */
> > +
> > +struct i386_cpu
> > +i386_this_cpu (void)
> > +{
> > + struct i386_cpu cpu;
> > + unsigned int eax, ebx, ecx, edx;
> > + int ok;
> > +
> > + cpu.vendor = CV_UNKNOWN;
> > +
> > + 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;
> > + cpu.stepping = cpuid & 0xf;
> > +
> > + if (cpu.family == 0x6)
> > + cpu.model += (cpuid >> 12) & 0xf0;
> > + }
> > + }
> > + }
> > +
> > + return cpu;
> > +}
> > +
> > +#else /* i386 && x86_64 */
> > +
> > +/* See i386-cpuid.h. */
> > +
> > +struct i386_cpu
> > +i386_this_cpu (void)
> > +{
> > + struct i386_cpu cpu;
> > +
> > + cpu.vendor = CV_UNKNOWN;
> > +
> > + return cpu;
> > +}
> > +
> > +#endif /* i386 && x86_64 */
> > diff --git a/gdb/common/i386-cpuid.h b/gdb/common/i386-cpuid.h
> > index 9aea054..1ed0251 100644
> > --- a/gdb/common/i386-cpuid.h
> > +++ b/gdb/common/i386-cpuid.h
> > @@ -22,6 +22,35 @@
> > /* Always include the header for the cpu bit defines. */
> > #include "i386-gcc-cpuid.h"
> >
> > +/* An enumeration of cpu vendors. */
> > +
> > +enum i386_cpu_vendor
> > +{
> > + /* We do not know this vendor. */
> > + CV_UNKNOWN,
> > +
> > + /* Intel. */
> > + CV_INTEL
> > +};
> > +
> > +/* A cpu identifier. */
> > +
> > +struct i386_cpu
> > +{
> > + /* The processor vendor. */
> > + enum i386_cpu_vendor vendor;
> > +
> > + /* The cpu family. */
> > + unsigned short family;
> > +
> > + /* The cpu model. */
> > + unsigned char model;
> > +
> > + /* The cpu stepping. */
> > + unsigned char stepping;
> > +};
> > +
> > +
> > #if defined(__i386__) || defined(__x86_64__)
> >
> > /* Return cpuid data for requested cpuid level, as found in returned
> > @@ -60,4 +89,8 @@ i386_cpuid (unsigned int __level,
> >
> > #endif /* i386 && x86_64 */
> >
> > +/* Identify the cpu we're running on. */
> > +
> > +extern struct i386_cpu i386_this_cpu (void);
> > +
> > #endif /* I386_CPUID_COMMON_H */
> > diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
> > index 5f69ddb..52d0248 100644
> > --- a/gdb/gdbserver/Makefile.in
> > +++ b/gdb/gdbserver/Makefile.in
> > @@ -164,7 +164,7 @@ SFILES= $(srcdir)/gdbreplay.c
> $(srcdir)/inferiors.c $(srcdir)/dll.c \
> > $(srcdir)/common/buffer.c $(srcdir)/common/linux-btrace.c \
> > $(srcdir)/common/filestuff.c $(srcdir)/target/waitstatus.c \
> > $(srcdir)/common/mips-linux-watch.c $(srcdir)/common/print-utils.c
> \
> > - $(srcdir)/common/rsp-low.c
> > + $(srcdir)/common/rsp-low.c $(srcdir)/common/i386-cpuid.c
> >
> > DEPFILES = @GDBSERVER_DEPFILES@
> >
> > @@ -177,7 +177,8 @@ OBS = agent.o ax.o inferiors.o regcache.o remote-
> utils.o server.o signals.o \
> > target.o waitstatus.o utils.o debug.o version.o vec.o gdb_vecs.o \
> > mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
> > common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
> > - tdesc.o print-utils.o rsp-low.o $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
> > + tdesc.o print-utils.o rsp-low.o i386-cpuid.o $(XML_BUILTIN)
> $(DEPFILES) \
> > + $(LIBOBJS)
> > GDBREPLAY_OBS = gdbreplay.o version.o
> > GDBSERVER_LIBS = @GDBSERVER_LIBS@
> > XM_CLIBS = @LIBS@
> > @@ -537,6 +538,10 @@ mips-linux-watch.o: ../common/mips-linux-
> watch.c
> > $(COMPILE) $<
> > $(POSTCOMPILE)
> >
> > +i386-cpuid.o: ../common/i386-cpuid.c
> > + $(COMPILE) $<
> > + $(POSTCOMPILE)
> > +
> > # Native object files rules from ../nat
> >
> > linux-waitpid.o: ../nat/linux-waitpid.c
> > --
> > 1.8.3.1
> >
> >
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] i386-cpuid: add support for identifying a processor
2014-02-13 13:34 ` Metzger, Markus T
@ 2014-02-13 18:32 ` Pedro Alves
2014-02-14 8:30 ` Metzger, Markus T
0 siblings, 1 reply; 8+ messages in thread
From: Pedro Alves @ 2014-02-13 18:32 UTC (permalink / raw)
To: Metzger, Markus T; +Cc: Mark Kettenis, jan.kratochvil, gdb-patches
On 02/13/2014 01:34 PM, Metzger, Markus T wrote:
> I need this for btrace
Please always send a rationale along with patches. I
looked over both patches, but couldn't figure out
what motivated them.
--
Pedro Alves
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 1/2] i386-cpuid: add support for identifying a processor
2014-02-13 18:32 ` Pedro Alves
@ 2014-02-14 8:30 ` Metzger, Markus T
0 siblings, 0 replies; 8+ messages in thread
From: Metzger, Markus T @ 2014-02-14 8:30 UTC (permalink / raw)
To: Pedro Alves; +Cc: Mark Kettenis, jan.kratochvil, gdb-patches
> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] On Behalf Of Pedro Alves
> Sent: Thursday, February 13, 2014 7:33 PM
> To: Metzger, Markus T
> > I need this for btrace
>
> Please always send a rationale along with patches. I
> looked over both patches, but couldn't figure out
> what motivated them.
OK. I'll resend the patches together with a bigger patch series
where the motivation is more clear. This will take some time.
Regards,
Markus.
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] i386-cpuid: add support for identifying a processor
2014-02-13 12:30 [PATCH 1/2] i386-cpuid: add support for identifying a processor Markus Metzger
2014-02-13 12:30 ` [PATCH 2/2] btrace: use i386-cpuid's cpu identifier Markus Metzger
2014-02-13 13:29 ` [PATCH 1/2] i386-cpuid: add support for identifying a processor Mark Kettenis
@ 2014-02-14 17:29 ` Mike Frysinger
2014-02-17 8:04 ` Metzger, Markus T
2 siblings, 1 reply; 8+ messages in thread
From: Mike Frysinger @ 2014-02-14 17:29 UTC (permalink / raw)
To: gdb-patches; +Cc: Markus Metzger, jan.kratochvil, Mark Kettenis
[-- Attachment #1: Type: text/plain, Size: 2301 bytes --]
On Thursday, February 13, 2014 13:30:14 Markus Metzger wrote:
> --- /dev/null
> +++ b/gdb/common/i386-cpuid.c
> @@ -0,0 +1,74 @@
> +/*
> + Copyright (C) 2014 Free Software Foundation, Inc.
> +
> + This file is part of GDB.
> +
> + This file 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 3, 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, see <http://www.gnu.org/licenses/>.
> */ +
> +#include "i386-cpuid.h"
> +
> +#if defined(__i386__) || defined(__x86_64__)
> +
> +/* See i386-cpuid.h. */
> +
> +struct i386_cpu
> +i386_this_cpu (void)
> +{
> + struct i386_cpu cpu;
> + unsigned int eax, ebx, ecx, edx;
> + int ok;
> +
> + cpu.vendor = CV_UNKNOWN;
> +
> + 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;
> + cpu.stepping = cpuid & 0xf;
> +
> + if (cpu.family == 0x6)
> + cpu.model += (cpuid >> 12) & 0xf0;
> + }
> + }
> + }
> +
> + return cpu;
> +}
> +
> +#else /* i386 && x86_64 */
> +
> +/* See i386-cpuid.h. */
> +
> +struct i386_cpu
> +i386_this_cpu (void)
> +{
> + struct i386_cpu cpu;
> +
> + cpu.vendor = CV_UNKNOWN;
> +
> + return cpu;
> +}
> +
> +#endif /* i386 && x86_64 */
afaict, you don't need the #else. the non-x86 codepaths in i386-cpuid.h will
set the return value to 0, and your main code will treat this as an error and
set cpu.vendor to CV_UNKNOWN.
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 1/2] i386-cpuid: add support for identifying a processor
2014-02-14 17:29 ` Mike Frysinger
@ 2014-02-17 8:04 ` Metzger, Markus T
0 siblings, 0 replies; 8+ messages in thread
From: Metzger, Markus T @ 2014-02-17 8:04 UTC (permalink / raw)
To: Mike Frysinger, gdb-patches; +Cc: jan.kratochvil, Mark Kettenis
> -----Original Message-----
> From: Mike Frysinger [mailto:vapier@gentoo.org]
> Sent: Friday, February 14, 2014 6:30 PM
> > +#else /* i386 && x86_64 */
> > +
> > +/* See i386-cpuid.h. */
> > +
> > +struct i386_cpu
> > +i386_this_cpu (void)
> > +{
> > + struct i386_cpu cpu;
> > +
> > + cpu.vendor = CV_UNKNOWN;
> > +
> > + return cpu;
> > +}
> > +
> > +#endif /* i386 && x86_64 */
>
>
> afaict, you don't need the #else. the non-x86 codepaths in i386-cpuid.h will
> set the return value to 0, and your main code will treat this as an error and
> set cpu.vendor to CV_UNKNOWN.
Thanks, you're right. That'll simplify it.
Regards,
Markus.
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-02-17 8:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-13 12:30 [PATCH 1/2] i386-cpuid: add support for identifying a processor Markus Metzger
2014-02-13 12:30 ` [PATCH 2/2] btrace: use i386-cpuid's cpu identifier Markus Metzger
2014-02-13 13:29 ` [PATCH 1/2] i386-cpuid: add support for identifying a processor Mark Kettenis
2014-02-13 13:34 ` Metzger, Markus T
2014-02-13 18:32 ` Pedro Alves
2014-02-14 8:30 ` Metzger, Markus T
2014-02-14 17:29 ` Mike Frysinger
2014-02-17 8:04 ` Metzger, Markus T
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox