pt-machine.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. 64 bit S/390 version.
  3. Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
  4. Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
  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, see <http://www.gnu.org/licenses/>. */
  17. #ifndef _PT_MACHINE_H
  18. #define _PT_MACHINE_H 1
  19. #ifndef PT_EI
  20. # define PT_EI __extern_always_inline
  21. #endif
  22. extern long int testandset (int *spinlock);
  23. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  24. /* For multiprocessor systems, we want to ensure all memory accesses
  25. are completed before we reset a lock. On other systems, we still
  26. need to make sure that the compiler has flushed everything to memory. */
  27. #define MEMORY_BARRIER() __asm__ __volatile__ ("bcr 15,0" : : : "memory")
  28. /* Spinlock implementation; required. */
  29. PT_EI long int
  30. testandset (int *spinlock)
  31. {
  32. int ret;
  33. __asm__ __volatile__(
  34. " la 1,%1\n"
  35. " lhi 0,1\n"
  36. " l %0,%1\n"
  37. "0: cs %0,0,0(1)\n"
  38. " jl 0b"
  39. : "=&d" (ret), "+m" (*spinlock)
  40. : : "0", "1", "cc");
  41. return ret;
  42. }
  43. /* Get some notion of the current stack. Need not be exactly the top
  44. of the stack, just something somewhere in the current frame. */
  45. #define CURRENT_STACK_FRAME stack_pointer
  46. register char * stack_pointer __asm__ ("15");
  47. #ifdef __UCLIBC_HAS_TLS__
  48. /* Return the thread descriptor for the current thread. */
  49. # define THREAD_SELF ((pthread_descr) __builtin_thread_pointer ())
  50. /* Initialize the thread-unique value. */
  51. #define INIT_THREAD_SELF(descr, nr) __builtin_set_thread_pointer (descr)
  52. #else
  53. /* Return the thread descriptor for the current thread.
  54. 64 bit S/390 uses access register 0 and 1 as "thread register". */
  55. #define THREAD_SELF ({ \
  56. register pthread_descr __self; \
  57. __asm__ (" ear %0,%%a0\n" \
  58. " sllg %0,%0,32\n" \
  59. " ear %0,%%a1\n" \
  60. : "=d" (__self) ); \
  61. __self; \
  62. })
  63. /* Initialize the thread-unique value. */
  64. #define INIT_THREAD_SELF(descr, nr) ({ \
  65. __asm__ (" sar %%a1,%0\n" \
  66. " srlg 0,%0,32\n" \
  67. " sar %%a0,0\n" \
  68. : : "d" (descr) : "0" ); \
  69. })
  70. #endif
  71. /* Access to data in the thread descriptor is easy. */
  72. #define THREAD_GETMEM(descr, member) \
  73. ((void) sizeof (descr), THREAD_SELF->member)
  74. #define THREAD_GETMEM_NC(descr, member) \
  75. ((void) sizeof (descr), THREAD_SELF->member)
  76. #define THREAD_SETMEM(descr, member, value) \
  77. ((void) sizeof (descr), THREAD_SELF->member = (value))
  78. #define THREAD_SETMEM_NC(descr, member, value) \
  79. ((void) sizeof (descr), THREAD_SELF->member = (value))
  80. /* We want the OS to assign stack addresses. */
  81. #define FLOATING_STACKS 1
  82. /* Maximum size of the stack if the rlimit is unlimited. */
  83. #define ARCH_STACK_MAX_SIZE 8*1024*1024
  84. /* Compare-and-swap for semaphores. */
  85. #define HAS_COMPARE_AND_SWAP
  86. PT_EI int
  87. __compare_and_swap(long int *p, long int oldval, long int newval)
  88. {
  89. int retval;
  90. __asm__ __volatile__(
  91. " lgr 0,%2\n"
  92. " csg 0,%3,%1\n"
  93. " ipm %0\n"
  94. " srl %0,28\n"
  95. "0:"
  96. : "=&d" (retval), "+m" (*p)
  97. : "d" (oldval) , "d" (newval)
  98. : "cc", "0");
  99. return retval == 0;
  100. }
  101. #endif /* pt-machine.h */