L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
9 */
10#pragma once
11
12#include <l4/sys/types.h>
13#include <l4/sys/vcon>
14#include <l4/sys/cxx/ipc_legacy>
15#include <l4/cxx/minmax>
16
17namespace L4Re { namespace Util {
18
35template< typename SVR >
37{
38public:
39 L4_RPC_LEGACY_DISPATCH(L4::Vcon);
40
41 l4_msgtag_t op_dispatch(l4_utcb_t *utcb, l4_msgtag_t tag, L4::Vcon::Rights)
42 {
43 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
44 L4::Opcode op = m->mr[0];
45
46 switch (op)
47 {
49 if (tag.words() < 3)
50 return l4_msgtag(-L4_ENOREPLY, 0, 0, 0);
51
52 this_vcon()->vcon_write(reinterpret_cast<char const *>(&m->mr[2]),
53 m->mr[1]);
54 return l4_msgtag(-L4_ENOREPLY, 0, 0, 0);
55
57 {
58 if (tag.words() < 4)
59 return l4_msgtag(-L4_EINVAL, 0, 0, 0);
60
61 auto attr = reinterpret_cast<l4_vcon_attr_t const *>(&m->mr[1]);
62 return l4_msgtag(this_vcon()->vcon_set_attr(attr), 0, 0, 0);
63 }
65 {
66 auto attr = reinterpret_cast<l4_vcon_attr_t *>(&m->mr[1]);
67 return l4_msgtag(this_vcon()->vcon_get_attr(attr), 4, 0, 0);
68 }
69
70 default:
71 break;
72 }
73
74 unsigned const max_size = sizeof(l4_utcb_mr()->mr) - sizeof(l4_utcb_mr()->mr[0]);
75 char buf[max_size];
76
77 unsigned size = cxx::min<unsigned>(op >> 16, max_size);
78
79 // Hmm, could we avoid the double copy here?
80 l4_umword_t v = this_vcon()->vcon_read(buf, size);
81 unsigned bytes = v & L4_VCON_READ_SIZE_MASK;
82
83 if (bytes <= size)
85
86 m->mr[0] = v;
87 __builtin_memcpy(&m->mr[1], buf, bytes);
88
89 return l4_msgtag(0, l4_bytes_to_mwords(bytes) + 1, 0, 0);
90 }
91
92 unsigned vcon_read(char *buf, unsigned size) noexcept;
93 void vcon_write(const char *buf, unsigned size) noexcept;
94 int vcon_set_attr(l4_vcon_attr_t const *) noexcept
95 { return -L4_EOK; }
96 int vcon_get_attr(l4_vcon_attr_t *attr) noexcept
97 {
98 attr->l_flags = attr->o_flags = attr->i_flags = 0;
99 return -L4_EOK;
100 }
101
102private:
103 SVR const *this_vcon() const { return static_cast<SVR const *>(this); }
104 SVR *this_vcon() { return static_cast<SVR *>(this); }
105};
106
107}}
Console server template class.
Definition vcon_svr:37
C++ L4 Vcon interface, see Virtual Console for the C interface.
Definition vcon:47
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
@ L4_EINVAL
Invalid argument.
Definition err.h:46
@ L4_ENOREPLY
No reply.
Definition err.h:55
@ L4_EOK
Ok.
Definition err.h:32
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:500
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:404
@ L4_VCON_GET_ATTR_OP
Set console attributes.
Definition vcon.h:294
@ L4_VCON_SET_ATTR_OP
Get console attributes.
Definition vcon.h:293
@ L4_VCON_WRITE_OP
Write.
Definition vcon.h:291
l4_msg_regs_t * l4_utcb_mr(void) L4_NOTHROW L4_PURE
Get the message-register block of a UTCB.
Definition utcb.h:358
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition cmd_control:14
int Opcode
Data type for RPC opcodes.
Definition __typeinfo.h:36
Message tag data structure.
Definition types.h:153
unsigned words() const L4_NOTHROW
Get the number of untyped words.
Definition types.h:168
Vcon attribute structure.
Definition vcon.h:186
l4_umword_t i_flags
input flags
Definition vcon.h:187
l4_umword_t o_flags
output flags
Definition vcon.h:188
l4_umword_t l_flags
local flags
Definition vcon.h:189
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:172
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:170
C++ Virtual console interface.