]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-ppc32/__semaphore_impl.h
ac42c7a41e29d074e7801480628f67e48774f590
[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 // dumb, however atomic sequences are defined in kdebug.h
26 #include <l4/sys/kdebug.h>
27
28 #include <l4/sys/compiler.h>
29 #include <l4/sys/ipc.h>
30
31 L4_INLINE l4_msgtag_t
32 l4_usem_down_to(l4_cap_idx_t lock, l4_u_semaphore_t *sem, l4_timeout_s timeout) L4_NOTHROW
33 {
34   do
35     {
36       if (__builtin_expect(l4_atomic_add((long*)&(sem->counter), -1) >= 0, 1))
37         return l4_msgtag(0,0,0,0);
38
39       l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
40
41       register unsigned long _lock    __asm__ ("r4") = lock | L4_SYSF_CALL;
42       register unsigned long _timeout __asm__ ("r5") = timeout.t;
43       register unsigned long _flags   __asm__ ("r6") = 0;
44       register unsigned long _tag     __asm__ ("r3") = 1;
45
46       __asm__ __volatile__
47         (" bla %[addr] \n"
48          :
49          "=r"(_lock),
50          "=r"(_timeout),
51          "=r"(_flags),
52          "=r"(_tag)
53          :
54          "0"(_lock),
55          "1"(_timeout),
56          "2"(_flags),
57          "3"(_tag),
58          [addr] "i" (L4_SYSCALL_INVOKE)
59          :
60          "memory", "lr");
61
62       if (_tag != 0x10000)
63         {
64           l4_msgtag_t t; t.raw = _tag;
65           return t;
66         }
67     }
68   while (1);
69 }
70
71 L4_INLINE l4_msgtag_t
72 l4_usem_up(l4_cap_idx_t lock, l4_u_semaphore_t *sem) L4_NOTHROW
73 {
74   l4_atomic_add((long*)&(sem->counter), 1);
75
76   if (__builtin_expect(sem->flags == 0, 1))
77     return l4_msgtag(0,0,0,0);
78
79   l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
80
81   register unsigned long _lock    __asm__ ("r4") = lock | L4_SYSF_CALL;
82   register unsigned long _timeout __asm__ ("r5") = 0;
83   register unsigned long _flags   __asm__ ("r6") = 0;
84   register unsigned long _tag     __asm__ ("r3") = 0x10001;
85
86   __asm__ __volatile__
87     (" bla %[addr] \n"
88      :
89      "=r"(_lock),
90      "=r"(_timeout),
91      "=r"(_flags),
92      "=r"(_tag)
93      :
94      "0"(_lock),
95      "1"(_timeout),
96      "2"(_flags),
97      "3"(_tag),
98      [addr] "i" (L4_SYSCALL_INVOKE)
99      :
100      "memory", "lr");
101
102   l4_msgtag_t t; t.raw = _tag;
103   return t;
104 }
105