atomic64_386_32.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 END; \
  26. CFI_ENDPROC; \
  27. ENDPROC(atomic64_##op##_386); \
  28. .purgem END; \
  29. .endm; \
  30. ENTRY(atomic64_##op##_386); \
  31. CFI_STARTPROC; \
  32. LOCK v;
  33. #define RET \
  34. UNLOCK v; \
  35. ret
  36. #define RET_END \
  37. RET; \
  38. END
  39. #define v %ecx
  40. BEGIN(read)
  41. movl (v), %eax
  42. movl 4(v), %edx
  43. RET_END
  44. #undef v
  45. #define v %esi
  46. BEGIN(set)
  47. movl %ebx, (v)
  48. movl %ecx, 4(v)
  49. RET_END
  50. #undef v
  51. #define v %esi
  52. BEGIN(xchg)
  53. movl (v), %eax
  54. movl 4(v), %edx
  55. movl %ebx, (v)
  56. movl %ecx, 4(v)
  57. RET_END
  58. #undef v
  59. #define v %ecx
  60. BEGIN(add)
  61. addl %eax, (v)
  62. adcl %edx, 4(v)
  63. RET_END
  64. #undef v
  65. #define v %ecx
  66. BEGIN(add_return)
  67. addl (v), %eax
  68. adcl 4(v), %edx
  69. movl %eax, (v)
  70. movl %edx, 4(v)
  71. RET_END
  72. #undef v
  73. #define v %ecx
  74. BEGIN(sub)
  75. subl %eax, (v)
  76. sbbl %edx, 4(v)
  77. RET_END
  78. #undef v
  79. #define v %ecx
  80. BEGIN(sub_return)
  81. negl %edx
  82. negl %eax
  83. sbbl $0, %edx
  84. addl (v), %eax
  85. adcl 4(v), %edx
  86. movl %eax, (v)
  87. movl %edx, 4(v)
  88. RET_END
  89. #undef v
  90. #define v %esi
  91. BEGIN(inc)
  92. addl $1, (v)
  93. adcl $0, 4(v)
  94. RET_END
  95. #undef v
  96. #define v %esi
  97. BEGIN(inc_return)
  98. movl (v), %eax
  99. movl 4(v), %edx
  100. addl $1, %eax
  101. adcl $0, %edx
  102. movl %eax, (v)
  103. movl %edx, 4(v)
  104. RET_END
  105. #undef v
  106. #define v %esi
  107. BEGIN(dec)
  108. subl $1, (v)
  109. sbbl $0, 4(v)
  110. RET_END
  111. #undef v
  112. #define v %esi
  113. BEGIN(dec_return)
  114. movl (v), %eax
  115. movl 4(v), %edx
  116. subl $1, %eax
  117. sbbl $0, %edx
  118. movl %eax, (v)
  119. movl %edx, 4(v)
  120. RET_END
  121. #undef v
  122. #define v %ecx
  123. BEGIN(add_unless)
  124. addl %eax, %esi
  125. adcl %edx, %edi
  126. addl (v), %eax
  127. adcl 4(v), %edx
  128. cmpl %eax, %esi
  129. je 3f
  130. 1:
  131. movl %eax, (v)
  132. movl %edx, 4(v)
  133. movl $1, %eax
  134. 2:
  135. RET
  136. 3:
  137. cmpl %edx, %edi
  138. jne 1b
  139. xorl %eax, %eax
  140. jmp 2b
  141. END
  142. #undef v
  143. #define v %esi
  144. BEGIN(inc_not_zero)
  145. movl (v), %eax
  146. movl 4(v), %edx
  147. testl %eax, %eax
  148. je 3f
  149. 1:
  150. addl $1, %eax
  151. adcl $0, %edx
  152. movl %eax, (v)
  153. movl %edx, 4(v)
  154. movl $1, %eax
  155. 2:
  156. RET
  157. 3:
  158. testl %edx, %edx
  159. jne 1b
  160. jmp 2b
  161. END
  162. #undef v
  163. #define v %esi
  164. BEGIN(dec_if_positive)
  165. movl (v), %eax
  166. movl 4(v), %edx
  167. subl $1, %eax
  168. sbbl $0, %edx
  169. js 1f
  170. movl %eax, (v)
  171. movl %edx, 4(v)
  172. 1:
  173. RET_END
  174. #undef v