make serialization at least seem to work
[gem5.git] / src / dev / simconsole.hh
1 /*
2 * Copyright (c) 2001-2005 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 * Authors: Nathan Binkert
29 * Ali Saidi
30 */
31
32 /* @file
33 * User Console Interface
34 */
35
36 #ifndef __CONSOLE_HH__
37 #define __CONSOLE_HH__
38
39 #include <iostream>
40
41 #include "base/circlebuf.hh"
42 #include "cpu/intr_control.hh"
43 #include "base/pollevent.hh"
44 #include "base/socket.hh"
45 #include "sim/sim_object.hh"
46
47 class ConsoleListener;
48 class Uart;
49
50 class SimConsole : public SimObject
51 {
52 public:
53 Uart *uart;
54
55 protected:
56 class ListenEvent : public PollEvent
57 {
58 protected:
59 SimConsole *cons;
60
61 public:
62 ListenEvent(SimConsole *c, int fd, int e);
63 void process(int revent);
64 };
65
66 friend class ListenEvent;
67 ListenEvent *listenEvent;
68
69 class DataEvent : public PollEvent
70 {
71 protected:
72 SimConsole *cons;
73
74 public:
75 DataEvent(SimConsole *c, int fd, int e);
76 void process(int revent);
77 };
78
79 friend class DataEvent;
80 DataEvent *dataEvent;
81
82 protected:
83 int number;
84 int data_fd;
85
86 public:
87 SimConsole(const std::string &name, std::ostream *os, int num, int port);
88 ~SimConsole();
89
90 protected:
91 ListenSocket listener;
92
93 void listen(int port);
94 void accept();
95
96 protected:
97 CircleBuf txbuf;
98 CircleBuf rxbuf;
99 std::ostream *outfile;
100 #if TRACING_ON == 1
101 CircleBuf linebuf;
102 #endif
103
104 public:
105 ///////////////////////
106 // Terminal Interface
107
108 void data();
109
110 void read(uint8_t &c) { read(&c, 1); }
111 size_t read(uint8_t *buf, size_t len);
112 void write(uint8_t c) { write(&c, 1); }
113 size_t write(const uint8_t *buf, size_t len);
114 void detach();
115
116 public:
117 /////////////////
118 // OS interface
119
120 // Get a character from the console.
121 uint8_t in();
122
123 // get a character from the console in the console specific format
124 // corresponds to GETC:
125 // retval<63:61>
126 // 000: success: character received
127 // 001: success: character received, more pending
128 // 100: failure: no character ready
129 // 110: failure: character received with error
130 // 111: failure: character received with error, more pending
131 // retval<31:0>
132 // character read from console
133 //
134 // Interrupts are cleared when the buffer is empty.
135 uint64_t console_in();
136
137 // Send a character to the console
138 void out(char c);
139
140 //Ask the console if data is available
141 bool dataAvailable() { return !rxbuf.empty(); }
142 };
143
144 #endif // __CONSOLE_HH__