(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / powerpc / powerpc64 / pt-machine.h
blob562e69fa18ef0293b18a0d370c288a93f9c27f8e
1 /* Machine-dependent pthreads configuration and inline functions.
2 powerpc version.
3 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* These routines are from Appendix G of the 'PowerPC 601 RISC Microprocessor
22 User's Manual', by IBM and Motorola. */
24 #ifndef _PT_MACHINE_H
25 #define _PT_MACHINE_H 1
27 #ifndef PT_EI
28 # define PT_EI extern inline __attribute__ ((always_inline))
29 #endif
31 extern long int testandset (int *spinlock);
32 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
33 extern int __compare_and_swap32 (int *p, int oldval, int newval);
35 /* For multiprocessor systems, we want to ensure all memory accesses
36 are completed before we reset a lock. On other systems, we still
37 need to make sure that the compiler has flushed everything to memory. */
38 #define MEMORY_BARRIER() __asm__ __volatile__ ("lwsync" : : : "memory")
39 #define READ_MEMORY_BARRIER() __asm__ __volatile__ ("lwsync" : : : "memory")
40 #define WRITE_MEMORY_BARRIER() __asm__ __volatile__ ("eieio" : : : "memory")
42 /* We want the OS to assign stack addresses. */
43 #define FLOATING_STACKS 1
45 /* Maximum size of the stack if the rlimit is unlimited. */
46 #define ARCH_STACK_MAX_SIZE 16*1024*1024
48 /* Get some notion of the current stack. Need not be exactly the top
49 of the stack, just something somewhere in the current frame. */
50 #define CURRENT_STACK_FRAME stack_pointer
51 register char * stack_pointer __asm__ ("r1");
53 /* Register r13 (tp) is reserved by the ABI as "thread pointer". */
54 struct _pthread_descr_struct;
55 register struct _pthread_descr_struct *__thread_self __asm__("r13");
57 /* Return the thread descriptor for the current thread. */
58 #define THREAD_SELF __thread_self
60 /* Initialize the thread-unique value. */
61 #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr))
63 /* Access to data in the thread descriptor is easy. */
64 #define THREAD_GETMEM(descr, member) \
65 ((void) (descr), THREAD_SELF->member)
66 #define THREAD_GETMEM_NC(descr, member) \
67 ((void) (descr), THREAD_SELF->member)
68 #define THREAD_SETMEM(descr, member, value) \
69 ((void) (descr), THREAD_SELF->member = (value))
70 #define THREAD_SETMEM_NC(descr, member, value) \
71 ((void) (descr), THREAD_SELF->member = (value))
73 /* Compare-and-swap for semaphores. */
74 /* note that test-and-set(x) is the same as !compare-and-swap(x, 0, 1) */
76 #define HAS_COMPARE_AND_SWAP
77 #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
79 PT_EI int
80 __compare_and_swap (long int *p, long int oldval, long int newval)
82 long int ret;
84 __asm__ __volatile__ (
85 "0: ldarx %0,0,%1 ;"
86 " xor. %0,%3,%0;"
87 " bne 1f;"
88 " stdcx. %2,0,%1;"
89 " bne- 0b;"
90 "1: "
91 : "=&r"(ret)
92 : "r"(p), "r"(newval), "r"(oldval)
93 : "cr0", "memory");
94 /* This version of __compare_and_swap is to be used when acquiring
95 a lock, so we don't need to worry about whether other memory
96 operations have completed, but we do need to be sure that any loads
97 after this point really occur after we have acquired the lock. */
98 __asm__ __volatile__ ("isync" : : : "memory");
99 return (int)(ret == 0);
102 PT_EI int
103 __compare_and_swap_with_release_semantics (long int *p,
104 long int oldval, long int newval)
106 long int ret;
108 MEMORY_BARRIER ();
109 __asm__ __volatile__ (
110 "0: ldarx %0,0,%1 ;"
111 " xor. %0,%3,%0;"
112 " bne 1f;"
113 " stdcx. %2,0,%1;"
114 " bne- 0b;"
115 "1: "
116 : "=&r"(ret)
117 : "r"(p), "r"(newval), "r"(oldval)
118 : "cr0", "memory");
119 return (int)(ret == 0);
122 PT_EI int
123 __compare_and_swap32 (int *p, int oldval, int newval)
125 int ret;
127 __asm__ __volatile__ (
128 "0: lwarx %0,0,%1 ;"
129 " xor. %0,%3,%0;"
130 " bne 1f;"
131 " stwcx. %2,0,%1;"
132 " bne- 0b;"
133 "1: "
134 : "=&r"(ret)
135 : "r"(p), "r"(newval), "r"(oldval)
136 : "cr0", "memory");
137 /* This version of __compare_and_swap is to be used when acquiring
138 a lock, so we don't need to worry about whether other memory
139 operations have completed, but we do need to be sure that any loads
140 after this point really occur after we have acquired the lock. */
141 __asm__ __volatile__ ("isync" : : : "memory");
142 return (int)(ret == 0);
145 PT_EI int
146 __compare_and_swap32_with_release_semantics (long int *p,
147 long int oldval, long int newval)
149 long int ret;
151 MEMORY_BARRIER ();
152 __asm__ __volatile__ (
153 "0: lwarx %0,0,%1 ;"
154 " xor. %0,%3,%0;"
155 " bne 1f;"
156 " stwcx. %2,0,%1;"
157 " bne- 0b;"
158 "1: "
159 : "=&r"(ret)
160 : "r"(p), "r"(newval), "r"(oldval)
161 : "cr0", "memory");
162 return (int)(ret == 0);
165 PT_EI long int
166 testandset (int *p)
168 long int ret, val = 1;
170 MEMORY_BARRIER ();
171 __asm__ __volatile__ (
172 "0: lwarx %0,0,%1 ;"
173 " cmpwi 0,%0,0;"
174 " bne 1f;"
175 " stwcx. %2,0,%1;"
176 " bne- 0b;"
177 "1: "
178 : "=&r"(ret)
179 : "r"(p), "r" (val)
180 : "cr0", "memory");
181 MEMORY_BARRIER ();
182 return ret != 0;
185 #endif /* pt-machine.h */