L4Re - L4 Runtime Environment
util.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  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU Lesser General Public License 2.1.
12  * Please see the COPYING-LGPL-2.1 file for details.
13  */
14 #ifndef __UTIL_H
15 #define __UTIL_H
16 
17 #include <l4/sys/types.h>
18 #include <l4/sys/compiler.h>
19 #include <l4/sys/ipc.h>
20 
22 
30 
34 L4_CV void l4_sleep(int ms) L4_NOTHROW;
35 
36 /* Suspend thread for a period of \a us microseconds.
37  * \param us Time in microseconds
38  * WARNING: This function is mostly bogus since the timer resolution of
39  * current L4 implementations is about 1ms! */
40 L4_CV void l4_usleep(int us) L4_NOTHROW;
41 
47 L4_INLINE void l4_sleep_forever(void) L4_NOTHROW __attribute__((noreturn));
48 
49 L4_INLINE void
51 {
52  for (;;)
54 }
55 
57 static inline void
58 l4_touch_ro(const void*addr, unsigned size) L4_NOTHROW
59 {
60  const char *bptr, *eptr;
61 
62  bptr = (const char*)(((l4_addr_t)addr) & L4_PAGEMASK);
63  eptr = (const char*)(((l4_addr_t)addr+size-1) & L4_PAGEMASK);
64  for(;bptr<=eptr;bptr+=L4_PAGESIZE){
65  asm volatile("or %0,%%rax \n"
66  :
67  : "m" (*(const unsigned*)bptr)
68  : "rax" );
69  }
70 }
71 
72 
74 static inline void
75 l4_touch_rw(const void*addr, unsigned size) L4_NOTHROW
76 {
77  const char *bptr, *eptr;
78 
79  bptr = (const char*)(((l4_addr_t)addr) & L4_PAGEMASK);
80  eptr = (const char*)(((l4_addr_t)addr+size-1) & L4_PAGEMASK);
81  for(;bptr<=eptr;bptr+=L4_PAGESIZE){
82  asm volatile("orb $0,%0 \n"
83  :
84  : "m" (*(const unsigned*)bptr)
85  );
86  }
87 }
88 
90 
91 #endif
92 
l4_timeout_s l4util_micros2l4to(unsigned int mus) L4_NOTHROW
Calculate l4 timeouts.
Common L4 ABI Data Types.
#define EXTERN_C_END
End section with C types and functions.
Definition: compiler.h:187
#define L4_PAGEMASK
Mask for the page number.
Definition: consts.h:286
#define L4_IPC_NEVER
never timeout
Definition: __timeout.h:80
void l4_touch_ro(const void *addr, unsigned size) L4_NOTHROW
Touch data area to force mapping (read-only)
Definition: util.h:94
L4 compiler related defines.
void l4_usleep(int us) L4_NOTHROW
Suspend thread for a period of us microseconds.
#define L4_PAGESIZE
Minimal page size (in bytes).
Definition: consts.h:277
Basic timeout specification.
Definition: __timeout.h:45
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition: compiler.h:186
l4_msgtag_t l4_ipc_sleep(l4_timeout_t timeout) L4_NOTHROW
Sleep for an amount of time.
Definition: ipc.h:496
#define L4_CV
Define calling convention.
Definition: linkage.h:44
void l4_sleep(int ms) L4_NOTHROW
Suspend thread for a period of ms milliseconds.
void l4_touch_rw(const void *addr, unsigned size) L4_NOTHROW
Touch data areas to force mapping (read-write)
Definition: util.h:107
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
void l4_sleep_forever(void) L4_NOTHROW)
Go sleep and never wake up.
Definition: util.h:50
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185