1# Copyright (C) 2018-2020 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# This file is part of the gdb testsuite. 17 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 23# register. 24 25if {![istarget "powerpc*-*-linux*"]} then { 26 verbose "Skipping PowerPC test for the TAR register." 27 return 28} 29 30standard_testfile .c 31 32if {[build_executable "compile" $binfile $srcfile {debug}] == -1} { 33 return -1 34} 35 36proc check_register_access { regname } { 37 global gdb_prompt 38 39 set test "$regname register access" 40 gdb_test_multiple "info reg $regname" "$test" { 41 -re "Invalid register.*\r\n$gdb_prompt $" { 42 unsupported "$test" 43 return 0 44 } 45 -re "\r\n$regname.*\r\n$gdb_prompt $" { 46 pass "$test" 47 return 1 48 } 49 } 50 return 0 51} 52 53proc tar_available {} { 54 global gdb_prompt 55 global inferior_exited_re 56 57 set test "TAR available to inferior" 58 gdb_test_multiple "continue" "" { 59 -re "Illegal instruction.*\r\n$gdb_prompt $" { 60 unsupported "$test" 61 return 0 62 } 63 -re "$inferior_exited_re normally.*$gdb_prompt $" { 64 pass "$test" 65 return 1 66 } 67 } 68 return 0 69} 70 71# Do one pass to check if TAR is usable, system 72# software can prevent it from being used. 73with_test_prefix "check TAR access" { 74 clean_restart $binfile 75 76 if ![runto_main] { 77 return 78 } 79 80 if {![check_register_access "tar"]} { 81 return 82 } 83 84 if {![tar_available]} { 85 return 86 } 87} 88 89# Now do the actual test 90clean_restart $binfile 91 92if ![runto_main] { 93 return 94} 95 96gdb_breakpoint [gdb_get_line_number "marker"] 97 98gdb_continue_to_breakpoint "continue to marker" 99 100set target1 [get_hexadecimal_valueof "target1" -1] 101set tar [get_hexadecimal_valueof "\$tar" -2] 102 103set test "TAR value from mtspr" 104 105if {${target1} == ${tar}} { 106 pass $test 107} else { 108 fail $test 109} 110 111set target2 [get_hexadecimal_valueof "target2" -1] 112 113if {$target2 == -1} { 114 fail "Could not get value of target2" 115 return 116} 117 118gdb_test_no_output "set \$tar = $target2" "set tar" 119 120gdb_breakpoint [gdb_get_line_number "marker 2"] 121 122gdb_continue_to_breakpoint "continue to new target address" ".*marker 2.*" 123