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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc1/] [sim/] [arm/] [kid.c] - Diff between revs 330 and 341

Only display areas with differences | Details | Blame | View Log

Rev 330 Rev 341
/*  kid.c -- ARMulator RDP/RDI interface:  ARM6 Instruction Emulator.
/*  kid.c -- ARMulator RDP/RDI interface:  ARM6 Instruction Emulator.
    Copyright (C) 1994 Advanced RISC Machines Ltd.
    Copyright (C) 1994 Advanced RISC Machines Ltd.
 
 
    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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
 
 
/*****************************************************************/
/*****************************************************************/
/* The child process continues here...                           */
/* The child process continues here...                           */
/* It waits on a pipe from the parent and translates the RDP     */
/* It waits on a pipe from the parent and translates the RDP     */
/* messages into RDI calls to the ARMulator passing RDP replies  */
/* messages into RDI calls to the ARMulator passing RDP replies  */
/* back up a pipe to the parent.                                 */
/* back up a pipe to the parent.                                 */
/*****************************************************************/
/*****************************************************************/
 
 
#include <sys/types.h>
#include <sys/types.h>
#include <signal.h>
#include <signal.h>
 
 
#include "armdefs.h"
#include "armdefs.h"
#include "dbg_conf.h"
#include "dbg_conf.h"
#include "dbg_hif.h"
#include "dbg_hif.h"
#include "dbg_rdi.h"
#include "dbg_rdi.h"
#include "gdbhost.h"
#include "gdbhost.h"
#include "communicate.h"
#include "communicate.h"
 
 
/* The pipes between the two processes */
/* The pipes between the two processes */
extern int mumkid[2];
extern int mumkid[2];
extern int kidmum[2];
extern int kidmum[2];
 
 
/* The maximum number of file descriptors */
/* The maximum number of file descriptors */
extern int nfds;
extern int nfds;
 
 
/* The machine name */
/* The machine name */
#define MAXHOSTNAMELENGTH 64
#define MAXHOSTNAMELENGTH 64
extern char localhost[MAXHOSTNAMELENGTH + 1];
extern char localhost[MAXHOSTNAMELENGTH + 1];
 
 
/* The socket number */
/* The socket number */
extern unsigned int socketnumber;
extern unsigned int socketnumber;
 
 
/* RDI interface */
/* RDI interface */
extern const struct RDIProcVec armul_rdi;
extern const struct RDIProcVec armul_rdi;
 
 
static int MYrdp_level = 0;
static int MYrdp_level = 0;
 
 
static int rdi_state = 0;
static int rdi_state = 0;
 
 
/**************************************************************/
/**************************************************************/
/* Signal handler that terminates excecution in the ARMulator */
/* Signal handler that terminates excecution in the ARMulator */
/**************************************************************/
/**************************************************************/
void
void
kid_handlesignal (int sig)
kid_handlesignal (int sig)
{
{
#ifdef DEBUG
#ifdef DEBUG
  fprintf (stderr, "Terminate ARMulator excecution\n");
  fprintf (stderr, "Terminate ARMulator excecution\n");
#endif
#endif
  if (sig != SIGUSR1)
  if (sig != SIGUSR1)
    {
    {
      fprintf (stderr, "Unsupported signal.\n");
      fprintf (stderr, "Unsupported signal.\n");
      return;
      return;
    }
    }
  armul_rdi.info (RDISignal_Stop, (unsigned long *) 0, (unsigned long *) 0);
  armul_rdi.info (RDISignal_Stop, (unsigned long *) 0, (unsigned long *) 0);
}
}
 
 
/********************************************************************/
/********************************************************************/
/* Waits on a pipe from the socket demon for RDP and                */
/* Waits on a pipe from the socket demon for RDP and                */
/* acts as an RDP to RDI interpreter on the front of the ARMulator. */
/* acts as an RDP to RDI interpreter on the front of the ARMulator. */
/********************************************************************/
/********************************************************************/
void
void
kid ()
kid ()
{
{
  char *p, *q;
  char *p, *q;
  int i, j, k;
  int i, j, k;
  long outofthebag;
  long outofthebag;
  unsigned char c, d, message;
  unsigned char c, d, message;
  ARMword x, y, z;
  ARMword x, y, z;
  struct sigaction action;
  struct sigaction action;
  PointHandle point;
  PointHandle point;
  Dbg_ConfigBlock config;
  Dbg_ConfigBlock config;
  Dbg_HostosInterface hostif;
  Dbg_HostosInterface hostif;
  struct Dbg_MCState *MCState;
  struct Dbg_MCState *MCState;
  char command_line[256];
  char command_line[256];
  struct fd_set readfds;
  struct fd_set readfds;
 
 
  /* Setup a signal handler for SIGUSR1 */
  /* Setup a signal handler for SIGUSR1 */
  action.sa_handler = kid_handlesignal;
  action.sa_handler = kid_handlesignal;
  action.sa_mask = 0;
  action.sa_mask = 0;
  action.sa_flags = 0;
  action.sa_flags = 0;
 
 
  sigaction (SIGUSR1, &action, (struct sigaction *) 0);
  sigaction (SIGUSR1, &action, (struct sigaction *) 0);
 
 
  while (1)
  while (1)
    {
    {
      /* Wait for ever */
      /* Wait for ever */
      FD_ZERO (&readfds);
      FD_ZERO (&readfds);
      FD_SET (mumkid[0], &readfds);
      FD_SET (mumkid[0], &readfds);
 
 
      i = select (nfds, &readfds,
      i = select (nfds, &readfds,
                  (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0);
                  (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0);
 
 
      if (i < 0)
      if (i < 0)
        {
        {
          perror ("select");
          perror ("select");
        }
        }
 
 
      if (read (mumkid[0], &message, 1) < 1)
      if (read (mumkid[0], &message, 1) < 1)
        {
        {
          perror ("read");
          perror ("read");
        }
        }
 
 
      switch (message)
      switch (message)
        {
        {
        case RDP_Start:
        case RDP_Start:
          /* Open and/or Initialise */
          /* Open and/or Initialise */
          BAG_newbag ();
          BAG_newbag ();
 
 
          MYread_char (mumkid[0], &c);   /* type */
          MYread_char (mumkid[0], &c);   /* type */
          MYread_word (mumkid[0], &x);   /* memorysize */
          MYread_word (mumkid[0], &x);   /* memorysize */
          if (c & 0x2)
          if (c & 0x2)
            MYread_char (mumkid[0], &d); /* speed */
            MYread_char (mumkid[0], &d); /* speed */
          config.processor = 0;
          config.processor = 0;
          config.memorysize = x;
          config.memorysize = x;
          config.bytesex = (c & 0x4) ? RDISex_Big : RDISex_Little;
          config.bytesex = (c & 0x4) ? RDISex_Big : RDISex_Little;
          if (c & 0x8)
          if (c & 0x8)
            config.bytesex = RDISex_DontCare;
            config.bytesex = RDISex_DontCare;
 
 
          hostif.dbgprint = myprint;
          hostif.dbgprint = myprint;
          hostif.dbgpause = mypause;
          hostif.dbgpause = mypause;
          hostif.dbgarg = stdout;
          hostif.dbgarg = stdout;
          hostif.writec = mywritec;
          hostif.writec = mywritec;
          hostif.readc = myreadc;
          hostif.readc = myreadc;
          hostif.write = mywrite;
          hostif.write = mywrite;
          hostif.gets = mygets;
          hostif.gets = mygets;
          hostif.reset = mypause;       /* do nothing */
          hostif.reset = mypause;       /* do nothing */
          hostif.resetarg = "Do I love resetting or what!\n";
          hostif.resetarg = "Do I love resetting or what!\n";
 
 
          if (rdi_state)
          if (rdi_state)
            {
            {
              /* we have restarted, so kill off the existing run.  */
              /* we have restarted, so kill off the existing run.  */
              /* armul_rdi.close(); */
              /* armul_rdi.close(); */
            }
            }
          i = armul_rdi.open (c & 0x3, &config, &hostif, MCState);
          i = armul_rdi.open (c & 0x3, &config, &hostif, MCState);
          rdi_state = 1;
          rdi_state = 1;
 
 
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
 
 
          x = ~0x4;
          x = ~0x4;
          armul_rdi.info (RDIVector_Catch, &x, 0);
          armul_rdi.info (RDIVector_Catch, &x, 0);
 
 
          break;
          break;
 
 
        case RDP_End:
        case RDP_End:
          /* Close and Finalise */
          /* Close and Finalise */
          i = armul_rdi.close ();
          i = armul_rdi.close ();
          rdi_state = 0;
          rdi_state = 0;
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_Read:
        case RDP_Read:
          /* Read Memory Address */
          /* Read Memory Address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &y);   /* nbytes */
          MYread_word (mumkid[0], &y);   /* nbytes */
          p = (char *) malloc (y);
          p = (char *) malloc (y);
          i = armul_rdi.read (x, p, (unsigned *) &y);
          i = armul_rdi.read (x, p, (unsigned *) &y);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          for (k = 0; k < y; k++)
          for (k = 0; k < y; k++)
            MYwrite_char (kidmum[1], p[k]);
            MYwrite_char (kidmum[1], p[k]);
          free (p);
          free (p);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          if (i)
          if (i)
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
          break;
          break;
 
 
        case RDP_Write:
        case RDP_Write:
          /* Write Memory Address */
          /* Write Memory Address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &y);   /* nbytes */
          MYread_word (mumkid[0], &y);   /* nbytes */
          p = (char *) malloc (y);
          p = (char *) malloc (y);
          for (k = 0; k < y; k++)
          for (k = 0; k < y; k++)
            MYread_char (mumkid[0], &p[k]);
            MYread_char (mumkid[0], &p[k]);
          i = armul_rdi.write (p, x, (unsigned *) &y);
          i = armul_rdi.write (p, x, (unsigned *) &y);
          free (p);
          free (p);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          if (i)
          if (i)
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
          break;
          break;
 
 
        case RDP_CPUread:
        case RDP_CPUread:
          /* Read CPU State */
          /* Read CPU State */
          MYread_char (mumkid[0], &c);   /* mode */
          MYread_char (mumkid[0], &c);   /* mode */
          MYread_word (mumkid[0], &x);   /* mask */
          MYread_word (mumkid[0], &x);   /* mask */
          p = (char *) malloc (4 * RDINumCPURegs);
          p = (char *) malloc (4 * RDINumCPURegs);
          i = armul_rdi.CPUread (c, x, (ARMword *) p);
          i = armul_rdi.CPUread (c, x, (ARMword *) p);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          for (k = 1, j = 0; k != 0x80000000; k *= 2)
          for (k = 1, j = 0; k != 0x80000000; k *= 2)
            if (k & x)
            if (k & x)
              MYwrite_word (kidmum[1], ((ARMword *) p)[j++]);
              MYwrite_word (kidmum[1], ((ARMword *) p)[j++]);
          free (p);
          free (p);
          if (i)
          if (i)
            MYwrite_char (kidmum[1], (unsigned char) j);
            MYwrite_char (kidmum[1], (unsigned char) j);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_CPUwrite:
        case RDP_CPUwrite:
          /* Write CPU State */
          /* Write CPU State */
          MYread_char (mumkid[0], &c);   /* mode */
          MYread_char (mumkid[0], &c);   /* mode */
          MYread_word (mumkid[0], &x);   /* mask */
          MYread_word (mumkid[0], &x);   /* mask */
 
 
          p = (char *) malloc (4 * RDINumCPURegs);
          p = (char *) malloc (4 * RDINumCPURegs);
          for (k = 1, j = 0; k != 0x80000000; k *= 2)
          for (k = 1, j = 0; k != 0x80000000; k *= 2)
            if (k & x)
            if (k & x)
              MYread_word (mumkid[0], &(((ARMword *) p)[j++]));
              MYread_word (mumkid[0], &(((ARMword *) p)[j++]));
          i = armul_rdi.CPUwrite (c, x, (ARMword *) p);
          i = armul_rdi.CPUwrite (c, x, (ARMword *) p);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          free (p);
          free (p);
          break;
          break;
 
 
        case RDP_CPread:
        case RDP_CPread:
          /* Read Co-Processor State */
          /* Read Co-Processor State */
          MYread_char (mumkid[0], &c);   /* CPnum */
          MYread_char (mumkid[0], &c);   /* CPnum */
          MYread_word (mumkid[0], &x);   /* mask */
          MYread_word (mumkid[0], &x);   /* mask */
          p = q = (char *) malloc (16 * RDINumCPRegs);
          p = q = (char *) malloc (16 * RDINumCPRegs);
          i = armul_rdi.CPread (c, x, (ARMword *) p);
          i = armul_rdi.CPread (c, x, (ARMword *) p);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          for (k = 1, j = 0; k != 0x80000000; k *= 2, j++)
          for (k = 1, j = 0; k != 0x80000000; k *= 2, j++)
            if (k & x)
            if (k & x)
              {
              {
                if ((c == 1 || c == 2) && k <= 128)
                if ((c == 1 || c == 2) && k <= 128)
                  {
                  {
                    MYwrite_FPword (kidmum[1], q);
                    MYwrite_FPword (kidmum[1], q);
                    q += 16;
                    q += 16;
                  }
                  }
                else
                else
                  {
                  {
                    MYwrite_word (kidmum[1], *q);
                    MYwrite_word (kidmum[1], *q);
                    q += 4;
                    q += 4;
                  }
                  }
              }
              }
          free (p);
          free (p);
          if (i)
          if (i)
            MYwrite_char (kidmum[1], (unsigned char) j);
            MYwrite_char (kidmum[1], (unsigned char) j);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_CPwrite:
        case RDP_CPwrite:
          /* Write Co-Processor State */
          /* Write Co-Processor State */
          MYread_char (mumkid[0], &c);   /* CPnum */
          MYread_char (mumkid[0], &c);   /* CPnum */
          MYread_word (mumkid[0], &x);   /* mask */
          MYread_word (mumkid[0], &x);   /* mask */
          p = q = (char *) malloc (16 * RDINumCPURegs);
          p = q = (char *) malloc (16 * RDINumCPURegs);
          for (k = 1, j = 0; k != 0x80000000; k *= 2, j++)
          for (k = 1, j = 0; k != 0x80000000; k *= 2, j++)
            if (k & x)
            if (k & x)
              {
              {
                if ((c == 1 || c == 2) && k <= 128)
                if ((c == 1 || c == 2) && k <= 128)
                  {
                  {
                    MYread_FPword (kidmum[1], q);
                    MYread_FPword (kidmum[1], q);
                    q += 16;
                    q += 16;
                  }
                  }
                else
                else
                  {
                  {
                    MYread_word (mumkid[0], (ARMword *) q);
                    MYread_word (mumkid[0], (ARMword *) q);
                    q += 4;
                    q += 4;
                  }
                  }
              }
              }
          i = armul_rdi.CPwrite (c, x, (ARMword *) p);
          i = armul_rdi.CPwrite (c, x, (ARMword *) p);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          free (p);
          free (p);
          break;
          break;
 
 
        case RDP_SetBreak:
        case RDP_SetBreak:
          /* Set Breakpoint */
          /* Set Breakpoint */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_char (mumkid[0], &c);   /* type */
          MYread_char (mumkid[0], &c);   /* type */
          if ((c & 0xf) >= 5)
          if ((c & 0xf) >= 5)
            MYread_word (mumkid[0], &y); /* bound */
            MYread_word (mumkid[0], &y); /* bound */
          i = armul_rdi.setbreak (x, c, y, &point);
          i = armul_rdi.setbreak (x, c, y, &point);
          if (!MYrdp_level)
          if (!MYrdp_level)
            BAG_putpair ((long) x, (long) point);
            BAG_putpair ((long) x, (long) point);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          if (MYrdp_level)
          if (MYrdp_level)
            MYwrite_word (kidmum[1], point);
            MYwrite_word (kidmum[1], point);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_ClearBreak:
        case RDP_ClearBreak:
          /* Clear Breakpoint */
          /* Clear Breakpoint */
          MYread_word (mumkid[0], &point);       /* PointHandle */
          MYread_word (mumkid[0], &point);       /* PointHandle */
          if (!MYrdp_level)
          if (!MYrdp_level)
            {
            {
              BAG_getsecond ((long) point, &outofthebag);       /* swap pointhandle for address */
              BAG_getsecond ((long) point, &outofthebag);       /* swap pointhandle for address */
              BAG_killpair_byfirst (outofthebag);
              BAG_killpair_byfirst (outofthebag);
              point = outofthebag;
              point = outofthebag;
            }
            }
          i = armul_rdi.clearbreak (point);
          i = armul_rdi.clearbreak (point);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_SetWatch:
        case RDP_SetWatch:
          /* Set Watchpoint */
          /* Set Watchpoint */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_char (mumkid[0], &c);   /* type */
          MYread_char (mumkid[0], &c);   /* type */
          MYread_char (mumkid[0], &d);   /* datatype */
          MYread_char (mumkid[0], &d);   /* datatype */
          if ((c & 0xf) >= 5)
          if ((c & 0xf) >= 5)
            MYread_word (mumkid[0], &y); /* bound */
            MYread_word (mumkid[0], &y); /* bound */
          i = armul_rdi.setwatch (x, c, d, y, &point);
          i = armul_rdi.setwatch (x, c, d, y, &point);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_word (kidmum[1], point);
          MYwrite_word (kidmum[1], point);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_ClearWatch:
        case RDP_ClearWatch:
          /* Clear Watchpoint */
          /* Clear Watchpoint */
          MYread_word (mumkid[0], &point);       /* PointHandle */
          MYread_word (mumkid[0], &point);       /* PointHandle */
          i = armul_rdi.clearwatch (point);
          i = armul_rdi.clearwatch (point);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_Execute:
        case RDP_Execute:
          /* Excecute */
          /* Excecute */
 
 
          MYread_char (mumkid[0], &c);   /* return */
          MYread_char (mumkid[0], &c);   /* return */
 
 
#ifdef DEBUG
#ifdef DEBUG
          fprintf (stderr, "Starting execution\n");
          fprintf (stderr, "Starting execution\n");
#endif
#endif
          i = armul_rdi.execute (&point);
          i = armul_rdi.execute (&point);
#ifdef DEBUG
#ifdef DEBUG
          fprintf (stderr, "Completed execution\n");
          fprintf (stderr, "Completed execution\n");
#endif
#endif
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          if (c & 0x80)
          if (c & 0x80)
            MYwrite_word (kidmum[1], point);
            MYwrite_word (kidmum[1], point);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_Step:
        case RDP_Step:
          /* Step */
          /* Step */
          MYread_char (mumkid[0], &c);   /* return */
          MYread_char (mumkid[0], &c);   /* return */
          MYread_word (mumkid[0], &x);   /* ninstr */
          MYread_word (mumkid[0], &x);   /* ninstr */
          point = 0x87654321;
          point = 0x87654321;
          i = armul_rdi.step (x, &point);
          i = armul_rdi.step (x, &point);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          if (c & 0x80)
          if (c & 0x80)
            MYwrite_word (kidmum[1], point);
            MYwrite_word (kidmum[1], point);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          break;
          break;
 
 
        case RDP_Info:
        case RDP_Info:
          /* Info */
          /* Info */
          MYread_word (mumkid[0], &x);
          MYread_word (mumkid[0], &x);
          switch (x)
          switch (x)
            {
            {
            case RDIInfo_Target:
            case RDIInfo_Target:
              i = armul_rdi.info (RDIInfo_Target, &y, &z);
              i = armul_rdi.info (RDIInfo_Target, &y, &z);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_word (kidmum[1], y);      /* Loads of info... */
              MYwrite_word (kidmum[1], y);      /* Loads of info... */
              MYwrite_word (kidmum[1], z);      /* Model */
              MYwrite_word (kidmum[1], z);      /* Model */
              MYwrite_char (kidmum[1], (unsigned char) i);
              MYwrite_char (kidmum[1], (unsigned char) i);
              break;
              break;
 
 
            case RDISet_RDILevel:
            case RDISet_RDILevel:
              MYread_word (mumkid[0], &x);       /* arg1, debug level */
              MYread_word (mumkid[0], &x);       /* arg1, debug level */
              i = armul_rdi.info (RDISet_RDILevel, &x, 0);
              i = armul_rdi.info (RDISet_RDILevel, &x, 0);
              if (i == RDIError_NoError)
              if (i == RDIError_NoError)
                MYrdp_level = x;
                MYrdp_level = x;
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], (unsigned char) i);
              MYwrite_char (kidmum[1], (unsigned char) i);
              break;
              break;
 
 
            case RDISet_Cmdline:
            case RDISet_Cmdline:
              for (p = command_line; MYread_char (mumkid[0], p), *p; p++)
              for (p = command_line; MYread_char (mumkid[0], p), *p; p++)
                ;               /* String */
                ;               /* String */
              i = armul_rdi.info (RDISet_Cmdline,
              i = armul_rdi.info (RDISet_Cmdline,
                                  (unsigned long *) command_line, 0);
                                  (unsigned long *) command_line, 0);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], (unsigned char) i);
              MYwrite_char (kidmum[1], (unsigned char) i);
              break;
              break;
 
 
            case RDIInfo_Step:
            case RDIInfo_Step:
              i = armul_rdi.info (RDIInfo_Step, &x, 0);
              i = armul_rdi.info (RDIInfo_Step, &x, 0);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_word (kidmum[1], x);
              MYwrite_word (kidmum[1], x);
              MYwrite_char (kidmum[1], (unsigned char) i);
              MYwrite_char (kidmum[1], (unsigned char) i);
              break;
              break;
 
 
            case RDIVector_Catch:
            case RDIVector_Catch:
              MYread_word (mumkid[0], &x);
              MYread_word (mumkid[0], &x);
              i = armul_rdi.info (RDIVector_Catch, &x, 0);
              i = armul_rdi.info (RDIVector_Catch, &x, 0);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], i);
              MYwrite_char (kidmum[1], i);
              break;
              break;
 
 
            case RDIInfo_Points:
            case RDIInfo_Points:
              i = armul_rdi.info (RDIInfo_Points, &x, 0);
              i = armul_rdi.info (RDIInfo_Points, &x, 0);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_char (kidmum[1], RDP_Return);
              MYwrite_word (kidmum[1], x);
              MYwrite_word (kidmum[1], x);
              MYwrite_char (kidmum[1], (unsigned char) i);
              MYwrite_char (kidmum[1], (unsigned char) i);
              break;
              break;
 
 
            default:
            default:
              fprintf (stderr, "Unsupported info code %d\n", x);
              fprintf (stderr, "Unsupported info code %d\n", x);
              break;
              break;
            }
            }
          break;
          break;
 
 
        case RDP_OSOpReply:
        case RDP_OSOpReply:
          /* OS Operation Reply */
          /* OS Operation Reply */
          MYwrite_char (kidmum[1], RDP_Fatal);
          MYwrite_char (kidmum[1], RDP_Fatal);
          break;
          break;
 
 
        case RDP_Reset:
        case RDP_Reset:
          /* Reset */
          /* Reset */
          for (i = 0; i < 50; i++)
          for (i = 0; i < 50; i++)
            MYwrite_char (kidmum[1], RDP_Reset);
            MYwrite_char (kidmum[1], RDP_Reset);
          p = (char *) malloc (MAXHOSTNAMELENGTH + 5 + 20);
          p = (char *) malloc (MAXHOSTNAMELENGTH + 5 + 20);
          sprintf (p, "Running on %s:%d\n", localhost, socketnumber);
          sprintf (p, "Running on %s:%d\n", localhost, socketnumber);
          MYwrite_string (kidmum[1], p);
          MYwrite_string (kidmum[1], p);
          free (p);
          free (p);
 
 
          break;
          break;
        default:
        default:
          fprintf (stderr, "Oh dear: Something is seriously wrong :-(\n");
          fprintf (stderr, "Oh dear: Something is seriously wrong :-(\n");
          /* Hmm.. bad RDP operation */
          /* Hmm.. bad RDP operation */
          break;
          break;
        }
        }
    }
    }
}
}
 
 
 
 
/* Handles memory read operations until an OS Operation Reply Message is */
/* Handles memory read operations until an OS Operation Reply Message is */
/* encounterd. It then returns the byte info value (0, 1, or 2) and fills  */
/* encounterd. It then returns the byte info value (0, 1, or 2) and fills  */
/* in 'putinr0' with the data if appropriate. */
/* in 'putinr0' with the data if appropriate. */
int
int
wait_for_osreply (ARMword * reply)
wait_for_osreply (ARMword * reply)
{
{
  char *p, *q;
  char *p, *q;
  int i, j, k;
  int i, j, k;
  unsigned char c, d, message;
  unsigned char c, d, message;
  ARMword x, y, z;
  ARMword x, y, z;
  struct sigaction action;
  struct sigaction action;
  PointHandle point;
  PointHandle point;
  Dbg_ConfigBlock config;
  Dbg_ConfigBlock config;
  Dbg_HostosInterface hostif;
  Dbg_HostosInterface hostif;
  struct Dbg_MCState *MCState;
  struct Dbg_MCState *MCState;
  char command_line[256];
  char command_line[256];
  struct fd_set readfds;
  struct fd_set readfds;
 
 
#ifdef DEBUG
#ifdef DEBUG
  fprintf (stderr, "wait_for_osreply ().\n");
  fprintf (stderr, "wait_for_osreply ().\n");
#endif
#endif
 
 
  /* Setup a signal handler for SIGUSR1 */
  /* Setup a signal handler for SIGUSR1 */
  action.sa_handler = kid_handlesignal;
  action.sa_handler = kid_handlesignal;
  action.sa_mask = 0;
  action.sa_mask = 0;
  action.sa_flags = 0;
  action.sa_flags = 0;
 
 
  sigaction (SIGUSR1, &action, (struct sigaction *) 0);
  sigaction (SIGUSR1, &action, (struct sigaction *) 0);
 
 
  while (1)
  while (1)
    {
    {
      /* Wait for ever */
      /* Wait for ever */
      FD_ZERO (&readfds);
      FD_ZERO (&readfds);
      FD_SET (mumkid[0], &readfds);
      FD_SET (mumkid[0], &readfds);
 
 
      i = select (nfds, &readfds,
      i = select (nfds, &readfds,
                  (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0);
                  (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0);
 
 
      if (i < 0)
      if (i < 0)
        {
        {
          perror ("select");
          perror ("select");
        }
        }
 
 
      if (read (mumkid[0], &message, 1) < 1)
      if (read (mumkid[0], &message, 1) < 1)
        {
        {
          perror ("read");
          perror ("read");
        }
        }
 
 
      switch (message)
      switch (message)
        {
        {
        case RDP_Read:
        case RDP_Read:
          /* Read Memory Address */
          /* Read Memory Address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &y);   /* nbytes */
          MYread_word (mumkid[0], &y);   /* nbytes */
          p = (char *) malloc (y);
          p = (char *) malloc (y);
          i = armul_rdi.read (x, p, (unsigned *) &y);
          i = armul_rdi.read (x, p, (unsigned *) &y);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          for (k = 0; k < y; k++)
          for (k = 0; k < y; k++)
            MYwrite_char (kidmum[1], p[k]);
            MYwrite_char (kidmum[1], p[k]);
          free (p);
          free (p);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          if (i)
          if (i)
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
          break;
          break;
 
 
        case RDP_Write:
        case RDP_Write:
          /* Write Memory Address */
          /* Write Memory Address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &x);   /* address */
          MYread_word (mumkid[0], &y);   /* nbytes */
          MYread_word (mumkid[0], &y);   /* nbytes */
          p = (char *) malloc (y);
          p = (char *) malloc (y);
          for (k = 0; k < y; k++)
          for (k = 0; k < y; k++)
            MYread_char (mumkid[0], &p[k]);
            MYread_char (mumkid[0], &p[k]);
          i = armul_rdi.write (p, x, (unsigned *) &y);
          i = armul_rdi.write (p, x, (unsigned *) &y);
          free (p);
          free (p);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], RDP_Return);
          MYwrite_char (kidmum[1], (unsigned char) i);
          MYwrite_char (kidmum[1], (unsigned char) i);
          if (i)
          if (i)
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
            MYwrite_word (kidmum[1], y);        /* number of bytes sent without error */
          break;
          break;
 
 
        case RDP_OSOpReply:
        case RDP_OSOpReply:
          /* OS Operation Reply */
          /* OS Operation Reply */
          MYread_char (mumkid[0], &c);
          MYread_char (mumkid[0], &c);
          if (c == 1)
          if (c == 1)
            MYread_char (mumkid[0], (char *) reply);
            MYread_char (mumkid[0], (char *) reply);
          if (c == 2)
          if (c == 2)
            MYread_word (mumkid[0], reply);
            MYread_word (mumkid[0], reply);
          return c;
          return c;
          break;
          break;
 
 
        default:
        default:
          fprintf (stderr,
          fprintf (stderr,
                   "HELP! Unaccounted-for message during OS request. \n");
                   "HELP! Unaccounted-for message during OS request. \n");
          MYwrite_char (kidmum[1], RDP_Fatal);
          MYwrite_char (kidmum[1], RDP_Fatal);
        }
        }
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

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