]>
Commit | Line | Data |
---|---|---|
9aae19cd UD |
1 | /* Machine-dependent pthreads configuration and inline functions. |
2 | IA-64 version. | |
e408880b | 3 | Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc. |
9aae19cd UD |
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 | |
cc7375ce RM |
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 | |
9aae19cd UD |
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 | |
cc7375ce | 14 | Lesser General Public License for more details. |
9aae19cd | 15 | |
cc7375ce | 16 | You should have received a copy of the GNU Lesser General Public |
9aae19cd UD |
17 | License along with the GNU C Library; see the file COPYING.LIB. If not, |
18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
3fc2f6c8 UD |
21 | #ifndef _PT_MACHINE_H |
22 | #define _PT_MACHINE_H 1 | |
23 | ||
c0a0f9a3 UD |
24 | #include <ia64intrin.h> |
25 | ||
9aae19cd | 26 | #ifndef PT_EI |
d347a4ab | 27 | # define PT_EI extern inline __attribute__ ((always_inline)) |
9aae19cd UD |
28 | #endif |
29 | ||
f68137c9 AJ |
30 | extern long int testandset (int *spinlock); |
31 | extern int __compare_and_swap (long int *p, long int oldval, long int newval); | |
32 | ||
9aae19cd UD |
33 | /* Make sure gcc doesn't try to be clever and move things around on |
34 | us. We need to use _exactly_ the address the user gave us, not some | |
35 | alias that contains the same information. */ | |
36 | #define __atomic_fool_gcc(x) (*(volatile struct { int a[100]; } *)x) | |
37 | ||
38 | #ifndef ELF_MACHINE_NAME | |
39 | ||
40 | #define NEED_SEPARATE_REGISTER_STACK | |
41 | ||
8d42e2e5 UD |
42 | /* We want the OS to assign stack addresses. */ |
43 | #define FLOATING_STACKS 1 | |
44 | ||
45 | /* Maximum size of the stack if the rlimit is unlimited. */ | |
46 | #define ARCH_STACK_MAX_SIZE 32*1024*1024 | |
47 | ||
9aae19cd UD |
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 | r12 (sp) is the stack pointer. */ | |
51 | #define CURRENT_STACK_FRAME stack_pointer | |
52 | register char *stack_pointer __asm__ ("sp"); | |
53 | ||
54 | ||
55 | /* Register r13 (tp) is reserved by the ABI as "thread pointer". */ | |
56 | struct _pthread_descr_struct; | |
57 | register struct _pthread_descr_struct *__thread_self __asm__("r13"); | |
58 | ||
59 | /* Return the thread descriptor for the current thread. */ | |
60 | #define THREAD_SELF __thread_self | |
61 | ||
62 | /* Initialize the thread-unique value. */ | |
63 | #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr)) | |
64 | ||
65 | ||
66 | /* Access to data in the thread descriptor is easy. */ | |
ec67a380 UD |
67 | #define THREAD_GETMEM(descr, member) \ |
68 | ((void) sizeof (descr), THREAD_SELF->member) | |
69 | #define THREAD_GETMEM_NC(descr, member) \ | |
70 | ((void) sizeof (descr), THREAD_SELF->member) | |
567678b6 | 71 | #define THREAD_SETMEM(descr, member, value) \ |
ec67a380 | 72 | ((void) sizeof (descr), THREAD_SELF->member = (value)) |
567678b6 | 73 | #define THREAD_SETMEM_NC(descr, member, value) \ |
ec67a380 | 74 | ((void) sizeof (descr), THREAD_SELF->member = (value)) |
9aae19cd UD |
75 | |
76 | ||
5210321d | 77 | /* Memory barrier */ |
b3aa0009 | 78 | #define MEMORY_BARRIER() __sync_synchronize () |
5210321d UD |
79 | |
80 | ||
9aae19cd UD |
81 | #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS |
82 | ||
ba908190 | 83 | PT_EI int |
9aae19cd UD |
84 | __compare_and_swap (long int *p, long int oldval, long int newval) |
85 | { | |
86 | long int readval; | |
87 | ||
88 | __asm__ __volatile__ | |
89 | ("mov ar.ccv=%4;;\n\t" | |
90 | "cmpxchg8.acq %0=%1,%2,ar.ccv" | |
91 | : "=r" (readval), "=m" (__atomic_fool_gcc (p)) | |
2dd18ce2 | 92 | : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval) |
9aae19cd UD |
93 | : "memory"); |
94 | return readval == oldval; | |
95 | } | |
96 | ||
ba908190 | 97 | PT_EI int |
9aae19cd UD |
98 | __compare_and_swap_with_release_semantics (long int *p, |
99 | long int oldval, | |
100 | long int newval) | |
101 | { | |
102 | long int readval; | |
103 | ||
104 | __asm__ __volatile__ | |
105 | ("mov ar.ccv=%4;;\n\t" | |
106 | "cmpxchg8.rel %0=%1,%2,ar.ccv" | |
107 | : "=r" (readval), "=m" (__atomic_fool_gcc (p)) | |
2dd18ce2 | 108 | : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval) |
9aae19cd UD |
109 | : "memory"); |
110 | return readval == oldval; | |
111 | } | |
112 | ||
113 | #endif /* ELF_MACHINE_NAME */ | |
114 | ||
115 | /* Spinlock implementation; required. */ | |
116 | PT_EI long int | |
117 | testandset (int *spinlock) | |
118 | { | |
119 | long int ret; | |
120 | ||
121 | __asm__ __volatile__( | |
122 | "xchg4 %0=%1,%2" | |
123 | : "=r"(ret), "=m"(__atomic_fool_gcc (spinlock)) | |
2dd18ce2 | 124 | : "r"(1), "m"(__atomic_fool_gcc (spinlock)) |
9aae19cd UD |
125 | : "memory"); |
126 | ||
127 | return ret; | |
128 | } | |
3fc2f6c8 | 129 | |
e408880b UD |
130 | /* Indicate that we are looping. */ |
131 | #define BUSY_WAIT_NOP __asm__ ("hint @pause") | |
132 | ||
3fc2f6c8 | 133 | #endif /* pt-machine.h */ |