Back to index

glibc  2.9
pt-machine.h
Go to the documentation of this file.
00001 /* Machine-dependent pthreads configuration and inline functions.
00002    Alpha version.
00003    Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003
00004    Free Software Foundation, Inc.
00005    This file is part of the GNU C Library.
00006    Contributed by Richard Henderson <rth@tamu.edu>.
00007 
00008    The GNU C Library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Lesser General Public License as
00010    published by the Free Software Foundation; either version 2.1 of the
00011    License, or (at your option) any later version.
00012 
00013    The GNU C Library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Lesser General Public License for more details.
00017 
00018    You should have received a copy of the GNU Lesser General Public
00019    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00020    write to the Free Software Foundation, Inc.,  59 Temple Place - Suite 330,
00021    Boston, MA 02111-1307, USA.  */
00022 
00023 #ifndef _PT_MACHINE_H
00024 #define _PT_MACHINE_H   1
00025 
00026 #ifndef PT_EI
00027 # define PT_EI extern inline __attribute__ ((always_inline))
00028 #endif
00029 
00030 #ifdef __linux__
00031 # include <asm/pal.h>
00032 #else
00033 # include <machine/pal.h>
00034 #endif
00035 
00036 extern long int testandset (int *spinlock);
00037 extern int __compare_and_swap (long int *p, long int oldval, long int newval);
00038 
00039 /* Get some notion of the current stack.  Need not be exactly the top
00040    of the stack, just something somewhere in the current frame.  */
00041 #define CURRENT_STACK_FRAME  stack_pointer
00042 register char *stack_pointer __asm__("$30");
00043 
00044 
00045 /* Memory barrier; default is to do nothing */
00046 #define MEMORY_BARRIER() __asm__ __volatile__("mb" : : : "memory")
00047 /* Write barrier.  */
00048 #define WRITE_MEMORY_BARRIER() __asm__ __volatile__("wmb" : : : "memory")
00049 
00050 
00051 /* Spinlock implementation; required.  */
00052 PT_EI long int
00053 testandset (int *spinlock)
00054 {
00055   long int ret, temp;
00056 
00057   __asm__ __volatile__(
00058        "/* Inline spinlock test & set */\n"
00059        "1:\t"
00060        "ldl_l %0,%3\n\t"
00061        "bne %0,2f\n\t"
00062        "or $31,1,%1\n\t"
00063        "stl_c %1,%2\n\t"
00064        "beq %1,1b\n"
00065        "2:\tmb\n"
00066        "/* End spinlock test & set */"
00067        : "=&r"(ret), "=&r"(temp), "=m"(*spinlock)
00068        : "m"(*spinlock)
00069         : "memory");
00070 
00071   return ret;
00072 }
00073 
00074 
00075 /* Begin allocating thread stacks at this address.  Default is to allocate
00076    them just below the initial program stack.  */
00077 #define THREAD_STACK_START_ADDRESS  0x40000000000
00078 
00079 
00080 /* Return the thread descriptor for the current thread.  */
00081 #define THREAD_SELF \
00082 ({                                                                   \
00083   register pthread_descr __self __asm__("$0");                              \
00084   __asm__ ("call_pal %1" : "=r"(__self) : "i"(PAL_rduniq));                 \
00085   __self;                                                            \
00086 })
00087 
00088 /* Initialize the thread-unique value.  */
00089 #define INIT_THREAD_SELF(descr, nr) \
00090 {                                                                    \
00091   register pthread_descr __self __asm__("$16") = (descr);                   \
00092   __asm__ __volatile__ ("call_pal %1" : : "r"(__self), "i"(PAL_wruniq));      \
00093 }
00094 
00095 
00096 /* Compare-and-swap for semaphores. */
00097 
00098 #define HAS_COMPARE_AND_SWAP
00099 PT_EI int
00100 __compare_and_swap (long int *p, long int oldval, long int newval)
00101 {
00102   long int ret;
00103 
00104   __asm__ __volatile__ (
00105        "/* Inline compare & swap */\n"
00106        "1:\t"
00107        "ldq_l %0,%4\n\t"
00108        "cmpeq %0,%2,%0\n\t"
00109        "beq %0,2f\n\t"
00110        "mov %3,%0\n\t"
00111        "stq_c %0,%1\n\t"
00112        "beq %0,1b\n\t"
00113        "2:\tmb\n"
00114        "/* End compare & swap */"
00115        : "=&r"(ret), "=m"(*p)
00116        : "r"(oldval), "r"(newval), "m"(*p)
00117         : "memory");
00118 
00119   return ret;
00120 }
00121 
00122 /* We want the OS to assign stack addresses.  */
00123 #define FLOATING_STACKS 1
00124 
00125 /* Maximum size of the stack if the rlimit is unlimited.  */
00126 #define ARCH_STACK_MAX_SIZE     32*1024*1024
00127 
00128 #endif /* pt-machine.h */