165f61a194a5ded4435a795176b3b8035f1b1b58
[external/binutils.git] / gdb / testsuite / gdb.arch / altivec-regs.exp
1 # Copyright (C) 2002-2017 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 AltiVec register setting and fetching
18
19 #
20 # Test the use of registers, especially AltiVec registers, for Powerpc.
21 # This file uses altivec-regs.c for input.
22 #
23
24
25 if {![istarget "powerpc*"] || [skip_altivec_tests]} then {
26     verbose "Skipping altivec register tests."
27     return
28 }
29
30 standard_testfile
31
32 set compile_flags {debug nowarnings}
33 if [get_compiler_info] {
34     warning "get_compiler failed"
35     return -1
36 }
37
38 if [test_compiler_info gcc*] {
39     set compile_flags "$compile_flags additional_flags=-maltivec additional_flags=-mabi=altivec"
40 } elseif [test_compiler_info xlc*] {
41     set compile_flags "$compile_flags additional_flags=-qaltivec"
42 } else {
43     warning "unknown compiler"
44     return -1
45 }
46
47 if  { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $compile_flags] != "" } {
48      untested "failed to compile"
49      return -1
50 }
51
52 gdb_start
53 gdb_reinitialize_dir $srcdir/$subdir
54 gdb_load ${binfile}
55
56 #
57 # Run to `main' where we begin our tests.
58 #
59
60 if ![runto_main] then {
61     gdb_suppress_tests
62 }
63
64 gdb_test "set print frame-arguments all"
65
66 # set all the registers integer portions to 1
67 for {set i 0} {$i < 32} {incr i 1} {
68         for {set j 0} {$j < 4} {incr j 1} {
69            gdb_test "set \$vr$i.v4_int32\[$j\] = 1" "" "set reg vr$i.v4si.f\[$j\]"
70         }
71 }
72
73 gdb_test "set \$vscr = 1" "" ""
74 gdb_test "set \$vrsave = 1" "" ""
75
76 # Now execute some target code, so that GDB's register cache is flushed.
77
78 gdb_test "next" "" ""
79
80 set endianness [get_endianness]
81
82 # And then read the AltiVec registers back, to see that
83 # a) the register write above worked, and
84 # b) the register read (below) also works.
85
86 if {$endianness == "big"} {
87 set vector_register ".uint128 = 0x1000000010000000100000001, 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.."
88 } else {
89 set vector_register ".uint128 = 0x1000000010000000100000001, 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.."
90 }
91
92 for {set i 0} {$i < 32} {incr i 1} {
93         gdb_test "info reg vr$i" "vr$i.*$vector_register" "info reg vr$i"
94 }
95
96 gdb_test "info reg vrsave" "vrsave.*0x1\t1" "info reg vrsave"
97 gdb_test "info reg vscr" "vscr.*0x1\t1" "info reg vscr"
98
99 # Now redo the same tests, but using the print command.
100 # Note: in LE case, the char array is printed WITHOUT the last character.
101 # Gdb treats the terminating null char in the array like the terminating
102 # null char in a string and doesn't print it. This is not a failure, but
103 # the way gdb works.
104
105 if {$endianness == "big"} {
106      set decimal_vector ".uint128 = 79228162532711081671548469249, 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.."
107 } else {
108      set decimal_vector ".uint128 = 79228162532711081671548469249, 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, 0.."
109 }
110
111 for {set i 0} {$i < 32} {incr i 1} {
112         gdb_test "print \$vr$i" ".* = $decimal_vector" "print vr$i"
113 }
114
115 gdb_test "print \$vrsave" ".* = 1" "print vrsave"
116 gdb_test "print \$vscr" ".* = 1" "print vscr"
117
118 for {set i 0} {$i < 32} {incr i 1} {
119          set pattern$i ".*vr$i.*"
120          append pattern$i $vector_register
121 }
122
123 send_gdb "info vector\n"
124 gdb_expect_list "info vector" ".*$gdb_prompt $" {
125 [$pattern0]
126 [$pattern1]
127 [$pattern2]
128 [$pattern3]
129 [$pattern4]
130 [$pattern5]
131 [$pattern6]
132 [$pattern7]
133 [$pattern8]
134 [$pattern9]
135 [$pattern10]
136 [$pattern11]
137 [$pattern12]
138 [$pattern13]
139 [$pattern14]
140 [$pattern15]
141 [$pattern16]
142 [$pattern17]
143 [$pattern18]
144 [$pattern19]
145 [$pattern20]
146 [$pattern21]
147 [$pattern22]
148 [$pattern23]
149 [$pattern24]
150 [$pattern25]
151 [$pattern26]
152 [$pattern27]
153 [$pattern28]
154 [$pattern29]
155 [$pattern30]
156 [$pattern31]
157 "\[ \t\n\r\]+vscr\[ \t\]+0x1"
158 "\[ \t\n\r\]+vrsave\[ \t\]+0x1"
159 }
160
161 gdb_test "break vector_fun" \
162  "Breakpoint 2 at.*altivec-regs.c, line \[0-9\]+\\." \
163  "set breakpoint at vector_fun"
164
165 # Actually it is nuch easier to see these results printed in hex.
166 gdb_test "set output-radix 16" \
167   "Output radix now set to decimal 16, hex 10, octal 20." \
168   "set output radix to hex"
169
170 gdb_test "continue" \
171   "Breakpoint 2, vector_fun .a=.0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe., b=.0x1010101, 0x1010101, 0x1010101, 0x1010101.*altivec-regs.c.*vec_splat_u8.2..;" \
172   "continue to vector_fun"
173
174 # Do a next over the assignment to vector 'a'. 
175 gdb_test "next" ".*b = \\(\\(vector unsigned int\\) vec_splat_u8\\(3\\)\\);" \
176   "next (1)"
177
178 # Do a next over the assignment to vector 'b'. 
179 gdb_test "next" "c = vec_add \\(a, b\\);" \
180   "next (2)"
181
182 # Now 'a' should be '0x02020202...' and 'b' should be '0x03030303...'
183 gdb_test "print/x a" \
184   ".*= .0x2020202, 0x2020202, 0x2020202, 0x2020202." \
185   "print vector parameter a"
186
187 gdb_test "print/x b" \
188   ".*= .0x3030303, 0x3030303, 0x3030303, 0x3030303." \
189   "print vector parameter b"
190
191 # If we do an 'up' now, and print 'x' and 'y' we should see the values they
192 # have in main, not the values they have in vector_fun.
193 gdb_test "up" ".1.*main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);" \
194   "up to main"
195
196 gdb_test "print/x x" \
197   ".*= .0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe." \
198   "print vector x"
199
200 gdb_test "print/x y" \
201   ".*= .0x1010101, 0x1010101, 0x1010101, 0x1010101." \
202   "print vector y"
203
204 # now go back to vector_func and do a finish, to see if we can print the return
205 # value correctly.
206
207 gdb_test "down" \
208   ".0  vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*c = vec_add \\(a, b\\);" \
209   "down to vector_fun"
210
211 gdb_test "finish" \
212   "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." \
213   "finish returned correct value"
214
215
216