# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
# 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
# DejaGnu is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# DejaGnu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DejaGnu; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

# This file was written by Bob Manson (manson@cygnus.com)

# We use GDB to talk to a vr4300 board.
load_generic_config "base68k"

set_board_info shell_prompt "NEC010> "
set_board_info download_command "load tty0\n"
set_board_info download_response "Downloading from"
set_board_info go_command "g -e"
set_board_info startaddr "a0100000"
set_board_info hex_startaddr "0xa0100000"
set_board_info go_response "(^|\[\r\n\])(Exception Cause|\[0-9a-z\]+ \[0-9a-z\]+ break|\\*\\*\\*EXIT code )\[^\r\n\]*\[\r\n\]"
set_board_info output_end "\[\r\n\](Exception Cause|\[0-9a-z\]+ \[0-9a-z\]+ break).*$"

# Reset the prompt to what GDB needs.
proc ${board}_init { dest } {
    global doing_ddb_init
    if {[is_remote host]} {
	return
    }

    if {![info exists doing_ddb_init]} {
	set doing_ddb_init 1

	for { set i 1 } { $i <= 3 } { incr i } {
	    remote_close $dest
	    for { set x 0 } { $x < 3 } { incr x } {
		set shell_id [remote_open $dest]
		if { $shell_id == "" || $shell_id < 0 } {
		    remote_reboot $dest
		} else {
		    break
		}
	    }

	    set count 0
	    remote_send $dest "\n"
	    remote_expect $dest 20 {
		-re ".*PMON> $" {
		    remote_send $dest "set prompt \"NEC010> \"\n"
		    exp_continue
		}
		-re "NEC010> $" {
		    set i 10
		}
		timeout { }
		-re "0x0" {
		    incr count
		    if(count<5) {
			exp_continue
		    }
		}
	    }
	    if { $i < 3 }  {
		remote_reboot $dest
	    }
	}
	remote_close $dest
	unset doing_ddb_init
    } else {
	return
    }
}

set_board_info send_initial_cr  1
set_board_info dont_wait_for_prompt 1

# If no output format is specified, use objcopy.
if {![board_info $board exists output_format]} {
    set tempfil [lookfor_file $tool_root_dir binutils/objcopy]
    if { $tempfil != "" } {
	set_board_info objcopy $tempfil
    } else {
	set_board_info objcopy [transform objcopy]
    }
    unset tempfil
}
