summaryrefslogtreecommitdiff
path: root/src/kernel/arch/i386/driver
diff options
context:
space:
mode:
authordzwdz2022-03-30 14:14:11 +0200
committerdzwdz2022-03-30 14:14:11 +0200
commit6b7cbc2842354eabb7c3345390c5891a6f881f0c (patch)
treed3eb3975ceb25e72f04938e04727b8af73c0104b /src/kernel/arch/i386/driver
parent32a4c0bc7712ea96391b468e63ea476313510323 (diff)
kernel: remove the keyboard driver, add a `/ps2` device
Diffstat (limited to 'src/kernel/arch/i386/driver')
-rw-r--r--src/kernel/arch/i386/driver/ps2.c28
-rw-r--r--src/kernel/arch/i386/driver/ps2.h7
2 files changed, 35 insertions, 0 deletions
diff --git a/src/kernel/arch/i386/driver/ps2.c b/src/kernel/arch/i386/driver/ps2.c
new file mode 100644
index 0000000..1af3166
--- /dev/null
+++ b/src/kernel/arch/i386/driver/ps2.c
@@ -0,0 +1,28 @@
+#include <kernel/arch/i386/driver/ps2.h>
+#include <kernel/arch/i386/interrupts/irq.h>
+#include <shared/mem.h>
+
+#define BACKLOG_CAPACITY 16
+
+/* TODO move away from tty/ */
+
+static volatile uint8_t backlog[BACKLOG_CAPACITY] = {};
+static volatile size_t backlog_size = 0;
+
+void ps2_recv(uint8_t s) {
+ if (backlog_size >= BACKLOG_CAPACITY) return;
+ backlog[backlog_size++] = s;
+}
+
+size_t ps2_read(uint8_t *buf, size_t max_len) {
+ irq_interrupt_flag(true);
+ while (backlog_size == 0)
+ asm("hlt" ::: "memory");
+ irq_interrupt_flag(false);
+
+ size_t len = backlog_size;
+ if (len > max_len) len = max_len;
+ backlog_size = 0;
+ memcpy(buf, (void*)backlog, len);
+ return len;
+}
diff --git a/src/kernel/arch/i386/driver/ps2.h b/src/kernel/arch/i386/driver/ps2.h
new file mode 100644
index 0000000..4b56056
--- /dev/null
+++ b/src/kernel/arch/i386/driver/ps2.h
@@ -0,0 +1,7 @@
+#pragma once
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+void ps2_recv(uint8_t scancode);
+size_t ps2_read(uint8_t *buf, size_t max_len);