2018-09-05 14:25:16 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <abi/entry.h>
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
/*
|
|
|
|
* int csky_cmpxchg(int oldval, int newval, int *ptr)
|
|
|
|
*
|
|
|
|
* If *ptr != oldval && return 1,
|
|
|
|
* else *ptr = newval return 0.
|
|
|
|
*/
|
|
|
|
ENTRY(csky_cmpxchg)
|
|
|
|
USPTOKSP
|
2020-09-07 14:20:18 +08:00
|
|
|
|
|
|
|
RD_MEH a3
|
|
|
|
WR_MEH a3
|
|
|
|
|
2018-09-05 14:25:16 +08:00
|
|
|
mfcr a3, epc
|
2019-04-01 19:06:09 +08:00
|
|
|
addi a3, TRAP0_SIZE
|
2018-09-05 14:25:16 +08:00
|
|
|
|
2019-12-17 11:12:55 +08:00
|
|
|
subi sp, 16
|
2018-09-05 14:25:16 +08:00
|
|
|
stw a3, (sp, 0)
|
|
|
|
mfcr a3, epsr
|
|
|
|
stw a3, (sp, 4)
|
2019-12-17 11:12:55 +08:00
|
|
|
mfcr a3, usp
|
|
|
|
stw a3, (sp, 8)
|
2018-09-05 14:25:16 +08:00
|
|
|
|
|
|
|
psrset ee
|
2019-04-01 19:06:09 +08:00
|
|
|
#ifdef CONFIG_CPU_HAS_LDSTEX
|
2018-09-05 14:25:16 +08:00
|
|
|
1:
|
|
|
|
ldex a3, (a2)
|
|
|
|
cmpne a0, a3
|
|
|
|
bt16 2f
|
|
|
|
mov a3, a1
|
|
|
|
stex a3, (a2)
|
|
|
|
bez a3, 1b
|
|
|
|
2:
|
|
|
|
sync.is
|
|
|
|
#else
|
2020-12-24 10:02:55 +08:00
|
|
|
GLOBAL(csky_cmpxchg_ldw)
|
2018-09-05 14:25:16 +08:00
|
|
|
ldw a3, (a2)
|
|
|
|
cmpne a0, a3
|
|
|
|
bt16 3f
|
2020-12-24 10:02:55 +08:00
|
|
|
GLOBAL(csky_cmpxchg_stw)
|
2018-09-05 14:25:16 +08:00
|
|
|
stw a1, (a2)
|
|
|
|
3:
|
2019-04-01 19:06:09 +08:00
|
|
|
#endif
|
2018-09-05 14:25:16 +08:00
|
|
|
mvc a0
|
|
|
|
ldw a3, (sp, 0)
|
|
|
|
mtcr a3, epc
|
|
|
|
ldw a3, (sp, 4)
|
|
|
|
mtcr a3, epsr
|
2019-12-17 11:12:55 +08:00
|
|
|
ldw a3, (sp, 8)
|
|
|
|
mtcr a3, usp
|
|
|
|
addi sp, 16
|
2018-09-05 14:25:16 +08:00
|
|
|
KSPTOUSP
|
|
|
|
rte
|
|
|
|
END(csky_cmpxchg)
|