pt-machine.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public License as
  9. published by the Free Software Foundation; either version 2.1 of the
  10. License, or (at your option) any later version.
  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. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; see the file COPYING.LIB. If not,
  17. see <http://www.gnu.org/licenses/>. */
  18. #ifndef _PT_MACHINE_H
  19. #define _PT_MACHINE_H 1
  20. #include <features.h>
  21. #ifndef PT_EI
  22. # define PT_EI __extern_always_inline
  23. #endif
  24. #ifdef __linux__
  25. # include <asm/pal.h>
  26. #else
  27. # include <machine/pal.h>
  28. #endif
  29. /* Get some notion of the current stack. Need not be exactly the top
  30. of the stack, just something somewhere in the current frame. */
  31. #define CURRENT_STACK_FRAME stack_pointer
  32. register char *stack_pointer __asm__("$30");
  33. /* Memory barrier; default is to do nothing */
  34. #define MEMORY_BARRIER() __asm__ __volatile__("mb" : : : "memory")
  35. /* Write barrier. */
  36. #define WRITE_MEMORY_BARRIER() __asm__ __volatile__("wmb" : : : "memory")
  37. /* Spinlock implementation; required. */
  38. PT_EI long int
  39. testandset (int *spinlock)
  40. {
  41. long int ret, temp;
  42. __asm__ __volatile__(
  43. "/* Inline spinlock test & set */\n"
  44. "1:\t"
  45. "ldl_l %0,%3\n\t"
  46. "bne %0,2f\n\t"
  47. "or $31,1,%1\n\t"
  48. "stl_c %1,%2\n\t"
  49. "beq %1,1b\n"
  50. "2:\tmb\n"
  51. "/* End spinlock test & set */"
  52. : "=&r"(ret), "=&r"(temp), "=m"(*spinlock)
  53. : "m"(*spinlock)
  54. : "memory");
  55. return ret;
  56. }
  57. /* Begin allocating thread stacks at this address. Default is to allocate
  58. them just below the initial program stack. */
  59. #define THREAD_STACK_START_ADDRESS 0x40000000000
  60. /* Return the thread descriptor for the current thread. */
  61. #define THREAD_SELF \
  62. ({ \
  63. register pthread_descr __self __asm__("$0"); \
  64. __asm__ ("call_pal %1" : "=r"(__self) : "i"(PAL_rduniq)); \
  65. __self; \
  66. })
  67. /* Initialize the thread-unique value. */
  68. #define INIT_THREAD_SELF(descr, nr) \
  69. { \
  70. register pthread_descr __self __asm__("$16") = (descr); \
  71. __asm__ __volatile__ ("call_pal %1" : : "r"(__self), "i"(PAL_wruniq)); \
  72. }
  73. /* Compare-and-swap for semaphores. */
  74. #define HAS_COMPARE_AND_SWAP
  75. PT_EI int
  76. __compare_and_swap (long int *p, long int oldval, long int newval)
  77. {
  78. long int ret;
  79. __asm__ __volatile__ (
  80. "/* Inline compare & swap */\n"
  81. "1:\t"
  82. "ldq_l %0,%4\n\t"
  83. "cmpeq %0,%2,%0\n\t"
  84. "beq %0,2f\n\t"
  85. "mov %3,%0\n\t"
  86. "stq_c %0,%1\n\t"
  87. "beq %0,1b\n\t"
  88. "2:\tmb\n"
  89. "/* End compare & swap */"
  90. : "=&r"(ret), "=m"(*p)
  91. : "r"(oldval), "r"(newval), "m"(*p)
  92. : "memory");
  93. return ret;
  94. }
  95. /* We want the OS to assign stack addresses. */
  96. #define FLOATING_STACKS 1
  97. /* Maximum size of the stack if the rlimit is unlimited. */
  98. #define ARCH_STACK_MAX_SIZE 32*1024*1024
  99. #endif /* pt-machine.h */