From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23799 invoked by alias); 5 Sep 2013 09:26:47 -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 23728 invoked by uid 89); 5 Sep 2013 09:26:47 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (143.182.124.37) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Sep 2013 09:26:47 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE autolearn=no version=3.3.2 X-HELO: mga14.intel.com Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 05 Sep 2013 02:26:43 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by azsmga001.ch.intel.com with ESMTP; 05 Sep 2013 02:26:41 -0700 Received: from ulslx001.iul.intel.com (ulslx001.iul.intel.com [172.28.207.63]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id r859QePe001763; Thu, 5 Sep 2013 10:26:40 +0100 Received: from ulslx001.iul.intel.com (localhost [127.0.0.1]) by ulslx001.iul.intel.com with ESMTP id r859QeQ5031242; Thu, 5 Sep 2013 11:26:40 +0200 Received: (from wtedesch@localhost) by ulslx001.iul.intel.com with id r859Qe3J031238; Thu, 5 Sep 2013 11:26:40 +0200 From: Walfred Tedeschi To: tromey@redhat.com, gdb-patches@sourceware.org, mark.kettenis@xs4all.nl Cc: Walfred Tedeschi Subject: [PATCH V4 7/8] Add MPX registers tests. Date: Thu, 05 Sep 2013 09:26:00 -0000 Message-Id: <1378373188-31144-8-git-send-email-walfred.tedeschi@intel.com> In-Reply-To: <1378373188-31144-1-git-send-email-walfred.tedeschi@intel.com> References: <1378373188-31144-1-git-send-email-walfred.tedeschi@intel.com> X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00156.txt.bz2 2013-06-25 Walfred Tedeschi * common/i386-gcc-cpuid.h (bit_MPX): Synchronize with gcc file. testsuite/ * gdb.arch/i386-mpx.c: New file * gdb.arch/i386-mpx.exp: New file. --- gdb/common/i386-gcc-cpuid.h | 8 +- gdb/testsuite/gdb.arch/i386-mpx.c | 92 +++++++++++++++++++++++ gdb/testsuite/gdb.arch/i386-mpx.exp | 142 +++++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.arch/i386-mpx.c create mode 100644 gdb/testsuite/gdb.arch/i386-mpx.exp diff --git a/gdb/common/i386-gcc-cpuid.h b/gdb/common/i386-gcc-cpuid.h index e045ba8..dafb21c 100644 --- a/gdb/common/i386-gcc-cpuid.h +++ b/gdb/common/i386-gcc-cpuid.h @@ -75,8 +75,14 @@ #define bit_AVX2 (1 << 5) #define bit_BMI2 (1 << 8) #define bit_RTM (1 << 11) +#define bit_AVX512F (1 << 16) +#define bit_MPX (1 << 14) #define bit_RDSEED (1 << 18) #define bit_ADX (1 << 19) +#define bit_AVX512PF (1 << 26) +#define bit_AVX512ER (1 << 27) +#define bit_AVX512CD (1 << 28) +#define bit_SHA (1 << 29) /* Extended State Enumeration Sub-leaf (%eax == 13, %ecx == 1) */ #define bit_XSAVEOPT (1 << 0) @@ -207,7 +213,7 @@ __get_cpuid_max (unsigned int __ext, unsigned int *__sig) { unsigned int __eax, __ebx, __ecx, __edx; -#ifdef __i386__ +#ifndef __x86_64__ /* See if we can use cpuid. On AMD64 we always can. */ #if __GNUC__ >= 3 __asm__ ("pushf{l|d}\n\t" diff --git a/gdb/testsuite/gdb.arch/i386-mpx.c b/gdb/testsuite/gdb.arch/i386-mpx.c new file mode 100644 index 0000000..db7cb3b --- /dev/null +++ b/gdb/testsuite/gdb.arch/i386-mpx.c @@ -0,0 +1,92 @@ +/* Test program for MPX registers. + + Copyright 2013 Free Software Foundation, Inc. + + This file is part of GDB. + + This program 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 of the License, 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 . */ + +#include +#include "i386-cpuid.h" + +#ifndef NOINLINE +#define NOINLINE __attribute__ ((noinline)) +#endif + +unsigned int have_mpx (void) NOINLINE; + +unsigned int NOINLINE +have_mpx (void) +{ + unsigned int eax, ebx, ecx, edx; + + if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) + return 0; + + if ((ecx & bit_OSXSAVE) == bit_OSXSAVE) + { + if (__get_cpuid_max (0, NULL) < 7) + return 0; + + __cpuid_count (7, 0, eax, ebx, ecx, edx); + + if ((ebx & bit_MPX) == bit_MPX) + return 1; + else + return 0; + } +} + +int +main (int argc, char **argv) +{ + if (have_mpx ()) + { +#ifdef __x86_64__ + asm ("mov $10, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd0\n\t" + "mov $20, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd1\n\t" + "mov $30, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd2\n\t" + "mov $40, %rax\n\t" + "mov $9, %rdx\n\t" + "bndmk (%rax,%rdx), %bnd3\n\t" + "bndstx %bnd3, (%rax) \n\t" + "nop\n\t" + ); +#else + asm ("mov $10, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd0\n\t" + "mov $20, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd1\n\t" + "mov $30, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd2\n\t" + "mov $40, %eax\n\t" + "mov $9, %edx\n\t" + "bndmk (%eax,%edx), %bnd3\n\t" + "bndstx %bnd3, (%eax)\n\t" + "nop\n\t" + ); +#endif + asm ("nop\n\t"); /* break here. */ + } + return 0; +} diff --git a/gdb/testsuite/gdb.arch/i386-mpx.exp b/gdb/testsuite/gdb.arch/i386-mpx.exp new file mode 100644 index 0000000..ff1c2eb --- /dev/null +++ b/gdb/testsuite/gdb.arch/i386-mpx.exp @@ -0,0 +1,142 @@ +# Copyright 2013 Free Software Foundation, Inc. +# +# Contributed by Intel Corp. +# +# This program 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 of the License, 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 . + +if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } { + verbose "Skipping x86 MPX tests." + return +} + +standard_testfile + +set comp_flags "-fmpx -I${srcdir}/../common" + +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \ + [list debug nowarnings additional_flags=${comp_flags}]] } { + return -1 +} + +if ![runto_main] { + untested "could not run to main" + return -1 +} + +send_gdb "print have_mpx ()\r" +gdb_expect { + -re ".. = 1\r\n$gdb_prompt " { + pass "check whether processor supports MPX" + } + -re ".. = 0\r\n$gdb_prompt " { + verbose "processor does not support MPX; skipping MPX tests" + return + } + -re ".*$gdb_prompt $" { + fail "check whether processor supports MPX" + } + timeout { + fail "check whether processor supports MPX (timeout)" + } +} + +# Test bndcfg register and bndstatus at startup +set test_string "\\\{raw = 0x\[0-9a-f\]+, config = \\\{base = \[0-9\]+,\ +reserved = \[0-9\]+, preserved = \[0-9\]+, enabled = \[0-9\]+\\\}\\\}" + +gdb_test "print \$bndcfgu" $test_string "bndcfgu formating" +gdb_test "print \$bndcfgu.config.enabled" "= 1" "test if bndstatus is enabled" +gdb_test "print \$bndstatus" "\\\{raw = 0x0, status = \\\{bde = 0, error = 0\\\}\\\}" \ + "bndstatus formating" +gdb_test "print \$bndstatus.raw" "= \\\(void \\\*\\\) 0x0" "bndstatus is zero by startup" + +# Read values from pseudo registers. +gdb_breakpoint [ gdb_get_line_number "break here" ] +gdb_continue_to_breakpoint "break here" ".*break here.*" + +set test_string ".*\\\{lbound = 0xa, ubound = 0x13\\\}.*" +gdb_test "info register bnd0" ".*bnd0$test_string" "Pure bnd0 register" + +set test_string ".*\\\{lbound = 0x14, ubound = 0x1d\\\}.*" +gdb_test "info register bnd1" ".*bnd1$test_string" "Pure bnd1 register" + +set test_string ".*\\\{lbound = 0x1e, ubound = 0x27\\\}.*" +gdb_test "info register bnd2" ".*bnd2$test_string" "Pure bnd2 register" + +set test_string ".*\\\{lbound = 0x28, ubound = 0x31\\\}.*" +gdb_test "info register bnd3" ".*bnd3$test_string" "Pure bnd3 register" + +# Read value from registers bndrs. + +set test_string ".*\\\{lbound = 0xa, ubound_raw = 0x\[f\]+ec\\\}.*" +gdb_test "info register bnd0raw" ".*bnd0$test_string" "Pure bnd0r register" + +set test_string ".*\\\{lbound = 0x14, ubound_raw = 0x\[f\]+e2\\\}.*" +gdb_test "info register bnd1raw" ".*bnd1$test_string" "Pure bnd1r register" + +set test_string ".*\\\{lbound = 0x1e, ubound_raw = 0x\[f\]+d8\\\}.*" +gdb_test "info register bnd2raw" ".*bnd2$test_string" "Pure bnd2r register" + +set test_string ".*\\\{lbound = 0x28, ubound_raw = 0x\[f\]+ce\\\}.*" +gdb_test "info register bnd3raw" ".*bnd3$test_string" "Pure bnd3r register" + +# Setting fields on bnds +set test_string ".*\\\{lbound = 0xa, ubound = 0x400\\\}.*" +gdb_test "print \$bnd0.ubound = 0x400" "= \\\(void \\\*\\\) 0x400" "set value for bnd0.ubound" +gdb_test "print \$bnd0" "$test_string" "after setting bnd0.ubound" +set test_string ".*\\\{lbound = 0xa, ubound_raw = 0x\[f\]+bff\\\}.*" +gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after set bnd0.ubound" + +set test_string ".*\\\{lbound = 0x1, ubound = 0x400\\\}.*" +gdb_test "print \$bnd0.lbound = 0x1" "= \\\(void \\\*\\\) 0x1" "set value for bnd0.lbound" +gdb_test "print \$bnd0" "$test_string" "after setting bnd0.lbound" +set test_string ".*\\\{lbound = 0x1, ubound_raw = 0x\[f\]+bff\\\}.*" +gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after set bnd0.lbound" + +# Setting fields on bnd0raw. +set test_string ".*\\\{lbound = 0x1, ubound_raw = 0x600\\\}.*" +gdb_test "print /x \$bnd0raw.ubound_raw = 0x600" "= 0x600" "set value for bnd0raw.ubound" +gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after setting bnd0raw.ubound" +set test_string ".*\\\{lbound = 0x1, ubound = 0x\[f\]+9ff\\\}.*" +gdb_test "print /x \$bnd0" "$test_string" "bnd0 after set bnd0raw.ubound" + +set test_string ".*\\\{lbound = 0x100, ubound_raw = 0x600\\\}.*" +gdb_test "print /x \$bnd0raw.lbound = 0x100" "= 0x100" "set value for bnd0raw.lbound" +gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after setting bnd0raw.lbound" +set test_string ".*\\\{lbound = 0x100, ubound = 0x\[f\]+9ff\\\}.*" +gdb_test "print /x \$bnd0" "$test_string" "bnd0 after set bnd0raw.lbound" + +# Set full value bnd raw +set test_string ".*\\\{lbound = 0x10, ubound_raw = 0x\[f\]+cff\\\}.*" +gdb_test "print /x \$bnd0raw = {0x10, ~0x300}" "$test_string" "set full value for bnd0raw" +set test_string ".*\\\{lbound = 0x10, ubound = 0x300\\\}.*" +gdb_test "print /x \$bnd0" "$test_string" "bnd0raw after setting full bnd0raw" + +# Set full value bnd +set test_string ".*\\\{lbound = 0x10, ubound = 0x300\\\}.*" +gdb_test "print /x \$bnd0 = {0x10, 0x300}" "$test_string" "set full value for bnd0" +set test_string ".*\\\{lbound = 0x10, ubound_raw = 0x\[f\]+cff\\\}.*" +gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after setting full bnd0" + +# Test bndcfg register and bndstatus after a failure on bndstr +gdb_test "print \$bndstatus.status.error" "= 2" "bndstatus error is 2\ +after a failure on allocating an entry" + +# Going to test the python extension for lenght. +if { [skip_python_tests] } { continue } +# Verify if size is right +set test_string ".*\\\: size 17.*" +gdb_test "print /x \$bnd0 = {0x10, 0x20}" "$test_string" "verify size for bnd0" + +send_gdb "quit\n" -- 1.7.10.4