cmpxchg-llsc.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 xchg_u8(volatile u8 *m, unsigned long val)
  22. {
  23. unsigned long retval;
  24. unsigned long tmp;
  25. __asm__ __volatile__ (
  26. "1: \n\t"
  27. "movli.l @%2, %0 ! xchg_u8 \n\t"
  28. "mov %0, %1 \n\t"
  29. "mov %3, %0 \n\t"
  30. "movco.l %0, @%2 \n\t"
  31. "bf 1b \n\t"
  32. "synco \n\t"
  33. : "=&z"(tmp), "=&r" (retval)
  34. : "r" (m), "r" (val & 0xff)
  35. : "t", "memory"
  36. );
  37. return retval;
  38. }
  39. static inline unsigned long
  40. __cmpxchg_u32(volatile int *m, unsigned long old, unsigned long new)
  41. {
  42. unsigned long retval;
  43. unsigned long tmp;
  44. __asm__ __volatile__ (
  45. "1: \n\t"
  46. "movli.l @%2, %0 ! __cmpxchg_u32 \n\t"
  47. "mov %0, %1 \n\t"
  48. "cmp/eq %1, %3 \n\t"
  49. "bf 2f \n\t"
  50. "mov %4, %0 \n\t"
  51. "2: \n\t"
  52. "movco.l %0, @%2 \n\t"
  53. "bf 1b \n\t"
  54. "synco \n\t"
  55. : "=&z" (tmp), "=&r" (retval)
  56. : "r" (m), "r" (old), "r" (new)
  57. : "t", "memory"
  58. );
  59. return retval;
  60. }
  61. #endif /* __ASM_SH_CMPXCHG_LLSC_H */