Rearchitecture PS2KB driver using event buffers
This commit is contained in:
@ -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;
|
||||
|
@ -33,6 +33,7 @@ typedef struct {
|
||||
uint64_t ss;
|
||||
} PACKED IntrStackFrame;
|
||||
|
||||
void intr_attchhandler(void (*fn)(void), int irq);
|
||||
void intr_init(void);
|
||||
|
||||
#endif // HAL_INTR_H_
|
||||
|
Reference in New Issue
Block a user