v2 initial commit

This commit is contained in:
Michael Shaw 2026-04-11 11:35:31 -04:00
commit d2ef885e8d
118 changed files with 2420 additions and 9320 deletions

13
amd64/kernel/atomic.S Normal file
View file

@ -0,0 +1,13 @@
.intel_syntax noprefix
.global atomic_cmpxchg
atomic_cmpxchg:
mov eax, esi
lock cmpxchg [rdi], edx
jnz nz
xor eax, eax
ret
nz:
mov eax, 1
ret

21
amd64/kernel/spinlock.c Normal file
View file

@ -0,0 +1,21 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h>
#include <kernel/spinlock.h>
int atomic_cmpxchg(spinlock_t *lock, int a, int b);
static uint64_t spinlock_attempt_acquire(spinlock_t *lock)
{
return atomic_cmpxchg(lock, 0, 1);
}
void spinlock_acquire(spinlock_t *lock)
{
while (spinlock_attempt_acquire(lock))
;
}
void spinlock_release(spinlock_t *lock)
{
atomic_cmpxchg(lock, 1, 0);
}