home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gdb-4.12-src.lha
/
GNU
/
src
/
amiga
/
gdb-4.12
/
gdb
/
remote-e7000.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-03
|
33KB
|
1,697 lines
/* Remote debugging interface for Hitachi E7000 ICE, for GDB
Copyright 1993 Free Software Foundation, Inc.
Contributed by Cygnus Support.
Written by Steve Chamberlain for Cygnus Support.
This file is part of GDB.
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "defs.h"
#include "gdbcore.h"
#include "target.h"
#include "wait.h"
#include <varargs.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include "serial.h"
/* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
Hitachi-SH processor. It has serial port and a lan port.
The monitor command set makes it difficult to load large ammounts of
data over the lan without using ftp - so try not to issue load
commands when communicating over ethernet; use the ftpload command.
The monitor pauses for a second when dumping srecords to the serial
line too, so we use a slower per byte mechanism but without the
startup overhead. Even so, it's pretty slow... */
int using_tcp; /* nonzero if using the tcp serial driver */
extern struct target_ops e7000_ops; /* Forward declaration */
#define CTRLC 0x03
#define ENQ 0x05
#define ACK 0x06
#define CTRLZ 0x1a
char *ENQSTRING = "\005";
int echo;
int ctrl_c;
static void e7000_close ();
static void e7000_fetch_register ();
static void e7000_store_register ();
static int timeout = 5;
static void expect PARAMS ((char *));
static void expect_full_prompt PARAMS (());
static void expect_prompt PARAMS (());
static serial_t e7000_desc;
/* Send data to e7000debug. Works just like printf. */
#if 0
static void
printf_e7000debug (va_alist)
va_dcl
{
va_list args;
char *pattern;
char buf[200];
va_start (args);
pattern = va_arg (args, char *);
vsprintf (buf, pattern, args);
#else
static void
printf_e7000debug(a,b,c,d,e)
{
char buf[200];
sprintf(buf, a,b,c,d,e);
#endif
if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
/* And expect to see it echoed */
expect (buf);
}
static void
putchar_e7000 (x)
{
char b[1];
b[0] = x;
SERIAL_WRITE (e7000_desc, b, 1);
}
static void
write_e7000 (s)
char *s;
{
SERIAL_WRITE (e7000_desc, s, strlen (s));
}
/* Read a character from the remote system, doing all the fancy timeout
stuff. */
static int
readchar (timeout)
int timeout;
{
int c;
do
{
c = SERIAL_READCHAR (e7000_desc, timeout);
}
while (c > 127);
if (c == SERIAL_TIMEOUT)
{
if (timeout == 0)
return c; /* Polls shouldn't generate timeout errors */
error ("Timeout reading from remote system.");
}
return c;
}
/* Scan input from the remote system, until STRING is found. If DISCARD is
non-zero, then discard non-matching input, else print it out.
Let the user break out immediately. */
static void
expect (string)
char *string;
{
char *p = string;
int c;
while (1)
{
c = readchar (timeout);
notice_quit ();
if (quit_flag == 1)
{
if (ctrl_c) {
putchar_e7000(CTRLC);
ctrl_c -- ;
}
else
{
quit();
}
}
if (c == SERIAL_ERROR)
{
error ("Serial communication error");
}
if (echo)
{
if (c != '\r')
putchar (c);
fflush (stdout);
}
if (c == *p++)
{
if (*p == '\0')
{
return;
}
}
else
{
p = string;
}
}
}
/* Keep discarding input until we see the e7000 prompt.
The convention for dealing with the prompt is that you
o give your command
o *then* wait for the prompt.
Thus the last thing that a procedure does with the serial line
will be an expect_prompt(). Exception: e7000_resume does not
wait for the prompt, because the terminal is being handed over
to the inferior. However, the next thing which happens after that
is a e7000_wait which does wait for the prompt.
Note that this includes abnormal exit, e.g. error(). This is
necessary to prevent getting into states from which we can't
recover. */
static void
expect_prompt ()
{
expect (":");
}
static void
expect_full_prompt ()
{
expect ("\n:");
}
static int
get_hex_digit (ch)
{
if (ch >= '0' && ch <= '9')
return ch - '0';
else if (ch >= 'A' && ch <= 'F')
return ch - 'A' + 10;
else if (ch >= 'a' && ch <= 'f')
return ch - 'a' + 10;
return -1;
}
static int
get_hex (start)
int *start;
{
int value = get_hex_digit (*start);
int try;
*start = readchar (timeout);
while ((try = get_hex_digit (*start)) >= 0)
{
value <<= 4;
value += try;
*start = readchar (timeout);
}
return value;
}
/* Get N 32-bit words from remote, each preceded by a space,
and put them in registers starting at REGNO. */
static void
get_hex_regs (n, regno)
int n;
int regno;
{
long val;
int i;
for (i = 0; i < n; i++)
{
int j;
val = 0;
for (j = 0; j < 8; j++)
val = (val << 4) + get_hex_digit (j == 0);
supply_register (regno++, (char *) &val);
}
}
/* This is called not only when we first attach, but also when the
user types "run" after having attached. */
static void
e7000_create_inferior (execfile, args, env)
char *execfile;
char *args;
char **env;
{
int entry_pt;
if (args && *args)
error ("Can't pass arguments to remote E7000DEBUG process");
if (execfile == 0 || exec_bfd == 0)
error ("No exec file specified");
entry_pt = (int) bfd_get_start_address (exec_bfd);
#ifdef CREATE_INFERIOR_HOOK
CREATE_INFERIOR_HOOK (0); /* No process-ID */
#endif
/* The "process" (board) is already stopped awaiting our commands, and
the program is already downloaded. We just set its PC and go. */
clear_proceed_status ();
/* Tell wait_for_inferior that we've started a new process. */
init_wait_for_inferior ();
/* Set up the "saved terminal modes" of the inferior
based on what modes we are starting it with. */
target_terminal_init ();
/* Install inferior's terminal modes. */
target_terminal_inferior ();
/* insert_step_breakpoint (); FIXME, do we need this? */
proceed ((CORE_ADDR) entry_pt, -1, 0); /* Let 'er rip... */
}
/* Open a connection to a remote debugger.
NAME is the filename used for communication. */
static int baudrate = 9600;
static char dev_name[100];
static char *machine = "";
static char *user = "";
static char *passwd = "";
static char *dir = "";
/* Grab the next token and buy some space for it */
static char *
next (ptr)
char **ptr;
{
char *p = *ptr;
char *s;
char *r;
int l = 0;
while (*p && *p == ' ')
{
p++;
}
s = p;
while (*p && (*p != ' ' && *p != '\t'))
{
l++;
p++;
}
r = xmalloc (l + 1);
memcpy (r, s, l);
r[l] = 0;
*ptr = p;
return r;
}
static
e7000_login (args, from_tty)
char *args;
int from_tty;
{
if (args)
{
machine = next (&args);
user = next (&args);
passwd = next (&args);
dir = next (&args);
if (from_tty)
{
printf ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
}
}
else
{
error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
}
}
/* Start an ftp transfer from the E7000 to a host */
static
e7000_ftp (args, from_tty)
char *args;
int from_tty;
{
int oldtimeout = timeout;
timeout = 10;
printf_e7000debug ("ftp %s\r", machine);
expect (" Username : ");
printf_e7000debug ("%s\r", user);
expect (" Password : ");
write_e7000 (passwd);