1997-03-07 09:15:56 +00:00
|
|
|
/* This file is part of the program psim.
|
|
|
|
|
|
|
|
Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
|
1998-05-06 03:32:12 +00:00
|
|
|
Copyright (C) 1998, Cygnus Solutions.
|
1997-03-07 09:15:56 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
#include "sim-main.h"
|
|
|
|
#include "sim-io.h"
|
|
|
|
#include "targ-vals.h"
|
1997-03-07 09:15:56 +00:00
|
|
|
|
1998-05-06 03:32:12 +00:00
|
|
|
#if HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1997-03-07 09:15:56 +00:00
|
|
|
/* See the file include/callbacks.h for a description */
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_init(SIM_DESC sd)
|
1997-03-07 09:15:56 +00:00
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->init (STATE_CALLBACK (sd));
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_shutdown(SIM_DESC sd)
|
1997-03-07 09:15:56 +00:00
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->shutdown (STATE_CALLBACK (sd));
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_unlink(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *f1)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->unlink (STATE_CALLBACK (sd), f1);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
long
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_time(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
long *t)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->time (STATE_CALLBACK (sd), t);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_system(SIM_DESC sd, const char *s)
|
1997-03-07 09:15:56 +00:00
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->system (STATE_CALLBACK (sd), s);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_rename(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *f1,
|
|
|
|
const char *f2)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->rename (STATE_CALLBACK (sd), f1, f2);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_write_stdout(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *buf,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
switch (CURRENT_STDIO) {
|
|
|
|
case DO_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->write_stdout (STATE_CALLBACK (sd), buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
case DONT_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), 1, buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_error (sd, "sim_io_write_stdout: unaccounted switch\n");
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
void
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_flush_stdout(SIM_DESC sd)
|
1997-03-07 09:15:56 +00:00
|
|
|
{
|
|
|
|
switch (CURRENT_STDIO) {
|
|
|
|
case DO_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->flush_stdout (STATE_CALLBACK (sd));
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
case DONT_USE_STDIO:
|
|
|
|
break;
|
|
|
|
default:
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_error (sd, "sim_io_flush_stdout: unaccounted switch\n");
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_write_stderr(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *buf,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
switch (CURRENT_STDIO) {
|
|
|
|
case DO_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->write_stderr (STATE_CALLBACK (sd), buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
case DONT_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), 2, buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_error (sd, "sim_io_write_stderr: unaccounted switch\n");
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
void
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_flush_stderr(SIM_DESC sd)
|
1997-03-07 09:15:56 +00:00
|
|
|
{
|
|
|
|
switch (CURRENT_STDIO) {
|
|
|
|
case DO_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->flush_stderr (STATE_CALLBACK (sd));
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
case DONT_USE_STDIO:
|
|
|
|
break;
|
|
|
|
default:
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_error (sd, "sim_io_flush_stderr: unaccounted switch\n");
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_write(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
int fd,
|
|
|
|
const char *buf,
|
|
|
|
int len)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->write (STATE_CALLBACK (sd), fd, buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_read_stdin(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
char *buf,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
switch (CURRENT_STDIO) {
|
|
|
|
case DO_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->read_stdin (STATE_CALLBACK (sd), buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
case DONT_USE_STDIO:
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->read (STATE_CALLBACK (sd), 0, buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_error (sd, "sim_io_read_stdin: unaccounted switch\n");
|
1997-03-07 09:15:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_read(SIM_DESC sd, int fd,
|
1997-03-07 09:15:56 +00:00
|
|
|
char *buf,
|
|
|
|
int len)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->read (STATE_CALLBACK (sd), fd, buf, len);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_open(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *name,
|
|
|
|
int flags)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->open (STATE_CALLBACK (sd), name, flags);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_lseek(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
int fd,
|
|
|
|
long off,
|
|
|
|
int way)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->lseek (STATE_CALLBACK (sd), fd, off, way);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_isatty(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
int fd)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->isatty (STATE_CALLBACK (sd), fd);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_get_errno(SIM_DESC sd)
|
1997-03-07 09:15:56 +00:00
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->get_errno (STATE_CALLBACK (sd));
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
int
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_close(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
int fd)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
return STATE_CALLBACK (sd)->close (STATE_CALLBACK (sd), fd);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
void
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_printf(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *fmt,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->vprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
|
1997-03-07 09:15:56 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
void
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_vprintf(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *fmt,
|
|
|
|
va_list ap)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->vprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
void
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_eprintf(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *fmt,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
|
1997-03-07 09:15:56 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
void
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_evprintf(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *fmt,
|
|
|
|
va_list ap)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
void
|
1997-03-21 03:56:07 +00:00
|
|
|
sim_io_error(SIM_DESC sd,
|
1997-03-07 09:15:56 +00:00
|
|
|
const char *fmt,
|
|
|
|
...)
|
|
|
|
{
|
1997-11-26 01:13:40 +00:00
|
|
|
if (sd == NULL || STATE_CALLBACK (sd) == NULL) {
|
1997-03-21 03:56:07 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf (stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
1997-11-26 01:13:40 +00:00
|
|
|
fprintf (stderr, "\n");
|
1997-03-21 03:56:07 +00:00
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->evprintf_filtered (STATE_CALLBACK (sd), fmt, ap);
|
1997-03-21 03:56:07 +00:00
|
|
|
va_end(ap);
|
1997-11-26 01:13:40 +00:00
|
|
|
STATE_CALLBACK (sd)->error (STATE_CALLBACK (sd), "");
|
1997-03-21 03:56:07 +00:00
|
|
|
}
|
1997-03-07 09:15:56 +00:00
|
|
|
}
|
|
|
|
|
1997-11-26 01:13:40 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
sim_io_poll_quit(SIM_DESC sd)
|
|
|
|
{
|
|
|
|
if (STATE_CALLBACK (sd)->poll_quit != NULL)
|
|
|
|
if (STATE_CALLBACK (sd)->poll_quit (STATE_CALLBACK (sd)))
|
|
|
|
sim_stop (sd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-06 03:32:12 +00:00
|
|
|
/* Based on gdb-4.17/sim/ppc/main.c:sim_io_read_stdin().
|
1997-11-26 01:13:40 +00:00
|
|
|
|
1998-05-06 03:32:12 +00:00
|
|
|
FIXME: Should not be calling fcntl() or grubbing around inside of
|
|
|
|
->fdmap and ->errno.
|
1997-11-26 01:13:40 +00:00
|
|
|
|
1998-05-06 03:32:12 +00:00
|
|
|
FIXME: Some completly new mechanism for handling the general
|
|
|
|
problem of asynchronous IO is needed.
|
1997-11-26 01:13:40 +00:00
|
|
|
|
1998-05-06 03:32:12 +00:00
|
|
|
FIXME: This function does not supress the echoing (ECHO) of input.
|
|
|
|
Consequently polled input is always displayed.
|
|
|
|
|
|
|
|
FIXME: This function does not perform uncooked reads.
|
|
|
|
Consequently, data will not be read until an EOLN character has
|
|
|
|
been entered. A cntrl-d may force the early termination of a line */
|
1997-11-26 01:13:40 +00:00
|
|
|
|
|
|
|
|
1998-05-06 03:32:12 +00:00
|
|
|
int
|
|
|
|
sim_io_poll_read (SIM_DESC sd,
|
|
|
|
int sim_io_fd,
|
|
|
|
char *buf,
|
|
|
|
int sizeof_buf)
|
|
|
|
{
|
|
|
|
#if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
|
|
|
|
int fd = STATE_CALLBACK (sd)->fdmap[sim_io_fd];
|
|
|
|
int flags;
|
|
|
|
int status;
|
|
|
|
int nr_read;
|
|
|
|
int result;
|
|
|
|
STATE_CALLBACK (sd)->last_errno = 0;
|
|
|
|
/* get the old status */
|
|
|
|
flags = fcntl (fd, F_GETFL, 0);
|
|
|
|
if (flags == -1)
|
1997-11-26 01:13:40 +00:00
|
|
|
{
|
1998-05-06 03:32:12 +00:00
|
|
|
perror ("sim_io_poll_read");
|
|
|
|
return 0;
|
1997-11-26 01:13:40 +00:00
|
|
|
}
|
1998-05-06 03:32:12 +00:00
|
|
|
/* temp, disable blocking IO */
|
|
|
|
status = fcntl (fd, F_SETFL, flags | O_NDELAY);
|
|
|
|
if (status == -1)
|
|
|
|
{
|
|
|
|
perror ("sim_io_read_stdin");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* try for input */
|
|
|
|
nr_read = read (fd, buf, sizeof_buf);
|
|
|
|
if (nr_read >= 0)
|
|
|
|
{
|
|
|
|
/* printf ("<nr-read=%d>\n", nr_read); */
|
|
|
|
result = nr_read;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* nr_read < 0 */
|
|
|
|
result = -1;
|
|
|
|
STATE_CALLBACK (sd)->last_errno = errno;
|
|
|
|
}
|
|
|
|
/* return to regular vewing */
|
|
|
|
status = fcntl (fd, F_SETFL, flags);
|
|
|
|
if (status == -1)
|
|
|
|
{
|
|
|
|
perror ("sim_io_read_stdin");
|
|
|
|
/* return 0; */
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
return sim_io_read (sd, sim_io_fd, buf, sizeof_buf);
|
|
|
|
#endif
|
1997-11-26 01:13:40 +00:00
|
|
|
}
|