xref: /openbmc/linux/arch/x86/lib/atomic64_386_32.S (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
2a7e926abSLuca Barbieri/*
3a7e926abSLuca Barbieri * atomic64_t for 386/486
4a7e926abSLuca Barbieri *
5a7e926abSLuca Barbieri * Copyright © 2010  Luca Barbieri
6a7e926abSLuca Barbieri */
7a7e926abSLuca Barbieri
8a7e926abSLuca Barbieri#include <linux/linkage.h>
95e21a3ecSJuergen Gross#include <asm/alternative.h>
10a7e926abSLuca Barbieri
11a7e926abSLuca Barbieri/* if you want SMP support, implement these with real spinlocks */
1222da5a07SPeter Zijlstra.macro IRQ_SAVE reg
13131484c8SIngo Molnar	pushfl
14a7e926abSLuca Barbieri	cli
15a7e926abSLuca Barbieri.endm
16a7e926abSLuca Barbieri
1722da5a07SPeter Zijlstra.macro IRQ_RESTORE reg
18131484c8SIngo Molnar	popfl
19a7e926abSLuca Barbieri.endm
20a7e926abSLuca Barbieri
2122da5a07SPeter Zijlstra#define BEGIN_IRQ_SAVE(op) \
22417484d4SLuca Barbieri.macro endp; \
236d685e53SJiri SlabySYM_FUNC_END(atomic64_##op##_386); \
24417484d4SLuca Barbieri.purgem endp; \
2530246557SLuca Barbieri.endm; \
266d685e53SJiri SlabySYM_FUNC_START(atomic64_##op##_386); \
2722da5a07SPeter Zijlstra	IRQ_SAVE v;
28a7e926abSLuca Barbieri
29417484d4SLuca Barbieri#define ENDP endp
30417484d4SLuca Barbieri
3122da5a07SPeter Zijlstra#define RET_IRQ_RESTORE \
3222da5a07SPeter Zijlstra	IRQ_RESTORE v; \
33*f94909ceSPeter Zijlstra	RET
34a7e926abSLuca Barbieri
3522da5a07SPeter Zijlstra#define v %ecx
3622da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(read)
3722da5a07SPeter Zijlstra	movl  (v), %eax
3822da5a07SPeter Zijlstra	movl 4(v), %edx
3922da5a07SPeter Zijlstra	RET_IRQ_RESTORE
40417484d4SLuca BarbieriENDP
4130246557SLuca Barbieri#undef v
42a7e926abSLuca Barbieri
4330246557SLuca Barbieri#define v %esi
4422da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(set)
4530246557SLuca Barbieri	movl %ebx,  (v)
4630246557SLuca Barbieri	movl %ecx, 4(v)
4722da5a07SPeter Zijlstra	RET_IRQ_RESTORE
4822da5a07SPeter ZijlstraENDP
4930246557SLuca Barbieri#undef v
50a7e926abSLuca Barbieri
5130246557SLuca Barbieri#define v  %esi
5222da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(xchg)
5330246557SLuca Barbieri	movl  (v), %eax
5430246557SLuca Barbieri	movl 4(v), %edx
5530246557SLuca Barbieri	movl %ebx,  (v)
5630246557SLuca Barbieri	movl %ecx, 4(v)
5722da5a07SPeter Zijlstra	RET_IRQ_RESTORE
5822da5a07SPeter ZijlstraENDP
5930246557SLuca Barbieri#undef v
60a7e926abSLuca Barbieri
6130246557SLuca Barbieri#define v %ecx
6222da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(add)
6330246557SLuca Barbieri	addl %eax,  (v)
6430246557SLuca Barbieri	adcl %edx, 4(v)
6522da5a07SPeter Zijlstra	RET_IRQ_RESTORE
6622da5a07SPeter ZijlstraENDP
6730246557SLuca Barbieri#undef v
68a7e926abSLuca Barbieri
6930246557SLuca Barbieri#define v %ecx
7022da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(add_return)
7130246557SLuca Barbieri	addl  (v), %eax
7230246557SLuca Barbieri	adcl 4(v), %edx
7330246557SLuca Barbieri	movl %eax,  (v)
7430246557SLuca Barbieri	movl %edx, 4(v)
7522da5a07SPeter Zijlstra	RET_IRQ_RESTORE
7622da5a07SPeter ZijlstraENDP
7730246557SLuca Barbieri#undef v
78a7e926abSLuca Barbieri
7930246557SLuca Barbieri#define v %ecx
8022da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(sub)
8130246557SLuca Barbieri	subl %eax,  (v)
8230246557SLuca Barbieri	sbbl %edx, 4(v)
8322da5a07SPeter Zijlstra	RET_IRQ_RESTORE
8422da5a07SPeter ZijlstraENDP
8530246557SLuca Barbieri#undef v
8630246557SLuca Barbieri
8730246557SLuca Barbieri#define v %ecx
8822da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(sub_return)
89a7e926abSLuca Barbieri	negl %edx
90a7e926abSLuca Barbieri	negl %eax
91a7e926abSLuca Barbieri	sbbl $0, %edx
9230246557SLuca Barbieri	addl  (v), %eax
9330246557SLuca Barbieri	adcl 4(v), %edx
9430246557SLuca Barbieri	movl %eax,  (v)
9530246557SLuca Barbieri	movl %edx, 4(v)
9622da5a07SPeter Zijlstra	RET_IRQ_RESTORE
9722da5a07SPeter ZijlstraENDP
9830246557SLuca Barbieri#undef v
99a7e926abSLuca Barbieri
10030246557SLuca Barbieri#define v %esi
10122da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(inc)
10230246557SLuca Barbieri	addl $1,  (v)
10330246557SLuca Barbieri	adcl $0, 4(v)
10422da5a07SPeter Zijlstra	RET_IRQ_RESTORE
10522da5a07SPeter ZijlstraENDP
10630246557SLuca Barbieri#undef v
107a7e926abSLuca Barbieri
10830246557SLuca Barbieri#define v %esi
10922da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(inc_return)
11030246557SLuca Barbieri	movl  (v), %eax
11130246557SLuca Barbieri	movl 4(v), %edx
112a7e926abSLuca Barbieri	addl $1, %eax
113a7e926abSLuca Barbieri	adcl $0, %edx
11430246557SLuca Barbieri	movl %eax,  (v)
11530246557SLuca Barbieri	movl %edx, 4(v)
11622da5a07SPeter Zijlstra	RET_IRQ_RESTORE
11722da5a07SPeter ZijlstraENDP
11830246557SLuca Barbieri#undef v
119a7e926abSLuca Barbieri
12030246557SLuca Barbieri#define v %esi
12122da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(dec)
12230246557SLuca Barbieri	subl $1,  (v)
12330246557SLuca Barbieri	sbbl $0, 4(v)
12422da5a07SPeter Zijlstra	RET_IRQ_RESTORE
12522da5a07SPeter ZijlstraENDP
12630246557SLuca Barbieri#undef v
127a7e926abSLuca Barbieri
12830246557SLuca Barbieri#define v %esi
12922da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(dec_return)
13030246557SLuca Barbieri	movl  (v), %eax
13130246557SLuca Barbieri	movl 4(v), %edx
132a7e926abSLuca Barbieri	subl $1, %eax
133a7e926abSLuca Barbieri	sbbl $0, %edx
13430246557SLuca Barbieri	movl %eax,  (v)
13530246557SLuca Barbieri	movl %edx, 4(v)
13622da5a07SPeter Zijlstra	RET_IRQ_RESTORE
13722da5a07SPeter ZijlstraENDP
13830246557SLuca Barbieri#undef v
139a7e926abSLuca Barbieri
140cb8095bbSJan Beulich#define v %esi
14122da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(add_unless)
142cb8095bbSJan Beulich	addl %eax, %ecx
143a7e926abSLuca Barbieri	adcl %edx, %edi
14430246557SLuca Barbieri	addl  (v), %eax
14530246557SLuca Barbieri	adcl 4(v), %edx
146cb8095bbSJan Beulich	cmpl %eax, %ecx
147a7e926abSLuca Barbieri	je 3f
148a7e926abSLuca Barbieri1:
14930246557SLuca Barbieri	movl %eax,  (v)
15030246557SLuca Barbieri	movl %edx, 4(v)
1516e6104feSLuca Barbieri	movl $1, %eax
152a7e926abSLuca Barbieri2:
15322da5a07SPeter Zijlstra	RET_IRQ_RESTORE
154a7e926abSLuca Barbieri3:
155a7e926abSLuca Barbieri	cmpl %edx, %edi
156a7e926abSLuca Barbieri	jne 1b
1576e6104feSLuca Barbieri	xorl %eax, %eax
158a7e926abSLuca Barbieri	jmp 2b
159417484d4SLuca BarbieriENDP
16030246557SLuca Barbieri#undef v
161a7e926abSLuca Barbieri
16230246557SLuca Barbieri#define v %esi
16322da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(inc_not_zero)
16430246557SLuca Barbieri	movl  (v), %eax
16530246557SLuca Barbieri	movl 4(v), %edx
166a7e926abSLuca Barbieri	testl %eax, %eax
167a7e926abSLuca Barbieri	je 3f
168a7e926abSLuca Barbieri1:
169a7e926abSLuca Barbieri	addl $1, %eax
170a7e926abSLuca Barbieri	adcl $0, %edx
17130246557SLuca Barbieri	movl %eax,  (v)
17230246557SLuca Barbieri	movl %edx, 4(v)
173f3e83131SLuca Barbieri	movl $1, %eax
174a7e926abSLuca Barbieri2:
17522da5a07SPeter Zijlstra	RET_IRQ_RESTORE
176a7e926abSLuca Barbieri3:
177a7e926abSLuca Barbieri	testl %edx, %edx
178a7e926abSLuca Barbieri	jne 1b
179a7e926abSLuca Barbieri	jmp 2b
180417484d4SLuca BarbieriENDP
18130246557SLuca Barbieri#undef v
182a7e926abSLuca Barbieri
18330246557SLuca Barbieri#define v %esi
18422da5a07SPeter ZijlstraBEGIN_IRQ_SAVE(dec_if_positive)
18530246557SLuca Barbieri	movl  (v), %eax
18630246557SLuca Barbieri	movl 4(v), %edx
187a7e926abSLuca Barbieri	subl $1, %eax
188a7e926abSLuca Barbieri	sbbl $0, %edx
189a7e926abSLuca Barbieri	js 1f
19030246557SLuca Barbieri	movl %eax,  (v)
19130246557SLuca Barbieri	movl %edx, 4(v)
192a7e926abSLuca Barbieri1:
19322da5a07SPeter Zijlstra	RET_IRQ_RESTORE
19422da5a07SPeter ZijlstraENDP
19530246557SLuca Barbieri#undef v
196