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