GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.arch / aarch64-sme-regs-available.c
blob3558007f79417a087d8ce05c313b64becfb502d4
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 reading/writing ZA contents 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 <string.h>
26 #include <unistd.h>
28 #ifndef HWCAP_SVE
29 #define HWCAP_SVE (1 << 22)
30 #endif
32 #ifndef HWCAP2_SME
33 #define HWCAP2_SME (1 << 23)
34 #endif
36 #ifndef PR_SVE_SET_VL
37 #define PR_SVE_SET_VL 50
38 #define PR_SVE_GET_VL 51
39 #define PR_SVE_VL_LEN_MASK 0xffff
40 #endif
42 #ifndef PR_SME_SET_VL
43 #define PR_SME_SET_VL 63
44 #define PR_SME_GET_VL 64
45 #define PR_SME_VL_LEN_MASK 0xffff
46 #endif
48 static void
49 enable_za ()
51 /* smstart za */
52 __asm __volatile (".word 0xD503457F");
55 static void
56 disable_za ()
58 /* smstop za */
59 __asm __volatile (".word 0xD503447F");
62 static int get_vl_size ()
64 int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0);
65 if (res < 0)
67 printf ("FAILED to PR_SVE_GET_VL (%d)\n", res);
68 return -1;
70 return (res & PR_SVE_VL_LEN_MASK);
73 static int get_svl_size ()
75 int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0);
76 if (res < 0)
78 printf ("FAILED to PR_SME_GET_VL (%d)\n", res);
79 return -1;
81 return (res & PR_SVE_VL_LEN_MASK);
84 static int set_vl_size (int new_vl)
86 int res = prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0);
87 if (res < 0)
89 printf ("FAILED to PR_SVE_SET_VL (%d)\n", res);
90 return -1;
93 res = get_vl_size ();
94 if (res != new_vl)
96 printf ("Unexpected VL value (%d)\n", res);
97 return -1;
100 return res;
103 static int set_svl_size (int new_svl)
105 int res = prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0);
106 if (res < 0)
108 printf ("FAILED to PR_SME_SET_VL (%d)\n", res);
109 return -1;
112 res = get_svl_size ();
113 if (res != new_svl)
115 printf ("Unexpected SVL value (%d)\n", res);
116 return -1;
119 return res;
122 static int
123 test_id_to_vl (int id)
125 return 16 << ((id / 5) % 5);
128 static int
129 test_id_to_svl (int id)
131 return 16 << (id % 5);
134 static void
135 dummy ()
140 main (int argc, char **argv)
142 if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME)
144 int id_start = ID_START;
145 int id_end = ID_END;
147 for (int id = id_start; id <= id_end; id++)
149 int vl = test_id_to_vl (id);
150 int svl = test_id_to_svl (id);
152 if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1)
153 continue;
155 enable_za ();
156 dummy (); /* stop 1 */
159 for (int id = id_start; id <= id_end; id++)
161 int vl = test_id_to_vl (id);
162 int svl = test_id_to_svl (id);
164 if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1)
165 continue;
167 disable_za ();
168 dummy (); /* stop 2 */
171 else
173 printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n");
174 return -1;
177 return 0;