cmpxchg-llsc.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef __ASM_SH_CMPXCHG_LLSC_H
  2. #define __ASM_SH_CMPXCHG_LLSC_H
  3. static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
  4. {
  5. unsigned long retval;
  6. unsigned long tmp;
  7. __asm__ __volatile__ (
  8. "1: \n\t"
  9. "movli.l @%2, %0 ! xchg_u32 \n\t"
  10. "mov %0, %1 \n\t"
  11. "mov %3, %0 \n\t"
  12. "movco.l %0, @%2 \n\t"
  13. "bf 1b \n\t"
  14. "synco \n\t"
  15. : "=&z"(tmp), "=&r" (retval)
  16. : "r" (m), "r" (val)
  17. : "t", "memory"
  18. );
  19. return retval;
  20. }
  21. static inline unsigned long
  22. __cmpxchg_u32(volatile u32 *m, unsigned long old, unsigned long new)
  23. {
  24. unsigned long retval;
  25. unsigned long tmp;
  26. __asm__ __volatile__ (
  27. "1: \n\t"
  28. "movli.l @%2, %0 ! __cmpxchg_u32 \n\t"
  29. "mov %0, %1 \n\t"
  30. "cmp/eq %1, %3 \n\t"
  31. "bf 2f \n\t"
  32. "mov %4, %0 \n\t"
  33. "2: \n\t"
  34. "movco.l %0, @%2 \n\t"
  35. "bf 1b \n\t"
  36. "synco \n\t"
  37. : "=&z" (tmp), "=&r" (retval)
  38. : "r" (m), "r" (old), "r" (new)
  39. : "t", "memory"
  40. );
  41. return retval;
  42. }
  43. #include <asm/cmpxchg-xchg.h>
  44. #endif /* __ASM_SH_CMPXCHG_LLSC_H */