1 # Copyright (C) 2018-2024 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 # This file is part of the gdb testsuite.
18 # Test access to special purpose register TAR (the Target Address
19 # Register). The test inferior writes to this register, we check that
20 # GDB reads the same value, then write to the register the address of
21 # another label. We then let the inferior continue and execute a
22 # branch to TAR and check that we stop at the address that we wrote to
25 require {istarget "powerpc*-*-linux*"}
29 if {[build_executable "compile" $binfile $srcfile {debug}] == -1} {
33 proc check_register_access { regname } {
36 set test "$regname register access"
37 gdb_test_multiple "info reg $regname" "$test" {
38 -re "Invalid register.*\r\n$gdb_prompt $" {
42 -re "\r\n$regname.*\r\n$gdb_prompt $" {
50 proc tar_available {} {
52 global inferior_exited_re
54 set test "TAR available to inferior"
55 gdb_test_multiple "continue" "" {
56 -re "Illegal instruction.*\r\n$gdb_prompt $" {
60 -re "$inferior_exited_re normally.*$gdb_prompt $" {
68 # Do one pass to check if TAR is usable, system
69 # software can prevent it from being used.
70 with_test_prefix "check TAR access" {
71 clean_restart $binfile
77 if {![check_register_access "tar"]} {
81 if {![tar_available]} {
86 # Now do the actual test
87 clean_restart $binfile
93 gdb_breakpoint [gdb_get_line_number "marker"]
95 gdb_continue_to_breakpoint "continue to marker"
97 set target1 [get_hexadecimal_valueof "target1" -1]
98 set tar [get_hexadecimal_valueof "\$tar" -2]
100 set test "TAR value from mtspr"
102 if {${target1} == ${tar}} {
108 set target2 [get_hexadecimal_valueof "target2" -1]
110 if {$target2 == -1} {
111 fail "Could not get value of target2"
115 gdb_test_no_output "set \$tar = $target2" "set tar"
117 gdb_breakpoint [gdb_get_line_number "marker 2"]
119 gdb_continue_to_breakpoint "continue to new target address" ".*marker 2.*"