1# Copyright 2021-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# Check the size of the $pc register as the user changes the selected
17# architecture.  As no executable is provided then the size of the $pc
18# register is defined by the default target description selected by
19# GDB.
20#
21# This test ensures that GDB is selecting an RV32 default if the user
22# has forced the current architecture to be riscv:rv32.
23#
24# In all other cases the default will be RV64.
25
26if {![istarget "riscv*-*-*"]} {
27    verbose "Skipping ${gdb_test_file_name}."
28    return
29}
30
31# Start GDB with no executable.
32gdb_start
33
34# The tests are defined by a list of architecture names to switch too
35# and the expected size of $pc.  The first list entry is special and
36# has an empty architecture string, this checks GDB's default value on
37# startup.
38foreach data {{"" 8} {"riscv:rv32" 4} {"riscv:rv64" 8} {"riscv" 8} \
39		  {"auto" 8}} {
40    set arch [lindex $data 0]
41    set size [lindex $data 1]
42
43    # Switch architecture.
44    if { $arch != "" && $arch != "auto" } {
45	gdb_test "set architecture $arch" \
46	    "The target architecture is set to \"$arch\"\\."
47    } elseif { $arch == "auto" } {
48	gdb_test "set architecture $arch" \
49	    "The target architecture is set to \"auto\" \\(currently \"riscv\"\\)\\."
50    } else {
51	set arch "default architecture"
52    }
53
54    # Check the size of $pc.
55    with_test_prefix "$arch" {
56	gdb_test "p sizeof (\$pc)" " = $size" \
57	    "size of \$pc register is $size"
58    }
59}
60