OSDN Git Service

2012-01-16 Pedro Alves <palves@redhat.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.arch / altivec-regs.exp
1 # Copyright (C) 2002-2003, 2005, 2007-2012 Free Software Foundation,
2 # Inc.
3
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.
8 #
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.
13 #
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/>.
16 #
17
18 # Tests for Powerpc AltiVec register setting and fetching
19
20 #
21 # Test the use of registers, especially AltiVec registers, for Powerpc.
22 # This file uses altivec-regs.c for input.
23 #
24
25
26 if {![istarget "powerpc*"] || [skip_altivec_tests]} then {
27     verbose "Skipping altivec register tests."
28     return
29 }
30
31 set testfile "altivec-regs"
32 set binfile ${objdir}/${subdir}/${testfile}
33 set srcfile ${testfile}.c
34
35 set compile_flags {debug nowarnings}
36 if [get_compiler_info $binfile] {
37     warning "get_compiler failed"
38     return -1
39 }
40
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"
45 } else {
46     warning "unknown compiler"
47     return -1
48 }
49
50 if  { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $compile_flags] != "" } {
51      untested altivec-regs.exp
52      return -1
53 }
54
55 gdb_start
56 gdb_reinitialize_dir $srcdir/$subdir
57 gdb_load ${binfile}
58
59 #
60 # Run to `main' where we begin our tests.
61 #
62
63 if ![runto_main] then {
64     gdb_suppress_tests
65 }
66
67 gdb_test "set print frame-arguments all"
68
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\]"
73         }
74 }
75
76 gdb_test "set \$vscr = 1" "" ""
77 gdb_test "set \$vrsave = 1" "" ""
78
79 # Now execute some target code, so that GDB's register cache is flushed.
80
81 gdb_test "next" "" ""
82
83 send_gdb "show endian\n"
84 set endianness ""
85 gdb_expect {
86     -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" {
87         pass "endianness"
88         set endianness $expect_out(2,string)
89     }
90     -re ".*$gdb_prompt $" {
91         fail "couldn't get endianness"
92     }
93     timeout             { fail "(timeout) endianness" }
94 }
95
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.
99
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.."
102 } else {
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.."
104 }
105
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"
108 }
109
110 gdb_test "info reg vrsave" "vrsave.*0x1\t1" "info reg vrsave"
111 gdb_test "info reg vscr" "vscr.*0x1\t1" "info reg vscr"
112
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
117 # the way gdb works.
118
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.."
121 } else {
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.."
123 }
124
125 for {set i 0} {$i < 32} {incr i 1} {
126         gdb_test "print \$vr$i" ".* = $decimal_vector" "print vr$i"
127 }
128
129 gdb_test "print \$vrsave" ".* = 1" "print vrsave"
130 gdb_test "print \$vscr" ".* = 1" "print vscr"
131
132 for {set i 0} {$i < 32} {incr i 1} {
133          set pattern$i ".*vr$i.*"
134          append pattern$i $vector_register
135 }
136
137 send_gdb "info vector\n"
138 gdb_expect_list "info vector" ".*$gdb_prompt $" {
139 [$pattern0]
140 [$pattern1]
141 [$pattern2]
142 [$pattern3]
143 [$pattern4]
144 [$pattern5]
145 [$pattern6]
146 [$pattern7]
147 [$pattern8]
148 [$pattern9]
149 [$pattern10]
150 [$pattern11]
151 [$pattern12]
152 [$pattern13]
153 [$pattern14]
154 [$pattern15]
155 [$pattern16]
156 [$pattern17]
157 [$pattern18]
158 [$pattern19]
159 [$pattern20]
160 [$pattern21]
161 [$pattern22]
162 [$pattern23]
163 [$pattern24]
164 [$pattern25]
165 [$pattern26]
166 [$pattern27]
167 [$pattern28]
168 [$pattern29]
169 [$pattern30]
170 [$pattern31]
171 "\[ \t\n\r\]+vscr\[ \t\]+0x1"
172 "\[ \t\n\r\]+vrsave\[ \t\]+0x1"
173 }
174
175 gdb_test "break vector_fun" \
176  "Breakpoint 2 at.*altivec-regs.c, line \[0-9\]+\\." \
177  "Set breakpoint at vector_fun"
178
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"
183
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"
187
188 # Do a next over the assignment to vector 'a'. 
189 gdb_test "next" ".*b = \\(\\(vector unsigned int\\) vec_splat_u8\\(3\\)\\);" \
190   "next (1)"
191
192 # Do a next over the assignment to vector 'b'. 
193 gdb_test "next" "c = vec_add \\(a, b\\);" \
194   "next (2)"
195
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"
200
201 gdb_test "print/x b" \
202   ".*= .0x3030303, 0x3030303, 0x3030303, 0x3030303." \
203   "print vector parameter b"
204
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\\);" \
208   "up to main"
209
210 gdb_test "print/x x" \
211   ".*= .0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe." \
212   "print vector x"
213
214 gdb_test "print/x y" \
215   ".*= .0x1010101, 0x1010101, 0x1010101, 0x1010101." \
216   "print vector y"
217
218 # now go back to vector_func and do a finish, to see if we can print the return
219 # value correctly.
220
221 gdb_test "down" \
222   ".0  vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*c = vec_add \\(a, b\\);" \
223   "down to vector_fun"
224
225 gdb_test "finish" \
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"
228
229
230