OSDN Git Service

modified: utilsrc/src/Admin/Makefile
[eos/others.git] / utilsrc / srcX86MAC64 / Admin / gdb-7.7.1 / gdb / testsuite / gdb.arch / i386-mpx.c
1 /* Test program for MPX registers.
2
3    Copyright 2013-2014 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include <stdio.h>
21 #include "i386-cpuid.h"
22
23 #ifndef NOINLINE
24 #define NOINLINE __attribute__ ((noinline))
25 #endif
26
27 unsigned int have_mpx (void) NOINLINE;
28
29 unsigned int NOINLINE
30 have_mpx (void)
31 {
32   unsigned int eax, ebx, ecx, edx;
33
34   if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
35     return 0;
36
37   if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
38      {
39        if (__get_cpuid_max (0, NULL) < 7)
40          return 0;
41
42        __cpuid_count (7, 0, eax, ebx, ecx, edx);
43
44        if ((ebx & bit_MPX) == bit_MPX)
45          return 1;
46        else
47          return 0;
48      }
49 }
50
51 int
52 main (int argc, char **argv)
53 {
54   if (have_mpx ())
55     {
56 #ifdef __x86_64__
57       asm ("mov $10, %rax\n\t"
58           "mov $9, %rdx\n\t"
59           "bndmk (%rax,%rdx), %bnd0\n\t"
60           "mov $20, %rax\n\t"
61           "mov $9, %rdx\n\t"
62           "bndmk (%rax,%rdx), %bnd1\n\t"
63           "mov $30, %rax\n\t"
64           "mov $9, %rdx\n\t"
65           "bndmk (%rax,%rdx), %bnd2\n\t"
66           "mov $40, %rax\n\t"
67           "mov $9, %rdx\n\t"
68           "bndmk (%rax,%rdx), %bnd3\n\t"
69           "bndstx %bnd3, (%rax) \n\t"
70           "nop\n\t"
71          );
72 #else
73       asm ("mov $10, %eax\n\t"
74            "mov $9, %edx\n\t"
75            "bndmk (%eax,%edx), %bnd0\n\t"
76            "mov $20, %eax\n\t"
77            "mov $9, %edx\n\t"
78            "bndmk (%eax,%edx), %bnd1\n\t"
79            "mov $30, %eax\n\t"
80            "mov $9, %edx\n\t"
81            "bndmk (%eax,%edx), %bnd2\n\t"
82            "mov $40, %eax\n\t"
83            "mov $9, %edx\n\t"
84            "bndmk (%eax,%edx), %bnd3\n\t"
85            "bndstx  %bnd3, (%eax)\n\t"
86            "nop\n\t"
87           );
88 #endif
89         asm ("nop\n\t");        /* break here.  */
90     }
91   return 0;
92 }