xref: /linux/arch/x86/lib/cmpxchg16b_emu.S (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
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
11.text
12
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 */
22ENTRY(this_cpu_cmpxchg16b_emu)
23
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	pushfq
34	cli
35
36	cmpq PER_CPU_VAR((%rsi)), %rax
37	jne .Lnot_same
38	cmpq PER_CPU_VAR(8(%rsi)), %rdx
39	jne .Lnot_same
40
41	movq %rbx, PER_CPU_VAR((%rsi))
42	movq %rcx, PER_CPU_VAR(8(%rsi))
43
44	popfq
45	mov $1, %al
46	ret
47
48.Lnot_same:
49	popfq
50	xor %al,%al
51	ret
52
53ENDPROC(this_cpu_cmpxchg16b_emu)
54