L4Re - L4 Runtime Environment
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 
56 L4_INLINE l4_msgtag_t
57 l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
58 
65 L4_INLINE l4_msgtag_t
66 l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
67 
79 L4_INLINE long
80 l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW;
81 
88 L4_INLINE long
89 l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
90 
96 {
101 };
102 
118 L4_INLINE int
119 l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
120 
127 L4_INLINE int
128 l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW;
129 
154 L4_INLINE int
155 l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW;
156 
160 L4_INLINE int
161 l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
162  l4_utcb_t *utcb) L4_NOTHROW;
163 
168 {
169  L4_VCON_READ_SIZE_MASK = 0x3fffffff,
172 };
173 
178 typedef struct l4_vcon_attr_t
179 {
184 
190 {
191  L4_VCON_INLCR = 000100,
192  L4_VCON_IGNCR = 000200,
193  L4_VCON_ICRNL = 000400,
194 };
195 
201 {
202  L4_VCON_ONLCR = 000004,
203  L4_VCON_OCRNL = 000010,
204  L4_VCON_ONLRET = 000040,
205 };
206 
212 {
213  L4_VCON_ICANON = 000002,
214  L4_VCON_ECHO = 000010,
215 };
216 
225 L4_INLINE l4_msgtag_t
227 
234 L4_INLINE l4_msgtag_t
236  l4_utcb_t *utcb) L4_NOTHROW;
237 
246 L4_INLINE l4_msgtag_t
248 
255 L4_INLINE l4_msgtag_t
257  l4_utcb_t *utcb) L4_NOTHROW;
258 
259 
265 {
270 };
271 
272 /******* Implementations ********************/
273 
274 L4_INLINE l4_msgtag_t
275 l4_vcon_send_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
276 {
277  l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
278  mr->mr[0] = L4_VCON_WRITE_OP;
279  mr->mr[1] = size;
280  __builtin_memcpy(&mr->mr[2], buf, size);
281  return l4_ipc_send(vcon, utcb,
283  2 + (size + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t),
284  0, L4_MSGTAG_SCHEDULE),
285  L4_IPC_NEVER);
286 }
287 
288 L4_INLINE l4_msgtag_t
289 l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
290 {
291  return l4_vcon_send_u(vcon, buf, size, l4_utcb());
292 }
293 
294 L4_INLINE long
295 l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
296 {
297  l4_msgtag_t t;
298 
299  if (size > L4_VCON_WRITE_SIZE)
300  size = L4_VCON_WRITE_SIZE;
301 
302  t = l4_vcon_send_u(vcon, buf, size, utcb);
303  if (l4_msgtag_has_error(t))
304  return l4_error(t);
305 
306  return (long) size;
307 }
308 
309 L4_INLINE long
310 l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
311 {
312  return l4_vcon_write_u(vcon, buf, size, l4_utcb());
313 }
314 
315 L4_INLINE int
316 l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
317  l4_utcb_t *utcb) L4_NOTHROW
318 {
319  int ret;
320  unsigned r;
321  l4_msg_regs_t *mr;
322 
323  mr = l4_utcb_mr_u(utcb);
324  mr->mr[0] = (size << 16) | L4_VCON_READ_OP;
325 
326  ret = l4_error_u(l4_ipc_call(vcon, utcb,
327  l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
328  L4_IPC_NEVER),
329  utcb);
330  if (ret < 0)
331  return ret;
332 
333  r = mr->mr[0] & L4_VCON_READ_SIZE_MASK;
334 
335  if (!(mr->mr[0] & L4_VCON_READ_STAT_DONE)) // !eof
336  ret = size + 1;
337  else if (r < size)
338  ret = r;
339  else
340  ret = size;
341 
342  if (L4_LIKELY(buf != NULL))
343  __builtin_memcpy(buf, &mr->mr[1], r < size ? r : size);
344 
345  return ret | (mr->mr[0] & ~(L4_VCON_READ_STAT_DONE | L4_VCON_READ_SIZE_MASK));
346 }
347 
348 L4_INLINE int
349 l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
350 {
351  return l4_vcon_read_with_flags_u(vcon, buf, size, l4_utcb());
352 }
353 
354 L4_INLINE int
355 l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
356 {
357  int r = l4_vcon_read_with_flags_u(vcon, buf, size, utcb);
358  if (r < 0)
359  return r;
360 
361  return r & L4_VCON_READ_SIZE_MASK;
362 }
363 
364 L4_INLINE int
365 l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
366 {
367  return l4_vcon_read_u(vcon, buf, size, l4_utcb());
368 }
369 
370 L4_INLINE l4_msgtag_t
372  l4_utcb_t *utcb) L4_NOTHROW
373 {
374  l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
375 
376  mr->mr[0] = L4_VCON_SET_ATTR_OP;
377  __builtin_memcpy(&mr->mr[1], attr, sizeof(*attr));
378 
379  return l4_ipc_call(vcon, utcb,
380  l4_msgtag(L4_PROTO_LOG, 4, 0, 0),
381  L4_IPC_NEVER);
382 }
383 
384 L4_INLINE l4_msgtag_t
385 l4_vcon_set_attr(l4_cap_idx_t vcon, l4_vcon_attr_t const *attr) L4_NOTHROW
386 {
387  return l4_vcon_set_attr_u(vcon, attr, l4_utcb());
388 }
389 
390 L4_INLINE l4_msgtag_t
392  l4_utcb_t *utcb) L4_NOTHROW
393 {
394  l4_msgtag_t res;
395  l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
396 
397  mr->mr[0] = L4_VCON_GET_ATTR_OP;
398 
399  res = l4_ipc_call(vcon, utcb,
400  l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
401  L4_IPC_NEVER);
402  if (l4_error_u(res, utcb) >= 0)
403  __builtin_memcpy(attr, &mr->mr[1], sizeof(*attr));
404 
405  return res;
406 }
407 
408 L4_INLINE l4_msgtag_t
410 {
411  return l4_vcon_get_attr_u(vcon, attr, l4_utcb());
412 }
Write.
Definition: vcon.h:266
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Protocol for messages to a log object.
Definition: types.h:65
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:295
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:371
Total number of message register (MRs) available.
Definition: utcb.h:47
Translate NL to CR-NL.
Definition: vcon.h:202
Translate NL to CR.
Definition: vcon.h:191
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:349
L4_vcon_ops
Operations on vcon objects.
Definition: vcon.h:264
Vcon attribute structure.
Definition: vcon.h:178
L4_vcon_o_flags
Output flags.
Definition: vcon.h:200
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition: types.h:436
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:409
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:385
l4_umword_t o_flags
output flags
Definition: vcon.h:181
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
Get console attributes.
Definition: vcon.h:268
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:445
int l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
Read data from virtual console.
Definition: vcon.h:365
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
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:289
L4_vcon_size_consts
Size constants.
Definition: vcon.h:95
Read.
Definition: vcon.h:267
Do not output CR.
Definition: vcon.h:204
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
#define L4_IPC_NEVER
never timeout
Definition: __timeout.h:80
L4_vcon_l_flags
Local flags.
Definition: vcon.h:211
Canonical mode.
Definition: vcon.h:213
Enable schedule in IPC flag.
Definition: types.h:123
Maximum size that can be written with one l4_vcon_write call.
Definition: vcon.h:98
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition: vcon.h:310
Translate CR to NL.
Definition: vcon.h:203
Size mask.
Definition: vcon.h:169
Ignore CR.
Definition: vcon.h:192
Translate CR to NL if L4_VCON_IGNCR is not set.
Definition: vcon.h:193
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
Done condition flag.
Definition: vcon.h:171
l4_umword_t l_flags
local flags
Definition: vcon.h:182
Maximum size that can be read with one l4_vcon_read* call.
Definition: vcon.h:100
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:275
L4_vcon_i_flags
Input flags.
Definition: vcon.h:189
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
#define L4_LIKELY(x)
Expression is likely to execute.
Definition: compiler.h:233
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:408
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:470
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:391
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag.
Definition: ipc.h:517
Set console attributes.
Definition: vcon.h:269
l4_umword_t i_flags
input flags
Definition: vcon.h:180
struct l4_vcon_attr_t l4_vcon_attr_t
Vcon attribute structure.
L4_vcon_read_flags
Vcon read flags.
Definition: vcon.h:167
Message tag data structure.
Definition: types.h:159
Echo input.
Definition: vcon.h:214
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:355
Break condition flag.
Definition: vcon.h:170
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185