1 /* Machine-dependent pthreads configuration and inline functions.
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
19 not, see <http://www.gnu.org/licenses/>. */
22 #define _PT_MACHINE_H 1
25 # define PT_EI __extern_always_inline
28 extern long int testandset (int *spinlock);
29 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
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")
36 /* Spinlock implementation; required. */
38 testandset (int *spinlock)
48 : "=&d" (ret), "+m" (*spinlock)
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");
60 #ifdef __UCLIBC_HAS_TLS__
61 /* Return the thread descriptor for the current thread. */
62 # define THREAD_SELF ((pthread_descr) __builtin_thread_pointer ())
64 /* Initialize the thread-unique value. */
65 #define INIT_THREAD_SELF(descr, nr) __builtin_set_thread_pointer (descr)
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" \
78 /* Initialize the thread-unique value. */
79 #define INIT_THREAD_SELF(descr, nr) ({ \
80 __asm__ (" sar %%a1,%0\n" \
83 : : "d" (descr) : "0" ); \
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))
97 /* We want the OS to assign stack addresses. */
98 #define FLOATING_STACKS 1
100 /* Maximum size of the stack if the rlimit is unlimited. */
101 #define ARCH_STACK_MAX_SIZE 8*1024*1024
103 /* Compare-and-swap for semaphores. */
105 #define HAS_COMPARE_AND_SWAP
108 __compare_and_swap(long int *p, long int oldval, long int newval)
112 __asm__ __volatile__(
118 : "=&d" (retval), "+m" (*p)
119 : "d" (oldval) , "d" (newval)
124 #endif /* pt-machine.h */