pt-machine.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If
  15. not, see <http://www.gnu.org/licenses/>. */
  16. #ifndef _PT_MACHINE_H
  17. #define _PT_MACHINE_H 1
  18. #include <features.h>
  19. #include <ia64intrin.h>
  20. #include <sys/types.h>
  21. extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
  22. size_t __child_stack_size, int __flags, void *__arg, ...);
  23. #ifndef PT_EI
  24. # define PT_EI __extern_always_inline
  25. #endif
  26. /* Make sure gcc doesn't try to be clever and move things around on
  27. us. We need to use _exactly_ the address the user gave us, not some
  28. alias that contains the same information. */
  29. #define __atomic_fool_gcc(x) (*(volatile struct { int a[100]; } *)x)
  30. #ifndef ELF_MACHINE_NAME
  31. #define NEED_SEPARATE_REGISTER_STACK
  32. /* We want the OS to assign stack addresses. */
  33. #define FLOATING_STACKS 1
  34. /* Maximum size of the stack if the rlimit is unlimited. */
  35. #define ARCH_STACK_MAX_SIZE 32*1024*1024
  36. /* Get some notion of the current stack. Need not be exactly the top
  37. of the stack, just something somewhere in the current frame.
  38. r12 (sp) is the stack pointer. */
  39. #define CURRENT_STACK_FRAME stack_pointer
  40. register char *stack_pointer __asm__ ("sp");
  41. /* Register r13 (tp) is reserved by the ABI as "thread pointer". */
  42. struct _pthread_descr_struct;
  43. register struct _pthread_descr_struct *__thread_self __asm__("r13");
  44. /* Return the thread descriptor for the current thread. */
  45. #define THREAD_SELF __thread_self
  46. /* Initialize the thread-unique value. */
  47. #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr))
  48. /* Access to data in the thread descriptor is easy. */
  49. #define THREAD_GETMEM(descr, member) \
  50. ((void) sizeof (descr), THREAD_SELF->member)
  51. #define THREAD_GETMEM_NC(descr, member) \
  52. ((void) sizeof (descr), THREAD_SELF->member)
  53. #define THREAD_SETMEM(descr, member, value) \
  54. ((void) sizeof (descr), THREAD_SELF->member = (value))
  55. #define THREAD_SETMEM_NC(descr, member, value) \
  56. ((void) sizeof (descr), THREAD_SELF->member = (value))
  57. /* Memory barrier */
  58. #define MEMORY_BARRIER() __sync_synchronize ()
  59. #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
  60. PT_EI int
  61. __compare_and_swap (long int *p, long int oldval, long int newval)
  62. {
  63. long int readval;
  64. __asm__ __volatile__
  65. ("mov ar.ccv=%4;;\n\t"
  66. "cmpxchg8.acq %0=%1,%2,ar.ccv"
  67. : "=r" (readval), "=m" (__atomic_fool_gcc (p))
  68. : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval)
  69. : "memory");
  70. return readval == oldval;
  71. }
  72. PT_EI int
  73. __compare_and_swap_with_release_semantics (long int *p,
  74. long int oldval,
  75. long int newval)
  76. {
  77. long int readval;
  78. __asm__ __volatile__
  79. ("mov ar.ccv=%4;;\n\t"
  80. "cmpxchg8.rel %0=%1,%2,ar.ccv"
  81. : "=r" (readval), "=m" (__atomic_fool_gcc (p))
  82. : "r"(newval), "m" (__atomic_fool_gcc (p)), "r" (oldval)
  83. : "memory");
  84. return readval == oldval;
  85. }
  86. #endif /* ELF_MACHINE_NAME */
  87. /* Spinlock implementation; required. */
  88. PT_EI long int
  89. testandset (int *spinlock)
  90. {
  91. long int ret;
  92. __asm__ __volatile__(
  93. "xchg4 %0=%1,%2"
  94. : "=r"(ret), "=m"(__atomic_fool_gcc (spinlock))
  95. : "r"(1), "m"(__atomic_fool_gcc (spinlock))
  96. : "memory");
  97. return ret;
  98. }
  99. /* Indicate that we are looping. */
  100. #define BUSY_WAIT_NOP __asm__ ("hint @pause")
  101. #endif /* pt-machine.h */