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 >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  32.2 KB  |  1,697 lines

  1. /* Remote debugging interface for Hitachi E7000 ICE, for GDB
  2.    Copyright 1993 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support. 
  4.  
  5.    Written by Steve Chamberlain for Cygnus Support.
  6.  
  7.    This file is part of GDB.
  8.  
  9.    This program is free software; you can redistribute it and/or modify
  10.    it under the terms of the GNU General Public License as published by
  11.    the Free Software Foundation; either version 2 of the License, or
  12.    (at your option) any later version.
  13.  
  14.    This program is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.    GNU General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU General Public License
  20.    along with this program; if not, write to the Free Software
  21.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  22.  
  23.  
  24. #include "defs.h"
  25. #include "gdbcore.h"
  26. #include "target.h"
  27. #include "wait.h"
  28. #include <varargs.h>
  29. #include <signal.h>
  30. #include <string.h>
  31. #include <sys/types.h>
  32. #include "serial.h"
  33.  
  34.  
  35. /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and
  36. Hitachi-SH processor.  It has serial port and a lan port.  
  37.  
  38. The monitor command set makes it difficult to load large ammounts of
  39. data over the lan without using ftp - so try not to issue load
  40. commands when communicating over ethernet; use the ftpload command.
  41.  
  42. The monitor pauses for a second when dumping srecords to the serial
  43. line too, so we use a slower per byte mechanism but without the
  44. startup overhead.  Even so, it's pretty slow... */
  45.  
  46. int using_tcp; /* nonzero if using the tcp serial driver */
  47.  
  48. extern struct target_ops e7000_ops;    /* Forward declaration */
  49. #define CTRLC 0x03
  50. #define ENQ  0x05
  51. #define ACK  0x06
  52. #define CTRLZ 0x1a
  53.  
  54. char *ENQSTRING = "\005";
  55.  
  56. int echo;
  57. int ctrl_c;
  58. static void e7000_close ();
  59. static void e7000_fetch_register ();
  60. static void e7000_store_register ();
  61.  
  62. static int timeout = 5;
  63.  
  64. static void expect PARAMS ((char *));
  65. static void expect_full_prompt PARAMS (());
  66. static void expect_prompt PARAMS (());
  67. static serial_t e7000_desc;
  68.  
  69.  
  70. /* Send data to e7000debug.  Works just like printf. */
  71. #if 0
  72. static void
  73. printf_e7000debug (va_alist)
  74.      va_dcl
  75. {
  76.   va_list args;
  77.   char *pattern;
  78.   char buf[200];
  79.  
  80.   va_start (args);
  81.  
  82.   pattern = va_arg (args, char *);
  83.  
  84.   vsprintf (buf, pattern, args);
  85. #else
  86.  
  87. static void
  88. printf_e7000debug(a,b,c,d,e)
  89.   {
  90.     char buf[200];
  91.     sprintf(buf, a,b,c,d,e);
  92. #endif
  93.   if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
  94.     fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
  95.  
  96.   /* And expect to see it echoed */
  97.   expect (buf);
  98. }
  99.  
  100. static void
  101. putchar_e7000 (x)
  102. {
  103.   char b[1];
  104.   b[0] = x;
  105.   SERIAL_WRITE (e7000_desc, b, 1);
  106. }
  107.  
  108. static void
  109. write_e7000 (s)
  110.      char *s;
  111. {
  112.   SERIAL_WRITE (e7000_desc, s, strlen (s));
  113. }
  114.  
  115. /* Read a character from the remote system, doing all the fancy timeout
  116.    stuff.  */
  117.  
  118. static int
  119. readchar (timeout)
  120.      int timeout;
  121. {
  122.   int c;
  123.   do
  124.     {
  125.       c = SERIAL_READCHAR (e7000_desc, timeout);
  126.     }
  127.   while (c > 127);
  128.   if (c == SERIAL_TIMEOUT)
  129.     {
  130.       if (timeout == 0)
  131.     return c;        /* Polls shouldn't generate timeout errors */
  132.  
  133.       error ("Timeout reading from remote system.");
  134.     }
  135.   return c;
  136. }
  137.  
  138.  
  139. /* Scan input from the remote system, until STRING is found.  If DISCARD is
  140.    non-zero, then discard non-matching input, else print it out.
  141.    Let the user break out immediately.  */
  142. static void
  143. expect (string)
  144.      char *string;
  145. {
  146.   char *p = string;
  147.   int c;
  148.  
  149.   while (1)
  150.  
  151.     {
  152.       c = readchar (timeout);
  153.  
  154.       notice_quit ();
  155.       if (quit_flag == 1) 
  156.     {
  157.       if (ctrl_c) {
  158.         putchar_e7000(CTRLC);
  159.         ctrl_c -- ;
  160.       }
  161.       else 
  162.         {
  163.           quit();
  164.         }
  165.     }
  166.       
  167.       if (c == SERIAL_ERROR)
  168.     {
  169.       error ("Serial communication error");
  170.     }
  171.       if (echo)
  172.     {
  173.       if (c != '\r')
  174.         putchar (c);
  175.       fflush (stdout);
  176.     }
  177.       if (c == *p++)
  178.     {
  179.       if (*p == '\0')
  180.         {
  181.           return;
  182.         }
  183.     }
  184.       else
  185.     {
  186.       p = string;
  187.     }
  188.     }
  189. }
  190.  
  191. /* Keep discarding input until we see the e7000 prompt.
  192.  
  193.    The convention for dealing with the prompt is that you
  194.    o give your command
  195.    o *then* wait for the prompt.
  196.  
  197.    Thus the last thing that a procedure does with the serial line
  198.    will be an expect_prompt().  Exception:  e7000_resume does not
  199.    wait for the prompt, because the terminal is being handed over
  200.    to the inferior.  However, the next thing which happens after that
  201.    is a e7000_wait which does wait for the prompt.
  202.    Note that this includes abnormal exit, e.g. error().  This is
  203.    necessary to prevent getting into states from which we can't
  204.    recover.  */
  205. static void
  206. expect_prompt ()
  207. {
  208.   expect (":");
  209. }
  210. static void
  211. expect_full_prompt ()
  212. {
  213.   expect ("\n:");
  214. }
  215.  
  216. static int
  217. get_hex_digit (ch)
  218. {
  219.   if (ch >= '0' && ch <= '9')
  220.     return ch - '0';
  221.   else if (ch >= 'A' && ch <= 'F')
  222.     return ch - 'A' + 10;
  223.   else if (ch >= 'a' && ch <= 'f')
  224.     return ch - 'a' + 10;
  225.   return -1;
  226.  
  227. }
  228.  
  229.  
  230.  
  231. static int
  232. get_hex (start)
  233.      int *start;
  234. {
  235.   int value = get_hex_digit (*start);
  236.   int try;
  237.  
  238.   *start = readchar (timeout);
  239.   while ((try = get_hex_digit (*start)) >= 0)
  240.     {
  241.       value <<= 4;
  242.       value += try;
  243.       *start = readchar (timeout);
  244.     }
  245.   return value;
  246. }
  247.  
  248. /* Get N 32-bit words from remote, each preceded by a space,
  249.    and put them in registers starting at REGNO.  */
  250.  
  251. static void
  252. get_hex_regs (n, regno)
  253.      int n;
  254.      int regno;
  255. {
  256.   long val;
  257.   int i;
  258.  
  259.   for (i = 0; i < n; i++)
  260.     {
  261.       int j;
  262.  
  263.       val = 0;
  264.       for (j = 0; j < 8; j++)
  265.     val = (val << 4) + get_hex_digit (j == 0);
  266.       supply_register (regno++, (char *) &val);
  267.     }
  268. }
  269.  
  270. /* This is called not only when we first attach, but also when the
  271.    user types "run" after having attached.  */
  272. static void
  273. e7000_create_inferior (execfile, args, env)
  274.      char *execfile;
  275.      char *args;
  276.      char **env;
  277. {
  278.   int entry_pt;
  279.  
  280.   if (args && *args)
  281.     error ("Can't pass arguments to remote E7000DEBUG process");
  282.  
  283.   if (execfile == 0 || exec_bfd == 0)
  284.     error ("No exec file specified");
  285.  
  286.   entry_pt = (int) bfd_get_start_address (exec_bfd);
  287.  
  288. #ifdef CREATE_INFERIOR_HOOK
  289.   CREATE_INFERIOR_HOOK (0);    /* No process-ID */
  290. #endif
  291.  
  292.   /* The "process" (board) is already stopped awaiting our commands, and
  293.      the program is already downloaded.  We just set its PC and go.  */
  294.  
  295.   clear_proceed_status ();
  296.  
  297.   /* Tell wait_for_inferior that we've started a new process.  */
  298.   init_wait_for_inferior ();
  299.  
  300.   /* Set up the "saved terminal modes" of the inferior
  301.      based on what modes we are starting it with.  */
  302.   target_terminal_init ();
  303.  
  304.   /* Install inferior's terminal modes.  */
  305.   target_terminal_inferior ();
  306.  
  307.   /* insert_step_breakpoint ();  FIXME, do we need this?  */
  308.   proceed ((CORE_ADDR) entry_pt, -1, 0);    /* Let 'er rip... */
  309. }
  310.  
  311. /* Open a connection to a remote debugger.
  312.    NAME is the filename used for communication.  */
  313.  
  314. static int baudrate = 9600;
  315. static char dev_name[100];
  316.  
  317. static char *machine = "";
  318. static char *user = "";
  319. static char *passwd = "";
  320. static char *dir = "";
  321.  
  322. /* Grab the next token and buy some space for it */
  323. static char *
  324. next (ptr)
  325.      char **ptr;
  326. {
  327.   char *p = *ptr;
  328.   char *s;
  329.   char *r;
  330.   int l = 0;
  331.   while (*p && *p == ' ')
  332.     {
  333.       p++;
  334.     }
  335.   s = p;
  336.   while (*p && (*p != ' ' && *p != '\t'))
  337.     {
  338.       l++;
  339.       p++;
  340.     }
  341.   r = xmalloc (l + 1);
  342.   memcpy (r, s, l);
  343.   r[l] = 0;
  344.   *ptr = p;
  345.   return r;
  346. }
  347.  
  348. static
  349. e7000_login (args, from_tty)
  350.      char *args;
  351.      int from_tty;
  352. {
  353.   if (args)
  354.     {
  355.       machine = next (&args);
  356.       user = next (&args);
  357.       passwd = next (&args);
  358.       dir = next (&args);
  359.       if (from_tty)
  360.     {
  361.       printf ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
  362.     }
  363.     }
  364.   else
  365.     {
  366.       error ("Syntax is ftplogin <machine> <user> <passwd> <directory>");
  367.     }
  368. }
  369.  
  370. /* Start an ftp transfer from the E7000 to a host */
  371.  
  372. static
  373. e7000_ftp (args, from_tty)
  374.      char *args;
  375.      int from_tty;
  376. {
  377.   int oldtimeout = timeout;
  378.   timeout = 10;
  379.   printf_e7000debug ("ftp %s\r", machine);
  380.   expect (" Username : ");
  381.   printf_e7000debug ("%s\r", user);
  382.   expect (" Password : ");
  383.   write_e7000 (passwd);
  384.   write_e7000 ("\r");
  385.   expect ("success\r");
  386.   expect ("FTP>");
  387.   printf_e7000debug ("cd %s\r", dir);
  388.   expect ("FTP>");
  389.   printf_e7000debug ("ll 0;s:%s\r", args);
  390.   expect ("FTP>");
  391.   printf_e7000debug ("bye\r");
  392.   expect (":");
  393.   timeout = oldtimeout;
  394. }
  395.  
  396. static void
  397. e7000_open (args, from_tty)
  398.      char *args;
  399.      int from_tty;
  400. {
  401.   int n;
  402.   char junk[100];
  403.   int sync;
  404.   target_preopen (from_tty);
  405.  
  406.   if (args)
  407.     n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk);
  408.   else
  409.     n = 0;
  410.   if (n != 1 && n != 2)
  411.     error ("Bad arguments.  Usage:\ttarget e7000 <device> <speed>\n\
  412. or \t\ttarget e7000 <host>[:<port>]\n");
  413.  
  414.   if (n == 1 && strchr (dev_name, ':') == 0)
  415.     {
  416.       /* Default to normal telnet port */
  417.       strcat (dev_name, ":23");
  418.     }
  419.  
  420.   push_target (&e7000_ops);
  421.   e7000_desc = SERIAL_OPEN (dev_name);
  422.  
  423.  
  424.   if (!e7000_desc)
  425.     perror_with_name (dev_name);
  426.  
  427.   using_tcp = strcmp (e7000_desc->ops->name, "tcp") == 0;
  428.  
  429.   SERIAL_SETBAUDRATE (e7000_desc, baudrate);
  430.   SERIAL_RAW (e7000_desc);
  431.  
  432.   /* Hello?  Are you there?  */
  433.   sync = 0;
  434.   putchar_e7000 (CTRLC);
  435.   while (!sync)
  436.     {
  437.       int c;
  438.       if (from_tty)
  439.     printf_unfiltered ("[waiting for e7000...]\n");
  440.       write_e7000 ("\r\n");
  441.       c = SERIAL_READCHAR (e7000_desc, 3);
  442.       while (c != SERIAL_TIMEOUT)
  443.     {
  444.       /* Dont echo cr's */
  445.       if (from_tty && c != '\r')
  446.         {
  447.           putchar (c);
  448.           fflush (stdout);
  449.         }
  450.       if (c == ':')
  451.         {
  452.           sync = 1;
  453.         }
  454.       c = SERIAL_READCHAR (e7000_desc, 3);
  455.       if (quit_flag)
  456.         {
  457.           putchar_e7000 (CTRLC);
  458.           quit_flag = 0;
  459.         }
  460.     }
  461.     }
  462.   printf_e7000debug ("\r\n");
  463.   expect_prompt ();
  464.  
  465.   if (from_tty)
  466.     printf_filtered ("Remote %s connected to %s\n", target_shortname,
  467.              dev_name);
  468.  
  469. #ifdef GDB_TARGET_IS_H8300
  470.   h8300hmode = 1;
  471. #endif
  472. }
  473.  
  474. /* Close out all files and local state before this target loses control. */
  475.  
  476. static void
  477. e7000_close (quitting)
  478.      int quitting;
  479. {
  480.   if (e7000_desc)
  481.     {
  482.       SERIAL_CLOSE (e7000_desc);
  483.       e7000_desc = 0;
  484.     }
  485. }
  486.  
  487. /* Terminate the open connection to the remote debugger.
  488.    Use this when you want to detach and do something else
  489.    with your gdb.  */
  490. static void
  491. e7000_detach (from_tty)
  492.      int from_tty;
  493. {
  494.   pop_target ();        /* calls e7000_close to do the real work */
  495.   if (from_tty)
  496.     printf ("Ending remote %s debugging\n", target_shortname);
  497. }
  498.  
  499. /* Tell the remote machine to resume.  */
  500.  
  501. static void
  502. e7000_resume (pid, step, sig)
  503.      int pid, step, sig;
  504. {
  505.   if (step)
  506.     {
  507.       printf_e7000debug ("S\r");
  508.     }
  509.   else
  510.     {
  511.       printf_e7000debug ("G\r");
  512.     }
  513. }
  514.  
  515. /* Read the remote registers into the block REGS.  
  516.  
  517.    For the H8/300 a register dump looks like:
  518.  
  519.  
  520.  PC=00021A  CCR=80:I*******
  521.  ER0 - ER3  0000000A 0000002E 0000002E 00000000
  522.  ER4 - ER7  00000000 00000000 00000000 00FFEFF6
  523.  000218           MOV.B     R1L,R2L
  524.  STEP NORMAL END or
  525.  BREAK POINT
  526.  */
  527.  
  528. #ifdef GDB_TARGET_IS_H8300
  529. char *want = "\n\
  530.  PC=%p CCR=%c\n\
  531.  ER0 - ER3  %0 %1 %2 %3\n\
  532.  ER4 - ER7  %4 %5 %6 %7\n";
  533.  
  534. char *want_nopc = "%p CCR=%c\n\
  535.  ER0 - ER3  %0 %1 %2 %3\n\
  536.  ER4 - ER7  %4 %5 %6 %7";
  537.  
  538.  
  539. #endif
  540. #ifdef GDB_TARGET_IS_SH
  541. char *want = "\n PC=%16 SR=%22\n\
  542.  PR=%17 GBR=%18 VBR=%19\n\
  543.  MACH=%20 MACL=%21\n\
  544.  R0-7  %0 %1 %2 %3 %4 %5 %6 %7\n\
  545.  R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n";
  546.  
  547. char *want_nopc = "%16 SR=%22\n\
  548.  PR=%17 GBR=%18 VBR=%19\n\
  549.  MACH=%20 MACL=%21\n\
  550.  R0-7  %0 %1 %2 %3 %4 %5 %6 %7\n\
  551.  R8-15 %8 %9 %10 %11 %12 %13 %14 %15";
  552.  
  553.  
  554. #endif
  555.  
  556. static
  557. int
  558. gch ()
  559. {
  560.   int c = readchar (timeout);
  561.   if (echo)
  562.     {
  563.       if (c >= ' ')
  564.     printf ("%c", c);
  565.       else if (c == '\n')
  566.     printf ("\n", c);
  567.     }
  568.   return c;
  569. }
  570.  
  571.  
  572. static
  573. unsigned int
  574. gbyte ()
  575. {
  576.   int high = get_hex_digit (gch ());
  577.   int low = get_hex_digit (gch ());
  578.   return (high << 4) + low;
  579. }
  580.  
  581. void
  582. fetch_regs_from_dump (nextchar, want)
  583.      int (*nextchar)();
  584.      char *want;
  585. {
  586.   int regno;
  587.   char buf[MAX_REGISTER_RAW_SIZE];
  588.  
  589.   int  thischar = nextchar();
  590.   
  591.   while (*want)
  592.     {
  593.       switch (*want)
  594.     {
  595.     case '\n':
  596.       while (thischar != '\n')
  597.         thischar = nextchar();
  598.       thischar = nextchar();
  599.       while (thischar == '\r')
  600.         thischar = nextchar();
  601.       want++;
  602.       break;
  603.  
  604.     case ' ':
  605.       while (thischar == ' ' || thischar == '\t' || thischar == '\r' || thischar == '\n')
  606.         thischar = nextchar();
  607.       want++;
  608.       break;
  609.       
  610.     default:
  611.       if (*want == thischar)
  612.         {
  613.           want++;
  614.           if (*want)
  615.         thischar = nextchar();
  616.           
  617.         }
  618.       else if (thischar == ' ')
  619.         {
  620.           thischar = nextchar();
  621.         }
  622.       else {
  623.         error("out of sync in fetch registers");
  624.       }
  625.     
  626.       break;
  627.     case '%':
  628.       /* Got a register command */
  629.       want++;
  630.       switch (*want)
  631.         {
  632. #ifdef PC_REGNUM
  633.         case 'p':
  634.           regno = PC_REGNUM;
  635.           want++;
  636.           break;
  637. #endif
  638. #ifdef CCR_REGNUM
  639.         case 'c':
  640.           regno = CCR_REGNUM;
  641.           want++;
  642.           break;
  643. #endif
  644. #ifdef SP_REGNUM
  645.         case 's':
  646.           regno = SP_REGNUM;
  647.           want++;
  648.           break;
  649. #endif
  650. #ifdef FP_REGNUM
  651.         case 'f':
  652.           regno = FP_REGNUM;
  653.           want++;
  654.           break;
  655. #endif
  656.  
  657.  
  658.         default:
  659.           if (isdigit(want[0])) 
  660.         {
  661.           if (isdigit(want[1]))
  662.             {
  663.               regno = (want[0] - '0') * 10 + want[1] - '0';
  664.               want+=2;
  665.             }
  666.           else 
  667.             {
  668.               regno = want[0] - '0';
  669.               want++;
  670.             }
  671.         }
  672.           
  673.           else
  674.         abort();
  675.         }
  676.       store_signed_integer (buf,
  677.                 REGISTER_RAW_SIZE(regno),
  678.                 (LONGEST)get_hex(&thischar, nextchar));
  679.       supply_register (regno, buf);
  680.       break;
  681.     }
  682.     }
  683. }
  684.  
  685. static void
  686. e7000_fetch_registers ()
  687. {
  688.   int regno;
  689.  
  690.   printf_e7000debug ("R\r");
  691.   fetch_regs_from_dump (gch, want);
  692.  
  693.   /* And supply the extra ones the simulator uses */
  694.   for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
  695.     {
  696.       int buf = 0;
  697.       supply_register (regno, (char *) (&buf));
  698.     }
  699. }
  700.  
  701. /* Fetch register REGNO, or all registers if REGNO is -1.
  702.    Returns errno value.  */
  703.  
  704. static
  705. void
  706. e7000_fetch_register (regno)
  707.      int regno;
  708. {
  709.   e7000_fetch_registers ();
  710. }
  711.  
  712. /* Store the remote registers from the contents of the block REGS.  */
  713.  
  714. static void
  715. e7000_store_registers ()
  716. {
  717.   int regno;
  718.  
  719.   for (regno = 0; regno < NUM_REALREGS; regno++)
  720.     e7000_store_register (regno);
  721.  
  722.   registers_changed ();
  723. }
  724.  
  725. /* Store register REGNO, or all if REGNO == 0.
  726.    Return errno value.  */
  727. static void
  728. e7000_store_register (regno)
  729.      int regno;
  730. {
  731.   if (regno == -1)
  732.     {
  733.       e7000_store_registers ();
  734.       return;
  735.     }
  736. #ifdef GDB_TARGET_IS_H8300
  737.   if (regno <= 7)
  738.     {
  739.       printf_e7000debug (".ER%d %x\r", regno,
  740.              read_register (regno));
  741.  
  742.     }
  743.   else if (regno == PC_REGNUM)
  744.     {
  745.       printf_e7000debug (".PC %x\r",
  746.              read_register (regno));
  747.     }
  748.   else if (regno == CCR_REGNUM)
  749.     {
  750.       printf_e7000debug (".CCR %x\r",
  751.              read_register (regno));
  752.     }
  753. #endif
  754.  
  755. #ifdef  GDB_TARGET_IS_SH
  756.   switch (regno)
  757.     {
  758.     default:
  759.       printf_e7000debug (".R%d %x\r", regno,
  760.              read_register (regno));
  761.  
  762.       break;
  763.     case PC_REGNUM:
  764.       printf_e7000debug (".PC %x\r",
  765.              read_register (regno));
  766.       break;
  767.     case SR_REGNUM:
  768.       printf_e7000debug (".SR %x\r",
  769.              read_register (regno));
  770.       break;
  771.  
  772.     case PR_REGNUM:
  773.       printf_e7000debug (".PR %x\r",
  774.              read_register (regno));
  775.       break;
  776.  
  777.     case GBR_REGNUM:
  778.       printf_e7000debug (".GBR %x\r",
  779.              read_register (regno));
  780.       break;
  781.  
  782.     case VBR_REGNUM:
  783.       printf_e7000debug (".VBR %x\r",
  784.              read_register (regno));
  785.       break;
  786.  
  787.     case MACH_REGNUM:
  788.       printf_e7000debug (".MACH %x\r",
  789.              read_register (regno));
  790.       break;
  791.  
  792.     case MACL_REGNUM:
  793.       printf_e7000debug (".MACL %x\r",
  794.              read_register (regno));
  795.       break;
  796.     }
  797.  
  798. #endif
  799.   expect_prompt ();
  800. }
  801.  
  802. /* Get ready to modify the registers array.  On machines which store
  803.    individual registers, this doesn't need to do anything.  On machines
  804.    which store all the registers in one fell swoop, this makes sure
  805.    that registers contains all the registers from the program being
  806.    debugged.  */
  807.  
  808. static void
  809. e7000_prepare_to_store ()
  810. {
  811.   /* Do nothing, since we can store individual regs */
  812. }
  813.  
  814. static void
  815. e7000_files_info ()
  816. {
  817.   printf ("\tAttached to %s at %d baud.\n",
  818.       dev_name, baudrate);
  819. }
  820.  
  821. static
  822. int
  823. stickbyte (where, what)
  824.      char *where;
  825.      unsigned int what;
  826. {
  827.   static CONST char digs[] = "0123456789ABCDEF";
  828.   where[0] = digs[(what >> 4) & 0xf];
  829.   where[1] = digs[(what & 0xf) & 0xf];
  830.   return what;
  831. }
  832.  
  833. /* Write a small ammount of memory */
  834. static int
  835. write_small (memaddr, myaddr, len)
  836.      CORE_ADDR memaddr;
  837.      unsigned char *myaddr;
  838.      int len;
  839. {
  840.   int i;
  841.   for (i = 0; i < len; i++)
  842.     {
  843.       if (((memaddr + i) & 3) == 0
  844.       && (i + 3 < len))
  845.     {
  846.       /* Can be done with a long word */
  847.       printf_e7000debug ("m %x %x%02x%02x%02x;l\r",
  848.                  memaddr + i,
  849.                  myaddr[i],
  850.                  myaddr[i + 1],
  851.                  myaddr[i + 2],
  852.                  myaddr[i + 3]);
  853.       i += 3;
  854.     }
  855.       else
  856.     {
  857.       printf_e7000debug ("m %x %x\r", memaddr + i, myaddr[i]);
  858.     }
  859.     }
  860.   expect_prompt ();
  861.   return len;
  862. }
  863. /* Write a large ammount of memory, this only works with the serial mode enabled.
  864.    Command is sent as
  865.     il ;s:s\r     ->
  866.             <- il ;s:s\r
  867.             <-      ENQ
  868.     ACK        ->
  869.             <- LO s\r
  870.     Srecords...
  871.     ^Z        ->
  872.             <-    ENQ
  873.     ACK        ->  
  874.             <-    :       
  875.  */
  876.  
  877. static int
  878. write_large (memaddr, myaddr, len)
  879.      CORE_ADDR memaddr;
  880.      unsigned char *myaddr;
  881.      int len;
  882. {
  883.   int i;
  884.   int c;
  885. #define maxstride  128
  886.   int stride;
  887.  
  888.   printf_e7000debug ("IL ;S:FK\r");
  889.   expect (ENQSTRING);
  890.   putchar_e7000 (ACK);
  891.   expect ("LO FK\r");
  892.   for (i = 0; i < len; i += stride)
  893.     {
  894.       char compose[maxstride * 2 + 50];
  895.       int address = i + memaddr;
  896.       int j;
  897.       int check_sum;
  898.       int where = 0;
  899.       int alen;
  900.       stride = len - i;
  901.       if (stride > maxstride)
  902.     stride = maxstride;
  903.  
  904.       compose[where++] = 'S';
  905.       check_sum = 0;
  906.       if (address >= 0xffffff)
  907.     {
  908.       alen = 4;
  909.     }
  910.       else if (address >= 0xffff)
  911.     {
  912.       alen = 3;
  913.     }
  914.       else
  915.     alen = 2;
  916.       compose[where++] = alen - 1 + '0'; /* insert type */
  917.       check_sum += stickbyte (compose + where, alen + stride + 1); /* Insert length */
  918.       where += 2;
  919.       while (alen > 0)
  920.     {
  921.       alen--;
  922.       check_sum += stickbyte (compose + where, address >> (8 * (alen)));
  923.       where += 2;
  924.     }
  925.  
  926.       for (j = 0; j < stride; j++)
  927.     {
  928.       check_sum += stickbyte (compose + where, myaddr[i + j]);
  929.       where += 2;
  930.     }
  931.  
  932.       stickbyte (compose + where, ~check_sum);
  933.  
  934.       where += 2;
  935.       compose[where++] = '\r';
  936.       compose[where++] = '\n';
  937.       compose[where++] = 0;
  938.       {
  939.     char *z;
  940.     for (z = compose; *z; z++) ;
  941.     {
  942.       SERIAL_WRITE (e7000_desc, compose, where);
  943.       j = SERIAL_READCHAR (e7000_desc, 0);
  944.       if (j == SERIAL_TIMEOUT)
  945.         {
  946.           /* This is ok - nothing there */
  947.         }
  948.       else if (j == ENQ)
  949.         {
  950.           /* Hmm, it's trying to tell us something */
  951.           expect (":");
  952.           error ("Error writing memory");
  953.         }
  954.       else
  955.         {
  956.           printf ("@%d}@", j);
  957.           while ((j = SERIAL_READCHAR(e7000_desc,0)) > 0) 
  958.         {
  959.           printf ("@{%d}@",j);
  960.         }
  961.         }
  962.     }
  963.       }
  964.     }
  965.   /* Send the trailer record */
  966.   write_e7000 ("S70500000000FA\r");
  967.   putchar_e7000 (CTRLZ);
  968.   expect (ENQSTRING);
  969.   putchar_e7000 (ACK);
  970.   expect (":");
  971.   return len;
  972. }
  973.  
  974. /* Copy LEN bytes of data from debugger memory at MYADDR
  975.    to inferior's memory at MEMADDR.  Returns length moved.  
  976.  
  977.    Can't use the Srecord load over ethernet, so dont use 
  978.    fast method then.
  979.  */
  980. static int
  981. e7000_write_inferior_memory (memaddr, myaddr, len)
  982.      CORE_ADDR memaddr;
  983.      unsigned char *myaddr;
  984.      int len;
  985. {
  986.   if (len < 16 || using_tcp)
  987.     {
  988.       return write_small (memaddr, myaddr, len);
  989.     }
  990.   else
  991.     {
  992.       return write_large (memaddr, myaddr, len);
  993.     }
  994. }
  995.  
  996. /* Read LEN bytes from inferior memory at MEMADDR.  Put the result
  997.    at debugger address MYADDR.  Returns length moved. 
  998.  
  999.    Done by requesting an srecord dump from the E7000.
  1000.  */
  1001.  
  1002.  
  1003.  
  1004. /* Read LEN bytes from inferior memory at MEMADDR.  Put the result
  1005.    at debugger address MYADDR.  Returns length moved. 
  1006.  
  1007.  
  1008.   Small transactions we send
  1009.   m <addr>;l
  1010.   and receive
  1011.     00000000 12345678 ?
  1012.  
  1013.  */
  1014.  
  1015. static int
  1016. e7000_read_inferior_memory (memaddr, myaddr, len)
  1017.      CORE_ADDR memaddr;
  1018.      unsigned char *myaddr;
  1019.      int len;
  1020. {
  1021.   int count;
  1022.   int c;
  1023.   int i;
  1024.   /* Starting address of this pass.  */
  1025.  
  1026.   if (((memaddr - 1) + len) < memaddr)
  1027.     {
  1028.       errno = EIO;
  1029.       return 0;
  1030.     }
  1031.  
  1032.   printf_e7000debug ("m %x;l\r", memaddr);
  1033.  
  1034.   for (count = 0; count < len; count += 4) 
  1035.     {
  1036.       /* Suck away the address */
  1037.       c = gch();    
  1038.       while (c != ' ')
  1039.     c = gch();    
  1040.       c = gch();
  1041.       if (c == '*') 
  1042.     {            /* Some kind of error */
  1043.       expect_prompt();
  1044.       return -1;
  1045.     }
  1046.       while (c != ' ')
  1047.     c = gch();    
  1048.  
  1049.       /* Now read in the data */
  1050.       for (i = 0; i < 4; i++) 
  1051.     {
  1052.       int b = gbyte();
  1053.       if (count + i < len) {
  1054.         myaddr[count + i] = b;
  1055.       }
  1056.     }
  1057.  
  1058.       /* Skip the trailing ? and send a . to end and a cr for more */
  1059.       gch();    
  1060.       gch();
  1061.       if (count + 4 >= len)
  1062.     printf_e7000debug(".\r");
  1063.       else
  1064.     printf_e7000debug("\r");
  1065.     }
  1066.   expect_prompt();
  1067. }
  1068.  
  1069.  
  1070. #if 0
  1071. /*
  1072.   For large transfers we used to send
  1073.  
  1074.  
  1075.   d <addr> <endaddr>\r
  1076.  
  1077.   and receive
  1078.    <ADDR>              <    D   A   T   A    >               <   ASCII CODE   >
  1079.    000000  5F FD FD FF DF 7F DF FF  01 00 01 00 02 00 08 04  "_..............."
  1080.    000010  FF D7 FF 7F D7 F1 7F FF  00 05 00 00 08 00 40 00  "..............@."
  1081.    000020  7F FD FF F7 7F FF FF F7  00 00 00 00 00 00 00 00  "................"
  1082.  
  1083.   A cost in chars for each transaction of 80 + 5*n-bytes. 
  1084.  
  1085.  
  1086.   Large transactions could be done with the srecord load code, but
  1087.   there is a pause for a second before dumping starts, which slows the
  1088.   average rate down!
  1089. */
  1090.  
  1091. static int
  1092. e7000_read_inferior_memory (memaddr, myaddr, len)
  1093.      CORE_ADDR memaddr;
  1094.      unsigned char *myaddr;
  1095.      int len;
  1096. {
  1097.   int count;
  1098.   int c;
  1099.  
  1100.   /* Starting address of this pass.  */
  1101.  
  1102.   if (((memaddr - 1) + len) < memaddr)
  1103.     {
  1104.       errno = EIO;
  1105.       return 0;
  1106.     }
  1107.  
  1108.   printf_e7000debug ("d %x %x\r", memaddr, memaddr + len - 1);
  1109.  
  1110.   count = 0;
  1111.   c = gch ();
  1112.  
  1113.   /* First skip the command */
  1114.   while (c == '\n')
  1115.     c = gch ();
  1116.  
  1117.   while (c == ' ')
  1118.     c = gch ();
  1119.   if (c == '*')
  1120.     {
  1121.       expect ("\r");
  1122.       return -1;
  1123.     }
  1124.  
  1125.   /* Skip the title line */
  1126.   while (c != '\n')
  1127.     c = gch ();
  1128.   c = gch ();
  1129.   while (count < len)
  1130.     {
  1131.       /* Skip the address */
  1132.       while (c <= ' ')
  1133.     c = gch ();
  1134.  
  1135.       get_hex (&c);
  1136.  
  1137.       /* read in the bytes on the line */
  1138.       while (c != '"' && count < len)
  1139.     {
  1140.       if (c == ' ')
  1141.         c = gch ();
  1142.       else
  1143.         {
  1144.           myaddr[count++] = get_hex (&c);
  1145.         }
  1146.     }
  1147.  
  1148.       while (c != '\n')
  1149.     c = gch ();
  1150.     }
  1151.  
  1152.   while (c != ':')
  1153.     c = gch ();
  1154.  
  1155.   return len;
  1156. }
  1157.  
  1158. static int
  1159. fast_but_for_the_pause_e7000_read_inferior_memory (memaddr, myaddr, len)
  1160.      CORE_ADDR memaddr;
  1161.      char *myaddr;
  1162.      int len;
  1163. {
  1164.   int loop;
  1165.   int c;
  1166.  
  1167.   if (((memaddr - 1) + len) < memaddr)
  1168.     {
  1169.       errno = EIO;
  1170.       return 0;
  1171.     }
  1172.  
  1173.   printf_e7000debug ("is %x@%x:s\r", memaddr, len);
  1174.   gch ();
  1175.   c = gch ();
  1176.   if (c != ENQ)
  1177.     {
  1178.       /* Got an error */
  1179.       error ("Memory read error");
  1180.     }
  1181.   putchar_e7000 (ACK);
  1182.   expect ("SV s");
  1183.   loop = 1;
  1184.   while (loop)
  1185.     {
  1186.       int type;
  1187.       int length;
  1188.       int addr;
  1189.       int i;
  1190.       c = gch ();
  1191.       switch (c)
  1192.     {
  1193.     case ENQ:        /* ENQ, at the end */
  1194.       loop = 0;
  1195.       break;
  1196.     case 'S':
  1197.       /* Start of an Srecord */
  1198.       type = gch ();
  1199.       length = gbyte ();
  1200.       switch (type)
  1201.         {
  1202.         case '7':        /* Termination record, ignore */
  1203.         case '0':
  1204.         case '8':
  1205.         case '9':
  1206.           /* Header record - ignore it */
  1207.           while (length--)
  1208.         {
  1209.           gbyte ();
  1210.         }
  1211.           break;
  1212.         case '1':
  1213.         case '2':
  1214.         case '3':
  1215.           {
  1216.         int alen;
  1217.         alen = type - '0' + 1;
  1218.         addr = 0;
  1219.         while (alen--)
  1220.           {
  1221.             addr = (addr << 8) + gbyte ();
  1222.             length--;
  1223.           }
  1224.  
  1225.         for (i = 0; i < length - 1; i++)
  1226.           {
  1227.             myaddr[i + addr - memaddr] = gbyte ();
  1228.           }
  1229.         gbyte ();    /* Ignore checksum */
  1230.           }
  1231.         }
  1232.     }
  1233.     }
  1234.   putchar_e7000 (ACK);
  1235.   expect ("TOP ADDRESS =");
  1236.   expect ("END ADDRESS =");
  1237.   expect (":");
  1238.  
  1239.   return len;
  1240. }
  1241.  
  1242. #endif
  1243.  
  1244. static int
  1245. e7000_xfer_inferior_memory (memaddr, myaddr, len, write, target)
  1246.      CORE_ADDR memaddr;
  1247.      unsigned char *myaddr;
  1248.      int len;
  1249.      int write;
  1250.      struct target_ops *target;    /* ignored */
  1251. {
  1252.   if (write)
  1253.     {
  1254.       return e7000_write_inferior_memory( memaddr, myaddr, len);
  1255.     }
  1256.   else
  1257.     {
  1258.       return e7000_read_inferior_memory( memaddr, myaddr, len);
  1259.     }
  1260. }
  1261.  
  1262. static void
  1263. e7000_kill (args, from_tty)
  1264.      char *args;
  1265.      int from_tty;
  1266. {
  1267.  
  1268. }
  1269.  
  1270. /* Clean up when a program exits.
  1271.  
  1272.    The program actually lives on in the remote processor's RAM, and may be
  1273.    run again without a download.  Don't leave it full of breakpoint
  1274.    instructions.  */
  1275.  
  1276. static void
  1277. e7000_mourn_inferior ()
  1278. {
  1279.   remove_breakpoints ();
  1280.   unpush_target (&e7000_ops);
  1281.   generic_mourn_inferior ();    /* Do all the proper things now */
  1282. }
  1283.  
  1284. #define MAX_E7000DEBUG_BREAKPOINTS 200
  1285.  
  1286. extern int memory_breakpoint_size;
  1287. static CORE_ADDR breakaddr[MAX_E7000DEBUG_BREAKPOINTS] =
  1288. {0};
  1289.  
  1290. static int
  1291. e7000_insert_breakpoint (addr, shadow)
  1292.      CORE_ADDR addr;
  1293.      unsigned char *shadow;
  1294. {
  1295.   int i;
  1296.   static char nop[2] = NOP;
  1297.  
  1298.   for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++)
  1299.     if (breakaddr[i] == 0)
  1300.       {
  1301.     breakaddr[i] = addr;
  1302.     /* Save old contents, and insert a nop in the space */
  1303.     e7000_read_inferior_memory (addr, shadow, 2);
  1304.     e7000_write_inferior_memory (addr, nop, 2);
  1305.     printf_e7000debug ("B %x\r", addr);
  1306.     expect_prompt ();
  1307.     return 0;
  1308.       }
  1309.  
  1310.   error("Too many breakpoints ( > %d) for the E7000\n", MAX_E7000DEBUG_BREAKPOINTS);
  1311.   return 1;
  1312. }
  1313.  
  1314. static int
  1315. e7000_remove_breakpoint (addr, shadow)
  1316.      CORE_ADDR addr;
  1317.      unsigned char *shadow;
  1318. {
  1319.   int i;
  1320.  
  1321.   for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++)
  1322.     if (breakaddr[i] == addr)
  1323.       {
  1324.     breakaddr[i] = 0;
  1325.     printf_e7000debug ("B - %x\r", addr);
  1326.     expect_prompt ();
  1327.     /* Replace the insn under the break */
  1328.     e7000_write_inferior_memory (addr, shadow, 2);
  1329.     return 0;
  1330.       }
  1331.  
  1332.   fprintf (stderr, "Can't find breakpoint associated with 0x%x\n", addr);
  1333.   return 1;
  1334. }
  1335.  
  1336.  
  1337. /* Put a command string, in args, out to STDBUG.  Output from STDBUG is placed
  1338.    on the users terminal until the prompt is seen. */
  1339.  
  1340. static void
  1341. e7000_command (args, fromtty)
  1342.      char *args;
  1343.      int fromtty;
  1344. {
  1345.  
  1346.   if (!e7000_desc)
  1347.     error ("e7000 target not open.");
  1348.   if (!args)
  1349.     {
  1350.       printf_e7000debug ("\r");
  1351.     }
  1352.   else
  1353.     {
  1354.       printf_e7000debug ("%s\r", args);
  1355.     }
  1356.   echo++;
  1357.   ctrl_c = 2;
  1358.   expect_full_prompt ();
  1359.   echo--;
  1360.   ctrl_c = 0;
  1361.   printf_unfiltered ("\n");
  1362. }
  1363.  
  1364. static void
  1365. e7000_load (args, fromtty)
  1366.      char *args;
  1367.      int fromtty;
  1368. {
  1369.   gr_load_image (args, fromtty);
  1370. }
  1371.  
  1372. static void
  1373. e7000_drain (args, fromtty)
  1374.      char *args;
  1375.      int fromtty;
  1376.  
  1377. {
  1378.   int c;
  1379.   printf_e7000debug("end\r");
  1380.   putchar_e7000 (CTRLC);
  1381.   while ((c = SERIAL_READCHAR (e7000_desc, 1) != SERIAL_TIMEOUT))
  1382.     {
  1383.       if(quit_flag)
  1384.     {
  1385.       putchar_e7000(CTRLC);
  1386.       quit_flag = 0;
  1387.     }
  1388.       if (c > ' ' && c < 127)
  1389.     printf ("%c", c & 0xff);
  1390.       else
  1391.     printf ("<%x>", c & 0xff);
  1392.     }
  1393. }
  1394.  
  1395. e7000_noecho ()
  1396. {
  1397.   echo = !echo;
  1398.   if (echo)
  1399.     printf_filtered ("Snoop enabled\n");
  1400.   else
  1401.     printf_filtered ("Snoop disabled\n");
  1402.  
  1403. }
  1404.  
  1405. #define NITEMS 3
  1406. static int
  1407. why_stop ()
  1408. {
  1409.   static  char *strings[NITEMS] = 
  1410.     {
  1411.       "STEP NORMAL",
  1412.       "BREAK POINT",
  1413.       "BREAK KEY",
  1414.     };
  1415.   char *p[NITEMS];
  1416.   int c;
  1417.   p[0] = strings[0];
  1418.   p[1] = strings[1];
  1419.   p[2] = strings[2];
  1420.   
  1421.   c = gch();
  1422.   while (1)
  1423.     {
  1424.       int i;
  1425.       for (i = 0; i < NITEMS; i++)
  1426.     {
  1427.       if (c == *(p[i])) 
  1428.         {
  1429.           p[i]++;
  1430.           if (*(p[i]) == 0) 
  1431.         { 
  1432.           /* found one of the choices */
  1433.           return i;
  1434.         }
  1435.         }
  1436.       else {
  1437.         p[i] = strings[i];
  1438.       }
  1439.     }
  1440.  
  1441.       c = gch();
  1442.     }
  1443. }
  1444. /* Suck characters, if a string match, then return the strings index
  1445.    otherwise echo them */
  1446. int
  1447. expect_n ( strings)
  1448. char **strings;
  1449. {
  1450.   char *(ptr[10]);
  1451.   int n; 
  1452.   int c;
  1453.   char saveaway[100];
  1454.   char *buffer = saveaway;
  1455.   /* Count number of expect strings  */
  1456.  
  1457.   for (n =0; strings[n]; n++) 
  1458.     {
  1459.       ptr[n] = strings[n];
  1460.     }
  1461.  
  1462.   while (1) {
  1463.     int i;
  1464.     int gotone = 0;
  1465.  
  1466.     c = SERIAL_READCHAR (e7000_desc, 1);
  1467.     if (c == SERIAL_TIMEOUT) {
  1468.       printf_unfiltered ("[waiting for e7000...]\n");
  1469.     }
  1470. #ifdef __GO32__
  1471.     if (kbhit())
  1472.       {
  1473.     int k = getkey();
  1474.     if (k == 1)
  1475.       quit_flag = 1;
  1476.       }
  1477. #endif
  1478.  
  1479.     if (quit_flag)
  1480.       {
  1481.     putchar_e7000 (CTRLC);    /* interrupt the running program */
  1482.     quit_flag = 0;
  1483.       }
  1484.  
  1485.     for (i = 0; i < n; i++)
  1486.       {
  1487.     if (c == ptr[i][0]) 
  1488.       {
  1489.         ptr[i]++;
  1490.         if (ptr[i][0] == 0)
  1491.           {
  1492.         /* Gone all the way */
  1493.         return i;
  1494.           }
  1495.         gotone = 1;
  1496.       }
  1497.     else 
  1498.       {
  1499.         ptr[i] = strings[i];
  1500.       }
  1501.       }
  1502.  
  1503.     
  1504.     if (gotone)
  1505.       {
  1506.     /* Save it up incase we find that there was no match */
  1507.     *buffer ++ = c;
  1508.       }
  1509.     else
  1510.       {
  1511.     if (buffer != saveaway) 
  1512.       {
  1513.         *buffer++ = 0;
  1514.         printf(buffer);
  1515.         buffer = saveaway;
  1516.       }
  1517.     if (c != SERIAL_TIMEOUT) {
  1518.       putchar (c);
  1519.       fflush(stdout);
  1520.     }
  1521.       }
  1522.   }
  1523. }
  1524.  
  1525. /* We subtract two from the pc here rather than use DECR_PC_AFTER_BREAK
  1526.    since the e7000 doesn't always add two to the pc, and the simulators never do. */
  1527.  
  1528. static void
  1529. sub2_from_pc()
  1530. {
  1531.   char buf[4];
  1532.   store_signed_integer (buf,
  1533.             REGISTER_RAW_SIZE(PC_REGNUM), 
  1534.             read_register (PC_REGNUM) -2);
  1535.   supply_register (PC_REGNUM, buf);
  1536.   printf_e7000debug (".PC %x\r", read_register (PC_REGNUM));
  1537. }
  1538. #define WAS_SLEEP 0
  1539. #define WAS_INT 1
  1540. #define WAS_RUNNING 2
  1541. #define WAS_OTHER 3
  1542. static char *estrings[] = { "** SLEEP", "BREAK !", "** PC", "PC", 0};
  1543.  
  1544. /* Wait until the remote machine stops, then return,
  1545.    storing status in STATUS just as `wait' would.  */
  1546.  
  1547. static int
  1548. e7000_wait (pid, status)
  1549.      int pid;
  1550.      WAITTYPE *status;
  1551. {
  1552.   int c;
  1553.   int reset_pc;
  1554.   int regno;
  1555.   int running_count = 0;
  1556.   int had_sleep = 0;
  1557.   int loop = 1;
  1558.   char *reg;
  1559.   int time = 0;
  1560.   WSETSTOP ((*status), 0);
  1561.   /* Then echo chars until PC= string seen */
  1562.   gch ();            /* Drop cr */
  1563.   gch ();            /* and space */
  1564.   while (loop)
  1565.     {
  1566.       switch (expect_n(estrings))
  1567.     {     
  1568.     case WAS_OTHER:
  1569.       /* how did this happen ? */
  1570.       loop =0;
  1571.       break;
  1572.     case WAS_SLEEP:
  1573.       had_sleep = 1;
  1574.       putchar_e7000 (CTRLC);
  1575.       loop = 0;
  1576.       break;
  1577.     case WAS_INT:
  1578.       loop = 0;
  1579.       break;
  1580.     case WAS_RUNNING:
  1581.       running_count++;
  1582.       if (running_count == 20)
  1583.         {
  1584.           printf_unfiltered ("[running...]\n");
  1585.           running_count = 0;
  1586.         }
  1587.       break;
  1588.     }
  1589.     }
  1590.   /* Skip till the PC=*/
  1591.   expect("=");
  1592.   fetch_regs_from_dump (gch, want_nopc);
  1593.  
  1594.   /* And supply the extra ones the simulator uses */
  1595.   for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
  1596.     {
  1597.       int buf = 0;
  1598.       supply_register (regno, (char *) &buf);
  1599.     }
  1600.  
  1601.   reset_pc = why_stop ();
  1602.   expect_full_prompt ();
  1603.  
  1604.   switch (reset_pc)
  1605.     {
  1606.     case 1:            /* Breakpoint */
  1607.   
  1608.       WSETSTOP ((*status), SIGTRAP);
  1609.       break;
  1610.     case 0:
  1611.       /* Single step */
  1612.       WSETSTOP ((*status), SIGTRAP);
  1613.       break;
  1614.     case 2:
  1615.       /* Interrupt */
  1616.       if (had_sleep)
  1617.     {
  1618.       sub2_from_pc();
  1619.       WSETSTOP ((*status), SIGTRAP);
  1620.     }
  1621.       else
  1622.     {
  1623.       WSETSTOP ((*status), SIGINT);
  1624.     }
  1625.       break;
  1626.     }
  1627.   return 0;
  1628. }
  1629.  
  1630. /* Define the target subroutine names */
  1631.  
  1632. struct target_ops e7000_ops =
  1633. {
  1634.   "e7000",
  1635.   "Remote Hitachi e7000 target",
  1636.   "Use a remote Hitachi e7000 ICE connected by a serial line,\n\
  1637. or a network connection.\n\
  1638. Arguments are the name of the device for the serial line,\n\
  1639. the speed to connect at in bits per second.\n\
  1640. eg\n\
  1641. target e7000 /dev/ttya 9600\n\
  1642. target e7000 foobar",
  1643.   e7000_open,
  1644.   e7000_close,
  1645.   0,
  1646.   e7000_detach,
  1647.   e7000_resume,
  1648.   e7000_wait,
  1649.   e7000_fetch_register,
  1650.   e7000_store_register,
  1651.   e7000_prepare_to_store,
  1652.   e7000_xfer_inferior_memory,
  1653.   e7000_files_info,
  1654. 0,0,/*  e7000_insert_breakpoint,
  1655.   e7000_remove_breakpoint,    /* Breakpoints */
  1656.   0,
  1657.   0,
  1658.   0,
  1659.   0,
  1660.   0,                /* Terminal handling */
  1661.   e7000_kill,
  1662.   e7000_load,            /* load */
  1663.   0,                /* lookup_symbol */
  1664.   e7000_create_inferior,
  1665.   e7000_mourn_inferior,
  1666.   0,                /* can_run */
  1667.   0,                /* notice_signals */
  1668.   process_stratum,
  1669.   0,                /* next */
  1670.   1,
  1671.   1,
  1672.   1,
  1673.   1,
  1674.   1,                /* all mem, mem, stack, regs, exec */
  1675.   0,
  1676.   0,                /* Section pointers */
  1677.   OPS_MAGIC,            /* Always the last thing */
  1678. };
  1679.  
  1680. void
  1681. _initialize_remote_e7000 ()
  1682. {
  1683.   add_target (&e7000_ops);
  1684.   add_com ("e7000 <command>", class_obscure, e7000_command,
  1685.        "Send a command to the e7000 monitor.");
  1686.  
  1687.   add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure, e7000_login,
  1688.        "Login to machine and change to directory.");
  1689.  
  1690.   add_com ("ftpload <file>", class_obscure, e7000_ftp,
  1691.        "Fetch and load a file from previously described place.");
  1692.  
  1693.   add_com ("drain", class_obscure, e7000_drain,
  1694.        "Drain pending e7000 text buffers.");
  1695.   add_com ("e7000-snoop",  class_obscure, e7000_noecho, "Toggle monitor echo.");
  1696. }
  1697.