blob: 3542502faa3b7ca930408a1b2dab2865e6f21a84 [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Christoph Lameterb9ec40af2011-02-28 11:02:24 +01002#include <linux/linkage.h>
Jan Beulich3f6357212014-09-24 08:37:00 +01003#include <asm/percpu.h>
Christoph Lameterd7c3f8c2011-03-26 20:57:18 -05004
Christoph Lameterb9ec40af2011-02-28 11:02:24 +01005.text
6
7/*
8 * Inputs:
9 * %rsi : memory location to compare
10 * %rax : low 64 bits of old value
11 * %rdx : high 64 bits of old value
12 * %rbx : low 64 bits of new value
13 * %rcx : high 64 bits of new value
14 * %al : Operation successful
15 */
Jiri Slaby6dcc5622019-10-11 13:51:04 +020016SYM_FUNC_START(this_cpu_cmpxchg16b_emu)
Christoph Lameterb9ec40af2011-02-28 11:02:24 +010017
18#
19# Emulate 'cmpxchg16b %gs:(%rsi)' except we return the result in %al not
20# via the ZF. Caller will access %al to get result.
21#
22# Note that this is only useful for a cpuops operation. Meaning that we
23# do *not* have a fully atomic operation but just an operation that is
24# *atomic* on a single cpu (as provided by the this_cpu_xx class of
25# macros).
26#
Ingo Molnar131484c2015-05-28 12:21:47 +020027 pushfq
Christoph Lameterb9ec40af2011-02-28 11:02:24 +010028 cli
29
Jan Beulich3f6357212014-09-24 08:37:00 +010030 cmpq PER_CPU_VAR((%rsi)), %rax
31 jne .Lnot_same
32 cmpq PER_CPU_VAR(8(%rsi)), %rdx
33 jne .Lnot_same
Christoph Lameterb9ec40af2011-02-28 11:02:24 +010034
Jan Beulich3f6357212014-09-24 08:37:00 +010035 movq %rbx, PER_CPU_VAR((%rsi))
36 movq %rcx, PER_CPU_VAR(8(%rsi))
Christoph Lameterb9ec40af2011-02-28 11:02:24 +010037
Ingo Molnar131484c2015-05-28 12:21:47 +020038 popfq
Christoph Lameterb9ec40af2011-02-28 11:02:24 +010039 mov $1, %al
40 ret
41
Jan Beulich3f6357212014-09-24 08:37:00 +010042.Lnot_same:
Ingo Molnar131484c2015-05-28 12:21:47 +020043 popfq
Christoph Lameterb9ec40af2011-02-28 11:02:24 +010044 xor %al,%al
45 ret
46
Jiri Slaby6dcc5622019-10-11 13:51:04 +020047SYM_FUNC_END(this_cpu_cmpxchg16b_emu)