L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
vcon_svr
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2008-2011 Alexander Warg <warg@os.inf.tu-dresden.de>,
4 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
5 * Adam Lackorzysnski <adam@os.inf.tu-dresden.de>
6 * economic rights: Technische Universität Dresden (Germany)
7 *
8 * This file is part of TUD:OS and distributed under the terms of the
9 * GNU General Public License 2.
10 * Please see the COPYING-GPL-2 file for details.
11 *
12 * As a special exception, you may use this file as part of a free software
13 * library without restriction. Specifically, if other files instantiate
14 * templates or use macros or inline functions from this file, or you compile
15 * this file and link it with other files to produce an executable, this
16 * file does not by itself cause the resulting executable to be covered by
17 * the GNU General Public License. This exception does not however
18 * invalidate any other reasons why the executable file might be covered by
19 * the GNU General Public License.
20 */
21#pragma once
22
23#include <l4/sys/types.h>
24#include <l4/sys/vcon>
25#include <l4/sys/cxx/ipc_legacy>
26#include <l4/cxx/minmax>
27
28namespace L4Re { namespace Util {
29
46template< typename SVR >
48{
49public:
50 L4_RPC_LEGACY_DISPATCH(L4::Vcon);
51
52 l4_msgtag_t op_dispatch(l4_utcb_t *utcb, l4_msgtag_t tag, L4::Vcon::Rights)
53 {
54 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
55 L4::Opcode op = m->mr[0];
56
57 switch (op)
58 {
60 if (tag.words() < 3)
61 return l4_msgtag(-L4_ENOREPLY, 0, 0, 0);
62
63 this_vcon()->vcon_write(reinterpret_cast<char const *>(&m->mr[2]),
64 m->mr[1]);
65 return l4_msgtag(-L4_ENOREPLY, 0, 0, 0);
66
68 {
69 if (tag.words() < 4)
70 return l4_msgtag(-L4_EINVAL, 0, 0, 0);
71
72 auto attr = reinterpret_cast<l4_vcon_attr_t const *>(&m->mr[1]);
73 return l4_msgtag(this_vcon()->vcon_set_attr(attr), 0, 0, 0);
74 }
76 {
77 auto attr = reinterpret_cast<l4_vcon_attr_t *>(&m->mr[1]);
78 return l4_msgtag(this_vcon()->vcon_get_attr(attr), 4, 0, 0);
79 }
80
81 default:
82 break;
83 }
84
85 unsigned const max_size = sizeof(l4_utcb_mr()->mr) - sizeof(l4_utcb_mr()->mr[0]);
86 char buf[max_size];
87
88 unsigned size = cxx::min<unsigned>(op >> 16, max_size);
89
90 // Hmm, could we avoid the double copy here?
91 l4_umword_t v = this_vcon()->vcon_read(buf, size);
92 unsigned bytes = v & L4_VCON_READ_SIZE_MASK;
93
94 if (bytes <= size)
96
97 m->mr[0] = v;
98 __builtin_memcpy(&m->mr[1], buf, bytes);
99
100 return l4_msgtag(0, l4_bytes_to_mwords(bytes) + 1, 0, 0);
101 }
102
103 unsigned vcon_read(char *buf, unsigned size) noexcept;
104 void vcon_write(const char *buf, unsigned size) noexcept;
105 int vcon_set_attr(l4_vcon_attr_t const *) noexcept
106 { return -L4_EOK; }
107 int vcon_get_attr(l4_vcon_attr_t *attr) noexcept
108 {
109 attr->l_flags = attr->o_flags = attr->i_flags = 0;
110 return -L4_EOK;
111 }
112
113private:
114 SVR const *this_vcon() const { return static_cast<SVR const *>(this); }
115 SVR *this_vcon() { return static_cast<SVR *>(this); }
116};
117
118}}
Console server template class.
Definition vcon_svr:48
C++ L4 Vcon interface, see Virtual Console for the C interface.
Definition vcon:58
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
@ L4_EINVAL
Invalid argument.
Definition err.h:57
@ L4_ENOREPLY
No reply.
Definition err.h:66
@ L4_EOK
Ok.
Definition err.h:43
unsigned l4_bytes_to_mwords(unsigned size) L4_NOTHROW
Determine how many machine words (l4_umword_t) are required to store a buffer of 'size' bytes.
Definition consts.h:485
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition types.h:428
@ L4_VCON_GET_ATTR_OP
Set console attributes.
Definition vcon.h:305
@ L4_VCON_SET_ATTR_OP
Get console attributes.
Definition vcon.h:304
@ L4_VCON_WRITE_OP
Write.
Definition vcon.h:302
l4_msg_regs_t * l4_utcb_mr(void) L4_NOTHROW L4_PURE
Get the message-register block of a UTCB.
Definition utcb.h:352
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition l4re.dox:17
int Opcode
Data type for RPC opcodes.
Definition __typeinfo.h:47
Message tag data structure.
Definition types.h:164
unsigned words() const L4_NOTHROW
Get the number of untyped words.
Definition types.h:172
Vcon attribute structure.
Definition vcon.h:197
l4_umword_t i_flags
input flags
Definition vcon.h:198
l4_umword_t o_flags
output flags
Definition vcon.h:199
l4_umword_t l_flags
local flags
Definition vcon.h:200
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:79
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:80
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:183
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:181
C++ Virtual console interface.