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