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  0, L4_MSGTAG_SCHEDULE),
284  L4_IPC_NEVER);
285 }
286 
287 L4_INLINE l4_msgtag_t
288 l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
289 {
290  return l4_vcon_send_u(vcon, buf, size, l4_utcb());
291 }
292 
293 L4_INLINE long
294 l4_vcon_write_u(l4_cap_idx_t vcon, char const *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
295 {
296  l4_msgtag_t t;
297 
298  if (size > L4_VCON_WRITE_SIZE)
299  size = L4_VCON_WRITE_SIZE;
300 
301  t = l4_vcon_send_u(vcon, buf, size, utcb);
302  if (l4_msgtag_has_error(t))
303  return l4_error(t);
304 
305  return (long) size;
306 }
307 
308 L4_INLINE long
309 l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
310 {
311  return l4_vcon_write_u(vcon, buf, size, l4_utcb());
312 }
313 
314 L4_INLINE int
315 l4_vcon_read_with_flags_u(l4_cap_idx_t vcon, char *buf, unsigned size,
316  l4_utcb_t *utcb) L4_NOTHROW
317 {
318  int ret;
319  unsigned r;
320  l4_msg_regs_t *mr;
321 
322  mr = l4_utcb_mr_u(utcb);
323  mr->mr[0] = (size << 16) | L4_VCON_READ_OP;
324 
325  ret = l4_error_u(l4_ipc_call(vcon, utcb,
326  l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
327  L4_IPC_NEVER),
328  utcb);
329  if (ret < 0)
330  return ret;
331 
332  r = mr->mr[0] & L4_VCON_READ_SIZE_MASK;
333 
334  if (!(mr->mr[0] & L4_VCON_READ_STAT_DONE)) // !eof
335  ret = size + 1;
336  else if (r < size)
337  ret = r;
338  else
339  ret = size;
340 
341  if (L4_LIKELY(buf != NULL))
342  __builtin_memcpy(buf, &mr->mr[1], r < size ? r : size);
343 
344  return ret | (mr->mr[0] & ~(L4_VCON_READ_STAT_DONE | L4_VCON_READ_SIZE_MASK));
345 }
346 
347 L4_INLINE int
348 l4_vcon_read_with_flags(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
349 {
350  return l4_vcon_read_with_flags_u(vcon, buf, size, l4_utcb());
351 }
352 
353 L4_INLINE int
354 l4_vcon_read_u(l4_cap_idx_t vcon, char *buf, unsigned size, l4_utcb_t *utcb) L4_NOTHROW
355 {
356  int r = l4_vcon_read_with_flags_u(vcon, buf, size, utcb);
357  if (r < 0)
358  return r;
359 
360  return r & L4_VCON_READ_SIZE_MASK;
361 }
362 
363 L4_INLINE int
364 l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
365 {
366  return l4_vcon_read_u(vcon, buf, size, l4_utcb());
367 }
368 
369 L4_INLINE l4_msgtag_t
371  l4_utcb_t *utcb) L4_NOTHROW
372 {
373  l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
374 
375  mr->mr[0] = L4_VCON_SET_ATTR_OP;
376  __builtin_memcpy(&mr->mr[1], attr, sizeof(*attr));
377 
378  return l4_ipc_call(vcon, utcb,
379  l4_msgtag(L4_PROTO_LOG, 4, 0, 0),
380  L4_IPC_NEVER);
381 }
382 
383 L4_INLINE l4_msgtag_t
385 {
386  return l4_vcon_set_attr_u(vcon, attr, l4_utcb());
387 }
388 
389 L4_INLINE l4_msgtag_t
391  l4_utcb_t *utcb) L4_NOTHROW
392 {
393  l4_msgtag_t res;
394  l4_msg_regs_t *mr = l4_utcb_mr_u(utcb);
395 
396  mr->mr[0] = L4_VCON_GET_ATTR_OP;
397 
398  res = l4_ipc_call(vcon, utcb,
399  l4_msgtag(L4_PROTO_LOG, 1, 0, 0),
400  L4_IPC_NEVER);
401  if (l4_error_u(res, utcb) >= 0)
402  __builtin_memcpy(attr, &mr->mr[1], sizeof(*attr));
403 
404  return res;
405 }
406 
407 L4_INLINE l4_msgtag_t
409 {
410  return l4_vcon_get_attr_u(vcon, attr, l4_utcb());
411 }
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:186
#define L4_LIKELY(x)
Expression is likely to execute.
Definition: compiler.h:237
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:51
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
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:488
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:463
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag or the tag label.
Definition: ipc.h:535
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:412
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition: types.h:437
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_PROTO_LOG
Protocol for messages to a log object.
Definition: types.h:65
@ L4_MSGTAG_SCHEDULE
Enable schedule in IPC flag.
Definition: types.h:123
L4_vcon_ops
Operations on vcon objects.
Definition: vcon.h:265
@ L4_VCON_READ_OP
Read.
Definition: vcon.h:267
@ L4_VCON_GET_ATTR_OP
Set console attributes.
Definition: vcon.h:269
@ L4_VCON_SET_ATTR_OP
Get console attributes.
Definition: vcon.h:268
@ L4_VCON_WRITE_OP
Write.
Definition: vcon.h:266
@ L4_UTCB_GENERIC_DATA_SIZE
Total number of message register (MRs) available.
Definition: utcb.h:47
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:275
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:370
L4_vcon_o_flags
Output flags.
Definition: vcon.h:201
int l4_vcon_read(l4_cap_idx_t vcon, char *buf, unsigned size) L4_NOTHROW
Read data from virtual console.
Definition: vcon.h:364
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:294
L4_vcon_l_flags
Local flags.
Definition: vcon.h:212
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition: vcon.h:309
L4_vcon_i_flags
Input flags.
Definition: vcon.h:190
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:354
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:288
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:384
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:408
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:348
struct l4_vcon_attr_t l4_vcon_attr_t
Vcon attribute structure.
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:390
@ L4_VCON_ONLCR
Translate NL to CR-NL.
Definition: vcon.h:202
@ L4_VCON_OCRNL
Translate CR to NL.
Definition: vcon.h:203
@ L4_VCON_ONLRET
Do not output CR.
Definition: vcon.h:204
@ L4_VCON_ECHO
Echo input.
Definition: vcon.h:214
@ L4_VCON_ICANON
Canonical mode.
Definition: vcon.h:213
@ L4_VCON_INLCR
Translate NL to CR.
Definition: vcon.h:191
@ L4_VCON_IGNCR
Ignore CR.
Definition: vcon.h:192
@ L4_VCON_ICRNL
Translate CR to NL if L4_VCON_IGNCR is not set.
Definition: vcon.h:193
@ 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
Message tag data structure.
Definition: types.h:160
Vcon attribute structure.
Definition: vcon.h:179
l4_umword_t i_flags
input flags
Definition: vcon.h:180
l4_umword_t o_flags
output flags
Definition: vcon.h:181
l4_umword_t l_flags
local flags
Definition: vcon.h:182
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:168
@ L4_VCON_READ_STAT_DONE
Done condition flag.
Definition: vcon.h:171
@ L4_VCON_READ_STAT_BREAK
Break condition flag.
Definition: vcon.h:170
@ L4_VCON_READ_SIZE_MASK
Size mask.
Definition: vcon.h:169