Loading...
Searching...
No Matches
vcon_svr
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2008-2011 Alexander Warg <warg@os.inf.tu-dresden.de>,
* Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
* Adam Lackorzynski <adam@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/sys/types.h>
#include <l4/sys/vcon>
#include <l4/sys/cxx/ipc_legacy>
#include <l4/cxx/minmax>
namespace L4Re { namespace Util {
template< typename SVR >
class Vcon_svr
{
public:
L4_RPC_LEGACY_DISPATCH(L4::Vcon);
l4_msgtag_t op_dispatch(l4_utcb_t *utcb, l4_msgtag_t tag, L4::Vcon::Rights)
{
l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
L4::Opcode op = m->mr[0];
switch (op)
{
case L4_VCON_WRITE_OP:
if (tag.words() < 3)
return l4_msgtag(-L4_ENOREPLY, 0, 0, 0);
this_vcon()->vcon_write(reinterpret_cast<char const *>(&m->mr[2]),
m->mr[1]);
return l4_msgtag(-L4_ENOREPLY, 0, 0, 0);
case L4_VCON_SET_ATTR_OP:
{
if (tag.words() < 4)
return l4_msgtag(-L4_EINVAL, 0, 0, 0);
auto attr = reinterpret_cast< l4_vcon_attr_t const *>(&m->mr[1]);
return l4_msgtag(this_vcon()->vcon_set_attr(attr), 0, 0, 0);
}
case L4_VCON_GET_ATTR_OP:
{
auto attr = reinterpret_cast< l4_vcon_attr_t *>(&m->mr[1]);
return l4_msgtag(this_vcon()->vcon_get_attr(attr), 4, 0, 0);
}
default:
break;
}
unsigned const max_size = sizeof(l4_utcb_mr()->mr) - sizeof(l4_utcb_mr()->mr[0]);
char buf[max_size];
unsigned size = cxx::min<unsigned>(op >> 16, max_size);
// Hmm, could we avoid the double copy here?
l4_umword_t v = this_vcon()->vcon_read(buf, size);
unsigned bytes = v & L4_VCON_READ_SIZE_MASK;
if (bytes <= size)
v |= L4_VCON_READ_STAT_DONE;
m->mr[0] = v;
__builtin_memcpy(&m->mr[1], buf, bytes);
return l4_msgtag(0, l4_bytes_to_mwords(bytes) + 1, 0, 0);
}
unsigned vcon_read(char *buf, unsigned size) noexcept;
void vcon_write(const char *buf, unsigned size) noexcept;
int vcon_set_attr(l4_vcon_attr_t const *) noexcept
{ return -L4_EOK; }
int vcon_get_attr(l4_vcon_attr_t *attr) noexcept
{
attr->l_flags = attr->o_flags = attr->i_flags = 0;
return -L4_EOK;
}
private:
SVR const *this_vcon() const { return static_cast<SVR const *>(this); }
SVR *this_vcon() { return static_cast<SVR *>(this); }
};
}}
L4Re::Util::Vcon_svr
Console server template class.
Definition vcon_svr:37
L4::Vcon
C++ L4 Vcon interface, see Virtual Console for the C interface.
Definition vcon:47
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
L4_EINVAL
@ L4_EINVAL
Invalid argument.
Definition err.h:46
L4_ENOREPLY
@ L4_ENOREPLY
No reply.
Definition err.h:55
L4_EOK
@ L4_EOK
Ok.
Definition err.h:32
l4_bytes_to_mwords
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:496
l4_msgtag
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:405
L4_VCON_GET_ATTR_OP
@ L4_VCON_GET_ATTR_OP
Set console attributes.
Definition vcon.h:296
L4_VCON_SET_ATTR_OP
@ L4_VCON_SET_ATTR_OP
Get console attributes.
Definition vcon.h:295
L4_VCON_WRITE_OP
@ L4_VCON_WRITE_OP
Write.
Definition vcon.h:293
l4_utcb_mr
l4_msg_regs_t * l4_utcb_mr(void) L4_NOTHROW L4_PURE
Get the message-register block of a UTCB.
Definition utcb.h:358
l4_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
types.h
Common L4 ABI Data Types.
L4Re::Util
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4::Opcode
int Opcode
Data type for RPC opcodes.
Definition __typeinfo.h:36
l4_msgtag_t
Message tag data structure.
Definition types.h:154
l4_msgtag_t::words
unsigned words() const L4_NOTHROW
Get the number of untyped words.
Definition types.h:169
l4_vcon_attr_t
Vcon attribute structure.
Definition vcon.h:188
l4_vcon_attr_t::i_flags
l4_umword_t i_flags
input flags
Definition vcon.h:189
l4_vcon_attr_t::o_flags
l4_umword_t o_flags
output flags
Definition vcon.h:190
l4_vcon_attr_t::l_flags
l4_umword_t l_flags
local flags
Definition vcon.h:191
l4_msg_regs_t
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_msg_regs_t::mr
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69
L4_VCON_READ_STAT_DONE
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:174
L4_VCON_READ_SIZE_MASK
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:172
vcon
C++ Virtual console interface.