Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/powerpc/include add some atomic operations.



details:   https://anonhg.NetBSD.org/src/rev/8a9f20b5a0ac
branches:  trunk
changeset: 534496:8a9f20b5a0ac
user:      chs <chs%NetBSD.org@localhost>
date:      Sun Jul 28 07:09:28 2002 +0000

description:
add some atomic operations.

diffstat:

 sys/arch/powerpc/include/atomic.h |  129 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 129 insertions(+), 0 deletions(-)

diffs (133 lines):

diff -r e6237ef21663 -r 8a9f20b5a0ac sys/arch/powerpc/include/atomic.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/powerpc/include/atomic.h Sun Jul 28 07:09:28 2002 +0000
@@ -0,0 +1,129 @@
+/* $NetBSD: atomic.h,v 1.1 2002/07/28 07:09:28 chs Exp $ */
+
+/*-
+ */
+
+/*
+ * Misc. `atomic' operations.
+ */
+
+#ifndef _POWERPC_ATOMIC_H_
+#define        _POWERPC_ATOMIC_H_
+
+/*
+ * atomic_setbits_ulong:
+ *
+ *     Atomically set bits in a `unsigned long'.
+ */
+static __inline void
+atomic_setbits_ulong(__volatile unsigned long *ulp, unsigned long v)
+{
+       unsigned long tmp;
+
+       __asm __volatile("
+# BEGIN atomic_setbits_ulong   \n\
+1:     lwarx   %0,0,%2         \n\
+       or      %0,%1,%0        \n\
+       stwcx.  %0,0,%2         \n\
+       bne-    1b              \n\
+       sync                    \n\
+# END atomic_setbits_ulong     \n"
+       : "=&r" (tmp)
+       : "r" (v), "r" (ulp)
+       : "memory");
+}
+
+/*
+ * atomic_clearbits_ulong:
+ *
+ *     Atomically clear bits in a `unsigned long'.
+ */
+static __inline void
+atomic_clearbits_ulong(__volatile unsigned long *ulp, unsigned long v)
+{
+       unsigned long tmp;
+
+       __asm __volatile("
+# BEGIN atomic_clearbits_ulong \n\
+1:     lwarx   %0,0,%2         \n\
+       and     %0,%1,%0        \n\
+       stwcx.  %0,0,%2         \n\
+       bne-    1b              \n\
+       sync                    \n\
+# END atomic_clearbits_ulong   \n"
+       : "=&r" (tmp)
+       : "r" (~v), "r" (ulp)
+       : "memory");
+}
+
+/*
+ * atomic_add_ulong:
+ *
+ *     Atomically add a value to a `unsigned long'.
+ */
+static __inline void
+atomic_add_ulong(__volatile unsigned long *ulp, unsigned long v)
+{
+       unsigned long tmp;
+
+       __asm __volatile("
+# BEGIN atomic_add_ulong       \n\
+1:     lwarx   %0,0,%2         \n\
+       add     %0,%1,%0        \n\
+       stwcx.  %0,0,%2         \n\
+       bne-    1b              \n\
+       sync                    \n\
+# END atomic_add_ulong         \n"
+       : "=&r" (tmp)
+       : "r" (v), "r" (ulp)
+       : "memory");
+}
+
+/*
+ * atomic_sub_ulong:
+ *
+ *     Atomically subtract a value from a `unsigned long'.
+ */
+static __inline void
+atomic_sub_ulong(__volatile unsigned long *ulp, unsigned long v)
+{
+       unsigned long tmp;
+
+       __asm __volatile("
+# BEGIN atomic_sub_ulong       \n\
+1:     lwarx   %0,0,%2         \n\
+       sub     %0,%0,%1        \n\
+       stwcx.  %0,0,%2         \n\
+       bne-    1b              \n\
+       sync                    \n\
+# END atomic_sub_ulong         \n"
+       : "=&r" (tmp)
+       : "r" (v), "r" (ulp)
+       : "memory");
+}
+
+/*
+ * atomic_loadlatch_ulong:
+ *
+ *     Atomically load and latch a `unsigned long' value.
+ */
+static __inline unsigned long
+atomic_loadlatch_ulong(__volatile unsigned long *ulp, unsigned long v)
+{
+       unsigned long tmp;
+
+       __asm __volatile("
+# BEGIN atomic_loadlatch_ulong \n\
+1:     lwarx   %0,0,%2         \n\
+       stwcx.  %1,0,%2         \n\
+       bne-    1b              \n\
+       sync                    \n\
+# END atomic_loadlatch_ulong   \n"
+       : "=r" (tmp)
+       : "r" (v), "r" (ulp)
+       : "memory");
+
+       return (tmp);
+}
+
+#endif /* _POWERPC_ATOMIC_H_ */



Home | Main Index | Thread Index | Old Index