From d5e63951bdf8c154bafee11c84816539fde77b81 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Mon, 27 May 2024 14:15:18 -0500 Subject: arch: i386: add a spinlock implementation Add two functions to control thread-local spinlocks. Signed-off-by: Danny Holman --- arch/i386/kernel/spinlock.s | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 arch/i386/kernel/spinlock.s (limited to 'arch/i386/kernel') diff --git a/arch/i386/kernel/spinlock.s b/arch/i386/kernel/spinlock.s new file mode 100644 index 0000000..c8235ca --- /dev/null +++ b/arch/i386/kernel/spinlock.s @@ -0,0 +1,30 @@ +.section .text + +.global aquire_lock +.type aquire_lock, @function +aquire_lock: + pushl %ebp + movl %esp, %ebp +locked: + movl 8(%esp), %eax + lock incl (%eax) + jc spin_wait + + popl %ebp + ret +spin_wait: + test %eax, 1 + jnz spin_wait + jmp locked + +.global release_lock +.type release_lock, @function +release_lock: + pushl %ebp + movl %esp, %ebp + + movl 8(%ebp), %eax + lock decl (%eax) + + popl %ebp + ret -- cgit v1.2.3