1*0a6a1f1dSLionel Sambuc/* $NetBSD: atomic_cas_8.S,v 1.7 2014/03/04 16:15:28 matt Exp $ */ 284d9c625SLionel Sambuc 3b6cbf720SGianluca Guida/*- 484d9c625SLionel Sambuc * Copyright (c) 2013 The NetBSD Foundation, Inc. 5b6cbf720SGianluca Guida * All rights reserved. 6b6cbf720SGianluca Guida * 7b6cbf720SGianluca Guida * This code is derived from software contributed to The NetBSD Foundation 8b6cbf720SGianluca Guida * by Matt Thomas <matt@3am-software.com> 9b6cbf720SGianluca Guida * 10b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without 11b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions 12b6cbf720SGianluca Guida * are met: 13b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright 14b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer. 15b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright 16b6cbf720SGianluca Guida * notice, this list of conditions and the following disclaimer in the 17b6cbf720SGianluca Guida * documentation and/or other materials provided with the distribution. 18b6cbf720SGianluca Guida * 19b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20b6cbf720SGianluca Guida * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21b6cbf720SGianluca Guida * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22b6cbf720SGianluca Guida * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23b6cbf720SGianluca Guida * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24b6cbf720SGianluca Guida * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25b6cbf720SGianluca Guida * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26b6cbf720SGianluca Guida * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27b6cbf720SGianluca Guida * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28b6cbf720SGianluca Guida * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29b6cbf720SGianluca Guida * POSSIBILITY OF SUCH DAMAGE. 30b6cbf720SGianluca Guida */ 31b6cbf720SGianluca Guida 32f14fb602SLionel Sambuc#include "atomic_op_asm.h" 33b6cbf720SGianluca Guida 34f14fb602SLionel Sambuc#if defined(_ARM_ARCH_6) 35f14fb602SLionel Sambuc/* 36f14fb602SLionel Sambuc * ARMv6 has load-exclusive/store-exclusive which works for both user 37f14fb602SLionel Sambuc * and kernel. 38f14fb602SLionel Sambuc */ 39f14fb602SLionel SambucENTRY_NP(_atomic_cas_8) 4084d9c625SLionel Sambuc mov ip, r0 /* we need r0 for return value */ 41f14fb602SLionel Sambuc1: 4284d9c625SLionel Sambuc ldrexb r0, [ip] /* load old value */ 4384d9c625SLionel Sambuc cmp r0, r1 /* compare? */ 4484d9c625SLionel Sambuc#ifdef __thumb__ 4584d9c625SLionel Sambuc bne 2f 4684d9c625SLionel Sambuc#else 47f14fb602SLionel Sambuc RETc(ne) /* return if different */ 4884d9c625SLionel Sambuc#endif 4984d9c625SLionel Sambuc strexb r3, r2, [ip] /* store new value */ 5084d9c625SLionel Sambuc cmp r3, #0 /* succeed? */ 51b6cbf720SGianluca Guida bne 1b /* nope, try again. */ 52f14fb602SLionel Sambuc#ifdef _ARM_ARCH_7 53f14fb602SLionel Sambuc dsb /* data synchronization barrier */ 54f14fb602SLionel Sambuc#else 5584d9c625SLionel Sambuc mcr p15, 0, r3, c7, c10, 4 /* data synchronization barrier */ 56b6cbf720SGianluca Guida#endif 5784d9c625SLionel Sambuc2: RET /* return. */ 58f14fb602SLionel Sambuc END(_atomic_cas_8) 59f14fb602SLionel Sambuc 60f14fb602SLionel SambucATOMIC_OP_ALIAS(atomic_cas_8,_atomic_cas_8) 61f14fb602SLionel SambucSTRONG_ALIAS(_atomic_cas_char,_atomic_cas_8) 62f14fb602SLionel SambucSTRONG_ALIAS(_atomic_cas_uchar,_atomic_cas_8) 63*0a6a1f1dSLionel SambucCRT_ALIAS(__sync_val_compare_and_swap_1,_atomic_cas_8) 64f14fb602SLionel Sambuc 6584d9c625SLionel Sambuc#endif /* _ARM_ARCH_6 */ 66