2 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
9 * As a special exception, you may use this file as part of a free software
10 * library without restriction. Specifically, if other files instantiate
11 * templates or use macros or inline functions from this file, or you compile
12 * this file and link it with other files to produce an executable, this
13 * file does not by itself cause the resulting executable to be covered by
14 * the GNU General Public License. This exception does not however
15 * invalidate any other reasons why the executable file might be covered by
16 * the GNU General Public License.
20 #include <l4/sys/factory>
22 #include "vcon_stream.h"
27 #include <sys/ioctl.h>
29 namespace L4Re { namespace Core {
30 Vcon_stream::Vcon_stream(L4::Cap<L4::Vcon> s) throw()
31 : Be_file(), _s(s), _irq(cap_alloc()->alloc<L4::Irq>())
34 //printf("VCON: irq cap = %lx\n", _irq.cap());
35 int res = l4_error(L4Re::Env::env()->factory()->create_irq(_irq));
36 //printf("VCON: irq create res=%d\n", res);
39 return; // handle errors!!!
41 res = l4_error(L4::cap_reinterpret_cast<L4::Icu>(_s)->bind(0, _irq));
42 //printf("VCON: bound irq to con res=%d\n", res);
47 Vcon_stream::readv(const struct iovec *iovec, int iovcnt) throw()
53 for (; iovcnt > 0; --iovcnt, ++iovec)
55 if (iovec->iov_len == 0)
58 char *buf = (char *)iovec->iov_base;
59 size_t len = iovec->iov_len;
63 int ret = _s->read(buf, len);
65 // BS: what is this ??
77 _irq->attach(12, L4::Cap<L4::Thread>::Invalid);
78 ret = _s->read(buf, len);
103 Vcon_stream::writev(const struct iovec *iovec, int iovcnt) throw()
106 l4_msg_regs_t *mr = l4_utcb_mr();
108 Vfs_config::memcpy(&store, mr, sizeof(store));
113 size_t sl = iovec->iov_len;
114 char const *b = (char const *)iovec->iov_base;
116 for (; sl > L4_VCON_WRITE_SIZE
117 ; sl -= L4_VCON_WRITE_SIZE, b += L4_VCON_WRITE_SIZE)
118 _s->write(b, L4_VCON_WRITE_SIZE);
122 written += iovec->iov_len;
127 Vfs_config::memcpy(mr, &store, sizeof(store));
132 Vcon_stream::fstat64(struct stat64 *buf) const throw()
136 buf->st_dev = _s.cap();
142 Vcon_stream::ioctl(unsigned long request, va_list args) throw()
147 //vt100_tcgetattr(term, (struct termios *)argp);
149 struct termios *t = va_arg(args, struct termios *);
152 if (!l4_error(_s->get_attr(&l4a)))
154 t->c_iflag = l4a.i_flags;
155 t->c_oflag = l4a.o_flags; // output flags
156 t->c_cflag = 0; // control flags
157 t->c_lflag = l4a.l_flags; // local flags
160 t->c_iflag = t->c_oflag = t->c_cflag = t->c_lflag = 0;
162 //t->c_lflag |= ECHO; // if term->echo
163 t->c_lflag |= ICANON; // if term->term_mode == VT100MODE_COOKED
166 t->c_cc[VEOF] = CEOF;
167 t->c_cc[VEOL] = _POSIX_VDISABLE;
168 t->c_cc[VEOL2] = _POSIX_VDISABLE;
169 t->c_cc[VERASE] = CERASE;
170 t->c_cc[VWERASE]= CWERASE;
171 t->c_cc[VKILL] = CKILL;
172 t->c_cc[VREPRINT]=CREPRINT;
173 t->c_cc[VINTR] = CINTR;
174 t->c_cc[VQUIT] = _POSIX_VDISABLE;
175 t->c_cc[VSUSP] = CSUSP;
176 t->c_cc[VSTART] = CSTART;
177 t->c_cc[VSTOP] = CSTOP;
178 t->c_cc[VLNEXT] = CLNEXT;
179 t->c_cc[VDISCARD]=CDISCARD;
180 t->c_cc[VMIN] = CMIN;
191 //vt100_tcsetattr(term, (struct termios *)argp);
192 struct termios const *t = va_arg(args, struct termios const *);
194 // XXX: well, we're cheating, get this from the other side!
197 l4a.i_flags = t->c_iflag;
198 l4a.o_flags = t->c_oflag; // output flags
199 l4a.l_flags = t->c_lflag; // local flags