pt-machine.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Alpha version.
  3. Copyright (C) 1996, 1997, 1998 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 Library General Public License as
  8. published by the Free Software Foundation; either version 2 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. Library General Public License for more details.
  14. You should have received a copy of the GNU Library 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_EI
  19. # define PT_EI extern inline
  20. #endif
  21. #include <asm/pal.h>
  22. /* Get some notion of the current stack. Need not be exactly the top
  23. of the stack, just something somewhere in the current frame. */
  24. #define CURRENT_STACK_FRAME stack_pointer
  25. register char *stack_pointer __asm__("$30");
  26. /* Spinlock implementation; required. */
  27. PT_EI long int
  28. testandset (int *spinlock)
  29. {
  30. long int ret, temp;
  31. __asm__ __volatile__(
  32. "/* Inline spinlock test & set */\n"
  33. "1:\t"
  34. "ldl_l %0,%3\n\t"
  35. "bne %0,2f\n\t"
  36. "or $31,1,%1\n\t"
  37. "stl_c %1,%2\n\t"
  38. "beq %1,1b\n"
  39. "2:\tmb\n"
  40. "/* End spinlock test & set */"
  41. : "=&r"(ret), "=&r"(temp), "=m"(*spinlock)
  42. : "m"(*spinlock)
  43. : "memory");
  44. return ret;
  45. }
  46. /* Spinlock release; default is just set to zero. */
  47. #define RELEASE(spinlock) \
  48. __asm__ __volatile__("mb" : : : "memory"); \
  49. *spinlock = 0
  50. /* Begin allocating thread stacks at this address. Default is to allocate
  51. them just below the initial program stack. */
  52. #define THREAD_STACK_START_ADDRESS 0x40000000000
  53. /* Return the thread descriptor for the current thread. */
  54. #define THREAD_SELF \
  55. ({ \
  56. register pthread_descr __self __asm__("$0"); \
  57. __asm__ ("call_pal %1" : "=r"(__self) : "i"(PAL_rduniq) : "$0"); \
  58. __self; \
  59. })
  60. /* Initialize the thread-unique value. */
  61. #define INIT_THREAD_SELF(descr, nr) \
  62. { \
  63. register pthread_descr __self __asm__("$16") = (descr); \
  64. __asm__ __volatile__ ("call_pal %1" : : "r"(__self), "i"(PAL_wruniq)); \
  65. }
  66. /* Compare-and-swap for semaphores. */
  67. #define HAS_COMPARE_AND_SWAP
  68. PT_EI int
  69. __compare_and_swap (long int *p, long int oldval, long int newval)
  70. {
  71. long int ret;
  72. __asm__ __volatile__ (
  73. "/* Inline compare & swap */\n"
  74. "1:\t"
  75. "ldq_l %0,%4\n\t"
  76. "cmpeq %0,%2,%0\n\t"
  77. "beq %0,2f\n\t"
  78. "mov %3,%0\n\t"
  79. "stq_c %0,%1\n\t"
  80. "beq %0,1b\n\t"
  81. "2:\tmb\n"
  82. "/* End compare & swap */"
  83. : "=&r"(ret), "=m"(*p)
  84. : "r"(oldval), "r"(newval), "m"(*p));
  85. return ret;
  86. }