L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vcon.h
Go to the documentation of this file.
1
5/*
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>,
8 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
9 * economic rights: Technische Universität Dresden (Germany)
10 *
11 * License: see LICENSE.spdx (in this directory or the directories above)
12 */
13#pragma once
14
15#include <l4/sys/ipc.h>
16
57l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
58
66l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
67
79L4_INLINE long
80l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
81
88L4_INLINE long
89l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
90
96{
98 L4_VCON_WRITE_SIZE = (L4_UTCB_GENERIC_DATA_SIZE - 2) * sizeof(l4_umword_t),
100 L4_VCON_READ_SIZE = (L4_UTCB_GENERIC_DATA_SIZE - 1) * sizeof(l4_umword_t),
101};
102
119L4_INLINE int
120l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
121
128L4_INLINE int
129l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
130
157L4_INLINE int
158l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
159
163L4_INLINE int
164l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
165 l4_utcb_t *utcb) L4_NOTHROW;
166
176
187typedef struct l4_vcon_attr_t
188{
192
193#ifdef __cplusplus
200 inline void set_raw();
201#endif
203
209{
210 L4_VCON_INLCR = 000100,
211 L4_VCON_IGNCR = 000200,
212 L4_VCON_ICRNL = 000400,
213};
214
220{
221 L4_VCON_ONLCR = 000004,
222 L4_VCON_OCRNL = 000010,
223 L4_VCON_ONLRET = 000040,
224};
225
231{
232 L4_VCON_ICANON = 000002,
233 L4_VCON_ECHO = 000010,
234};
235
246
255 l4_utcb_t *utcb) L4_NOTHROW;
256
267
276 l4_utcb_t *utcb) L4_NOTHROW;
277
283L4_INLINE void
285
286
298
299/******* Implementations ********************/
300
302l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
303{
304 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
305 mr->mr[0] = L4_VCON_WRITE_OP;
306 mr->mr[1] = size;
307 __builtin_memcpy(&mr->mr[2], buf, size);
308 return l4_ipc_send(vcon, utcb,
312}
313
315l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
316{
317 return l4_vcon_send_u(vcon, buf, size, l4_utcb());
318}
319
320L4_INLINE long
321l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
322{
323 l4_msgtag_t t;
324
325 if (size > L4_VCON_WRITE_SIZE)
326 size = L4_VCON_WRITE_SIZE;
327
328 t = l4_vcon_send_u(vcon, buf, size, utcb);
329 if (l4_msgtag_has_error(t))
330 return l4_error(t);
331
332 return (long) size;
333}
334
335L4_INLINE long
336l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
337{
338 return l4_vcon_write_u(vcon, buf, size, l4_utcb());
339}
340
341L4_INLINE int
342l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
343 l4_utcb_t *utcb) L4_NOTHROW
344{
345 int ret;
346 unsigned r;
347 l4_msg_regs_t *mr;
348
349 mr = l4_utcb_mr_u(utcb);
350 mr->mr[0] = (size << 16) | L4_VCON_READ_OP;
351
352 ret = l4_error_u(l4_ipc_call(vcon, utcb,
353 l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
355 utcb);
356 if (ret < 0)
357 return ret;
358
359 r = mr->mr[0] & L4_VCON_READ_SIZE_MASK;
360
361 if (!(mr->mr[0] & L4_VCON_READ_STAT_DONE)) // !eof
362 ret = size + 1;
363 else if (r < size)
364 ret = r;
365 else
366 ret = size;
367
368 if (L4_LIKELY(buf != NULL))
369 __builtin_memcpy(buf, &mr->mr[1], r < size ? r : size);
370
371 return ret | (mr->mr[0] & ~(L4_VCON_READ_STAT_DONE | L4_VCON_READ_SIZE_MASK));
372}
373
374L4_INLINE int
375l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
376{
377 return l4_vcon_read_with_flags_u(vcon, buf, size, l4_utcb());
378}
379
380L4_INLINE int
381l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
382{
383 int r = l4_vcon_read_with_flags_u(vcon, buf, size, utcb);
384 if (r < 0)
385 return r;
386
387 return r & L4_VCON_READ_SIZE_MASK;
388}
389
390L4_INLINE int
391l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
392{
393 return l4_vcon_read_u(vcon, buf, size, l4_utcb());
394}
395
398 l4_utcb_t *utcb) L4_NOTHROW
399{
400 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
401
402 mr->mr[0] = L4_VCON_SET_ATTR_OP;
403 __builtin_memcpy(&mr->mr[1], attr, sizeof(*attr));
404
405 return l4_ipc_call(vcon, utcb,
406 l4_msgtag(L4_PROTO_LOG, 4, 0, 0),
408}
409
412{
413 return l4_vcon_set_attr_u(vcon, attr, l4_utcb());
414}
415
418 l4_utcb_t *utcb) L4_NOTHROW
419{
420 l4_msgtag_t res;
421 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
422
423 mr->mr[0] = L4_VCON_GET_ATTR_OP;
424
425 res = l4_ipc_call(vcon, utcb,
426 l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
428 if (l4_error_u(res, utcb) >= 0)
429 __builtin_memcpy(attr, &mr->mr[1], sizeof(*attr));
430
431 return res;
432}
433
436{
437 return l4_vcon_get_attr_u(vcon, attr, l4_utcb());
438}
439
440L4_INLINE void
442{
443 attr->i_flags = 0;
444 attr->o_flags = 0;
445 attr->l_flags = 0;
446}
447
448#ifdef __cplusplus
449inline void
452#endif
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
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_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
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
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
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:439
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_MSGTAG_SCHEDULE
Enable schedule in IPC flag.
Definition types.h:113
@ L4_PROTO_LOG
Protocol for messages to a log object.
Definition types.h:54
L4_vcon_ops
Operations on vcon objects.
Definition vcon.h:292
@ 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
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
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
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_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
Output flags.
Definition vcon.h:220
int l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
Read data from virtual console.
Definition vcon.h:391
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
Local flags.
Definition vcon.h:231
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
Input flags.
Definition vcon.h:209
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_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
Size constants.
Definition vcon.h:96
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_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
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_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
Translate NL to CR-NL.
Definition vcon.h:221
@ L4_VCON_OCRNL
Translate CR to NL.
Definition vcon.h:222
@ L4_VCON_ONLRET
Do not output CR.
Definition vcon.h:223
@ L4_VCON_ECHO
Echo input.
Definition vcon.h:233
@ L4_VCON_ICANON
Canonical mode.
Definition vcon.h:232
@ L4_VCON_INLCR
Translate NL to CR.
Definition vcon.h:210
@ L4_VCON_IGNCR
Ignore CR.
Definition vcon.h:211
@ L4_VCON_ICRNL
Translate CR to NL if L4_VCON_IGNCR is not set.
Definition vcon.h:212
@ L4_VCON_READ_SIZE
Maximum size that can be read with one l4_vcon_read* call.
Definition vcon.h:100
@ L4_VCON_WRITE_SIZE
Maximum size that can be written with one l4_vcon_write call.
Definition vcon.h:98
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:159
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define L4_LIKELY(x)
Expression is likely to execute.
Definition compiler.h:274
Message tag data structure.
Definition types.h:153
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
void set_raw()
Set terminal attributes to disable all special processing.
Definition vcon.h:450
l4_umword_t l_flags
local flags
Definition vcon.h:191
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_flags
Vcon read flags.
Definition vcon.h:171
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:174
@ L4_VCON_READ_STAT_BREAK
Break condition flag.
Definition vcon.h:173
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:172