cmpxchg16b_emu.S 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. .text
  13. /*
  14. * Inputs:
  15. * %rsi : memory location to compare
  16. * %rax : low 64 bits of old value
  17. * %rdx : high 64 bits of old value
  18. * %rbx : low 64 bits of new value
  19. * %rcx : high 64 bits of new value
  20. * %al : Operation successful
  21. */
  22. ENTRY(this_cpu_cmpxchg16b_emu)
  23. CFI_STARTPROC
  24. #
  25. # Emulate 'cmpxchg16b %gs:(%rsi)' except we return the result in %al not
  26. # via the ZF. Caller will access %al to get result.
  27. #
  28. # Note that this is only useful for a cpuops operation. Meaning that we
  29. # do *not* have a fully atomic operation but just an operation that is
  30. # *atomic* on a single cpu (as provided by the this_cpu_xx class of
  31. # macros).
  32. #
  33. this_cpu_cmpxchg16b_emu:
  34. pushf
  35. cli
  36. cmpq %gs:(%rsi), %rax
  37. jne not_same
  38. cmpq %gs:8(%rsi), %rdx
  39. jne not_same
  40. movq %rbx, %gs:(%rsi)
  41. movq %rcx, %gs:8(%rsi)
  42. popf
  43. mov $1, %al
  44. ret
  45. not_same:
  46. popf
  47. xor %al,%al
  48. ret
  49. CFI_ENDPROC
  50. ENDPROC(this_cpu_cmpxchg16b_emu)