1/*
2 * Copyright (c) 2025 Travis Geiselbrecht
3 *
4 * Use of this source code is governed by a MIT-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/MIT
7 */
8#include <lk/asm.h>
9
10#if WITH_SMP
11
12// void arch_spin_lock(spin_lock_t *lock);
13FUNCTION(arch_spin_lock)
14    mov  $1, %esi
150:
16    xor  %eax, %eax
17    lock cmpxchg  %esi, (%rdi)
18    jz 1f
19    pause
20    jmp 0b
211:
22    ret
23END_FUNCTION(arch_spin_lock)
24
25// int arch_spin_trylock(spin_lock_t *lock);
26FUNCTION(arch_spin_trylock)
27    mov  $1, %eax
28
29    lock xchg  %eax, (%rdi)
30
31    ret
32END_FUNCTION(arch_spin_trylock)
33
34// void arch_spin_unlock(spin_lock_t *lock);
35FUNCTION(arch_spin_unlock)
36    movl  $0, (%rdi)
37    ret
38END_FUNCTION(arch_spin_unlock)
39
40#endif // WITH_SMP