OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [lib/] [xsh.exp] - Blame information for rev 1776

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 92, 93, 94, 95, 96, 97, 98, 1999 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 2 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, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-dejagnu@prep.ai.mit.edu
19
 
20
# This file was written by Rob Savoye. (rob@cygnus.com)
21
 
22
#
23
# Connect to Spectra (VTRX) using xsh
24
#
25
proc xsh_open { hostname } {
26
    global hex
27
    global target_triplet
28
    global xsh_shell_prompt
29
    global board_info
30
 
31
    if [board_info $hostname exists fileid] {
32
        unset board_info($hostname,fileid);
33
    }
34
 
35
    if ![board_info $hostname exists spectra] {
36
        perror "No spectra directory for $hostname";
37
        return -1;
38
    } else {
39
        set spectra [board_info $hostname spectra];
40
    }
41
 
42
    if ![board_info $hostname exists xsh_shell_prompt] {
43
        set xsh_shell_prompt ".*> "
44
    } else {
45
        set xsh_shell_prompt [board_info $hostname shell_prompt];
46
    }
47
 
48
    set retries 0
49
    set result  0
50
    if ![board_info $hostname exists xsh_prog] {
51
        set xsh xsh;
52
    } else {
53
        set xsh [board_info $hostname xsh_prog];
54
    }
55
 
56
    if {[which $xsh] != 0} {
57
        spawn $xsh
58
    } else {
59
        warning "Can't find xsh in path"
60
        return -1
61
    }
62
 
63
    set shell_id $spawn_id
64
 
65
    # start the shell
66
    expect {
67
        "*Spectra Cross-Development Shell version*$xsh_shell_prompt" {
68
            verbose "Got prompt"
69
            set result 0
70
        }
71
        timeout                 {
72
            warning "Timed out trying to connect."
73
            set result -1
74
            incr retries
75
            if { $retries <= 2 } {
76
                exp_continue
77
            }
78
        }
79
    }
80
 
81
    # connect to the shell
82
    set retries 0
83
    send "connect $hostname\n"
84
    expect {
85
        "connect $hostname*$hostname connected \(non-os mode\)*\n" {
86
            set xsh_shell_prompt "$hostname> "
87
            verbose "Connected to $hostname"
88
        }
89
        "*connect: not attached*" {
90
            warning "Couldn't attach target"
91
            set result -1
92
        }
93
        -re ".* reset on target.*$" {
94
            send_user "Spectra was reset\n"
95
            exp_continue
96
        }
97
        -re "\[0-9A-Fa-f\]+\[ 0x\]+\[0-9A-Fa-f\]+.*$" {
98
            exp_continue
99
        }
100
        "$hostname> " {
101
            #send "\n"
102
        }
103
        timeout {
104
            warning "Timed out trying to connect after $expect_out(seconds) seconds."
105
            set result -1
106
            incr retries
107
            if { $retries <= 2 } {
108
                exp_continue
109
            }
110
        }
111
    }
112
 
113
    send "\n\n\n"
114
    expect {
115
        "*$hostname*$hostname" {
116
            verbose "Cleared reset messages" 1
117
        }
118
        timeout {
119
            warning "Couldn't clear reset messages"
120
            set result 1
121
        }
122
    }
123
 
124
    set board_info($hostname,fileid) $spawn_id;
125
    # load to operating system
126
    set timeout 20
127
    set retries 0
128
    if {[xsh_download $hostname $spectra/${target_triplet}-os.o "" {-e sys_start_crt0}]!=0} {
129
        perror "Couldn't load Spectra into target"
130
        return -1
131
    }
132
 
133
    set timeout 10
134
    # start the OS running
135
    set retries 0
136
    send "go\n"
137
    expect {
138
        -re ".*Multithreading on target darkstar.*$" {
139
            verbose "Spectra has been started..." 1
140
            set result 0
141
        }
142
        -re ".*reset on target.*$" {
143
            verbose "Spectra was reset"
144
            exp_continue
145
        }
146
        -re "\[0-9A-Fa-f\]+\[ 0x\]+\[0-9A-Fa-f\]+.*$" {
147
            #send "\n"
148
            exp_continue
149
        }
150
        -re "go\n" { exp_continue }
151
        "$xsh_shell_prompt" { exp_continue }
152
        timeout {
153
            perror "Spectra wouldn't start"
154
            set result -1
155
            incr retries
156
            if { $retries <= 2 } {
157
                send "go\r"
158
                exp_continue
159
            }
160
        }
161
    }
162
 
163
    if { $result < 0 } {
164
        perror "Couldn't connect after $retries retries.\n"
165
        return -1
166
    } else {
167
        set board_info($hostname,fileid) $spawn_id;
168
        return $spawn_id
169
    }
170
}
171
 
172
#
173
# Download an executable using the load command in Spectra.
174
#     arg[0] - is a full path name to the file to download.
175
#     arg[1] - optional arguments to the load command.
176
#     returns  1 if a spectra error occured,
177
#             -1 if an internal error occured,
178
#              0 otherwise.
179
#
180
proc xsh_download { dest file destfile args } {
181
    global verbose
182
    global shell_id
183
    global decimal
184
    global hex
185
    global expect_out
186
    global board_info
187
 
188
    set result 1
189
    set retries 0
190
    set shell_id [board_info $dest fileid];
191
 
192
    if { [llength $args] > 1 } {
193
        set opts [lindex $args 1]
194
    } else {
195
        set opts ""
196
    }
197
 
198
    if { [llength $args] > 0 } {
199
        set destfile [lindex $args 0]
200
    }
201
 
202
    if ![file exists $file] {
203
        perror "$file doesn't exist."
204
        return 1
205
    }
206
 
207
    verbose "Downloading $file..."
208
 
209
    send -i $shell_id "load $opts $file\r"
210
    set force 0
211
    expect {
212
        -i $shell_id -re "\[0-9A-Fa-f\]+\[ 0x\]+\[0-9A-Fa-f\]+\r\n" {
213
            set timeout 1
214
            send "dout\n"
215
            while $force<2 {
216
                expect {
217
                    "dout*undefined kernel symbol*$xsh_shell_prompt" {
218
                        verbose "Attempted to flush I/O buffers" 1
219
                    }
220
                    timout {
221
                        incr force
222
                        flush stdout
223
                    }
224
                }
225
            }
226
            set timeout 20
227
            exp_continue
228
        }
229
        -i $shell_id  "load $opts $file*\r" {
230
            verbose "Loading a.out..."
231
            exp_continue
232
        }
233
        -i $shell_id "Warm reset on target*\n" {
234
            verbose "Spectra did a warm reset"
235
            exp_continue
236
        }
237
        -i $shell_id "Cold reset on target*\n" {
238
            verbose "Spectra did a cold reset"
239
            exp_continue
240
        }
241
        -i $shell_id "loading a.out*\r" {
242
            verbose "Loading a.out..."
243
            exp_continue
244
        }
245
        -i $shell_id "reading symbols*\r" {
246
            verbose "Reading symbols..."
247
            exp_continue
248
        }
249
        -i $shell_id "defining symbols*\r" {
250
            verbose "defining symbols..."
251
            exp_continue
252
        }
253
        -i $shell_id "*loading image*\r" {
254
            verbose "Loading image..."
255
            exp_continue
256
        }
257
        -i $shell_id -re ".*bytes loaded:.*$decimal.*$" {
258
            verbose "$expect_out(buffer)"
259
            exp_continue
260
        }
261
        -i $shell_id "*loading done*\r" {
262
            verbose "Loading done..."
263
            exp_continue
264
        }
265
        -i $shell_id "*setting PC*\r" {
266
            verbose "Setting PC..."
267
            exp_continue
268
        }
269
        -i $shell_id "*resolving symbols*\r" {
270
            verbose "Resolving symbols..."
271
            exp_continue
272
        }
273
        -i $shell_id -re ".*load module id = $decimal.*$" {
274
            verbose ""
275
        }
276
        -i $shell_id -re ".*load: undefined symbols.*$"  {
277
            perror "undefined symbols, make sure os is loaded and running"
278
            set result -1
279
        }
280
        -i $shell_id "$xsh_shell_prompt" {
281
            set result 0
282
            exp_continue
283
        }
284
        -i $shell_id "load: no default target" {
285
            perror "default target isn't set"
286
            return -1
287
        }
288
        -i $shell_id timeout {
289
            perror "Timed out trying to download after $expect_out(seconds) seconds."
290
            incr retries
291
            set result 1
292
            if { $retries <= 2 } {
293
                exp_continue
294
            }
295
        }
296
    }
297
 
298
    set timeout 10
299
    if [info exists expect_out(buffer)] {
300
        send_log $expect_out(buffer)
301
    }
302
    set board_info($hostname,fileid) $shell_id
303
    return $result
304
}
305
 
306
#
307
# Exit the remote shell
308
#
309
proc xsh_close { hostname } {
310
    global board_info
311
 
312
    if ![board_info $hostname exists fileid] {
313
        return;
314
    }
315
 
316
    set shell_id [board_info ${hostname} fileid];
317
    send -i $shell_id "exit\n"
318
    unset board_info(${hostname},fileid);
319
 
320
    verbose "Exiting shell."
321
    return 0
322
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.