change the path that i track from two separate paths to one.
[gem5.git] / dev / console.hh
1 /*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29 /* @file
30 * User Console Interface
31 */
32
33 #ifndef __CONSOLE_HH__
34 #define __CONSOLE_HH__
35
36 #include <iostream>
37
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"
43
44 class ConsoleListener;
45 class SimConsole : public SimObject
46 {
47 protected:
48 class Event : public PollEvent
49 {
50 protected:
51 SimConsole *cons;
52
53 public:
54 Event(SimConsole *c, int fd, int e);
55 void process(int revent);
56 };
57
58 friend class Event;
59 Event *event;
60
61 protected:
62 int number;
63 int in_fd;
64 int out_fd;
65
66 protected:
67 ConsoleListener *listener;
68
69 public:
70 SimConsole(const std::string &name, const std::string &file, int num);
71 ~SimConsole();
72
73 protected:
74 CircleBuf txbuf;
75 CircleBuf rxbuf;
76 std::ostream *outfile;
77 #if TRACING_ON == 1
78 CircleBuf linebuf;
79 #endif
80
81 public:
82 ///////////////////////
83 // Terminal Interface
84
85 void attach(int fd, ConsoleListener *l = NULL) { attach(fd, fd, l); }
86 void attach(int in, int out, ConsoleListener *l = NULL);
87 void detach();
88
89 void data();
90
91 void close();
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);
96
97 void configTerm();
98
99 protected:
100 // interrupt status/enable
101 int _status;
102 int _enable;
103
104 // interrupt handle
105 IntrControl *intr;
106
107 public:
108 /////////////////
109 // OS interface
110
111 // Get a character from the console.
112 // return of -1 means there is no character pending.
113 // Interrupts are cleared when the buffer is empty.
114 int in();
115
116 // Send a character to the console
117 void out(char c, bool raise_int = true);
118
119 enum {
120 TransmitInterrupt = 1,
121 ReceiveInterrupt = 2
122 };
123
124 // Read the current interrupt status of this console.
125 int intStatus() { return _status; }
126
127 // Set the interrupt enable bits.
128 int clearInt(int i);
129 void raiseInt(int i);
130
131 void initInt(IntrControl *i);
132 void setInt(int bits);
133
134 virtual void serialize(std::ostream &os);
135 virtual void unserialize(Checkpoint *cp, const std::string &section);
136 };
137
138 class ConsoleListener : public SimObject
139 {
140 protected:
141 class Event : public PollEvent
142 {
143 protected:
144 ConsoleListener *listener;
145
146 public:
147 Event(ConsoleListener *l, int fd, int e)
148 : PollEvent(fd, e), listener(l) {}
149 void process(int revent);
150 };
151
152 friend class Event;
153 Event *event;
154
155 typedef std::list<SimConsole *> list_t;
156 typedef list_t::iterator iter_t;
157 list_t ConsoleList;
158
159 protected:
160 ListenSocket listener;
161
162 public:
163 ConsoleListener(const std::string &name);
164 ~ConsoleListener();
165
166 void add(SimConsole *cons);
167
168 void accept();
169 void listen(int port);
170 };
171
172 #endif // __CONSOLE_HH__