This is the mail archive of the sid@sourceware.org mailing list for the SID project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch][commit] EOF Handling for sid-io-stdio


Hi,

I've committed this patch which corrects a problem with sid-io-stdio. Currently, when there is no data available to be read, the gloss component cannot distinguish this from EOF. This causes eof to be reported by do_sys_read prematurely in some instances.

I've committed this patch which adds an eof pin to the sid-io-stdio compoenent which is now checked by do_sys_read when no data is returned to ensure that it really is eof.

Let me know if you find any problems.

Dave
2006-06-21  Dave Brolley  <brolley@redhat.com>

	* stdio.cxx (stdioConsole): Initialize eof_p. Add "eof" pin.
	(read): Remove 'value'. Check eof_p. Drive eof_pin and set
	eof_p as needed.
	* components.h (eof_pin): New member of stdioConsole.
	(eof_p): Likewise.
	* sid-io-stdio.xml: Document eof pin.
	* sid-io-stdio.txt: Regenerated.

2006-06-21  Dave Brolley  <brolley@redhat.com>

	* gloss.h (rx_eof_pin): New member of gloss32.
	* gloss.cxx (gloss32): Add debug-rx-eof pin.
	(read): Check rx_eof_pin.

2006-06-21  Dave Brolley  <brolley@redhat.com>

	* commonCfg.cxx (BoardCfg::write_config): Connect stdio_obj's eof pin to
	gloss' debug-rx-eof pin.

Index: sid/component/consoles/components.h
===================================================================
RCS file: /cvs/src/src/sid/component/consoles/components.h,v
retrieving revision 1.5
diff -c -p -r1.5 components.h
*** sid/component/consoles/components.h	19 Aug 2005 19:43:09 -0000	1.5
--- sid/component/consoles/components.h	14 Jul 2006 19:16:02 -0000
***************
*** 1,7 ****
  // file.cxx - Joint header file for nearby component classes.
  // -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2003, 2005 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
--- 1,7 ----
  // file.cxx - Joint header file for nearby component classes.
  // -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2003, 2005, 2006 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
*************** private:
*** 106,111 ****
--- 106,114 ----
    callback_pin<stdioConsole> activity_pin;
    callback_pin<stdioConsole> stdout_pin;
    output_pin stdin_pin;
+   output_pin eof_pin;
+ 
+   bool eof_p;
  
    // save & restore state
    string save_state ( );
Index: sid/component/consoles/sid-io-stdio.xml
===================================================================
RCS file: /cvs/src/src/sid/component/consoles/sid-io-stdio.xml,v
retrieving revision 1.2
diff -c -p -r1.2 sid-io-stdio.xml
*** sid/component/consoles/sid-io-stdio.xml	10 Jun 2003 18:28:19 -0000	1.2
--- sid/component/consoles/sid-io-stdio.xml	14 Jul 2006 19:16:02 -0000
***************
*** 8,13 ****
--- 8,14 ----
      <!-- pins -->
      <defpin name="poll" direction="in" legalvalues="N/A" behaviors="input" />
      <defpin name="stdin" direction="out" legalvalues="any character code" behaviors="input" />
+     <defpin name="eof" direction="out" legalvalues="boolean" behaviors="input" />
      <defpin name="stdout" direction="in" legalvalues="any character code" behaviors="output" />
  
  
***************
*** 45,53 ****
  
      <behavior name="input">
      When the <pin>poll</pin> pin is driven, the <tt>stdin</tt> stream is checked for
!     unread input, without blocking.  All available input is consumed,
      and transmitted individually by driving the <pin>stdin</pin> pin with each
!     byte, in sequence.
      </behavior>
  
      <convention name="functional" supported="true"/>
--- 46,57 ----
  
      <behavior name="input">
      When the <pin>poll</pin> pin is driven, the <tt>stdin</tt> stream is checked for
!     unread input, without blocking.  If end of file has not been detected, the <pin>eof</pin>
!     pin is driven with the value 0. All available input is consumed,
      and transmitted individually by driving the <pin>stdin</pin> pin with each
!     byte, in sequence. When end of file is detected, the <pin>eof</pin> is driven with
!     a value of 1 and no data is transmitted via the <pin>stdin</pin> pin.
! 
      </behavior>
  
      <convention name="functional" supported="true"/>
Index: sid/component/consoles/stdio.cxx
===================================================================
RCS file: /cvs/src/src/sid/component/consoles/stdio.cxx,v
retrieving revision 1.3
diff -c -p -r1.3 stdio.cxx
*** sid/component/consoles/stdio.cxx	14 Jul 2003 18:42:14 -0000	1.3
--- sid/component/consoles/stdio.cxx	14 Jul 2006 19:16:02 -0000
***************
*** 1,7 ****
  // stdio.cxx - A simple console that uses standard I/O for
  // enunciation.  -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2003 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
--- 1,7 ----
  // stdio.cxx - A simple console that uses standard I/O for
  // enunciation.  -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2003, 2006 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
*************** namespace console_stuff
*** 13,23 ****
  
  stdioConsole::stdioConsole()
    :activity_pin(this, & stdioConsole::read),
!    stdout_pin(this, & stdioConsole::write)
  {
    add_pin("poll", &activity_pin);
    add_pin("stdin", &stdin_pin);
    add_pin("stdout", &stdout_pin);
    add_attribute_virtual ("state-snapshot", this,
  			 & stdioConsole::save_state,
  			 & stdioConsole::restore_state);
--- 13,25 ----
  
  stdioConsole::stdioConsole()
    :activity_pin(this, & stdioConsole::read),
!    stdout_pin(this, & stdioConsole::write),
!    eof_p (false)
  {
    add_pin("poll", &activity_pin);
    add_pin("stdin", &stdin_pin);
    add_pin("stdout", &stdout_pin);
+   add_pin("eof", &eof_pin);
    add_attribute_virtual ("state-snapshot", this,
  			 & stdioConsole::save_state,
  			 & stdioConsole::restore_state);
*************** stdioConsole::write(host_int_4 value)
*** 32,52 ****
  void
  stdioConsole::read(host_int_4)
  {
    unsigned char buf[1000];
    int len;
-   host_int_4 value;
- 
    // Switch to non-blocking input.
    long flags = fcntl(0, F_GETFL);
    fcntl(0, F_SETFL, flags | O_NONBLOCK);
  
    if ((len = ::read(0, buf, 1000)) > 0)
      {
        for (int i = 0; i < len; ++i)
  	{
  	  stdin_pin.drive(buf[i]);
  	}
      }
  
    // Restore flags.
    fcntl(0, F_SETFL, flags);
--- 34,62 ----
  void
  stdioConsole::read(host_int_4)
  {
+   // Check for EOF
+   if (eof_p)
+     return;
+ 
    unsigned char buf[1000];
    int len;
    // Switch to non-blocking input.
    long flags = fcntl(0, F_GETFL);
    fcntl(0, F_SETFL, flags | O_NONBLOCK);
  
    if ((len = ::read(0, buf, 1000)) > 0)
      {
+       eof_pin.drive (0);
        for (int i = 0; i < len; ++i)
  	{
  	  stdin_pin.drive(buf[i]);
  	}
      }
+   else if (len == 0)
+     {
+       eof_p = true;
+       eof_pin.drive (1);
+     }
  
    // Restore flags.
    fcntl(0, F_SETFL, flags);
Index: sid/component/gloss/gloss.cxx
===================================================================
RCS file: /cvs/src/src/sid/component/gloss/gloss.cxx,v
retrieving revision 1.20
diff -c -p -r1.20 gloss.cxx
*** sid/component/gloss/gloss.cxx	19 Aug 2005 19:44:46 -0000	1.20
--- sid/component/gloss/gloss.cxx	14 Jul 2006 19:16:03 -0000
***************
*** 1,6 ****
  // gloss.cxx - Gloss routines.  -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2001, 2002, 2005 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
--- 1,6 ----
  // gloss.cxx - Gloss routines.  -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
*************** gloss32::gloss32() :
*** 63,68 ****
--- 65,71 ----
  
    add_pin("debug-tx", &this->tx_pin);
    add_pin("debug-rx", &this->rx_pin);
+   add_pin("debug-rx-eof", &this->rx_eof_pin);
    add_attribute_ro_value ("tk tty", string("hw-visual-tty"), "gui");
  
    add_uni_relation("cpu", &this->cpu);
*************** gloss32::read (int fd, address32 addr, s
*** 1543,1548 ****
--- 1645,1655 ----
  		  strbuf += c;
  		}
  	    }
+ 	  else if (rx_eof_pin.sense () != 0)
+ 	    {
+ 	      len_read = 0;
+ 	      return true;
+ 	    }
  	  else
  	    {
  	      this->blocked_p = true;
Index: sid/component/gloss/gloss.h
===================================================================
RCS file: /cvs/src/src/sid/component/gloss/gloss.h,v
retrieving revision 1.12
diff -c -p -r1.12 gloss.h
*** sid/component/gloss/gloss.h	19 Aug 2005 19:44:46 -0000	1.12
--- sid/component/gloss/gloss.h	14 Jul 2006 19:16:03 -0000
***************
*** 1,7 ****
  // gloss.h - Basic process emulation plus ROM monitor support.
  // -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2001, 2002, 2005 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
--- 1,7 ----
  // gloss.h - Basic process emulation plus ROM monitor support.
  // -*- C++ -*-
  
! // Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006 Red Hat.
  // This file is part of SID and is licensed under the GPL.
  // See the file COPYING.SID for conditions for redistribution.
  
*************** protected:
*** 119,124 ****
--- 119,125 ----
    callback_pin<gloss32> rx_pin;
    void rx_handler(host_int_4 byte);
    vector<host_int_1> rx_buffer;
+   input_pin rx_eof_pin;
    output_pin tx_pin;
  
    // ABI-specifics, for getting syscall arguments and setting results.
Index: sid/main/dynamic/commonCfg.cxx
===================================================================
RCS file: /cvs/src/src/sid/main/dynamic/commonCfg.cxx,v
retrieving revision 1.15
diff -c -p -r1.15 commonCfg.cxx
*** sid/main/dynamic/commonCfg.cxx	26 Jun 2006 21:03:00 -0000	1.15
--- sid/main/dynamic/commonCfg.cxx	14 Jul 2006 19:16:05 -0000
*************** void BoardCfg::write_config (Writer &w)
*** 1285,1290 ****
--- 1285,1291 ----
  	  assert (sess->stdio_obj);
  	  PinConnection (gloss, "debug-tx", sess->stdio_obj, "stdout").write_to(w);
  	  PinConnection (gloss, "debug-rx", sess->stdio_obj, "stdin", dst_to_src).write_to(w);
+ 	  PinConnection (gloss, "debug-rx-eof", sess->stdio_obj, "eof", dst_to_src).write_to(w);
  	  PinConnection (gloss, "process-signal", sess->main_obj, "stop!").write_to(w);
  	  PinConnection (gloss, "process-signal", sess->yield_net, "input").write_to(w);
  	}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]