aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Machado <lgustavo@codesourcery.com>2017-02-23 14:36:58 -0600
committerLuis Machado <lgustavo@codesourcery.com>2017-02-23 14:39:16 -0600
commit17cd494709a60750234c7dbe4f1db2932f8a71c4 (patch)
tree4eaf73161d75025746e59409b47088aba3405a56
parent359ca075e7fe20a5106d5c068193dad0c53af480 (diff)
downloadgdb-17cd494709a60750234c7dbe4f1db2932f8a71c4.zip
gdb-17cd494709a60750234c7dbe4f1db2932f8a71c4.tar.gz
gdb-17cd494709a60750234c7dbe4f1db2932f8a71c4.tar.bz2
PR21166: Validate rdrand/rdseed support separately in gdb.reverse/insn-reverse-x86.c
As reported in PR21166, there are Intel processors out there that support rdrand but not rdseed. The fix is to verify both features separately and only run rdrand/rdseed tests if supported. gdb/testsuite/ChangeLog: 2017-02-23 Luis Machado <lgustavo@codesourcery.com> * gdb.reverse/insn-reverse.x86.c (check_rdrand_support): Renamed to ... (check_supported_features): ... this. Changed return type to void. (supports_rdseed): New static global. (rdseed): Check supports_rdseed. (initialize): Call check_supported_features.
-rw-r--r--gdb/testsuite/ChangeLog8
-rw-r--r--gdb/testsuite/gdb.reverse/insn-reverse-x86.c36
2 files changed, 35 insertions, 9 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 420bfc4..b102b87 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2017-02-23 Luis Machado <lgustavo@codesourcery.com>
+
+ * gdb.reverse/insn-reverse.x86.c (check_rdrand_support): Renamed to ...
+ (check_supported_features): ... this. Changed return type to void.
+ (supports_rdseed): New static global.
+ (rdseed): Check supports_rdseed.
+ (initialize): Call check_supported_features.
+
2017-02-21 Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
* gdb.arch/ppc64-isa207-atomic-inst.exp: New testcase based on
diff --git a/gdb/testsuite/gdb.reverse/insn-reverse-x86.c b/gdb/testsuite/gdb.reverse/insn-reverse-x86.c
index 7f87392..85b169d 100644
--- a/gdb/testsuite/gdb.reverse/insn-reverse-x86.c
+++ b/gdb/testsuite/gdb.reverse/insn-reverse-x86.c
@@ -18,20 +18,38 @@
#include <cpuid.h>
#include <stdint.h>
-/* 0 if the CPU supports rdrand/rdseed and non-zero otherwise. */
+/* 0 if the CPU supports rdrand and non-zero otherwise. */
static unsigned int supports_rdrand;
-/* Returns non-zero if rdrand/rdseed instructions are supported and
- zero otherwise. */
+/* 0 if the CPU supports rdseed and non-zero otherwise. */
+static unsigned int supports_rdseed;
-static unsigned int
-check_rdrand_support (void)
+/* Check supported features and set globals accordingly. The globals
+ can be used to prevent unsupported tests from running. */
+
+static void
+check_supported_features (void)
{
unsigned int rdrand_mask = (1 << 30);
+ unsigned int rdseed_mask = (1 << 18);
unsigned int eax, ebx, ecx, edx;
+ unsigned int vendor;
+ unsigned int max_level;
+
+ max_level = __get_cpuid_max (0, &vendor);
+
+ if (max_level < 1)
+ return;
+
+ __cpuid (1, eax, ebx, ecx, edx);
- __get_cpuid (1, &eax, &ebx, &ecx, &edx);
- return ((ecx & rdrand_mask) == rdrand_mask);
+ supports_rdrand = ((ecx & rdrand_mask) == rdrand_mask);
+
+ if (max_level >= 7)
+ {
+ __cpuid_count (7, 0, eax, ebx, ecx, edx);
+ supports_rdseed = ((ebx & rdseed_mask) == rdseed_mask);
+ }
}
/* Test rdrand support for various output registers. */
@@ -147,7 +165,7 @@ rdseed (void)
/* Get a random seed from the rdseed assembly instruction. */
register long seed;
- if (!supports_rdrand)
+ if (!supports_rdseed)
return;
/* 16-bit random seeds. */
@@ -250,7 +268,7 @@ static void
initialize (void)
{
/* Initialize supported features. */
- supports_rdrand = check_rdrand_support ();
+ check_supported_features ();
}
/* Functions testing instruction decodings. GDB will test all of these. */