xref: /openbmc/linux/arch/csky/kernel/atomic.S (revision 62e59c4e)
1/* SPDX-License-Identifier: GPL-2.0 */
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#include <linux/linkage.h>
5#include <abi/entry.h>
6
7.text
8
9/*
10 * int csky_cmpxchg(int oldval, int newval, int *ptr)
11 *
12 * If *ptr != oldval && return 1,
13 * else *ptr = newval return 0.
14 */
15#ifdef CONFIG_CPU_HAS_LDSTEX
16ENTRY(csky_cmpxchg)
17	USPTOKSP
18	mfcr	a3, epc
19	INCTRAP	a3
20
21	subi    sp, 8
22	stw     a3, (sp, 0)
23	mfcr    a3, epsr
24	stw     a3, (sp, 4)
25
26	psrset	ee
271:
28	ldex	a3, (a2)
29	cmpne	a0, a3
30	bt16	2f
31	mov	a3, a1
32	stex	a3, (a2)
33	bez	a3, 1b
342:
35	sync.is
36	mvc	a0
37	ldw	a3, (sp, 0)
38	mtcr	a3, epc
39	ldw     a3, (sp, 4)
40	mtcr	a3, epsr
41	addi	sp, 8
42	KSPTOUSP
43	rte
44END(csky_cmpxchg)
45#else
46ENTRY(csky_cmpxchg)
47	USPTOKSP
48	mfcr	a3, epc
49	INCTRAP	a3
50
51	subi    sp, 8
52	stw     a3, (sp, 0)
53	mfcr    a3, epsr
54	stw     a3, (sp, 4)
55
56	psrset	ee
571:
58	ldw	a3, (a2)
59	cmpne	a0, a3
60	bt16	3f
612:
62	stw	a1, (a2)
633:
64	mvc	a0
65	ldw	a3, (sp, 0)
66	mtcr	a3, epc
67	ldw     a3, (sp, 4)
68	mtcr	a3, epsr
69	addi	sp, 8
70	KSPTOUSP
71	rte
72END(csky_cmpxchg)
73
74/*
75 * Called from tlbmodified exception
76 */
77ENTRY(csky_cmpxchg_fixup)
78	mfcr	a0, epc
79	lrw	a1, 2b
80	cmpne	a1, a0
81	bt	1f
82	subi	a1, (2b - 1b)
83	stw	a1, (sp, LSAVE_PC)
841:
85	rts
86END(csky_cmpxchg_fixup)
87#endif
88