pt-machine.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Copyright (C) 1996, 1998, 2000, 2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson <rth@tamu.edu>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If
  15. not, write to the Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. #ifndef _PT_MACHINE_H
  18. #define _PT_MACHINE_H 1
  19. #ifndef PT_EI
  20. # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  21. # define PT_EI static inline __attribute__((always_inline))
  22. # else
  23. # define PT_EI extern inline __attribute__((always_inline))
  24. # endif
  25. #endif
  26. #include <asm/fixed_code.h>
  27. /* Spinlock implementation; required. */
  28. /* The semantics of the TESTSET instruction cannot be guaranteed. We cannot
  29. easily move all locks used by linux kernel to non-cacheable memory.
  30. EXCPT 0x4 is used to trap into kernel to do the atomic testandset.
  31. It's ugly. But it's the only thing we can do now.
  32. The handler of EXCPT 0x4 expects the address of the lock is passed through
  33. R0. And the result is returned by R0. */
  34. PT_EI long int
  35. testandset (int *spinlock)
  36. {
  37. long int res;
  38. __asm__ __volatile__ (
  39. "CALL (%4);"
  40. : "=q0" (res), "=m" (*spinlock)
  41. : "qA" (spinlock), "m" (*spinlock), "a" (ATOMIC_XCHG32), "q1" (1)
  42. : "RETS", "cc", "memory");
  43. return res;
  44. }
  45. #define HAS_COMPARE_AND_SWAP
  46. PT_EI int
  47. __compare_and_swap (long int *p, long int oldval, long int newval)
  48. {
  49. long int readval;
  50. __asm__ __volatile__ (
  51. "CALL (%5);"
  52. : "=q0" (readval), "=m" (*p)
  53. : "qA" (p),
  54. "q1" (oldval),
  55. "q2" (newval),
  56. "a" (ATOMIC_CAS32),
  57. "m" (*p)
  58. : "RETS", "memory", "cc");
  59. return readval == oldval;
  60. }
  61. #ifdef SHARED
  62. # define PTHREAD_STATIC_FN_REQUIRE(name)
  63. #else
  64. # define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " "_"#name);
  65. #endif
  66. #endif /* pt-machine.h */