1130812Smarcel/* Remote debugging interface for Renesas E7000 ICE, for GDB
2130812Smarcel
3130812Smarcel   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4130812Smarcel   2002, 2003 Free Software Foundation, Inc.
5130812Smarcel
6130812Smarcel   Contributed by Cygnus Support.
7130812Smarcel
8130812Smarcel   Written by Steve Chamberlain for Cygnus Support.
9130812Smarcel
10130812Smarcel   This file is part of GDB.
11130812Smarcel
12130812Smarcel   This program is free software; you can redistribute it and/or modify
13130812Smarcel   it under the terms of the GNU General Public License as published by
14130812Smarcel   the Free Software Foundation; either version 2 of the License, or
15130812Smarcel   (at your option) any later version.
16130812Smarcel
17130812Smarcel   This program is distributed in the hope that it will be useful,
18130812Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
19130812Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20130812Smarcel   GNU General Public License for more details.
21130812Smarcel
22130812Smarcel   You should have received a copy of the GNU General Public License
23130812Smarcel   along with this program; if not, write to the Free Software
24130812Smarcel   Foundation, Inc., 59 Temple Place - Suite 330,
25130812Smarcel   Boston, MA 02111-1307, USA.  */
26130812Smarcel
27130812Smarcel/* The E7000 is an in-circuit emulator for the Renesas H8/300-H and
28130812Smarcel   Renesas-SH processor.  It has serial port and a lan port.
29130812Smarcel
30130812Smarcel   The monitor command set makes it difficult to load large ammounts of
31130812Smarcel   data over the lan without using ftp - so try not to issue load
32130812Smarcel   commands when communicating over ethernet; use the ftpload command.
33130812Smarcel
34130812Smarcel   The monitor pauses for a second when dumping srecords to the serial
35130812Smarcel   line too, so we use a slower per byte mechanism but without the
36130812Smarcel   startup overhead.  Even so, it's pretty slow... */
37130812Smarcel
38130812Smarcel#include "defs.h"
39130812Smarcel#include "gdbcore.h"
40130812Smarcel#include "gdbarch.h"
41130812Smarcel#include "inferior.h"
42130812Smarcel#include "target.h"
43130812Smarcel#include "value.h"
44130812Smarcel#include "command.h"
45130812Smarcel#include "gdb_string.h"
46130812Smarcel#include "gdbcmd.h"
47130812Smarcel#include <sys/types.h>
48130812Smarcel#include "serial.h"
49130812Smarcel#include "remote-utils.h"
50130812Smarcel#include "symfile.h"
51130812Smarcel#include "regcache.h"
52130812Smarcel#include <time.h>
53130812Smarcel#include <ctype.h>
54130812Smarcel
55130812Smarcel
56130812Smarcel#if 1
57130812Smarcel#define HARD_BREAKPOINTS	/* Now handled by set option. */
58130812Smarcel#define BC_BREAKPOINTS use_hard_breakpoints
59130812Smarcel#endif
60130812Smarcel
61130812Smarcel#define CTRLC 0x03
62130812Smarcel#define ENQ  0x05
63130812Smarcel#define ACK  0x06
64130812Smarcel#define CTRLZ 0x1a
65130812Smarcel
66130812Smarcel/* This file is used by 2 different targets, sh-elf and h8300. The
67130812Smarcel   h8300 is not multiarched and doesn't use the registers defined in
68130812Smarcel   tm-sh.h. To avoid using a macro GDB_TARGET_IS_SH, we do runtime check
69130812Smarcel   of the target, which requires that these namse below are always
70130812Smarcel   defined also in the h8300 case. */
71130812Smarcel
72130812Smarcel#if !defined (PR_REGNUM)
73130812Smarcel#define PR_REGNUM 	-1
74130812Smarcel#endif
75130812Smarcel#if !defined (GBR_REGNUM)
76130812Smarcel#define GBR_REGNUM 	-1
77130812Smarcel#endif
78130812Smarcel#if !defined (VBR_REGNUM)
79130812Smarcel#define VBR_REGNUM 	-1
80130812Smarcel#endif
81130812Smarcel#if !defined (MACH_REGNUM)
82130812Smarcel#define MACH_REGNUM 	-1
83130812Smarcel#endif
84130812Smarcel#if !defined (MACL_REGNUM)
85130812Smarcel#define MACL_REGNUM 	-1
86130812Smarcel#endif
87130812Smarcel#if !defined (SR_REGNUM)
88130812Smarcel#define SR_REGNUM 	-1
89130812Smarcel#endif
90130812Smarcel
91130812Smarcelextern void report_transfer_performance (unsigned long, time_t, time_t);
92130812Smarcel
93130812Smarcelextern char *sh_processor_type;
94130812Smarcel
95130812Smarcel/* Local function declarations.  */
96130812Smarcel
97130812Smarcelstatic void e7000_close (int);
98130812Smarcel
99130812Smarcelstatic void e7000_fetch_register (int);
100130812Smarcel
101130812Smarcelstatic void e7000_store_register (int);
102130812Smarcel
103130812Smarcelstatic void e7000_command (char *, int);
104130812Smarcel
105130812Smarcelstatic void e7000_login_command (char *, int);
106130812Smarcel
107130812Smarcelstatic void e7000_ftp_command (char *, int);
108130812Smarcel
109130812Smarcelstatic void e7000_drain_command (char *, int);
110130812Smarcel
111130812Smarcelstatic void expect (char *);
112130812Smarcel
113130812Smarcelstatic void expect_full_prompt (void);
114130812Smarcel
115130812Smarcelstatic void expect_prompt (void);
116130812Smarcel
117130812Smarcelstatic int e7000_parse_device (char *args, char *dev_name, int baudrate);
118130812Smarcel/* Variables. */
119130812Smarcel
120130812Smarcelstatic struct serial *e7000_desc;
121130812Smarcel
122130812Smarcel/* Allow user to chose between using hardware breakpoints or memory. */
123130812Smarcelstatic int use_hard_breakpoints = 0;	/* use sw breakpoints by default */
124130812Smarcel
125130812Smarcel/* Nonzero if using the tcp serial driver.  */
126130812Smarcel
127130812Smarcelstatic int using_tcp;		/* direct tcp connection to target */
128130812Smarcelstatic int using_tcp_remote;	/* indirect connection to target
129130812Smarcel				   via tcp to controller */
130130812Smarcel
131130812Smarcel/* Nonzero if using the pc isa card.  */
132130812Smarcel
133130812Smarcelstatic int using_pc;
134130812Smarcel
135130812Smarcelextern struct target_ops e7000_ops;	/* Forward declaration */
136130812Smarcel
137130812Smarcelchar *ENQSTRING = "\005";
138130812Smarcel
139130812Smarcel/* Nonzero if some routine (as opposed to the user) wants echoing.
140130812Smarcel   FIXME: Do this reentrantly with an extra parameter.  */
141130812Smarcel
142130812Smarcelstatic int echo;
143130812Smarcel
144130812Smarcelstatic int ctrl_c;
145130812Smarcel
146130812Smarcelstatic int timeout = 20;
147130812Smarcel
148130812Smarcel/* Send data to e7000debug.  */
149130812Smarcel
150130812Smarcelstatic void
151130812Smarcelputs_e7000debug (char *buf)
152130812Smarcel{
153130812Smarcel  if (!e7000_desc)
154130812Smarcel    error ("Use \"target e7000 ...\" first.");
155130812Smarcel
156130812Smarcel  if (remote_debug)
157130812Smarcel    printf_unfiltered ("Sending %s\n", buf);
158130812Smarcel
159130812Smarcel  if (serial_write (e7000_desc, buf, strlen (buf)))
160130812Smarcel    fprintf_unfiltered (gdb_stderr, "serial_write failed: %s\n", safe_strerror (errno));
161130812Smarcel
162130812Smarcel  /* And expect to see it echoed, unless using the pc interface */
163130812Smarcel#if 0
164130812Smarcel  if (!using_pc)
165130812Smarcel#endif
166130812Smarcel    expect (buf);
167130812Smarcel}
168130812Smarcel
169130812Smarcelstatic void
170130812Smarcelputchar_e7000 (int x)
171130812Smarcel{
172130812Smarcel  char b[1];
173130812Smarcel
174130812Smarcel  b[0] = x;
175130812Smarcel  serial_write (e7000_desc, b, 1);
176130812Smarcel}
177130812Smarcel
178130812Smarcelstatic void
179130812Smarcelwrite_e7000 (char *s)
180130812Smarcel{
181130812Smarcel  serial_write (e7000_desc, s, strlen (s));
182130812Smarcel}
183130812Smarcel
184130812Smarcelstatic int
185130812Smarcelnormal (int x)
186130812Smarcel{
187130812Smarcel  if (x == '\n')
188130812Smarcel    return '\r';
189130812Smarcel  return x;
190130812Smarcel}
191130812Smarcel
192130812Smarcel/* Read a character from the remote system, doing all the fancy timeout
193130812Smarcel   stuff.  Handles serial errors and EOF.  If TIMEOUT == 0, and no chars,
194130812Smarcel   returns -1, else returns next char.  Discards chars > 127.  */
195130812Smarcel
196130812Smarcelstatic int
197130812Smarcelreadchar (int timeout)
198130812Smarcel{
199130812Smarcel  int c;
200130812Smarcel
201130812Smarcel  do
202130812Smarcel    {
203130812Smarcel      c = serial_readchar (e7000_desc, timeout);
204130812Smarcel    }
205130812Smarcel  while (c > 127);
206130812Smarcel
207130812Smarcel  if (c == SERIAL_TIMEOUT)
208130812Smarcel    {
209130812Smarcel      if (timeout == 0)
210130812Smarcel	return -1;
211130812Smarcel      echo = 0;
212130812Smarcel      error ("Timeout reading from remote system.");
213130812Smarcel    }
214130812Smarcel  else if (c < 0)
215130812Smarcel    error ("Serial communication error");
216130812Smarcel
217130812Smarcel  if (remote_debug)
218130812Smarcel    {
219130812Smarcel      putchar_unfiltered (c);
220130812Smarcel      gdb_flush (gdb_stdout);
221130812Smarcel    }
222130812Smarcel
223130812Smarcel  return normal (c);
224130812Smarcel}
225130812Smarcel
226130812Smarcel#if 0
227130812Smarcelchar *
228130812Smarceltl (int x)
229130812Smarcel{
230130812Smarcel  static char b[8][10];
231130812Smarcel  static int p;
232130812Smarcel
233130812Smarcel  p++;
234130812Smarcel  p &= 7;
235130812Smarcel  if (x >= ' ')
236130812Smarcel    {
237130812Smarcel      b[p][0] = x;
238130812Smarcel      b[p][1] = 0;
239130812Smarcel    }
240130812Smarcel  else
241130812Smarcel    {
242130812Smarcel      sprintf (b[p], "<%d>", x);
243130812Smarcel    }
244130812Smarcel
245130812Smarcel  return b[p];
246130812Smarcel}
247130812Smarcel#endif
248130812Smarcel
249130812Smarcel/* Scan input from the remote system, until STRING is found.  If
250130812Smarcel   DISCARD is non-zero, then discard non-matching input, else print it
251130812Smarcel   out.  Let the user break out immediately.  */
252130812Smarcel
253130812Smarcelstatic void
254130812Smarcelexpect (char *string)
255130812Smarcel{
256130812Smarcel  char *p = string;
257130812Smarcel  int c;
258130812Smarcel  int nl = 0;
259130812Smarcel
260130812Smarcel  while (1)
261130812Smarcel    {
262130812Smarcel      c = readchar (timeout);
263130812Smarcel
264130812Smarcel      if (echo)
265130812Smarcel	{
266130812Smarcel	  if (c == '\r' || c == '\n')
267130812Smarcel	    {
268130812Smarcel	      if (!nl)
269130812Smarcel		putchar_unfiltered ('\n');
270130812Smarcel	      nl = 1;
271130812Smarcel	    }
272130812Smarcel	  else
273130812Smarcel	    {
274130812Smarcel	      nl = 0;
275130812Smarcel	      putchar_unfiltered (c);
276130812Smarcel	    }
277130812Smarcel	  gdb_flush (gdb_stdout);
278130812Smarcel	}
279130812Smarcel      if (normal (c) == normal (*p++))
280130812Smarcel	{
281130812Smarcel	  if (*p == '\0')
282130812Smarcel	    return;
283130812Smarcel	}
284130812Smarcel      else
285130812Smarcel	{
286130812Smarcel	  p = string;
287130812Smarcel
288130812Smarcel	  if (normal (c) == normal (string[0]))
289130812Smarcel	    p++;
290130812Smarcel	}
291130812Smarcel    }
292130812Smarcel}
293130812Smarcel
294130812Smarcel/* Keep discarding input until we see the e7000 prompt.
295130812Smarcel
296130812Smarcel   The convention for dealing with the prompt is that you
297130812Smarcel   o give your command
298130812Smarcel   o *then* wait for the prompt.
299130812Smarcel
300130812Smarcel   Thus the last thing that a procedure does with the serial line will
301130812Smarcel   be an expect_prompt().  Exception: e7000_resume does not wait for
302130812Smarcel   the prompt, because the terminal is being handed over to the
303130812Smarcel   inferior.  However, the next thing which happens after that is a
304130812Smarcel   e7000_wait which does wait for the prompt.  Note that this includes
305130812Smarcel   abnormal exit, e.g. error().  This is necessary to prevent getting
306130812Smarcel   into states from which we can't recover.  */
307130812Smarcel
308130812Smarcelstatic void
309130812Smarcelexpect_prompt (void)
310130812Smarcel{
311130812Smarcel  expect (":");
312130812Smarcel}
313130812Smarcel
314130812Smarcelstatic void
315130812Smarcelexpect_full_prompt (void)
316130812Smarcel{
317130812Smarcel  expect ("\r:");
318130812Smarcel}
319130812Smarcel
320130812Smarcelstatic int
321130812Smarcelconvert_hex_digit (int ch)
322130812Smarcel{
323130812Smarcel  if (ch >= '0' && ch <= '9')
324130812Smarcel    return ch - '0';
325130812Smarcel  else if (ch >= 'A' && ch <= 'F')
326130812Smarcel    return ch - 'A' + 10;
327130812Smarcel  else if (ch >= 'a' && ch <= 'f')
328130812Smarcel    return ch - 'a' + 10;
329130812Smarcel  return -1;
330130812Smarcel}
331130812Smarcel
332130812Smarcelstatic int
333130812Smarcelget_hex (int *start)
334130812Smarcel{
335130812Smarcel  int value = convert_hex_digit (*start);
336130812Smarcel  int try;
337130812Smarcel
338130812Smarcel  *start = readchar (timeout);
339130812Smarcel  while ((try = convert_hex_digit (*start)) >= 0)
340130812Smarcel    {
341130812Smarcel      value <<= 4;
342130812Smarcel      value += try;
343130812Smarcel      *start = readchar (timeout);
344130812Smarcel    }
345130812Smarcel  return value;
346130812Smarcel}
347130812Smarcel
348130812Smarcel#if 0
349130812Smarcel/* Get N 32-bit words from remote, each preceded by a space, and put
350130812Smarcel   them in registers starting at REGNO.  */
351130812Smarcel
352130812Smarcelstatic void
353130812Smarcelget_hex_regs (int n, int regno)
354130812Smarcel{
355130812Smarcel  long val;
356130812Smarcel  int i;
357130812Smarcel
358130812Smarcel  for (i = 0; i < n; i++)
359130812Smarcel    {
360130812Smarcel      int j;
361130812Smarcel
362130812Smarcel      val = 0;
363130812Smarcel      for (j = 0; j < 8; j++)
364130812Smarcel	val = (val << 4) + get_hex_digit (j == 0);
365130812Smarcel      supply_register (regno++, (char *) &val);
366130812Smarcel    }
367130812Smarcel}
368130812Smarcel#endif
369130812Smarcel
370130812Smarcel/* This is called not only when we first attach, but also when the
371130812Smarcel   user types "run" after having attached.  */
372130812Smarcel
373130812Smarcelstatic void
374130812Smarcele7000_create_inferior (char *execfile, char *args, char **env)
375130812Smarcel{
376130812Smarcel  int entry_pt;
377130812Smarcel
378130812Smarcel  if (args && *args)
379130812Smarcel    error ("Can't pass arguments to remote E7000DEBUG process");
380130812Smarcel
381130812Smarcel  if (execfile == 0 || exec_bfd == 0)
382130812Smarcel    error ("No executable file specified");
383130812Smarcel
384130812Smarcel  entry_pt = (int) bfd_get_start_address (exec_bfd);
385130812Smarcel
386130812Smarcel#ifdef CREATE_INFERIOR_HOOK
387130812Smarcel  CREATE_INFERIOR_HOOK (0);	/* No process-ID */
388130812Smarcel#endif
389130812Smarcel
390130812Smarcel  /* The "process" (board) is already stopped awaiting our commands, and
391130812Smarcel     the program is already downloaded.  We just set its PC and go.  */
392130812Smarcel
393130812Smarcel  clear_proceed_status ();
394130812Smarcel
395130812Smarcel  /* Tell wait_for_inferior that we've started a new process.  */
396130812Smarcel  init_wait_for_inferior ();
397130812Smarcel
398130812Smarcel  /* Set up the "saved terminal modes" of the inferior
399130812Smarcel     based on what modes we are starting it with.  */
400130812Smarcel  target_terminal_init ();
401130812Smarcel
402130812Smarcel  /* Install inferior's terminal modes.  */
403130812Smarcel  target_terminal_inferior ();
404130812Smarcel
405130812Smarcel  /* insert_step_breakpoint ();  FIXME, do we need this?  */
406130812Smarcel  proceed ((CORE_ADDR) entry_pt, -1, 0);	/* Let 'er rip... */
407130812Smarcel}
408130812Smarcel
409130812Smarcel/* Open a connection to a remote debugger.  NAME is the filename used
410130812Smarcel   for communication.  */
411130812Smarcel
412130812Smarcelstatic int baudrate = 9600;
413130812Smarcelstatic char dev_name[100];
414130812Smarcel
415130812Smarcelstatic char *machine = "";
416130812Smarcelstatic char *user = "";
417130812Smarcelstatic char *passwd = "";
418130812Smarcelstatic char *dir = "";
419130812Smarcel
420130812Smarcel/* Grab the next token and buy some space for it */
421130812Smarcel
422130812Smarcelstatic char *
423130812Smarcelnext (char **ptr)
424130812Smarcel{
425130812Smarcel  char *p = *ptr;
426130812Smarcel  char *s;
427130812Smarcel  char *r;
428130812Smarcel  int l = 0;
429130812Smarcel
430130812Smarcel  while (*p && *p == ' ')
431130812Smarcel    p++;
432130812Smarcel  s = p;
433130812Smarcel  while (*p && (*p != ' ' && *p != '\t'))
434130812Smarcel    {
435130812Smarcel      l++;
436130812Smarcel      p++;
437130812Smarcel    }
438130812Smarcel  r = xmalloc (l + 1);
439130812Smarcel  memcpy (r, s, l);
440130812Smarcel  r[l] = 0;
441130812Smarcel  *ptr = p;
442130812Smarcel  return r;
443130812Smarcel}
444130812Smarcel
445130812Smarcelstatic void
446130812Smarcele7000_login_command (char *args, int from_tty)
447130812Smarcel{
448130812Smarcel  if (args)
449130812Smarcel    {
450130812Smarcel      machine = next (&args);
451130812Smarcel      user = next (&args);
452130812Smarcel      passwd = next (&args);
453130812Smarcel      dir = next (&args);
454130812Smarcel      if (from_tty)
455130812Smarcel	{
456130812Smarcel	  printf_unfiltered ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
457130812Smarcel	}
458130812Smarcel    }
459130812Smarcel  else
460130812Smarcel    {
461130812Smarcel      error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
462130812Smarcel    }
463130812Smarcel}
464130812Smarcel
465130812Smarcel/* Start an ftp transfer from the E7000 to a host */
466130812Smarcel
467130812Smarcelstatic void
468130812Smarcele7000_ftp_command (char *args, int from_tty)
469130812Smarcel{
470130812Smarcel  /* FIXME: arbitrary limit on machine names and such.  */
471130812Smarcel  char buf[200];
472130812Smarcel
473130812Smarcel  int oldtimeout = timeout;
474130812Smarcel  timeout = remote_timeout;
475130812Smarcel
476130812Smarcel  sprintf (buf, "ftp %s\r", machine);
477130812Smarcel  puts_e7000debug (buf);
478130812Smarcel  expect (" Username : ");
479130812Smarcel  sprintf (buf, "%s\r", user);
480130812Smarcel  puts_e7000debug (buf);
481130812Smarcel  expect (" Password : ");
482130812Smarcel  write_e7000 (passwd);
483130812Smarcel  write_e7000 ("\r");
484130812Smarcel  expect ("success\r");
485130812Smarcel  expect ("FTP>");
486130812Smarcel  sprintf (buf, "cd %s\r", dir);
487130812Smarcel  puts_e7000debug (buf);
488130812Smarcel  expect ("FTP>");
489130812Smarcel  sprintf (buf, "ll 0;s:%s\r", args);
490130812Smarcel  puts_e7000debug (buf);
491130812Smarcel  expect ("FTP>");
492130812Smarcel  puts_e7000debug ("bye\r");
493130812Smarcel  expect (":");
494130812Smarcel  timeout = oldtimeout;
495130812Smarcel}
496130812Smarcel
497130812Smarcelstatic int
498130812Smarcele7000_parse_device (char *args, char *dev_name, int baudrate)
499130812Smarcel{
500130812Smarcel  char junk[128];
501130812Smarcel  int n = 0;
502130812Smarcel  if (args && strcasecmp (args, "pc") == 0)
503130812Smarcel    {
504130812Smarcel      strcpy (dev_name, args);
505130812Smarcel      using_pc = 1;
506130812Smarcel    }
507130812Smarcel  else
508130812Smarcel    {
509130812Smarcel      /* FIXME! temp hack to allow use with port master -
510130812Smarcel         target tcp_remote <device> */
511130812Smarcel      if (args && strncmp (args, "tcp", 10) == 0)
512130812Smarcel	{
513130812Smarcel	  char com_type[128];
514130812Smarcel	  n = sscanf (args, " %s %s %d %s", com_type, dev_name, &baudrate, junk);
515130812Smarcel	  using_tcp_remote = 1;
516130812Smarcel	  n--;
517130812Smarcel	}
518130812Smarcel      else if (args)
519130812Smarcel	{
520130812Smarcel	  n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk);
521130812Smarcel	}
522130812Smarcel
523130812Smarcel      if (n != 1 && n != 2)
524130812Smarcel	{
525130812Smarcel	  error ("Bad arguments.  Usage:\ttarget e7000 <device> <speed>\n\
526130812Smarcelor \t\ttarget e7000 <host>[:<port>]\n\
527130812Smarcelor \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
528130812Smarcelor \t\ttarget e7000 pc\n");
529130812Smarcel	}
530130812Smarcel
531130812Smarcel#if !defined(__GO32__) && !defined(_WIN32) && !defined(__CYGWIN__)
532130812Smarcel      /* FIXME!  test for ':' is ambiguous */
533130812Smarcel      if (n == 1 && strchr (dev_name, ':') == 0)
534130812Smarcel	{
535130812Smarcel	  /* Default to normal telnet port */
536130812Smarcel	  /* serial_open will use this to determine tcp communication */
537130812Smarcel	  strcat (dev_name, ":23");
538130812Smarcel	}
539130812Smarcel#endif
540130812Smarcel      if (!using_tcp_remote && strchr (dev_name, ':'))
541130812Smarcel	using_tcp = 1;
542130812Smarcel    }
543130812Smarcel
544130812Smarcel  return n;
545130812Smarcel}
546130812Smarcel
547130812Smarcel/* Stub for catch_errors.  */
548130812Smarcel
549130812Smarcelstatic int
550130812Smarcele7000_start_remote (void *dummy)
551130812Smarcel{
552130812Smarcel  int loop;
553130812Smarcel  int sync;
554130812Smarcel  int try;
555130812Smarcel  int quit_trying;
556130812Smarcel
557130812Smarcel  immediate_quit++;		/* Allow user to interrupt it */
558130812Smarcel
559130812Smarcel  /* Hello?  Are you there?  */
560130812Smarcel  sync = 0;
561130812Smarcel  loop = 0;
562130812Smarcel  try = 0;
563130812Smarcel  quit_trying = 20;
564130812Smarcel  putchar_e7000 (CTRLC);
565130812Smarcel  while (!sync && ++try <= quit_trying)
566130812Smarcel    {
567130812Smarcel      int c;
568130812Smarcel
569130812Smarcel      printf_unfiltered ("[waiting for e7000...]\n");
570130812Smarcel
571130812Smarcel      write_e7000 ("\r");
572130812Smarcel      c = readchar (1);
573130812Smarcel
574130812Smarcel      /* FIXME!  this didn't seem right->  while (c != SERIAL_TIMEOUT)
575130812Smarcel       * we get stuck in this loop ...
576130812Smarcel       * We may never timeout, and never sync up :-(
577130812Smarcel       */
578130812Smarcel      while (!sync && c != -1)
579130812Smarcel	{
580130812Smarcel	  /* Dont echo cr's */
581130812Smarcel	  if (c != '\r')
582130812Smarcel	    {
583130812Smarcel	      putchar_unfiltered (c);
584130812Smarcel	      gdb_flush (gdb_stdout);
585130812Smarcel	    }
586130812Smarcel	  /* Shouldn't we either break here, or check for sync in inner loop? */
587130812Smarcel	  if (c == ':')
588130812Smarcel	    sync = 1;
589130812Smarcel
590130812Smarcel	  if (loop++ == 20)
591130812Smarcel	    {
592130812Smarcel	      putchar_e7000 (CTRLC);
593130812Smarcel	      loop = 0;
594130812Smarcel	    }
595130812Smarcel
596130812Smarcel	  QUIT;
597130812Smarcel
598130812Smarcel	  if (quit_flag)
599130812Smarcel	    {
600130812Smarcel	      putchar_e7000 (CTRLC);
601130812Smarcel	      /* Was-> quit_flag = 0; */
602130812Smarcel	      c = -1;
603130812Smarcel	      quit_trying = try + 1;	/* we don't want to try anymore */
604130812Smarcel	    }
605130812Smarcel	  else
606130812Smarcel	    {
607130812Smarcel	      c = readchar (1);
608130812Smarcel	    }
609130812Smarcel	}
610130812Smarcel    }
611130812Smarcel
612130812Smarcel  if (!sync)
613130812Smarcel    {
614130812Smarcel      fprintf_unfiltered (gdb_stderr, "Giving up after %d tries...\n", try);
615130812Smarcel      error ("Unable to synchronize with target.\n");
616130812Smarcel    }
617130812Smarcel
618130812Smarcel  puts_e7000debug ("\r");
619130812Smarcel  expect_prompt ();
620130812Smarcel  puts_e7000debug ("b -\r");	/* Clear breakpoints */
621130812Smarcel  expect_prompt ();
622130812Smarcel
623130812Smarcel  immediate_quit--;
624130812Smarcel
625130812Smarcel/* This is really the job of start_remote however, that makes an assumption
626130812Smarcel   that the target is about to print out a status message of some sort.  That
627130812Smarcel   doesn't happen here. */
628130812Smarcel
629130812Smarcel  flush_cached_frames ();
630130812Smarcel  registers_changed ();
631130812Smarcel  stop_pc = read_pc ();
632130812Smarcel  print_stack_frame (get_selected_frame (), -1, 1);
633130812Smarcel
634130812Smarcel  return 1;
635130812Smarcel}
636130812Smarcel
637130812Smarcelstatic void
638130812Smarcele7000_open (char *args, int from_tty)
639130812Smarcel{
640130812Smarcel  int n;
641130812Smarcel
642130812Smarcel  target_preopen (from_tty);
643130812Smarcel
644130812Smarcel  n = e7000_parse_device (args, dev_name, baudrate);
645130812Smarcel
646130812Smarcel  push_target (&e7000_ops);
647130812Smarcel
648130812Smarcel  e7000_desc = serial_open (dev_name);
649130812Smarcel
650130812Smarcel  if (!e7000_desc)
651130812Smarcel    perror_with_name (dev_name);
652130812Smarcel
653130812Smarcel  if (serial_setbaudrate (e7000_desc, baudrate))
654130812Smarcel    {
655130812Smarcel      serial_close (e7000_desc);
656130812Smarcel      perror_with_name (dev_name);
657130812Smarcel    }
658130812Smarcel  serial_raw (e7000_desc);
659130812Smarcel
660130812Smarcel  /* Start the remote connection; if error (0), discard this target.
661130812Smarcel     In particular, if the user quits, be sure to discard it
662130812Smarcel     (we'd be in an inconsistent state otherwise).  */
663130812Smarcel  if (!catch_errors (e7000_start_remote, (char *) 0,
664130812Smarcel       "Couldn't establish connection to remote target\n", RETURN_MASK_ALL))
665130812Smarcel    if (from_tty)
666130812Smarcel      printf_filtered ("Remote target %s connected to %s\n", target_shortname,
667130812Smarcel		       dev_name);
668130812Smarcel}
669130812Smarcel
670130812Smarcel/* Close out all files and local state before this target loses control. */
671130812Smarcel
672130812Smarcelstatic void
673130812Smarcele7000_close (int quitting)
674130812Smarcel{
675130812Smarcel  if (e7000_desc)
676130812Smarcel    {
677130812Smarcel      serial_close (e7000_desc);
678130812Smarcel      e7000_desc = 0;
679130812Smarcel    }
680130812Smarcel}
681130812Smarcel
682130812Smarcel/* Terminate the open connection to the remote debugger.  Use this
683130812Smarcel   when you want to detach and do something else with your gdb.  */
684130812Smarcel
685130812Smarcelstatic void
686130812Smarcele7000_detach (char *arg, int from_tty)
687130812Smarcel{
688130812Smarcel  pop_target ();		/* calls e7000_close to do the real work */
689130812Smarcel  if (from_tty)
690130812Smarcel    printf_unfiltered ("Ending remote %s debugging\n", target_shortname);
691130812Smarcel}
692130812Smarcel
693130812Smarcel/* Tell the remote machine to resume.  */
694130812Smarcel
695130812Smarcelstatic void
696130812Smarcele7000_resume (ptid_t ptid, int step, enum target_signal sigal)
697130812Smarcel{
698130812Smarcel  if (step)
699130812Smarcel    puts_e7000debug ("S\r");
700130812Smarcel  else
701130812Smarcel    puts_e7000debug ("G\r");
702130812Smarcel}
703130812Smarcel
704130812Smarcel/* Read the remote registers into the block REGS.
705130812Smarcel
706130812Smarcel   For the H8/300 a register dump looks like:
707130812Smarcel
708130812Smarcel   PC=00021A  CCR=80:I*******
709130812Smarcel   ER0 - ER3  0000000A 0000002E 0000002E 00000000
710130812Smarcel   ER4 - ER7  00000000 00000000 00000000 00FFEFF6
711130812Smarcel   000218           MOV.B     R1L,R2L
712130812Smarcel   STEP NORMAL END or
713130812Smarcel   BREAK POINT
714130812Smarcel */
715130812Smarcel
716130812Smarcelchar *want_h8300h = "PC=%p CCR=%c\n\
717130812Smarcel ER0 - ER3  %0 %1 %2 %3\n\
718130812Smarcel ER4 - ER7  %4 %5 %6 %7\n";
719130812Smarcel
720130812Smarcelchar *want_nopc_h8300h = "%p CCR=%c\n\
721130812Smarcel ER0 - ER3  %0 %1 %2 %3\n\
722130812Smarcel ER4 - ER7  %4 %5 %6 %7";
723130812Smarcel
724130812Smarcelchar *want_h8300s = "PC=%p CCR=%c\n\
725130812Smarcel MACH=\n\
726130812Smarcel ER0 - ER3  %0 %1 %2 %3\n\
727130812Smarcel ER4 - ER7  %4 %5 %6 %7\n";
728130812Smarcel
729130812Smarcelchar *want_nopc_h8300s = "%p CCR=%c EXR=%9\n\
730130812Smarcel ER0 - ER3  %0 %1 %2 %3\n\
731130812Smarcel ER4 - ER7  %4 %5 %6 %7";
732130812Smarcel
733130812Smarcelchar *want_sh = "PC=%16 SR=%22\n\
734130812SmarcelPR=%17 GBR=%18 VBR=%19\n\
735130812SmarcelMACH=%20 MACL=%21\n\
736130812SmarcelR0-7  %0 %1 %2 %3 %4 %5 %6 %7\n\
737130812SmarcelR8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
738130812Smarcel
739130812Smarcelchar *want_nopc_sh = "%16 SR=%22\n\
740130812Smarcel PR=%17 GBR=%18 VBR=%19\n\
741130812Smarcel MACH=%20 MACL=%21\n\
742130812Smarcel R0-7  %0 %1 %2 %3 %4 %5 %6 %7\n\
743130812Smarcel R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
744130812Smarcel
745130812Smarcelchar *want_sh3 = "PC=%16 SR=%22\n\
746130812SmarcelPR=%17 GBR=%18 VBR=%19\n\
747130812SmarcelMACH=%20 MACL=%21 SSR=%23 SPC=%24\n\
748130812SmarcelR0-7  %0 %1 %2 %3 %4 %5 %6 %7\n\
749130812SmarcelR8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
750130812SmarcelR0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
751130812SmarcelR4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
752130812SmarcelR0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
753130812SmarcelR4_BANK1-R7_BANK1 %37 %38 %39 %40";
754130812Smarcel
755130812Smarcelchar *want_nopc_sh3 = "%16 SR=%22\n\
756130812Smarcel PR=%17 GBR=%18 VBR=%19\n\
757130812Smarcel MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\
758130812Smarcel R0-7  %0 %1 %2 %3 %4 %5 %6 %7\n\
759130812Smarcel R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\
760130812Smarcel R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\
761130812Smarcel R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\
762130812Smarcel R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\
763130812Smarcel R4_BANK1-R7_BANK1 %37 %38 %39 %40";
764130812Smarcel
765130812Smarcelstatic int
766130812Smarcelgch (void)
767130812Smarcel{
768130812Smarcel  return readchar (timeout);
769130812Smarcel}
770130812Smarcel
771130812Smarcelstatic unsigned int
772130812Smarcelgbyte (void)
773130812Smarcel{
774130812Smarcel  int high = convert_hex_digit (gch ());
775130812Smarcel  int low = convert_hex_digit (gch ());
776130812Smarcel
777130812Smarcel  return (high << 4) + low;
778130812Smarcel}
779130812Smarcel
780130812Smarcelstatic void
781130812Smarcelfetch_regs_from_dump (int (*nextchar) (), char *want)
782130812Smarcel{
783130812Smarcel  int regno;
784130812Smarcel  char buf[MAX_REGISTER_SIZE];
785130812Smarcel
786130812Smarcel  int thischar = nextchar ();
787130812Smarcel
788130812Smarcel  if (want == NULL)
789130812Smarcel    internal_error (__FILE__, __LINE__, "Register set not selected.");
790130812Smarcel
791130812Smarcel  while (*want)
792130812Smarcel    {
793130812Smarcel      switch (*want)
794130812Smarcel	{
795130812Smarcel	case '\n':
796130812Smarcel	  /* Skip to end of line and then eat all new line type stuff */
797130812Smarcel	  while (thischar != '\n' && thischar != '\r')
798130812Smarcel	    thischar = nextchar ();
799130812Smarcel	  while (thischar == '\n' || thischar == '\r')
800130812Smarcel	    thischar = nextchar ();
801130812Smarcel	  want++;
802130812Smarcel	  break;
803130812Smarcel
804130812Smarcel	case ' ':
805130812Smarcel	  while (thischar == ' '
806130812Smarcel		 || thischar == '\t'
807130812Smarcel		 || thischar == '\r'
808130812Smarcel		 || thischar == '\n')
809130812Smarcel	    thischar = nextchar ();
810130812Smarcel	  want++;
811130812Smarcel	  break;
812130812Smarcel
813130812Smarcel	default:
814130812Smarcel	  if (*want == thischar)
815130812Smarcel	    {
816130812Smarcel	      want++;
817130812Smarcel	      if (*want)
818130812Smarcel		thischar = nextchar ();
819130812Smarcel
820130812Smarcel	    }
821130812Smarcel	  else if (thischar == ' ' || thischar == '\n' || thischar == '\r')
822130812Smarcel	    {
823130812Smarcel	      thischar = nextchar ();
824130812Smarcel	    }
825130812Smarcel	  else
826130812Smarcel	    {
827130812Smarcel	      error ("out of sync in fetch registers wanted <%s>, got <%c 0x%x>",
828130812Smarcel		     want, thischar, thischar);
829130812Smarcel	    }
830130812Smarcel
831130812Smarcel	  break;
832130812Smarcel	case '%':
833130812Smarcel	  /* Got a register command */
834130812Smarcel	  want++;
835130812Smarcel	  switch (*want)
836130812Smarcel	    {
837130812Smarcel#ifdef PC_REGNUM
838130812Smarcel	    case 'p':
839130812Smarcel	      regno = PC_REGNUM;
840130812Smarcel	      want++;
841130812Smarcel	      break;
842130812Smarcel#endif
843130812Smarcel#ifdef CCR_REGNUM
844130812Smarcel	    case 'c':
845130812Smarcel	      regno = CCR_REGNUM;
846130812Smarcel	      want++;
847130812Smarcel	      break;
848130812Smarcel#endif
849130812Smarcel#ifdef SP_REGNUM
850130812Smarcel	    case 's':
851130812Smarcel	      regno = SP_REGNUM;
852130812Smarcel	      want++;
853130812Smarcel	      break;
854130812Smarcel#endif
855130812Smarcel#ifdef DEPRECATED_FP_REGNUM
856130812Smarcel	    case 'f':
857130812Smarcel	      regno = DEPRECATED_FP_REGNUM;
858130812Smarcel	      want++;
859130812Smarcel	      break;
860130812Smarcel#endif
861130812Smarcel
862130812Smarcel	    default:
863130812Smarcel	      if (isdigit (want[0]))
864130812Smarcel		{
865130812Smarcel		  if (isdigit (want[1]))
866130812Smarcel		    {
867130812Smarcel		      regno = (want[0] - '0') * 10 + want[1] - '0';
868130812Smarcel		      want += 2;
869130812Smarcel		    }
870130812Smarcel		  else
871130812Smarcel		    {
872130812Smarcel		      regno = want[0] - '0';
873130812Smarcel		      want++;
874130812Smarcel		    }
875130812Smarcel		}
876130812Smarcel
877130812Smarcel	      else
878130812Smarcel		internal_error (__FILE__, __LINE__, "failed internal consistency check");
879130812Smarcel	    }
880130812Smarcel	  store_signed_integer (buf,
881130812Smarcel				DEPRECATED_REGISTER_RAW_SIZE (regno),
882130812Smarcel				(LONGEST) get_hex (&thischar));
883130812Smarcel	  supply_register (regno, buf);
884130812Smarcel	  break;
885130812Smarcel	}
886130812Smarcel    }
887130812Smarcel}
888130812Smarcel
889130812Smarcelstatic void
890130812Smarcele7000_fetch_registers (void)
891130812Smarcel{
892130812Smarcel  int regno;
893130812Smarcel  char *wanted = NULL;
894130812Smarcel
895130812Smarcel  puts_e7000debug ("R\r");
896130812Smarcel
897130812Smarcel  if (TARGET_ARCHITECTURE->arch == bfd_arch_sh)
898130812Smarcel    {
899130812Smarcel      wanted = want_sh;
900130812Smarcel      switch (TARGET_ARCHITECTURE->mach)
901130812Smarcel	{
902130812Smarcel	case bfd_mach_sh3:
903130812Smarcel	case bfd_mach_sh3e:
904130812Smarcel	case bfd_mach_sh4:
905130812Smarcel	  wanted = want_sh3;
906130812Smarcel	}
907130812Smarcel    }
908130812Smarcel  if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300)
909130812Smarcel    {
910130812Smarcel      wanted = want_h8300h;
911130812Smarcel      switch (TARGET_ARCHITECTURE->mach)
912130812Smarcel	{
913130812Smarcel	case bfd_mach_h8300s:
914130812Smarcel	case bfd_mach_h8300sn:
915130812Smarcel	case bfd_mach_h8300sx:
916130812Smarcel	case bfd_mach_h8300sxn:
917130812Smarcel	  wanted = want_h8300s;
918130812Smarcel	}
919130812Smarcel    }
920130812Smarcel
921130812Smarcel  fetch_regs_from_dump (gch, wanted);
922130812Smarcel
923130812Smarcel  /* And supply the extra ones the simulator uses */
924130812Smarcel  for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
925130812Smarcel    {
926130812Smarcel      int buf = 0;
927130812Smarcel
928130812Smarcel      supply_register (regno, (char *) (&buf));
929130812Smarcel    }
930130812Smarcel}
931130812Smarcel
932130812Smarcel/* Fetch register REGNO, or all registers if REGNO is -1.  Returns
933130812Smarcel   errno value.  */
934130812Smarcel
935130812Smarcelstatic void
936130812Smarcele7000_fetch_register (int regno)
937130812Smarcel{
938130812Smarcel  e7000_fetch_registers ();
939130812Smarcel}
940130812Smarcel
941130812Smarcel/* Store the remote registers from the contents of the block REGS.  */
942130812Smarcel
943130812Smarcelstatic void
944130812Smarcele7000_store_registers (void)
945130812Smarcel{
946130812Smarcel  int regno;
947130812Smarcel
948130812Smarcel  for (regno = 0; regno < NUM_REALREGS; regno++)
949130812Smarcel    e7000_store_register (regno);
950130812Smarcel
951130812Smarcel  registers_changed ();
952130812Smarcel}
953130812Smarcel
954130812Smarcel/* Store register REGNO, or all if REGNO == 0.  Return errno value.  */
955130812Smarcel
956130812Smarcelstatic void
957130812Smarcele7000_store_register (int regno)
958130812Smarcel{
959130812Smarcel  char buf[200];
960130812Smarcel
961130812Smarcel  if (regno == -1)
962130812Smarcel    {
963130812Smarcel      e7000_store_registers ();
964130812Smarcel      return;
965130812Smarcel    }
966130812Smarcel
967130812Smarcel  if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300)
968130812Smarcel    {
969130812Smarcel      if (regno <= 7)
970130812Smarcel	{
971130812Smarcel	  sprintf (buf, ".ER%d %s\r", regno, phex_nz (read_register (regno), 0));
972130812Smarcel	  puts_e7000debug (buf);
973130812Smarcel	}
974130812Smarcel      else if (regno == PC_REGNUM)
975130812Smarcel	{
976130812Smarcel	  sprintf (buf, ".PC %s\r", phex_nz (read_register (regno), 0));
977130812Smarcel	  puts_e7000debug (buf);
978130812Smarcel	}
979130812Smarcel#ifdef CCR_REGNUM
980130812Smarcel      else if (regno == CCR_REGNUM)
981130812Smarcel	{
982130812Smarcel	  sprintf (buf, ".CCR %s\r", phex_nz (read_register (regno), 0));
983130812Smarcel	  puts_e7000debug (buf);
984130812Smarcel	}
985130812Smarcel#endif
986130812Smarcel    }
987130812Smarcel
988130812Smarcel  else if (TARGET_ARCHITECTURE->arch == bfd_arch_sh)
989130812Smarcel    {
990130812Smarcel      if (regno == PC_REGNUM)
991130812Smarcel	{
992130812Smarcel	  sprintf (buf, ".PC %s\r", phex_nz (read_register (regno), 0));
993130812Smarcel	  puts_e7000debug (buf);
994130812Smarcel	}
995130812Smarcel
996130812Smarcel      else if (regno == SR_REGNUM)
997130812Smarcel	{
998130812Smarcel	  sprintf (buf, ".SR %s\r", phex_nz (read_register (regno), 0));
999130812Smarcel	  puts_e7000debug (buf);
1000130812Smarcel	}
1001130812Smarcel
1002130812Smarcel      else if (regno ==  PR_REGNUM)
1003130812Smarcel	{
1004130812Smarcel	  sprintf (buf, ".PR %s\r", phex_nz (read_register (regno), 0));
1005130812Smarcel	  puts_e7000debug (buf);
1006130812Smarcel	}
1007130812Smarcel
1008130812Smarcel      else if (regno == GBR_REGNUM)
1009130812Smarcel	{
1010130812Smarcel	  sprintf (buf, ".GBR %s\r", phex_nz (read_register (regno), 0));
1011130812Smarcel	  puts_e7000debug (buf);
1012130812Smarcel	}
1013130812Smarcel
1014130812Smarcel      else if (regno == VBR_REGNUM)
1015130812Smarcel	{
1016130812Smarcel	  sprintf (buf, ".VBR %s\r", phex_nz (read_register (regno), 0));
1017130812Smarcel	  puts_e7000debug (buf);
1018130812Smarcel	}
1019130812Smarcel
1020130812Smarcel      else if (regno == MACH_REGNUM)
1021130812Smarcel	{
1022130812Smarcel	  sprintf (buf, ".MACH %s\r", phex_nz (read_register (regno), 0));
1023130812Smarcel	  puts_e7000debug (buf);
1024130812Smarcel	}
1025130812Smarcel
1026130812Smarcel      else if (regno == MACL_REGNUM)
1027130812Smarcel	{
1028130812Smarcel	  sprintf (buf, ".MACL %s\r", phex_nz (read_register (regno), 0));
1029130812Smarcel	  puts_e7000debug (buf);
1030130812Smarcel	}
1031130812Smarcel      else
1032130812Smarcel	{
1033130812Smarcel	  sprintf (buf, ".R%d %s\r", regno, phex_nz (read_register (regno), 0));
1034130812Smarcel	  puts_e7000debug (buf);
1035130812Smarcel	}
1036130812Smarcel    }
1037130812Smarcel
1038130812Smarcel  expect_prompt ();
1039130812Smarcel}
1040130812Smarcel
1041130812Smarcel/* Get ready to modify the registers array.  On machines which store
1042130812Smarcel   individual registers, this doesn't need to do anything.  On machines
1043130812Smarcel   which store all the registers in one fell swoop, this makes sure
1044130812Smarcel   that registers contains all the registers from the program being
1045130812Smarcel   debugged.  */
1046130812Smarcel
1047130812Smarcelstatic void
1048130812Smarcele7000_prepare_to_store (void)
1049130812Smarcel{
1050130812Smarcel  /* Do nothing, since we can store individual regs */
1051130812Smarcel}
1052130812Smarcel
1053130812Smarcelstatic void
1054130812Smarcele7000_files_info (struct target_ops *ops)
1055130812Smarcel{
1056130812Smarcel  printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name, baudrate);
1057130812Smarcel}
1058130812Smarcel
1059130812Smarcelstatic int
1060130812Smarcelstickbyte (char *where, unsigned int what)
1061130812Smarcel{
1062130812Smarcel  static CONST char digs[] = "0123456789ABCDEF";
1063130812Smarcel
1064130812Smarcel  where[0] = digs[(what >> 4) & 0xf];
1065130812Smarcel  where[1] = digs[(what & 0xf) & 0xf];
1066130812Smarcel
1067130812Smarcel  return what;
1068130812Smarcel}
1069130812Smarcel
1070130812Smarcel/* Write a small ammount of memory. */
1071130812Smarcel
1072130812Smarcelstatic int
1073130812Smarcelwrite_small (CORE_ADDR memaddr, unsigned char *myaddr, int len)
1074130812Smarcel{
1075130812Smarcel  int i;
1076130812Smarcel  char buf[200];
1077130812Smarcel
1078130812Smarcel  for (i = 0; i < len; i++)
1079130812Smarcel    {
1080130812Smarcel      if (((memaddr + i) & 3) == 0 && (i + 3 < len))
1081130812Smarcel	{
1082130812Smarcel	  /* Can be done with a long word */
1083130812Smarcel	  sprintf (buf, "m %s %x%02x%02x%02x;l\r",
1084130812Smarcel		   paddr_nz (memaddr + i),
1085130812Smarcel		   myaddr[i], myaddr[i + 1], myaddr[i + 2], myaddr[i + 3]);
1086130812Smarcel	  puts_e7000debug (buf);
1087130812Smarcel	  i += 3;
1088130812Smarcel	}
1089130812Smarcel      else
1090130812Smarcel	{
1091130812Smarcel	  sprintf (buf, "m %s %x\r", paddr_nz (memaddr + i), myaddr[i]);
1092130812Smarcel	  puts_e7000debug (buf);
1093130812Smarcel	}
1094130812Smarcel    }
1095130812Smarcel
1096130812Smarcel  expect_prompt ();
1097130812Smarcel
1098130812Smarcel  return len;
1099130812Smarcel}
1100130812Smarcel
1101130812Smarcel/* Write a large ammount of memory, this only works with the serial
1102130812Smarcel   mode enabled.  Command is sent as
1103130812Smarcel
1104130812Smarcel   il ;s:s\r     ->
1105130812Smarcel   <- il ;s:s\r
1106130812Smarcel   <-   ENQ
1107130812Smarcel   ACK          ->
1108130812Smarcel   <- LO s\r
1109130812Smarcel   Srecords...
1110130812Smarcel   ^Z           ->
1111130812Smarcel   <-   ENQ
1112130812Smarcel   ACK          ->
1113130812Smarcel   <-   :
1114130812Smarcel */
1115130812Smarcel
1116130812Smarcelstatic int
1117130812Smarcelwrite_large (CORE_ADDR memaddr, unsigned char *myaddr, int len)
1118130812Smarcel{
1119130812Smarcel  int i;
1120130812Smarcel#define maxstride  128
1121130812Smarcel  int stride;
1122130812Smarcel
1123130812Smarcel  puts_e7000debug ("IL ;S:FK\r");
1124130812Smarcel  expect (ENQSTRING);
1125130812Smarcel  putchar_e7000 (ACK);
1126130812Smarcel  expect ("LO FK\r");
1127130812Smarcel
1128130812Smarcel  for (i = 0; i < len; i += stride)
1129130812Smarcel    {
1130130812Smarcel      char compose[maxstride * 2 + 50];
1131130812Smarcel      int address = i + memaddr;
1132130812Smarcel      int j;
1133130812Smarcel      int check_sum;
1134130812Smarcel      int where = 0;
1135130812Smarcel      int alen;
1136130812Smarcel
1137130812Smarcel      stride = len - i;
1138130812Smarcel      if (stride > maxstride)
1139130812Smarcel	stride = maxstride;
1140130812Smarcel
1141130812Smarcel      compose[where++] = 'S';
1142130812Smarcel      check_sum = 0;
1143130812Smarcel      if (address >= 0xffffff)
1144130812Smarcel	alen = 4;
1145130812Smarcel      else if (address >= 0xffff)
1146130812Smarcel	alen = 3;
1147130812Smarcel      else
1148130812Smarcel	alen = 2;
1149130812Smarcel      /* Insert type. */
1150130812Smarcel      compose[where++] = alen - 1 + '0';
1151130812Smarcel      /* Insert length. */
1152130812Smarcel      check_sum += stickbyte (compose + where, alen + stride + 1);
1153130812Smarcel      where += 2;
1154130812Smarcel      while (alen > 0)
1155130812Smarcel	{
1156130812Smarcel	  alen--;
1157130812Smarcel	  check_sum += stickbyte (compose + where, address >> (8 * (alen)));
1158130812Smarcel	  where += 2;
1159130812Smarcel	}
1160130812Smarcel
1161130812Smarcel      for (j = 0; j < stride; j++)
1162130812Smarcel	{
1163130812Smarcel	  check_sum += stickbyte (compose + where, myaddr[i + j]);
1164130812Smarcel	  where += 2;
1165130812Smarcel	}
1166130812Smarcel      stickbyte (compose + where, ~check_sum);
1167130812Smarcel      where += 2;
1168130812Smarcel      compose[where++] = '\r';
1169130812Smarcel      compose[where++] = '\n';
1170130812Smarcel      compose[where++] = 0;
1171130812Smarcel
1172130812Smarcel      serial_write (e7000_desc, compose, where);
1173130812Smarcel      j = readchar (0);
1174130812Smarcel      if (j == -1)
1175130812Smarcel	{
1176130812Smarcel	  /* This is ok - nothing there */
1177130812Smarcel	}
1178130812Smarcel      else if (j == ENQ)
1179130812Smarcel	{
1180130812Smarcel	  /* Hmm, it's trying to tell us something */
1181130812Smarcel	  expect (":");
1182130812Smarcel	  error ("Error writing memory");
1183130812Smarcel	}
1184130812Smarcel      else
1185130812Smarcel	{
1186130812Smarcel	  printf_unfiltered ("@%d}@", j);
1187130812Smarcel	  while ((j = readchar (0)) > 0)
1188130812Smarcel	    {
1189130812Smarcel	      printf_unfiltered ("@{%d}@", j);
1190130812Smarcel	    }
1191130812Smarcel	}
1192130812Smarcel    }
1193130812Smarcel
1194130812Smarcel  /* Send the trailer record */
1195130812Smarcel  write_e7000 ("S70500000000FA\r");
1196130812Smarcel  putchar_e7000 (CTRLZ);
1197130812Smarcel  expect (ENQSTRING);
1198130812Smarcel  putchar_e7000 (ACK);
1199130812Smarcel  expect (":");
1200130812Smarcel
1201130812Smarcel  return len;
1202130812Smarcel}
1203130812Smarcel
1204130812Smarcel/* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1205130812Smarcel   memory at MEMADDR.  Returns length moved.
1206130812Smarcel
1207130812Smarcel   Can't use the Srecord load over ethernet, so don't use fast method
1208130812Smarcel   then.  */
1209130812Smarcel
1210130812Smarcelstatic int
1211130812Smarcele7000_write_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
1212130812Smarcel{
1213130812Smarcel  if (len < 16 || using_tcp || using_pc)
1214130812Smarcel    return write_small (memaddr, myaddr, len);
1215130812Smarcel  else
1216130812Smarcel    return write_large (memaddr, myaddr, len);
1217130812Smarcel}
1218130812Smarcel
1219130812Smarcel/* Read LEN bytes from inferior memory at MEMADDR.  Put the result
1220130812Smarcel   at debugger address MYADDR.  Returns length moved.
1221130812Smarcel
1222130812Smarcel   Small transactions we send
1223130812Smarcel   m <addr>;l
1224130812Smarcel   and receive
1225130812Smarcel   00000000 12345678 ?
1226130812Smarcel */
1227130812Smarcel
1228130812Smarcelstatic int
1229130812Smarcele7000_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
1230130812Smarcel{
1231130812Smarcel  int count;
1232130812Smarcel  int c;
1233130812Smarcel  int i;
1234130812Smarcel  char buf[200];
1235130812Smarcel  /* Starting address of this pass.  */
1236130812Smarcel
1237130812Smarcel/*  printf("READ INF %x %x %d\n", memaddr, myaddr, len); */
1238130812Smarcel  if (((memaddr - 1) + len) < memaddr)
1239130812Smarcel    {
1240130812Smarcel      errno = EIO;
1241130812Smarcel      return 0;
1242130812Smarcel    }
1243130812Smarcel
1244130812Smarcel  sprintf (buf, "m %s;l\r", paddr_nz (memaddr));
1245130812Smarcel  puts_e7000debug (buf);
1246130812Smarcel
1247130812Smarcel  for (count = 0; count < len; count += 4)
1248130812Smarcel    {
1249130812Smarcel      /* Suck away the address */
1250130812Smarcel      c = gch ();
1251130812Smarcel      while (c != ' ')
1252130812Smarcel	c = gch ();
1253130812Smarcel      c = gch ();
1254130812Smarcel      if (c == '*')
1255130812Smarcel	{			/* Some kind of error */
1256130812Smarcel	  puts_e7000debug (".\r");	/* Some errors leave us in memory input mode */
1257130812Smarcel	  expect_full_prompt ();
1258130812Smarcel	  return -1;
1259130812Smarcel	}
1260130812Smarcel      while (c != ' ')
1261130812Smarcel	c = gch ();
1262130812Smarcel
1263130812Smarcel      /* Now read in the data */
1264130812Smarcel      for (i = 0; i < 4; i++)
1265130812Smarcel	{
1266130812Smarcel	  int b = gbyte ();
1267130812Smarcel	  if (count + i < len)
1268130812Smarcel	    {
1269130812Smarcel	      myaddr[count + i] = b;
1270130812Smarcel	    }
1271130812Smarcel	}
1272130812Smarcel
1273130812Smarcel      /* Skip the trailing ? and send a . to end and a cr for more */
1274130812Smarcel      gch ();
1275130812Smarcel      gch ();
1276130812Smarcel      if (count + 4 >= len)
1277130812Smarcel	puts_e7000debug (".\r");
1278130812Smarcel      else
1279130812Smarcel	puts_e7000debug ("\r");
1280130812Smarcel
1281130812Smarcel    }
1282130812Smarcel  expect_prompt ();
1283130812Smarcel  return len;
1284130812Smarcel}
1285130812Smarcel
1286130812Smarcel
1287130812Smarcel
1288130812Smarcel/*
1289130812Smarcel   For large transfers we used to send
1290130812Smarcel
1291130812Smarcel
1292130812Smarcel   d <addr> <endaddr>\r
1293130812Smarcel
1294130812Smarcel   and receive
1295130812Smarcel   <ADDRESS>           <    D   A   T   A    >               <   ASCII CODE   >
1296130812Smarcel   00000000 5F FD FD FF DF 7F DF FF  01 00 01 00 02 00 08 04  "_..............."
1297130812Smarcel   00000010 FF D7 FF 7F D7 F1 7F FF  00 05 00 00 08 00 40 00  "..............@."
1298130812Smarcel   00000020 7F FD FF F7 7F FF FF F7  00 00 00 00 00 00 00 00  "................"
1299130812Smarcel
1300130812Smarcel   A cost in chars for each transaction of 80 + 5*n-bytes.
1301130812Smarcel
1302130812Smarcel   Large transactions could be done with the srecord load code, but
1303130812Smarcel   there is a pause for a second before dumping starts, which slows the
1304130812Smarcel   average rate down!
1305130812Smarcel */
1306130812Smarcel
1307130812Smarcelstatic int
1308130812Smarcele7000_read_inferior_memory_large (CORE_ADDR memaddr, unsigned char *myaddr,
1309130812Smarcel				  int len)
1310130812Smarcel{
1311130812Smarcel  int count;
1312130812Smarcel  int c;
1313130812Smarcel  char buf[200];
1314130812Smarcel
1315130812Smarcel  /* Starting address of this pass.  */
1316130812Smarcel
1317130812Smarcel  if (((memaddr - 1) + len) < memaddr)
1318130812Smarcel    {
1319130812Smarcel      errno = EIO;
1320130812Smarcel      return 0;
1321130812Smarcel    }
1322130812Smarcel
1323130812Smarcel  sprintf (buf, "d %s %s\r", paddr_nz (memaddr), paddr_nz (memaddr + len - 1));
1324130812Smarcel  puts_e7000debug (buf);
1325130812Smarcel
1326130812Smarcel  count = 0;
1327130812Smarcel  c = gch ();
1328130812Smarcel
1329130812Smarcel  /* skip down to the first ">" */
1330130812Smarcel  while (c != '>')
1331130812Smarcel    c = gch ();
1332130812Smarcel  /* now skip to the end of that line */
1333130812Smarcel  while (c != '\r')
1334130812Smarcel    c = gch ();
1335130812Smarcel  c = gch ();
1336130812Smarcel
1337130812Smarcel  while (count < len)
1338130812Smarcel    {
1339130812Smarcel      /* get rid of any white space before the address */
1340130812Smarcel      while (c <= ' ')
1341130812Smarcel	c = gch ();
1342130812Smarcel
1343130812Smarcel      /* Skip the address */
1344130812Smarcel      get_hex (&c);
1345130812Smarcel
1346130812Smarcel      /* read in the bytes on the line */
1347130812Smarcel      while (c != '"' && count < len)
1348130812Smarcel	{
1349130812Smarcel	  if (c == ' ')
1350130812Smarcel	    c = gch ();
1351130812Smarcel	  else
1352130812Smarcel	    {
1353130812Smarcel	      myaddr[count++] = get_hex (&c);
1354130812Smarcel	    }
1355130812Smarcel	}
1356130812Smarcel      /* throw out the rest of the line */
1357130812Smarcel      while (c != '\r')
1358130812Smarcel	c = gch ();
1359130812Smarcel    }
1360130812Smarcel
1361130812Smarcel  /* wait for the ":" prompt */
1362130812Smarcel  while (c != ':')
1363130812Smarcel    c = gch ();
1364130812Smarcel
1365130812Smarcel  return len;
1366130812Smarcel}
1367130812Smarcel
1368130812Smarcel#if 0
1369130812Smarcel
1370130812Smarcelstatic int
1371130812Smarcelfast_but_for_the_pause_e7000_read_inferior_memory (CORE_ADDR memaddr,
1372130812Smarcel						   char *myaddr, int len)
1373130812Smarcel{
1374130812Smarcel  int loop;
1375130812Smarcel  int c;
1376130812Smarcel  char buf[200];
1377130812Smarcel
1378130812Smarcel  if (((memaddr - 1) + len) < memaddr)
1379130812Smarcel    {
1380130812Smarcel      errno = EIO;
1381130812Smarcel      return 0;
1382130812Smarcel    }
1383130812Smarcel
1384130812Smarcel  sprintf (buf, "is %x@%x:s\r", memaddr, len);
1385130812Smarcel  puts_e7000debug (buf);
1386130812Smarcel  gch ();
1387130812Smarcel  c = gch ();
1388130812Smarcel  if (c != ENQ)
1389130812Smarcel    {
1390130812Smarcel      /* Got an error */
1391130812Smarcel      error ("Memory read error");
1392130812Smarcel    }
1393130812Smarcel  putchar_e7000 (ACK);
1394130812Smarcel  expect ("SV s");
1395130812Smarcel  loop = 1;
1396130812Smarcel  while (loop)
1397130812Smarcel    {
1398130812Smarcel      int type;
1399130812Smarcel      int length;
1400130812Smarcel      int addr;
1401130812Smarcel      int i;
1402130812Smarcel
1403130812Smarcel      c = gch ();
1404130812Smarcel      switch (c)
1405130812Smarcel	{
1406130812Smarcel	case ENQ:		/* ENQ, at the end */
1407130812Smarcel	  loop = 0;
1408130812Smarcel	  break;
1409130812Smarcel	case 'S':
1410130812Smarcel	  /* Start of an Srecord */
1411130812Smarcel	  type = gch ();
1412130812Smarcel	  length = gbyte ();
1413130812Smarcel	  switch (type)
1414130812Smarcel	    {
1415130812Smarcel	    case '7':		/* Termination record, ignore */
1416130812Smarcel	    case '0':
1417130812Smarcel	    case '8':
1418130812Smarcel	    case '9':
1419130812Smarcel	      /* Header record - ignore it */
1420130812Smarcel	      while (length--)
1421130812Smarcel		{
1422130812Smarcel		  gbyte ();
1423130812Smarcel		}
1424130812Smarcel	      break;
1425130812Smarcel	    case '1':
1426130812Smarcel	    case '2':
1427130812Smarcel	    case '3':
1428130812Smarcel	      {
1429130812Smarcel		int alen;
1430130812Smarcel
1431130812Smarcel		alen = type - '0' + 1;
1432130812Smarcel		addr = 0;
1433130812Smarcel		while (alen--)
1434130812Smarcel		  {
1435130812Smarcel		    addr = (addr << 8) + gbyte ();
1436130812Smarcel		    length--;
1437130812Smarcel		  }
1438130812Smarcel
1439130812Smarcel		for (i = 0; i < length - 1; i++)
1440130812Smarcel		  myaddr[i + addr - memaddr] = gbyte ();
1441130812Smarcel
1442130812Smarcel		gbyte ();	/* Ignore checksum */
1443130812Smarcel	      }
1444130812Smarcel	    }
1445130812Smarcel	}
1446130812Smarcel    }
1447130812Smarcel
1448130812Smarcel  putchar_e7000 (ACK);
1449130812Smarcel  expect ("TOP ADDRESS =");
1450130812Smarcel  expect ("END ADDRESS =");
1451130812Smarcel  expect (":");
1452130812Smarcel
1453130812Smarcel  return len;
1454130812Smarcel}
1455130812Smarcel
1456130812Smarcel#endif
1457130812Smarcel
1458130812Smarcel/* Transfer LEN bytes between GDB address MYADDR and target address
1459130812Smarcel   MEMADDR.  If WRITE is non-zero, transfer them to the target,
1460130812Smarcel   otherwise transfer them from the target.  TARGET is unused.
1461130812Smarcel
1462130812Smarcel   Returns the number of bytes transferred. */
1463130812Smarcel
1464130812Smarcelstatic int
1465130812Smarcele7000_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len,
1466130812Smarcel			    int write, struct mem_attrib *attrib,
1467130812Smarcel			    struct target_ops *target)
1468130812Smarcel{
1469130812Smarcel  if (write)
1470130812Smarcel    return e7000_write_inferior_memory (memaddr, myaddr, len);
1471130812Smarcel  else if (len < 16)
1472130812Smarcel    return e7000_read_inferior_memory (memaddr, myaddr, len);
1473130812Smarcel  else
1474130812Smarcel    return e7000_read_inferior_memory_large (memaddr, myaddr, len);
1475130812Smarcel}
1476130812Smarcel
1477130812Smarcelstatic void
1478130812Smarcele7000_kill (void)
1479130812Smarcel{
1480130812Smarcel}
1481130812Smarcel
1482130812Smarcelstatic void
1483130812Smarcele7000_load (char *args, int from_tty)
1484130812Smarcel{
1485130812Smarcel  struct cleanup *old_chain;
1486130812Smarcel  asection *section;
1487130812Smarcel  bfd *pbfd;
1488130812Smarcel  bfd_vma entry;
1489130812Smarcel#define WRITESIZE 0x1000
1490130812Smarcel  char buf[2 + 4 + 4 + WRITESIZE];	/* `DT' + <addr> + <len> + <data> */
1491130812Smarcel  char *filename;
1492130812Smarcel  int quiet;
1493130812Smarcel  int nostart;
1494130812Smarcel  time_t start_time, end_time;	/* Start and end times of download */
1495130812Smarcel  unsigned long data_count;	/* Number of bytes transferred to memory */
1496130812Smarcel  int oldtimeout = timeout;
1497130812Smarcel
1498130812Smarcel  timeout = remote_timeout;
1499130812Smarcel
1500130812Smarcel
1501130812Smarcel  /* FIXME! change test to test for type of download */
1502130812Smarcel  if (!using_tcp)
1503130812Smarcel    {
1504130812Smarcel      generic_load (args, from_tty);
1505130812Smarcel      return;
1506130812Smarcel    }
1507130812Smarcel
1508130812Smarcel  /* for direct tcp connections, we can do a fast binary download */
1509130812Smarcel  buf[0] = 'D';
1510130812Smarcel  buf[1] = 'T';
1511130812Smarcel  quiet = 0;
1512130812Smarcel  nostart = 0;
1513130812Smarcel  filename = NULL;
1514130812Smarcel
1515130812Smarcel  while (*args != '\000')
1516130812Smarcel    {
1517130812Smarcel      char *arg;
1518130812Smarcel
1519130812Smarcel      while (isspace (*args))
1520130812Smarcel	args++;
1521130812Smarcel
1522130812Smarcel      arg = args;
1523130812Smarcel
1524130812Smarcel      while ((*args != '\000') && !isspace (*args))
1525130812Smarcel	args++;
1526130812Smarcel
1527130812Smarcel      if (*args != '\000')
1528130812Smarcel	*args++ = '\000';
1529130812Smarcel
1530130812Smarcel      if (*arg != '-')
1531130812Smarcel	filename = arg;
1532130812Smarcel      else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
1533130812Smarcel	quiet = 1;
1534130812Smarcel      else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
1535130812Smarcel	nostart = 1;
1536130812Smarcel      else
1537130812Smarcel	error ("unknown option `%s'", arg);
1538130812Smarcel    }
1539130812Smarcel
1540130812Smarcel  if (!filename)
1541130812Smarcel    filename = get_exec_file (1);
1542130812Smarcel
1543130812Smarcel  pbfd = bfd_openr (filename, gnutarget);
1544130812Smarcel  if (pbfd == NULL)
1545130812Smarcel    {
1546130812Smarcel      perror_with_name (filename);
1547130812Smarcel      return;
1548130812Smarcel    }
1549130812Smarcel  old_chain = make_cleanup_bfd_close (pbfd);
1550130812Smarcel
1551130812Smarcel  if (!bfd_check_format (pbfd, bfd_object))
1552130812Smarcel    error ("\"%s\" is not an object file: %s", filename,
1553130812Smarcel	   bfd_errmsg (bfd_get_error ()));
1554130812Smarcel
1555130812Smarcel  start_time = time (NULL);
1556130812Smarcel  data_count = 0;
1557130812Smarcel
1558130812Smarcel  puts_e7000debug ("mw\r");
1559130812Smarcel
1560130812Smarcel  expect ("\nOK");
1561130812Smarcel
1562130812Smarcel  for (section = pbfd->sections; section; section = section->next)
1563130812Smarcel    {
1564130812Smarcel      if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
1565130812Smarcel	{
1566130812Smarcel	  bfd_vma section_address;
1567130812Smarcel	  bfd_size_type section_size;
1568130812Smarcel	  file_ptr fptr;
1569130812Smarcel
1570130812Smarcel	  section_address = bfd_get_section_vma (pbfd, section);
1571218822Sdim	  section_size = bfd_get_section_size (section);
1572130812Smarcel
1573130812Smarcel	  if (!quiet)
1574130812Smarcel	    printf_filtered ("[Loading section %s at 0x%s (%s bytes)]\n",
1575130812Smarcel			     bfd_get_section_name (pbfd, section),
1576130812Smarcel			     paddr_nz (section_address),
1577130812Smarcel			     paddr_u (section_size));
1578130812Smarcel
1579130812Smarcel	  fptr = 0;
1580130812Smarcel
1581130812Smarcel	  data_count += section_size;
1582130812Smarcel
1583130812Smarcel	  while (section_size > 0)
1584130812Smarcel	    {
1585130812Smarcel	      int count;
1586130812Smarcel	      static char inds[] = "|/-\\";
1587130812Smarcel	      static int k = 0;
1588130812Smarcel
1589130812Smarcel	      QUIT;
1590130812Smarcel
1591130812Smarcel	      count = min (section_size, WRITESIZE);
1592130812Smarcel
1593130812Smarcel	      buf[2] = section_address >> 24;
1594130812Smarcel	      buf[3] = section_address >> 16;
1595130812Smarcel	      buf[4] = section_address >> 8;
1596130812Smarcel	      buf[5] = section_address;
1597130812Smarcel
1598130812Smarcel	      buf[6] = count >> 24;
1599130812Smarcel	      buf[7] = count >> 16;
1600130812Smarcel	      buf[8] = count >> 8;
1601130812Smarcel	      buf[9] = count;
1602130812Smarcel
1603130812Smarcel	      bfd_get_section_contents (pbfd, section, buf + 10, fptr, count);
1604130812Smarcel
1605130812Smarcel	      if (serial_write (e7000_desc, buf, count + 10))
1606130812Smarcel		fprintf_unfiltered (gdb_stderr,
1607130812Smarcel				    "e7000_load: serial_write failed: %s\n",
1608130812Smarcel				    safe_strerror (errno));
1609130812Smarcel
1610130812Smarcel	      expect ("OK");
1611130812Smarcel
1612130812Smarcel	      if (!quiet)
1613130812Smarcel		{
1614130812Smarcel		  printf_unfiltered ("\r%c", inds[k++ % 4]);
1615130812Smarcel		  gdb_flush (gdb_stdout);
1616130812Smarcel		}
1617130812Smarcel
1618130812Smarcel	      section_address += count;
1619130812Smarcel	      fptr += count;
1620130812Smarcel	      section_size -= count;
1621130812Smarcel	    }
1622130812Smarcel	}
1623130812Smarcel    }
1624130812Smarcel
1625130812Smarcel  write_e7000 ("ED");
1626130812Smarcel
1627130812Smarcel  expect_prompt ();
1628130812Smarcel
1629130812Smarcel  end_time = time (NULL);
1630130812Smarcel
1631130812Smarcel/* Finally, make the PC point at the start address */
1632130812Smarcel
1633130812Smarcel  if (exec_bfd)
1634130812Smarcel    write_pc (bfd_get_start_address (exec_bfd));
1635130812Smarcel
1636130812Smarcel  inferior_ptid = null_ptid;	/* No process now */
1637130812Smarcel
1638130812Smarcel/* This is necessary because many things were based on the PC at the time that
1639130812Smarcel   we attached to the monitor, which is no longer valid now that we have loaded
1640130812Smarcel   new code (and just changed the PC).  Another way to do this might be to call
1641130812Smarcel   normal_stop, except that the stack may not be valid, and things would get
1642130812Smarcel   horribly confused... */
1643130812Smarcel
1644130812Smarcel  clear_symtab_users ();
1645130812Smarcel
1646130812Smarcel  if (!nostart)
1647130812Smarcel    {
1648130812Smarcel      entry = bfd_get_start_address (pbfd);
1649130812Smarcel
1650130812Smarcel      if (!quiet)
1651130812Smarcel	printf_unfiltered ("[Starting %s at 0x%s]\n", filename, paddr_nz (entry));
1652130812Smarcel
1653130812Smarcel/*      start_routine (entry); */
1654130812Smarcel    }
1655130812Smarcel
1656130812Smarcel  report_transfer_performance (data_count, start_time, end_time);
1657130812Smarcel
1658130812Smarcel  do_cleanups (old_chain);
1659130812Smarcel  timeout = oldtimeout;
1660130812Smarcel}
1661130812Smarcel
1662130812Smarcel/* Clean up when a program exits.
1663130812Smarcel
1664130812Smarcel   The program actually lives on in the remote processor's RAM, and may be
1665130812Smarcel   run again without a download.  Don't leave it full of breakpoint
1666130812Smarcel   instructions.  */
1667130812Smarcel
1668130812Smarcelstatic void
1669130812Smarcele7000_mourn_inferior (void)
1670130812Smarcel{
1671130812Smarcel  remove_breakpoints ();
1672130812Smarcel  unpush_target (&e7000_ops);
1673130812Smarcel  generic_mourn_inferior ();	/* Do all the proper things now */
1674130812Smarcel}
1675130812Smarcel
1676130812Smarcel#define MAX_BREAKPOINTS 200
1677130812Smarcel#ifdef  HARD_BREAKPOINTS
1678130812Smarcel#define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 :  MAX_BREAKPOINTS)
1679130812Smarcel#else
1680130812Smarcel#define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
1681130812Smarcel#endif
1682130812Smarcel
1683130812Smarcel/* Since we can change to soft breakpoints dynamically, we must define
1684130812Smarcel   more than enough.  Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
1685130812Smarcelstatic CORE_ADDR breakaddr[MAX_BREAKPOINTS] =
1686130812Smarcel{0};
1687130812Smarcel
1688130812Smarcelstatic int
1689130812Smarcele7000_insert_breakpoint (CORE_ADDR addr, char *shadow)
1690130812Smarcel{
1691130812Smarcel  int i;
1692130812Smarcel  char buf[200];
1693130812Smarcel#if 0
1694130812Smarcel  static char nop[2] = NOP;
1695130812Smarcel#endif
1696130812Smarcel
1697130812Smarcel  for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++)
1698130812Smarcel    if (breakaddr[i] == 0)
1699130812Smarcel      {
1700130812Smarcel	breakaddr[i] = addr;
1701130812Smarcel	/* Save old contents, and insert a nop in the space */
1702130812Smarcel#ifdef HARD_BREAKPOINTS
1703130812Smarcel	if (BC_BREAKPOINTS)
1704130812Smarcel	  {
1705130812Smarcel	    sprintf (buf, "BC%d A=%s\r", i + 1, paddr_nz (addr));
1706130812Smarcel	    puts_e7000debug (buf);
1707130812Smarcel	  }
1708130812Smarcel	else
1709130812Smarcel	  {
1710130812Smarcel	    sprintf (buf, "B %s\r", paddr_nz (addr));
1711130812Smarcel	    puts_e7000debug (buf);
1712130812Smarcel	  }
1713130812Smarcel#else
1714130812Smarcel#if 0
1715130812Smarcel	e7000_read_inferior_memory (addr, shadow, 2);
1716130812Smarcel	e7000_write_inferior_memory (addr, nop, 2);
1717130812Smarcel#endif
1718130812Smarcel
1719130812Smarcel	sprintf (buf, "B %x\r", addr);
1720130812Smarcel	puts_e7000debug (buf);
1721130812Smarcel#endif
1722130812Smarcel	expect_prompt ();
1723130812Smarcel	return 0;
1724130812Smarcel      }
1725130812Smarcel
1726130812Smarcel  error ("Too many breakpoints ( > %d) for the E7000\n",
1727130812Smarcel	 MAX_E7000DEBUG_BREAKPOINTS);
1728130812Smarcel  return 1;
1729130812Smarcel}
1730130812Smarcel
1731130812Smarcelstatic int
1732130812Smarcele7000_remove_breakpoint (CORE_ADDR addr, char *shadow)
1733130812Smarcel{
1734130812Smarcel  int i;
1735130812Smarcel  char buf[200];
1736130812Smarcel
1737130812Smarcel  for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++)
1738130812Smarcel    if (breakaddr[i] == addr)
1739130812Smarcel      {
1740130812Smarcel	breakaddr[i] = 0;
1741130812Smarcel#ifdef HARD_BREAKPOINTS
1742130812Smarcel	if (BC_BREAKPOINTS)
1743130812Smarcel	  {
1744130812Smarcel	    sprintf (buf, "BC%d - \r", i + 1);
1745130812Smarcel	    puts_e7000debug (buf);
1746130812Smarcel	  }
1747130812Smarcel	else
1748130812Smarcel	  {
1749130812Smarcel	    sprintf (buf, "B - %s\r", paddr_nz (addr));
1750130812Smarcel	    puts_e7000debug (buf);
1751130812Smarcel	  }
1752130812Smarcel	expect_prompt ();
1753130812Smarcel#else
1754130812Smarcel	sprintf (buf, "B - %s\r", paddr_nz (addr));
1755130812Smarcel	puts_e7000debug (buf);
1756130812Smarcel	expect_prompt ();
1757130812Smarcel
1758130812Smarcel#if 0
1759130812Smarcel	/* Replace the insn under the break */
1760130812Smarcel	e7000_write_inferior_memory (addr, shadow, 2);
1761130812Smarcel#endif
1762130812Smarcel#endif
1763130812Smarcel
1764130812Smarcel	return 0;
1765130812Smarcel      }
1766130812Smarcel
1767130812Smarcel  warning ("Can't find breakpoint associated with 0x%s\n", paddr_nz (addr));
1768130812Smarcel  return 1;
1769130812Smarcel}
1770130812Smarcel
1771130812Smarcel/* Put a command string, in args, out to STDBUG.  Output from STDBUG
1772130812Smarcel   is placed on the users terminal until the prompt is seen. */
1773130812Smarcel
1774130812Smarcelstatic void
1775130812Smarcele7000_command (char *args, int fromtty)
1776130812Smarcel{
1777130812Smarcel  /* FIXME: arbitrary limit on length of args.  */
1778130812Smarcel  char buf[200];
1779130812Smarcel
1780130812Smarcel  echo = 0;
1781130812Smarcel
1782130812Smarcel  if (!e7000_desc)
1783130812Smarcel    error ("e7000 target not open.");
1784130812Smarcel  if (!args)
1785130812Smarcel    {
1786130812Smarcel      puts_e7000debug ("\r");
1787130812Smarcel    }
1788130812Smarcel  else
1789130812Smarcel    {
1790130812Smarcel      sprintf (buf, "%s\r", args);
1791130812Smarcel      puts_e7000debug (buf);
1792130812Smarcel    }
1793130812Smarcel
1794130812Smarcel  echo++;
1795130812Smarcel  ctrl_c = 2;
1796130812Smarcel  expect_full_prompt ();
1797130812Smarcel  echo--;
1798130812Smarcel  ctrl_c = 0;
1799130812Smarcel  printf_unfiltered ("\n");
1800130812Smarcel
1801130812Smarcel  /* Who knows what the command did... */
1802130812Smarcel  registers_changed ();
1803130812Smarcel}
1804130812Smarcel
1805130812Smarcel
1806130812Smarcelstatic void
1807130812Smarcele7000_drain_command (char *args, int fromtty)
1808130812Smarcel{
1809130812Smarcel  int c;
1810130812Smarcel
1811130812Smarcel  puts_e7000debug ("end\r");
1812130812Smarcel  putchar_e7000 (CTRLC);
1813130812Smarcel
1814130812Smarcel  while ((c = readchar (1)) != -1)
1815130812Smarcel    {
1816130812Smarcel      if (quit_flag)
1817130812Smarcel	{
1818130812Smarcel	  putchar_e7000 (CTRLC);
1819130812Smarcel	  quit_flag = 0;
1820130812Smarcel	}
1821130812Smarcel      if (c > ' ' && c < 127)
1822130812Smarcel	printf_unfiltered ("%c", c & 0xff);
1823130812Smarcel      else
1824130812Smarcel	printf_unfiltered ("<%x>", c & 0xff);
1825130812Smarcel    }
1826130812Smarcel}
1827130812Smarcel
1828130812Smarcel#define NITEMS 7
1829130812Smarcel
1830130812Smarcelstatic int
1831130812Smarcelwhy_stop (void)
1832130812Smarcel{
1833130812Smarcel  static char *strings[NITEMS] =
1834130812Smarcel  {
1835130812Smarcel    "STEP NORMAL",
1836130812Smarcel    "BREAK POINT",
1837130812Smarcel    "BREAK KEY",
1838130812Smarcel    "BREAK CONDI",
1839130812Smarcel    "CYCLE ACCESS",
1840130812Smarcel    "ILLEGAL INSTRUCTION",
1841130812Smarcel    "WRITE PROTECT",
1842130812Smarcel  };
1843130812Smarcel  char *p[NITEMS];
1844130812Smarcel  int c;
1845130812Smarcel  int i;
1846130812Smarcel
1847130812Smarcel  for (i = 0; i < NITEMS; ++i)
1848130812Smarcel    p[i] = strings[i];
1849130812Smarcel
1850130812Smarcel  c = gch ();
1851130812Smarcel  while (1)
1852130812Smarcel    {
1853130812Smarcel      for (i = 0; i < NITEMS; i++)
1854130812Smarcel	{
1855130812Smarcel	  if (c == *(p[i]))
1856130812Smarcel	    {
1857130812Smarcel	      p[i]++;
1858130812Smarcel	      if (*(p[i]) == 0)
1859130812Smarcel		{
1860130812Smarcel		  /* found one of the choices */
1861130812Smarcel		  return i;
1862130812Smarcel		}
1863130812Smarcel	    }
1864130812Smarcel	  else
1865130812Smarcel	    p[i] = strings[i];
1866130812Smarcel	}
1867130812Smarcel
1868130812Smarcel      c = gch ();
1869130812Smarcel    }
1870130812Smarcel}
1871130812Smarcel
1872130812Smarcel/* Suck characters, if a string match, then return the strings index
1873130812Smarcel   otherwise echo them.  */
1874130812Smarcel
1875130812Smarcelstatic int
1876130812Smarcelexpect_n (char **strings)
1877130812Smarcel{
1878130812Smarcel  char *(ptr[10]);
1879130812Smarcel  int n;
1880130812Smarcel  int c;
1881130812Smarcel  char saveaway[100];
1882130812Smarcel  char *buffer = saveaway;
1883130812Smarcel  /* Count number of expect strings  */
1884130812Smarcel
1885130812Smarcel  for (n = 0; strings[n]; n++)
1886130812Smarcel    {
1887130812Smarcel      ptr[n] = strings[n];
1888130812Smarcel    }
1889130812Smarcel
1890130812Smarcel  while (1)
1891130812Smarcel    {
1892130812Smarcel      int i;
1893130812Smarcel      int gotone = 0;
1894130812Smarcel
1895130812Smarcel      c = readchar (1);
1896130812Smarcel      if (c == -1)
1897130812Smarcel	{
1898130812Smarcel	  printf_unfiltered ("[waiting for e7000...]\n");
1899130812Smarcel	}
1900130812Smarcel#ifdef __GO32__
1901130812Smarcel      if (kbhit ())
1902130812Smarcel	{
1903130812Smarcel	  int k = getkey ();
1904130812Smarcel
1905130812Smarcel	  if (k == 1)
1906130812Smarcel	    quit_flag = 1;
1907130812Smarcel	}
1908130812Smarcel#endif
1909130812Smarcel      if (quit_flag)
1910130812Smarcel	{
1911130812Smarcel	  putchar_e7000 (CTRLC);	/* interrupt the running program */
1912130812Smarcel	  quit_flag = 0;
1913130812Smarcel	}
1914130812Smarcel
1915130812Smarcel      for (i = 0; i < n; i++)
1916130812Smarcel	{
1917130812Smarcel	  if (c == ptr[i][0])
1918130812Smarcel	    {
1919130812Smarcel	      ptr[i]++;
1920130812Smarcel	      if (ptr[i][0] == 0)
1921130812Smarcel		{
1922130812Smarcel		  /* Gone all the way */
1923130812Smarcel		  return i;
1924130812Smarcel		}
1925130812Smarcel	      gotone = 1;
1926130812Smarcel	    }
1927130812Smarcel	  else
1928130812Smarcel	    {
1929130812Smarcel	      ptr[i] = strings[i];
1930130812Smarcel	    }
1931130812Smarcel	}
1932130812Smarcel
1933130812Smarcel      if (gotone)
1934130812Smarcel	{
1935130812Smarcel	  /* Save it up incase we find that there was no match */
1936130812Smarcel	  *buffer++ = c;
1937130812Smarcel	}
1938130812Smarcel      else
1939130812Smarcel	{
1940130812Smarcel	  if (buffer != saveaway)
1941130812Smarcel	    {
1942130812Smarcel	      *buffer++ = 0;
1943130812Smarcel	      printf_unfiltered ("%s", buffer);
1944130812Smarcel	      buffer = saveaway;
1945130812Smarcel	    }
1946130812Smarcel	  if (c != -1)
1947130812Smarcel	    {
1948130812Smarcel	      putchar_unfiltered (c);
1949130812Smarcel	      gdb_flush (gdb_stdout);
1950130812Smarcel	    }
1951130812Smarcel	}
1952130812Smarcel    }
1953130812Smarcel}
1954130812Smarcel
1955130812Smarcel/* We subtract two from the pc here rather than use
1956130812Smarcel   DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the
1957130812Smarcel   pc, and the simulators never do. */
1958130812Smarcel
1959130812Smarcelstatic void
1960130812Smarcelsub2_from_pc (void)
1961130812Smarcel{
1962130812Smarcel  char buf[4];
1963130812Smarcel  char buf2[200];
1964130812Smarcel
1965130812Smarcel  store_signed_integer (buf,
1966130812Smarcel			DEPRECATED_REGISTER_RAW_SIZE (PC_REGNUM),
1967130812Smarcel			read_register (PC_REGNUM) - 2);
1968130812Smarcel  supply_register (PC_REGNUM, buf);
1969130812Smarcel  sprintf (buf2, ".PC %s\r", phex_nz (read_register (PC_REGNUM), 0));
1970130812Smarcel  puts_e7000debug (buf2);
1971130812Smarcel}
1972130812Smarcel
1973130812Smarcel#define WAS_SLEEP 0
1974130812Smarcel#define WAS_INT 1
1975130812Smarcel#define WAS_RUNNING 2
1976130812Smarcel#define WAS_OTHER 3
1977130812Smarcel
1978130812Smarcelstatic char *estrings[] =
1979130812Smarcel{
1980130812Smarcel  "** SLEEP",
1981130812Smarcel  "BREAK !",
1982130812Smarcel  "** PC",
1983130812Smarcel  "PC",
1984130812Smarcel  NULL
1985130812Smarcel};
1986130812Smarcel
1987130812Smarcel/* Wait until the remote machine stops, then return, storing status in
1988130812Smarcel   STATUS just as `wait' would.  */
1989130812Smarcel
1990130812Smarcelstatic ptid_t
1991130812Smarcele7000_wait (ptid_t ptid, struct target_waitstatus *status)
1992130812Smarcel{
1993130812Smarcel  int stop_reason;
1994130812Smarcel  int regno;
1995130812Smarcel  int running_count = 0;
1996130812Smarcel  int had_sleep = 0;
1997130812Smarcel  int loop = 1;
1998130812Smarcel  char *wanted_nopc = NULL;
1999130812Smarcel
2000130812Smarcel  /* Then echo chars until PC= string seen */
2001130812Smarcel  gch ();			/* Drop cr */
2002130812Smarcel  gch ();			/* and space */
2003130812Smarcel
2004130812Smarcel  while (loop)
2005130812Smarcel    {
2006130812Smarcel      switch (expect_n (estrings))
2007130812Smarcel	{
2008130812Smarcel	case WAS_OTHER:
2009130812Smarcel	  /* how did this happen ? */
2010130812Smarcel	  loop = 0;
2011130812Smarcel	  break;
2012130812Smarcel	case WAS_SLEEP:
2013130812Smarcel	  had_sleep = 1;
2014130812Smarcel	  putchar_e7000 (CTRLC);
2015130812Smarcel	  loop = 0;
2016130812Smarcel	  break;
2017130812Smarcel	case WAS_INT:
2018130812Smarcel	  loop = 0;
2019130812Smarcel	  break;
2020130812Smarcel	case WAS_RUNNING:
2021130812Smarcel	  running_count++;
2022130812Smarcel	  if (running_count == 20)
2023130812Smarcel	    {
2024130812Smarcel	      printf_unfiltered ("[running...]\n");
2025130812Smarcel	      running_count = 0;
2026130812Smarcel	    }
2027130812Smarcel	  break;
2028130812Smarcel	default:
2029130812Smarcel	  /* error? */
2030130812Smarcel	  break;
2031130812Smarcel	}
2032130812Smarcel    }
2033130812Smarcel
2034130812Smarcel  /* Skip till the PC= */
2035130812Smarcel  expect ("=");
2036130812Smarcel
2037130812Smarcel  if (TARGET_ARCHITECTURE->arch == bfd_arch_sh)
2038130812Smarcel    {
2039130812Smarcel      wanted_nopc = want_nopc_sh;
2040130812Smarcel      switch (TARGET_ARCHITECTURE->mach)
2041130812Smarcel	{
2042130812Smarcel	case bfd_mach_sh3:
2043130812Smarcel	case bfd_mach_sh3e:
2044130812Smarcel	case bfd_mach_sh4:
2045130812Smarcel	  wanted_nopc = want_nopc_sh3;
2046130812Smarcel	}
2047130812Smarcel    }
2048130812Smarcel  if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300)
2049130812Smarcel    {
2050130812Smarcel      wanted_nopc = want_nopc_h8300h;
2051130812Smarcel      switch (TARGET_ARCHITECTURE->mach)
2052130812Smarcel	{
2053130812Smarcel	case bfd_mach_h8300s:
2054130812Smarcel	case bfd_mach_h8300sn:
2055130812Smarcel	case bfd_mach_h8300sx:
2056130812Smarcel	case bfd_mach_h8300sxn:
2057130812Smarcel	  wanted_nopc = want_nopc_h8300s;
2058130812Smarcel	}
2059130812Smarcel    }
2060130812Smarcel  fetch_regs_from_dump (gch, wanted_nopc);
2061130812Smarcel
2062130812Smarcel  /* And supply the extra ones the simulator uses */
2063130812Smarcel  for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
2064130812Smarcel    {
2065130812Smarcel      int buf = 0;
2066130812Smarcel      supply_register (regno, (char *) &buf);
2067130812Smarcel    }
2068130812Smarcel
2069130812Smarcel  stop_reason = why_stop ();
2070130812Smarcel  expect_full_prompt ();
2071130812Smarcel
2072130812Smarcel  status->kind = TARGET_WAITKIND_STOPPED;
2073130812Smarcel  status->value.sig = TARGET_SIGNAL_TRAP;
2074130812Smarcel
2075130812Smarcel  switch (stop_reason)
2076130812Smarcel    {
2077130812Smarcel    case 1:			/* Breakpoint */
2078130812Smarcel      write_pc (read_pc ());	/* PC is always off by 2 for breakpoints */
2079130812Smarcel      status->value.sig = TARGET_SIGNAL_TRAP;
2080130812Smarcel      break;
2081130812Smarcel    case 0:			/* Single step */
2082130812Smarcel      status->value.sig = TARGET_SIGNAL_TRAP;
2083130812Smarcel      break;
2084130812Smarcel    case 2:			/* Interrupt */
2085130812Smarcel      if (had_sleep)
2086130812Smarcel	{
2087130812Smarcel	  status->value.sig = TARGET_SIGNAL_TRAP;
2088130812Smarcel	  sub2_from_pc ();
2089130812Smarcel	}
2090130812Smarcel      else
2091130812Smarcel	{
2092130812Smarcel	  status->value.sig = TARGET_SIGNAL_INT;
2093130812Smarcel	}
2094130812Smarcel      break;
2095130812Smarcel    case 3:
2096130812Smarcel      break;
2097130812Smarcel    case 4:
2098130812Smarcel      printf_unfiltered ("a cycle address error?\n");
2099130812Smarcel      status->value.sig = TARGET_SIGNAL_UNKNOWN;
2100130812Smarcel      break;
2101130812Smarcel    case 5:
2102130812Smarcel      status->value.sig = TARGET_SIGNAL_ILL;
2103130812Smarcel      break;
2104130812Smarcel    case 6:
2105130812Smarcel      status->value.sig = TARGET_SIGNAL_SEGV;
2106130812Smarcel      break;
2107130812Smarcel    case 7:			/* Anything else (NITEMS + 1) */
2108130812Smarcel      printf_unfiltered ("a write protect error?\n");
2109130812Smarcel      status->value.sig = TARGET_SIGNAL_UNKNOWN;
2110130812Smarcel      break;
2111130812Smarcel    default:
2112130812Smarcel      /* Get the user's attention - this should never happen. */
2113130812Smarcel      internal_error (__FILE__, __LINE__, "failed internal consistency check");
2114130812Smarcel    }
2115130812Smarcel
2116130812Smarcel  return inferior_ptid;
2117130812Smarcel}
2118130812Smarcel
2119130812Smarcel/* Stop the running program.  */
2120130812Smarcel
2121130812Smarcelstatic void
2122130812Smarcele7000_stop (void)
2123130812Smarcel{
2124130812Smarcel  /* Sending a ^C is supposed to stop the running program.  */
2125130812Smarcel  putchar_e7000 (CTRLC);
2126130812Smarcel}
2127130812Smarcel
2128130812Smarcel/* Define the target subroutine names. */
2129130812Smarcel
2130130812Smarcelstruct target_ops e7000_ops;
2131130812Smarcel
2132130812Smarcelstatic void
2133130812Smarcelinit_e7000_ops (void)
2134130812Smarcel{
2135130812Smarcel  e7000_ops.to_shortname = "e7000";
2136130812Smarcel  e7000_ops.to_longname = "Remote Renesas e7000 target";
2137130812Smarcel  e7000_ops.to_doc = "Use a remote Renesas e7000 ICE connected by a serial line;\n\
2138130812Smarcelor a network connection.\n\
2139130812SmarcelArguments are the name of the device for the serial line,\n\
2140130812Smarcelthe speed to connect at in bits per second.\n\
2141130812Smarceleg\n\
2142130812Smarceltarget e7000 /dev/ttya 9600\n\
2143130812Smarceltarget e7000 foobar";
2144130812Smarcel  e7000_ops.to_open = e7000_open;
2145130812Smarcel  e7000_ops.to_close = e7000_close;
2146130812Smarcel  e7000_ops.to_detach = e7000_detach;
2147130812Smarcel  e7000_ops.to_resume = e7000_resume;
2148130812Smarcel  e7000_ops.to_wait = e7000_wait;
2149130812Smarcel  e7000_ops.to_fetch_registers = e7000_fetch_register;
2150130812Smarcel  e7000_ops.to_store_registers = e7000_store_register;
2151130812Smarcel  e7000_ops.to_prepare_to_store = e7000_prepare_to_store;
2152130812Smarcel  e7000_ops.to_xfer_memory = e7000_xfer_inferior_memory;
2153130812Smarcel  e7000_ops.to_files_info = e7000_files_info;
2154130812Smarcel  e7000_ops.to_insert_breakpoint = e7000_insert_breakpoint;
2155130812Smarcel  e7000_ops.to_remove_breakpoint = e7000_remove_breakpoint;
2156130812Smarcel  e7000_ops.to_kill = e7000_kill;
2157130812Smarcel  e7000_ops.to_load = e7000_load;
2158130812Smarcel  e7000_ops.to_create_inferior = e7000_create_inferior;
2159130812Smarcel  e7000_ops.to_mourn_inferior = e7000_mourn_inferior;
2160130812Smarcel  e7000_ops.to_stop = e7000_stop;
2161130812Smarcel  e7000_ops.to_stratum = process_stratum;
2162130812Smarcel  e7000_ops.to_has_all_memory = 1;
2163130812Smarcel  e7000_ops.to_has_memory = 1;
2164130812Smarcel  e7000_ops.to_has_stack = 1;
2165130812Smarcel  e7000_ops.to_has_registers = 1;
2166130812Smarcel  e7000_ops.to_has_execution = 1;
2167130812Smarcel  e7000_ops.to_magic = OPS_MAGIC;
2168130812Smarcel};
2169130812Smarcel
2170130812Smarcelextern initialize_file_ftype _initialize_remote_e7000; /* -Wmissing-prototypes */
2171130812Smarcel
2172130812Smarcelvoid
2173130812Smarcel_initialize_remote_e7000 (void)
2174130812Smarcel{
2175130812Smarcel  init_e7000_ops ();
2176130812Smarcel  add_target (&e7000_ops);
2177130812Smarcel
2178130812Smarcel  add_com ("e7000", class_obscure, e7000_command,
2179130812Smarcel	   "Send a command to the e7000 monitor.");
2180130812Smarcel
2181130812Smarcel  add_com ("ftplogin", class_obscure, e7000_login_command,
2182130812Smarcel	   "Login to machine and change to directory.");
2183130812Smarcel
2184130812Smarcel  add_com ("ftpload", class_obscure, e7000_ftp_command,
2185130812Smarcel	   "Fetch and load a file from previously described place.");
2186130812Smarcel
2187130812Smarcel  add_com ("drain", class_obscure, e7000_drain_command,
2188130812Smarcel	   "Drain pending e7000 text buffers.");
2189130812Smarcel
2190130812Smarcel  add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class,
2191130812Smarcel				var_integer, (char *) &use_hard_breakpoints,
2192130812Smarcel	"Set use of hardware breakpoints for all breakpoints.\n", &setlist),
2193130812Smarcel		     &showlist);
2194130812Smarcel}
2195