pt-machine.h 3.5 KB

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