pt-machine.h 4.2 KB

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