xref: /netbsd-src/common/lib/libc/arch/arm/atomic/atomic_swap_16.S (revision 8e8c0784cfc7904978df419ced10b97609ae1746)
1*8e8c0784Sskrll/*	$NetBSD: atomic_swap_16.S,v 1.7 2021/07/28 07:32:20 skrll Exp $ */
2918e319dSmatt
3918e319dSmatt/*-
4918e319dSmatt * Copyright (c) 2013 The NetBSD Foundation, Inc.
5918e319dSmatt * All rights reserved.
6918e319dSmatt *
7918e319dSmatt * This code is derived from software contributed to The NetBSD Foundation
8918e319dSmatt * by Matt Thomas of 3am Software Foundry.
9918e319dSmatt *
10918e319dSmatt * Redistribution and use in source and binary forms, with or without
11918e319dSmatt * modification, are permitted provided that the following conditions
12918e319dSmatt * are met:
13918e319dSmatt * 1. Redistributions of source code must retain the above copyright
14918e319dSmatt *    notice, this list of conditions and the following disclaimer.
15918e319dSmatt * 2. Redistributions in binary form must reproduce the above copyright
16918e319dSmatt *    notice, this list of conditions and the following disclaimer in the
17918e319dSmatt *    documentation and/or other materials provided with the distribution.
18918e319dSmatt *
19918e319dSmatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20918e319dSmatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21918e319dSmatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22918e319dSmatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23918e319dSmatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24918e319dSmatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25918e319dSmatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26918e319dSmatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27918e319dSmatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28918e319dSmatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29918e319dSmatt * POSSIBILITY OF SUCH DAMAGE.
30918e319dSmatt */
31918e319dSmatt
32918e319dSmatt#include "atomic_op_asm.h"
33918e319dSmatt
345e911a38Sskrll#if defined(_ARM_ARCH_6)
355e911a38Sskrll
36*8e8c0784SskrllENTRY_NP(__sync_lock_test_and_set_2)
37*8e8c0784Sskrll	DMB
38*8e8c0784Sskrll	/* FALLTHROUGH */
39*8e8c0784Sskrll
40918e319dSmattENTRY_NP(_atomic_swap_16)
41918e319dSmatt	mov	ip, r0
42918e319dSmatt1:
43918e319dSmatt	ldrexh	r0, [ip]
44918e319dSmatt	strexh	r3, r1, [ip]
45918e319dSmatt	cmp	r3, #0
46918e319dSmatt	bne	1b
47918e319dSmatt	RET
48918e319dSmattEND(_atomic_swap_16)
49*8e8c0784SskrllEND(__sync_lock_test_and_set_2)
50918e319dSmatt
51918e319dSmattATOMIC_OP_ALIAS(atomic_swap_16,_atomic_swap_16)
52918e319dSmattATOMIC_OP_ALIAS(atomic_swap_short,_atomic_swap_16)
53918e319dSmattATOMIC_OP_ALIAS(atomic_swap_ushort,_atomic_swap_16)
54bd7dee05SjoergCRT_ALIAS(__atomic_exchange_2,_atomic_swap_16)
55918e319dSmattSTRONG_ALIAS(_atomic_swap_short,_atomic_swap_16)
56918e319dSmattSTRONG_ALIAS(_atomic_swap_ushort,_atomic_swap_16)
57918e319dSmatt
58*8e8c0784Sskrll
59b4bb7421Sjustin#if (!defined(_KERNEL) || !defined(_RUMPKERNEL)) && !defined(_STANDALONE)
60918e319dSmattENTRY_NP(__sync_lock_release_2)
61918e319dSmatt	mov	r1, #0
62*8e8c0784Sskrll	DMB
63918e319dSmatt	strh	r1, [r0]
64918e319dSmatt	RET
65918e319dSmattEND(__sync_lock_release_2)
66ab7ecd2cSmatt#endif
67918e319dSmatt#endif /* _ARM_ARCH_6 */
68