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