1 # Copyright 2009 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Contributed by Markus Deuling <deuling@de.ibm.com>.
18 # Support library for testing the combined debugger for Linux
19 # on the Cell Broadband Engine.
21 # Compile SPU objects.
22 proc gdb_compile_cell_spu {source dest type options} {
25 # Save and unset multilib flags; these are not appropriate
26 # for the SPU compiler.
27 set board [target_info name]
28 set save_multilib_flag [board_info $board multilib_flags]
29 unset_board_info "multilib_flags"
31 set options_spu [concat $options [list compiler=spu-gcc]]
32 set ccout [gdb_compile $source $dest $type $options_spu]
34 set_board_info multilib_flags $save_multilib_flag
38 # Compile PPU objects. This is just like gdb_compile_pthreads, except that we
39 # always add the libspe2 library for compiling Cell/B.E. programs.
40 proc gdb_compile_cell_ppu {source dest type options} {
41 # We do not need to try multiple names for the pthread library
42 # -lpthread works on all Cell/B.E. systems
43 set lib "-lspe2 -lpthread"
44 set options_ppu [concat $options [list libs=$lib]]
45 return [gdb_compile $source $dest $type $options_ppu]
48 # Embed SPU executable into a PPU object.
49 proc gdb_cell_embedspu {source dest options} {
52 if [info exists CC_FOR_TARGET] {
53 set compiler $CC_FOR_TARGET
55 set compiler [board_info [target_info name] compiler]
58 # We assume the PPU compiler is called gcc or ppu-gcc,
59 # and find the appropriate embedspu based on that.
60 regsub gcc "$compiler" embedspu embedspu
62 # Determine default embedded symbol name from source filename.
63 set path [split "$source" /]
64 set filename [lindex $path [expr [llength $path] - 1]]
65 regsub -all -- "\[-\.\]" "$filename" "_" symbol
67 set options_embed [concat $options [list compiler=$embedspu]]
68 return [gdb_compile "$symbol $source $dest" "" none $options_embed]
71 # Run a test on the target to see if it supports Cell/B.E. hardware.
72 # Return 0 if so, 1 if it does not.
73 proc skip_cell_tests {} {
74 global skip_cell_tests_saved
75 global srcdir subdir gdb_prompt
77 # Use the cached value, if it exists.
78 set me "skip_cell_tests"
79 if [info exists skip_cell_tests_saved] {
80 verbose "$me: returning saved $skip_cell_tests_saved" 2
81 return $skip_cell_tests_saved
84 # Set up, compile, and execute a combined Cell/B.E. test program.
85 # Include the current process ID in the file names to prevent conflicts
86 # with invocations for multiple testsuites.
89 set src_spu cell[pid]-spu.c
90 set exe_spu cell[pid]-spu.x
93 puts $f "#include <libspe2.h>"
94 puts $f "extern spe_program_handle_t cell[pid]_spu_x;"
95 puts $f "int main (void) {"
96 puts $f "unsigned int entry = SPE_DEFAULT_ENTRY;"
97 puts $f "spe_context_ptr_t ctx = spe_context_create (0, NULL);"
98 puts $f "spe_program_load (ctx, &cell[pid]_spu_x);"
99 puts $f "return spe_context_run (ctx, &entry, 0, NULL, NULL, NULL); }"
102 set f [open $src_spu "w"]
103 puts $f "int main (void) { return 0; }"
106 verbose "$me: compiling testfile $src" 2
107 set compile_flags {debug nowarnings quiet}
109 if { [gdb_compile_cell_spu $src_spu $exe_spu executable $compile_flags] != "" } {
110 verbose "$me: compiling spu binary failed, returning 1" 2
111 return [set skip_cell_tests_saved 1]
113 if { [gdb_cell_embedspu $exe_spu $exe_spu-embed.o $compile_flags] != "" } {
114 verbose "$me: embedding spu binary failed, returning 1" 2
115 return [set skip_cell_tests_saved 1]
117 if { [gdb_compile_cell_ppu [list $src $exe_spu-embed.o] $exe executable $compile_flags] != "" } {
118 verbose "$me: compiling ppu binary failed, returning 1" 2
119 return [set skip_cell_tests_saved 1]
124 file delete $exe_spu-embed.o
126 # Compilation succeeded so now run it via gdb.
130 gdb_reinitialize_dir $srcdir/$subdir
134 -re ".*Program exited normally.*${gdb_prompt} $" {
135 verbose -log "\n$me: Cell/B.E. hardware detected"
136 set skip_cell_tests_saved 0
138 -re ".*Program exited with code.*${gdb_prompt} $" {
139 verbose -log "\n$me: Cell/B.E. hardware not detected"
140 set skip_cell_tests_saved 1
143 verbose -log "\n$me Cell/B.E. hardware not detected (default case)"
144 set skip_cell_tests_saved 1
148 remote_file build delete $exe
150 verbose "$me: returning $skip_cell_tests_saved" 2
151 return $skip_cell_tests_saved
154 # Delete all breakpoints and stop on the next new SPU thread
155 proc cont_spu_main { } {
157 gdb_test "set spu stop-on-load on"
158 gdb_test "continue" \
159 "Continuing.*Temporary breakpoint .*main .*" \
160 "continue to SPU main"
164 proc c_to { marker srcfile } {
165 set line [gdb_get_line_number $marker $srcfile]
166 gdb_test "break $line" \
167 "Breakpoint.*at.*file.*$srcfile.*line $line.*" \
169 gdb_test "continue" \
170 "Continuing.*Breakpoint.*at.*$srcfile.*$line.*" \
174 # Check if the current thread has SPU architecture
175 proc check_spu_arch { msg } {
177 set msg "spu architecture is spu256K"
179 gdb_test "show architecture" \
180 "The target architecture is set automatically.*currently spu:256K.*" \