aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch/riscv-tdesc-regs.exp
blob: 1a92f424cbe11836f738931353edff580df1e31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Copyright 2020-2023 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Various tests to check which register names are available after
# loading a new target description file, and which registers show up
# in the output of the 'info registers' command.

require {istarget "riscv*-*-*"}

standard_testfile

if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
	  {debug quiet}] } {
    unsupported "failed to compile"
    return -1
}

if { ![runto_main] } {
    return -1
}

# First, figure out if we are 32-bit or 64-bit.
set xlen [get_valueof "/d" "sizeof (\$a0)" 0]
set flen [get_valueof "/d" "sizeof (\$fa0)" 0]

gdb_assert { $xlen != 0 && $flen != 0 } "read xlen and flen"

# We only handle 32-bit or 64-bit x-registers.
if { $xlen != 4 && $xlen != 8 } {
    unsupported "unknown x-register size"
    return -1
}

# If FLEN is 1 then the target doesn't have floating point support
# (the register $fa0 was not recognised).  Otherwise, we can only
# proceed if FLEN equals XLEN, otherwise we'd need more test XML
# files.
if { $flen != 1 && $flen != $xlen } {
    unsupport "unknown xlen/flen combination"
    return -1
}

if { $xlen == 4 } {
    set xml_tdesc "riscv-tdesc-regs-32.xml"
} else {
    set xml_tdesc "riscv-tdesc-regs-64.xml"
}
set xml_tdesc "${srcdir}/${subdir}/${xml_tdesc}"

# Maybe copy the target over if we're remote testing.
if {[is_remote host]} {
    set remote_file [remote_download host $xml_tdesc]
} else {
    set remote_file $xml_tdesc
}

gdb_test_no_output "set tdesc filename $remote_file" \
    "load the new target description"

# Check that an alias for an unknown CSR will give a suitable error.
gdb_test "info registers \$csr0" "Invalid register `csr0'"

# Return the number of times REGISTER should appear in GROUP, this
# will either be 0 or 1.
proc get_expected_result { register group } {

    # Everything should appear once in the 'all' group.
    if { $group == "all" || $group == "x_all" } {
	return 1
    }

    if { $group == "save" || $group == "restore" } {
	# Everything is in the save/restore groups except these two.
	if { $register == "unknown_csr" || $register == "dscratch" } {
	    return 0
	}
	return 1
    }

    if { $group == "system" || $group == "csr" } {
	# All the registers we check should be in these groups.
	return 1
    }

    return 0
}

foreach rgroup {x_all all save restore general system csr} {
    # Now use 'info registers all' to see how many times the floating
    # point status registers show up in the output.
    array set reg_counts {}
    if {$rgroup == "x_all"} {
	set test "info all-registers"
    } else {
	set test "info registers $rgroup"
    }
    gdb_test_multiple $test $test {
	-re ".*info registers all\r\n" {
	    verbose -log "Skip to first register"
	    exp_continue
	}
	-re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" {
	    set reg $expect_out(1,string)
	    incr reg_counts($reg)
	exp_continue
	}
	-re "^$gdb_prompt $" {
	    # Done.
	}
    }

    foreach reg {fflags frm fcsr unknown_csr dscratch} {
	if { [info exists reg_counts($reg) ] } {
	    set count $reg_counts($reg)
	} else {
	    set count 0
	}

	set expected_count [ get_expected_result $reg $rgroup ]
	gdb_assert {$count == $expected_count} \
	    "register $reg seen in reggroup $rgroup $expected_count times"
    }
    array unset reg_counts
}

# Next load a target description that contains fcsr, but not fflags or
# frm.  Then check that GDB provides an fflags and frm registers using
# the pseudo-register mechanism.
if { $xlen == 4 } {
    set xml_tdesc "riscv-tdesc-fcsr-32.xml"
} else {
    set xml_tdesc "riscv-tdesc-fcsr-64.xml"
}
set xml_tdesc "${srcdir}/${subdir}/${xml_tdesc}"

# Maybe copy the target over if we're remote testing.
if {[is_remote host]} {
    set remote_file [remote_download host $xml_tdesc]
} else {
    set remote_file $xml_tdesc
}

gdb_test_no_output "set tdesc filename $remote_file" \
    "load the target description that lacks fflags and frm"

foreach reg {fflags frm} {
    gdb_test_multiple "info registers $reg" "" {
	-re "^info registers $reg\r\n" {
	    exp_continue
	}

	-wrap -re "^Invalid register `$reg`" {
	    fail $gdb_test_name
	}

	-wrap -re "^$reg\\s+\[^\r\n\]+" {
	    pass $gdb_test_name
	}
    }
}