1
0

atomic_arch.h 945 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "libc.h"
  2. #if defined(__SH4A__)
  3. #define a_ll a_ll
  4. static inline int a_ll(volatile int *p)
  5. {
  6. int v;
  7. __asm__ __volatile__ ("movli.l @%1, %0" : "=z"(v) : "r"(p), "m"(*p));
  8. return v;
  9. }
  10. #define a_sc a_sc
  11. static inline int a_sc(volatile int *p, int v)
  12. {
  13. int r;
  14. __asm__ __volatile__ (
  15. "movco.l %2, @%3 ; movt %0"
  16. : "=r"(r), "=m"(*p) : "z"(v), "r"(p) : "memory", "cc");
  17. return r;
  18. }
  19. #define a_barrier a_barrier
  20. static inline void a_barrier()
  21. {
  22. __asm__ __volatile__ ("synco" ::: "memory");
  23. }
  24. #define a_pre_llsc a_barrier
  25. #define a_post_llsc a_barrier
  26. #else
  27. #define a_cas a_cas
  28. extern hidden const void *__sh_cas_ptr;
  29. static inline int a_cas(volatile int *p, int t, int s)
  30. {
  31. register int r1 __asm__("r1");
  32. register int r2 __asm__("r2") = t;
  33. register int r3 __asm__("r3") = s;
  34. __asm__ __volatile__ (
  35. "jsr @%4 ; nop"
  36. : "=r"(r1), "+r"(r3) : "z"(p), "r"(r2), "r"(__sh_cas_ptr)
  37. : "memory", "pr", "cc");
  38. return r3;
  39. }
  40. #endif