]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/i386-mpx-simple_segv.c
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / i386-mpx-simple_segv.c
1 /* Copyright (C) 2015-2021 Free Software Foundation, Inc.
2
3 Contributed by Intel Corp. <walfred.tedeschi@intel.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 #include "x86-cpuid.h"
19 #include <stdio.h>
20
21 #define OUR_SIZE 5
22
23 unsigned int
24 have_mpx (void)
25 {
26 unsigned int eax, ebx, ecx, edx;
27
28 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
29 return 0;
30
31 if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
32 {
33 if (__get_cpuid_max (0, NULL) < 7)
34 return 0;
35
36 __cpuid_count (7, 0, eax, ebx, ecx, edx);
37
38 if ((ebx & bit_MPX) == bit_MPX)
39 return 1;
40 else
41 return 0;
42 }
43 return 0;
44 }
45
46 void
47 upper (int * p, int len)
48 {
49 int value;
50 len++; /* b0-size-test. */
51 value = *(p + len);
52 }
53
54 int
55 main (void)
56 {
57 if (have_mpx ())
58 {
59 int a = 0; /* Dummy variable for debugging purposes. */
60 int sx[OUR_SIZE];
61 a++; /* register-eval. */
62 upper (sx, OUR_SIZE + 2);
63 return sx[1];
64 }
65 return 0;
66 }