xref: /netbsd-src/common/lib/libc/arch/arm/atomic/atomic_swap_64.S (revision 5298fab779741f242bc9edef59c60d92530d14f7)
1*5298fab7Sandvar/*	$NetBSD: atomic_swap_64.S,v 1.15 2021/08/01 21:58:56 andvar Exp $	*/
2b9b9bd89Smatt/*-
36e8da97cSmatt * Copyright (c) 2012 The NetBSD Foundation, Inc.
4b9b9bd89Smatt * All rights reserved.
5b9b9bd89Smatt *
6b9b9bd89Smatt * This code is derived from software contributed to The NetBSD Foundation
76e8da97cSmatt * by Matt Thomas.
8b9b9bd89Smatt *
9b9b9bd89Smatt * Redistribution and use in source and binary forms, with or without
10b9b9bd89Smatt * modification, are permitted provided that the following conditions
11b9b9bd89Smatt * are met:
12b9b9bd89Smatt * 1. Redistributions of source code must retain the above copyright
13b9b9bd89Smatt *    notice, this list of conditions and the following disclaimer.
14b9b9bd89Smatt * 2. Redistributions in binary form must reproduce the above copyright
15b9b9bd89Smatt *    notice, this list of conditions and the following disclaimer in the
16b9b9bd89Smatt *    documentation and/or other materials provided with the distribution.
17b9b9bd89Smatt *
18b9b9bd89Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19b9b9bd89Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20b9b9bd89Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21b9b9bd89Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22b9b9bd89Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23b9b9bd89Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24b9b9bd89Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25b9b9bd89Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26b9b9bd89Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27b9b9bd89Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28b9b9bd89Smatt * POSSIBILITY OF SUCH DAMAGE.
29b9b9bd89Smatt */
30b9b9bd89Smatt
31b9b9bd89Smatt#include "atomic_op_asm.h"
32b9b9bd89Smatt
338e8c0784SskrllENTRY_NP(__sync_lock_test_and_set_8)
348e8c0784Sskrll	DMB
358e8c0784Sskrll	/* FALLTHROUGH */
368e8c0784Sskrll
37b9b9bd89SmattENTRY_NP(_atomic_swap_64)
387eb7e9aaSmatt	push	{r3, r4}		/* save temporary */
39d6502094Smatt	mov	ip, r0			/* return value will be in r0 */
40b9b9bd89Smatt#ifndef __ARM_EABI__
41*5298fab7Sandvar	mov	r3, r2			/* r2 will be overwritten by r1 */
42b9b9bd89Smatt	mov	r2, r1			/* and r1 will be overwritten by ldrexd */
43b9b9bd89Smatt#endif
445ce8d6dfSjoerg1:	ldrexd	r0, r1, [ip]		/* load old value */
455ce8d6dfSjoerg	strexd	r4, r2, r3, [ip]	/* store new value */
46d6502094Smatt	cmp	r4, #0			/*   succeed? */
47b9b9bd89Smatt	bne	1b			/*    no, try again */
487eb7e9aaSmatt	pop	{r3, r4}		/* restore temporary */
49b9b9bd89Smatt	RET
50b9b9bd89SmattEND(_atomic_swap_64)
518e8c0784SskrllEND(__sync_lock_test_and_set_8)
528e8c0784Sskrll
538e8c0784Sskrll
54b9b9bd89SmattATOMIC_OP_ALIAS(atomic_swap_64,_atomic_swap_64)
55bd7dee05SjoergCRT_ALIAS(__atomic_exchange_8,_atomic_swap_64)
56918e319dSmatt
57b4bb7421Sjustin#if (!defined(_KERNEL) || !defined(_RUMPKERNEL)) && !defined(_STANDALONE)
58918e319dSmattENTRY_NP(__sync_lock_release_8)
59918e319dSmatt	mov	r2, #0
60918e319dSmatt	mov	r3, #0
618e8c0784Sskrll
628e8c0784Sskrll	DMB
635ce8d6dfSjoerg	strd	r2, r3, [r0]
64918e319dSmatt	RET
65918e319dSmattEND(__sync_lock_release_8)
66ab7ecd2cSmatt#endif
67