blob: 3b6544111ac92dc310f23e4919b699e541ea3c56 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Luca Barbieria7e926a2010-02-24 10:54:25 +01002/*
3 * atomic64_t for 386/486
4 *
5 * Copyright © 2010 Luca Barbieri
Luca Barbieria7e926a2010-02-24 10:54:25 +01006 */
7
8#include <linux/linkage.h>
9#include <asm/alternative-asm.h>
Luca Barbieria7e926a2010-02-24 10:54:25 +010010
11/* if you want SMP support, implement these with real spinlocks */
12.macro LOCK reg
Ingo Molnar131484c2015-05-28 12:21:47 +020013 pushfl
Luca Barbieria7e926a2010-02-24 10:54:25 +010014 cli
15.endm
16
17.macro UNLOCK reg
Ingo Molnar131484c2015-05-28 12:21:47 +020018 popfl
Luca Barbieria7e926a2010-02-24 10:54:25 +010019.endm
20
Luca Barbieri30246552010-08-06 04:04:38 +020021#define BEGIN(op) \
Luca Barbieri417484d2010-08-12 07:00:35 -070022.macro endp; \
Jiri Slaby6d685e52019-10-11 13:51:07 +020023SYM_FUNC_END(atomic64_##op##_386); \
Luca Barbieri417484d2010-08-12 07:00:35 -070024.purgem endp; \
Luca Barbieri30246552010-08-06 04:04:38 +020025.endm; \
Jiri Slaby6d685e52019-10-11 13:51:07 +020026SYM_FUNC_START(atomic64_##op##_386); \
Luca Barbieri30246552010-08-06 04:04:38 +020027 LOCK v;
Luca Barbieria7e926a2010-02-24 10:54:25 +010028
Luca Barbieri417484d2010-08-12 07:00:35 -070029#define ENDP endp
30
Luca Barbieri30246552010-08-06 04:04:38 +020031#define RET \
32 UNLOCK v; \
Luca Barbieria7e926a2010-02-24 10:54:25 +010033 ret
Luca Barbieria7e926a2010-02-24 10:54:25 +010034
Luca Barbieri417484d2010-08-12 07:00:35 -070035#define RET_ENDP \
Luca Barbieri30246552010-08-06 04:04:38 +020036 RET; \
Luca Barbieri417484d2010-08-12 07:00:35 -070037 ENDP
Luca Barbieria7e926a2010-02-24 10:54:25 +010038
Luca Barbieri30246552010-08-06 04:04:38 +020039#define v %ecx
40BEGIN(read)
41 movl (v), %eax
42 movl 4(v), %edx
Luca Barbieri417484d2010-08-12 07:00:35 -070043RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +020044#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +010045
Luca Barbieri30246552010-08-06 04:04:38 +020046#define v %esi
47BEGIN(set)
48 movl %ebx, (v)
49 movl %ecx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -070050RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +020051#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +010052
Luca Barbieri30246552010-08-06 04:04:38 +020053#define v %esi
54BEGIN(xchg)
55 movl (v), %eax
56 movl 4(v), %edx
57 movl %ebx, (v)
58 movl %ecx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -070059RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +020060#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +010061
Luca Barbieri30246552010-08-06 04:04:38 +020062#define v %ecx
63BEGIN(add)
64 addl %eax, (v)
65 adcl %edx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -070066RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +020067#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +010068
Luca Barbieri30246552010-08-06 04:04:38 +020069#define v %ecx
70BEGIN(add_return)
71 addl (v), %eax
72 adcl 4(v), %edx
73 movl %eax, (v)
74 movl %edx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -070075RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +020076#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +010077
Luca Barbieri30246552010-08-06 04:04:38 +020078#define v %ecx
79BEGIN(sub)
80 subl %eax, (v)
81 sbbl %edx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -070082RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +020083#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +010084
Luca Barbieri30246552010-08-06 04:04:38 +020085#define v %ecx
86BEGIN(sub_return)
Luca Barbieria7e926a2010-02-24 10:54:25 +010087 negl %edx
88 negl %eax
89 sbbl $0, %edx
Luca Barbieri30246552010-08-06 04:04:38 +020090 addl (v), %eax
91 adcl 4(v), %edx
92 movl %eax, (v)
93 movl %edx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -070094RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +020095#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +010096
Luca Barbieri30246552010-08-06 04:04:38 +020097#define v %esi
98BEGIN(inc)
99 addl $1, (v)
100 adcl $0, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -0700101RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +0200102#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +0100103
Luca Barbieri30246552010-08-06 04:04:38 +0200104#define v %esi
105BEGIN(inc_return)
106 movl (v), %eax
107 movl 4(v), %edx
Luca Barbieria7e926a2010-02-24 10:54:25 +0100108 addl $1, %eax
109 adcl $0, %edx
Luca Barbieri30246552010-08-06 04:04:38 +0200110 movl %eax, (v)
111 movl %edx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -0700112RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +0200113#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +0100114
Luca Barbieri30246552010-08-06 04:04:38 +0200115#define v %esi
116BEGIN(dec)
117 subl $1, (v)
118 sbbl $0, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -0700119RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +0200120#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +0100121
Luca Barbieri30246552010-08-06 04:04:38 +0200122#define v %esi
123BEGIN(dec_return)
124 movl (v), %eax
125 movl 4(v), %edx
Luca Barbieria7e926a2010-02-24 10:54:25 +0100126 subl $1, %eax
127 sbbl $0, %edx
Luca Barbieri30246552010-08-06 04:04:38 +0200128 movl %eax, (v)
129 movl %edx, 4(v)
Luca Barbieri417484d2010-08-12 07:00:35 -0700130RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +0200131#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +0100132
Jan Beulichcb8095b2012-01-20 16:22:04 +0000133#define v %esi
Luca Barbieri30246552010-08-06 04:04:38 +0200134BEGIN(add_unless)
Jan Beulichcb8095b2012-01-20 16:22:04 +0000135 addl %eax, %ecx
Luca Barbieria7e926a2010-02-24 10:54:25 +0100136 adcl %edx, %edi
Luca Barbieri30246552010-08-06 04:04:38 +0200137 addl (v), %eax
138 adcl 4(v), %edx
Jan Beulichcb8095b2012-01-20 16:22:04 +0000139 cmpl %eax, %ecx
Luca Barbieria7e926a2010-02-24 10:54:25 +0100140 je 3f
1411:
Luca Barbieri30246552010-08-06 04:04:38 +0200142 movl %eax, (v)
143 movl %edx, 4(v)
Luca Barbieri6e6104f2010-03-01 19:55:46 +0100144 movl $1, %eax
Luca Barbieria7e926a2010-02-24 10:54:25 +01001452:
Luca Barbieri30246552010-08-06 04:04:38 +0200146 RET
Luca Barbieria7e926a2010-02-24 10:54:25 +01001473:
148 cmpl %edx, %edi
149 jne 1b
Luca Barbieri6e6104f2010-03-01 19:55:46 +0100150 xorl %eax, %eax
Luca Barbieria7e926a2010-02-24 10:54:25 +0100151 jmp 2b
Luca Barbieri417484d2010-08-12 07:00:35 -0700152ENDP
Luca Barbieri30246552010-08-06 04:04:38 +0200153#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +0100154
Luca Barbieri30246552010-08-06 04:04:38 +0200155#define v %esi
156BEGIN(inc_not_zero)
157 movl (v), %eax
158 movl 4(v), %edx
Luca Barbieria7e926a2010-02-24 10:54:25 +0100159 testl %eax, %eax
160 je 3f
1611:
162 addl $1, %eax
163 adcl $0, %edx
Luca Barbieri30246552010-08-06 04:04:38 +0200164 movl %eax, (v)
165 movl %edx, 4(v)
Luca Barbierif3e83132010-03-01 19:55:49 +0100166 movl $1, %eax
Luca Barbieria7e926a2010-02-24 10:54:25 +01001672:
Luca Barbieri30246552010-08-06 04:04:38 +0200168 RET
Luca Barbieria7e926a2010-02-24 10:54:25 +01001693:
170 testl %edx, %edx
171 jne 1b
Luca Barbieria7e926a2010-02-24 10:54:25 +0100172 jmp 2b
Luca Barbieri417484d2010-08-12 07:00:35 -0700173ENDP
Luca Barbieri30246552010-08-06 04:04:38 +0200174#undef v
Luca Barbieria7e926a2010-02-24 10:54:25 +0100175
Luca Barbieri30246552010-08-06 04:04:38 +0200176#define v %esi
177BEGIN(dec_if_positive)
178 movl (v), %eax
179 movl 4(v), %edx
Luca Barbieria7e926a2010-02-24 10:54:25 +0100180 subl $1, %eax
181 sbbl $0, %edx
182 js 1f
Luca Barbieri30246552010-08-06 04:04:38 +0200183 movl %eax, (v)
184 movl %edx, 4(v)
Luca Barbieria7e926a2010-02-24 10:54:25 +01001851:
Luca Barbieri417484d2010-08-12 07:00:35 -0700186RET_ENDP
Luca Barbieri30246552010-08-06 04:04:38 +0200187#undef v