pt-machine.h 2.3 KB

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