OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [gdbserver/] [remote-utils.c] - Diff between revs 107 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 107 Rev 1765
/* Remote utility routines for the remote server for GDB.
/* Remote utility routines for the remote server for GDB.
   Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc.
   Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
#include "server.h"
#include "server.h"
#include "terminal.h"
#include "terminal.h"
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/file.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <signal.h>
#include <fcntl.h>
#include <fcntl.h>
 
 
int remote_debug = 0;
int remote_debug = 0;
 
 
static int remote_desc;
static int remote_desc;
 
 
/* Open a connection to a remote debugger.
/* Open a connection to a remote debugger.
   NAME is the filename used for communication.  */
   NAME is the filename used for communication.  */
 
 
void
void
remote_open (name)
remote_open (name)
     char *name;
     char *name;
{
{
  int save_fcntl_flags;
  int save_fcntl_flags;
 
 
  if (!strchr (name, ':'))
  if (!strchr (name, ':'))
    {
    {
      remote_desc = open (name, O_RDWR);
      remote_desc = open (name, O_RDWR);
      if (remote_desc < 0)
      if (remote_desc < 0)
        perror_with_name ("Could not open remote device");
        perror_with_name ("Could not open remote device");
 
 
#ifdef HAVE_TERMIOS
#ifdef HAVE_TERMIOS
      {
      {
        struct termios termios;
        struct termios termios;
        tcgetattr (remote_desc, &termios);
        tcgetattr (remote_desc, &termios);
 
 
        termios.c_iflag = 0;
        termios.c_iflag = 0;
        termios.c_oflag = 0;
        termios.c_oflag = 0;
        termios.c_lflag = 0;
        termios.c_lflag = 0;
        termios.c_cflag &= ~(CSIZE | PARENB);
        termios.c_cflag &= ~(CSIZE | PARENB);
        termios.c_cflag |= CLOCAL | CS8;
        termios.c_cflag |= CLOCAL | CS8;
        termios.c_cc[VMIN] = 0;
        termios.c_cc[VMIN] = 0;
        termios.c_cc[VTIME] = 0;
        termios.c_cc[VTIME] = 0;
 
 
        tcsetattr (remote_desc, TCSANOW, &termios);
        tcsetattr (remote_desc, TCSANOW, &termios);
      }
      }
#endif
#endif
 
 
#ifdef HAVE_TERMIO
#ifdef HAVE_TERMIO
      {
      {
        struct termio termio;
        struct termio termio;
        ioctl (remote_desc, TCGETA, &termio);
        ioctl (remote_desc, TCGETA, &termio);
 
 
        termio.c_iflag = 0;
        termio.c_iflag = 0;
        termio.c_oflag = 0;
        termio.c_oflag = 0;
        termio.c_lflag = 0;
        termio.c_lflag = 0;
        termio.c_cflag &= ~(CSIZE | PARENB);
        termio.c_cflag &= ~(CSIZE | PARENB);
        termio.c_cflag |= CLOCAL | CS8;
        termio.c_cflag |= CLOCAL | CS8;
        termio.c_cc[VMIN] = 0;
        termio.c_cc[VMIN] = 0;
        termio.c_cc[VTIME] = 0;
        termio.c_cc[VTIME] = 0;
 
 
        ioctl (remote_desc, TCSETA, &termio);
        ioctl (remote_desc, TCSETA, &termio);
      }
      }
#endif
#endif
 
 
#ifdef HAVE_SGTTY
#ifdef HAVE_SGTTY
      {
      {
        struct sgttyb sg;
        struct sgttyb sg;
 
 
        ioctl (remote_desc, TIOCGETP, &sg);
        ioctl (remote_desc, TIOCGETP, &sg);
        sg.sg_flags = RAW;
        sg.sg_flags = RAW;
        ioctl (remote_desc, TIOCSETP, &sg);
        ioctl (remote_desc, TIOCSETP, &sg);
      }
      }
#endif
#endif
 
 
 
 
    }
    }
  else
  else
    {
    {
      char *port_str;
      char *port_str;
      int port;
      int port;
      struct sockaddr_in sockaddr;
      struct sockaddr_in sockaddr;
      int tmp;
      int tmp;
      struct protoent *protoent;
      struct protoent *protoent;
      int tmp_desc;
      int tmp_desc;
 
 
      port_str = strchr (name, ':');
      port_str = strchr (name, ':');
 
 
      port = atoi (port_str + 1);
      port = atoi (port_str + 1);
 
 
      tmp_desc = socket (PF_INET, SOCK_STREAM, 0);
      tmp_desc = socket (PF_INET, SOCK_STREAM, 0);
      if (tmp_desc < 0)
      if (tmp_desc < 0)
        perror_with_name ("Can't open socket");
        perror_with_name ("Can't open socket");
 
 
      /* Allow rapid reuse of this port. */
      /* Allow rapid reuse of this port. */
      tmp = 1;
      tmp = 1;
      setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp,
      setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp,
                  sizeof (tmp));
                  sizeof (tmp));
 
 
      sockaddr.sin_family = PF_INET;
      sockaddr.sin_family = PF_INET;
      sockaddr.sin_port = htons (port);
      sockaddr.sin_port = htons (port);
      sockaddr.sin_addr.s_addr = INADDR_ANY;
      sockaddr.sin_addr.s_addr = INADDR_ANY;
 
 
      if (bind (tmp_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr))
      if (bind (tmp_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr))
          || listen (tmp_desc, 1))
          || listen (tmp_desc, 1))
        perror_with_name ("Can't bind address");
        perror_with_name ("Can't bind address");
 
 
      tmp = sizeof (sockaddr);
      tmp = sizeof (sockaddr);
      remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &tmp);
      remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &tmp);
      if (remote_desc == -1)
      if (remote_desc == -1)
        perror_with_name ("Accept failed");
        perror_with_name ("Accept failed");
 
 
      protoent = getprotobyname ("tcp");
      protoent = getprotobyname ("tcp");
      if (!protoent)
      if (!protoent)
        perror_with_name ("getprotobyname");
        perror_with_name ("getprotobyname");
 
 
      /* Enable TCP keep alive process. */
      /* Enable TCP keep alive process. */
      tmp = 1;
      tmp = 1;
      setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (tmp));
      setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (tmp));
 
 
      /* Tell TCP not to delay small packets.  This greatly speeds up
      /* Tell TCP not to delay small packets.  This greatly speeds up
         interactive response. */
         interactive response. */
      tmp = 1;
      tmp = 1;
      setsockopt (remote_desc, protoent->p_proto, TCP_NODELAY,
      setsockopt (remote_desc, protoent->p_proto, TCP_NODELAY,
                  (char *) &tmp, sizeof (tmp));
                  (char *) &tmp, sizeof (tmp));
 
 
      close (tmp_desc);         /* No longer need this */
      close (tmp_desc);         /* No longer need this */
 
 
      signal (SIGPIPE, SIG_IGN);        /* If we don't do this, then gdbserver simply
      signal (SIGPIPE, SIG_IGN);        /* If we don't do this, then gdbserver simply
                                           exits when the remote side dies.  */
                                           exits when the remote side dies.  */
    }
    }
 
 
#if defined(F_SETFL) && defined (FASYNC)
#if defined(F_SETFL) && defined (FASYNC)
  save_fcntl_flags = fcntl (remote_desc, F_GETFL, 0);
  save_fcntl_flags = fcntl (remote_desc, F_GETFL, 0);
  fcntl (remote_desc, F_SETFL, save_fcntl_flags | FASYNC);
  fcntl (remote_desc, F_SETFL, save_fcntl_flags | FASYNC);
  disable_async_io ();
  disable_async_io ();
#endif /* FASYNC */
#endif /* FASYNC */
  fprintf (stderr, "Remote debugging using %s\n", name);
  fprintf (stderr, "Remote debugging using %s\n", name);
}
}
 
 
void
void
remote_close ()
remote_close ()
{
{
  close (remote_desc);
  close (remote_desc);
}
}
 
 
/* Convert hex digit A to a number.  */
/* Convert hex digit A to a number.  */
 
 
static int
static int
fromhex (a)
fromhex (a)
     int a;
     int a;
{
{
  if (a >= '0' && a <= '9')
  if (a >= '0' && a <= '9')
    return a - '0';
    return a - '0';
  else if (a >= 'a' && a <= 'f')
  else if (a >= 'a' && a <= 'f')
    return a - 'a' + 10;
    return a - 'a' + 10;
  else
  else
    error ("Reply contains invalid hex digit");
    error ("Reply contains invalid hex digit");
}
}
 
 
/* Convert number NIB to a hex digit.  */
/* Convert number NIB to a hex digit.  */
 
 
static int
static int
tohex (nib)
tohex (nib)
     int nib;
     int nib;
{
{
  if (nib < 10)
  if (nib < 10)
    return '0' + nib;
    return '0' + nib;
  else
  else
    return 'a' + nib - 10;
    return 'a' + nib - 10;
}
}
 
 
/* Send a packet to the remote machine, with error checking.
/* Send a packet to the remote machine, with error checking.
   The data of the packet is in BUF.  Returns >= 0 on success, -1 otherwise. */
   The data of the packet is in BUF.  Returns >= 0 on success, -1 otherwise. */
 
 
int
int
putpkt (buf)
putpkt (buf)
     char *buf;
     char *buf;
{
{
  int i;
  int i;
  unsigned char csum = 0;
  unsigned char csum = 0;
  char buf2[PBUFSIZ];
  char buf2[PBUFSIZ];
  char buf3[1];
  char buf3[1];
  int cnt = strlen (buf);
  int cnt = strlen (buf);
  char *p;
  char *p;
 
 
  /* Copy the packet into buffer BUF2, encapsulating it
  /* Copy the packet into buffer BUF2, encapsulating it
     and giving it a checksum.  */
     and giving it a checksum.  */
 
 
  p = buf2;
  p = buf2;
  *p++ = '$';
  *p++ = '$';
 
 
  for (i = 0; i < cnt; i++)
  for (i = 0; i < cnt; i++)
    {
    {
      csum += buf[i];
      csum += buf[i];
      *p++ = buf[i];
      *p++ = buf[i];
    }
    }
  *p++ = '#';
  *p++ = '#';
  *p++ = tohex ((csum >> 4) & 0xf);
  *p++ = tohex ((csum >> 4) & 0xf);
  *p++ = tohex (csum & 0xf);
  *p++ = tohex (csum & 0xf);
 
 
  *p = '\0';
  *p = '\0';
 
 
  /* Send it over and over until we get a positive ack.  */
  /* Send it over and over until we get a positive ack.  */
 
 
  do
  do
    {
    {
      int cc;
      int cc;
 
 
      if (write (remote_desc, buf2, p - buf2) != p - buf2)
      if (write (remote_desc, buf2, p - buf2) != p - buf2)
        {
        {
          perror ("putpkt(write)");
          perror ("putpkt(write)");
          return -1;
          return -1;
        }
        }
 
 
      if (remote_debug)
      if (remote_debug)
        printf ("putpkt (\"%s\"); [looking for ack]\n", buf2);
        printf ("putpkt (\"%s\"); [looking for ack]\n", buf2);
      cc = read (remote_desc, buf3, 1);
      cc = read (remote_desc, buf3, 1);
      if (remote_debug)
      if (remote_debug)
        printf ("[received '%c' (0x%x)]\n", buf3[0], buf3[0]);
        printf ("[received '%c' (0x%x)]\n", buf3[0], buf3[0]);
      if (cc <= 0)
      if (cc <= 0)
        {
        {
          if (cc == 0)
          if (cc == 0)
            fprintf (stderr, "putpkt(read): Got EOF\n");
            fprintf (stderr, "putpkt(read): Got EOF\n");
          else
          else
            perror ("putpkt(read)");
            perror ("putpkt(read)");
 
 
          return -1;
          return -1;
        }
        }
    }
    }
  while (buf3[0] != '+');
  while (buf3[0] != '+');
 
 
  return 1;                     /* Success! */
  return 1;                     /* Success! */
}
}
 
 
/* Come here when we get an input interrupt from the remote side.  This
/* Come here when we get an input interrupt from the remote side.  This
   interrupt should only be active while we are waiting for the child to do
   interrupt should only be active while we are waiting for the child to do
   something.  About the only thing that should come through is a ^C, which
   something.  About the only thing that should come through is a ^C, which
   will cause us to send a SIGINT to the child.  */
   will cause us to send a SIGINT to the child.  */
 
 
static void
static void
input_interrupt ()
input_interrupt ()
{
{
  int cc;
  int cc;
  char c;
  char c;
 
 
  cc = read (remote_desc, &c, 1);
  cc = read (remote_desc, &c, 1);
 
 
  if (cc != 1 || c != '\003')
  if (cc != 1 || c != '\003')
    {
    {
      fprintf (stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
      fprintf (stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
      return;
      return;
    }
    }
 
 
  kill (inferior_pid, SIGINT);
  kill (inferior_pid, SIGINT);
}
}
 
 
void
void
enable_async_io ()
enable_async_io ()
{
{
  signal (SIGIO, input_interrupt);
  signal (SIGIO, input_interrupt);
}
}
 
 
void
void
disable_async_io ()
disable_async_io ()
{
{
  signal (SIGIO, SIG_IGN);
  signal (SIGIO, SIG_IGN);
}
}
 
 
/* Returns next char from remote GDB.  -1 if error.  */
/* Returns next char from remote GDB.  -1 if error.  */
 
 
static int
static int
readchar ()
readchar ()
{
{
  static char buf[BUFSIZ];
  static char buf[BUFSIZ];
  static int bufcnt = 0;
  static int bufcnt = 0;
  static char *bufp;
  static char *bufp;
 
 
  if (bufcnt-- > 0)
  if (bufcnt-- > 0)
    return *bufp++ & 0x7f;
    return *bufp++ & 0x7f;
 
 
  bufcnt = read (remote_desc, buf, sizeof (buf));
  bufcnt = read (remote_desc, buf, sizeof (buf));
 
 
  if (bufcnt <= 0)
  if (bufcnt <= 0)
    {
    {
      if (bufcnt == 0)
      if (bufcnt == 0)
        fprintf (stderr, "readchar: Got EOF\n");
        fprintf (stderr, "readchar: Got EOF\n");
      else
      else
        perror ("readchar");
        perror ("readchar");
 
 
      return -1;
      return -1;
    }
    }
 
 
  bufp = buf;
  bufp = buf;
  bufcnt--;
  bufcnt--;
  return *bufp++ & 0x7f;
  return *bufp++ & 0x7f;
}
}
 
 
/* Read a packet from the remote machine, with error checking,
/* Read a packet from the remote machine, with error checking,
   and store it in BUF.  Returns length of packet, or negative if error. */
   and store it in BUF.  Returns length of packet, or negative if error. */
 
 
int
int
getpkt (buf)
getpkt (buf)
     char *buf;
     char *buf;
{
{
  char *bp;
  char *bp;
  unsigned char csum, c1, c2;
  unsigned char csum, c1, c2;
  int c;
  int c;
 
 
  while (1)
  while (1)
    {
    {
      csum = 0;
      csum = 0;
 
 
      while (1)
      while (1)
        {
        {
          c = readchar ();
          c = readchar ();
          if (c == '$')
          if (c == '$')
            break;
            break;
          if (remote_debug)
          if (remote_debug)
            printf ("[getpkt: discarding char '%c']\n", c);
            printf ("[getpkt: discarding char '%c']\n", c);
          if (c < 0)
          if (c < 0)
            return -1;
            return -1;
        }
        }
 
 
      bp = buf;
      bp = buf;
      while (1)
      while (1)
        {
        {
          c = readchar ();
          c = readchar ();
          if (c < 0)
          if (c < 0)
            return -1;
            return -1;
          if (c == '#')
          if (c == '#')
            break;
            break;
          *bp++ = c;
          *bp++ = c;
          csum += c;
          csum += c;
        }
        }
      *bp = 0;
      *bp = 0;
 
 
      c1 = fromhex (readchar ());
      c1 = fromhex (readchar ());
      c2 = fromhex (readchar ());
      c2 = fromhex (readchar ());
 
 
      if (csum == (c1 << 4) + c2)
      if (csum == (c1 << 4) + c2)
        break;
        break;
 
 
      fprintf (stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
      fprintf (stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
               (c1 << 4) + c2, csum, buf);
               (c1 << 4) + c2, csum, buf);
      write (remote_desc, "-", 1);
      write (remote_desc, "-", 1);
    }
    }
 
 
  if (remote_debug)
  if (remote_debug)
    printf ("getpkt (\"%s\");  [sending ack] \n", buf);
    printf ("getpkt (\"%s\");  [sending ack] \n", buf);
 
 
  write (remote_desc, "+", 1);
  write (remote_desc, "+", 1);
 
 
  if (remote_debug)
  if (remote_debug)
    printf ("[sent ack]\n");
    printf ("[sent ack]\n");
  return bp - buf;
  return bp - buf;
}
}
 
 
void
void
write_ok (buf)
write_ok (buf)
     char *buf;
     char *buf;
{
{
  buf[0] = 'O';
  buf[0] = 'O';
  buf[1] = 'K';
  buf[1] = 'K';
  buf[2] = '\0';
  buf[2] = '\0';
}
}
 
 
void
void
write_enn (buf)
write_enn (buf)
     char *buf;
     char *buf;
{
{
  buf[0] = 'E';
  buf[0] = 'E';
  buf[1] = 'N';
  buf[1] = 'N';
  buf[2] = 'N';
  buf[2] = 'N';
  buf[3] = '\0';
  buf[3] = '\0';
}
}
 
 
void
void
convert_int_to_ascii (from, to, n)
convert_int_to_ascii (from, to, n)
     char *from, *to;
     char *from, *to;
     int n;
     int n;
{
{
  int nib;
  int nib;
  char ch;
  char ch;
  while (n--)
  while (n--)
    {
    {
      ch = *from++;
      ch = *from++;
      nib = ((ch & 0xf0) >> 4) & 0x0f;
      nib = ((ch & 0xf0) >> 4) & 0x0f;
      *to++ = tohex (nib);
      *to++ = tohex (nib);
      nib = ch & 0x0f;
      nib = ch & 0x0f;
      *to++ = tohex (nib);
      *to++ = tohex (nib);
    }
    }
  *to++ = 0;
  *to++ = 0;
}
}
 
 
 
 
void
void
convert_ascii_to_int (from, to, n)
convert_ascii_to_int (from, to, n)
     char *from, *to;
     char *from, *to;
     int n;
     int n;
{
{
  int nib1, nib2;
  int nib1, nib2;
  while (n--)
  while (n--)
    {
    {
      nib1 = fromhex (*from++);
      nib1 = fromhex (*from++);
      nib2 = fromhex (*from++);
      nib2 = fromhex (*from++);
      *to++ = (((nib1 & 0x0f) << 4) & 0xf0) | (nib2 & 0x0f);
      *to++ = (((nib1 & 0x0f) << 4) & 0xf0) | (nib2 & 0x0f);
    }
    }
}
}
 
 
static char *
static char *
outreg (regno, buf)
outreg (regno, buf)
     int regno;
     int regno;
     char *buf;
     char *buf;
{
{
  int regsize = REGISTER_RAW_SIZE (regno);
  int regsize = REGISTER_RAW_SIZE (regno);
 
 
  if ((regno >> 12) != 0)
  if ((regno >> 12) != 0)
    *buf++ = tohex ((regno >> 12) & 0xf);
    *buf++ = tohex ((regno >> 12) & 0xf);
  if ((regno >> 8) != 0)
  if ((regno >> 8) != 0)
    *buf++ = tohex ((regno >> 8) & 0xf);
    *buf++ = tohex ((regno >> 8) & 0xf);
  *buf++ = tohex ((regno >> 4) & 0xf);
  *buf++ = tohex ((regno >> 4) & 0xf);
  *buf++ = tohex (regno & 0xf);
  *buf++ = tohex (regno & 0xf);
  *buf++ = ':';
  *buf++ = ':';
  convert_int_to_ascii (&registers[REGISTER_BYTE (regno)], buf, regsize);
  convert_int_to_ascii (&registers[REGISTER_BYTE (regno)], buf, regsize);
  buf += 2 * regsize;
  buf += 2 * regsize;
  *buf++ = ';';
  *buf++ = ';';
 
 
  return buf;
  return buf;
}
}
 
 
void
void
prepare_resume_reply (buf, status, signo)
prepare_resume_reply (buf, status, signo)
     char *buf;
     char *buf;
     char status;
     char status;
     unsigned char signo;
     unsigned char signo;
{
{
  int nib;
  int nib;
 
 
  *buf++ = status;
  *buf++ = status;
 
 
  /* FIXME!  Should be converting this signal number (numbered
  /* FIXME!  Should be converting this signal number (numbered
     according to the signal numbering of the system we are running on)
     according to the signal numbering of the system we are running on)
     to the signal numbers used by the gdb protocol (see enum target_signal
     to the signal numbers used by the gdb protocol (see enum target_signal
     in gdb/target.h).  */
     in gdb/target.h).  */
  nib = ((signo & 0xf0) >> 4);
  nib = ((signo & 0xf0) >> 4);
  *buf++ = tohex (nib);
  *buf++ = tohex (nib);
  nib = signo & 0x0f;
  nib = signo & 0x0f;
  *buf++ = tohex (nib);
  *buf++ = tohex (nib);
 
 
  if (status == 'T')
  if (status == 'T')
    {
    {
#ifdef GDBSERVER_RESUME_REGS
#ifdef GDBSERVER_RESUME_REGS
      static int gdbserver_resume_regs[] = GDBSERVER_RESUME_REGS ;
      static int gdbserver_resume_regs[] = GDBSERVER_RESUME_REGS ;
      int i;
      int i;
      for (i = 0;
      for (i = 0;
           i < sizeof (gdbserver_resume_regs)
           i < sizeof (gdbserver_resume_regs)
                / sizeof (gdbserver_resume_regs[0]);
                / sizeof (gdbserver_resume_regs[0]);
           i++)
           i++)
        {
        {
          int regnum = gdbserver_resume_regs[i];
          int regnum = gdbserver_resume_regs[i];
          buf = outreg (regnum, buf);
          buf = outreg (regnum, buf);
        }
        }
#else /* !defined(GDBSERVER_RESUME_REGS) */
#else /* !defined(GDBSERVER_RESUME_REGS) */
      buf = outreg (PC_REGNUM, buf);
      buf = outreg (PC_REGNUM, buf);
      buf = outreg (FP_REGNUM, buf);
      buf = outreg (FP_REGNUM, buf);
      buf = outreg (SP_REGNUM, buf);
      buf = outreg (SP_REGNUM, buf);
#ifdef NPC_REGNUM
#ifdef NPC_REGNUM
      buf = outreg (NPC_REGNUM, buf);
      buf = outreg (NPC_REGNUM, buf);
#endif
#endif
#ifdef O7_REGNUM
#ifdef O7_REGNUM
      buf = outreg (O7_REGNUM, buf);
      buf = outreg (O7_REGNUM, buf);
#endif
#endif
#endif /* GDBSERVER_RESUME_REGS */
#endif /* GDBSERVER_RESUME_REGS */
 
 
      /* If the debugger hasn't used any thread features, don't burden it with
      /* If the debugger hasn't used any thread features, don't burden it with
         threads.  If we didn't check this, GDB 4.13 and older would choke.  */
         threads.  If we didn't check this, GDB 4.13 and older would choke.  */
      if (cont_thread != 0)
      if (cont_thread != 0)
        {
        {
          if (old_thread_from_wait != thread_from_wait)
          if (old_thread_from_wait != thread_from_wait)
            {
            {
              sprintf (buf, "thread:%x;", thread_from_wait);
              sprintf (buf, "thread:%x;", thread_from_wait);
              buf += strlen (buf);
              buf += strlen (buf);
              old_thread_from_wait = thread_from_wait;
              old_thread_from_wait = thread_from_wait;
            }
            }
        }
        }
    }
    }
  /* For W and X, we're done.  */
  /* For W and X, we're done.  */
  *buf++ = 0;
  *buf++ = 0;
}
}
 
 
void
void
decode_m_packet (from, mem_addr_ptr, len_ptr)
decode_m_packet (from, mem_addr_ptr, len_ptr)
     char *from;
     char *from;
     CORE_ADDR *mem_addr_ptr;
     CORE_ADDR *mem_addr_ptr;
     unsigned int *len_ptr;
     unsigned int *len_ptr;
{
{
  int i = 0, j = 0;
  int i = 0, j = 0;
  char ch;
  char ch;
  *mem_addr_ptr = *len_ptr = 0;
  *mem_addr_ptr = *len_ptr = 0;
 
 
  while ((ch = from[i++]) != ',')
  while ((ch = from[i++]) != ',')
    {
    {
      *mem_addr_ptr = *mem_addr_ptr << 4;
      *mem_addr_ptr = *mem_addr_ptr << 4;
      *mem_addr_ptr |= fromhex (ch) & 0x0f;
      *mem_addr_ptr |= fromhex (ch) & 0x0f;
    }
    }
 
 
  for (j = 0; j < 4; j++)
  for (j = 0; j < 4; j++)
    {
    {
      if ((ch = from[i++]) == 0)
      if ((ch = from[i++]) == 0)
        break;
        break;
      *len_ptr = *len_ptr << 4;
      *len_ptr = *len_ptr << 4;
      *len_ptr |= fromhex (ch) & 0x0f;
      *len_ptr |= fromhex (ch) & 0x0f;
    }
    }
}
}
 
 
void
void
decode_M_packet (from, mem_addr_ptr, len_ptr, to)
decode_M_packet (from, mem_addr_ptr, len_ptr, to)
     char *from, *to;
     char *from, *to;
     CORE_ADDR *mem_addr_ptr;
     CORE_ADDR *mem_addr_ptr;
     unsigned int *len_ptr;
     unsigned int *len_ptr;
{
{
  int i = 0;
  int i = 0;
  char ch;
  char ch;
  *mem_addr_ptr = *len_ptr = 0;
  *mem_addr_ptr = *len_ptr = 0;
 
 
  while ((ch = from[i++]) != ',')
  while ((ch = from[i++]) != ',')
    {
    {
      *mem_addr_ptr = *mem_addr_ptr << 4;
      *mem_addr_ptr = *mem_addr_ptr << 4;
      *mem_addr_ptr |= fromhex (ch) & 0x0f;
      *mem_addr_ptr |= fromhex (ch) & 0x0f;
    }
    }
 
 
  while ((ch = from[i++]) != ':')
  while ((ch = from[i++]) != ':')
    {
    {
      *len_ptr = *len_ptr << 4;
      *len_ptr = *len_ptr << 4;
      *len_ptr |= fromhex (ch) & 0x0f;
      *len_ptr |= fromhex (ch) & 0x0f;
    }
    }
 
 
  convert_ascii_to_int (&from[i++], to, *len_ptr);
  convert_ascii_to_int (&from[i++], to, *len_ptr);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.