1 /**
2 * \file
3 * \brief Utilities for x86
4 */
5 /*
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>,
8 * Frank Mehnert <fm3@os.inf.tu-dresden.de>,
9 * Jork Löser <jork@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
11 * This file is part of TUD:OS and distributed under the terms of the
12 * GNU Lesser General Public License 2.1.
13 * Please see the COPYING-LGPL-2.1 file for details.
14 */
15 #ifndef __UTIL_H
16 #define __UTIL_H
17
18 #include <l4/sys/types.h>
19 #include <l4/sys/compiler.h>
20 #include <l4/sys/ipc.h>
21
22 EXTERN_C_BEGIN
23
24 /** Calculate l4 timeouts
25 * \param mus time in microseconds. Special cases:
26 * - 0 - > timeout 0
27 * - ~0U -> timeout NEVER
28 * \return the corresponding l4_timeout value
29 */
30 L4_CV l4_timeout_s l4util_micros2l4to(unsigned int mus) L4_NOTHROW;
31
32 /** Suspend thread for a period of \a ms milliseconds
33 * \param ms Time in milliseconds
34 */
35 L4_CV void l4_sleep(int ms) L4_NOTHROW;
36
37 /* Suspend thread for a period of \a us microseconds.
38 * \param us Time in microseconds
39 * WARNING: This function is mostly bogus since the timer resolution of
40 * current L4 implementations is about 1ms! */
41 L4_CV void l4_usleep(int us) L4_NOTHROW;
42
43 /**
44 * \brief Go sleep and never wake up.
45 * \ingroup l4util_api
46 *
47 */
48 L4_INLINE void l4_sleep_forever(void) L4_NOTHROW __attribute__((noreturn));
49
50 L4_INLINE void
l4_sleep_forever(void)51 l4_sleep_forever(void) L4_NOTHROW
52 {
53 for (;;)
54 l4_ipc_sleep(L4_IPC_NEVER);
55 }
56
57 /** Touch data areas to force mapping read-only */
58 static inline void
l4_touch_ro(const void * addr,unsigned size)59 l4_touch_ro(const void*addr, unsigned size) L4_NOTHROW
60 {
61 const char *bptr, *eptr;
62
63 bptr = (const char*)(((l4_addr_t)addr) & L4_PAGEMASK);
64 eptr = (const char*)(((l4_addr_t)addr+size-1) & L4_PAGEMASK);
65 for(;bptr<=eptr;bptr+=L4_PAGESIZE){
66 asm volatile("or %0,%%eax \n"
67 :
68 : "m" (*(const unsigned*)bptr)
69 : "eax" );
70 }
71 }
72
73
74 /** Touch data areas to force mapping read-write */
75 static inline void
l4_touch_rw(const void * addr,unsigned size)76 l4_touch_rw(const void*addr, unsigned size) L4_NOTHROW
77 {
78 const char *bptr, *eptr;
79
80 bptr = (const char*)(((l4_addr_t)addr) & L4_PAGEMASK);
81 eptr = (const char*)(((l4_addr_t)addr+size-1) & L4_PAGEMASK);
82 for(;bptr<=eptr;bptr+=L4_PAGESIZE){
83 asm volatile("orb $0,%0 \n"
84 :
85 : "m" (*(const unsigned*)bptr)
86 );
87 }
88 }
89
90 EXTERN_C_END
91
92 #endif
93
94