]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libpthread/linuxthreads/sysdeps/s390/s390-64/pt-machine.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libpthread / linuxthreads / sysdeps / s390 / s390-64 / pt-machine.h
1 /* Machine-dependent pthreads configuration and inline functions.
2    64 bit S/390 version.
3    Copyright (C) 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    64 bit S/390 uses access register 0 and 1 as "thread register".  */
69 #define THREAD_SELF  ({                                                       \
70   register pthread_descr __self;                                              \
71   __asm__ ("   ear  %0,%%a0\n"                                                \
72            "   sllg %0,%0,32\n"                                               \
73            "   ear  %0,%%a1\n"                                                \
74            : "=d" (__self) );                                                 \
75   __self;                                                                     \
76 })
77
78 /* Initialize the thread-unique value.  */
79 #define INIT_THREAD_SELF(descr, nr)  ({                                       \
80   __asm__ ("   sar  %%a1,%0\n"                                                \
81            "   srlg 0,%0,32\n"                                                \
82            "   sar  %%a0,0\n"                                                 \
83            : : "d" (descr) : "0" );                                           \
84 })
85 #endif
86
87 /* Access to data in the thread descriptor is easy.  */
88 #define THREAD_GETMEM(descr, member) \
89   ((void) sizeof (descr), THREAD_SELF->member)
90 #define THREAD_GETMEM_NC(descr, member) \
91   ((void) sizeof (descr), THREAD_SELF->member)
92 #define THREAD_SETMEM(descr, member, value) \
93   ((void) sizeof (descr), THREAD_SELF->member = (value))
94 #define THREAD_SETMEM_NC(descr, member, value) \
95   ((void) sizeof (descr), THREAD_SELF->member = (value))
96
97 /* We want the OS to assign stack addresses.  */
98 #define FLOATING_STACKS 1
99
100 /* Maximum size of the stack if the rlimit is unlimited.  */
101 #define ARCH_STACK_MAX_SIZE     8*1024*1024
102
103 /* Compare-and-swap for semaphores. */
104
105 #define HAS_COMPARE_AND_SWAP
106
107 PT_EI int
108 __compare_and_swap(long int *p, long int oldval, long int newval)
109 {
110         int retval;
111
112         __asm__ __volatile__(
113                 "  lgr  0,%2\n"
114                 "  csg  0,%3,%1\n"
115                 "  ipm  %0\n"
116                 "  srl  %0,28\n"
117                 "0:"
118                 : "=&d" (retval), "+m" (*p)
119                 : "d" (oldval) , "d" (newval)
120                 : "cc", "0");
121         return retval == 0;
122 }
123
124 #endif /* pt-machine.h */