cmpxchg16b_emu.S 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #include <linux/linkage.h>
  3. #include <asm/percpu.h>
  4. .text
  5. /*
  6. * Inputs:
  7. * %rsi : memory location to compare
  8. * %rax : low 64 bits of old value
  9. * %rdx : high 64 bits of old value
  10. * %rbx : low 64 bits of new value
  11. * %rcx : high 64 bits of new value
  12. * %al : Operation successful
  13. */
  14. SYM_FUNC_START(this_cpu_cmpxchg16b_emu)
  15. #
  16. # Emulate 'cmpxchg16b %gs:(%rsi)' except we return the result in %al not
  17. # via the ZF. Caller will access %al to get result.
  18. #
  19. # Note that this is only useful for a cpuops operation. Meaning that we
  20. # do *not* have a fully atomic operation but just an operation that is
  21. # *atomic* on a single cpu (as provided by the this_cpu_xx class of
  22. # macros).
  23. #
  24. pushfq
  25. cli
  26. cmpq PER_CPU_VAR((%rsi)), %rax
  27. jne .Lnot_same
  28. cmpq PER_CPU_VAR(8(%rsi)), %rdx
  29. jne .Lnot_same
  30. movq %rbx, PER_CPU_VAR((%rsi))
  31. movq %rcx, PER_CPU_VAR(8(%rsi))
  32. popfq
  33. mov $1, %al
  34. RET
  35. .Lnot_same:
  36. popfq
  37. xor %al,%al
  38. RET
  39. SYM_FUNC_END(this_cpu_cmpxchg16b_emu)