pt-machine.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. powerpc version.
  3. Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003
  4. Free Software Foundation, Inc.
  5. This file is part of the GNU C Library.
  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. /* These routines are from Appendix G of the 'PowerPC 601 RISC Microprocessor
  19. User's Manual', by IBM and Motorola. */
  20. #ifndef _PT_MACHINE_H
  21. #define _PT_MACHINE_H 1
  22. #ifndef PT_EI
  23. # define PT_EI __extern_always_inline
  24. #endif
  25. extern long int testandset (int *spinlock);
  26. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  27. /* For multiprocessor systems, we want to ensure all memory accesses
  28. are completed before we reset a lock. On other systems, we still
  29. need to make sure that the compiler has flushed everything to memory. */
  30. #define MEMORY_BARRIER() __asm__ __volatile__ ("sync" : : : "memory")
  31. /* We want the OS to assign stack addresses. */
  32. #define FLOATING_STACKS 1
  33. /* Maximum size of the stack if the rlimit is unlimited. */
  34. #define ARCH_STACK_MAX_SIZE 8*1024*1024
  35. /* Get some notion of the current stack. Need not be exactly the top
  36. of the stack, just something somewhere in the current frame. */
  37. #define CURRENT_STACK_FRAME stack_pointer
  38. register char * stack_pointer __asm__ ("r1");
  39. /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
  40. struct _pthread_descr_struct;
  41. register struct _pthread_descr_struct *__thread_self __asm__("r2");
  42. /* Return the thread descriptor for the current thread. */
  43. #define THREAD_SELF __thread_self
  44. /* Initialize the thread-unique value. */
  45. #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr))
  46. /* Access to data in the thread descriptor is easy. */
  47. #define THREAD_GETMEM(descr, member) \
  48. ((void) (descr), THREAD_SELF->member)
  49. #define THREAD_GETMEM_NC(descr, member) \
  50. ((void) (descr), THREAD_SELF->member)
  51. #define THREAD_SETMEM(descr, member, value) \
  52. ((void) (descr), THREAD_SELF->member = (value))
  53. #define THREAD_SETMEM_NC(descr, member, value) \
  54. ((void) (descr), THREAD_SELF->member = (value))
  55. /* Compare-and-swap for semaphores. */
  56. /* note that test-and-set(x) is the same as !compare-and-swap(x, 0, 1) */
  57. #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
  58. #define IMPLEMENT_TAS_WITH_CAS
  59. PT_EI int
  60. __compare_and_swap (long int *p, long int oldval, long int newval)
  61. {
  62. int ret;
  63. __asm__ __volatile__ (
  64. "0: lwarx %0,0,%1 ;"
  65. " xor. %0,%3,%0;"
  66. " bne 1f;"
  67. " stwcx. %2,0,%1;"
  68. " bne- 0b;"
  69. "1: "
  70. : "=&r"(ret)
  71. : "r"(p), "r"(newval), "r"(oldval)
  72. : "cr0", "memory");
  73. /* This version of __compare_and_swap is to be used when acquiring
  74. a lock, so we don't need to worry about whether other memory
  75. operations have completed, but we do need to be sure that any loads
  76. after this point really occur after we have acquired the lock. */
  77. __asm__ __volatile__ ("isync" : : : "memory");
  78. return ret == 0;
  79. }
  80. PT_EI int
  81. __compare_and_swap_with_release_semantics (long int *p,
  82. long int oldval, long int newval)
  83. {
  84. int ret;
  85. MEMORY_BARRIER ();
  86. __asm__ __volatile__ (
  87. "0: lwarx %0,0,%1 ;"
  88. " xor. %0,%3,%0;"
  89. " bne 1f;"
  90. " stwcx. %2,0,%1;"
  91. " bne- 0b;"
  92. "1: "
  93. : "=&r"(ret)
  94. : "r"(p), "r"(newval), "r"(oldval)
  95. : "cr0", "memory");
  96. return ret == 0;
  97. }
  98. #endif /* pt-machine.h */