1*0a6a1f1dSLionel Sambuc/* $NetBSD: atomic_swap.S,v 1.9 2014/06/28 20:18:55 joerg Exp $ */ 2b6cbf720SGianluca Guida 3b6cbf720SGianluca Guida/*- 4b6cbf720SGianluca Guida * Copyright (c) 2007 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 Jason R. Thorpe. 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 32b6cbf720SGianluca Guida#include "atomic_op_asm.h" 33b6cbf720SGianluca Guida 34b6cbf720SGianluca Guida .text 35b6cbf720SGianluca Guida 36b6cbf720SGianluca GuidaENTRY(_atomic_swap_32) 3784d9c625SLionel Sambuc movl 4(%sp), %a0 3884d9c625SLionel Sambuc1: movl (%a0), %d0 3984d9c625SLionel Sambuc movl 8(%sp), %d1 4084d9c625SLionel Sambuc casl %d0, %d1, (%a0) 41b6cbf720SGianluca Guida bne 1b 42b6cbf720SGianluca Guida /* %d0 now contains the old value */ 43b6cbf720SGianluca Guida movl %d0, %a0 /* pointers return also in %a0 */ 44b6cbf720SGianluca Guida rts 4584d9c625SLionel SambucEND(_atomic_swap_32) 46b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_swap_32,_atomic_swap_32) 47b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_swap_uint,_atomic_swap_32) 48b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_swap_uint,_atomic_swap_32) 49b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_swap_ulong,_atomic_swap_32) 50b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_swap_ulong,_atomic_swap_32) 51b6cbf720SGianluca GuidaATOMIC_OP_ALIAS(atomic_swap_ptr,_atomic_swap_32) 52b6cbf720SGianluca GuidaSTRONG_ALIAS(_atomic_swap_ptr,_atomic_swap_32) 53*0a6a1f1dSLionel SambucCRT_ALIAS(__sync_lock_test_and_set_4,_atomic_swap_32) 54*0a6a1f1dSLionel SambucCRT_ALIAS(__atomic_exchange_4,_atomic_swap_32) 55*0a6a1f1dSLionel Sambuc 56*0a6a1f1dSLionel Sambuc 57*0a6a1f1dSLionel SambucENTRY(_atomic_swap_16) 58*0a6a1f1dSLionel Sambuc movl 4(%sp), %a0 59*0a6a1f1dSLionel Sambuc1: movw (%a0), %d0 60*0a6a1f1dSLionel Sambuc movw 8(%sp), %d1 61*0a6a1f1dSLionel Sambuc casw %d0, %d1, (%a0) 62*0a6a1f1dSLionel Sambuc bne 1b 63*0a6a1f1dSLionel Sambuc /* %d0 now contains the old value */ 64*0a6a1f1dSLionel Sambuc rts 65*0a6a1f1dSLionel SambucEND(_atomic_swap_16) 66*0a6a1f1dSLionel SambucATOMIC_OP_ALIAS(atomic_swap_16,_atomic_swap_16) 67*0a6a1f1dSLionel SambucCRT_ALIAS(__sync_lock_test_and_set_2,_atomic_swap_16) 68*0a6a1f1dSLionel SambucCRT_ALIAS(__atomic_exchange_2,_atomic_swap_16) 69*0a6a1f1dSLionel Sambuc 70*0a6a1f1dSLionel SambucENTRY(_atomic_swap_8) 71*0a6a1f1dSLionel Sambuc movl 4(%sp), %a0 72*0a6a1f1dSLionel Sambuc1: movb (%a0), %d0 73*0a6a1f1dSLionel Sambuc movb 8(%sp), %d1 74*0a6a1f1dSLionel Sambuc casb %d0, %d1, (%a0) 75*0a6a1f1dSLionel Sambuc bne 1b 76*0a6a1f1dSLionel Sambuc /* %d0 now contains the old value */ 77*0a6a1f1dSLionel Sambuc rts 78*0a6a1f1dSLionel SambucEND(_atomic_swap_8) 79*0a6a1f1dSLionel SambucATOMIC_OP_ALIAS(atomic_swap_8,_atomic_swap_8) 80*0a6a1f1dSLionel SambucCRT_ALIAS(__sync_lock_test_and_set_1,_atomic_swap_8) 81*0a6a1f1dSLionel SambucCRT_ALIAS(__atomic_exchange_1,_atomic_swap_8) 82