minor mods for mimicking NS83820 functionality
[gem5.git] / dev / console.hh
1 /* $Id$ */
2
3 /* @file
4 * User Console Interface
5 */
6
7 #ifndef __CONSOLE_HH__
8 #define __CONSOLE_HH__
9
10 #include <iostream>
11
12 #include "base/circlebuf.hh"
13 #include "cpu/intr_control.hh"
14 #include "base/pollevent.hh"
15 #include "base/socket.hh"
16 #include "sim/sim_object.hh"
17
18 class ConsoleListener;
19 class SimConsole : public SimObject
20 {
21 protected:
22 class Event : public PollEvent
23 {
24 protected:
25 SimConsole *cons;
26
27 public:
28 Event(SimConsole *c, int fd, int e);
29 void process(int revent);
30 };
31
32 friend class Event;
33 Event *event;
34
35 protected:
36 int number;
37 int in_fd;
38 int out_fd;
39
40 protected:
41 ConsoleListener *listener;
42
43 public:
44 SimConsole(const std::string &name, const std::string &file, int num);
45 ~SimConsole();
46
47 protected:
48 CircleBuf txbuf;
49 CircleBuf rxbuf;
50 std::ostream *outfile;
51 #if TRACING_ON == 1
52 CircleBuf linebuf;
53 #endif
54
55 public:
56 ///////////////////////
57 // Terminal Interface
58
59 void attach(int fd, ConsoleListener *l = NULL) { attach(fd, fd, l); }
60 void attach(int in, int out, ConsoleListener *l = NULL);
61 void detach();
62
63 void data();
64
65 void close();
66 void read(uint8_t &c) { read(&c, 1); }
67 size_t read(uint8_t *buf, size_t len);
68 void write(uint8_t c) { write(&c, 1); }
69 size_t write(const uint8_t *buf, size_t len);
70
71 void configTerm();
72
73 protected:
74 // interrupt status/enable
75 int _status;
76 int _enable;
77
78 // interrupt handle
79 IntrControl *intr;
80 // Platform so we can post interrupts
81 Platform *platform;
82
83 public:
84 /////////////////
85 // OS interface
86
87 // Get a character from the console.
88 bool in(uint8_t &value);
89
90 // get a character from the console in the console specific format
91 // corresponds to GETC:
92 // retval<63:61>
93 // 000: success: character received
94 // 001: success: character received, more pending
95 // 100: failure: no character ready
96 // 110: failure: character received with error
97 // 111: failure: character received with error, more pending
98 // retval<31:0>
99 // character read from console
100 //
101 // Interrupts are cleared when the buffer is empty.
102 uint64_t console_in();
103
104 // Send a character to the console
105 void out(char c, bool raise_int = true);
106
107 enum {
108 TransmitInterrupt = 1,
109 ReceiveInterrupt = 2
110 };
111
112 // Read the current interrupt status of this console.
113 int intStatus() { return _status; }
114
115 // Set the interrupt enable bits.
116 int clearInt(int i);
117 void raiseInt(int i);
118
119 void initInt(IntrControl *i);
120 void setInt(int bits);
121
122 void setPlatform(Platform *p);
123
124 virtual void serialize(std::ostream &os);
125 virtual void unserialize(Checkpoint *cp, const std::string &section);
126 };
127
128 class ConsoleListener : public SimObject
129 {
130 protected:
131 class Event : public PollEvent
132 {
133 protected:
134 ConsoleListener *listener;
135
136 public:
137 Event(ConsoleListener *l, int fd, int e)
138 : PollEvent(fd, e), listener(l) {}
139 void process(int revent);
140 };
141
142 friend class Event;
143 Event *event;
144
145 typedef std::list<SimConsole *> list_t;
146 typedef list_t::iterator iter_t;
147 list_t ConsoleList;
148
149 protected:
150 ListenSocket listener;
151
152 public:
153 ConsoleListener(const std::string &name);
154 ~ConsoleListener();
155
156 void add(SimConsole *cons);
157
158 void accept();
159 void listen(int port);
160 };
161
162 #endif // __CONSOLE_HH__