]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/riscv-tdesc-regs.exp
1a92f424cbe11836f738931353edff580df1e31a
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / riscv-tdesc-regs.exp
1 # Copyright 2020-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 # Various tests to check which register names are available after
17 # loading a new target description file, and which registers show up
18 # in the output of the 'info registers' command.
19
20 require {istarget "riscv*-*-*"}
21
22 standard_testfile
23
24 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
25 {debug quiet}] } {
26 unsupported "failed to compile"
27 return -1
28 }
29
30 if { ![runto_main] } {
31 return -1
32 }
33
34 # First, figure out if we are 32-bit or 64-bit.
35 set xlen [get_valueof "/d" "sizeof (\$a0)" 0]
36 set flen [get_valueof "/d" "sizeof (\$fa0)" 0]
37
38 gdb_assert { $xlen != 0 && $flen != 0 } "read xlen and flen"
39
40 # We only handle 32-bit or 64-bit x-registers.
41 if { $xlen != 4 && $xlen != 8 } {
42 unsupported "unknown x-register size"
43 return -1
44 }
45
46 # If FLEN is 1 then the target doesn't have floating point support
47 # (the register $fa0 was not recognised). Otherwise, we can only
48 # proceed if FLEN equals XLEN, otherwise we'd need more test XML
49 # files.
50 if { $flen != 1 && $flen != $xlen } {
51 unsupport "unknown xlen/flen combination"
52 return -1
53 }
54
55 if { $xlen == 4 } {
56 set xml_tdesc "riscv-tdesc-regs-32.xml"
57 } else {
58 set xml_tdesc "riscv-tdesc-regs-64.xml"
59 }
60 set xml_tdesc "${srcdir}/${subdir}/${xml_tdesc}"
61
62 # Maybe copy the target over if we're remote testing.
63 if {[is_remote host]} {
64 set remote_file [remote_download host $xml_tdesc]
65 } else {
66 set remote_file $xml_tdesc
67 }
68
69 gdb_test_no_output "set tdesc filename $remote_file" \
70 "load the new target description"
71
72 # Check that an alias for an unknown CSR will give a suitable error.
73 gdb_test "info registers \$csr0" "Invalid register `csr0'"
74
75 # Return the number of times REGISTER should appear in GROUP, this
76 # will either be 0 or 1.
77 proc get_expected_result { register group } {
78
79 # Everything should appear once in the 'all' group.
80 if { $group == "all" || $group == "x_all" } {
81 return 1
82 }
83
84 if { $group == "save" || $group == "restore" } {
85 # Everything is in the save/restore groups except these two.
86 if { $register == "unknown_csr" || $register == "dscratch" } {
87 return 0
88 }
89 return 1
90 }
91
92 if { $group == "system" || $group == "csr" } {
93 # All the registers we check should be in these groups.
94 return 1
95 }
96
97 return 0
98 }
99
100 foreach rgroup {x_all all save restore general system csr} {
101 # Now use 'info registers all' to see how many times the floating
102 # point status registers show up in the output.
103 array set reg_counts {}
104 if {$rgroup == "x_all"} {
105 set test "info all-registers"
106 } else {
107 set test "info registers $rgroup"
108 }
109 gdb_test_multiple $test $test {
110 -re ".*info registers all\r\n" {
111 verbose -log "Skip to first register"
112 exp_continue
113 }
114 -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
115 set reg $expect_out(1,string)
116 incr reg_counts($reg)
117 exp_continue
118 }
119 -re "^$gdb_prompt $" {
120 # Done.
121 }
122 }
123
124 foreach reg {fflags frm fcsr unknown_csr dscratch} {
125 if { [info exists reg_counts($reg) ] } {
126 set count $reg_counts($reg)
127 } else {
128 set count 0
129 }
130
131 set expected_count [ get_expected_result $reg $rgroup ]
132 gdb_assert {$count == $expected_count} \
133 "register $reg seen in reggroup $rgroup $expected_count times"
134 }
135 array unset reg_counts
136 }
137
138 # Next load a target description that contains fcsr, but not fflags or
139 # frm. Then check that GDB provides an fflags and frm registers using
140 # the pseudo-register mechanism.
141 if { $xlen == 4 } {
142 set xml_tdesc "riscv-tdesc-fcsr-32.xml"
143 } else {
144 set xml_tdesc "riscv-tdesc-fcsr-64.xml"
145 }
146 set xml_tdesc "${srcdir}/${subdir}/${xml_tdesc}"
147
148 # Maybe copy the target over if we're remote testing.
149 if {[is_remote host]} {
150 set remote_file [remote_download host $xml_tdesc]
151 } else {
152 set remote_file $xml_tdesc
153 }
154
155 gdb_test_no_output "set tdesc filename $remote_file" \
156 "load the target description that lacks fflags and frm"
157
158 foreach reg {fflags frm} {
159 gdb_test_multiple "info registers $reg" "" {
160 -re "^info registers $reg\r\n" {
161 exp_continue
162 }
163
164 -wrap -re "^Invalid register `$reg`" {
165 fail $gdb_test_name
166 }
167
168 -wrap -re "^$reg\\s+\[^\r\n\]+" {
169 pass $gdb_test_name
170 }
171 }
172 }