Import changeset
[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 "circlebuf.hh"
13 #include "intr_control.hh"
14 #include "pollevent.hh"
15 #include "socket.hh"
16 #include "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
52 public:
53 ///////////////////////
54 // Terminal Interface
55
56 void attach(int fd, ConsoleListener *l = NULL) { attach(fd, fd, l); }
57 void attach(int in, int out, ConsoleListener *l = NULL);
58 void detach();
59
60 void data();
61
62 void close();
63 void read(uint8_t &c) { read(&c, 1); }
64 size_t read(uint8_t *buf, size_t len);
65 void write(uint8_t c) { write(&c, 1); }
66 size_t write(const uint8_t *buf, size_t len);
67
68 void configTerm();
69
70 protected:
71 // interrupt status/enable
72 int intr_status;
73 int intr_enable;
74
75 // interrupt handle
76 IntrControl *intr;
77
78 public:
79 /////////////////
80 // OS interface
81
82 // Input a character from the console. Returns the character (if
83 // any) or -1 if there is no character pending on this console. If
84 // no further characters are pending, the (input) interrupt is
85 // cleared.
86 int in();
87
88 // Output a character to the console. This never fails, as this
89 // device doesn't model finite buffering capacity.
90 void out(char c);
91 void simple(char c);
92
93 enum {
94 TransmitInterrupt = 1,
95 ReceiveInterrupt = 2
96 };
97
98 // Read the current interrupt status of this console.
99 int intStatus();
100
101 // Set the interrupt enable bits.
102 int clearInt(int i);
103 void raiseInt(int i);
104
105 void initInt(IntrControl *i);
106 void setInt(int bits);
107
108 virtual void serialize();
109 virtual void unserialize(IniFile &db, const std::string &category,
110 ConfigNode *node);
111 };
112
113 class ConsoleListener : public SimObject
114 {
115 protected:
116 class Event : public PollEvent
117 {
118 protected:
119 ConsoleListener *listener;
120
121 public:
122 Event(ConsoleListener *l, int fd, int e)
123 : PollEvent(fd, e), listener(l) {}
124 void process(int revent);
125 };
126
127 friend class Event;
128 Event *event;
129
130 typedef std::list<SimConsole *> list_t;
131 typedef list_t::iterator iter_t;
132 list_t ConsoleList;
133
134 protected:
135 ListenSocket listener;
136
137 public:
138 ConsoleListener(const std::string &name);
139 ~ConsoleListener();
140
141 void add(SimConsole *cons);
142
143 void accept();
144 void listen(int port);
145 };
146
147 #endif // __CONSOLE_HH__