home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / lib / dejagnu / vrtx.exp < prev    next >
Encoding:
Text File  |  1996-10-12  |  7.2 KB  |  335 lines

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