]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-amd64/L4API-l4f/__semaphore_impl.h
update
[l4.git] / l4 / pkg / l4sys / include / ARCH-amd64 / L4API-l4f / __semaphore_impl.h
1 /**
2  * \file
3  * \brief  User-lock implementation for amd64
4  */
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  *               Alexander Warg <warg@os.inf.tu-dresden.de>
8  *     economic rights: Technische Universität Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction.  Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License.  This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #pragma once
24
25 #include <l4/sys/utcb.h>
26 #include <l4/sys/ipc-invoke.h>
27
28 L4_INLINE l4_msgtag_t
29 l4_usem_down_to(l4_cap_idx_t ksem, l4_u_semaphore_t *sem, l4_timeout_s timeout) L4_NOTHROW
30 {
31   l4_msgtag_t res;
32
33   l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
34
35   do
36     {
37       unsigned long dummy1, dummy2, dummy3;
38       __asm__ __volatile__(
39        "   xor %%rax, %%rax     \n\t"
40        "   decq 0(%%rdi)        \n\t"
41        "   jge  1f              \n\t"
42        "   mov $1, %%rax        \n\t"
43        L4_ENTER_KERNEL
44        "1:                      \n\t"
45        :
46        "=D" (dummy1),
47        "=c" (dummy2),
48        "=d" (dummy3),
49        "=a" (res.raw)
50        :
51        "D" (sem),
52        "d" (ksem),
53        "c" (timeout)
54        :
55        "rsi", "memory"
56       );
57     }
58   while (l4_msgtag_label(res) == L4_USEM_RETRY);
59
60   return res;
61 }
62
63 L4_INLINE l4_msgtag_t
64 l4_usem_up(l4_cap_idx_t ksem, l4_u_semaphore_t *sem) L4_NOTHROW
65 {
66   l4_msgtag_t tag;
67   l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
68   __asm__ __volatile__(
69         "xor %%rax, %%rax       \n\t"
70         "incq 0(%%rdi)          \n\t"
71         "testb $1, 8(%%rdi)     \n\t"
72         "jz   2f                \n\t"
73         "mov $0x10001, %%rax    \n\t"
74         L4_ENTER_KERNEL
75         "2:                     \n\t"
76        :
77         "=D" (sem),
78         "=d" (ksem),
79         "=a" (tag.raw)
80        :
81         "D" (sem),
82         "d" (ksem)
83        :
84         "rcx", "rsi", "memory"
85        );
86
87   return tag;
88 }
89