1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
4 Copyright (C) 1998, Cygnus Solutions.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "targ-vals.h"
32 /* See the file include/callbacks.h for a description */
36 sim_io_init(SIM_DESC sd
)
38 return STATE_CALLBACK (sd
)->init (STATE_CALLBACK (sd
));
43 sim_io_shutdown(SIM_DESC sd
)
45 return STATE_CALLBACK (sd
)->shutdown (STATE_CALLBACK (sd
));
50 sim_io_unlink(SIM_DESC sd
,
53 return STATE_CALLBACK (sd
)->unlink (STATE_CALLBACK (sd
), f1
);
58 sim_io_time(SIM_DESC sd
,
61 return STATE_CALLBACK (sd
)->time (STATE_CALLBACK (sd
), t
);
66 sim_io_system(SIM_DESC sd
, const char *s
)
68 return STATE_CALLBACK (sd
)->system (STATE_CALLBACK (sd
), s
);
73 sim_io_rename(SIM_DESC sd
,
77 return STATE_CALLBACK (sd
)->rename (STATE_CALLBACK (sd
), f1
, f2
);
82 sim_io_write_stdout(SIM_DESC sd
,
86 switch (CURRENT_STDIO
) {
88 return STATE_CALLBACK (sd
)->write_stdout (STATE_CALLBACK (sd
), buf
, len
);
91 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), 1, buf
, len
);
94 sim_io_error (sd
, "sim_io_write_stdout: unaccounted switch\n");
102 sim_io_flush_stdout(SIM_DESC sd
)
104 switch (CURRENT_STDIO
) {
106 STATE_CALLBACK (sd
)->flush_stdout (STATE_CALLBACK (sd
));
111 sim_io_error (sd
, "sim_io_flush_stdout: unaccounted switch\n");
118 sim_io_write_stderr(SIM_DESC sd
,
122 switch (CURRENT_STDIO
) {
124 return STATE_CALLBACK (sd
)->write_stderr (STATE_CALLBACK (sd
), buf
, len
);
127 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), 2, buf
, len
);
130 sim_io_error (sd
, "sim_io_write_stderr: unaccounted switch\n");
138 sim_io_flush_stderr(SIM_DESC sd
)
140 switch (CURRENT_STDIO
) {
142 STATE_CALLBACK (sd
)->flush_stderr (STATE_CALLBACK (sd
));
147 sim_io_error (sd
, "sim_io_flush_stderr: unaccounted switch\n");
154 sim_io_write(SIM_DESC sd
,
159 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), fd
, buf
, len
);
164 sim_io_read_stdin(SIM_DESC sd
,
168 switch (CURRENT_STDIO
) {
170 return STATE_CALLBACK (sd
)->read_stdin (STATE_CALLBACK (sd
), buf
, len
);
173 return STATE_CALLBACK (sd
)->read (STATE_CALLBACK (sd
), 0, buf
, len
);
176 sim_io_error (sd
, "sim_io_read_stdin: unaccounted switch\n");
184 sim_io_read(SIM_DESC sd
, int fd
,
188 return STATE_CALLBACK (sd
)->read (STATE_CALLBACK (sd
), fd
, buf
, len
);
193 sim_io_open(SIM_DESC sd
,
197 return STATE_CALLBACK (sd
)->open (STATE_CALLBACK (sd
), name
, flags
);
202 sim_io_lseek(SIM_DESC sd
,
207 return STATE_CALLBACK (sd
)->lseek (STATE_CALLBACK (sd
), fd
, off
, way
);
212 sim_io_isatty(SIM_DESC sd
,
215 return STATE_CALLBACK (sd
)->isatty (STATE_CALLBACK (sd
), fd
);
220 sim_io_get_errno(SIM_DESC sd
)
222 return STATE_CALLBACK (sd
)->get_errno (STATE_CALLBACK (sd
));
227 sim_io_close(SIM_DESC sd
,
230 return STATE_CALLBACK (sd
)->close (STATE_CALLBACK (sd
), fd
);
235 sim_io_printf(SIM_DESC sd
,
241 STATE_CALLBACK (sd
)->vprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
247 sim_io_vprintf(SIM_DESC sd
,
251 STATE_CALLBACK (sd
)->vprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
256 sim_io_eprintf(SIM_DESC sd
,
262 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
268 sim_io_evprintf(SIM_DESC sd
,
272 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
277 sim_io_error(SIM_DESC sd
,
281 if (sd
== NULL
|| STATE_CALLBACK (sd
) == NULL
) {
284 vfprintf (stderr
, fmt
, ap
);
286 fprintf (stderr
, "\n");
292 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
294 STATE_CALLBACK (sd
)->error (STATE_CALLBACK (sd
), "");
300 sim_io_poll_quit(SIM_DESC sd
)
302 if (STATE_CALLBACK (sd
)->poll_quit
!= NULL
)
303 if (STATE_CALLBACK (sd
)->poll_quit (STATE_CALLBACK (sd
)))
308 /* Based on gdb-4.17/sim/ppc/main.c:sim_io_read_stdin().
310 FIXME: Should not be calling fcntl() or grubbing around inside of
313 FIXME: Some completly new mechanism for handling the general
314 problem of asynchronous IO is needed.
316 FIXME: This function does not supress the echoing (ECHO) of input.
317 Consequently polled input is always displayed.
319 FIXME: This function does not perform uncooked reads.
320 Consequently, data will not be read until an EOLN character has
321 been entered. A cntrl-d may force the early termination of a line */
325 sim_io_poll_read (SIM_DESC sd
,
330 #if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
331 int fd
= STATE_CALLBACK (sd
)->fdmap
[sim_io_fd
];
336 STATE_CALLBACK (sd
)->last_errno
= 0;
337 /* get the old status */
338 flags
= fcntl (fd
, F_GETFL
, 0);
341 perror ("sim_io_poll_read");
344 /* temp, disable blocking IO */
345 status
= fcntl (fd
, F_SETFL
, flags
| O_NDELAY
);
348 perror ("sim_io_read_stdin");
352 nr_read
= read (fd
, buf
, sizeof_buf
);
355 /* printf ("<nr-read=%d>\n", nr_read); */
361 STATE_CALLBACK (sd
)->last_errno
= errno
;
363 /* return to regular vewing */
364 status
= fcntl (fd
, F_SETFL
, flags
);
367 perror ("sim_io_read_stdin");
372 return sim_io_read (sd
, sim_io_fd
, buf
, sizeof_buf
);
This page took 0.061798 seconds and 4 git commands to generate.