diff options
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/event.c | 32 | ||||
-rw-r--r-- | kernel/features/syscall.c | 5 |
2 files changed, 37 insertions, 0 deletions
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(); |