From: Andrew Cagney Date: Wed, 6 May 1998 03:32:12 +0000 (+0000) Subject: Copy polling code in PSIM simulator into common directory. Will X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=844f40d3935780dc3cdaa6da363a5e83e03ea5ad;p=binutils-gdb.git Copy polling code in PSIM simulator into common directory. Will need rewrite later. Use in mn10300 simulator. --- diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index ba2cf3a7446..d546540ee26 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,5 +1,21 @@ +Wed May 6 12:39:15 1998 Andrew Cagney +start-sanitize-am30 + + * dv-pal.c (struct hw_pal_device): Add reader. + (hw_pal_finish): Initialize reader. + (scan_hw_pal): Use reader. + + * hw-base.h, sim-hw.c (do_hw_poll_read): New function. + (HW_IO_EOF, HW_IO_NOT_READY): Define. + * dv-pal.c: Use. + +end-sanitize-am30 + * sim-io.h, sim-io.c (sim_io_poll_read): New function. Copy from + ../ppc/main.c sim_io_read_stdin. + Fri May 1 12:11:02 1998 Andrew Cagney +start-sanitize-am30 * hw-tree.h (hw_tree_print): Paramaterize with print and file arguments. * hw-tree.c: Update. @@ -18,7 +34,6 @@ Fri May 1 12:11:02 1998 Andrew Cagney * dv-glue.c (hw_glue_io_read_buffer): Update. (hw_glue_port_event): Update. - * hw-device.h (SIM_DESC): Replace with struct sim_state. * hw-base.h (hw_create): Ditto. * hw-base.c (hw_create): Ditto. @@ -50,10 +65,11 @@ Fri May 1 12:11:02 1998 Andrew Cagney sim_cpu_hw_io_read_buffer, sim_cpu_hw_io_write_buffer): New functions. (sim_hw_print): New function. - + +end-sanitize-am30 * sim-engine.h (sim_engine_vabort): Declare. * sim-engine.c (sim_engine_vabort): New function. - + Wed Apr 29 23:58:52 1998 Andrew Cagney * sim-trace.c (print_data): For floating-point numbers trace raw diff --git a/sim/common/sim-io.c b/sim/common/sim-io.c index 994d30fcb1e..51f5348667d 100644 --- a/sim/common/sim-io.c +++ b/sim/common/sim-io.c @@ -1,6 +1,7 @@ /* This file is part of the program psim. Copyright (C) 1994-1997, Andrew Cagney + Copyright (C) 1998, Cygnus Solutions. 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 @@ -23,6 +24,11 @@ #include "sim-io.h" #include "targ-vals.h" +#if HAVE_FCNTL_H +#include +#endif + + /* See the file include/callbacks.h for a description */ @@ -299,156 +305,70 @@ sim_io_poll_quit(SIM_DESC sd) } -static char * -sim_io_getstring(SIM_DESC sd, - sim_cpu *cpu, - address_word cia, - address_word target_string) -{ - int len = 0; - char *buf; +/* Based on gdb-4.17/sim/ppc/main.c:sim_io_read_stdin(). - while (sim_core_read_1 (cpu, cia, sim_core_read_map, target_string+len) != 0) - len++; + FIXME: Should not be calling fcntl() or grubbing around inside of + ->fdmap and ->errno. - buf = NZALLOC (char, len+1); - buf[len] = '\0'; - sim_core_read_buffer (sd, cpu, sim_core_read_map, buf, target_string, len); - return buf; -} + FIXME: Some completly new mechanism for handling the general + problem of asynchronous IO is needed. -void -sim_io_syscalls(SIM_DESC sd, - int syscall, - address_word cia, - address_word parm1, - address_word parm2, - address_word parm3, - address_word parm4, - address_word *syscall_return, - address_word *errno_return) -{ - sim_cpu *cpu = STATE_CPU (sd, 0); - struct host_callback_struct *callback = STATE_CALLBACK (sd); - int len, len2, len3; - int ret; - char *buf; - int fd; + 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 */ - *errno_return = 0; - *syscall_return = 0; - switch (syscall) +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) { - case 1: /* exit (status) */ - sim_engine_halt (sd, STATE_CPU (sd, 0), NULL, cia, sim_exited, parm1); - break; - - case 2: /* open (filename, flags, mode) */ - buf = sim_io_getstring (sd, cpu, cia, parm1); - ret = *syscall_return = callback->open (callback, buf, parm2); - if (ret < 0) - *errno_return = callback->get_errno (callback); - - zfree (buf); - break; - - case 3: /* close (filedes) */ - ret = *syscall_return = callback->close (callback, parm1); - if (ret < 0) - *errno_return = callback->get_errno (callback); - break; - - case 4: /* read (filedes, buffer, len) */ - fd = parm1; - len = parm3; - buf = NZALLOC (char, len); - - if (fd == 0) - len2 = sim_io_read_stdin (sd, buf, len); - else - len2 = sim_io_read (sd, fd, buf, len); - - if (len2 > 0) - { - len3 = sim_core_write_buffer (sd, cpu, sim_core_write_map, buf, parm2, - len); - - if (len3 < len2) - sim_engine_abort (sd, cpu, cia, - "Could only write back %d bytes for read system call, wanted to write %d\n", - len3, len2); - - *syscall_return = len2; - } - else - *errno_return = callback->get_errno (callback); - - zfree (buf); - break; - - case 5: /* write (filedes, buffer, len) */ - fd = parm1; - len = parm3; - buf = NZALLOC (char, len); - - len = sim_core_read_buffer (sd, cpu, sim_core_read_map, buf, parm2, len); - if (fd == 1) - { - len2 = sim_io_write_stdout (sd, buf, len); - sim_io_flush_stdout (sd); - } - else if (fd == 2) - { - len2 = sim_io_write_stderr (sd, buf, len); - sim_io_flush_stderr (sd); - } - else - len2 = sim_io_write (sd, fd, buf, len); - - if (len2 > 0) - *syscall_return = len2; - else - *errno_return = callback->get_errno (callback); - - zfree (buf); - break; - - case 6: /* lseek (filedes, offset, whence) */ - *errno_return = TARGET_ENOSYS; - break; - - case 7: /* unlink (filename) */ - buf = sim_io_getstring (sd, cpu, cia, parm1); - ret = *syscall_return = callback->unlink (callback, buf); - if (ret < 0) - *errno_return = callback->get_errno (callback); - - zfree (buf); - break; - - case 8: /* getpid () */ - case 9: /* kill (signal, pid) */ - case 10: /* fstat (filedes, packet) */ - case 11: /* reserved for sbrk */ - case 12: /* argvlen () */ - case 13: /* argv () */ - case 14: /* chdir (dir) */ - case 15: /* stat (filename, packet) */ - case 16: /* chmod (filename, mode) */ - case 17: /* utime (filename, packet) */ - case 18: /* time (time_t *) */ - *errno_return = TARGET_ENOSYS; - break; - - default: - sim_engine_abort (sd, cpu, cia, "Unknown monitor call %d", syscall); - break; + perror ("sim_io_poll_read"); + return 0; } - - if (*errno_return) - *syscall_return = -1; - - return; + /* 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 ("\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 } -