diff --git a/common/lib/libc/arch/arm/atomic/Makefile.inc b/common/lib/libc/arch/arm/atomic/Makefile.inc index 600f3aa0b311..2985cb26277c 100644 --- a/common/lib/libc/arch/arm/atomic/Makefile.inc +++ b/common/lib/libc/arch/arm/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.5 2008/02/11 14:21:12 ad Exp $ +# $NetBSD: Makefile.inc,v 1.6 2008/04/29 20:57:50 scw Exp $ .if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c") @@ -12,5 +12,7 @@ SRCS+= atomic_add_32_cas.c atomic_add_32_nv_cas.c atomic_and_32_cas.c \ .if defined(LIB) && (${LIB} == "c") SRCS+= atomic_init_testset.c +SRCS+= atomic_cas_up.S +CPPFLAGS+= -D__HAVE_ASM_ATOMIC_CAS_UP .endif diff --git a/common/lib/libc/arch/arm/atomic/atomic_cas_up.S b/common/lib/libc/arch/arm/atomic/atomic_cas_up.S new file mode 100644 index 000000000000..ba585a717a5b --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_cas_up.S @@ -0,0 +1,43 @@ +/* $NetBSD: atomic_cas_up.S,v 1.1 2008/04/29 20:57:50 scw Exp $ */ + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Steve C. Woodford. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +ENTRY_NP(_atomic_cas_up) + .hidden _C_LABEL(_atomic_cas_up) + mov r3, r0 +RAS_START_ASM_HIDDEN(_atomic_cas) + ldr r0, [r3] + cmp r0, r1 + streq r2, [r3] +RAS_END_ASM_HIDDEN(_atomic_cas) + RET diff --git a/common/lib/libc/arch/m68k/atomic/Makefile.inc b/common/lib/libc/arch/m68k/atomic/Makefile.inc index 26b5838dfc74..c36a6f761eed 100644 --- a/common/lib/libc/arch/m68k/atomic/Makefile.inc +++ b/common/lib/libc/arch/m68k/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.6 2008/04/06 04:01:56 tsutsui Exp $ +# $NetBSD: Makefile.inc,v 1.7 2008/04/29 20:57:50 scw Exp $ # # Note: The atomic operations here in these assembly files are atomic @@ -33,6 +33,8 @@ SRCS+= atomic_init_cas.c .else SRCS+= atomic_init_testset.c +SRCS+= atomic_cas_68000.S +CPPFLAGS+= -D__HAVE_ASM_ATOMIC_CAS_UP .endif .endif diff --git a/common/lib/libc/arch/m68k/atomic/atomic_cas_68000.S b/common/lib/libc/arch/m68k/atomic/atomic_cas_68000.S new file mode 100644 index 000000000000..9ab68c281dda --- /dev/null +++ b/common/lib/libc/arch/m68k/atomic/atomic_cas_68000.S @@ -0,0 +1,49 @@ +/* $NetBSD: atomic_cas_68000.S,v 1.1 2008/04/29 20:57:50 scw Exp $ */ + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Steve C. Woodford. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "atomic_op_asm.h" + + .text + +ENTRY_NOPROFILE(_atomic_cas_up) + .hidden _C_LABEL(_atomic_cas_up) + + movl %sp@(4), %a0 /* Fetch ptr */ + +RAS_START_ASM_HIDDEN(_atomic_cas) + movl %a0@, d0 /* d0 = *ptr */ + cmp %sp@(8), d0 /* Same as old? */ + jne 1f /* Nope */ + movl %sp@(12), %a0@ /* *ptr = new */ +RAS_END_ASM_HIDDEN(_atomic_cas) +1: rts + diff --git a/common/lib/libc/atomic/atomic_init_testset.c b/common/lib/libc/atomic/atomic_init_testset.c index 6be35aeaaa4f..87256f24360e 100644 --- a/common/lib/libc/atomic/atomic_init_testset.c +++ b/common/lib/libc/atomic/atomic_init_testset.c @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_init_testset.c,v 1.4 2008/04/28 20:22:53 martin Exp $ */ +/* $NetBSD: atomic_init_testset.c,v 1.5 2008/04/29 20:57:50 scw Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ */ #include -__RCSID("$NetBSD: atomic_init_testset.c,v 1.4 2008/04/28 20:22:53 martin Exp $"); +__RCSID("$NetBSD: atomic_init_testset.c,v 1.5 2008/04/29 20:57:50 scw Exp $"); #include "atomic_op_namespace.h" @@ -59,6 +59,9 @@ void __libc_atomic_init(void) __attribute__ ((visibility("hidden"))); RAS_DECL(_atomic_cas); +#ifdef __HAVE_ASM_ATOMIC_CAS_UP +extern uint32_t _atomic_cas_up(volatile uint32_t *, uint32_t, uint32_t); +#else static uint32_t _atomic_cas_up(volatile uint32_t *ptr, uint32_t old, uint32_t new) { @@ -74,6 +77,7 @@ _atomic_cas_up(volatile uint32_t *ptr, uint32_t old, uint32_t new) return ret; } +#endif static uint32_t _atomic_cas_mp(volatile uint32_t *ptr, uint32_t old, uint32_t new)