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
118L4_INLINE int
119l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
120
127L4_INLINE int
128l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
129
155L4_INLINE int
156l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
157
161L4_INLINE int
162l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
163 l4_utcb_t *utcb) L4_NOTHROW;
164
174
185typedef struct l4_vcon_attr_t
186{
190
191#ifdef __cplusplus
198 inline void set_raw();
199#endif
201
207{
208 L4_VCON_INLCR = 000100,
209 L4_VCON_IGNCR = 000200,
210 L4_VCON_ICRNL = 000400,
211};
212
218{
219 L4_VCON_ONLCR = 000004,
220 L4_VCON_OCRNL = 000010,
221 L4_VCON_ONLRET = 000040,
222};
223
229{
230 L4_VCON_ICANON = 000002,
231 L4_VCON_ECHO = 000010,
232};
233
244
253 l4_utcb_t *utcb) L4_NOTHROW;
254
265
274 l4_utcb_t *utcb) L4_NOTHROW;
275
281L4_INLINE void
283
284
296
297/******* Implementations ********************/
298
300l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
301{
302 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
303 mr->mr[0] = L4_VCON_WRITE_OP;
304 mr->mr[1] = size;
305 __builtin_memcpy(&mr->mr[2], buf, size);
306 return l4_ipc_send(vcon, utcb,
310}
311
313l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
314{
315 return l4_vcon_send_u(vcon, buf, size, l4_utcb());
316}
317
318L4_INLINE long
319l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
320{
321 l4_msgtag_t t;
322
323 if (size > L4_VCON_WRITE_SIZE)
324 size = L4_VCON_WRITE_SIZE;
325
326 t = l4_vcon_send_u(vcon, buf, size, utcb);
327 if (l4_msgtag_has_error(t))
328 return l4_error(t);
329
330 return (long) size;
331}
332
333L4_INLINE long
334l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
335{
336 return l4_vcon_write_u(vcon, buf, size, l4_utcb());
337}
338
339L4_INLINE int
340l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
341 l4_utcb_t *utcb) L4_NOTHROW
342{
343 int ret;
344 unsigned r;
345 l4_msg_regs_t *mr;
346
347 mr = l4_utcb_mr_u(utcb);
348 mr->mr[0] = (size << 16) | L4_VCON_READ_OP;
349
350 ret = l4_error_u(l4_ipc_call(vcon, utcb,
351 l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
353 utcb);
354 if (ret < 0)
355 return ret;
356
357 r = mr->mr[0] & L4_VCON_READ_SIZE_MASK;
358
359 if (!(mr->mr[0] & L4_VCON_READ_STAT_DONE)) // !eof
360 ret = size + 1;
361 else if (r < size)
362 ret = r;
363 else
364 ret = size;
365
366 if (L4_LIKELY(buf != NULL))
367 __builtin_memcpy(buf, &mr->mr[1], r < size ? r : size);
368
369 return ret | (mr->mr[0] & ~(L4_VCON_READ_STAT_DONE | L4_VCON_READ_SIZE_MASK));
370}
371
372L4_INLINE int
373l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
374{
375 return l4_vcon_read_with_flags_u(vcon, buf, size, l4_utcb());
376}
377
378L4_INLINE int
379l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
380{
381 int r = l4_vcon_read_with_flags_u(vcon, buf, size, utcb);
382 if (r < 0)
383 return r;
384
385 return r & L4_VCON_READ_SIZE_MASK;
386}
387
388L4_INLINE int
389l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
390{
391 return l4_vcon_read_u(vcon, buf, size, l4_utcb());
392}
393
396 l4_utcb_t *utcb) L4_NOTHROW
397{
398 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
399
400 mr->mr[0] = L4_VCON_SET_ATTR_OP;
401 __builtin_memcpy(&mr->mr[1], attr, sizeof(*attr));
402
403 return l4_ipc_call(vcon, utcb,
404 l4_msgtag(L4_PROTO_LOG, 4, 0, 0),
406}
407
410{
411 return l4_vcon_set_attr_u(vcon, attr, l4_utcb());
412}
413
416 l4_utcb_t *utcb) L4_NOTHROW
417{
418 l4_msgtag_t res;
419 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
420
421 mr->mr[0] = L4_VCON_GET_ATTR_OP;
422
423 res = l4_ipc_call(vcon, utcb,
424 l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
426 if (l4_error_u(res, utcb) >= 0)
427 __builtin_memcpy(attr, &mr->mr[1], sizeof(*attr));
428
429 return res;
430}
431
434{
435 return l4_vcon_get_attr_u(vcon, attr, l4_utcb());
436}
437
438L4_INLINE void
440{
441 attr->i_flags = 0;
442 attr->o_flags = 0;
443 attr->l_flags = 0;
444}
445
446#ifdef __cplusplus
447inline void
450#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:500
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:290
@ L4_VCON_READ_OP
Read.
Definition vcon.h:292
@ 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
#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:300
void l4_vcon_set_attr_raw(l4_vcon_attr_t *attr) L4_NOTHROW
Set terminal attributes to disable all special processing.
Definition vcon.h:439
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:395
L4_vcon_o_flags
Output flags.
Definition vcon.h:218
int l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
Read data from virtual console.
Definition vcon.h:389
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:319
L4_vcon_l_flags
Local flags.
Definition vcon.h:229
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition vcon.h:334
L4_vcon_i_flags
Input flags.
Definition vcon.h:207
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:379
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:313
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:409
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:433
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:373
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:415
@ L4_VCON_ONLCR
Translate NL to CR-NL.
Definition vcon.h:219
@ L4_VCON_OCRNL
Translate CR to NL.
Definition vcon.h:220
@ L4_VCON_ONLRET
Do not output CR.
Definition vcon.h:221
@ L4_VCON_ECHO
Echo input.
Definition vcon.h:231
@ L4_VCON_ICANON
Canonical mode.
Definition vcon.h:230
@ L4_VCON_INLCR
Translate NL to CR.
Definition vcon.h:208
@ L4_VCON_IGNCR
Ignore CR.
Definition vcon.h:209
@ L4_VCON_ICRNL
Translate CR to NL if L4_VCON_IGNCR is not set.
Definition vcon.h:210
@ 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:186
l4_umword_t i_flags
input flags
Definition vcon.h:187
l4_umword_t o_flags
output flags
Definition vcon.h:188
void set_raw()
Set terminal attributes to disable all special processing.
Definition vcon.h:448
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_flags
Vcon read flags.
Definition vcon.h:169
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:172
@ L4_VCON_READ_STAT_BREAK
Break condition flag.
Definition vcon.h:171
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:170