atomic64_386_32.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * atomic64_t for 386/486
  3. *
  4. * Copyright © 2010 Luca Barbieri
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/linkage.h>
  12. #include <asm/alternative-asm.h>
  13. #include <asm/dwarf2.h>
  14. /* if you want SMP support, implement these with real spinlocks */
  15. .macro LOCK reg
  16. pushfl
  17. CFI_ADJUST_CFA_OFFSET 4
  18. cli
  19. .endm
  20. .macro UNLOCK reg
  21. popfl
  22. CFI_ADJUST_CFA_OFFSET -4
  23. .endm
  24. #define BEGIN(op) \
  25. .macro endp; \
  26. CFI_ENDPROC; \
  27. ENDPROC(atomic64_##op##_386); \
  28. .purgem endp; \
  29. .endm; \
  30. ENTRY(atomic64_##op##_386); \
  31. CFI_STARTPROC; \
  32. LOCK v;
  33. #define ENDP endp
  34. #define RET \
  35. UNLOCK v; \
  36. ret
  37. #define RET_ENDP \
  38. RET; \
  39. ENDP
  40. #define v %ecx
  41. BEGIN(read)
  42. movl (v), %eax
  43. movl 4(v), %edx
  44. RET_ENDP
  45. #undef v
  46. #define v %esi
  47. BEGIN(set)
  48. movl %ebx, (v)
  49. movl %ecx, 4(v)
  50. RET_ENDP
  51. #undef v
  52. #define v %esi
  53. BEGIN(xchg)
  54. movl (v), %eax
  55. movl 4(v), %edx
  56. movl %ebx, (v)
  57. movl %ecx, 4(v)
  58. RET_ENDP
  59. #undef v
  60. #define v %ecx
  61. BEGIN(add)
  62. addl %eax, (v)
  63. adcl %edx, 4(v)
  64. RET_ENDP
  65. #undef v
  66. #define v %ecx
  67. BEGIN(add_return)
  68. addl (v), %eax
  69. adcl 4(v), %edx
  70. movl %eax, (v)
  71. movl %edx, 4(v)
  72. RET_ENDP
  73. #undef v
  74. #define v %ecx
  75. BEGIN(sub)
  76. subl %eax, (v)
  77. sbbl %edx, 4(v)
  78. RET_ENDP
  79. #undef v
  80. #define v %ecx
  81. BEGIN(sub_return)
  82. negl %edx
  83. negl %eax
  84. sbbl $0, %edx
  85. addl (v), %eax
  86. adcl 4(v), %edx
  87. movl %eax, (v)
  88. movl %edx, 4(v)
  89. RET_ENDP
  90. #undef v
  91. #define v %esi
  92. BEGIN(inc)
  93. addl $1, (v)
  94. adcl $0, 4(v)
  95. RET_ENDP
  96. #undef v
  97. #define v %esi
  98. BEGIN(inc_return)
  99. movl (v), %eax
  100. movl 4(v), %edx
  101. addl $1, %eax
  102. adcl $0, %edx
  103. movl %eax, (v)
  104. movl %edx, 4(v)
  105. RET_ENDP
  106. #undef v
  107. #define v %esi
  108. BEGIN(dec)
  109. subl $1, (v)
  110. sbbl $0, 4(v)
  111. RET_ENDP
  112. #undef v
  113. #define v %esi
  114. BEGIN(dec_return)
  115. movl (v), %eax
  116. movl 4(v), %edx
  117. subl $1, %eax
  118. sbbl $0, %edx
  119. movl %eax, (v)
  120. movl %edx, 4(v)
  121. RET_ENDP
  122. #undef v
  123. #define v %ecx
  124. BEGIN(add_unless)
  125. addl %eax, %esi
  126. adcl %edx, %edi
  127. addl (v), %eax
  128. adcl 4(v), %edx
  129. cmpl %eax, %esi
  130. je 3f
  131. 1:
  132. movl %eax, (v)
  133. movl %edx, 4(v)
  134. movl $1, %eax
  135. 2:
  136. RET
  137. 3:
  138. cmpl %edx, %edi
  139. jne 1b
  140. xorl %eax, %eax
  141. jmp 2b
  142. ENDP
  143. #undef v
  144. #define v %esi
  145. BEGIN(inc_not_zero)
  146. movl (v), %eax
  147. movl 4(v), %edx
  148. testl %eax, %eax
  149. je 3f
  150. 1:
  151. addl $1, %eax
  152. adcl $0, %edx
  153. movl %eax, (v)
  154. movl %edx, 4(v)
  155. movl $1, %eax
  156. 2:
  157. RET
  158. 3:
  159. testl %edx, %edx
  160. jne 1b
  161. jmp 2b
  162. ENDP
  163. #undef v
  164. #define v %esi
  165. BEGIN(dec_if_positive)
  166. movl (v), %eax
  167. movl 4(v), %edx
  168. subl $1, %eax
  169. sbbl $0, %edx
  170. js 1f
  171. movl %eax, (v)
  172. movl %edx, 4(v)
  173. 1:
  174. RET_ENDP
  175. #undef v