1*0a6a1f1dSLionel Sambuc/* $NetBSD: atomic_xor_32.S,v 1.3 2014/06/23 21:53:45 joerg Exp $ */ 284d9c625SLionel Sambuc/*- 384d9c625SLionel Sambuc * Copyright (c) 2008 The NetBSD Foundation, Inc. 484d9c625SLionel Sambuc * All rights reserved. 584d9c625SLionel Sambuc * 684d9c625SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation 784d9c625SLionel Sambuc * by Matt Thomas <matt@3am-software.com> 884d9c625SLionel Sambuc * 984d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without 1084d9c625SLionel Sambuc * modification, are permitted provided that the following conditions 1184d9c625SLionel Sambuc * are met: 1284d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 1384d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer. 1484d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 1584d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 1684d9c625SLionel Sambuc * documentation and/or other materials provided with the distribution. 1784d9c625SLionel Sambuc * 1884d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1984d9c625SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2084d9c625SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2184d9c625SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2284d9c625SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2384d9c625SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2484d9c625SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2584d9c625SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2684d9c625SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2784d9c625SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2884d9c625SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE. 2984d9c625SLionel Sambuc */ 3084d9c625SLionel Sambuc 3184d9c625SLionel Sambuc#include "atomic_op_asm.h" 3284d9c625SLionel Sambuc 3384d9c625SLionel Sambuc#ifdef _ARM_ARCH_6 3484d9c625SLionel Sambuc 3584d9c625SLionel SambucENTRY_NP(_atomic_xor_32) 3684d9c625SLionel Sambuc mov ip, r0 3784d9c625SLionel Sambuc1: ldrex r0, [ip] /* load old value (to be returned) */ 3884d9c625SLionel Sambuc eors r3, r0, r1 /* calculate new value */ 3984d9c625SLionel Sambuc strex r2, r3, [ip] /* try to store */ 4084d9c625SLionel Sambuc cmp r2, #0 /* succeed? */ 4184d9c625SLionel Sambuc bne 1b /* no, try again */ 4284d9c625SLionel Sambuc#ifdef _ARM_ARCH_7 4384d9c625SLionel Sambuc dmb 4484d9c625SLionel Sambuc#else 4584d9c625SLionel Sambuc mcr p15, 0, r2, c7, c10, 5 /* data memory barrier */ 4684d9c625SLionel Sambuc#endif 4784d9c625SLionel Sambuc RET /* return old value */ 4884d9c625SLionel SambucEND(_atomic_xor_32) 4984d9c625SLionel Sambuc 5084d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_xor_32,_atomic_xor_32) 5184d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_xor_uint,_atomic_xor_32) 5284d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_xor_ulong,_atomic_xor_32) 53*0a6a1f1dSLionel SambucCRT_ALIAS(__sync_fetch_and_xor_4,_atomic_xor_32) 54*0a6a1f1dSLionel SambucCRT_ALIAS(__atomic_fetch_xor_4,_atomic_xor_32) 5584d9c625SLionel SambucSTRONG_ALIAS(_atomic_xor_uint,_atomic_xor_32) 5684d9c625SLionel SambucSTRONG_ALIAS(_atomic_xor_ulong,_atomic_xor_32) 5784d9c625SLionel Sambuc 5884d9c625SLionel SambucENTRY_NP(_atomic_xor_32_nv) 5984d9c625SLionel Sambuc mov ip, r0 /* need r0 for return value */ 6084d9c625SLionel Sambuc1: ldrex r0, [ip] /* load old value */ 6184d9c625SLionel Sambuc eors r0, r0, r1 /* calculate new value (return value) */ 6284d9c625SLionel Sambuc strex r2, r0, [ip] /* try to store */ 6384d9c625SLionel Sambuc cmp r2, #0 /* succeed? */ 6484d9c625SLionel Sambuc bne 1b /* no, try again? */ 6584d9c625SLionel Sambuc#ifdef _ARM_ARCH_7 6684d9c625SLionel Sambuc dmb 6784d9c625SLionel Sambuc#else 6884d9c625SLionel Sambuc mcr p15, 0, r2, c7, c10, 5 /* data memory barrier */ 6984d9c625SLionel Sambuc#endif 7084d9c625SLionel Sambuc RET /* return new value */ 7184d9c625SLionel SambucEND(_atomic_xor_32_nv) 7284d9c625SLionel Sambuc 7384d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_xor_32_nv,_atomic_xor_32_nv) 7484d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_xor_uint_nv,_atomic_xor_32_nv) 7584d9c625SLionel SambucATOMIC_OP_ALIAS(atomic_xor_ulong_nv,_atomic_xor_32_nv) 76*0a6a1f1dSLionel SambucCRT_ALIAS(__sync_xor_and_fetch_4,_atomic_xor_32_nv) 7784d9c625SLionel SambucSTRONG_ALIAS(_atomic_xor_uint_nv,_atomic_xor_32_nv) 7884d9c625SLionel SambucSTRONG_ALIAS(_atomic_xor_ulong_nv,_atomic_xor_32_nv) 7984d9c625SLionel Sambuc 8084d9c625SLionel Sambuc#endif /* _ARM_ARCH_6 */ 81