pt-machine.h 4.6 KB

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