sem_wait.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <sysdep.h>
  16. #include <pthread-errnos.h>
  17. #include <tcb-offsets.h>
  18. #include "lowlevel-atomic.h"
  19. #define SYS_gettimeofday __NR_gettimeofday
  20. #define FUTEX_WAIT 0
  21. #define FUTEX_WAKE 1
  22. .text
  23. .globl __new_sem_wait
  24. .type __new_sem_wait,@function
  25. .align 5
  26. cfi_startproc
  27. __new_sem_wait:
  28. /* First check for cancellation. */
  29. stc gbr, r0
  30. mov.w .Lchand, r1
  31. mov.l @(r0,r1), r0
  32. mov #0xf9, r1
  33. and r1, r0
  34. cmp/eq #8, r0
  35. bt 5f
  36. mov.l r8, @-r15
  37. cfi_adjust_cfa_offset(4)
  38. cfi_rel_offset (r8, 0)
  39. mov.l r10, @-r15
  40. cfi_adjust_cfa_offset(4)
  41. cfi_rel_offset (r10, 0)
  42. mov.l r12, @-r15
  43. cfi_adjust_cfa_offset(4)
  44. cfi_rel_offset (r12, 0)
  45. sts.l pr, @-r15
  46. cfi_adjust_cfa_offset(4)
  47. cfi_rel_offset (pr, 0)
  48. mov r4, r8
  49. 3:
  50. mov.l @r8, r0
  51. 2:
  52. tst r0, r0
  53. bt 1f
  54. mov r0, r3
  55. mov r0, r4
  56. add #-1, r3
  57. CMPXCHG (r4, @r8, r3, r2)
  58. bf/s 2b
  59. mov r2, r0
  60. bra 9f
  61. mov #0, r0
  62. 1:
  63. mov.l .Lenable0, r1
  64. bsrf r1
  65. nop
  66. .Lenable0b:
  67. mov r0, r10
  68. mov r8, r4
  69. mov #FUTEX_WAIT, r5
  70. mov #0, r6
  71. mov #0, r7
  72. mov #SYS_futex, r3
  73. extu.b r3, r3
  74. trapa #0x14
  75. SYSCALL_INST_PAD
  76. mov.l .Ldisable0, r1
  77. mov r10, r4
  78. bsrf r1
  79. mov r0, r10
  80. .Ldisable0b:
  81. mov r10, r0
  82. tst r0, r0
  83. bt 3b
  84. cmp/eq #-EWOULDBLOCK, r0
  85. bt 3b
  86. neg r0, r0
  87. mov r0, r8
  88. mova .Lgot0, r0
  89. mov.l .Lgot0, r12
  90. add r0, r12
  91. #if USE___THREAD
  92. mov.l .Lerrno0, r0
  93. stc gbr, r1
  94. mov.l @(r0, r12), r0
  95. bra .Lexit
  96. add r1, r0
  97. .align 2
  98. .Lerrno0:
  99. .long errno@GOTTPOFF
  100. .Lexit:
  101. #else
  102. mov.l .Lerrloc0, r1
  103. bsrf r1
  104. nop
  105. .Lerrloc0b:
  106. #endif
  107. mov.l r8, @r0
  108. mov #-1, r0
  109. 9:
  110. lds.l @r15+, pr
  111. mov.l @r15+, r12
  112. mov.l @r15+, r10
  113. rts
  114. mov.l @r15+, r8
  115. 5:
  116. /* Canceled. */
  117. stc gbr, r0
  118. mov.w .Lresult, r1
  119. mov #-1, r2
  120. mov.l r2, @(r0,r1)
  121. mov.w .Lchand, r0
  122. or.b #0x10, @(r0,gbr)
  123. stc gbr, r0
  124. mov.w .Lclbuf, r1
  125. mov.l .Lunwind, r2
  126. braf r2
  127. mov.l @(r0,r1), r4
  128. .Lunwindb:
  129. cfi_endproc
  130. .Lchand:
  131. .word CANCELHANDLING - TLS_PRE_TCB_SIZE
  132. .Lresult:
  133. .word RESULT - TLS_PRE_TCB_SIZE
  134. .Lclbuf:
  135. .word CLEANUP_JMP_BUF - TLS_PRE_TCB_SIZE
  136. .align 2
  137. .Lgot0:
  138. .long _GLOBAL_OFFSET_TABLE_
  139. #if !USE___THREAD
  140. .Lerrloc0:
  141. .long __errno_location@PLT-(.Lerrloc0b-.)
  142. #endif
  143. .Lenable0:
  144. .long __pthread_enable_asynccancel-.Lenable0b
  145. .Ldisable0:
  146. .long __pthread_disable_asynccancel-.Ldisable0b
  147. .Lunwind:
  148. .long HIDDEN_JUMPTARGET (__pthread_unwind)-.Lunwindb
  149. .size __new_sem_wait,.-__new_sem_wait
  150. weak_alias(__new_sem_wait, sem_wait)