pt-machine.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <features.h>
  20. #ifndef PT_EI
  21. # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  22. # define PT_EI static inline __attribute__((always_inline))
  23. # else
  24. # define PT_EI extern inline __attribute__((always_inline))
  25. # endif
  26. #endif
  27. #include <asm/fixed_code.h>
  28. /* Spinlock implementation; required. */
  29. /* The semantics of the TESTSET instruction cannot be guaranteed. We cannot
  30. easily move all locks used by linux kernel to non-cacheable memory.
  31. EXCPT 0x4 is used to trap into kernel to do the atomic testandset.
  32. It's ugly. But it's the only thing we can do now.
  33. The handler of EXCPT 0x4 expects the address of the lock is passed through
  34. R0. And the result is returned by R0. */
  35. PT_EI long int
  36. testandset (int *spinlock)
  37. {
  38. long int res;
  39. __asm__ __volatile__ (
  40. "CALL (%4);"
  41. : "=q0" (res), "=m" (*spinlock)
  42. : "qA" (spinlock), "m" (*spinlock), "a" (ATOMIC_XCHG32), "q1" (1)
  43. : "RETS", "cc", "memory");
  44. return res;
  45. }
  46. #define HAS_COMPARE_AND_SWAP
  47. PT_EI int
  48. __compare_and_swap (long int *p, long int oldval, long int newval)
  49. {
  50. long int readval;
  51. __asm__ __volatile__ (
  52. "CALL (%5);"
  53. : "=q0" (readval), "=m" (*p)
  54. : "qA" (p),
  55. "q1" (oldval),
  56. "q2" (newval),
  57. "a" (ATOMIC_CAS32),
  58. "m" (*p)
  59. : "RETS", "memory", "cc");
  60. return readval == oldval;
  61. }
  62. #ifdef SHARED
  63. # define PTHREAD_STATIC_FN_REQUIRE(name)
  64. #else
  65. # define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " "_"#name);
  66. #endif
  67. #endif /* pt-machine.h */