pt-machine.h 2.9 KB

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