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 Lackorzynski <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] & 0xFFFF;
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 case L4_VCON_READ_OP:
70 break;
71
72 default:
73 return l4_msgtag(-L4_ENOSYS, 0, 0, 0);
74 }
75
76 unsigned const max_size = L4_VCON_READ_SIZE;
77 char buf[max_size];
78
79 unsigned size = cxx::min<unsigned>(m->mr[0] >> 16, max_size);
80
81 // Hmm, could we avoid the double copy here?
82 l4_umword_t v = this_vcon()->vcon_read(buf, size);
83 unsigned bytes = v & L4_VCON_READ_SIZE_MASK;
84
85 if (bytes <= size)
87 else
88 // In case of size == max_size, the returned bytes value is greater than
89 // the buffer.
90 bytes = size;
91
92 m->mr[0] = v;
93 __builtin_memcpy(&m->mr[1], buf, bytes);
94
95 return l4_msgtag(0, l4_bytes_to_mwords(bytes) + 1, 0, 0);
96 }
97
98 unsigned vcon_read(char *buf, unsigned size) noexcept;
99 void vcon_write(const char *buf, unsigned size) noexcept;
100 int vcon_set_attr(l4_vcon_attr_t const *) noexcept
101 { return -L4_EOK; }
102 int vcon_get_attr(l4_vcon_attr_t *attr) noexcept
103 {
104 attr->l_flags = attr->o_flags = attr->i_flags = 0;
105 return -L4_EOK;
106 }
107
108private:
109 SVR const *this_vcon() const { return static_cast<SVR const *>(this); }
110 SVR *this_vcon() { return static_cast<SVR *>(this); }
111};
112
113}}
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_ENOSYS
No sys.
Definition err.h:51
@ L4_EINVAL
Invalid argument.
Definition err.h:47
@ L4_ENOREPLY
No reply.
Definition err.h:56
@ L4_EOK
Ok.
Definition err.h:33
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:494
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:421
@ L4_VCON_READ_OP
Read.
Definition vcon.h:294
@ L4_VCON_GET_ATTR_OP
Set console attributes.
Definition vcon.h:296
@ L4_VCON_SET_ATTR_OP
Get console attributes.
Definition vcon.h:295
@ L4_VCON_WRITE_OP
Write.
Definition vcon.h:293
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
@ L4_VCON_READ_SIZE
Maximum size that can be read with one l4_vcon_read* call.
Definition vcon.h:100
Common L4 ABI Data Types.
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
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:266
unsigned words() const L4_NOTHROW
Get the number of untyped words.
Definition types.h:274
Vcon attribute structure.
Definition vcon.h:188
l4_umword_t i_flags
input flags
Definition vcon.h:189
l4_umword_t o_flags
output flags
Definition vcon.h:190
l4_umword_t l_flags
local flags
Definition vcon.h:191
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:133
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:134
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:174
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:172
C++ Virtual console interface.