]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-ppc32/__semaphore_impl.h
update
[l4.git] / l4 / pkg / l4sys / include / ARCH-ppc32 / __semaphore_impl.h
1 /**
2  * \file
3  * \brief  User-lock implementation for x86
4  */
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
7  *     economic rights: Technische Universität Dresden (Germany)
8  *
9  * This file is part of TUD:OS and distributed under the terms of the
10  * GNU General Public License 2.
11  * Please see the COPYING-GPL-2 file for details.
12  *
13  * As a special exception, you may use this file as part of a free software
14  * library without restriction.  Specifically, if other files instantiate
15  * templates or use macros or inline functions from this file, or you compile
16  * this file and link it with other files to produce an executable, this
17  * file does not by itself cause the resulting executable to be covered by
18  * the GNU General Public License.  This exception does not however
19  * invalidate any other reasons why the executable file might be covered by
20  * the GNU General Public License.
21  */
22 #pragma once
23
24 #include <l4/sys/utcb.h>
25 #include <l4/sys/atomic.h>
26 #include <l4/sys/compiler.h>
27 #include <l4/sys/ipc.h>
28
29 L4_INLINE l4_msgtag_t
30 l4_usem_down_to(l4_cap_idx_t lock, l4_u_semaphore_t *sem, l4_timeout_s timeout) L4_NOTHROW
31 {
32   do
33     {
34       if (__builtin_expect(l4_atomic_add((long*)&(sem->counter), -1) >= 0, 1))
35         return l4_msgtag(0,0,0,0);
36
37       l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
38
39       register unsigned long _lock    __asm__ ("r4") = lock | L4_SYSF_CALL;
40       register unsigned long _timeout __asm__ ("r5") = timeout.t;
41       register unsigned long _flags   __asm__ ("r6") = 0;
42       register unsigned long _tag     __asm__ ("r3") = 1;
43
44       __asm__ __volatile__
45         (" bla %[addr] \n"
46          :
47          "=r"(_lock),
48          "=r"(_timeout),
49          "=r"(_flags),
50          "=r"(_tag)
51          :
52          "0"(_lock),
53          "1"(_timeout),
54          "2"(_flags),
55          "3"(_tag),
56          [addr] "i" (L4_SYSCALL_INVOKE)
57          :
58          "memory", "lr");
59
60       if (_tag != 0x10000)
61         {
62           l4_msgtag_t t; t.raw = _tag;
63           return t;
64         }
65     }
66   while (1);
67 }
68
69 L4_INLINE l4_msgtag_t
70 l4_usem_up(l4_cap_idx_t lock, l4_u_semaphore_t *sem) L4_NOTHROW
71 {
72   l4_atomic_add((long*)&(sem->counter), 1);
73
74   if (__builtin_expect(sem->flags == 0, 1))
75     return l4_msgtag(0,0,0,0);
76
77   l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
78
79   register unsigned long _lock    __asm__ ("r4") = lock | L4_SYSF_CALL;
80   register unsigned long _timeout __asm__ ("r5") = 0;
81   register unsigned long _flags   __asm__ ("r6") = 0;
82   register unsigned long _tag     __asm__ ("r3") = 0x10001;
83
84   __asm__ __volatile__
85     (" bla %[addr] \n"
86      :
87      "=r"(_lock),
88      "=r"(_timeout),
89      "=r"(_flags),
90      "=r"(_tag)
91      :
92      "0"(_lock),
93      "1"(_timeout),
94      "2"(_flags),
95      "3"(_tag),
96      [addr] "i" (L4_SYSCALL_INVOKE)
97      :
98      "memory", "lr");
99
100   l4_msgtag_t t; t.raw = _tag;
101   return t;
102 }
103