2 * Copyright (c) 2003 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * User Console Interface
33 #ifndef __CONSOLE_HH__
34 #define __CONSOLE_HH__
38 #include "base/circlebuf.hh"
39 #include "cpu/intr_control.hh"
40 #include "base/pollevent.hh"
41 #include "base/socket.hh"
42 #include "sim/sim_object.hh"
44 class ConsoleListener;
45 class SimConsole : public SimObject
48 class Event : public PollEvent
54 Event(SimConsole *c, int fd, int e);
55 void process(int revent);
67 ConsoleListener *listener;
70 SimConsole(const std::string &name, const std::string &file, int num);
76 std::ostream *outfile;
82 ///////////////////////
85 void attach(int fd, ConsoleListener *l = NULL) { attach(fd, fd, l); }
86 void attach(int in, int out, ConsoleListener *l = NULL);
92 void read(uint8_t &c) { read(&c, 1); }
93 size_t read(uint8_t *buf, size_t len);
94 void write(uint8_t c) { write(&c, 1); }
95 size_t write(const uint8_t *buf, size_t len);
100 // interrupt status/enable
106 // Platform so we can post interrupts
113 // Get a character from the console.
114 bool in(uint8_t &value);
116 // get a character from the console in the console specific format
117 // corresponds to GETC:
119 // 000: success: character received
120 // 001: success: character received, more pending
121 // 100: failure: no character ready
122 // 110: failure: character received with error
123 // 111: failure: character received with error, more pending
125 // character read from console
127 // Interrupts are cleared when the buffer is empty.
128 uint64_t console_in();
130 // Send a character to the console
131 void out(char c, bool raise_int = true);
134 TransmitInterrupt = 1,
138 // Read the current interrupt status of this console.
139 int intStatus() { return _status; }
141 // Set the interrupt enable bits.
143 void raiseInt(int i);
145 void initInt(IntrControl *i);
146 void setInt(int bits);
148 void setPlatform(Platform *p);
150 virtual void serialize(std::ostream &os);
151 virtual void unserialize(Checkpoint *cp, const std::string §ion);
154 class ConsoleListener : public SimObject
157 class Event : public PollEvent
160 ConsoleListener *listener;
163 Event(ConsoleListener *l, int fd, int e)
164 : PollEvent(fd, e), listener(l) {}
165 void process(int revent);
171 typedef std::list<SimConsole *> list_t;
172 typedef list_t::iterator iter_t;
176 ListenSocket listener;
179 ConsoleListener(const std::string &name);
182 void add(SimConsole *cons);
185 void listen(int port);
188 #endif // __CONSOLE_HH__