diff options
Diffstat (limited to 'kernel/features/event.c')
-rw-r--r-- | kernel/features/event.c | 32 |
1 files changed, 32 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; +} |