1*84d9c625SLionel Sambuc/* $NetBSD: atomic_inc_32.S,v 1.7 2013/11/08 22:42:52 matt Exp $ */ 2b6cbf720SGianluca Guida/*- 3b6cbf720SGianluca Guida * Copyright (c) 2008 The NetBSD Foundation, Inc. 4b6cbf720SGianluca Guida * All rights reserved. 5b6cbf720SGianluca Guida * 6b6cbf720SGianluca Guida * This code is derived from software contributed to The NetBSD Foundation 7b6cbf720SGianluca Guida * by Matt Thomas <matt@3am-software.com> 8b6cbf720SGianluca Guida * 9b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without 10b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions 11b6cbf720SGianluca Guida * are met: 12b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright 13b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer. 14b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright 15b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer in the 16b6cbf720SGianluca Guida * documentation and/or other materials provided with the distribution. 17b6cbf720SGianluca Guida * 18b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19b6cbf720SGianluca Guida * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20b6cbf720SGianluca Guida * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21b6cbf720SGianluca Guida * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22b6cbf720SGianluca Guida * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23b6cbf720SGianluca Guida * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24b6cbf720SGianluca Guida * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25b6cbf720SGianluca Guida * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26b6cbf720SGianluca Guida * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27b6cbf720SGianluca Guida * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28b6cbf720SGianluca Guida * POSSIBILITY OF SUCH DAMAGE. 29b6cbf720SGianluca Guida */ 30b6cbf720SGianluca Guida 31b6cbf720SGianluca Guida#include "atomic_op_asm.h" 32b6cbf720SGianluca Guida 33b6cbf720SGianluca Guida#ifdef _ARM_ARCH_6 34b6cbf720SGianluca Guida 35b6cbf720SGianluca GuidaENTRY_NP(_atomic_inc_32) 36*84d9c625SLionel Sambuc1: ldrex r3, [r0] /* load old value (return value) */ 37*84d9c625SLionel Sambuc adds r3, r3, #1 /* calculate new value */ 38*84d9c625SLionel Sambuc strex r2, r3, [r0] /* try to store */ 39*84d9c625SLionel Sambuc cmp r2, #0 /* succeed? */ 40b6cbf720SGianluca Guida bne 1b /* no, try again? */ 41f14fb602SLionel Sambuc#ifdef _ARM_ARCH_7 42f14fb602SLionel Sambuc dmb 43f14fb602SLionel Sambuc#else 44*84d9c625SLionel Sambuc mcr p15, 0, r2, c7, c10, 5 /* data memory barrier */ 45f14fb602SLionel Sambuc#endif 46b6cbf720SGianluca Guida RET /* return new value */ 47b6cbf720SGianluca GuidaEND(_atomic_inc_32) 48b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_32,_atomic_inc_32) 49b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_uint,_atomic_inc_32) 50b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_ulong,_atomic_inc_32) 51b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_ptr,_atomic_inc_32) 52b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_inc_uint,_atomic_inc_32) 53b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_inc_ulong,_atomic_inc_32) 54b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_inc_ptr,_atomic_inc_32) 55b6cbf720SGianluca Guida 56b6cbf720SGianluca GuidaENTRY_NP(_atomic_inc_32_nv) 57*84d9c625SLionel Sambuc mov ip, r0 /* need r0 for return value */ 58*84d9c625SLionel Sambuc1: ldrex r0, [ip] /* load old value */ 59*84d9c625SLionel Sambuc adds r0, r0, #1 /* calculate new value (return value) */ 60*84d9c625SLionel Sambuc strex r2, r0, [ip] /* try to store */ 61*84d9c625SLionel Sambuc cmp r2, #0 /* succeed? */ 62b6cbf720SGianluca Guida bne 1b /* no, try again? */ 63f14fb602SLionel Sambuc#ifdef _ARM_ARCH_7 64f14fb602SLionel Sambuc dmb 65f14fb602SLionel Sambuc#else 66*84d9c625SLionel Sambuc mcr p15, 0, r2, c7, c10, 5 /* data memory barrier */ 67f14fb602SLionel Sambuc#endif 68b6cbf720SGianluca Guida RET /* return new value */ 69b6cbf720SGianluca GuidaEND(_atomic_inc_32_nv) 70b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_32_nv,_atomic_inc_32_nv) 71b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_uint_nv,_atomic_inc_32_nv) 72b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_ulong_nv,_atomic_inc_32_nv) 73b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_inc_ptr_nv,_atomic_inc_32_nv) 74b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_inc_uint_nv,_atomic_inc_32_nv) 75b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_inc_ulong_nv,_atomic_inc_32_nv) 76b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_inc_ptr_nv,_atomic_inc_32_nv) 77b6cbf720SGianluca Guida 78*84d9c625SLionel Sambuc#endif /* _ARM_ARCH_6 */ 79