Only issue responses if we aren;t already blocked
[gem5.git] / src / dev / simconsole.cc
index c3e4f554ac6f4978a30a6443a7363d437576f820..77aafd9fac51c36a2e45ac90f96264c5afb08466 100644 (file)
@@ -24,6 +24,9 @@
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Nathan Binkert
+ *          Ali Saidi
  */
 
 /* @file
@@ -202,32 +205,31 @@ SimConsole::write(const uint8_t *buf, size_t len)
 #define RECEIVE_NONE (ULL(2) << 62)
 #define RECEIVE_ERROR (ULL(3) << 62)
 
-bool
-SimConsole::in(uint8_t &c)
+uint8_t
+SimConsole::in()
 {
-    bool empty, ret;
+    bool empty;
+    uint8_t c;
 
     empty = rxbuf.empty();
-    ret = !empty;
-    if (!empty) {
-        rxbuf.read((char *)&c, 1);
-        empty = rxbuf.empty();
-    }
+    assert(!empty);
+    rxbuf.read((char *)&c, 1);
+    empty = rxbuf.empty();
 
-    DPRINTF(ConsoleVerbose, "in: \'%c\' %#02x more: %d, return: %d\n",
-            isprint(c) ? c : ' ', c, !empty, ret);
 
-    return ret;
+    DPRINTF(ConsoleVerbose, "in: \'%c\' %#02x more: %d\n",
+            isprint(c) ? c : ' ', c, !empty);
+
+    return c;
 }
 
 uint64_t
 SimConsole::console_in()
 {
-    uint8_t c;
     uint64_t value;
 
-    if (in(c)) {
-        value = RECEIVE_SUCCESS | c;
+    if (dataAvailable()) {
+        value = RECEIVE_SUCCESS | in();
         if (!rxbuf.empty())
             value  |= MORE_PENDING;
     } else {