xref: /netbsd-src/common/lib/libc/arch/or1k/atomic/atomic_swap_32.S (revision 09ff5f3b480cb7eb269d9eec28950bf196ce206c)
1*09ff5f3bSriastradh/*	$NetBSD: atomic_swap_32.S,v 1.2 2022/04/06 22:47:56 riastradh Exp $	*/
227620987Smatt
327620987Smatt/*-
427620987Smatt * Copyright (c) 2007,2012 The NetBSD Foundation, Inc.
527620987Smatt * All rights reserved.
627620987Smatt *
727620987Smatt * This code is derived from software contributed to The NetBSD Foundation
827620987Smatt * by Jason R. Thorpe and Matt Thomas.
927620987Smatt *
1027620987Smatt * Redistribution and use in source and binary forms, with or without
1127620987Smatt * modification, are permitted provided that the following conditions
1227620987Smatt * are met:
1327620987Smatt * 1. Redistributions of source code must retain the above copyright
1427620987Smatt *    notice, this list of conditions and the following disclaimer.
1527620987Smatt * 2. Redistributions in binary form must reproduce the above copyright
1627620987Smatt *    notice, this list of conditions and the following disclaimer in the
1727620987Smatt *    documentation and/or other materials provided with the distribution.
1827620987Smatt *
1927620987Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2027620987Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2127620987Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2227620987Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2327620987Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2427620987Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2527620987Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2627620987Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2727620987Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2827620987Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2927620987Smatt * POSSIBILITY OF SUCH DAMAGE.
3027620987Smatt */
3127620987Smatt
3227620987Smatt#include "atomic_op_asm.h"
3327620987Smatt
3427620987SmattENTRY_NP(_atomic_swap_32)
3527620987Smatt1:	l.lwa	r11, 0(r3)
3627620987Smatt	l.swa	0(r3), r4
3727620987Smatt	l.bnf	1b
3827620987Smatt	l.nop
3927620987Smatt2:	l.jr	lr
4027620987Smatt	l.nop
4127620987SmattEND(_atomic_swap_32)
4227620987Smatt
4327620987SmattATOMIC_OP_ALIAS(atomic_swap_32,_atomic_swap_32)
4427620987SmattATOMIC_OP_ALIAS(atomic_swap_uint,_atomic_swap_32)
4527620987SmattATOMIC_OP_ALIAS(atomic_swap_ulong,_atomic_swap_32)
4627620987SmattATOMIC_OP_ALIAS(atomic_swap_ptr,_atomic_swap_32)
4727620987SmattCRT_ALIAS(__sync_lock_test_and_set_4,_atomic_swap_32)
4827620987SmattCRT_ALIAS(__atomic_exchange_4,_atomic_swap_32)
4927620987SmattSTRONG_ALIAS(_atomic_swap_uint,_atomic_swap_32)
5027620987SmattSTRONG_ALIAS(_atomic_swap_ulong,_atomic_swap_32)
5127620987SmattSTRONG_ALIAS(_atomic_swap_ptr,_atomic_swap_32)
5227620987Smatt
5327620987Smatt#if (!defined(_KERNEL) || defined(_RUMPKERNEL)) && !defined(_STANDALONE)
5427620987SmattENTRY_NP(__sync_lock_release_4)
5527620987Smatt	l.sw	0(r3), r0
5627620987Smatt	l.jr	lr
5727620987Smatt	l.nop
5827620987SmattEND(__sync_lock_release_4)
5927620987Smatt#endif
60