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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [arm/] [main.c] - Diff between revs 227 and 816

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

Rev 227 Rev 816
/*  main.c -- top level of ARMulator:  ARM6 Instruction Emulator.
/*  main.c -- top level of ARMulator:  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. */
 
 
/**********************************************************************/
/**********************************************************************/
/* Forks the ARMulator and hangs on a socket passing on RDP messages  */
/* Forks the ARMulator and hangs on a socket passing on RDP messages  */
/* down a pipe to the ARMulator which translates them into RDI calls. */
/* down a pipe to the ARMulator which translates them into RDI calls. */
/**********************************************************************/
/**********************************************************************/
 
 
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <signal.h>
#include <signal.h>
#include <netdb.h>
#include <netdb.h>
#include <unistd.h>
#include <unistd.h>
 
 
#include "armdefs.h"
#include "armdefs.h"
#include "dbg_rdi.h"
#include "dbg_rdi.h"
#include "dbg_conf.h"
#include "dbg_conf.h"
 
 
#define MAXHOSTNAMELENGTH 64
#define MAXHOSTNAMELENGTH 64
 
 
/* Read and write routines down sockets and pipes */
/* Read and write routines down sockets and pipes */
 
 
void MYread_chars (int sock, void *p, int n);
void MYread_chars (int sock, void *p, int n);
unsigned char MYread_char (int sock);
unsigned char MYread_char (int sock);
ARMword MYread_word (int sock);
ARMword MYread_word (int sock);
void MYread_FPword (int sock, char *putinhere);
void MYread_FPword (int sock, char *putinhere);
 
 
void MYwrite_word (int sock, ARMword i);
void MYwrite_word (int sock, ARMword i);
void MYwrite_string (int sock, char *s);
void MYwrite_string (int sock, char *s);
void MYwrite_FPword (int sock, char *fromhere);
void MYwrite_FPword (int sock, char *fromhere);
void MYwrite_char (int sock, unsigned char c);
void MYwrite_char (int sock, unsigned char c);
 
 
void passon (int source, int dest, int n);
void passon (int source, int dest, int n);
 
 
 
 
/* Mother and child processes */
/* Mother and child processes */
void parent (void);
void parent (void);
void kid (void);
void kid (void);
 
 
/* The child process id. */
/* The child process id. */
pid_t child;
pid_t child;
 
 
/* The socket to the debugger */
/* The socket to the debugger */
int debugsock;
int debugsock;
 
 
/* The pipes between the two processes */
/* The pipes between the two processes */
int mumkid[2];
int mumkid[2];
int kidmum[2];
int kidmum[2];
 
 
/* A pipe for handling SWI return values that goes straight from the */
/* A pipe for handling SWI return values that goes straight from the */
/* parent to the ARMulator host interface, bypassing the childs RDP */
/* parent to the ARMulator host interface, bypassing the childs RDP */
/* to RDI interpreter */
/* to RDI interpreter */
int DebuggerARMul[2];
int DebuggerARMul[2];
 
 
/* The maximum number of file descriptors */
/* The maximum number of file descriptors */
int nfds;
int nfds;
 
 
/* The socket handle */
/* The socket handle */
int sockethandle;
int sockethandle;
 
 
/* The machine name */
/* The machine name */
char localhost[MAXHOSTNAMELENGTH + 1];
char localhost[MAXHOSTNAMELENGTH + 1];
 
 
/* The socket number */
/* The socket number */
unsigned int socketnumber;
unsigned int socketnumber;
 
 
/**************************************************************/
/**************************************************************/
/* Takes one argument: the socket number.                     */
/* Takes one argument: the socket number.                     */
/* Opens a socket to the debugger, and once opened spawns the */
/* Opens a socket to the debugger, and once opened spawns the */
/* ARMulator and sets up a couple of pipes.                   */
/* ARMulator and sets up a couple of pipes.                   */
/**************************************************************/
/**************************************************************/
int
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
{
  int i;
  int i;
  struct sockaddr_in devil, isa;
  struct sockaddr_in devil, isa;
  struct hostent *hp;
  struct hostent *hp;
 
 
 
 
  if (argc == 1)
  if (argc == 1)
    {
    {
      fprintf (stderr, "No socket number\n");
      fprintf (stderr, "No socket number\n");
      return 1;
      return 1;
    }
    }
 
 
  sscanf (argv[1], "%d", &socketnumber);
  sscanf (argv[1], "%d", &socketnumber);
  if (!socketnumber || socketnumber > 0xffff)
  if (!socketnumber || socketnumber > 0xffff)
    {
    {
      fprintf (stderr, "Invalid socket number: %d\n", socketnumber);
      fprintf (stderr, "Invalid socket number: %d\n", socketnumber);
      return 1;
      return 1;
    }
    }
 
 
  gethostname (localhost, MAXHOSTNAMELENGTH);
  gethostname (localhost, MAXHOSTNAMELENGTH);
  hp = gethostbyname (localhost);
  hp = gethostbyname (localhost);
  if (!hp)
  if (!hp)
    {
    {
      fprintf (stderr, "Cannot get local host info\n");
      fprintf (stderr, "Cannot get local host info\n");
      return 1;
      return 1;
    }
    }
 
 
  /* Open a socket */
  /* Open a socket */
  sockethandle = socket (hp->h_addrtype, SOCK_STREAM, 0);
  sockethandle = socket (hp->h_addrtype, SOCK_STREAM, 0);
  if (sockethandle < 0)
  if (sockethandle < 0)
    {
    {
      perror ("socket");
      perror ("socket");
      return 1;
      return 1;
    }
    }
 
 
  devil.sin_family = hp->h_addrtype;
  devil.sin_family = hp->h_addrtype;
  devil.sin_port = htons (socketnumber);
  devil.sin_port = htons (socketnumber);
  devil.sin_addr.s_addr = 0;
  devil.sin_addr.s_addr = 0;
  for (i = 0; i < sizeof (devil.sin_zero); i++)
  for (i = 0; i < sizeof (devil.sin_zero); i++)
    devil.sin_zero[i] = '\000';
    devil.sin_zero[i] = '\000';
  memcpy (&devil.sin_addr, hp->h_addr_list[0], hp->h_length);
  memcpy (&devil.sin_addr, hp->h_addr_list[0], hp->h_length);
 
 
  if (bind (sockethandle, &devil, sizeof (devil)) < 0)
  if (bind (sockethandle, &devil, sizeof (devil)) < 0)
    {
    {
      perror ("bind");
      perror ("bind");
      return 1;
      return 1;
    }
    }
 
 
  /* May only accept one debugger at once */
  /* May only accept one debugger at once */
 
 
  if (listen (sockethandle, 0))
  if (listen (sockethandle, 0))
    {
    {
      perror ("listen");
      perror ("listen");
      return 1;
      return 1;
    }
    }
 
 
  fprintf (stderr, "Waiting for connection from debugger...");
  fprintf (stderr, "Waiting for connection from debugger...");
 
 
  debugsock = accept (sockethandle, &isa, &i);
  debugsock = accept (sockethandle, &isa, &i);
  if (debugsock < 0)
  if (debugsock < 0)
    {
    {
      perror ("accept");
      perror ("accept");
      return 1;
      return 1;
    }
    }
 
 
  fprintf (stderr, " done.\nConnection Established.\n");
  fprintf (stderr, " done.\nConnection Established.\n");
 
 
  nfds = getdtablesize ();
  nfds = getdtablesize ();
 
 
  if (pipe (mumkid))
  if (pipe (mumkid))
    {
    {
      perror ("pipe");
      perror ("pipe");
      return 1;
      return 1;
    }
    }
  if (pipe (kidmum))
  if (pipe (kidmum))
    {
    {
      perror ("pipe");
      perror ("pipe");
      return 1;
      return 1;
    }
    }
 
 
  if (pipe (DebuggerARMul))
  if (pipe (DebuggerARMul))
    {
    {
      perror ("pipe");
      perror ("pipe");
      return 1;
      return 1;
    }
    }
 
 
#ifdef DEBUG
#ifdef DEBUG
  fprintf (stderr, "Created pipes ok\n");
  fprintf (stderr, "Created pipes ok\n");
#endif
#endif
 
 
  child = fork ();
  child = fork ();
 
 
#ifdef DEBUG
#ifdef DEBUG
  fprintf (stderr, "fork() ok\n");
  fprintf (stderr, "fork() ok\n");
#endif
#endif
 
 
  if (child == 0)
  if (child == 0)
    kid ();
    kid ();
  if (child != -1)
  if (child != -1)
    parent ();
    parent ();
 
 
  perror ("fork");
  perror ("fork");
  return 1;
  return 1;
}
}
 
 

powered by: WebSVN 2.1.0

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