blob: 9b330242e7408125d6865e8f753c61ab9ae64802 [file] [log] [blame]
Christoph Lameterb9ec40a2011-02-28 11:02:24 +01001/*
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>
Jan Beulich3f635722014-09-24 08:37:00 +01009#include <asm/percpu.h>
Christoph Lameterd7c3f8c2011-03-26 20:57:18 -050010
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010011.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)
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010023
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#
Ingo Molnar131484c2015-05-28 12:21:47 +020033 pushfq
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010034 cli
35
Jan Beulich3f635722014-09-24 08:37:00 +010036 cmpq PER_CPU_VAR((%rsi)), %rax
37 jne .Lnot_same
38 cmpq PER_CPU_VAR(8(%rsi)), %rdx
39 jne .Lnot_same
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010040
Jan Beulich3f635722014-09-24 08:37:00 +010041 movq %rbx, PER_CPU_VAR((%rsi))
42 movq %rcx, PER_CPU_VAR(8(%rsi))
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010043
Ingo Molnar131484c2015-05-28 12:21:47 +020044 popfq
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010045 mov $1, %al
46 ret
47
Jan Beulich3f635722014-09-24 08:37:00 +010048.Lnot_same:
Ingo Molnar131484c2015-05-28 12:21:47 +020049 popfq
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010050 xor %al,%al
51 ret
52
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010053ENDPROC(this_cpu_cmpxchg16b_emu)