Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 2009-2015 Free Software Foundation, Inc. |
79d0a52d UW |
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 | # Contributed by Markus Deuling <deuling@de.ibm.com>. | |
17 | # | |
18 | # Support library for testing the combined debugger for Linux | |
19 | # on the Cell Broadband Engine. | |
20 | ||
21 | # Compile SPU objects. | |
22 | proc gdb_compile_cell_spu {source dest type options} { | |
23 | global board | |
24 | ||
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" | |
30 | ||
31 | set options_spu [concat $options [list compiler=spu-gcc]] | |
32 | set ccout [gdb_compile $source $dest $type $options_spu] | |
33 | ||
34 | set_board_info multilib_flags $save_multilib_flag | |
35 | return $ccout | |
36 | } | |
37 | ||
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] | |
46 | } | |
47 | ||
48 | # Embed SPU executable into a PPU object. | |
49 | proc gdb_cell_embedspu {source dest options} { | |
50 | global CC_FOR_TARGET | |
51 | ||
52 | if [info exists CC_FOR_TARGET] { | |
53 | set compiler $CC_FOR_TARGET | |
54 | } else { | |
55 | set compiler [board_info [target_info name] compiler] | |
56 | } | |
57 | ||
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 | |
61 | ||
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 | |
66 | ||
67 | set options_embed [concat $options [list compiler=$embedspu]] | |
68 | return [gdb_compile "$symbol $source $dest" "" none $options_embed] | |
69 | } | |
70 | ||
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. | |
17e1c970 | 73 | gdb_caching_proc skip_cell_tests { |
fda326dd | 74 | global srcdir subdir gdb_prompt inferior_exited_re |
79d0a52d | 75 | |
79d0a52d | 76 | set me "skip_cell_tests" |
79d0a52d UW |
77 | |
78 | # Set up, compile, and execute a combined Cell/B.E. test program. | |
79 | # Include the current process ID in the file names to prevent conflicts | |
80 | # with invocations for multiple testsuites. | |
16cfcbc2 TT |
81 | set src [standard_temp_file cell[pid].c] |
82 | set exe [standard_temp_file cell[pid].x] | |
83 | set src_spu [standard_temp_file cell[pid]-spu.c] | |
84 | set exe_spu [standard_temp_file cell[pid]-spu.x] | |
79d0a52d UW |
85 | |
86 | set f [open $src "w"] | |
87 | puts $f "#include <libspe2.h>" | |
88 | puts $f "extern spe_program_handle_t cell[pid]_spu_x;" | |
89 | puts $f "int main (void) {" | |
90 | puts $f "unsigned int entry = SPE_DEFAULT_ENTRY;" | |
91 | puts $f "spe_context_ptr_t ctx = spe_context_create (0, NULL);" | |
92 | puts $f "spe_program_load (ctx, &cell[pid]_spu_x);" | |
93 | puts $f "return spe_context_run (ctx, &entry, 0, NULL, NULL, NULL); }" | |
94 | close $f | |
95 | ||
96 | set f [open $src_spu "w"] | |
97 | puts $f "int main (void) { return 0; }" | |
98 | close $f | |
99 | ||
100 | verbose "$me: compiling testfile $src" 2 | |
101 | set compile_flags {debug nowarnings quiet} | |
102 | ||
a69b7d9d | 103 | set skip 0 |
79d0a52d UW |
104 | if { [gdb_compile_cell_spu $src_spu $exe_spu executable $compile_flags] != "" } { |
105 | verbose "$me: compiling spu binary failed, returning 1" 2 | |
a69b7d9d | 106 | set skip 1 |
79d0a52d | 107 | } |
a69b7d9d | 108 | if { ! $skip && [gdb_cell_embedspu $exe_spu $exe_spu-embed.o $compile_flags] != "" } { |
79d0a52d | 109 | verbose "$me: embedding spu binary failed, returning 1" 2 |
a69b7d9d | 110 | set skip 1 |
79d0a52d | 111 | } |
a69b7d9d | 112 | if { ! $skip && [gdb_compile_cell_ppu [list $src $exe_spu-embed.o] $exe executable $compile_flags] != "" } { |
79d0a52d | 113 | verbose "$me: compiling ppu binary failed, returning 1" 2 |
a69b7d9d | 114 | set skip 1 |
79d0a52d UW |
115 | } |
116 | file delete $src | |
117 | file delete $src_spu | |
118 | file delete $exe_spu | |
119 | file delete $exe_spu-embed.o | |
120 | ||
a69b7d9d | 121 | if { $skip } { |
17e1c970 | 122 | return 1 |
a69b7d9d DJ |
123 | } |
124 | ||
79d0a52d UW |
125 | # Compilation succeeded so now run it via gdb. |
126 | ||
127 | gdb_exit | |
128 | gdb_start | |
129 | gdb_reinitialize_dir $srcdir/$subdir | |
130 | gdb_load "$exe" | |
131 | gdb_run_cmd | |
132 | gdb_expect { | |
fda326dd | 133 | -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { |
79d0a52d | 134 | verbose -log "\n$me: Cell/B.E. hardware detected" |
17e1c970 | 135 | set result 0 |
79d0a52d | 136 | } |
fda326dd | 137 | -re ".*$inferior_exited_re with code.*${gdb_prompt} $" { |
79d0a52d | 138 | verbose -log "\n$me: Cell/B.E. hardware not detected" |
17e1c970 | 139 | set result 1 |
79d0a52d UW |
140 | } |
141 | default { | |
142 | verbose -log "\n$me Cell/B.E. hardware not detected (default case)" | |
17e1c970 | 143 | set result 1 |
79d0a52d UW |
144 | } |
145 | } | |
146 | gdb_exit | |
147 | remote_file build delete $exe | |
148 | ||
17e1c970 TT |
149 | verbose "$me: returning $result" 2 |
150 | return $result | |
79d0a52d UW |
151 | } |
152 | ||
153 | # Delete all breakpoints and stop on the next new SPU thread | |
154 | proc cont_spu_main { } { | |
155 | delete_breakpoints | |
156 | gdb_test "set spu stop-on-load on" | |
157 | gdb_test "continue" \ | |
158 | "Continuing.*Temporary breakpoint .*main .*" \ | |
159 | "continue to SPU main" | |
160 | } | |
161 | ||
162 | # Continue to MARKER | |
163 | proc c_to { marker srcfile } { | |
164 | set line [gdb_get_line_number $marker $srcfile] | |
165 | gdb_test "break $line" \ | |
166 | "Breakpoint.*at.*file.*$srcfile.*line $line.*" \ | |
167 | "break $line" | |
168 | gdb_test "continue" \ | |
169 | "Continuing.*Breakpoint.*at.*$srcfile.*$line.*" \ | |
170 | "continue to $line" | |
171 | } | |
172 | ||
173 | # Check if the current thread has SPU architecture | |
174 | proc check_spu_arch { msg } { | |
175 | if { $msg == "" } { | |
176 | set msg "spu architecture is spu256K" | |
177 | } | |
178 | gdb_test "show architecture" \ | |
179 | "The target architecture is set automatically.*currently spu:256K.*" \ | |
180 | $msg | |
181 | } |