Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | /* Copyright (C) 2015-2020 Free Software Foundation, Inc. |
012b3a21 WT |
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 | int gx[OUR_SIZE]; | |
24 | int ga[OUR_SIZE]; | |
25 | int gb[OUR_SIZE]; | |
26 | int gc[OUR_SIZE]; | |
27 | int gd[OUR_SIZE]; | |
28 | ||
29 | unsigned int | |
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 | return 0; | |
50 | } | |
51 | ||
52 | int | |
53 | bp1 (int value) | |
54 | { | |
55 | return 1; | |
56 | } | |
57 | ||
58 | int | |
59 | bp2 (int value) | |
60 | { | |
61 | return 1; | |
62 | } | |
63 | ||
64 | void | |
65 | upper (int * p, int * a, int * b, int * c, int * d, int len) | |
66 | { | |
67 | int value; | |
68 | value = *(p + len); | |
69 | value = *(a + len); | |
70 | value = *(b + len); | |
71 | value = *(c + len); | |
72 | value = *(d + len); | |
73 | } | |
74 | ||
75 | void | |
76 | lower (int * p, int * a, int * b, int * c, int * d, int len) | |
77 | { | |
78 | int value; | |
79 | value = *(p - len); | |
80 | value = *(a - len); | |
81 | value = *(b - len); | |
82 | value = *(c - len); | |
83 | bp2 (value); | |
84 | value = *(d - len); | |
85 | } | |
86 | ||
87 | int | |
88 | main (void) | |
89 | { | |
90 | if (have_mpx ()) | |
91 | { | |
92 | int sx[OUR_SIZE]; | |
93 | int sa[OUR_SIZE]; | |
94 | int sb[OUR_SIZE]; | |
95 | int sc[OUR_SIZE]; | |
96 | int sd[OUR_SIZE]; | |
97 | int *x, *a, *b, *c, *d; | |
98 | ||
99 | x = calloc (OUR_SIZE, sizeof (int)); | |
100 | a = calloc (OUR_SIZE, sizeof (int)); | |
101 | b = calloc (OUR_SIZE, sizeof (int)); | |
102 | c = calloc (OUR_SIZE, sizeof (int)); | |
103 | d = calloc (OUR_SIZE, sizeof (int)); | |
104 | ||
105 | upper (x, a, b, c, d, OUR_SIZE + 2); | |
106 | upper (sx, sa, sb, sc, sd, OUR_SIZE + 2); | |
107 | upper (gx, ga, gb, gc, gd, OUR_SIZE + 2); | |
108 | lower (x, a, b, c, d, 1); | |
109 | lower (sx, sa, sb, sc, sd, 1); | |
110 | bp1 (*x); | |
111 | lower (gx, ga, gb, gc, gd, 1); | |
112 | ||
113 | free (x); | |
114 | free (a); | |
115 | free (b); | |
116 | free (c); | |
117 | free (d); | |
118 | } | |
119 | return 0; | |
120 | } |