Handle ps2 keyboard via special process
This commit is contained in:
@ -1,24 +1,36 @@
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "spinlock.h"
|
||||
#include "hal/hal.h"
|
||||
#include "kprintf.h"
|
||||
|
||||
void spinlock_init(SpinLock *sl) {
|
||||
atomic_store(&sl->lock, false);
|
||||
sl->flags = 0;
|
||||
}
|
||||
|
||||
uint64_t spinlock_irqsave(void) {
|
||||
uint64_t flags;
|
||||
asm volatile("pushfq; cli; popq %0" : "=r"(flags));
|
||||
return flags;
|
||||
}
|
||||
|
||||
void spinlock_irqrestore(uint64_t flags) {
|
||||
asm volatile("pushq %0; popfq" :: "r"(flags));
|
||||
}
|
||||
|
||||
void spinlock_acquire(SpinLock *sl) {
|
||||
bool unlocked = false;
|
||||
while (!atomic_compare_exchange_weak(&sl->lock, &unlocked, true)) {
|
||||
unlocked = false;
|
||||
sl->flags = spinlock_irqsave();
|
||||
|
||||
while (atomic_test_and_set_explicit(&sl->lock, memory_order_acquire)) {
|
||||
SPINLOCK_HINT();
|
||||
}
|
||||
}
|
||||
|
||||
void spinlock_release(SpinLock *sl) {
|
||||
bool locked = true;
|
||||
if (atomic_compare_exchange_strong(&sl->lock, &locked, false)) {
|
||||
atomic_store(&sl->lock, false);
|
||||
}
|
||||
atomic_clear_flag_explicit(&sl->lock, memory_order_release);
|
||||
|
||||
spinlock_irqrestore(sl->flags);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user