Test for stack alignment.
[glibc.git] / linuxthreads / sysdeps / s390 / s390-64 / pt-machine.h
blob49f8ae2b9aea388a1d8867bd05f3624ec91157b8
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.
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.
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.
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 not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #ifndef _PT_MACHINE_H
23 #define _PT_MACHINE_H 1
25 #ifndef PT_EI
26 # define PT_EI extern inline __attribute__ ((always_inline))
27 #endif
29 extern long int testandset (int *spinlock);
30 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
32 /* For multiprocessor systems, we want to ensure all memory accesses
33 are completed before we reset a lock. On other systems, we still
34 need to make sure that the compiler has flushed everything to memory. */
35 #define MEMORY_BARRIER() __asm__ __volatile__ ("bcr 15,0" : : : "memory")
37 /* Spinlock implementation; required. */
38 PT_EI long int
39 testandset (int *spinlock)
41 int ret;
43 __asm__ __volatile__(
44 " la 1,%1\n"
45 " lhi 0,1\n"
46 " l %0,%1\n"
47 "0: cs %0,0,0(1)\n"
48 " jl 0b"
49 : "=&d" (ret), "+m" (*spinlock)
50 : : "0", "1", "cc");
52 return ret;
56 /* Get some notion of the current stack. Need not be exactly the top
57 of the stack, just something somewhere in the current frame. */
58 #define CURRENT_STACK_FRAME stack_pointer
59 register char * stack_pointer __asm__ ("15");
61 #ifdef USE_TLS
62 /* Return the thread descriptor for the current thread. */
63 # define THREAD_SELF ((pthread_descr) __builtin_thread_pointer ())
65 /* Initialize the thread-unique value. */
66 #define INIT_THREAD_SELF(descr, nr) __builtin_set_thread_pointer (descr)
67 #else
68 /* Return the thread descriptor for the current thread.
69 64 bit S/390 uses access register 0 and 1 as "thread register". */
70 #define THREAD_SELF ({ \
71 register pthread_descr __self; \
72 __asm__ (" ear %0,%%a0\n" \
73 " sllg %0,%0,32\n" \
74 " ear %0,%%a1\n" \
75 : "=d" (__self) ); \
76 __self; \
79 /* Initialize the thread-unique value. */
80 #define INIT_THREAD_SELF(descr, nr) ({ \
81 __asm__ (" sar %%a1,%0\n" \
82 " srlg 0,%0,32\n" \
83 " sar %%a0,0\n" \
84 : : "d" (descr) : "0" ); \
86 #endif
88 /* Access to data in the thread descriptor is easy. */
89 #define THREAD_GETMEM(descr, member) \
90 ((void) sizeof (descr), THREAD_SELF->member)
91 #define THREAD_GETMEM_NC(descr, member) \
92 ((void) sizeof (descr), THREAD_SELF->member)
93 #define THREAD_SETMEM(descr, member, value) \
94 ((void) sizeof (descr), THREAD_SELF->member = (value))
95 #define THREAD_SETMEM_NC(descr, member, value) \
96 ((void) sizeof (descr), THREAD_SELF->member = (value))
98 /* We want the OS to assign stack addresses. */
99 #define FLOATING_STACKS 1
101 /* Maximum size of the stack if the rlimit is unlimited. */
102 #define ARCH_STACK_MAX_SIZE 8*1024*1024
104 /* Compare-and-swap for semaphores. */
106 #define HAS_COMPARE_AND_SWAP
108 PT_EI int
109 __compare_and_swap(long int *p, long int oldval, long int newval)
111 int retval;
113 __asm__ __volatile__(
114 " lgr 0,%2\n"
115 " csg 0,%3,%1\n"
116 " ipm %0\n"
117 " srl %0,28\n"
118 "0:"
119 : "=&d" (retval), "+m" (*p)
120 : "d" (oldval) , "d" (newval)
121 : "cc", "0");
122 return retval == 0;
125 #endif /* pt-machine.h */