Re: ld plugin bfd_make_readable leak
[binutils-gdb.git] / gdb / testsuite / gdb.arch / aarch64-sme-sanity.c
blob0a316db05245d171d241ee4a753d21ce1542523b
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 /* Sanity test to exercise AArch64's Scalable Vector/Matrix Extension basic
19 functionality. It cycles through different combinations of state and
20 initializes different register sets. */
22 #include <stdio.h>
23 #include <sys/auxv.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 HWCAP2_SME2
37 #define HWCAP2_SME2 (1UL << 37)
38 #define HWCAP2_SME2P1 (1UL << 38)
39 #endif
41 static void
42 enable_za ()
44 /* smstart za */
45 __asm __volatile (".word 0xD503457F");
48 static void
49 disable_za ()
51 /* smstop za */
52 __asm __volatile (".word 0xD503447F");
55 static void
56 enable_sm ()
58 /* smstart sm */
59 __asm __volatile (".word 0xD503437F");
62 static void
63 disable_sm ()
65 /* smstop sm */
66 __asm __volatile (".word 0xD503427F");
69 static void
70 initialize_fpsimd_state ()
72 char buffer[16];
74 for (int i = 0; i < 16; i++)
75 buffer[i] = 0x55;
77 __asm __volatile ("mov x0, %0\n\t" \
78 : : "r" (buffer));
80 __asm __volatile ("ldr q0, [x0]");
81 __asm __volatile ("ldr q1, [x0]");
82 __asm __volatile ("ldr q2, [x0]");
83 __asm __volatile ("ldr q3, [x0]");
84 __asm __volatile ("ldr q4, [x0]");
85 __asm __volatile ("ldr q5, [x0]");
86 __asm __volatile ("ldr q6, [x0]");
87 __asm __volatile ("ldr q7, [x0]");
88 __asm __volatile ("ldr q8, [x0]");
89 __asm __volatile ("ldr q9, [x0]");
90 __asm __volatile ("ldr q10, [x0]");
91 __asm __volatile ("ldr q11, [x0]");
92 __asm __volatile ("ldr q12, [x0]");
93 __asm __volatile ("ldr q13, [x0]");
94 __asm __volatile ("ldr q14, [x0]");
95 __asm __volatile ("ldr q15, [x0]");
96 __asm __volatile ("ldr q16, [x0]");
97 __asm __volatile ("ldr q17, [x0]");
98 __asm __volatile ("ldr q18, [x0]");
99 __asm __volatile ("ldr q19, [x0]");
100 __asm __volatile ("ldr q20, [x0]");
101 __asm __volatile ("ldr q21, [x0]");
102 __asm __volatile ("ldr q22, [x0]");
103 __asm __volatile ("ldr q23, [x0]");
104 __asm __volatile ("ldr q24, [x0]");
105 __asm __volatile ("ldr q25, [x0]");
106 __asm __volatile ("ldr q26, [x0]");
107 __asm __volatile ("ldr q27, [x0]");
108 __asm __volatile ("ldr q28, [x0]");
109 __asm __volatile ("ldr q29, [x0]");
110 __asm __volatile ("ldr q30, [x0]");
111 __asm __volatile ("ldr q31, [x0]");
114 static void
115 initialize_za_state ()
117 /* zero za */
118 __asm __volatile (".word 0xC00800FF");
120 char buffer[256];
122 for (int i = 0; i < 256; i++)
123 buffer[i] = 0xaa;
125 __asm __volatile ("mov x0, %0\n\t" \
126 : : "r" (buffer));
128 /* Initialize loop boundaries. */
129 __asm __volatile ("mov w12, 0");
130 __asm __volatile ("mov w17, 256");
132 /* loop: ldr za[w12, 0], [x0] */
133 __asm __volatile ("loop: .word 0xe1000000");
134 __asm __volatile ("add w12, w12, 1");
135 __asm __volatile ("cmp w12, w17");
136 __asm __volatile ("bne loop");
139 static void
140 initialize_zt_state ()
142 unsigned long hwcap2 = getauxval (AT_HWCAP2);
144 if (!(hwcap2 & HWCAP2_SME2) && !(hwcap2 & HWCAP2_SME2P1))
145 return;
147 char buffer[64];
149 for (int i = 0; i < 64; i++)
150 buffer[i] = 0xff;
152 __asm __volatile ("mov x0, %0\n\t" \
153 : : "r" (buffer));
155 /* Initialize ZT0. */
156 /* ldr zt0, x0 */
157 __asm __volatile (".word 0xe11f8000");
160 static void
161 initialize_sve_state ()
163 __asm __volatile ("dup z0.b, -1");
164 __asm __volatile ("dup z1.b, -1");
165 __asm __volatile ("dup z2.b, -1");
166 __asm __volatile ("dup z3.b, -1");
167 __asm __volatile ("dup z4.b, -1");
168 __asm __volatile ("dup z5.b, -1");
169 __asm __volatile ("dup z6.b, -1");
170 __asm __volatile ("dup z7.b, -1");
171 __asm __volatile ("dup z8.b, -1");
172 __asm __volatile ("dup z9.b, -1");
173 __asm __volatile ("dup z10.b, -1");
174 __asm __volatile ("dup z11.b, -1");
175 __asm __volatile ("dup z12.b, -1");
176 __asm __volatile ("dup z13.b, -1");
177 __asm __volatile ("dup z14.b, -1");
178 __asm __volatile ("dup z15.b, -1");
179 __asm __volatile ("dup z16.b, -1");
180 __asm __volatile ("dup z17.b, -1");
181 __asm __volatile ("dup z18.b, -1");
182 __asm __volatile ("dup z19.b, -1");
183 __asm __volatile ("dup z20.b, -1");
184 __asm __volatile ("dup z21.b, -1");
185 __asm __volatile ("dup z22.b, -1");
186 __asm __volatile ("dup z23.b, -1");
187 __asm __volatile ("dup z24.b, -1");
188 __asm __volatile ("dup z25.b, -1");
189 __asm __volatile ("dup z26.b, -1");
190 __asm __volatile ("dup z27.b, -1");
191 __asm __volatile ("dup z28.b, -1");
192 __asm __volatile ("dup z29.b, -1");
193 __asm __volatile ("dup z30.b, -1");
194 __asm __volatile ("dup z31.b, -1");
195 __asm __volatile ("ptrue p0.b");
196 __asm __volatile ("ptrue p1.b");
197 __asm __volatile ("ptrue p2.b");
198 __asm __volatile ("ptrue p3.b");
199 __asm __volatile ("ptrue p4.b");
200 __asm __volatile ("ptrue p5.b");
201 __asm __volatile ("ptrue p6.b");
202 __asm __volatile ("ptrue p7.b");
203 __asm __volatile ("ptrue p8.b");
204 __asm __volatile ("ptrue p9.b");
205 __asm __volatile ("ptrue p10.b");
206 __asm __volatile ("ptrue p11.b");
207 __asm __volatile ("ptrue p12.b");
208 __asm __volatile ("ptrue p13.b");
209 __asm __volatile ("ptrue p14.b");
210 __asm __volatile ("ptrue p15.b");
211 __asm __volatile ("setffr");
214 /* Enable register states based on STATE.
216 0 - FPSIMD
217 1 - SVE
218 2 - SSVE
219 3 - ZA (+ SME2 ZT0)
220 4 - ZA and SSVE (+ SME2 ZT0). */
222 void enable_states (int state)
224 disable_za ();
225 disable_sm ();
226 initialize_fpsimd_state ();
228 if (state == 1)
230 initialize_sve_state ();
232 else if (state == 2)
234 enable_sm ();
235 initialize_sve_state ();
237 else if (state == 3)
239 enable_za ();
240 initialize_za_state ();
241 initialize_zt_state ();
243 else if (state == 4)
245 enable_za ();
246 enable_sm ();
247 initialize_sve_state ();
248 initialize_za_state ();
249 initialize_zt_state ();
252 return;
255 void dummy ()
260 main (int argc, char **argv)
262 if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME)
264 for (int state = 0; state < 5; state++)
266 enable_states (state);
267 dummy (); /* stop here */
270 else
272 printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n");
273 return -1;
276 return 0;