Linux Audio

Check our new training course

Loading...
v6.8
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2#include <linux/linkage.h>
 3#include <asm/percpu.h>
 4#include <asm/processor-flags.h>
 5
 6.text
 7
 8/*
 9 * Emulate 'cmpxchg16b %gs:(%rsi)'
10 *
11 * Inputs:
12 * %rsi : memory location to compare
13 * %rax : low 64 bits of old value
14 * %rdx : high 64 bits of old value
15 * %rbx : low 64 bits of new value
16 * %rcx : high 64 bits of new value
17 *
18 * Notably this is not LOCK prefixed and is not safe against NMIs
19 */
20SYM_FUNC_START(this_cpu_cmpxchg16b_emu)
21
 
 
 
 
 
 
 
 
 
22	pushfq
23	cli
24
25	/* if (*ptr == old) */
26	cmpq	PER_CPU_VAR(0(%rsi)), %rax
27	jne	.Lnot_same
28	cmpq	PER_CPU_VAR(8(%rsi)), %rdx
29	jne	.Lnot_same
30
31	/* *ptr = new */
32	movq	%rbx, PER_CPU_VAR(0(%rsi))
33	movq	%rcx, PER_CPU_VAR(8(%rsi))
34
35	/* set ZF in EFLAGS to indicate success */
36	orl	$X86_EFLAGS_ZF, (%rsp)
37
38	popfq
 
39	RET
40
41.Lnot_same:
42	/* *ptr != old */
43
44	/* old = *ptr */
45	movq	PER_CPU_VAR(0(%rsi)), %rax
46	movq	PER_CPU_VAR(8(%rsi)), %rdx
47
48	/* clear ZF in EFLAGS to indicate failure */
49	andl	$(~X86_EFLAGS_ZF), (%rsp)
50
51	popfq
 
52	RET
53
54SYM_FUNC_END(this_cpu_cmpxchg16b_emu)
v6.2
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2#include <linux/linkage.h>
 3#include <asm/percpu.h>
 
 4
 5.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 */
16SYM_FUNC_START(this_cpu_cmpxchg16b_emu)
17
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#
27	pushfq
28	cli
29
30	cmpq PER_CPU_VAR((%rsi)), %rax
31	jne .Lnot_same
32	cmpq PER_CPU_VAR(8(%rsi)), %rdx
33	jne .Lnot_same
 
 
 
 
 
34
35	movq %rbx, PER_CPU_VAR((%rsi))
36	movq %rcx, PER_CPU_VAR(8(%rsi))
37
38	popfq
39	mov $1, %al
40	RET
41
42.Lnot_same:
 
 
 
 
 
 
 
 
 
43	popfq
44	xor %al,%al
45	RET
46
47SYM_FUNC_END(this_cpu_cmpxchg16b_emu)