aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorMarvin Borner2021-01-13 19:51:40 +0100
committerMarvin Borner2021-01-13 19:51:40 +0100
commit91abed9333241731d0cd877beba4e2d4675989c8 (patch)
tree09a5e509afda809d56db88ec720c78864312620e /kernel/drivers
parent9ac1eda2988b6c7472a24817f4fd623de28a33f5 (diff)
VFS ready function and read yielding
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/ide.c1
-rw-r--r--kernel/drivers/keyboard.c34
2 files changed, 34 insertions, 1 deletions
diff --git a/kernel/drivers/ide.c b/kernel/drivers/ide.c
index f3d0f6e..5a51cb8 100644
--- a/kernel/drivers/ide.c
+++ b/kernel/drivers/ide.c
@@ -147,6 +147,7 @@ void ata_probe(void)
struct vfs *vfs = malloc(sizeof(*vfs));
vfs->type = VFS_EXT2;
vfs->read = ext2_read;
+ vfs->ready = ext2_ready;
vfs->stat = ext2_stat;
dev->vfs = vfs;
vfs_mount(dev, "/");
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index 7f3247f..6936c22 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -2,12 +2,17 @@
#include <cpu.h>
#include <def.h>
+#include <fs.h>
#include <interrupts.h>
#include <mem.h>
#include <print.h>
+#include <proc.h>
+#include <stack.h>
+#include <str.h>
#include <sys.h>
static struct event_keyboard *event = NULL;
+static struct stack *queue = NULL;
static int state = 0;
static int merged = 0;
@@ -33,10 +38,13 @@ void keyboard_handler()
event->magic = KEYBOARD_MAGIC;
event->press = (scancode & 0x80) == 0;
event->scancode = event->press ? scancode : scancode & ~0x80;
- //event_trigger(EVENT_KEYBOARD, event);
+ stack_push_bot(queue, event);
state = 0;
merged = 0;
+
+ // TODO: Only enable waiting procs
+ proc_current()->state = PROC_RUNNING;
}
void keyboard_acknowledge(void)
@@ -52,8 +60,32 @@ void keyboard_rate(void)
outb(0x60, 0x0); // Rate{00000} Delay{00} 0
}
+u32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev)
+{
+ (void)dev;
+ if (stack_empty(queue))
+ return 0;
+
+ struct event *e = stack_pop(queue);
+ memcpy(buf, (u8 *)e + offset, count);
+ return count;
+}
+
+u32 keyboard_ready()
+{
+ return !stack_empty(queue);
+}
+
void keyboard_install(void)
{
//keyboard_rate(); TODO: Fix keyboard rate?
irq_install_handler(1, keyboard_handler);
+
+ queue = stack_new();
+ struct device *dev = malloc(sizeof(*dev));
+ dev->name = strdup("kbd");
+ dev->type = DEV_CHAR;
+ dev->read = keyboard_read;
+ dev->ready = keyboard_ready;
+ device_add(dev);
}