OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libpthread / linuxthreads / sysdeps / powerpc / powerpc32 / pt-machine.h
1 /* Machine-dependent pthreads configuration and inline functions.
2    powerpc version.
3    Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003
4    Free Software Foundation, Inc.
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 /* These routines are from Appendix G of the 'PowerPC 601 RISC Microprocessor
22    User's Manual', by IBM and Motorola.  */
23
24 #ifndef _PT_MACHINE_H
25 #define _PT_MACHINE_H   1
26
27 #ifndef PT_EI
28 # define PT_EI __extern_always_inline
29 #endif
30
31 extern long int testandset (int *spinlock);
32 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
33
34 /* For multiprocessor systems, we want to ensure all memory accesses
35    are completed before we reset a lock.  On other systems, we still
36    need to make sure that the compiler has flushed everything to memory.  */
37 #define MEMORY_BARRIER() __asm__ __volatile__ ("sync" : : : "memory")
38
39 /* We want the OS to assign stack addresses.  */
40 #define FLOATING_STACKS 1
41
42 /* Maximum size of the stack if the rlimit is unlimited.  */
43 #define ARCH_STACK_MAX_SIZE     8*1024*1024
44
45 /* Get some notion of the current stack.  Need not be exactly the top
46    of the stack, just something somewhere in the current frame.  */
47 #define CURRENT_STACK_FRAME  stack_pointer
48 register char * stack_pointer __asm__ ("r1");
49
50 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
51 struct _pthread_descr_struct;
52 register struct _pthread_descr_struct *__thread_self __asm__("r2");
53
54 /* Return the thread descriptor for the current thread.  */
55 #define THREAD_SELF  __thread_self
56
57 /* Initialize the thread-unique value.  */
58 #define INIT_THREAD_SELF(descr, nr)  (__thread_self = (descr))
59
60 /* Access to data in the thread descriptor is easy.  */
61 #define THREAD_GETMEM(descr, member) \
62   ((void) (descr), THREAD_SELF->member)
63 #define THREAD_GETMEM_NC(descr, member) \
64   ((void) (descr), THREAD_SELF->member)
65 #define THREAD_SETMEM(descr, member, value) \
66   ((void) (descr), THREAD_SELF->member = (value))
67 #define THREAD_SETMEM_NC(descr, member, value) \
68   ((void) (descr), THREAD_SELF->member = (value))
69
70 /* Compare-and-swap for semaphores. */
71 /* note that test-and-set(x) is the same as !compare-and-swap(x, 0, 1) */
72
73 #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
74 #define IMPLEMENT_TAS_WITH_CAS
75
76 PT_EI int
77 __compare_and_swap (long int *p, long int oldval, long int newval)
78 {
79   int ret;
80
81   __asm__ __volatile__ (
82            "0:    lwarx %0,0,%1 ;"
83            "      xor. %0,%3,%0;"
84            "      bne 1f;"
85            "      stwcx. %2,0,%1;"
86            "      bne- 0b;"
87            "1:    "
88         : "=&r"(ret)
89         : "r"(p), "r"(newval), "r"(oldval)
90         : "cr0", "memory");
91   /* This version of __compare_and_swap is to be used when acquiring
92      a lock, so we don't need to worry about whether other memory
93      operations have completed, but we do need to be sure that any loads
94      after this point really occur after we have acquired the lock.  */
95   __asm__ __volatile__ ("isync" : : : "memory");
96   return ret == 0;
97 }
98
99 PT_EI int
100 __compare_and_swap_with_release_semantics (long int *p,
101                                            long int oldval, long int newval)
102 {
103   int ret;
104
105   MEMORY_BARRIER ();
106   __asm__ __volatile__ (
107            "0:    lwarx %0,0,%1 ;"
108            "      xor. %0,%3,%0;"
109            "      bne 1f;"
110            "      stwcx. %2,0,%1;"
111            "      bne- 0b;"
112            "1:    "
113         : "=&r"(ret)
114         : "r"(p), "r"(newval), "r"(oldval)
115         : "cr0", "memory");
116   return ret == 0;
117 }
118
119 #endif /* pt-machine.h */