vbos/init/atomic.S
Michael Shaw 8e6d0d4fbc kernel: add support for basic type spinlock_t
A spinlock is the most basic type of lock. It will attempt to acquire,
and upon failure, will continue attempting indefinitely until it is
successful.
2023-05-27 01:44:33 -04:00

18 lines
392 B
ArmAsm

/* SPDX-License-Identifier: GPL-2.0-only */
#define __ASM__
/* int atomic_cmpxchg(volatile int *ptr, int cmpval, int newval) */
.global atomic_cmpxchg
atomic_cmpxchg:
/* if (*ptr == cmpval) *ptr = newval, but atomic :) */
movl %esi, %eax
lock cmpxchg %edx, (%rdi)
/* if ZF is set, the exchange was successful */
pushfq
popq %rax
andl $0x40, %eax
shrl $6, %eax
xorl $1, %eax
ret