cmpxchg16b_emu.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; version 2
  5. * of the License.
  6. *
  7. */
  8. #include <linux/linkage.h>
  9. #include <asm/alternative-asm.h>
  10. #include <asm/frame.h>
  11. #include <asm/dwarf2.h>
  12. #ifdef CONFIG_SMP
  13. #define SEG_PREFIX %gs:
  14. #else
  15. #define SEG_PREFIX
  16. #endif
  17. .text
  18. /*
  19. * Inputs:
  20. * %rsi : memory location to compare
  21. * %rax : low 64 bits of old value
  22. * %rdx : high 64 bits of old value
  23. * %rbx : low 64 bits of new value
  24. * %rcx : high 64 bits of new value
  25. * %al : Operation successful
  26. */
  27. ENTRY(this_cpu_cmpxchg16b_emu)
  28. CFI_STARTPROC
  29. #
  30. # Emulate 'cmpxchg16b %gs:(%rsi)' except we return the result in %al not
  31. # via the ZF. Caller will access %al to get result.
  32. #
  33. # Note that this is only useful for a cpuops operation. Meaning that we
  34. # do *not* have a fully atomic operation but just an operation that is
  35. # *atomic* on a single cpu (as provided by the this_cpu_xx class of
  36. # macros).
  37. #
  38. this_cpu_cmpxchg16b_emu:
  39. pushf
  40. cli
  41. cmpq SEG_PREFIX(%rsi), %rax
  42. jne not_same
  43. cmpq SEG_PREFIX 8(%rsi), %rdx
  44. jne not_same
  45. movq %rbx, SEG_PREFIX(%rsi)
  46. movq %rcx, SEG_PREFIX 8(%rsi)
  47. popf
  48. mov $1, %al
  49. ret
  50. not_same:
  51. popf
  52. xor %al,%al
  53. ret
  54. CFI_ENDPROC
  55. ENDPROC(this_cpu_cmpxchg16b_emu)