1# Copyright 2003-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 17# Tests for Powerpc E500 register setting and fetching 18 19# 20# Test the use of registers, especially E500 registers, for Powerpc. 21# This file uses e500-regs.c for input. 22# 23 24 25if {![istarget "powerpc-*eabispe"]} { 26 verbose "Skipping e500 register tests." 27 return 28} 29 30set testfile "e500-regs" 31set binfile ${objdir}/${subdir}/${testfile} 32set src1 ${srcdir}/${subdir}/${testfile}.c 33 34if { [gdb_compile ${src1} ${binfile} executable {debug nowarnings}] != "" } { 35 untested "failed to compile" 36 return -1 37} 38 39gdb_start 40gdb_reinitialize_dir $srcdir/$subdir 41gdb_load ${binfile} 42 43# 44# Run to `main' where we begin our tests. 45# 46 47if {![runto_main]} { 48 return 0 49} 50 51# set all the registers integer portions to 1 52for {set i 0} {$i < 32} {incr i 1} { 53 for {set j 0} {$j < 2} {incr j 1} { 54 gdb_test "set \$ev$i.v2_int32\[$j\] = 1" "" "set reg ev$i.v4si.f\[$j\]" 55 } 56} 57 58# Now execute some target code, so that GDB's register cache is flushed. 59 60#gdb_test "next" "" "" 61 62set endianness [get_endianness] 63 64# And then read the E500 registers back, to see that 65# a) the register write above worked, and 66# b) the register read (below) also works. 67 68if {$endianness == "big"} { 69set vector_register ".uint64 = 0x100000001, v2_float = .0x0, 0x0., v2_int32 = .0x1, 0x1., v4_int16 = .0x0, 0x1, 0x0, 0x1., v8_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.." 70} else { 71set vector_register ".uint64 = 0x100000001, v2_float = .0x0, 0x0., v2_int32 = .0x1, 0x1., v4_int16 = .0x1, 0x0, 0x1, 0x0., v8_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.." 72} 73 74for {set i 0} {$i < 32} {incr i 1} { 75 gdb_test "info reg ev$i" "ev$i.*$vector_register" "info reg ev$i" 76} 77 78# Test wether the GPRs are updated accordingly. (GPRs are just the lower 79# 32 bits of the EV registers.) 80 81set general_register "0x1\[ \t\]+1" 82 83for {set i 0} {$i < 32} {incr i 1} { 84 gdb_test "info reg r$i" "r$i.*$general_register" "info reg r$i" 85} 86 87# Now redo the same tests, but using the print command. 88 89if {$endianness == "big"} { 90 set decimal_vector ".uint64 = 4294967297, v2_float = .1.*e-45, 1.*e-45., v2_int32 = .1, 1., v4_int16 = .0, 1, 0, 1., v8_int8 = .0, 0, 0, 1, 0, 0, 0, 1.." 91} else { 92 set decimal_vector ".uint64 = 4294967297, v2_float = .1.*e-45, 1.*e-45., v2_int32 = .1, 1., v4_int16 = .1, 0, 1, 0., v8_int8 = .1, 0, 0, 0, 1, 0, 0, 0.." 93} 94 95for {set i 0} {$i < 32} {incr i 1} { 96 gdb_test "print \$ev$i" ".* = $decimal_vector" "print ev$i" 97} 98 99for {set i 0} {$i < 32} {incr i 1} { 100 set pattern$i ".*ev$i.*" 101 append pattern$i $vector_register 102} 103 104send_gdb "info vector\n" 105gdb_expect_list "info vector" ".*$gdb_prompt $" { 106[$pattern0] 107[$pattern1] 108[$pattern2] 109[$pattern3] 110[$pattern4] 111[$pattern5] 112[$pattern6] 113[$pattern7] 114[$pattern8] 115[$pattern9] 116[$pattern10] 117[$pattern11] 118[$pattern12] 119[$pattern13] 120[$pattern14] 121[$pattern15] 122[$pattern16] 123[$pattern17] 124[$pattern18] 125[$pattern19] 126[$pattern20] 127[$pattern21] 128[$pattern22] 129[$pattern23] 130[$pattern24] 131[$pattern25] 132[$pattern26] 133[$pattern27] 134[$pattern28] 135[$pattern29] 136[$pattern30] 137[$pattern31] 138} 139 140# We must restart everything, because we have set important registers to 141# some unusual values. 142 143gdb_exit 144gdb_start 145gdb_reinitialize_dir $srcdir/$subdir 146gdb_load ${binfile} 147if {![runto_main]} { 148 return 0 149} 150 151gdb_test "break vector_fun" \ 152 "Breakpoint 2 at.*e500-regs.c, line \[0-9\]+\\." \ 153 "set breakpoint at vector_fun" 154 155# Actually it is nuch easier to see these results printed in hex. 156# gdb_test "set output-radix 16" \ 157# "Output radix now set to decimal 16, hex 10, octal 20." \ 158# "set output radix to hex" 159 160gdb_test "continue" \ 161 "Breakpoint 2, vector_fun .a=.-2, -2., b=.1, 1.*e500-regs.c.*ev_create_s32 .2, 2.;" \ 162 "continue to vector_fun" 163 164# Do a next over the assignment to vector 'a'. 165gdb_test "next" ".*b = \\(vector int\\) __ev_create_s32 \\(3, 3\\);" \ 166 "next (1)" 167 168# Do a next over the assignment to vector 'b'. 169gdb_test "next" "c = __ev_and \\(a, b\\);" \ 170 "next (2)" 171 172# Now 'a' should be '0x02020202...' and 'b' should be '0x03030303...' 173gdb_test "print/x a" \ 174 ".*= .0x2, 0x2." \ 175 "print vector parameter a" 176 177gdb_test "print/x b" \ 178 ".*= .0x3, 0x3." \ 179 "print vector parameter b" 180 181# If we do an 'up' now, and print 'x' and 'y' we should see the values they 182# have in main, not the values they have in vector_fun. 183gdb_test "up" ".1.*main \\(\\) at.*e500-regs.c.*z = vector_fun \\(x, y\\);" \ 184 "up to main" 185 186gdb_test "print x" \ 187 ".*= .-2, -2." \ 188 "print vector x" 189 190gdb_test "print y" \ 191 ".*= .1, 1." \ 192 "print vector y" 193 194# now go back to vector_func and do a finish, to see if we can print the return 195# value correctly. 196 197gdb_test "down" \ 198 ".0 vector_fun \\(a=.2, 2., b=.3, 3.\\) at.*e500-regs.c.*c = __ev_and \\(a, b\\);" \ 199 "down to vector_fun" 200 201gdb_test "finish" \ 202 "Run till exit from .0 vector_fun \\(a=.2, 2., b=.3, 3.\\) at.*e500-regs.c.*main \\(\\) at.*e500-regs.c.*z = vector_fun \\(x, y\\);.*Value returned is.*= .2, 2." \ 203 "finish returned correct value" 204 205 206 207