From 4d157a3dbec7c227678793daba16f2972d1f85d5 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 19 Jun 2013 22:29:36 +0000 Subject: gdb: clean up x86 cpuid implementations We've currently got 3 files doing open coded implementations of cpuid. Each has its own set of workarounds and varying levels of how well they're written and are generally hardcoded to specific cpuid functions. If you try to build the latest gdb as a PIE on an i386 system, the build will fail because one of them lacks PIC workarounds (wrt ebx). Specifically, we have: common/linux-btrace.c: two copies of cpuid asm w/specific args, one has no workarounds while the other implicitly does to avoid memcpy go32-nat.c: two copies of cpuid asm w/specific args, one has workarounds to avoid memcpy gdb/testsuite/gdb.arch/i386-cpuid.h: one general cpuid asm w/many workarounds copied from older gcc Fortunately, that last header there is pretty damn good -- it handles lots of edge cases, the code is nice & tight (uses gcc asm operands rather than manual movs), and is already almost a general library type header. It's also the basis of what is now the public cpuid.h that is shipped with gcc-4.3+. So what I've done is pull that test header out and into gdb/common/ (not sure if there's a better place), synced to the version found in gcc-4.8.0, put a wrapper API around it, and then cut over all the existing call points to this new header. Since the func already has support for "is cpuid supported on this proc", it makes it trivial to push the i386/x86_64 ifdefs down into this wrapper API too. Now it can be safely used for all targets and gcc will elide the unused code for us. I've verified the gdb.arch testsuite still passes, and this code compiles for an armv7a host as well as x86_64. The go32-nat code has been left ifdef-ed out until someone can test & verify the new stuff works (and if it doesn't, figure out how to make the new code work). URL: https://bugs.gentoo.org/467806 Signed-off-by: Mike Frysinger --- gdb/go32-nat.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gdb/go32-nat.c') diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index 0d9bb9d..a3f75b2 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -96,6 +96,7 @@ #include "buildsym.h" #include "i387-tdep.h" #include "i386-tdep.h" +#include "i386-cpuid.h" #include "value.h" #include "regcache.h" #include "gdb_string.h" @@ -1141,6 +1142,21 @@ go32_sysinfo (char *arg, int from_tty) else if (u.machine[0] == 'i' && u.machine[1] > 4) { /* CPUID with EAX = 0 returns the Vendor ID. */ +#if 0 + /* Ideally we would use i386_cpuid(), but it needs someone to run + native tests first to make sure things actually work. They should. + http://sourceware.org/ml/gdb-patches/2013-05/msg00164.html */ + unsigned int eax, ebx, ecx, edx; + + if (i386_cpuid (0, &eax, &ebx, &ecx, &edx)) + { + cpuid_max = eax; + memcpy (&vendor[0], &ebx, 4); + memcpy (&vendor[4], &ecx, 4); + memcpy (&vendor[8], &edx, 4); + cpuid_vendor[12] = '\0'; + } +#else __asm__ __volatile__ ("xorl %%ebx, %%ebx;" "xorl %%ecx, %%ecx;" "xorl %%edx, %%edx;" @@ -1157,6 +1173,7 @@ go32_sysinfo (char *arg, int from_tty) : : "%eax", "%ebx", "%ecx", "%edx"); cpuid_vendor[12] = '\0'; +#endif } printf_filtered ("CPU Type.......................%s", u.machine); @@ -1182,6 +1199,10 @@ go32_sysinfo (char *arg, int from_tty) int amd_p = strcmp (cpuid_vendor, "AuthenticAMD") == 0; unsigned cpu_family, cpu_model; +#if 0 + /* See comment above about cpuid usage. */ + i386_cpuid (1, &cpuid_eax, &cpuid_ebx, NULL, &cpuid_edx); +#else __asm__ __volatile__ ("movl $1, %%eax;" "cpuid;" : "=a" (cpuid_eax), @@ -1189,6 +1210,7 @@ go32_sysinfo (char *arg, int from_tty) "=d" (cpuid_edx) : : "%ecx"); +#endif brand_idx = cpuid_ebx & 0xff; cpu_family = (cpuid_eax >> 8) & 0xf; cpu_model = (cpuid_eax >> 4) & 0xf; -- cgit v1.1