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