1 # Copyright (C) 2002-2003, 2005, 2007-2012 Free Software Foundation,
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Tests for Powerpc AltiVec register setting and fetching
21 # Test the use of registers, especially AltiVec registers, for Powerpc.
22 # This file uses altivec-regs.c for input.
26 if {![istarget "powerpc*"] || [skip_altivec_tests]} then {
27 verbose "Skipping altivec register tests."
31 set testfile "altivec-regs"
32 set binfile ${objdir}/${subdir}/${testfile}
33 set srcfile ${testfile}.c
35 set compile_flags {debug nowarnings}
36 if [get_compiler_info] {
37 warning "get_compiler failed"
41 if [test_compiler_info gcc*] {
42 set compile_flags "$compile_flags additional_flags=-maltivec additional_flags=-mabi=altivec"
43 } elseif [test_compiler_info xlc*] {
44 set compile_flags "$compile_flags additional_flags=-qaltivec"
46 warning "unknown compiler"
50 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $compile_flags] != "" } {
51 untested altivec-regs.exp
56 gdb_reinitialize_dir $srcdir/$subdir
60 # Run to `main' where we begin our tests.
63 if ![runto_main] then {
67 gdb_test "set print frame-arguments all"
69 # set all the registers integer portions to 1
70 for {set i 0} {$i < 32} {incr i 1} {
71 for {set j 0} {$j < 4} {incr j 1} {
72 gdb_test "set \$vr$i.v4_int32\[$j\] = 1" "" "set reg vr$i.v4si.f\[$j\]"
76 gdb_test "set \$vscr = 1" "" ""
77 gdb_test "set \$vrsave = 1" "" ""
79 # Now execute some target code, so that GDB's register cache is flushed.
83 send_gdb "show endian\n"
86 -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" {
88 set endianness $expect_out(2,string)
90 -re ".*$gdb_prompt $" {
91 fail "couldn't get endianness"
93 timeout { fail "(timeout) endianness" }
96 # And then read the AltiVec registers back, to see that
97 # a) the register write above worked, and
98 # b) the register read (below) also works.
100 if {$endianness == "big"} {
101 set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.."
103 set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.."
106 for {set i 0} {$i < 32} {incr i 1} {
107 gdb_test "info reg vr$i" "vr$i.*$vector_register" "info reg vr$i"
110 gdb_test "info reg vrsave" "vrsave.*0x1\t1" "info reg vrsave"
111 gdb_test "info reg vscr" "vscr.*0x1\t1" "info reg vscr"
113 # Now redo the same tests, but using the print command.
114 # Note: in LE case, the char array is printed WITHOUT the last character.
115 # Gdb treats the terminating null char in the array like the terminating
116 # null char in a string and doesn't print it. This is not a failure, but
119 if {$endianness == "big"} {
120 set decimal_vector ".uint128 = 0x00000001000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .0, 1, 0, 1, 0, 1, 0, 1., v16_int8 = .0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1.."
122 set decimal_vector ".uint128 = 0x00000001000000010000000100000001, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .1, 0, 1, 0, 1, 0, 1, 0., v16_int8 = .1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.."
125 for {set i 0} {$i < 32} {incr i 1} {
126 gdb_test "print \$vr$i" ".* = $decimal_vector" "print vr$i"
129 gdb_test "print \$vrsave" ".* = 1" "print vrsave"
130 gdb_test "print \$vscr" ".* = 1" "print vscr"
132 for {set i 0} {$i < 32} {incr i 1} {
133 set pattern$i ".*vr$i.*"
134 append pattern$i $vector_register
137 send_gdb "info vector\n"
138 gdb_expect_list "info vector" ".*$gdb_prompt $" {
171 "\[ \t\n\r\]+vscr\[ \t\]+0x1"
172 "\[ \t\n\r\]+vrsave\[ \t\]+0x1"
175 gdb_test "break vector_fun" \
176 "Breakpoint 2 at.*altivec-regs.c, line \[0-9\]+\\." \
177 "Set breakpoint at vector_fun"
179 # Actually it is nuch easier to see these results printed in hex.
180 gdb_test "set output-radix 16" \
181 "Output radix now set to decimal 16, hex 10, octal 20." \
182 "Set output radix to hex"
184 gdb_test "continue" \
185 "Breakpoint 2, vector_fun .a=.0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe., b=.0x1010101, 0x1010101, 0x1010101, 0x1010101.*altivec-regs.c.*vec_splat_u8.2..;" \
186 "continue to vector_fun"
188 # Do a next over the assignment to vector 'a'.
189 gdb_test "next" ".*b = \\(\\(vector unsigned int\\) vec_splat_u8\\(3\\)\\);" \
192 # Do a next over the assignment to vector 'b'.
193 gdb_test "next" "c = vec_add \\(a, b\\);" \
196 # Now 'a' should be '0x02020202...' and 'b' should be '0x03030303...'
197 gdb_test "print/x a" \
198 ".*= .0x2020202, 0x2020202, 0x2020202, 0x2020202." \
199 "print vector parameter a"
201 gdb_test "print/x b" \
202 ".*= .0x3030303, 0x3030303, 0x3030303, 0x3030303." \
203 "print vector parameter b"
205 # If we do an 'up' now, and print 'x' and 'y' we should see the values they
206 # have in main, not the values they have in vector_fun.
207 gdb_test "up" ".1.*main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);" \
210 gdb_test "print/x x" \
211 ".*= .0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe." \
214 gdb_test "print/x y" \
215 ".*= .0x1010101, 0x1010101, 0x1010101, 0x1010101." \
218 # now go back to vector_func and do a finish, to see if we can print the return
222 ".0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*c = vec_add \\(a, b\\);" \
226 "Run till exit from .0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*in main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);.*Value returned is.*= .0x5050505, 0x5050505, 0x5050505, 0x5050505." \
227 "finish returned correct value"