0b54723d8bc31c4b8e628219ab03b56d39d19164
[external/binutils.git] / gdb / testsuite / gdb.arch / riscv-reg-aliases.exp
1 # Copyright 2018 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 if {![istarget "riscv*-*-*"]} {
17     verbose "Skipping ${gdb_test_file_name}."
18     return
19 }
20
21 standard_testfile
22
23 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
24     return -1
25 }
26
27 if ![runto_main] then {
28    fail "can't run to main"
29    return 0
30 }
31
32 # A list, each entry is itself a list, the first item being the
33 # primary name of a register (the name GDB uses by default), and the
34 # second entry being a list of register aliases.
35 set register_names \
36 { { ra {x1} } { sp {x2} } { gp {x3} } { tp {x4} } { t0 {x5} } \
37   { t1 {x6} } { t2 {x7} } { fp {x8 s0} } { s1 {x9} } { a0 {x10} } \
38   { a1 {x11} } { a2 {x12} } { a3 {x13} } { a4 {x14} } { a5 {x15} } \
39   { a6 {x16} } { a7 {x17} } { s2 {x18} } { s3 {x19} } { s4 {x20} } \
40   { s5 {x21} } { s6 {x22} } { s7 {x23} } { s8 {x24} } { s9 {x25} } \
41   { s10 {x26} } { s11 {x27} } { t3 {x28} } { t4 {x29} } { t5 {x30} } \
42   { t6 {x31} } { ft0 {f0} } { ft1 {f1} } { ft2 {f2} } { ft3 {f3} } \
43   { ft4 {f4} } { ft5 {f5} } { ft6 {f6} } { ft7 {f7} } { fs0 {f8} } \
44   { fs1 {f9} } { fa0 {f10} } { fa1 {f11} } { fa2 {f12} } { fa3 {f13} } \
45   { fa4 {f14} } { fa5 {f15} } { fa6 {f16} } { fa7 {f17} } { fs2 {f18} } \
46   { fs3 {f19} } { fs4 {f20} } { fs5 {f21} } { fs6 {f22} } { fs7 {f23} } \
47   { fs8 {f24} } { fs9 {f25} } { fs10 {f26} } { fs11 {f27} } { ft8 {f28} } \
48   { ft9 {f29} } { ft10 {f30} } { ft11 {f31} } }
49
50 # Check that the zero register (and its x0 alias) both contain the
51 # value 0.
52
53 proc check_zero_register_value {testname} {
54     gdb_test "p/d \$zero" " = 0" "check \$zero: ${testname}"
55     gdb_test "p/d \$x0" " = 0" "check \$x0: ${testname}"
56 }
57
58 # First, some testing of the zero register.  This register should
59 # always read as zero, and should swallow any attempt to write a
60 # non-zero value to the register.
61
62 check_zero_register_value "before any writes"
63
64 gdb_test_no_output "set \$zero = 123" \
65     "write to the \$zero register"
66
67 check_zero_register_value "after write to \$zero"
68
69 gdb_test_no_output "set \$x0 = 123" \
70     "write to the \$x0 register"
71
72 check_zero_register_value "after write to \$x0"
73
74 # Set all of the general registers to zero.  Confirm that the value of
75 # zero can be read back from the primary name, and from all of the
76 # alias names.
77
78 foreach reg_desc ${register_names} {
79     set primary_name [lindex ${reg_desc} 0]
80     set alias_names [lindex ${reg_desc} 1]
81
82     gdb_test_no_output "set \$${primary_name} = 0" \
83         "set register ${primary_name} to an initial value of zero"
84     gdb_test "p/d \$${primary_name}" " = 0" \
85         "check the initial value of ${primary_name} is now zero"
86
87     foreach reg_alias ${alias_names} {
88         gdb_test "p/d \$${reg_alias}" " = 0" \
89             "check the initial value of ${reg_alias} is now zero"
90     }
91 }
92
93 # Set each register in turn to a new value, and confirm that the new
94 # value can be read back from the primary name, and from all of the
95 # alias names.
96
97 set reg_value 100
98 foreach reg_desc ${register_names} {
99     set primary_name [lindex ${reg_desc} 0]
100     set alias_names [lindex ${reg_desc} 1]
101
102     # Set value through the primary register name, and check that all
103     # the aliases see the same value.
104     set reg_value [incr reg_value]
105     gdb_test_no_output "set \$${primary_name} = $reg_value" \
106         "write non-zero value to ${primary_name}"
107     gdb_test "p/d \$${primary_name}" " = $reg_value" \
108         "read ${primary_name} after non-zero write to ${primary_name}"
109     foreach reg_alias ${alias_names} {
110         gdb_test "p/d \$${reg_alias}" " = $reg_value" \
111             "read ${reg_alias} after non-zero write to ${primary_name}"
112     }
113
114     # For each alias, set a new value, and check that the primary
115     # register name, and all the other aliases, see the new value.
116     foreach reg_alias ${alias_names} {
117         set reg_value [incr reg_value]
118
119         gdb_test_no_output "set \$${reg_alias} = $reg_value" \
120             "write non-zero value to ${reg_alias}"
121
122         gdb_test "p/d \$${primary_name}" " = $reg_value" \
123             "read ${primary_name} after non-zero write to ${reg_alias}"
124
125         foreach other_reg_alias ${alias_names} {
126             gdb_test "p/d \$${other_reg_alias}" " = $reg_value" \
127                 "read ${other_reg_alias} after non-zero write to ${reg_alias}"
128         }
129     }
130 }