summaryrefslogtreecommitdiff
path: root/software/smp/atomic.h
diff options
context:
space:
mode:
authorPalmer Dabbelt <palmer@dabbelt.com>2017-06-14 08:59:41 -0700
committerGitHub <noreply@github.com>2017-06-14 08:59:41 -0700
commit61d6152830d752cd81c34368ecc24a5a2a107061 (patch)
tree58c5b8c05ae24b8c6b035545634200eb3742c064 /software/smp/atomic.h
parent809711e87af06ca5c151a2fac568382330f2feb6 (diff)
parent99a8e6a697a340a5f44db82e68ab8ab9be604131 (diff)
Merge pull request #64 from sifive/multicore-scratchpad
Add support for multicore systems and scratchpad-only systems
Diffstat (limited to 'software/smp/atomic.h')
-rw-r--r--software/smp/atomic.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/software/smp/atomic.h b/software/smp/atomic.h
new file mode 100644
index 0000000..074c6a2
--- /dev/null
+++ b/software/smp/atomic.h
@@ -0,0 +1,29 @@
+#ifndef SIFIVE_ATOMIC_H
+#define SIFIVE_ATOMIC_H
+
+#define ATOMIC_INIT(x) \
+ { \
+ .counter = (x), \
+ }
+
+typedef struct {
+ int counter;
+} atomic_t;
+
+static inline int atomic_xchg(atomic_t *v, int n)
+{
+ register int c;
+
+ __asm__ __volatile__ (
+ "amoswap.w.aqrl %0, %2, %1"
+ : "=r" (c), "+A" (v->counter)
+ : "r" (n));
+ return c;
+}
+
+static inline void mb(void)
+{
+ __asm__ __volatile__ ("fence");
+}
+
+#endif