pt-machine.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, see <http://www.gnu.org/licenses/>. */
  18. #ifndef _PT_MACHINE_H
  19. #define _PT_MACHINE_H 1
  20. #include <features.h>
  21. #include <sgidefs.h>
  22. #include <sys/tas.h>
  23. #ifndef PT_EI
  24. # define PT_EI __extern_always_inline
  25. #endif
  26. /* Spinlock implementation; required. */
  27. PT_EI long int
  28. testandset (int *spinlock)
  29. {
  30. return _test_and_set (spinlock, 1);
  31. }
  32. /* Get some notion of the current stack. Need not be exactly the top
  33. of the stack, just something somewhere in the current frame. */
  34. #define CURRENT_STACK_FRAME stack_pointer
  35. register char * stack_pointer __asm__ ("$29");
  36. /* Compare-and-swap for semaphores. */
  37. #define HAS_COMPARE_AND_SWAP
  38. PT_EI int
  39. __compare_and_swap (long int *p, long int oldval, long int newval)
  40. {
  41. long int ret, temp;
  42. __asm__ __volatile__
  43. ("/* Inline compare & swap */\n"
  44. "1:\n\t"
  45. ".set push\n\t"
  46. #if _MIPS_SIM == _ABIO32
  47. ".set mips2\n\t"
  48. #endif
  49. #if _MIPS_SIM == _ABI64
  50. "lld %1,%5\n\t"
  51. #else
  52. "ll %1,%5\n\t"
  53. #endif
  54. "move %0,$0\n\t"
  55. "bne %1,%3,2f\n\t"
  56. "move %0,%4\n\t"
  57. #if _MIPS_SIM == _ABI64
  58. "scd %0,%2\n\t"
  59. #else
  60. "sc %0,%2\n\t"
  61. #endif
  62. ".set pop\n\t"
  63. "beqz %0,1b\n"
  64. "2:\n\t"
  65. "/* End compare & swap */"
  66. : "=&r" (ret), "=&r" (temp), "=m" (*p)
  67. : "r" (oldval), "r" (newval), "m" (*p)
  68. : "memory");
  69. return ret;
  70. }
  71. #endif /* pt-machine.h */