Re: ld plugin bfd_make_readable leak
[binutils-gdb.git] / gdb / testsuite / gdb.arch / aarch64-sme-regs-unavailable.c
blob4648193a9a37bc057ab8495e6220792b1e7d5822
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2023-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
18 /* Exercise various cases of ZA contents not being available for AArch64's
19 Scalable Matrix Extension. */
21 #include <stdio.h>
22 #include <sys/auxv.h>
23 #include <sys/prctl.h>
24 #include <stdlib.h>
25 #include <unistd.h>
27 #ifndef HWCAP_SVE
28 #define HWCAP_SVE (1 << 22)
29 #endif
31 #ifndef HWCAP2_SME
32 #define HWCAP2_SME (1 << 23)
33 #endif
35 #ifndef PR_SVE_SET_VL
36 #define PR_SVE_SET_VL 50
37 #define PR_SVE_GET_VL 51
38 #define PR_SVE_VL_LEN_MASK 0xffff
39 #endif
41 #ifndef PR_SME_SET_VL
42 #define PR_SME_SET_VL 63
43 #define PR_SME_GET_VL 64
44 #define PR_SME_VL_LEN_MASK 0xffff
45 #endif
47 static int get_vl_size ()
49 int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0);
50 if (res < 0)
52 printf ("FAILED to PR_SVE_GET_VL (%d)\n", res);
53 return -1;
55 return (res & PR_SVE_VL_LEN_MASK);
58 static int get_svl_size ()
60 int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0);
61 if (res < 0)
63 printf ("FAILED to PR_SME_GET_VL (%d)\n", res);
64 return -1;
66 return (res & PR_SVE_VL_LEN_MASK);
69 static int set_vl_size (int new_vl)
71 int res = prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0);
72 if (res < 0)
74 printf ("FAILED to PR_SVE_SET_VL (%d)\n", res);
75 return -1;
78 res = get_vl_size ();
79 if (res != new_vl)
81 printf ("Unexpected VL value (%d)\n", res);
82 return -1;
85 return res;
88 static int set_svl_size (int new_svl)
90 int res = prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0);
91 if (res < 0)
93 printf ("FAILED to PR_SME_SET_VL (%d)\n", res);
94 return -1;
97 res = get_svl_size ();
98 if (res != new_svl)
100 printf ("Unexpected SVL value (%d)\n", res);
101 return -1;
104 return res;
107 static int
108 test_id_to_vl (int id)
110 return 16 << ((id / 5) % 5);
113 static int
114 test_id_to_svl (int id)
116 return 16 << (id % 5);
119 static void
120 dummy ()
125 main (int argc, char **argv)
127 if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME)
129 int id_start = ID_START;
130 int id_end = ID_END;
132 for (int id = id_start; id <= id_end; id++)
134 int vl = test_id_to_vl (id);
135 int svl = test_id_to_svl (id);
137 if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1)
138 continue;
140 dummy (); /* stop 1 */
143 dummy (); /* stop 2 */
145 else
147 printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n");
148 return -1;
151 return 0;