1*84d9c625SLionel Sambuc/* $NetBSD: atomic_dec_32.S,v 1.5 2013/08/11 04:41:17 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_dec_32) 36*84d9c625SLionel Sambuc1: ldrex r3, [r0] /* load old value (return value) */ 37*84d9c625SLionel Sambuc subs 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_dec_32) 48*84d9c625SLionel Sambuc 49b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_32,_atomic_dec_32) 50b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_uint,_atomic_dec_32) 51b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ulong,_atomic_dec_32) 52b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ptr,_atomic_dec_32) 53b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_uint,_atomic_dec_32) 54b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ulong,_atomic_dec_32) 55b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ptr,_atomic_dec_32) 56b6cbf720SGianluca Guida 57b6cbf720SGianluca GuidaENTRY_NP(_atomic_dec_32_nv) 58*84d9c625SLionel Sambuc mov ip, r0 /* need r0 for return value */ 59*84d9c625SLionel Sambuc1: ldrex r0, [ip] /* load old value */ 60*84d9c625SLionel Sambuc subs r0, r0, #1 /* calculate new value (return value) */ 61*84d9c625SLionel Sambuc strex r2, r0, [ip] /* try to store */ 62*84d9c625SLionel Sambuc cmp r2, #0 /* succeed? */ 63b6cbf720SGianluca Guida bne 1b /* no, try again? */ 64f14fb602SLionel Sambuc#ifdef _ARM_ARCH_7 65f14fb602SLionel Sambuc dmb 66f14fb602SLionel Sambuc#else 67*84d9c625SLionel Sambuc mcr p15, 0, r2, c7, c10, 5 /* data memory barrier */ 68f14fb602SLionel Sambuc#endif 69b6cbf720SGianluca Guida RET /* return new value */ 70b6cbf720SGianluca GuidaEND(_atomic_dec_32_nv) 71*84d9c625SLionel Sambuc 72b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_32_nv,_atomic_dec_32_nv) 73b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_uint_nv,_atomic_dec_32_nv) 74b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ulong_nv,_atomic_dec_32_nv) 75b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_dec_ptr_nv,_atomic_dec_32_nv) 76b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_uint_nv,_atomic_dec_32_nv) 77b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ulong_nv,_atomic_dec_32_nv) 78b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_dec_ptr_nv,_atomic_dec_32_nv) 79b6cbf720SGianluca Guida 80b6cbf720SGianluca Guida#endif /* _ARM_ARCH_6 */ 81