cmpxchg16b_emu.S 1.1 KB

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