Update version numbers for continued development
[dejagnu.git] / baseboards / qemu.exp
blob193a7597c5cfec5a07e30e1f4bd3a826ac7c1d64
2 # Copyright (C) 2020 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # 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.
9 # DejaGnu is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with DejaGnu; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
18 # load_base_board_description "gdbserver-support"
20 set qemu ""
21 set spec ""
23 # No multilib flags needed by default.
24 process_multilib_options ""
26 set_board_info compiler [find_gcc]
28 # When testing GCC in tree, the libgloss linker scripts files aren't
29 # usually in a known location, so we have to find them in the sysroot.
30 # FIXME: this may change in the near future, but for now it works.
31 set compiler "[find_gcc]"
32 set ret [local_exec "$compiler --print-sysroot" "" "" $timeout]
33 if { [lindex $ret 0] == 0 } {
34 set sysroot "[lindex $ret 1]"
35 # Strip the CR or LF off the end of the line as returned by GCC
36 regsub -all "\[\n\r\]+" $sysroot "" sysroot
38 # set library path environment variable for qemu
39 set env(QEMU_LD_PREFIX) $sysroot
41 # Define ld_library_path variable to workaround asan and go testsuites
42 # referring to it
43 set ld_library_path ""
45 # In the beginning, only linker scripts were used to produce a fully
46 # linked executable. Then a better solution of having GCC spec file
47 # "patches" worked much better. None of the ARM/AARCH64 target
48 # use linker scripts, some targets support both, some just the
49 # linker script.
50 set ldscripts [ glob -nocomplain $sysroot/usr/lib/*.ld ]
51 if { [string length $ldscripts] == 0 } {
52 warning "No linker scripts found."
54 set specfiles [ glob -nocomplain $sysroot/usr/lib/*.specs ]
55 if { [string length $specfiles] == 0 } {
56 warning "No spec files found."
57 } else {
58 # FIXME: For now, both ldscripts and specfiles are ignored, and a
59 # single value is used tor testing.
60 foreach spec $specfiles {
61 verbose "Found spec file $spec"
65 # The basic set of flags needed to build "hello world" for this
66 # board. This board uses libgloss and newlib.
67 case "$target_triplet" in {
68 { "armeb-*-eabi*" } {
69 set qemu "qemu-armeb"
70 set spec "elf-rdimon.specs"
72 { "arm-pi3-*" } {
73 set qemu "qemu-arm"
74 set spec="-static"
75 set target_list pi
77 { "arm*-*-eabi*" } {
78 set qemu "qemu-arm"
79 set spec="-static"
80 set spec "elf-rdimon.specs"
82 { "aarch64be-*-elf" } {
83 set qemu "qemu-aarch64_be"
84 set spec "rdimon.specs"
86 { "aarch64*-gnu*" } {
87 set qemu "qemu-aarch64"
88 set spec "-static"
90 { "aarch64*-*elf*" } {
91 # There's multiple spec files, but rdimon is the
92 # one usually used for testing.
93 set qemu "qemu-aarch64"
94 set spec "rdimon.specs"
96 # FIXME: These following qemu variants are just what QEMU
97 # supports, the pattern to match for the target needs to be
98 # researched.
99 { "cris*" } {
100 set qemu "qemu-cris"
102 { "microblaze-*" } {
103 set qemu "qemu-microblaze"
104 set spec "elf-gloss-linux.specs"
106 { "microblazeel-*" } {
107 set qemu "qemu-microblazeel"
108 set spec "elf-gloss-linux.specs"
110 { "mips" } {
111 set qemu "qemu-mips"
113 { "mips64-*" } {
114 set qemu "qemu-mips64"
116 { "mips64el-*" } {
117 set qemu "qemu-mips64el"
119 { "mipsel-*" } {
120 set qemu "qemu-mipsel"
122 { "mipsn32-*" } {
123 set qemu "qemu-mipsn32"
125 { "mipsn32el-*" } {
126 set qemu "qemu-mipsn32el"
128 { "ppc-*" } {
129 set qemu "qemu-ppc"
131 { "ppc64-*" } {
132 set qemu "qemu-ppc64"
134 { "ppc64abi32-*" } {
135 set qemu "qemu-ppc64abi32"
137 { "ppc64le-*" } {
138 set qemu "qemu-ppc64le"
140 { "riscv32-elf" } {
141 set qemu "qemu-riscv32"
143 { "riscv64-elf" } {
144 set qemu "qemu-riscv64"
145 set spec "nano.spec"
147 { "sh4-*" } {
148 set qemu "qemu-sh4"
150 { "sh4eb-*" } {
151 set qemu "qemu-sh4eb"
153 { "sparc=*" } {
154 set qemu "qemu-sparc"
156 { "sparc32plus-*" } {
157 set qemu "qemu-sparc32plus"
159 { "sparc64-*" } {
160 set qemu "qemu-sparc64"
162 default {
163 puts "No target hardware for $target_triplet"
167 # 2345 is the default port used for the remote debugging protocol
168 set port "2345"
169 # QEMU uses the standard renmote debugging protocol as used by gdbserver.
170 set_board_info gdb_protocol "remote"
171 # localhost is the default host used for the remote debugging protocol
172 set_board_info sockethost "localhost"
173 set_board_info gdb,socketport $port
174 set_board_info target_sim_options "-g $port"
175 set_board_info gdb_server_prog $qemu
176 set_board_info specfile $spec
177 set_board_info needs_status_wrapper 1
178 #set_board_info protocol standard
179 push_config target qemu
181 # Path to the gdbserver executable, if required.
182 set_board_info gdb_server_prog "/usr/bin/gdbserver"
184 # This gdbserver can only run a process once per session.
185 set_board_info gdb,do_reload_on_run 1
186 set_board_info exit_is_reliable 1
188 # Set this if the board does not support passing arguments to the
189 # inferior process.
190 set_board_info noargs 0
192 set_board_info cflags "[libgloss_include_flags]"
193 set_board_info ldflags "[libgloss_link_flags] [newlib_link_flags] -specs=$spec -static"
196 set_board_info rsh_prog /usr/bin/ssh
197 set_board_info rcp_prog /usr/bin/scp
199 proc qemu_load { dest prog args } {
200 global qemu
201 global timeout
202 set ret [local_exec "$qemu $prog" "" "" $timeout]
204 if { [array size ret] == 0 } {
205 return "pass"
206 } else {
207 return "fail"
212 # Start QEMU with the executable
214 proc qemu_download { dest prog args } {
215 global qemu
216 global timeout
217 # qemu is already running with our executable.
221 # Load executable into GDB
223 proc gdb_load { args } {
224 global gdb_prompt
225 global verbose
226 global GDB
227 global user_spawn_id
228 global spawn_id
229 global qemu
231 if { $args != "" } {
232 if [gdb_file_cmd $args] then { return -1 }
235 if { $args == "{}"} {
236 puts "No executable passed to GDB!"
238 # Only the remote protocol is used with the QEMU's gdbserver support
239 send_gdb "target extended-remote :2345\n"
240 gdb_expect 2400 {
241 -re ".*$gdb_prompt $" {
242 if $verbose>1 then {
243 send_user "Connected to QEMU target\n"
246 -re "Remote debugging using .*$gdb_prompt $" {
247 verbose "Set target to remote for QEMU"
249 timeout {
250 if $verbose>1 then {
251 perror "Timed out trying to connect to QEMU target."
255 # send_gdb "continue\n"
258 send_gdb "load\n"
259 gdb_expect 2400 {
260 -re ".*$gdb_prompt $" {
261 if $verbose>1 then {
262 send_user "Loaded $args into GDB\n"
264 close $spawn_id
265 return 0
267 -re "$gdb_prompt $" {
268 if $verbose>1 then {
269 perror "GDB couldn't load."
272 timeout {
273 if $verbose>1 then {
274 perror "Timed out trying to load $args."
279 close $spawn_id
280 return -1
283 proc runto_main { } {
284 global verbose
285 global gdb_prompt
287 send_gdb "continue\n"
288 gdb_expect 2400 {
289 -re ".*$gdb_prompt $" {
290 if $verbose>1 then {
291 send_user "Continuing QEMU target\n"
294 timeout {
295 if $verbose>1 then {
296 perror "Timed out trying to connect to QEMU target."
301 return ""
302 # return [runto main no-message]