pt-machine.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. S390 version.
  3. Copyright (C) 1999, 2000, 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. S/390 registers uses access register 0 as "thread register". */
  55. #define THREAD_SELF ({ \
  56. register pthread_descr __self; \
  57. __asm__ ("ear %0,%%a0" : "=d" (__self) ); \
  58. __self; \
  59. })
  60. /* Initialize the thread-unique value. */
  61. #define INIT_THREAD_SELF(descr, nr) ({ \
  62. __asm__ ("sar %%a0,%0" : : "d" (descr) ); \
  63. })
  64. #endif
  65. /* Access to data in the thread descriptor is easy. */
  66. #define THREAD_GETMEM(descr, member) \
  67. ((void) sizeof (descr), THREAD_SELF->member)
  68. #define THREAD_GETMEM_NC(descr, member) \
  69. ((void) sizeof (descr), THREAD_SELF->member)
  70. #define THREAD_SETMEM(descr, member, value) \
  71. ((void) sizeof (descr), THREAD_SELF->member = (value))
  72. #define THREAD_SETMEM_NC(descr, member, value) \
  73. ((void) sizeof (descr), THREAD_SELF->member = (value))
  74. /* We want the OS to assign stack addresses. */
  75. #define FLOATING_STACKS 1
  76. /* Maximum size of the stack if the rlimit is unlimited. */
  77. #define ARCH_STACK_MAX_SIZE 8*1024*1024
  78. /* Compare-and-swap for semaphores. */
  79. #define HAS_COMPARE_AND_SWAP
  80. PT_EI int
  81. __compare_and_swap(long int *p, long int oldval, long int newval)
  82. {
  83. int retval;
  84. __asm__ __volatile__(
  85. " la 1,%1\n"
  86. " lr 0,%2\n"
  87. " cs 0,%3,0(1)\n"
  88. " ipm %0\n"
  89. " srl %0,28\n"
  90. "0:"
  91. : "=&d" (retval), "+m" (*p)
  92. : "d" (oldval) , "d" (newval)
  93. : "cc", "0", "1" );
  94. return retval == 0;
  95. }
  96. #endif /* pt-machine.h */