Handle ps2 keyboard via special process

This commit is contained in:
2025-09-07 20:53:36 +02:00
parent 4f3053bc8e
commit 9644ad0b4e
16 changed files with 312 additions and 40 deletions

View File

@ -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);
}

View File

@ -6,6 +6,7 @@
typedef struct {
atomic_bool lock;
uint64_t flags;
} SpinLock;
#define SPINLOCK_HINT() asm volatile("pause")