Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 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> |
Jan Beulich | 3f63572 | 2014-09-24 08:37:00 +0100 | [diff] [blame] | 9 | #include <asm/percpu.h> |
Christoph Lameter | d7c3f8c | 2011-03-26 20:57:18 -0500 | [diff] [blame] | 10 | |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 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 | */ |
| 22 | ENTRY(this_cpu_cmpxchg16b_emu) |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 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 | # |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 33 | pushfq |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 34 | cli |
| 35 | |
Jan Beulich | 3f63572 | 2014-09-24 08:37:00 +0100 | [diff] [blame] | 36 | cmpq PER_CPU_VAR((%rsi)), %rax |
| 37 | jne .Lnot_same |
| 38 | cmpq PER_CPU_VAR(8(%rsi)), %rdx |
| 39 | jne .Lnot_same |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 40 | |
Jan Beulich | 3f63572 | 2014-09-24 08:37:00 +0100 | [diff] [blame] | 41 | movq %rbx, PER_CPU_VAR((%rsi)) |
| 42 | movq %rcx, PER_CPU_VAR(8(%rsi)) |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 43 | |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 44 | popfq |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 45 | mov $1, %al |
| 46 | ret |
| 47 | |
Jan Beulich | 3f63572 | 2014-09-24 08:37:00 +0100 | [diff] [blame] | 48 | .Lnot_same: |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 49 | popfq |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 50 | xor %al,%al |
| 51 | ret |
| 52 | |
Christoph Lameter | b9ec40a | 2011-02-28 11:02:24 +0100 | [diff] [blame] | 53 | ENDPROC(this_cpu_cmpxchg16b_emu) |