aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-08-16 17:13:32 +0200
committerMarvin Borner2020-08-16 17:13:32 +0200
commit0dd3f5e6f4f7607611ce23510858ab3597b5df9f (patch)
tree19fa08636168489fa097dea675ef38a27d913d4d /kernel
parent36e36fae364dec02999f58edbe997780d901b674 (diff)
Added events and map syscall
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile3
-rw-r--r--kernel/drivers/keyboard.c4
-rw-r--r--kernel/features/event.c32
-rw-r--r--kernel/features/syscall.c5
-rw-r--r--kernel/inc/event.h12
5 files changed, 53 insertions, 3 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 50e3ab8..e781141 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -10,7 +10,8 @@ COBJS = main.o \
features/load.o \
features/proc.o \
features/proc_asm.o \
- features/syscall.o
+ features/syscall.o \
+ features/event.o
CC = ../cross/opt/bin/i686-elf-gcc
LD = ../cross/opt/bin/i686-elf-ld
OC = ../cross/opt/bin/i686-elf-objcopy
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index 16809b6..6405018 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -2,11 +2,11 @@
#include <cpu.h>
#include <def.h>
+#include <event.h>
#include <interrupts.h>
char keymap[128];
-// TODO: Use keyboard as event and move logic to other file
void keyboard_handler()
{
u8 scan_code = inb(0x60);
@@ -15,7 +15,7 @@ void keyboard_handler()
return;
if ((scan_code & 0x80) == 0) { // PRESS
- /* gui_term_write_char(keymap[scan_code]); */
+ event_trigger(EVENT_KEYBOARD, NULL);
}
}
diff --git a/kernel/features/event.c b/kernel/features/event.c
new file mode 100644
index 0000000..e91dcab
--- /dev/null
+++ b/kernel/features/event.c
@@ -0,0 +1,32 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#include <assert.h>
+#include <def.h>
+#include <sys.h>
+
+u32 (*event_table[])() = { [EVENT_KEYBOARD] = NULL, [EVENT_MOUSE] = NULL };
+
+u32 event_map(enum event id, u32 (*function)())
+{
+ printf("%x to %x\n", id, function);
+ if (id >= sizeof(event_table) / sizeof(*event_table))
+ return -1;
+
+ event_table[id] = function;
+ return 0;
+}
+
+u32 event_trigger(enum event id, u32 *data)
+{
+ assert(id < sizeof(event_table) / sizeof(*event_table));
+
+ u32 (*location)(u32 *) = event_table[id];
+ if (!location) {
+ printf("Event %d not mapped!\n", id);
+ return -1;
+ }
+
+ // TODO: Execute event function in ring3 with process stack, ...
+ location(data);
+ return 0;
+}
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index e6bcb83..2f2cbbb 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -1,6 +1,7 @@
// MIT License, Copyright (c) 2020 Marvin Borner
#include <cpu.h>
+#include <event.h>
#include <fs.h>
#include <interrupts.h>
#include <load.h>
@@ -50,6 +51,10 @@ void syscall_handler(struct regs *r)
proc_exit();
break;
}
+ case SYS_MAP: {
+ event_map(r->ebx, (u32(*)())r->ecx);
+ break;
+ }
default: {
printf("Unknown syscall!\n");
loop();
diff --git a/kernel/inc/event.h b/kernel/inc/event.h
new file mode 100644
index 0000000..f4025b4
--- /dev/null
+++ b/kernel/inc/event.h
@@ -0,0 +1,12 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#ifndef EVENT_H
+#define EVENT_H
+
+#include <def.h>
+#include <sys.h>
+
+u32 event_map(enum event id, u32 (*function)());
+u32 event_trigger(enum event id, u32 *data);
+
+#endif