]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.exp.tcl
2dadcc684559941e5266bdec38b67d5e4eb22ee7
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / aarch64-sme-regs-sigframe.exp.tcl
1 # Copyright (C) 2023 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # Exercise restoring SME/TPIDR2 state from a signal frame.
17
18 load_lib aarch64-scalable.exp
19
20 #
21 # Validate the state of registers in the signal frame for various states.
22 #
23 proc test_sme_registers_sigframe { id_start id_end } {
24
25 set compile_flags {"debug" "macros"}
26 lappend compile_flags "additional_flags=-march=armv8.5-a+sve"
27 lappend compile_flags "additional_flags=-DID_START=${id_start}"
28 lappend compile_flags "additional_flags=-DID_END=${id_end}"
29
30 standard_testfile ${::srcdir}/${::subdir}/aarch64-sme-regs-sigframe.c
31 set executable "${::testfile}-${id_start}-${id_end}"
32 if {[prepare_for_testing "failed to prepare" ${executable} ${::srcfile} ${compile_flags}]} {
33 return -1
34 }
35 set binfile [standard_output_file ${executable}]
36
37 if ![runto_main] {
38 untested "could not run to main"
39 return -1
40 }
41
42 # Check if we are talking to a remote target. If so, bail out, as right now
43 # remote targets can't communicate vector length (vl or svl) changes to gdb
44 # via the RSP. When this restriction is lifted, we can remove this guard.
45 if {[gdb_is_target_remote]} {
46 unsupported "aarch64 sve/sme tests not supported for remote targets"
47 return -1
48 }
49
50 set sigill_breakpoint "stop before SIGILL"
51 set handler_breakpoint "handler"
52 gdb_breakpoint [gdb_get_line_number $sigill_breakpoint]
53 gdb_breakpoint [gdb_get_line_number $handler_breakpoint]
54
55 for {set id $id_start} {$id <= $id_end} {incr id} {
56 set state [test_id_to_state $id]
57 set vl [test_id_to_vl $id]
58 set svl [test_id_to_svl $id]
59
60 set skip_unsupported 0
61 if {![aarch64_supports_sve_vl $vl]
62 || ![aarch64_supports_sme_svl $svl]} {
63 # We have a vector length or streaming vector length that
64 # is not supported by this target. Skip to the next iteration
65 # since it is no use running tests for an unsupported vector
66 # length.
67 if {![aarch64_supports_sve_vl $vl]} {
68 verbose -log "SVE vector length $vl not supported."
69 } elseif {![aarch64_supports_sme_svl $svl]} {
70 verbose -log "SME streaming vector length $svl not supported."
71 }
72 verbose -log "Skipping test."
73 set skip_unsupported 1
74 }
75
76 with_test_prefix "state=${state} vl=${vl} svl=${svl}" {
77
78 # If the SVE or SME vector length is not supported, just skip
79 # these next tests.
80 if {$skip_unsupported} {
81 untested "unsupported configuration on target"
82 continue
83 }
84
85 # Run the program until it has adjusted the svl.
86 if [gdb_continue_to_breakpoint $sigill_breakpoint] {
87 return -1
88 }
89
90 # Check SVG to make sure it is correct
91 set expected_svg [expr $svl / 8]
92 gdb_test "print \$svg" "= ${expected_svg}"
93
94 # Check the size of ZA.
95 set expected_za_size [expr $svl * $svl]
96 gdb_test "print sizeof \$za" " = $expected_za_size"
97
98 # Check the value of SVCR.
99 gdb_test "print \$svcr" [get_svcr_value $state] "svcr before signal"
100
101 # Handle SME ZA and SME2 initialization and state.
102 set byte 0
103 set sme2_byte 0
104 if { $state == "za" || $state == "za_ssve" } {
105 set byte 170
106 set sme2_byte 255
107 }
108
109 # Set the expected ZA pattern.
110 set za_pattern [string_to_regexp [2d_array_value_pattern $byte $svl $svl]]
111
112 # Handle SVE/SSVE initialization and state.
113 set sve_vl $svl
114 if { $state == "ssve" || $state == "za_ssve" } {
115 # SVE state comes from SSVE.
116 set sve_vl $svl
117 } else {
118 # SVE state comes from regular SVE.
119 set sve_vl $vl
120 }
121
122 # Initialize the SVE state.
123 set sve_pattern [string_to_regexp [sve_value_pattern $state $sve_vl 85 255]]
124 for {set row 0} {$row < 32} {incr row} {
125 set register_name "\$z${row}\.b\.u"
126 gdb_test "print sizeof $register_name" " = $sve_vl" "size of $register_name"
127 gdb_test "print $register_name" $sve_pattern "read back from $register_name"
128 }
129
130 # Print ZA to check its value.
131 gdb_test "print \$za" $za_pattern "read back from za"
132
133 # Test TPIDR2 restore from signal frame as well.
134 gdb_test_no_output "set \$tpidr2=0x0102030405060708"
135
136 # Run to the illegal instruction.
137 if [gdb_test "continue" "Continuing\.\r\n\r\nProgram received signal SIGILL, Illegal instruction\..*in main.*"] {
138 return
139 }
140
141 # Skip the illegal instruction. The signal handler will be called after we continue.
142 gdb_test_no_output "set \$pc=\$pc+4"
143 # Continue to the signal handler.
144 if [gdb_continue_to_breakpoint $handler_breakpoint] {
145 return -1
146 }
147
148 # Modify TPIDR2 so it is different from its value past the signal
149 # frame.
150 gdb_test_no_output "set \$tpidr2 = 0x0"
151
152 # Select the frame that contains "main".
153 gdb_test "frame 2" "#2.* main \\\(.*\\\) at.*"
154
155 for {set row 0} {$row < 32} {incr row} {
156 set register_name "\$z${row}\.b\.u"
157 gdb_test "print sizeof $register_name" " = $sve_vl" "size of $register_name in the signal frame"
158 gdb_test "print $register_name" $sve_pattern "$register_name contents from signal frame"
159 }
160
161 # Check the size of ZA in the signal frame.
162 set expected_za_size [expr $svl * $svl]
163 gdb_test "print sizeof \$za" " = $expected_za_size" "size of za in signal frame"
164
165 # Check the value of SVCR in the signal frame.
166 gdb_test "print \$svcr" [get_svcr_value $state] "svcr from signal frame"
167
168 # Check the value of ZA in the signal frame.
169 gdb_test "print \$za" $za_pattern "za contents from signal frame"
170
171 # Check the value of TPIDR2 in the signal frame.
172 gdb_test "print/x \$tpidr2" " = 0x102030405060708" "tpidr2 contents from signal frame"
173
174 # Check the value of SME2 ZT0 in the signal frame.
175 if [is_sme2_available] {
176 # The target supports SME2.
177 set zt_size 64
178 gdb_test "print sizeof \$zt0" " = $zt_size"
179 set zt_pattern [string_to_regexp [1d_array_value_pattern $sme2_byte $zt_size]]
180 gdb_test "print \$zt0" " = $zt_pattern" "zt contents from signal frame"
181 }
182 }
183 }
184 }
185
186 require is_aarch64_target
187 require allow_aarch64_sve_tests
188 require allow_aarch64_sme_tests
189
190 test_sme_registers_sigframe $id_start $id_end