Fix ps2 keyboard handling

This commit is contained in:
2025-09-09 21:43:05 +02:00
parent 3b42abc027
commit c4c26e0e19
2 changed files with 13 additions and 10 deletions

View File

@ -201,13 +201,15 @@ void intr_handleintr(IntrStackFrame *frame) {
break; break;
case INTR_IRQBASE+1: case INTR_IRQBASE+1:
int32_t c = ps2kb_intr(); int32_t c = ps2kb_intr();
intr_eoi(frame->trapnum - INTR_IRQBASE); if (c >= 0) {
uint8_t *bytes = (uint8_t *)&c; uint8_t *bytes = (uint8_t *)&c;
spinlock_acquire(&PS2KB_BUF.spinlock); spinlock_acquire(&PS2KB_BUF.spinlock);
for (size_t i = 0; i < sizeof(c); i++) { for (size_t i = 0; i < sizeof(c); i++) {
rbuf_push(&PS2KB_BUF.rbuf, bytes[i]); rbuf_push(&PS2KB_BUF.rbuf, bytes[i]);
}
spinlock_release(&PS2KB_BUF.spinlock);
} }
spinlock_release(&PS2KB_BUF.spinlock); intr_eoi(frame->trapnum - INTR_IRQBASE);
break; break;
} }
} else if (frame->trapnum == 0x80) { } else if (frame->trapnum == 0x80) {

View File

@ -22,17 +22,18 @@ void ps2kbproc_init(Proc *proc) {
void ps2kbproc_fn(void) { void ps2kbproc_fn(void) {
for (;;) { for (;;) {
int32_t kbchr; int32_t kbchr = 0;
uint8_t *buf = (uint8_t *)&kbchr; uint8_t *buf = (uint8_t *)&kbchr;
size_t i = 0; size_t total = 0;
spinlock_acquire(&PS2KB_BUF.spinlock); spinlock_acquire(&PS2KB_BUF.spinlock);
for (; i < sizeof(kbchr); i++) { for (size_t i = 0; i < sizeof(kbchr); i++) {
if (rbuf_pop(&PS2KB_BUF.rbuf, &buf[i]) < 0) { if (rbuf_pop(&PS2KB_BUF.rbuf, &buf[i]) < 0) {
break; break;
} }
total++;
} }
spinlock_release(&PS2KB_BUF.spinlock); spinlock_release(&PS2KB_BUF.spinlock);
if (i > 0) { if (total == sizeof(kbchr)) {
spinlock_acquire(&PS2KBPROC->bcast_pipes.spinlock); spinlock_acquire(&PS2KBPROC->bcast_pipes.spinlock);
IpcPipe *head = PS2KBPROC->bcast_pipes.list; IpcPipe *head = PS2KBPROC->bcast_pipes.list;
while (head != NULL) { while (head != NULL) {