+ if (callbacks->poll_quit != NULL && poll_quit_count-- < 0)
+ {
+ poll_quit_count = POLL_QUIT_INTERVAL;
+ if (callbacks->poll_quit (callbacks))
+ psim_stop (simulator);
+ }
+}
+
+
+
+/* Map simulator IO operations onto the corresponding GDB I/O
+ functions.
+
+ NB: Only a limited subset of operations are mapped across. More
+ advanced operations (such as dup or write) must either be mapped to
+ one of the below calls or handled internally */
+
+int
+sim_io_read_stdin(char *buf,
+ int sizeof_buf)
+{
+ switch (CURRENT_STDIO) {
+ case DO_USE_STDIO:
+ return callbacks->read_stdin(callbacks, buf, sizeof_buf);
+ break;
+ case DONT_USE_STDIO:
+ return callbacks->read(callbacks, 0, buf, sizeof_buf);
+ break;
+ default:
+ error("sim_io_read_stdin: unaccounted switch\n");
+ break;
+ }
+ return 0;
+}
+
+int
+sim_io_write_stdout(const char *buf,
+ int sizeof_buf)
+{
+ switch (CURRENT_STDIO) {
+ case DO_USE_STDIO:
+ return callbacks->write_stdout(callbacks, buf, sizeof_buf);
+ break;
+ case DONT_USE_STDIO:
+ return callbacks->write(callbacks, 1, buf, sizeof_buf);
+ break;
+ default:
+ error("sim_io_write_stdout: unaccounted switch\n");
+ break;
+ }
+ return 0;
+}
+
+int
+sim_io_write_stderr(const char *buf,
+ int sizeof_buf)
+{
+ switch (CURRENT_STDIO) {
+ case DO_USE_STDIO:
+ /* NB: I think there should be an explicit write_stderr callback */
+ return callbacks->write(callbacks, 3, buf, sizeof_buf);
+ break;
+ case DONT_USE_STDIO:
+ return callbacks->write(callbacks, 3, buf, sizeof_buf);
+ break;
+ default:
+ error("sim_io_write_stderr: unaccounted switch\n");
+ break;
+ }
+ return 0;
+}
+
+
+void
+sim_io_printf_filtered(const char *fmt,
+ ...)
+{
+ char message[1024];
+ va_list ap;
+ /* format the message */
+ va_start(ap, fmt);
+ vsprintf(message, fmt, ap);
+ va_end(ap);
+ /* sanity check */
+ if (strlen(message) >= sizeof(message))
+ error("sim_io_printf_filtered: buffer overflow\n");
+ callbacks->printf_filtered(callbacks, "%s", message);
+}
+
+void
+sim_io_flush_stdoutput(void)
+{
+ switch (CURRENT_STDIO) {
+ case DO_USE_STDIO:
+ callbacks->flush_stdout (callbacks);
+ break;
+ case DONT_USE_STDIO:
+ break;
+ default:
+ error("sim_io_read_stdin: unaccounted switch\n");
+ break;
+ }