Loading...
Searching...
No Matches
vcon.h
Go to the documentation of this file.
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>,
* Torsten Frenzel <frenzel@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/ipc.h>
L4_INLINE l4_msgtag_t
l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE long
l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
L4_INLINE long
l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
enum L4_vcon_size_consts
{
L4_VCON_WRITE_SIZE = (L4_UTCB_GENERIC_DATA_SIZE - 2) * sizeof(l4_umword_t),
L4_VCON_READ_SIZE = (L4_UTCB_GENERIC_DATA_SIZE - 1) * sizeof(l4_umword_t),
};
L4_INLINE int
l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
L4_INLINE int
l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int
l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
L4_INLINE int
l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
l4_utcb_t *utcb) L4_NOTHROW;
enum L4_vcon_read_flags
{
L4_VCON_READ_SIZE_MASK = 0x3fffffff,
L4_VCON_READ_STAT_BREAK = 1 << 30,
L4_VCON_READ_STAT_DONE = 1 << 31,
};
typedef struct l4_vcon_attr_t
{
l4_umword_t i_flags;
l4_umword_t o_flags;
l4_umword_t l_flags;
#ifdef __cplusplus
inline void set_raw();
#endif
} l4_vcon_attr_t;
enum L4_vcon_i_flags
{
L4_VCON_INLCR = 000100,
L4_VCON_IGNCR = 000200,
L4_VCON_ICRNL = 000400,
};
enum L4_vcon_o_flags
{
L4_VCON_ONLCR = 000004,
L4_VCON_OCRNL = 000010,
L4_VCON_ONLRET = 000040,
};
enum L4_vcon_l_flags
{
L4_VCON_ICANON = 000002,
L4_VCON_ECHO = 000010,
};
L4_INLINE l4_msgtag_t
l4_vcon_set_attr(l4_cap_idx_t vcon, l4_vcon_attr_t const *attr) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_vcon_set_attr_u(l4_cap_idx_t vcon, l4_vcon_attr_t const *attr,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_vcon_get_attr(l4_cap_idx_t vcon, l4_vcon_attr_t *attr) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_vcon_get_attr_u(l4_cap_idx_t vcon, l4_vcon_attr_t *attr,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE void
l4_vcon_set_attr_raw(l4_vcon_attr_t *attr) L4_NOTHROW;
enum L4_vcon_ops
{
L4_VCON_WRITE_OP = 0UL,
L4_VCON_READ_OP = 1UL,
L4_VCON_SET_ATTR_OP = 2UL,
L4_VCON_GET_ATTR_OP = 3UL,
};
/******* Implementations ********************/
L4_INLINE l4_msgtag_t
l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
{
l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
mr->mr[0] = L4_VCON_WRITE_OP;
mr->mr[1] = size;
__builtin_memcpy(&mr->mr[2], buf, size);
return l4_ipc_send(vcon, utcb,
l4_msgtag(L4_PROTO_LOG, 2 + l4_bytes_to_mwords(size),
0, L4_MSGTAG_SCHEDULE),
L4_IPC_NEVER);
}
L4_INLINE l4_msgtag_t
l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
{
return l4_vcon_send_u(vcon, buf, size, l4_utcb());
}
L4_INLINE long
l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
{
l4_msgtag_t t;
if (size > L4_VCON_WRITE_SIZE)
size = L4_VCON_WRITE_SIZE;
t = l4_vcon_send_u(vcon, buf, size, utcb);
if (l4_msgtag_has_error(t))
return l4_error(t);
return (long) size;
}
L4_INLINE long
l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
{
return l4_vcon_write_u(vcon, buf, size, l4_utcb());
}
L4_INLINE int
l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
l4_utcb_t *utcb) L4_NOTHROW
{
int ret;
unsigned r;
l4_msg_regs_t *mr;
mr = l4_utcb_mr_u(utcb);
mr->mr[0] = (size << 16) | L4_VCON_READ_OP;
ret = l4_error_u(l4_ipc_call(vcon, utcb,
l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
L4_IPC_NEVER),
utcb);
if (ret < 0)
return ret;
r = mr->mr[0] & L4_VCON_READ_SIZE_MASK;
if (!(mr->mr[0] & L4_VCON_READ_STAT_DONE)) // !eof
ret = size + 1;
else if (r < size)
ret = r;
else
ret = size;
if (L4_LIKELY(buf != NULL))
__builtin_memcpy(buf, &mr->mr[1], r < size ? r : size);
return ret | (mr->mr[0] & ~(L4_VCON_READ_STAT_DONE | L4_VCON_READ_SIZE_MASK));
}
L4_INLINE int
l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
{
return l4_vcon_read_with_flags_u(vcon, buf, size, l4_utcb());
}
L4_INLINE int
l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
{
int r = l4_vcon_read_with_flags_u(vcon, buf, size, utcb);
if (r < 0)
return r;
return r & L4_VCON_READ_SIZE_MASK;
}
L4_INLINE int
l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
{
return l4_vcon_read_u(vcon, buf, size, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_vcon_set_attr_u(l4_cap_idx_t vcon, l4_vcon_attr_t const *attr,
l4_utcb_t *utcb) L4_NOTHROW
{
l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
mr->mr[0] = L4_VCON_SET_ATTR_OP;
__builtin_memcpy(&mr->mr[1], attr, sizeof(*attr));
return l4_ipc_call(vcon, utcb,
l4_msgtag(L4_PROTO_LOG, 4, 0, 0),
L4_IPC_NEVER);
}
L4_INLINE l4_msgtag_t
l4_vcon_set_attr(l4_cap_idx_t vcon, l4_vcon_attr_t const *attr) L4_NOTHROW
{
return l4_vcon_set_attr_u(vcon, attr, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_vcon_get_attr_u(l4_cap_idx_t vcon, l4_vcon_attr_t *attr,
l4_utcb_t *utcb) L4_NOTHROW
{
l4_msgtag_t res;
l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
mr->mr[0] = L4_VCON_GET_ATTR_OP;
res = l4_ipc_call(vcon, utcb,
l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
L4_IPC_NEVER);
if (l4_error_u(res, utcb) >= 0)
__builtin_memcpy(attr, &mr->mr[1], sizeof(*attr));
return res;
}
L4_INLINE l4_msgtag_t
l4_vcon_get_attr(l4_cap_idx_t vcon, l4_vcon_attr_t *attr) L4_NOTHROW
{
return l4_vcon_get_attr_u(vcon, attr, l4_utcb());
}
L4_INLINE void
l4_vcon_set_attr_raw(l4_vcon_attr_t *attr) L4_NOTHROW
{
attr->i_flags = 0;
attr->o_flags = 0;
attr->l_flags = 0;
}
#ifdef __cplusplus
inline void
l4_vcon_attr_t::set_raw()
{ l4_vcon_set_attr_raw(this); }
#endif
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
l4_ipc_send
l4_msgtag_t l4_ipc_send(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Send a message to an object (do not wait for a reply).
Definition ipc.h:586
l4_ipc_call
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition ipc.h:565
l4_error
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Get IPC error code if any or message tag label otherwise for an IPC call.
Definition ipc.h:646
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_has_error
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:440
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_MSGTAG_SCHEDULE
@ L4_MSGTAG_SCHEDULE
Enable schedule in IPC flag.
Definition types.h:114
L4_PROTO_LOG
@ L4_PROTO_LOG
Protocol for messages to a log object.
Definition types.h:55
L4_vcon_ops
L4_vcon_ops
Operations on vcon objects.
Definition vcon.h:292
L4_VCON_READ_OP
@ L4_VCON_READ_OP
Read.
Definition vcon.h:294
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_IPC_NEVER
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
l4_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
l4_vcon_send_u
l4_msgtag_t l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
Send data to this virtual console.
Definition vcon.h:302
l4_vcon_set_attr_raw
void l4_vcon_set_attr_raw(l4_vcon_attr_t *attr) L4_NOTHROW
Set terminal attributes to disable all special processing.
Definition vcon.h:441
l4_vcon_set_attr_u
l4_msgtag_t l4_vcon_set_attr_u(l4_cap_idx_t vcon, l4_vcon_attr_t const *attr, l4_utcb_t *utcb) L4_NOTHROW
Set the attributes of this virtual console.
Definition vcon.h:397
L4_vcon_o_flags
L4_vcon_o_flags
Output flags.
Definition vcon.h:220
l4_vcon_read
int l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
Read data from virtual console.
Definition vcon.h:391
l4_vcon_write_u
long l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
Write data to this virtual console.
Definition vcon.h:321
L4_vcon_l_flags
L4_vcon_l_flags
Local flags.
Definition vcon.h:231
l4_vcon_write
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition vcon.h:336
L4_vcon_i_flags
L4_vcon_i_flags
Input flags.
Definition vcon.h:209
l4_vcon_read_u
int l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
Read data from this virtual console.
Definition vcon.h:381
l4_vcon_send
l4_msgtag_t l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Send data to virtual console.
Definition vcon.h:315
L4_vcon_size_consts
L4_vcon_size_consts
Size constants.
Definition vcon.h:96
l4_vcon_set_attr
l4_msgtag_t l4_vcon_set_attr(l4_cap_idx_t vcon, l4_vcon_attr_t const *attr) L4_NOTHROW
Set attributes of a Vcon.
Definition vcon.h:411
l4_vcon_get_attr
l4_msgtag_t l4_vcon_get_attr(l4_cap_idx_t vcon, l4_vcon_attr_t *attr) L4_NOTHROW
Get attributes of a Vcon.
Definition vcon.h:435
l4_vcon_read_with_flags
int l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
Read data from virtual console, extended version including flags.
Definition vcon.h:375
l4_vcon_get_attr_u
l4_msgtag_t l4_vcon_get_attr_u(l4_cap_idx_t vcon, l4_vcon_attr_t *attr, l4_utcb_t *utcb) L4_NOTHROW
Get attributes of this virtual console.
Definition vcon.h:417
L4_VCON_ONLCR
@ L4_VCON_ONLCR
Translate NL to CR-NL.
Definition vcon.h:221
L4_VCON_OCRNL
@ L4_VCON_OCRNL
Translate CR to NL.
Definition vcon.h:222
L4_VCON_ONLRET
@ L4_VCON_ONLRET
Do not output CR.
Definition vcon.h:223
L4_VCON_ECHO
@ L4_VCON_ECHO
Echo input.
Definition vcon.h:233
L4_VCON_ICANON
@ L4_VCON_ICANON
Canonical mode.
Definition vcon.h:232
L4_VCON_INLCR
@ L4_VCON_INLCR
Translate NL to CR.
Definition vcon.h:210
L4_VCON_IGNCR
@ L4_VCON_IGNCR
Ignore CR.
Definition vcon.h:211
L4_VCON_ICRNL
@ L4_VCON_ICRNL
Translate CR to NL if L4_VCON_IGNCR is not set.
Definition vcon.h:212
L4_VCON_READ_SIZE
@ L4_VCON_READ_SIZE
Maximum size that can be read with one l4_vcon_read* call.
Definition vcon.h:100
L4_VCON_WRITE_SIZE
@ L4_VCON_WRITE_SIZE
Maximum size that can be written with one l4_vcon_write call.
Definition vcon.h:98
L4_NOTHROW
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:161
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
L4_LIKELY
#define L4_LIKELY(x)
Expression is likely to execute.
Definition compiler.h:283
ipc.h
Common IPC interface.
l4_msgtag_t
Message tag data structure.
Definition types.h:154
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::set_raw
void set_raw()
Set terminal attributes to disable all special processing.
Definition vcon.h:450
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_flags
L4_vcon_read_flags
Vcon read flags.
Definition vcon.h:171
L4_VCON_READ_STAT_DONE
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:174
L4_VCON_READ_STAT_BREAK
@ L4_VCON_READ_STAT_BREAK
Break condition flag.
Definition vcon.h:173
L4_VCON_READ_SIZE_MASK
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:172