pt-machine.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004
  3. Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Ralf Baechle <ralf@gnu.org>.
  6. Based on the Alpha version 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
  17. not, write to the Free Software Foundation, Inc.,
  18. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  19. #ifndef _PT_MACHINE_H
  20. #define _PT_MACHINE_H 1
  21. #include <features.h>
  22. #ifndef PT_EI
  23. # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  24. # define PT_EI static inline __attribute__((always_inline))
  25. # else
  26. # define PT_EI extern inline __attribute__((always_inline))
  27. # endif
  28. #endif
  29. /* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
  30. This file is part of the GNU C Library.
  31. Contributed by Maciej W. Rozycki <macro@ds2.pg.gda.pl>, 2000. */
  32. static inline int
  33. __NTH (_test_and_set (int *p, int v))
  34. {
  35. int r, t;
  36. __asm__ __volatile__
  37. ("/* Inline test and set */\n"
  38. "1:\n\t"
  39. ".set push\n\t"
  40. ".set mips2\n\t"
  41. "ll %0,%3\n\t"
  42. "move %1,%4\n\t"
  43. "beq %0,%4,2f\n\t"
  44. "sc %1,%2\n\t"
  45. ".set pop\n\t"
  46. "beqz %1,1b\n"
  47. "2:\n\t"
  48. "/* End test and set */"
  49. : "=&r" (r), "=&r" (t), "=m" (*p)
  50. : "m" (*p), "r" (v)
  51. : "memory");
  52. return r;
  53. }
  54. /* Spinlock implementation; required. */
  55. PT_EI long int
  56. testandset (int *spinlock)
  57. {
  58. return _test_and_set (spinlock, 1);
  59. }
  60. /* Get some notion of the current stack. Need not be exactly the top
  61. of the stack, just something somewhere in the current frame. */
  62. #define CURRENT_STACK_FRAME stack_pointer
  63. register char * stack_pointer __asm__ ("$29");
  64. /* Compare-and-swap for semaphores. */
  65. #define HAS_COMPARE_AND_SWAP
  66. PT_EI int
  67. __compare_and_swap (long int *p, long int oldval, long int newval)
  68. {
  69. long int ret, temp;
  70. __asm__ __volatile__
  71. ("/* Inline compare & swap */\n"
  72. "1:\n\t"
  73. ".set push\n\t"
  74. ".set mips2\n\t"
  75. "ll %1,%5\n\t"
  76. "move %0,$0\n\t"
  77. "bne %1,%3,2f\n\t"
  78. "move %0,%4\n\t"
  79. "sc %0,%2\n\t"
  80. ".set pop\n\t"
  81. "beqz %0,1b\n"
  82. "2:\n\t"
  83. "/* End compare & swap */"
  84. : "=&r" (ret), "=&r" (temp), "=m" (*p)
  85. : "r" (oldval), "r" (newval), "m" (*p)
  86. : "memory");
  87. return ret;
  88. }
  89. #endif /* pt-machine.h */