xref: /minix3/common/lib/libc/arch/arm/atomic/atomic_swap_16.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: atomic_swap_16.S,v 1.4 2015/05/17 20:57:11 justin Exp $ */
284d9c625SLionel Sambuc
384d9c625SLionel Sambuc/*-
484d9c625SLionel Sambuc * Copyright (c) 2013 The NetBSD Foundation, Inc.
584d9c625SLionel Sambuc * All rights reserved.
684d9c625SLionel Sambuc *
784d9c625SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
884d9c625SLionel Sambuc * by Matt Thomas of 3am Software Foundry.
984d9c625SLionel Sambuc *
1084d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without
1184d9c625SLionel Sambuc * modification, are permitted provided that the following conditions
1284d9c625SLionel Sambuc * are met:
1384d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1484d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer.
1584d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1684d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer in the
1784d9c625SLionel Sambuc *    documentation and/or other materials provided with the distribution.
1884d9c625SLionel Sambuc *
1984d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2084d9c625SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2184d9c625SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2284d9c625SLionel Sambuc * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2384d9c625SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2484d9c625SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2584d9c625SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2684d9c625SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2784d9c625SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2884d9c625SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2984d9c625SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
3084d9c625SLionel Sambuc */
3184d9c625SLionel Sambuc
3284d9c625SLionel Sambuc#include "atomic_op_asm.h"
3384d9c625SLionel Sambuc
3484d9c625SLionel Sambuc#ifdef _ARM_ARCH_6
3584d9c625SLionel SambucENTRY_NP(_atomic_swap_16)
3684d9c625SLionel Sambuc	mov	ip, r0
3784d9c625SLionel Sambuc1:
3884d9c625SLionel Sambuc	ldrexh	r0, [ip]
3984d9c625SLionel Sambuc	strexh	r3, r1, [ip]
4084d9c625SLionel Sambuc	cmp	r3, #0
4184d9c625SLionel Sambuc	bne	1b
4284d9c625SLionel Sambuc#ifdef _ARM_ARCH_7
4384d9c625SLionel Sambuc	dmb
4484d9c625SLionel Sambuc#else
4584d9c625SLionel Sambuc	mcr	p15, 0, ip, c7, c10, 5	/* data memory barrier */
4684d9c625SLionel Sambuc#endif
4784d9c625SLionel Sambuc	RET
4884d9c625SLionel SambucEND(_atomic_swap_16)
4984d9c625SLionel Sambuc
5084d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_swap_16,_atomic_swap_16)
5184d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_swap_short,_atomic_swap_16)
5284d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_swap_ushort,_atomic_swap_16)
53*0a6a1f1dSLionel SambucCRT_ALIAS(__sync_lock_test_and_set_2,_atomic_swap_16)
54*0a6a1f1dSLionel SambucCRT_ALIAS(__atomic_exchange_2,_atomic_swap_16)
5584d9c625SLionel SambucSTRONG_ALIAS(_atomic_swap_short,_atomic_swap_16)
5684d9c625SLionel SambucSTRONG_ALIAS(_atomic_swap_ushort,_atomic_swap_16)
5784d9c625SLionel Sambuc
58*0a6a1f1dSLionel Sambuc#if (!defined(_KERNEL) || !defined(_RUMPKERNEL)) && !defined(_STANDALONE)
5984d9c625SLionel SambucENTRY_NP(__sync_lock_release_2)
6084d9c625SLionel Sambuc	mov	r1, #0
6184d9c625SLionel Sambuc	strh	r1, [r0]
6284d9c625SLionel Sambuc	RET
6384d9c625SLionel SambucEND(__sync_lock_release_2)
64*0a6a1f1dSLionel Sambuc#endif
6584d9c625SLionel Sambuc#endif /* _ARM_ARCH_6 */
66