diff options
author | Palmer Dabbelt <palmer@dabbelt.com> | 2017-06-14 08:59:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 08:59:41 -0700 |
commit | 61d6152830d752cd81c34368ecc24a5a2a107061 (patch) | |
tree | 58c5b8c05ae24b8c6b035545634200eb3742c064 /software/smp/atomic.h | |
parent | 809711e87af06ca5c151a2fac568382330f2feb6 (diff) | |
parent | 99a8e6a697a340a5f44db82e68ab8ab9be604131 (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.h | 29 |
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 |