L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
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 * This file is part of TUD:OS and distributed under the terms of the
12 * GNU General Public License 2.
13 * Please see the COPYING-GPL-2 file for details.
14 *
15 * As a special exception, you may use this file as part of a free software
16 * library without restriction. Specifically, if other files instantiate
17 * templates or use macros or inline functions from this file, or you compile
18 * this file and link it with other files to produce an executable, this
19 * file does not by itself cause the resulting executable to be covered by
20 * the GNU General Public License. This exception does not however
21 * invalidate any other reasons why the executable file might be covered by
22 * the GNU General Public License.
23 */
24#pragma once
25
26#include <l4/sys/ipc.h>
27
68l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
69
77l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
78
90L4_INLINE long
91l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
92
99L4_INLINE long
100l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
101
107{
109 L4_VCON_WRITE_SIZE = (L4_UTCB_GENERIC_DATA_SIZE - 2) * sizeof(l4_umword_t),
111 L4_VCON_READ_SIZE = (L4_UTCB_GENERIC_DATA_SIZE - 1) * sizeof(l4_umword_t),
112};
113
129L4_INLINE int
130l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
131
138L4_INLINE int
139l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
140
166L4_INLINE int
167l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
168
172L4_INLINE int
173l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
174 l4_utcb_t *utcb) L4_NOTHROW;
175
185
196typedef struct l4_vcon_attr_t
197{
201
202#ifdef __cplusplus
209 inline void set_raw();
210#endif
212
218{
219 L4_VCON_INLCR = 000100,
220 L4_VCON_IGNCR = 000200,
221 L4_VCON_ICRNL = 000400,
222};
223
229{
230 L4_VCON_ONLCR = 000004,
231 L4_VCON_OCRNL = 000010,
232 L4_VCON_ONLRET = 000040,
233};
234
240{
241 L4_VCON_ICANON = 000002,
242 L4_VCON_ECHO = 000010,
243};
244
255
264 l4_utcb_t *utcb) L4_NOTHROW;
265
276
285 l4_utcb_t *utcb) L4_NOTHROW;
286
292L4_INLINE void
294
295
307
308/******* Implementations ********************/
309
311l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
312{
313 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
314 mr->mr[0] = L4_VCON_WRITE_OP;
315 mr->mr[1] = size;
316 __builtin_memcpy(&mr->mr[2], buf, size);
317 return l4_ipc_send(vcon, utcb,
321}
322
324l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
325{
326 return l4_vcon_send_u(vcon, buf, size, l4_utcb());
327}
328
329L4_INLINE long
330l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
331{
332 l4_msgtag_t t;
333
334 if (size > L4_VCON_WRITE_SIZE)
335 size = L4_VCON_WRITE_SIZE;
336
337 t = l4_vcon_send_u(vcon, buf, size, utcb);
338 if (l4_msgtag_has_error(t))
339 return l4_error(t);
340
341 return (long) size;
342}
343
344L4_INLINE long
345l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
346{
347 return l4_vcon_write_u(vcon, buf, size, l4_utcb());
348}
349
350L4_INLINE int
351l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
352 l4_utcb_t *utcb) L4_NOTHROW
353{
354 int ret;
355 unsigned r;
356 l4_msg_regs_t *mr;
357
358 mr = l4_utcb_mr_u(utcb);
359 mr->mr[0] = (size << 16) | L4_VCON_READ_OP;
360
361 ret = l4_error_u(l4_ipc_call(vcon, utcb,
362 l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
364 utcb);
365 if (ret < 0)
366 return ret;
367
368 r = mr->mr[0] & L4_VCON_READ_SIZE_MASK;
369
370 if (!(mr->mr[0] & L4_VCON_READ_STAT_DONE)) // !eof
371 ret = size + 1;
372 else if (r < size)
373 ret = r;
374 else
375 ret = size;
376
377 if (L4_LIKELY(buf != NULL))
378 __builtin_memcpy(buf, &mr->mr[1], r < size ? r : size);
379
380 return ret | (mr->mr[0] & ~(L4_VCON_READ_STAT_DONE | L4_VCON_READ_SIZE_MASK));
381}
382
383L4_INLINE int
384l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
385{
386 return l4_vcon_read_with_flags_u(vcon, buf, size, l4_utcb());
387}
388
389L4_INLINE int
390l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
391{
392 int r = l4_vcon_read_with_flags_u(vcon, buf, size, utcb);
393 if (r < 0)
394 return r;
395
396 return r & L4_VCON_READ_SIZE_MASK;
397}
398
399L4_INLINE int
400l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
401{
402 return l4_vcon_read_u(vcon, buf, size, l4_utcb());
403}
404
407 l4_utcb_t *utcb) L4_NOTHROW
408{
409 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
410
411 mr->mr[0] = L4_VCON_SET_ATTR_OP;
412 __builtin_memcpy(&mr->mr[1], attr, sizeof(*attr));
413
414 return l4_ipc_call(vcon, utcb,
415 l4_msgtag(L4_PROTO_LOG, 4, 0, 0),
417}
418
421{
422 return l4_vcon_set_attr_u(vcon, attr, l4_utcb());
423}
424
427 l4_utcb_t *utcb) L4_NOTHROW
428{
429 l4_msgtag_t res;
430 l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
431
432 mr->mr[0] = L4_VCON_GET_ATTR_OP;
433
434 res = l4_ipc_call(vcon, utcb,
435 l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
437 if (l4_error_u(res, utcb) >= 0)
438 __builtin_memcpy(attr, &mr->mr[1], sizeof(*attr));
439
440 return res;
441}
442
445{
446 return l4_vcon_get_attr_u(vcon, attr, l4_utcb());
447}
448
449L4_INLINE void
451{
452 attr->i_flags = 0;
453 attr->o_flags = 0;
454 attr->l_flags = 0;
455}
456
457#ifdef __cplusplus
458inline void
461#endif
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:358
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:575
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:550
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:636
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:485
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:456
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:427
@ L4_MSGTAG_SCHEDULE
Enable schedule in IPC flag.
Definition types.h:123
@ L4_PROTO_LOG
Protocol for messages to a log object.
Definition types.h:65
L4_vcon_ops
Operations on vcon objects.
Definition vcon.h:301
@ L4_VCON_READ_OP
Read.
Definition vcon.h:303
@ L4_VCON_GET_ATTR_OP
Set console attributes.
Definition vcon.h:305
@ L4_VCON_SET_ATTR_OP
Get console attributes.
Definition vcon.h:304
@ L4_VCON_WRITE_OP
Write.
Definition vcon.h:302
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:82
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
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:311
void l4_vcon_set_attr_raw(l4_vcon_attr_t *attr) L4_NOTHROW
Set terminal attributes to disable all special processing.
Definition vcon.h:450
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:406
L4_vcon_o_flags
Output flags.
Definition vcon.h:229
int l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
Read data from virtual console.
Definition vcon.h:400
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:330
L4_vcon_l_flags
Local flags.
Definition vcon.h:240
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition vcon.h:345
L4_vcon_i_flags
Input flags.
Definition vcon.h:218
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:390
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:324
L4_vcon_size_consts
Size constants.
Definition vcon.h:107
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:420
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:444
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:384
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:426
@ L4_VCON_ONLCR
Translate NL to CR-NL.
Definition vcon.h:230
@ L4_VCON_OCRNL
Translate CR to NL.
Definition vcon.h:231
@ L4_VCON_ONLRET
Do not output CR.
Definition vcon.h:232
@ L4_VCON_ECHO
Echo input.
Definition vcon.h:242
@ L4_VCON_ICANON
Canonical mode.
Definition vcon.h:241
@ L4_VCON_INLCR
Translate NL to CR.
Definition vcon.h:219
@ L4_VCON_IGNCR
Ignore CR.
Definition vcon.h:220
@ L4_VCON_ICRNL
Translate CR to NL if L4_VCON_IGNCR is not set.
Definition vcon.h:221
@ L4_VCON_READ_SIZE
Maximum size that can be read with one l4_vcon_read* call.
Definition vcon.h:111
@ L4_VCON_WRITE_SIZE
Maximum size that can be written with one l4_vcon_write call.
Definition vcon.h:109
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:188
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
#define L4_LIKELY(x)
Expression is likely to execute.
Definition compiler.h:284
Message tag data structure.
Definition types.h:163
Vcon attribute structure.
Definition vcon.h:197
l4_umword_t i_flags
input flags
Definition vcon.h:198
l4_umword_t o_flags
output flags
Definition vcon.h:199
void set_raw()
Set terminal attributes to disable all special processing.
Definition vcon.h:459
l4_umword_t l_flags
local flags
Definition vcon.h:200
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:79
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:80
L4_vcon_read_flags
Vcon read flags.
Definition vcon.h:180
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition vcon.h:183
@ L4_VCON_READ_STAT_BREAK
Break condition flag.
Definition vcon.h:182
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition vcon.h:181