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 \a ms milliseconds
32 * \param ms Time in milliseconds
33 */
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
42 /**
43 * \brief Go sleep and never wake up.
44 * \ingroup l4util_api
45 *
46 */
47 L4_INLINE void l4_sleep_forever(void) L4_NOTHROW __attribute__((noreturn));
48
49 L4_INLINE void
l4_sleep_forever(void)50 l4_sleep_forever(void) L4_NOTHROW
51 {
52 for (;;)
53 l4_ipc_sleep(L4_IPC_NEVER);
54 }
55
56 /** Touch data areas to force mapping read-only */
57 static inline void
l4_touch_ro(const void * addr,unsigned size)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
73 /** Touch data areas to force mapping read-write */
74 static inline void
l4_touch_rw(const void * addr,unsigned size)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
89 EXTERN_C_END
90
91 #endif
92
93