Test for stack alignment.
[jlayton/glibc.git] / linuxthreads / sysdeps / alpha / pt-machine.h
1 /* Machine-dependent pthreads configuration and inline functions.
2    Alpha version.
3    Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003
4    Free Software Foundation, Inc.
5    This file is part of the GNU C Library.
6    Contributed by Richard Henderson <rth@tamu.edu>.
7
8    The GNU C Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public License as
10    published by the Free Software Foundation; either version 2.1 of the
11    License, or (at your option) any later version.
12
13    The GNU C Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the GNU C Library; see the file COPYING.LIB.  If not,
20    write to the Free Software Foundation, Inc.,  59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #ifndef _PT_MACHINE_H
24 #define _PT_MACHINE_H   1
25
26 #ifndef PT_EI
27 # define PT_EI extern inline __attribute__ ((always_inline))
28 #endif
29
30 #ifdef __linux__
31 # include <asm/pal.h>
32 #else
33 # include <machine/pal.h>
34 #endif
35
36 extern long int testandset (int *spinlock);
37 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
38
39 /* Get some notion of the current stack.  Need not be exactly the top
40    of the stack, just something somewhere in the current frame.  */
41 #define CURRENT_STACK_FRAME  stack_pointer
42 register char *stack_pointer __asm__("$30");
43
44
45 /* Memory barrier; default is to do nothing */
46 #define MEMORY_BARRIER() __asm__ __volatile__("mb" : : : "memory")
47 /* Write barrier.  */
48 #define WRITE_MEMORY_BARRIER() __asm__ __volatile__("wmb" : : : "memory")
49
50
51 /* Spinlock implementation; required.  */
52 PT_EI long int
53 testandset (int *spinlock)
54 {
55   long int ret, temp;
56
57   __asm__ __volatile__(
58         "/* Inline spinlock test & set */\n"
59         "1:\t"
60         "ldl_l %0,%3\n\t"
61         "bne %0,2f\n\t"
62         "or $31,1,%1\n\t"
63         "stl_c %1,%2\n\t"
64         "beq %1,1b\n"
65         "2:\tmb\n"
66         "/* End spinlock test & set */"
67         : "=&r"(ret), "=&r"(temp), "=m"(*spinlock)
68         : "m"(*spinlock)
69         : "memory");
70
71   return ret;
72 }
73
74
75 /* Begin allocating thread stacks at this address.  Default is to allocate
76    them just below the initial program stack.  */
77 #define THREAD_STACK_START_ADDRESS  0x40000000000
78
79
80 /* Return the thread descriptor for the current thread.  */
81 #define THREAD_SELF \
82 ({                                                                            \
83   register pthread_descr __self __asm__("$0");                                \
84   __asm__ ("call_pal %1" : "=r"(__self) : "i"(PAL_rduniq));                   \
85   __self;                                                                     \
86 })
87
88 /* Initialize the thread-unique value.  */
89 #define INIT_THREAD_SELF(descr, nr) \
90 {                                                                             \
91   register pthread_descr __self __asm__("$16") = (descr);                     \
92   __asm__ __volatile__ ("call_pal %1" : : "r"(__self), "i"(PAL_wruniq));      \
93 }
94
95
96 /* Compare-and-swap for semaphores. */
97
98 #define HAS_COMPARE_AND_SWAP
99 PT_EI int
100 __compare_and_swap (long int *p, long int oldval, long int newval)
101 {
102   long int ret;
103
104   __asm__ __volatile__ (
105         "/* Inline compare & swap */\n"
106         "1:\t"
107         "ldq_l %0,%4\n\t"
108         "cmpeq %0,%2,%0\n\t"
109         "beq %0,2f\n\t"
110         "mov %3,%0\n\t"
111         "stq_c %0,%1\n\t"
112         "beq %0,1b\n\t"
113         "2:\tmb\n"
114         "/* End compare & swap */"
115         : "=&r"(ret), "=m"(*p)
116         : "r"(oldval), "r"(newval), "m"(*p)
117         : "memory");
118
119   return ret;
120 }
121
122 /* We want the OS to assign stack addresses.  */
123 #define FLOATING_STACKS 1
124
125 /* Maximum size of the stack if the rlimit is unlimited.  */
126 #define ARCH_STACK_MAX_SIZE     32*1024*1024
127
128 #endif /* pt-machine.h */