OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libpthread / linuxthreads / sysdeps / ia64 / pt-machine.h
1 /* Machine-dependent pthreads configuration and inline functions.
2    IA-64 version.
3    Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public License as
8    published by the Free Software Foundation; either version 2.1 of the
9    License, or (at your option) any later version.
10
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    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; see the file COPYING.LIB.  If
18    not, see <http://www.gnu.org/licenses/>.  */
19
20 #ifndef _PT_MACHINE_H
21 #define _PT_MACHINE_H   1
22
23 #include <features.h>
24 #include <ia64intrin.h>
25
26 #ifndef PT_EI
27 # define PT_EI __extern_always_inline
28 #endif
29
30 /* Make sure gcc doesn't try to be clever and move things around on
31    us. We need to use _exactly_ the address the user gave us, not some
32    alias that contains the same information.  */
33 #define __atomic_fool_gcc(x) (*(__volatile__ struct { int a[100]; } *)x)
34
35 #ifndef ELF_MACHINE_NAME
36
37 #define NEED_SEPARATE_REGISTER_STACK
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     32*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    r12 (sp) is the stack pointer. */
48 #define CURRENT_STACK_FRAME  stack_pointer
49 register char *stack_pointer __asm__ ("sp");
50
51
52 /* Register r13 (tp) is reserved by the ABI as "thread pointer". */
53 struct _pthread_descr_struct;
54 register struct _pthread_descr_struct *__thread_self __asm__("r13");
55
56 /* Return the thread descriptor for the current thread.  */
57 #define THREAD_SELF  __thread_self
58
59 /* Initialize the thread-unique value.  */
60 #define INIT_THREAD_SELF(descr, nr)  (__thread_self = (descr))
61
62
63 /* Access to data in the thread descriptor is easy.  */
64 #define THREAD_GETMEM(descr, member) \
65   ((void) sizeof (descr), THREAD_SELF->member)
66 #define THREAD_GETMEM_NC(descr, member) \
67   ((void) sizeof (descr), THREAD_SELF->member)
68 #define THREAD_SETMEM(descr, member, value) \
69   ((void) sizeof (descr), THREAD_SELF->member = (value))
70 #define THREAD_SETMEM_NC(descr, member, value) \
71   ((void) sizeof (descr), THREAD_SELF->member = (value))
72
73
74 /* Memory barrier */
75 #define MEMORY_BARRIER() __sync_synchronize ()
76
77
78 #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
79
80 PT_EI int
81 __compare_and_swap (long int *p, long int oldval, long int newval)
82 {
83   long int readval;
84
85   __asm__ __volatile__
86        ("mov ar.ccv=%4;;\n\t"
87         "cmpxchg8.acq %0=%1,%2,ar.ccv"
88         : "=r" (readval), "=m" (__atomic_fool_gcc (p))
89         : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval)
90         : "memory");
91   return readval == oldval;
92 }
93
94 PT_EI int
95 __compare_and_swap_with_release_semantics (long int *p,
96                                            long int oldval,
97                                            long int newval)
98 {
99   long int readval;
100
101   __asm__ __volatile__
102        ("mov ar.ccv=%4;;\n\t"
103         "cmpxchg8.rel %0=%1,%2,ar.ccv"
104         : "=r" (readval), "=m" (__atomic_fool_gcc (p))
105         : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval)
106         : "memory");
107   return readval == oldval;
108 }
109
110 #endif /* ELF_MACHINE_NAME */
111
112 /* Spinlock implementation; required.  */
113 PT_EI long int
114 testandset (int *spinlock)
115 {
116   long int ret;
117
118   __asm__ __volatile__(
119        "xchg4 %0=%1,%2"
120        : "=r"(ret), "=m"(__atomic_fool_gcc (spinlock))
121        : "r"(1), "m"(__atomic_fool_gcc (spinlock))
122        : "memory");
123
124   return ret;
125 }
126
127 /* Indicate that we are looping.  */
128 #define BUSY_WAIT_NOP   __asm__ ("hint @pause")
129
130 #endif /* pt-machine.h */