From ee4263f72e547d551e26b058ee16a48a5f47e3c4 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 29 Jan 2004 16:32:03 -0500 Subject: [PATCH 1/3] Fix character input by handling the character and the special console values separately. dev/alpha_console.cc: use new console specific input function --HG-- extra : convert_revision : 08997d6115d2aac3a26cac2774b3c3fc0cd76ab0 --- dev/alpha_console.cc | 2 +- dev/console.cc | 51 +++++++++++++++++++++++++++++--------------- dev/console.hh | 8 +++++-- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/dev/alpha_console.cc b/dev/alpha_console.cc index ccf6c33fd..8e59db932 100644 --- a/dev/alpha_console.cc +++ b/dev/alpha_console.cc @@ -81,7 +81,7 @@ AlphaConsole::read(MemReqPtr req, uint8_t *data) Addr daddr = req->paddr & addr_mask; switch (daddr) { case offsetof(AlphaAccess, inputChar): - val = console->in(); + val = console->console_in(); break; default: diff --git a/dev/console.cc b/dev/console.cc index 3fa51a414..5e7b0abf6 100644 --- a/dev/console.cc +++ b/dev/console.cc @@ -228,27 +228,44 @@ SimConsole::configTerm() #define RECEIVE_NONE (ULL(2) << 62) #define RECEIVE_ERROR (ULL(3) << 62) -uint64_t -SimConsole::in() +bool +SimConsole::in(uint8_t &c) { - char c = 0; - uint64_t val = 0; - if (rxbuf.empty()) { - clearInt(ReceiveInterrupt); - val |= RECEIVE_NONE; - return 0x8; - } else { - uint64_t val; - rxbuf.read(&c, 1); - val |= RECEIVE_SUCCESS | c; - if (!rxbuf.empty()) - val |= MORE_PENDING; + bool empty, ret; + + empty = rxbuf.empty(); + ret = !empty; + if (!empty) { + rxbuf.read((char *)&c, 1); + empty = rxbuf.empty(); } - DPRINTF(ConsoleVerbose, "in: \'%c\' %#02x retval: %#x\n", - isprint(c) ? c : ' ', c, val); + if (empty) + clearInt(ReceiveInterrupt); - return val; + DPRINTF(ConsoleVerbose, "in: \'%c\' %#02x more: %d, return: %d\n", + isprint(c) ? c : ' ', c, !empty, ret); + + return ret; +} + +uint64_t +SimConsole::console_in() +{ + uint8_t c; + uint64_t value; + + if (in(c)) { + value = RECEIVE_SUCCESS | c; + if (!rxbuf.empty()) + value |= MORE_PENDING; + } else { + value = RECEIVE_NONE; + } + + DPRINTF(ConsoleVerbose, "console_in: return: %#x\n", value); + + return value; } void diff --git a/dev/console.hh b/dev/console.hh index 9913fe379..d2bba4612 100644 --- a/dev/console.hh +++ b/dev/console.hh @@ -109,7 +109,10 @@ class SimConsole : public SimObject // OS interface // Get a character from the console. - // the return value corresponds to the console GETC return value: + bool in(uint8_t &value); + + // get a character from the console in the console specific format + // corresponds to GETC: // retval<63:61> // 000: success: character received // 001: success: character received, more pending @@ -118,8 +121,9 @@ class SimConsole : public SimObject // 111: failure: character received with error, more pending // retval<31:0> // character read from console + // // Interrupts are cleared when the buffer is empty. - uint64_t in(); + uint64_t console_in(); // Send a character to the console void out(char c, bool raise_int = true); From cb35f819c5326b37899695345ad78e032e8d7cdf Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 29 Jan 2004 17:44:08 -0500 Subject: [PATCH 3/3] delete the data in the arglist when the list is destroyed, not while printing out the data. This allows the data to be dumped more than once. base/cprintf.hh: need a destructor --HG-- extra : convert_revision : 235e9fe24488ac4c0ae1b562ef9fa6e0bd1e899c --- base/cprintf.cc | 26 ++++++++++++++++---------- base/cprintf.hh | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/base/cprintf.cc b/base/cprintf.cc index 5796a712b..5cbf0c057 100644 --- a/base/cprintf.cc +++ b/base/cprintf.cc @@ -37,9 +37,20 @@ using namespace std; namespace cp { +ArgList::~ArgList() +{ + while (!objects.empty()) { + delete objects.front(); + objects.pop_front(); + } +} + void ArgList::dump(const string &format) { + list_t::iterator iter = objects.begin(); + list_t::iterator end = objects.end(); + const char *p = format.c_str(); stream->fill(' '); @@ -198,22 +209,19 @@ ArgList::dump(const string &format) } } - if (!objects.empty()) + if (iter != end) { - Base *data = objects.front(); - objects.pop_front(); - ios::fmtflags saved_flags = stream->flags(); char old_fill = stream->fill(); int old_precision = stream->precision(); - data->process(*stream, fmt); + (*iter)->process(*stream, fmt); stream->flags(saved_flags); stream->fill(old_fill); stream->precision(old_precision); - delete data; + ++iter; } else { *stream << ""; } @@ -241,11 +249,9 @@ ArgList::dump(const string &format) } } - while (!objects.empty()) { + while (iter != end) { *stream << ""; - Base *data = objects.front(); - objects.pop_front(); - delete data; + ++iter; } } diff --git a/base/cprintf.hh b/base/cprintf.hh index ac34cd252..ca5c08b16 100644 --- a/base/cprintf.hh +++ b/base/cprintf.hh @@ -89,6 +89,7 @@ class ArgList public: ArgList() : stream(&std::cout) {} + ~ArgList(); template void append(const T &data) {