Implement _atomic_cas_up() in assembly code as the compiler cannot be

trusted to generate fully restartable code sequences.

Addresses lib/38482 for ARM and m68000.
This commit is contained in:
scw 2008-04-29 20:57:50 +00:00
parent ebbad0004d
commit 4e2c4c42b4
5 changed files with 104 additions and 4 deletions

View File

@ -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

View File

@ -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 <sys/ras.h>
#include <machine/asm.h>
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

View File

@ -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

View File

@ -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 <sys/ras.h>
#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

View File

@ -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 <sys/cdefs.h>
__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)