1 # Copyright (C) 2023-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Exercise restoring SME/TPIDR2 state from a signal frame.
18 load_lib aarch64-scalable.exp
20 require is_aarch64_target
21 require allow_aarch64_sve_tests
22 require allow_aarch64_sme_tests
24 # Remote targets can't communicate vector length (vl or svl) changes
26 require
!gdb_protocol_is_remote
29 # Validate the state of registers in the signal frame for various states.
31 proc test_sme_registers_sigframe
{ id_start id_end
} {
33 set compile_flags
{"debug" "macros"}
34 lappend compile_flags
"additional_flags=-march=armv8.5-a+sve"
35 lappend compile_flags
"additional_flags=-DID_START=${id_start}"
36 lappend compile_flags
"additional_flags=-DID_END=${id_end}"
38 standard_testfile
${::srcdir}/${::subdir}/aarch64-sme-regs-sigframe.c
39 set executable
"${::testfile}-${id_start}-${id_end}"
40 if {[prepare_for_testing
"failed to prepare" ${executable
} ${::srcfile} ${compile_flags
}]} {
43 set binfile
[standard_output_file
${executable
}]
46 untested
"could not run to main"
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]
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]
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
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."
72 verbose
-log "Skipping test."
73 set skip_unsupported
1
76 with_test_prefix
"state=${state} vl=${vl} svl=${svl}" {
78 # If the SVE or SME vector length is not supported, just skip
80 if {$skip_unsupported} {
81 untested
"unsupported configuration on target"
85 # Run the program until it has adjusted the svl.
86 if [gdb_continue_to_breakpoint
$sigill_breakpoint] {
90 # Check SVG to make sure it is correct
91 set expected_svg
[expr $svl / 8]
92 gdb_test
"print \$svg" "= ${expected_svg}"
94 # Check the size of ZA.
95 set expected_za_size
[expr $svl * $svl]
96 gdb_test
"print sizeof \$za" " = $expected_za_size"
98 # Check the value of SVCR.
99 gdb_test
"print \$svcr" [get_svcr_value
$state] "svcr before signal"
101 # Handle SME ZA and SME2 initialization and state.
104 if { $state == "za" ||
$state == "za_ssve" } {
109 # Set the expected ZA pattern.
110 set za_pattern
[string_to_regexp
[2d_array_value_pattern
$byte $svl $svl]]
112 # Handle SVE/SSVE initialization and state.
114 if { $state == "ssve" ||
$state == "za_ssve" } {
115 # SVE state comes from SSVE.
118 # SVE state comes from regular SVE.
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"
130 # Print ZA to check its value.
131 gdb_test
"print \$za" $za_pattern "read back from za"
133 # Test TPIDR2 restore from signal frame as well.
134 gdb_test_no_output
"set \$tpidr2=0x0102030405060708"
136 # Run to the illegal instruction.
137 if [gdb_test
"continue" "Continuing\.\r\n\r\nProgram received signal SIGILL, Illegal instruction\..*in main.*"] {
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] {
148 # Modify TPIDR2 so it is different from its value past the signal
150 gdb_test_no_output
"set \$tpidr2 = 0x0"
152 # Select the frame that contains "main".
153 gdb_test
"frame 2" "#2.* main \\\(.*\\\) at.*"
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"
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"
165 # Check the value of SVCR in the signal frame.
166 gdb_test
"print \$svcr" [get_svcr_value
$state] "svcr from signal frame"
168 # Check the value of ZA in the signal frame.
169 gdb_test
"print \$za" $za_pattern "za contents from signal frame"
171 # Check the value of TPIDR2 in the signal frame.
172 gdb_test
"print/x \$tpidr2" " = 0x102030405060708" "tpidr2 contents from signal frame"
174 # Check the value of SME2 ZT0 in the signal frame.
175 if [is_sme2_available
] {
176 # The target supports SME2.
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"
186 test_sme_registers_sigframe
$id_start $id_end