Rearchitecture PS2KB driver using event buffers

This commit is contained in:
2025-10-05 19:48:15 +02:00
parent 247ef1bbd1
commit e9838d530f
10 changed files with 262 additions and 189 deletions

View File

@ -12,10 +12,25 @@
#include "proc/proc.h"
#include "syscall/syscall.h"
#include "errors.h"
#include "drivers/ps2kb/ps2kb.h"
#include "ipc/pipe/pipe.h"
#include "rbuf/rbuf.h"
#include "dev/ps2kbdev.h"
#include "dlmalloc/malloc.h"
#include "util/util.h"
typedef struct IntrHandler {
struct IntrHandler *next;
void (*fn)(void);
int irq;
} IntrHandler;
IntrHandler *INTR_HANDLERS = NULL;
void intr_attchhandler(void (*fn)(void), int irq) {
IntrHandler *ih = dlmalloc(sizeof(*ih));
ih->fn = fn;
ih->irq = irq;
LL_APPEND(INTR_HANDLERS, ih);
}
typedef struct BackTraceFrame {
struct BackTraceFrame *rbp;
@ -211,13 +226,12 @@ void intr_handleintr(IntrStackFrame *frame) {
intr_eoi();
proc_sched((void *)frame);
break;
case INTR_IRQBASE+1:
int32_t c = ps2kb_intr();
if (c >= 0 && PS2KB_BUF.init) {
uint8_t b = c;
spinlock_acquire(&PS2KB_BUF.spinlock);
rbuf_push(&PS2KB_BUF.rbuf, b);
spinlock_release(&PS2KB_BUF.spinlock);
default:
IntrHandler *ih, *ihtmp;
LL_FOREACH_SAFE(INTR_HANDLERS, ih, ihtmp) {
if (ih->irq == frame->trapnum) {
ih->fn();
}
}
intr_eoi();
break;