]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libpthread/linuxthreads/sysdeps/s390/s390-32/pt-machine.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libpthread / linuxthreads / sysdeps / s390 / s390-32 / pt-machine.h
1 /* Machine-dependent pthreads configuration and inline functions.
2    S390 version.
3    Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
5    This file is part of the GNU C Library.
6
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 2.1 of the
10    License, or (at your option) any later version.
11
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; see the file COPYING.LIB.  If
19    not, see <http://www.gnu.org/licenses/>.  */
20
21 #ifndef _PT_MACHINE_H
22 #define _PT_MACHINE_H   1
23
24 #ifndef PT_EI
25 # define PT_EI __extern_always_inline
26 #endif
27
28 extern long int testandset (int *spinlock);
29 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
30
31 /* For multiprocessor systems, we want to ensure all memory accesses
32    are completed before we reset a lock.  On other systems, we still
33    need to make sure that the compiler has flushed everything to memory.  */
34 #define MEMORY_BARRIER() __asm__ __volatile__ ("bcr 15,0" : : : "memory")
35
36 /* Spinlock implementation; required.  */
37 PT_EI long int
38 testandset (int *spinlock)
39 {
40   int ret;
41
42   __asm__ __volatile__(
43        "    la    1,%1\n"
44        "    lhi   0,1\n"
45        "    l     %0,%1\n"
46        "0:  cs    %0,0,0(1)\n"
47        "    jl    0b"
48        : "=&d" (ret), "+m" (*spinlock)
49        : : "0", "1", "cc");
50
51   return ret;
52 }
53
54
55 /* Get some notion of the current stack.  Need not be exactly the top
56    of the stack, just something somewhere in the current frame.  */
57 #define CURRENT_STACK_FRAME  stack_pointer
58 register char * stack_pointer __asm__ ("15");
59
60 #ifdef __UCLIBC_HAS_TLS__
61 /* Return the thread descriptor for the current thread.  */
62 # define THREAD_SELF ((pthread_descr) __builtin_thread_pointer ())
63
64 /* Initialize the thread-unique value.  */
65 #define INIT_THREAD_SELF(descr, nr) __builtin_set_thread_pointer (descr)
66 #else
67 /* Return the thread descriptor for the current thread.
68    S/390 registers uses access register 0 as "thread register".  */
69 #define THREAD_SELF  ({                                                       \
70   register pthread_descr __self;                                              \
71   __asm__ ("ear %0,%%a0" : "=d" (__self) );                                   \
72   __self;                                                                     \
73 })
74
75 /* Initialize the thread-unique value.  */
76 #define INIT_THREAD_SELF(descr, nr)  ({                                       \
77   __asm__ ("sar %%a0,%0" : : "d" (descr) );                                   \
78 })
79 #endif
80
81 /* Access to data in the thread descriptor is easy.  */
82 #define THREAD_GETMEM(descr, member) \
83   ((void) sizeof (descr), THREAD_SELF->member)
84 #define THREAD_GETMEM_NC(descr, member) \
85   ((void) sizeof (descr), THREAD_SELF->member)
86 #define THREAD_SETMEM(descr, member, value) \
87   ((void) sizeof (descr), THREAD_SELF->member = (value))
88 #define THREAD_SETMEM_NC(descr, member, value) \
89   ((void) sizeof (descr), THREAD_SELF->member = (value))
90
91 /* We want the OS to assign stack addresses.  */
92 #define FLOATING_STACKS 1
93
94 /* Maximum size of the stack if the rlimit is unlimited.  */
95 #define ARCH_STACK_MAX_SIZE     8*1024*1024
96
97 /* Compare-and-swap for semaphores. */
98
99 #define HAS_COMPARE_AND_SWAP
100
101 PT_EI int
102 __compare_and_swap(long int *p, long int oldval, long int newval)
103 {
104         int retval;
105
106         __asm__ __volatile__(
107                 "  la   1,%1\n"
108                 "  lr   0,%2\n"
109                 "  cs   0,%3,0(1)\n"
110                 "  ipm  %0\n"
111                 "  srl  %0,28\n"
112                 "0:"
113                 : "=&d" (retval), "+m" (*p)
114                 : "d" (oldval) , "d" (newval)
115                 : "cc", "0", "1" );
116         return retval == 0;
117 }
118
119 #endif /* pt-machine.h */