]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/sim-io.c
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"
37 /* See the file include/callbacks.h for a description */
41 sim_io_init(SIM_DESC sd
)
43 return STATE_CALLBACK (sd
)->init (STATE_CALLBACK (sd
));
48 sim_io_shutdown(SIM_DESC sd
)
50 return STATE_CALLBACK (sd
)->shutdown (STATE_CALLBACK (sd
));
55 sim_io_unlink(SIM_DESC sd
,
58 return STATE_CALLBACK (sd
)->unlink (STATE_CALLBACK (sd
), f1
);
63 sim_io_time(SIM_DESC sd
,
66 return STATE_CALLBACK (sd
)->time (STATE_CALLBACK (sd
), t
);
71 sim_io_system(SIM_DESC sd
, const char *s
)
73 return STATE_CALLBACK (sd
)->system (STATE_CALLBACK (sd
), s
);
78 sim_io_rename(SIM_DESC sd
,
82 return STATE_CALLBACK (sd
)->rename (STATE_CALLBACK (sd
), f1
, f2
);
87 sim_io_write_stdout(SIM_DESC sd
,
91 switch (CURRENT_STDIO
) {
93 return STATE_CALLBACK (sd
)->write_stdout (STATE_CALLBACK (sd
), buf
, len
);
96 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), 1, buf
, len
);
99 sim_io_error (sd
, "sim_io_write_stdout: unaccounted switch\n");
107 sim_io_flush_stdout(SIM_DESC sd
)
109 switch (CURRENT_STDIO
) {
111 STATE_CALLBACK (sd
)->flush_stdout (STATE_CALLBACK (sd
));
116 sim_io_error (sd
, "sim_io_flush_stdout: unaccounted switch\n");
123 sim_io_write_stderr(SIM_DESC sd
,
127 switch (CURRENT_STDIO
) {
129 return STATE_CALLBACK (sd
)->write_stderr (STATE_CALLBACK (sd
), buf
, len
);
132 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), 2, buf
, len
);
135 sim_io_error (sd
, "sim_io_write_stderr: unaccounted switch\n");
143 sim_io_flush_stderr(SIM_DESC sd
)
145 switch (CURRENT_STDIO
) {
147 STATE_CALLBACK (sd
)->flush_stderr (STATE_CALLBACK (sd
));
152 sim_io_error (sd
, "sim_io_flush_stderr: unaccounted switch\n");
159 sim_io_write(SIM_DESC sd
,
164 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), fd
, buf
, len
);
169 sim_io_read_stdin(SIM_DESC sd
,
173 switch (CURRENT_STDIO
) {
175 return STATE_CALLBACK (sd
)->read_stdin (STATE_CALLBACK (sd
), buf
, len
);
178 return STATE_CALLBACK (sd
)->read (STATE_CALLBACK (sd
), 0, buf
, len
);
181 sim_io_error (sd
, "sim_io_read_stdin: unaccounted switch\n");
189 sim_io_read(SIM_DESC sd
, int fd
,
193 return STATE_CALLBACK (sd
)->read (STATE_CALLBACK (sd
), fd
, buf
, len
);
198 sim_io_open(SIM_DESC sd
,
202 return STATE_CALLBACK (sd
)->open (STATE_CALLBACK (sd
), name
, flags
);
207 sim_io_lseek(SIM_DESC sd
,
212 return STATE_CALLBACK (sd
)->lseek (STATE_CALLBACK (sd
), fd
, off
, way
);
217 sim_io_isatty(SIM_DESC sd
,
220 return STATE_CALLBACK (sd
)->isatty (STATE_CALLBACK (sd
), fd
);
225 sim_io_get_errno(SIM_DESC sd
)
227 return STATE_CALLBACK (sd
)->get_errno (STATE_CALLBACK (sd
));
232 sim_io_close(SIM_DESC sd
,
235 return STATE_CALLBACK (sd
)->close (STATE_CALLBACK (sd
), fd
);
240 sim_io_printf(SIM_DESC sd
,
246 STATE_CALLBACK (sd
)->vprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
252 sim_io_vprintf(SIM_DESC sd
,
256 STATE_CALLBACK (sd
)->vprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
261 sim_io_eprintf(SIM_DESC sd
,
267 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
273 sim_io_evprintf(SIM_DESC sd
,
277 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
282 sim_io_error(SIM_DESC sd
,
286 if (sd
== NULL
|| STATE_CALLBACK (sd
) == NULL
) {
289 vfprintf (stderr
, fmt
, ap
);
291 fprintf (stderr
, "\n");
297 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
299 STATE_CALLBACK (sd
)->error (STATE_CALLBACK (sd
), "");
305 sim_io_poll_quit(SIM_DESC sd
)
307 if (STATE_CALLBACK (sd
)->poll_quit
!= NULL
)
308 if (STATE_CALLBACK (sd
)->poll_quit (STATE_CALLBACK (sd
)))
313 /* Based on gdb-4.17/sim/ppc/main.c:sim_io_read_stdin().
315 FIXME: Should not be calling fcntl() or grubbing around inside of
318 FIXME: Some completly new mechanism for handling the general
319 problem of asynchronous IO is needed.
321 FIXME: This function does not supress the echoing (ECHO) of input.
322 Consequently polled input is always displayed.
324 FIXME: This function does not perform uncooked reads.
325 Consequently, data will not be read until an EOLN character has
326 been entered. A cntrl-d may force the early termination of a line */
330 sim_io_poll_read (SIM_DESC sd
,
335 #if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
336 int fd
= STATE_CALLBACK (sd
)->fdmap
[sim_io_fd
];
341 STATE_CALLBACK (sd
)->last_errno
= 0;
342 /* get the old status */
343 flags
= fcntl (fd
, F_GETFL
, 0);
346 perror ("sim_io_poll_read");
349 /* temp, disable blocking IO */
350 status
= fcntl (fd
, F_SETFL
, flags
| O_NDELAY
);
353 perror ("sim_io_read_stdin");
357 nr_read
= read (fd
, buf
, sizeof_buf
);
360 /* printf ("<nr-read=%d>\n", nr_read); */
366 STATE_CALLBACK (sd
)->last_errno
= errno
;
368 /* return to regular vewing */
369 status
= fcntl (fd
, F_SETFL
, flags
);
372 perror ("sim_io_read_stdin");
377 return sim_io_read (sd
, sim_io_fd
, buf
, sizeof_buf
);