]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.arch/riscv-reg-aliases.exp
gdb/testsuite: remove use of then keyword from gdb.arch/*.exp
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / riscv-reg-aliases.exp
CommitLineData
4a94e368 1# Copyright 2018-2022 Free Software Foundation, Inc.
0dbfcfff
AB
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
16if {![istarget "riscv*-*-*"]} {
17 verbose "Skipping ${gdb_test_file_name}."
18 return
19}
20
21standard_testfile
22
23if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
24 return -1
25}
26
75b6f386 27if {![runto_main]} {
0dbfcfff
AB
28 return 0
29}
30
92dcebf3
AB
31
32# A list for all the integer register names and their aliases. The format is
33# a list with each entry being itself a list, the first item being the primary
34# name of a register (the name GDB uses by default), and the second entry
35# being a list of register aliases.
36set xreg_names \
0dbfcfff
AB
37{ { ra {x1} } { sp {x2} } { gp {x3} } { tp {x4} } { t0 {x5} } \
38 { t1 {x6} } { t2 {x7} } { fp {x8 s0} } { s1 {x9} } { a0 {x10} } \
39 { a1 {x11} } { a2 {x12} } { a3 {x13} } { a4 {x14} } { a5 {x15} } \
40 { a6 {x16} } { a7 {x17} } { s2 {x18} } { s3 {x19} } { s4 {x20} } \
41 { s5 {x21} } { s6 {x22} } { s7 {x23} } { s8 {x24} } { s9 {x25} } \
42 { s10 {x26} } { s11 {x27} } { t3 {x28} } { t4 {x29} } { t5 {x30} } \
92dcebf3
AB
43 { t6 {x31} } }
44
45# This is just like XREG_NAMES, except it contains all the floating point
46# register names and their aliases.
47set freg_names \
48{ { ft0 {f0} } { ft1 {f1} } { ft2 {f2} } { ft3 {f3} } { ft4 {f4} } \
49 { ft5 {f5} } { ft6 {f6} } { ft7 {f7} } { fs0 {f8} } { fs1 {f9} } \
50 { fa0 {f10} } { fa1 {f11} } { fa2 {f12} } { fa3 {f13} } { fa4 {f14} } \
51 { fa5 {f15} } { fa6 {f16} } { fa7 {f17} } { fs2 {f18} } { fs3 {f19} } \
52 { fs4 {f20} } { fs5 {f21} } { fs6 {f22} } { fs7 {f23} } { fs8 {f24} } \
53 { fs9 {f25} } { fs10 {f26} } { fs11 {f27} } { ft8 {f28} } { ft9 {f29} } \
54 { ft10 {f30} } { ft11 {f31} } }
0dbfcfff
AB
55
56# Check that the zero register (and its x0 alias) both contain the
57# value 0.
0dbfcfff
AB
58proc check_zero_register_value {testname} {
59 gdb_test "p/d \$zero" " = 0" "check \$zero: ${testname}"
60 gdb_test "p/d \$x0" " = 0" "check \$x0: ${testname}"
61}
62
92dcebf3
AB
63# Set all of the registers in REG_SET to zero. Confirm that the value of zero
64# can be read back using the primary name, and from all of the alias names.
65#
66# For some architectures (RV64, RV128) the float registers have union type,
67# and we need to read/write using a ".float" extension. This is passed in
68# REG_EXTENSION. If no extension is needed then REG_EXTENSION is the empty
69# string.
c1abad9e
AB
70#
71# PRINT_FMT is used when inspecting the registers, and should be a
72# character that can be used in a GDB print command as an output
73# format, e.g. 'd' (decimal), or 'f' (float).
74proc check_setting_registers_to_zero { reg_set reg_extension print_fmt } {
92dcebf3
AB
75 foreach reg_desc ${reg_set} {
76 set primary_name [lindex ${reg_desc} 0]
77 set alias_names [lindex ${reg_desc} 1]
78
79 gdb_test_no_output "set \$${primary_name}${reg_extension} = 0" \
80 "set register ${primary_name} to an initial value of zero"
c1abad9e 81 gdb_test "p/${print_fmt} \$${primary_name}${reg_extension}" " = 0" \
92dcebf3
AB
82 "check the initial value of ${primary_name} is now zero"
83
84 foreach reg_alias ${alias_names} {
c1abad9e 85 gdb_test "p/${print_fmt} \$${reg_alias}${reg_extension}" " = 0" \
92dcebf3
AB
86 "check the initial value of ${reg_alias} is now zero"
87 }
88 }
89}
90
91# Set all of the registers in REG_SET to a new value (the value starts at
92# REG_VALUE and is incremented after each test). Then confirm that the new
93# value can be read back using the primary name, and from all of the alias
94# names.
95#
96# Next, set each register in REG_SET using each of its alias names, then
97# confirm that the value can be read back using both the primary name, and all
98# of the aliases.
99#
100# The REG_EXTENSION field is used as in CHECK_SETTING_REGISTERS_TO_ZERO.
c1abad9e
AB
101#
102# PRINT_FMT is used when inspecting the registers, and should be a
103# character that can be used in a GDB print command as an output
104# format, e.g. 'd' (decimal), or 'f' (float).
105proc check_setting_registers_to_value { reg_set reg_extension reg_value print_fmt } {
92dcebf3
AB
106 foreach reg_desc ${reg_set} {
107 set primary_name [lindex ${reg_desc} 0]
108 set alias_names [lindex ${reg_desc} 1]
109
110 # Set value through the primary register name, and check that all
111 # the aliases see the same value.
112 set reg_value [incr reg_value]
113 gdb_test_no_output "set \$${primary_name}${reg_extension} = $reg_value" \
114 "write non-zero value to ${primary_name}"
c1abad9e 115 gdb_test "p/${print_fmt} \$${primary_name}${reg_extension}" " = $reg_value" \
92dcebf3
AB
116 "read ${primary_name} after non-zero write to ${primary_name}"
117 foreach reg_alias ${alias_names} {
c1abad9e 118 gdb_test "p/${print_fmt} \$${reg_alias}${reg_extension}" " = $reg_value" \
92dcebf3
AB
119 "read ${reg_alias} after non-zero write to ${primary_name}"
120 }
121
122 # For each alias, set a new value, and check that the primary
123 # register name, and all the other aliases, see the new value.
124 foreach reg_alias ${alias_names} {
125 set reg_value [incr reg_value]
126
127 gdb_test_no_output "set \$${reg_alias}${reg_extension} = $reg_value" \
128 "write non-zero value to ${reg_alias}"
129
c1abad9e 130 gdb_test "p/${print_fmt} \$${primary_name}${reg_extension}" " = $reg_value" \
92dcebf3
AB
131 "read ${primary_name} after non-zero write to ${reg_alias}"
132
133 foreach other_reg_alias ${alias_names} {
c1abad9e 134 gdb_test "p/${print_fmt} \$${other_reg_alias}${reg_extension}" " = $reg_value" \
92dcebf3
AB
135 "read ${other_reg_alias} after non-zero write to ${reg_alias}"
136 }
137 }
138 }
139}
140
0dbfcfff
AB
141# First, some testing of the zero register. This register should
142# always read as zero, and should swallow any attempt to write a
143# non-zero value to the register.
144
145check_zero_register_value "before any writes"
146
147gdb_test_no_output "set \$zero = 123" \
148 "write to the \$zero register"
149
150check_zero_register_value "after write to \$zero"
151
152gdb_test_no_output "set \$x0 = 123" \
153 "write to the \$x0 register"
154
155check_zero_register_value "after write to \$x0"
156
92dcebf3
AB
157# Some RISC-V variants model the fregs as a union (RV64, RV128). In this case
158# we should access the register using 'REG_NAME.float'. In the following we
159# figure out if the field name is needed or not by looking at how GDB prints
160# on register.
cd115d61 161set skip_freg_tests 0
92dcebf3
AB
162set freg_extension "INVALID"
163set message "check format of float registers"
cd115d61
AB
164gdb_test_multiple "info registers \$ft0" $message {
165 -re "Invalid register `ft0'\r\n$gdb_prompt $" {
166 set skip_freg_tests 1
167 set freg_extension "NONE"
92dcebf3 168 pass $message
0dbfcfff 169 }
cd115d61 170 -re "ft0 \+\[0-9\]\+.*\r\n$gdb_prompt $" {
92dcebf3
AB
171 set freg_extension ""
172 pass $message
0dbfcfff 173 }
cd115d61
AB
174 -re "ft0 \+\{float = .*\r\n$gdb_prompt $" {
175 set freg_extension ".float"
176 pass $message
177 }
0dbfcfff 178}
92dcebf3
AB
179gdb_assert ![string eq "${freg_extension}" "INVALID"] \
180 "check that floating point format has been understood"
181
182# Now check that we can write zero, and read zero back to all of the integer
183# and floating point registers.
c1abad9e 184check_setting_registers_to_zero ${xreg_names} "" "d"
cd115d61
AB
185
186if { ! $skip_freg_tests } {
c1abad9e 187 check_setting_registers_to_zero ${freg_names} ${freg_extension} "f"
cd115d61 188}
92dcebf3
AB
189
190# Set each register in turn to a new value, and confirm that the new value can
191# be read back from the primary name, and from all of the alias names. The
192# value passed in to each test invocation here is arbitrary, they are
193# significantly different so that the float tests don't reuse value from the
194# integer tests.
c1abad9e 195check_setting_registers_to_value ${xreg_names} "" 100 "d"
cd115d61
AB
196
197if { ! $skip_freg_tests } {
c1abad9e 198 check_setting_registers_to_value ${freg_names} ${freg_extension} 500 "f"
cd115d61 199}