]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4util/include/ARCH-amd64/util.h
update
[l4.git] / l4 / pkg / l4util / include / ARCH-amd64 / util.h
1 /**
2  * \file
3  * \brief Utilities, amd64 version
4  */
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
21 EXTERN_C_BEGIN
22
23 /** Calculate l4 timeouts
24  * \param mus   time in microseconds. Special cases:
25  *              - 0 - > timeout 0
26  *              - ~0U -> timeout NEVER
27  * \return the corresponding l4_timeout value
28  */
29 L4_CV l4_timeout_s l4util_micros2l4to(unsigned int mus) L4_NOTHROW;
30
31 /** Suspend thread for a period of <ms> milliseconds */
32 L4_CV void l4_sleep(int ms) L4_NOTHROW;
33
34 /* Suspend thread for a period of <us> micro seconds.
35  * WARNING: This function is mostly bogus since the timer resolution of
36  *          current L4 implementations is about 1ms! */
37 L4_CV void l4_usleep(int us) L4_NOTHROW;
38
39 /**
40  * \brief Go sleep and never wake up.
41  * \ingroup l4util_api
42  *
43  */
44 L4_INLINE void l4_sleep_forever(void) L4_NOTHROW __attribute__((noreturn));
45
46 L4_INLINE void
47 l4_sleep_forever(void) L4_NOTHROW
48 {
49   for (;;)
50     l4_ipc_sleep(L4_IPC_NEVER);
51 }
52
53 /** Touch data areas to force mapping read-only */
54 static inline void
55 l4_touch_ro(const void*addr, unsigned size) L4_NOTHROW
56 {
57   const char *bptr, *eptr;
58
59   bptr = (const char*)(((l4_addr_t)addr) & L4_PAGEMASK);
60   eptr = (const char*)(((l4_addr_t)addr+size-1) & L4_PAGEMASK);
61   for(;bptr<=eptr;bptr+=L4_PAGESIZE){
62     asm volatile("or    %0,%%rax \n"
63                  :
64                  : "m" (*(const unsigned*)bptr)
65                  : "rax" );
66   }
67 }
68
69
70 /** Touch data areas to force mapping read-write */
71 static inline void
72 l4_touch_rw(const void*addr, unsigned size) L4_NOTHROW
73 {
74   const char *bptr, *eptr;
75
76   bptr = (const char*)(((l4_addr_t)addr) & L4_PAGEMASK);
77   eptr = (const char*)(((l4_addr_t)addr+size-1) & L4_PAGEMASK);
78   for(;bptr<=eptr;bptr+=L4_PAGESIZE){
79     asm volatile("or    $0,%0 \n"
80                  :
81                  : "m" (*(const unsigned*)bptr)
82                  );
83   }
84 }
85
86 EXTERN_C_END
87
88 #endif
89