xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.arch/i386-mpx-call.c (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1 /* Test for inferior function calls MPX context.
2 
3    Copyright (C) 2017-2023 Free Software Foundation, Inc.
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 <stdlib.h>
19 #include <string.h>
20 
21 /* Defined size for arrays.  */
22 #define ARRAY_LENGTH    5
23 
24 
25 int
26 upper (int *a, int *b, int *c, int *d, int len)
27 {
28   int value;
29 
30   value = *(a + len);
31   value = *(b + len);
32   value = *(c + len);
33   value = *(d + len);
34 
35   value = value - *a + 1;
36   return value;
37 }
38 
39 
40 int
41 lower (int *a, int *b, int *c, int *d, int len)
42 {
43   int value;
44 
45   value = *(a - len);
46   value = *(b - len);
47   value = *(c - len);
48   value = *(d - len);
49 
50   value = value - *a + 1;
51   return value;
52 }
53 
54 
55 char
56 char_upper (char *str, int length)
57 {
58   char ch;
59   ch = *(str + length);
60 
61   return ch;
62 }
63 
64 
65 char
66 char_lower (char *str, int length)
67 {
68   char ch;
69   ch = *(str - length);
70 
71   return ch;
72 }
73 
74 
75 int
76 main (void)
77 {
78   int sa[ARRAY_LENGTH];
79   int sb[ARRAY_LENGTH];
80   int sc[ARRAY_LENGTH];
81   int sd[ARRAY_LENGTH];
82   int *x, *a, *b, *c, *d;
83   char mchar;
84   char hello[] = "Hello";
85 
86   x = malloc (sizeof (int) * ARRAY_LENGTH);
87   a = malloc (sizeof (int) * ARRAY_LENGTH);
88   b = malloc (sizeof (int) * ARRAY_LENGTH);
89   c = malloc (sizeof (int) * ARRAY_LENGTH);
90   d = malloc (sizeof (int) * ARRAY_LENGTH);
91 
92   *x = upper (sa, sb, sc, sd, 0);  /* bkpt 1.  */
93   *x = lower (a, b, c, d, 0);
94 
95   mchar = char_upper (hello, 10);
96   mchar = char_lower (hello, 10);
97 
98   free (x);
99   free (a);
100   free (b);
101   free (c);
102   free (d);
103 
104   return 0;
105 }
106