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