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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [sim/] [common/] [sim-io.c] - Diff between revs 24 and 157

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

Rev 24 Rev 157
/* The common simulator framework for GDB, the GNU Debugger.
/* The common simulator framework for GDB, the GNU Debugger.
 
 
   Copyright 2002, 2007, 2008 Free Software Foundation, Inc.
   Copyright 2002, 2007, 2008 Free Software Foundation, Inc.
 
 
   Contributed by Andrew Cagney and Red Hat.
   Contributed by Andrew Cagney and Red Hat.
 
 
   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 3 of the License, or
   the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.  */
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 
 
#include "sim-main.h"
#include "sim-main.h"
#include "sim-io.h"
#include "sim-io.h"
#include "targ-vals.h"
#include "targ-vals.h"
 
 
#include <errno.h>
#include <errno.h>
#if HAVE_FCNTL_H
#if HAVE_FCNTL_H
#include <fcntl.h>
#include <fcntl.h>
#endif
#endif
 
 
#if HAVE_UNISTD_H
#if HAVE_UNISTD_H
#include <unistd.h>
#include <unistd.h>
#endif
#endif
 
 
/* Define the rate at which the simulator should poll the host
/* Define the rate at which the simulator should poll the host
   for a quit. */
   for a quit. */
#ifndef POLL_QUIT_INTERVAL
#ifndef POLL_QUIT_INTERVAL
#define POLL_QUIT_INTERVAL 0x10
#define POLL_QUIT_INTERVAL 0x10
#endif
#endif
 
 
static int poll_quit_count = POLL_QUIT_INTERVAL;
static int poll_quit_count = POLL_QUIT_INTERVAL;
 
 
/* See the file include/callbacks.h for a description */
/* See the file include/callbacks.h for a description */
 
 
 
 
int
int
sim_io_init(SIM_DESC sd)
sim_io_init(SIM_DESC sd)
{
{
  return STATE_CALLBACK (sd)->init (STATE_CALLBACK (sd));
  return STATE_CALLBACK (sd)->init (STATE_CALLBACK (sd));
}
}
 
 
 
 
int
int
sim_io_shutdown(SIM_DESC sd)
sim_io_shutdown(SIM_DESC sd)
{
{
  return STATE_CALLBACK (sd)->shutdown (STATE_CALLBACK (sd));
  return STATE_CALLBACK (sd)->shutdown (STATE_CALLBACK (sd));
}
}
 
 
 
 
int
int
sim_io_unlink(SIM_DESC sd,
sim_io_unlink(SIM_DESC sd,
              const char *f1)
              const char *f1)
{
{
  return STATE_CALLBACK (sd)->unlink (STATE_CALLBACK (sd), f1);
  return STATE_CALLBACK (sd)->unlink (STATE_CALLBACK (sd), f1);
}
}
 
 
 
 
long
long
sim_io_time(SIM_DESC sd,
sim_io_time(SIM_DESC sd,
            long *t)
            long *t)
{
{
  return STATE_CALLBACK (sd)->time (STATE_CALLBACK (sd), t);
  return STATE_CALLBACK (sd)->time (STATE_CALLBACK (sd), t);
}
}
 
 
 
 
int
int
sim_io_system(SIM_DESC sd, const char *s)
sim_io_system(SIM_DESC sd, const char *s)
{
{
  return STATE_CALLBACK (sd)->system (STATE_CALLBACK (sd), s);
  return STATE_CALLBACK (sd)->system (STATE_CALLBACK (sd), s);
}
}
 
 
 
 
int
int
sim_io_rename(SIM_DESC sd,
sim_io_rename(SIM_DESC sd,
              const char *f1,
              const char *f1,
              const char *f2)
              const char *f2)
{
{
  return STATE_CALLBACK (sd)->rename (STATE_CALLBACK (sd), f1, f2);
  return STATE_CALLBACK (sd)->rename (STATE_CALLBACK (sd), f1, f2);
}
}
 
 
 
 
int
int
sim_io_write_stdout(SIM_DESC sd,
sim_io_write_stdout(SIM_DESC sd,
                    const char *buf,
                    const char *buf,
                    int len)
                    int len)
{
{
  switch (CURRENT_STDIO) {
  switch (CURRENT_STDIO) {
  case DO_USE_STDIO:
  case DO_USE_STDIO:
    return STATE_CALLBACK (sd)->write_stdout (STATE_CALLBACK (sd), buf, len);
    return STATE_CALLBACK (sd)->write_stdout (STATE_CALLBACK (sd), buf, len);
    break;
    break;
  case DONT_USE_STDIO:
  case DONT_USE_STDIO:
    return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), 1, buf, len);
    return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), 1, buf, len);
    break;
    break;
  default:
  default:
    sim_io_error (sd, "sim_io_write_stdout: unaccounted switch\n");
    sim_io_error (sd, "sim_io_write_stdout: unaccounted switch\n");
    break;
    break;
  }
  }
  return 0;
  return 0;
}
}
 
 
 
 
void
void
sim_io_flush_stdout(SIM_DESC sd)
sim_io_flush_stdout(SIM_DESC sd)
{
{
  switch (CURRENT_STDIO) {
  switch (CURRENT_STDIO) {
  case DO_USE_STDIO:
  case DO_USE_STDIO:
    STATE_CALLBACK (sd)->flush_stdout (STATE_CALLBACK (sd));
    STATE_CALLBACK (sd)->flush_stdout (STATE_CALLBACK (sd));
    break;
    break;
  case DONT_USE_STDIO:
  case DONT_USE_STDIO:
    break;
    break;
  default:
  default:
    sim_io_error (sd, "sim_io_flush_stdout: unaccounted switch\n");
    sim_io_error (sd, "sim_io_flush_stdout: unaccounted switch\n");
    break;
    break;
  }
  }
}
}
 
 
 
 
int
int
sim_io_write_stderr(SIM_DESC sd,
sim_io_write_stderr(SIM_DESC sd,
                    const char *buf,
                    const char *buf,
                    int len)
                    int len)
{
{
  switch (CURRENT_STDIO) {
  switch (CURRENT_STDIO) {
  case DO_USE_STDIO:
  case DO_USE_STDIO:
    return STATE_CALLBACK (sd)->write_stderr (STATE_CALLBACK (sd), buf, len);
    return STATE_CALLBACK (sd)->write_stderr (STATE_CALLBACK (sd), buf, len);
    break;
    break;
  case DONT_USE_STDIO:
  case DONT_USE_STDIO:
    return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), 2, buf, len);
    return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), 2, buf, len);
    break;
    break;
  default:
  default:
    sim_io_error (sd, "sim_io_write_stderr: unaccounted switch\n");
    sim_io_error (sd, "sim_io_write_stderr: unaccounted switch\n");
    break;
    break;
  }
  }
  return 0;
  return 0;
}
}
 
 
 
 
void
void
sim_io_flush_stderr(SIM_DESC sd)
sim_io_flush_stderr(SIM_DESC sd)
{
{
  switch (CURRENT_STDIO) {
  switch (CURRENT_STDIO) {
  case DO_USE_STDIO:
  case DO_USE_STDIO:
    STATE_CALLBACK (sd)->flush_stderr (STATE_CALLBACK (sd));
    STATE_CALLBACK (sd)->flush_stderr (STATE_CALLBACK (sd));
    break;
    break;
  case DONT_USE_STDIO:
  case DONT_USE_STDIO:
    break;
    break;
  default:
  default:
    sim_io_error (sd, "sim_io_flush_stderr: unaccounted switch\n");
    sim_io_error (sd, "sim_io_flush_stderr: unaccounted switch\n");
    break;
    break;
  }
  }
}
}
 
 
 
 
int
int
sim_io_write(SIM_DESC sd,
sim_io_write(SIM_DESC sd,
             int fd,
             int fd,
             const char *buf,
             const char *buf,
             int len)
             int len)
{
{
  return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), fd, buf, len);
  return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), fd, buf, len);
}
}
 
 
 
 
int
int
sim_io_read_stdin(SIM_DESC sd,
sim_io_read_stdin(SIM_DESC sd,
                  char *buf,
                  char *buf,
                  int len)
                  int len)
{
{
  switch (CURRENT_STDIO) {
  switch (CURRENT_STDIO) {
  case DO_USE_STDIO:
  case DO_USE_STDIO:
    return STATE_CALLBACK (sd)->read_stdin (STATE_CALLBACK (sd), buf, len);
    return STATE_CALLBACK (sd)->read_stdin (STATE_CALLBACK (sd), buf, len);
    break;
    break;
  case DONT_USE_STDIO:
  case DONT_USE_STDIO:
    return STATE_CALLBACK (sd)->read (STATE_CALLBACK (sd), 0, buf, len);
    return STATE_CALLBACK (sd)->read (STATE_CALLBACK (sd), 0, buf, len);
    break;
    break;
  default:
  default:
    sim_io_error (sd, "sim_io_read_stdin: unaccounted switch\n");
    sim_io_error (sd, "sim_io_read_stdin: unaccounted switch\n");
    break;
    break;
  }
  }
  return 0;
  return 0;
}
}
 
 
 
 
int
int
sim_io_read(SIM_DESC sd, int fd,
sim_io_read(SIM_DESC sd, int fd,
            char *buf,
            char *buf,
            int len)
            int len)
{
{
  return STATE_CALLBACK (sd)->read (STATE_CALLBACK (sd), fd, buf, len);
  return STATE_CALLBACK (sd)->read (STATE_CALLBACK (sd), fd, buf, len);
}
}
 
 
 
 
int
int
sim_io_open(SIM_DESC sd,
sim_io_open(SIM_DESC sd,
            const char *name,
            const char *name,
            int flags)
            int flags)
{
{
  return STATE_CALLBACK (sd)->open (STATE_CALLBACK (sd), name, flags);
  return STATE_CALLBACK (sd)->open (STATE_CALLBACK (sd), name, flags);
}
}
 
 
 
 
int
int
sim_io_lseek(SIM_DESC sd,
sim_io_lseek(SIM_DESC sd,
             int fd,
             int fd,
             long off,
             long off,
             int way)
             int way)
{
{
  return STATE_CALLBACK (sd)->lseek (STATE_CALLBACK (sd), fd, off, way);
  return STATE_CALLBACK (sd)->lseek (STATE_CALLBACK (sd), fd, off, way);
}
}
 
 
 
 
int
int
sim_io_isatty(SIM_DESC sd,
sim_io_isatty(SIM_DESC sd,
              int fd)
              int fd)
{
{
  return STATE_CALLBACK (sd)->isatty (STATE_CALLBACK (sd), fd);
  return STATE_CALLBACK (sd)->isatty (STATE_CALLBACK (sd), fd);
}
}
 
 
 
 
int
int
sim_io_get_errno(SIM_DESC sd)
sim_io_get_errno(SIM_DESC sd)
{
{
  return STATE_CALLBACK (sd)->get_errno (STATE_CALLBACK (sd));
  return STATE_CALLBACK (sd)->get_errno (STATE_CALLBACK (sd));
}
}
 
 
 
 
int
int
sim_io_close(SIM_DESC sd,
sim_io_close(SIM_DESC sd,
             int fd)
             int fd)
{
{
  return STATE_CALLBACK (sd)->close (STATE_CALLBACK (sd), fd);
  return STATE_CALLBACK (sd)->close (STATE_CALLBACK (sd), fd);
}
}
 
 
 
 
void
void
sim_io_printf(SIM_DESC sd,
sim_io_printf(SIM_DESC sd,
              const char *fmt,
              const char *fmt,
              ...)
              ...)
{
{
  va_list ap;
  va_list ap;
  va_start(ap, fmt);
  va_start(ap, fmt);
  STATE_CALLBACK (sd)->vprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
  STATE_CALLBACK (sd)->vprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
  va_end(ap);
  va_end(ap);
}
}
 
 
 
 
void
void
sim_io_vprintf(SIM_DESC sd,
sim_io_vprintf(SIM_DESC sd,
               const char *fmt,
               const char *fmt,
               va_list ap)
               va_list ap)
{
{
  STATE_CALLBACK (sd)->vprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
  STATE_CALLBACK (sd)->vprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
}
}
 
 
 
 
void
void
sim_io_eprintf(SIM_DESC sd,
sim_io_eprintf(SIM_DESC sd,
              const char *fmt,
              const char *fmt,
              ...)
              ...)
{
{
  va_list ap;
  va_list ap;
  va_start(ap, fmt);
  va_start(ap, fmt);
  STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
  STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
  va_end(ap);
  va_end(ap);
}
}
 
 
 
 
void
void
sim_io_evprintf(SIM_DESC sd,
sim_io_evprintf(SIM_DESC sd,
                const char *fmt,
                const char *fmt,
                va_list ap)
                va_list ap)
{
{
  STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
  STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
}
}
 
 
 
 
void
void
sim_io_error(SIM_DESC sd,
sim_io_error(SIM_DESC sd,
             const char *fmt,
             const char *fmt,
             ...)
             ...)
{
{
  if (sd == NULL || STATE_CALLBACK (sd) == NULL) {
  if (sd == NULL || STATE_CALLBACK (sd) == NULL) {
    va_list ap;
    va_list ap;
    va_start(ap, fmt);
    va_start(ap, fmt);
    vfprintf (stderr, fmt, ap);
    vfprintf (stderr, fmt, ap);
    va_end(ap);
    va_end(ap);
    fprintf (stderr, "\n");
    fprintf (stderr, "\n");
    abort ();
    abort ();
  }
  }
  else {
  else {
    va_list ap;
    va_list ap;
    va_start(ap, fmt);
    va_start(ap, fmt);
    STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
    STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
    va_end(ap);
    va_end(ap);
    STATE_CALLBACK (sd)->error (STATE_CALLBACK (sd), "");
    STATE_CALLBACK (sd)->error (STATE_CALLBACK (sd), "");
  }
  }
}
}
 
 
 
 
void
void
sim_io_poll_quit(SIM_DESC sd)
sim_io_poll_quit(SIM_DESC sd)
{
{
  if (STATE_CALLBACK (sd)->poll_quit != NULL && poll_quit_count-- < 0)
  if (STATE_CALLBACK (sd)->poll_quit != NULL && poll_quit_count-- < 0)
    {
    {
      poll_quit_count = POLL_QUIT_INTERVAL;
      poll_quit_count = POLL_QUIT_INTERVAL;
      if (STATE_CALLBACK (sd)->poll_quit (STATE_CALLBACK (sd)))
      if (STATE_CALLBACK (sd)->poll_quit (STATE_CALLBACK (sd)))
        sim_stop (sd);
        sim_stop (sd);
    }
    }
}
}
 
 
 
 
/* Based on gdb-4.17/sim/ppc/main.c:sim_io_read_stdin().
/* Based on gdb-4.17/sim/ppc/main.c:sim_io_read_stdin().
 
 
   FIXME: Should not be calling fcntl() or grubbing around inside of
   FIXME: Should not be calling fcntl() or grubbing around inside of
   ->fdmap and ->errno.
   ->fdmap and ->errno.
 
 
   FIXME: Some completly new mechanism for handling the general
   FIXME: Some completly new mechanism for handling the general
   problem of asynchronous IO is needed.
   problem of asynchronous IO is needed.
 
 
   FIXME: This function does not supress the echoing (ECHO) of input.
   FIXME: This function does not supress the echoing (ECHO) of input.
   Consequently polled input is always displayed.
   Consequently polled input is always displayed.
 
 
   FIXME: This function does not perform uncooked reads.
   FIXME: This function does not perform uncooked reads.
   Consequently, data will not be read until an EOLN character has
   Consequently, data will not be read until an EOLN character has
   been entered. A cntrl-d may force the early termination of a line */
   been entered. A cntrl-d may force the early termination of a line */
 
 
 
 
int
int
sim_io_poll_read (SIM_DESC sd,
sim_io_poll_read (SIM_DESC sd,
                  int sim_io_fd,
                  int sim_io_fd,
                  char *buf,
                  char *buf,
                  int sizeof_buf)
                  int sizeof_buf)
{
{
#if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
#if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
  int fd = STATE_CALLBACK (sd)->fdmap[sim_io_fd];
  int fd = STATE_CALLBACK (sd)->fdmap[sim_io_fd];
  int flags;
  int flags;
  int status;
  int status;
  int nr_read;
  int nr_read;
  int result;
  int result;
  STATE_CALLBACK (sd)->last_errno = 0;
  STATE_CALLBACK (sd)->last_errno = 0;
  /* get the old status */
  /* get the old status */
  flags = fcntl (fd, F_GETFL, 0);
  flags = fcntl (fd, F_GETFL, 0);
  if (flags == -1)
  if (flags == -1)
    {
    {
      perror ("sim_io_poll_read");
      perror ("sim_io_poll_read");
      return 0;
      return 0;
    }
    }
  /* temp, disable blocking IO */
  /* temp, disable blocking IO */
  status = fcntl (fd, F_SETFL, flags | O_NDELAY);
  status = fcntl (fd, F_SETFL, flags | O_NDELAY);
  if (status == -1)
  if (status == -1)
    {
    {
      perror ("sim_io_read_stdin");
      perror ("sim_io_read_stdin");
      return 0;
      return 0;
    }
    }
  /* try for input */
  /* try for input */
  nr_read = read (fd, buf, sizeof_buf);
  nr_read = read (fd, buf, sizeof_buf);
  if (nr_read >= 0)
  if (nr_read >= 0)
    {
    {
      /* printf ("<nr-read=%d>\n", nr_read); */
      /* printf ("<nr-read=%d>\n", nr_read); */
      result = nr_read;
      result = nr_read;
    }
    }
  else
  else
    { /* nr_read < 0 */
    { /* nr_read < 0 */
      result = -1;
      result = -1;
      STATE_CALLBACK (sd)->last_errno = errno;
      STATE_CALLBACK (sd)->last_errno = errno;
    }
    }
  /* return to regular vewing */
  /* return to regular vewing */
  status = fcntl (fd, F_SETFL, flags);
  status = fcntl (fd, F_SETFL, flags);
  if (status == -1)
  if (status == -1)
    {
    {
      perror ("sim_io_read_stdin");
      perror ("sim_io_read_stdin");
      /* return 0; */
      /* return 0; */
    }
    }
  return result;
  return result;
#else
#else
  return sim_io_read (sd, sim_io_fd, buf, sizeof_buf);
  return sim_io_read (sd, sim_io_fd, buf, sizeof_buf);
#endif
#endif
}
}
 
 

powered by: WebSVN 2.1.0

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