Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for atomic operations to NetBSD port to lm32

  • Loading branch information...
commit 21b5975f4c9b97e5d0d517ed30540163a2b0cf9c 1 parent 75703dc
Yann Sionneau authored
View
17 common/lib/libc/arch/lm32/atomic/Makefile.inc
@@ -0,0 +1,17 @@
+# $NetBSD: Makefile.inc,v 1.5 2009/01/04 17:54:29 pooka Exp $
+
+.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
+ || ${LIB} == "rump")
+
+SRCS+= atomic_add_32_cas.c atomic_add_32_nv_cas.c atomic_and_32_cas.c \
+ atomic_and_32_nv_cas.c atomic_dec_32_cas.c atomic_dec_32_nv_cas.c \
+ atomic_inc_32_cas.c atomic_inc_32_nv_cas.c atomic_or_32_cas.c \
+ atomic_or_32_nv_cas.c atomic_swap_32_cas.c membar_ops_nop.c
+
+.endif
+
+.if defined(LIB) && (${LIB} == "c" || ${LIB} == "pthread")
+
+SRCS+= atomic_init_testset.c
+
+.endif
View
1  sys/arch/lm32/conf/files.lm32
@@ -2,3 +2,4 @@ include "arch/lm32/conf/majors.lm32"
file arch/lm32/lm32/pmap.c
file arch/lm32/lm32/copy.c
+file arch/lm32/lm32/lock_stubs.S
View
43 sys/arch/lm32/lm32/lock_stubs.S
@@ -0,0 +1,43 @@
+/*
+ * COPYRIGHT (C) 2013 Yann Sionneau <yann.sionneau@gmail.com>
+ */
+
+#include <lm32/asm.h>
+
+/*
+ * int _atomic_cas_32(volatile uint32_t *val, uint32_t old, uint32_t new);
+ *
+ * The lm32 softcore does not have a cas instruction, so we implement this as
+ * a restartable atomic sequence. For an example of how this is used,
+ * see sun68k/sun68k/isr.c or vax/vax/trap.c
+ */
+ENTRY(_atomic_cas_32)
+
+ .globl _C_LABEL(_atomic_cas_ras_start)
+_C_LABEL(_atomic_cas_ras_start):
+ lw r4, (r1+0) /* load *val into r4 */
+ bne r4, r2, 1f /* compare r4 (*val) and old (r2) */
+ sw (r1+0), r3
+ .globl _C_LABEL(_atomic_cas_ras_end)
+_C_LABEL(_atomic_cas_ras_end):
+
+1:
+ mv r1, r4 /* return (*val) */
+ ret
+
+STRONG_ALIAS(atomic_cas_ptr,_atomic_cas_32)
+STRONG_ALIAS(_atomic_cas_ptr,_atomic_cas_32)
+STRONG_ALIAS(atomic_cas_uint,_atomic_cas_32)
+STRONG_ALIAS(_atomic_cas_uint,_atomic_cas_32)
+STRONG_ALIAS(atomic_cas_ulong,_atomic_cas_32)
+STRONG_ALIAS(_atomic_cas_ulong,_atomic_cas_32)
+STRONG_ALIAS(atomic_cas_32,_atomic_cas_32)
+
+STRONG_ALIAS(atomic_cas_ptr_ni,_atomic_cas_32)
+STRONG_ALIAS(_atomic_cas_ptr_ni,_atomic_cas_32)
+STRONG_ALIAS(atomic_cas_uint_ni,_atomic_cas_32)
+STRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32)
+STRONG_ALIAS(atomic_cas_ulong_ni,_atomic_cas_32)
+STRONG_ALIAS(_atomic_cas_ulong_ni,_atomic_cas_32)
+STRONG_ALIAS(atomic_cas_32_ni,_atomic_cas_32)
+STRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32)

0 comments on commit 21b5975

Please sign in to comment.
Something went wrong with that request. Please try again.