openEuler_kernel_rk3588/arch/x86/lib/cmpxchg16b_emu.S

55 lines
1.0 KiB
ArmAsm
Raw Normal View History

2026-01-21 18:59:54 +08:00
/* SPDX-License-Identifier: GPL-2.0-only */
#include <linux/linkage.h>
#include <asm/percpu.h>
2026-01-29 22:25:33 +08:00
#include <asm/processor-flags.h>
2026-01-21 18:59:54 +08:00
.text
/*
2026-01-29 22:25:33 +08:00
* Emulate 'cmpxchg16b %gs:(%rsi)'
*
2026-01-21 18:59:54 +08:00
* Inputs:
* %rsi : memory location to compare
* %rax : low 64 bits of old value
* %rdx : high 64 bits of old value
* %rbx : low 64 bits of new value
* %rcx : high 64 bits of new value
2026-01-29 22:25:33 +08:00
*
* Notably this is not LOCK prefixed and is not safe against NMIs
2026-01-21 18:59:54 +08:00
*/
SYM_FUNC_START(this_cpu_cmpxchg16b_emu)
pushfq
cli
2026-01-29 22:25:33 +08:00
/* if (*ptr == old) */
cmpq PER_CPU_VAR(0(%rsi)), %rax
jne .Lnot_same
cmpq PER_CPU_VAR(8(%rsi)), %rdx
jne .Lnot_same
2026-01-21 18:59:54 +08:00
2026-01-29 22:25:33 +08:00
/* *ptr = new */
movq %rbx, PER_CPU_VAR(0(%rsi))
movq %rcx, PER_CPU_VAR(8(%rsi))
/* set ZF in EFLAGS to indicate success */
orl $X86_EFLAGS_ZF, (%rsp)
2026-01-21 18:59:54 +08:00
popfq
RET
.Lnot_same:
2026-01-29 22:25:33 +08:00
/* *ptr != old */
/* old = *ptr */
movq PER_CPU_VAR(0(%rsi)), %rax
movq PER_CPU_VAR(8(%rsi)), %rdx
/* clear ZF in EFLAGS to indicate failure */
andl $(~X86_EFLAGS_ZF), (%rsp)
2026-01-21 18:59:54 +08:00
popfq
RET
SYM_FUNC_END(this_cpu_cmpxchg16b_emu)