yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 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 not, |
| 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #ifndef _PT_MACHINE_H |
| 22 | #define _PT_MACHINE_H 1 |
| 23 | |
| 24 | #include <features.h> |
| 25 | #include <ia64intrin.h> |
| 26 | |
| 27 | #ifndef PT_EI |
| 28 | # define PT_EI __extern_always_inline |
| 29 | #endif |
| 30 | |
| 31 | /* Make sure gcc doesn't try to be clever and move things around on |
| 32 | us. We need to use _exactly_ the address the user gave us, not some |
| 33 | alias that contains the same information. */ |
| 34 | #define __atomic_fool_gcc(x) (*(__volatile__ struct { int a[100]; } *)x) |
| 35 | |
| 36 | #ifndef ELF_MACHINE_NAME |
| 37 | |
| 38 | #define NEED_SEPARATE_REGISTER_STACK |
| 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 32*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 | r12 (sp) is the stack pointer. */ |
| 49 | #define CURRENT_STACK_FRAME stack_pointer |
| 50 | register char *stack_pointer __asm__ ("sp"); |
| 51 | |
| 52 | |
| 53 | /* Register r13 (tp) is reserved by the ABI as "thread pointer". */ |
| 54 | struct _pthread_descr_struct; |
| 55 | register struct _pthread_descr_struct *__thread_self __asm__("r13"); |
| 56 | |
| 57 | /* Return the thread descriptor for the current thread. */ |
| 58 | #define THREAD_SELF __thread_self |
| 59 | |
| 60 | /* Initialize the thread-unique value. */ |
| 61 | #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr)) |
| 62 | |
| 63 | |
| 64 | /* Access to data in the thread descriptor is easy. */ |
| 65 | #define THREAD_GETMEM(descr, member) \ |
| 66 | ((void) sizeof (descr), THREAD_SELF->member) |
| 67 | #define THREAD_GETMEM_NC(descr, member) \ |
| 68 | ((void) sizeof (descr), THREAD_SELF->member) |
| 69 | #define THREAD_SETMEM(descr, member, value) \ |
| 70 | ((void) sizeof (descr), THREAD_SELF->member = (value)) |
| 71 | #define THREAD_SETMEM_NC(descr, member, value) \ |
| 72 | ((void) sizeof (descr), THREAD_SELF->member = (value)) |
| 73 | |
| 74 | |
| 75 | /* Memory barrier */ |
| 76 | #define MEMORY_BARRIER() __sync_synchronize () |
| 77 | |
| 78 | |
| 79 | #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS |
| 80 | |
| 81 | PT_EI int |
| 82 | __compare_and_swap (long int *p, long int oldval, long int newval) |
| 83 | { |
| 84 | long int readval; |
| 85 | |
| 86 | __asm__ __volatile__ |
| 87 | ("mov ar.ccv=%4;;\n\t" |
| 88 | "cmpxchg8.acq %0=%1,%2,ar.ccv" |
| 89 | : "=r" (readval), "=m" (__atomic_fool_gcc (p)) |
| 90 | : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval) |
| 91 | : "memory"); |
| 92 | return readval == oldval; |
| 93 | } |
| 94 | |
| 95 | PT_EI int |
| 96 | __compare_and_swap_with_release_semantics (long int *p, |
| 97 | long int oldval, |
| 98 | long int newval) |
| 99 | { |
| 100 | long int readval; |
| 101 | |
| 102 | __asm__ __volatile__ |
| 103 | ("mov ar.ccv=%4;;\n\t" |
| 104 | "cmpxchg8.rel %0=%1,%2,ar.ccv" |
| 105 | : "=r" (readval), "=m" (__atomic_fool_gcc (p)) |
| 106 | : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval) |
| 107 | : "memory"); |
| 108 | return readval == oldval; |
| 109 | } |
| 110 | |
| 111 | #endif /* ELF_MACHINE_NAME */ |
| 112 | |
| 113 | /* Spinlock implementation; required. */ |
| 114 | PT_EI long int |
| 115 | testandset (int *spinlock) |
| 116 | { |
| 117 | long int ret; |
| 118 | |
| 119 | __asm__ __volatile__( |
| 120 | "xchg4 %0=%1,%2" |
| 121 | : "=r"(ret), "=m"(__atomic_fool_gcc (spinlock)) |
| 122 | : "r"(1), "m"(__atomic_fool_gcc (spinlock)) |
| 123 | : "memory"); |
| 124 | |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | /* Indicate that we are looping. */ |
| 129 | #define BUSY_WAIT_NOP __asm__ ("hint @pause") |
| 130 | |
| 131 | #endif /* pt-machine.h */ |