3 * \brief User-lock implementation for x86
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
7 * economic rights: Technische Universität Dresden (Germany)
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.
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.
24 #include <l4/sys/utcb.h>
25 #include <l4/sys/atomic.h>
26 #include <l4/sys/compiler.h>
27 #include <l4/sys/ipc.h>
30 l4_usem_down_to(l4_cap_idx_t lock, l4_u_semaphore_t *sem, l4_timeout_s timeout) L4_NOTHROW
34 if (__builtin_expect(l4_atomic_add((long*)&(sem->counter), -1) >= 0, 1))
35 return l4_msgtag(0,0,0,0);
37 l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
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;
56 [addr] "i" (L4_SYSCALL_INVOKE)
62 l4_msgtag_t t; t.raw = _tag;
70 l4_usem_up(l4_cap_idx_t lock, l4_u_semaphore_t *sem) L4_NOTHROW
72 l4_atomic_add((long*)&(sem->counter), 1);
74 if (__builtin_expect(sem->flags == 0, 1))
75 return l4_msgtag(0,0,0,0);
77 l4_utcb_mr()->mr[0] = (l4_addr_t)sem;
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;
96 [addr] "i" (L4_SYSCALL_INVOKE)
100 l4_msgtag_t t; t.raw = _tag;