blob: 40a172541ee2cb2c2342a0a9934948769e87337f [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>
Christoph Lameterb9ec40a2011-02-28 11:02:24 +01009#include <asm/dwarf2.h>
Jan Beulich3f635722014-09-24 08:37:00 +010010#include <asm/percpu.h>
Christoph Lameterd7c3f8c2011-03-26 20:57:18 -050011
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010012.text
13
14/*
15 * Inputs:
16 * %rsi : memory location to compare
17 * %rax : low 64 bits of old value
18 * %rdx : high 64 bits of old value
19 * %rbx : low 64 bits of new value
20 * %rcx : high 64 bits of new value
21 * %al : Operation successful
22 */
23ENTRY(this_cpu_cmpxchg16b_emu)
24CFI_STARTPROC
25
26#
27# Emulate 'cmpxchg16b %gs:(%rsi)' except we return the result in %al not
28# via the ZF. Caller will access %al to get result.
29#
30# Note that this is only useful for a cpuops operation. Meaning that we
31# do *not* have a fully atomic operation but just an operation that is
32# *atomic* on a single cpu (as provided by the this_cpu_xx class of
33# macros).
34#
Jan Beulich3f635722014-09-24 08:37:00 +010035 pushfq_cfi
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010036 cli
37
Jan Beulich3f635722014-09-24 08:37:00 +010038 cmpq PER_CPU_VAR((%rsi)), %rax
39 jne .Lnot_same
40 cmpq PER_CPU_VAR(8(%rsi)), %rdx
41 jne .Lnot_same
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010042
Jan Beulich3f635722014-09-24 08:37:00 +010043 movq %rbx, PER_CPU_VAR((%rsi))
44 movq %rcx, PER_CPU_VAR(8(%rsi))
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010045
Jan Beulich3f635722014-09-24 08:37:00 +010046 CFI_REMEMBER_STATE
47 popfq_cfi
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010048 mov $1, %al
49 ret
50
Jan Beulich3f635722014-09-24 08:37:00 +010051 CFI_RESTORE_STATE
52.Lnot_same:
53 popfq_cfi
Christoph Lameterb9ec40a2011-02-28 11:02:24 +010054 xor %al,%al
55 ret
56
57CFI_ENDPROC
58
59ENDPROC(this_cpu_cmpxchg16b_emu)